Skip to content

Commit

Permalink
Support adding/editing short description (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp authored Feb 28, 2022
1 parent 2b8f4d3 commit fd9c10c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/modules/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,17 @@
return deferred;
};

this.getShortDescription = function () {
return AFCH.api.get( {
action: 'query',
prop: 'description',
titles: this.rawTitle,
formatversion: 2
} ).then( function ( json ) {
return json.query.pages[ 0 ].description || '';
} );
};

this.getLastModifiedDate = function () {
var deferred = $.Deferred();

Expand Down
41 changes: 38 additions & 3 deletions src/modules/submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,36 @@
return this.text;
};

AFCH.Text.prototype.updateShortDescription = function ( existingShortDescription, newShortDescription ) {
var shortDescTemplateExists = /\{\{[Ss]hort ?desc(ription)?\s*\|/.test( this.text );
var shortDescExists = !!existingShortDescription;

if ( newShortDescription ) {
// 1. No shortdesc - insert the one provided by user
if ( !shortDescExists ) {
this.prepend( '{{Short description|' + newShortDescription + '}}\n' );

// 2. Shortdesc exists from {{short description}} template - replace it
} else if ( shortDescExists && shortDescTemplateExists ) {
this.text = this.text.replace( /\{\{[Ss]hort ?desc(ription)?\s*\|.*?\}\}\n*/g, '' );
this.prepend( '{{Short description|' + newShortDescription + '}}\n' );

// 3. Shortdesc exists, but not generated by {{short description}}. If the user
// has changed the value, save the new value
} else if ( shortDescExists && existingShortDescription !== newShortDescription ) {
this.prepend( '{{Short description|' + newShortDescription + '}}\n' );

// 4. Shortdesc exists, but not generated by {{short description}}, and user hasn't changed the value
} else {
// Do nothing
}
} else {
// User emptied the shortdesc field (or didn't exist from before): remove any existing shortdesc.
// This doesn't remove any shortdesc that is generated by other templates
this.text = this.text.replace( /\{\{[Ss]hort ?desc(ription)?\s*\|.*?\}\}\n*/g, '' );
}
};

// Add the launch link
$afchLaunchLink = $( mw.util.addPortletLink( AFCH.prefs.launchLinkPosition, '#', 'Review (AFCH beta)',
'afch-launch', 'Review submission using afch-rewrite', '1' ) );
Expand Down Expand Up @@ -1497,8 +1527,9 @@
$.when(
afchPage.getText( false ),
existingWikiProjectsPromise,
afchPage.getCategories( /* useApi */ false, /* includeCategoryLinks */ true )
).then( function ( pageText, existingWikiProjectsResult, categories ) {
afchPage.getCategories( /* useApi */ false, /* includeCategoryLinks */ true ),
afchPage.getShortDescription()
).then( function ( pageText, existingWikiProjectsResult, categories, shortDescription ) {
var alreadyHasWPBio = existingWikiProjectsResult.alreadyHasWPBio,
wikiProjectMap = existingWikiProjectsResult.wikiProjectMap,
existingWPBioTemplateName = existingWikiProjectsResult.existingWPBioTemplateName;
Expand All @@ -1519,6 +1550,7 @@
hasWikiProjects: hasWikiProjects,
wikiProjects: wikiProjectObjs,
categories: categories,
shortDescription: shortDescription,
// Only offer to patrol the page if not already patrolled (in other words, if
// the "Mark as patrolled" link can be found in the DOM)
showPatrolOption: !!$afch.find( '.patrollink' ).length
Expand Down Expand Up @@ -1791,7 +1823,8 @@
addFormSubmitHandler( handleAccept, {
existingWikiProjects: existingWikiProjects,
alreadyHasWPBio: alreadyHasWPBio,
existingWPBioTemplateName: existingWPBioTemplateName
existingWPBioTemplateName: existingWPBioTemplateName,
existingShortDescription: shortDescription
} );

} );
Expand Down Expand Up @@ -2187,6 +2220,8 @@

newText.updateCategories( data.newCategories );

newText.updateShortDescription( data.existingShortDescription, data.shortDescription );

// Clean the page
newText.cleanUp( /* isAccept */ true );

Expand Down
5 changes: 5 additions & 0 deletions src/templates/tpl-submissions.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@
</select>
</div>

<div id="shortDescriptionWrapper">
<label for="shortDescription" class="afch-label">Short description</label>
<input type="text" id="shortDescription" class="afch-input afch-textfield" placeholder="British astronomer" value="{{shortDescription}}">
</div>

<div id="stubSorterWrapper" class="hidden">
<label class="afch-label" for="stub-sorter-select">Add stub tag</label>
<div id="stubSorterContainer"></div>
Expand Down

0 comments on commit fd9c10c

Please sign in to comment.