Skip to content

Commit

Permalink
Merge branch 'master' into auto-subscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
NovemLinguae authored Apr 16, 2024
2 parents e76ee6e + d79ffdf commit 3dbc4dd
Show file tree
Hide file tree
Showing 6 changed files with 305 additions and 160 deletions.
14 changes: 0 additions & 14 deletions contrib/loader.js

This file was deleted.

85 changes: 0 additions & 85 deletions contrib/old-afch-whitelist-checker.js

This file was deleted.

93 changes: 90 additions & 3 deletions src/modules/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,17 +604,18 @@

/**
* Modifies a page's content
* TODO the property name "contents" is quite silly, because people used to the MediaWiki API are gonna write "text"
*
* @todo the property name "contents" is quite silly, because people used to the MediaWiki API are gonna write "text"
* @param {string} pagename The page to be modified, namespace included
* @param {Object} options Object with properties:
* @param {Object} options Object with properties ('contents' is required, others are optional):
* contents: {string} the text to add to/replace the page,
* summary: {string} edit summary, will have the edit summary ad at the end,
* createonly: {bool} set to true to only edit the page if it doesn't exist,
* mode: {string} 'appendtext' or 'prependtext'; default: (replace everything)
* hide: {bool} Set to true to supress logging in statusWindow
* statusText: {string} message to show in status; default: "Editing"
* followRedirects: {boolean} true to follow redirects, false to ignore redirects
* watchlist: {string} 'nochange', 'preferences', 'unwatch', or 'watch'
* @return {jQuery.Deferred} Resolves if saved with all data
*/
editPage: function ( pagename, options ) {
Expand Down Expand Up @@ -652,6 +653,12 @@
request.minor = 'true';
}

if ( [ 'nochange', 'preferences', 'unwatch', 'watch' ].includes( options.watchlist ) ) {
request.watchlist = options.watchlist;
} else if ( AFCH.prefs.noWatch ) {
request.watchlist = 'nochange';
}

// Depending on mode, set appendtext=text or prependtext=text,
// which overrides the default text option
if ( options.mode ) {
Expand Down Expand Up @@ -737,6 +744,10 @@
reason: reason + AFCH.consts.summaryAd
}, additionalParameters );

if ( AFCH.prefs.noWatch ) {
request.watchlist = 'nochange';
}

if ( AFCH.consts.mockItUp ) {
AFCH.log( request );
deferred.resolve( { to: newTitle } );
Expand Down Expand Up @@ -1216,7 +1227,8 @@
autoOpen: false,
logCsd: true,
launchLinkPosition: 'p-cactions',
logAfc: false
logAfc: false,
noWatch: false
};

/**
Expand Down Expand Up @@ -1636,6 +1648,81 @@
return wikicode;
},

/**
* @param {string} talkText Wikitext of the draft talk page
* @param {string} newAssessment Value of "Article assessment" dropdown list, or "" if blank
* @param {number} revId Revision ID of the draft that is being accepted
* @param {boolean} isBiography Value of the "Is the article a biography?" check box
* @param {Array} newWikiProjects Value of the "Add WikiPrjects" part of the form. The <input> is a chips interface called jquery.chosen. Note that if there are existing WikiProject banners on the page, the form will auto-add those to the "Add WikiProjects" part of the form when it first loads.
* @param {string} lifeStatus Value of "Is the subject alive?" dropdown list ("unknown", "living", "dead")
* @param {string} subjectName Value of the "Subject name (last, first)" text input, or "" if blank
* @param {Array<Object>} existingWikiProjects An array of associative arrays. The associative arrays contain the keys {string} displayName (example: Somalia), {string} templateName (example: WikiProject Somalia), and {boolean} alreadyOnPage
* @param {boolean} alreadyHasWPBio
* @param {null} existingWPBioTemplateName
* @returns {Object} { {string} talkText, {number} countOfWikiProjectsAdded, {number} countOfWikiProjectsRemoved }
*/
addTalkPageBanners: function ( talkText, newAssessment, revId, isBiography, newWikiProjects, lifeStatus, subjectName, existingWikiProjects, alreadyHasWPBio, existingWPBioTemplateName ) {
var talkTextPrefix = '';

// Add the AFC banner
talkTextPrefix += '{{subst:WPAFC/article|class=' + newAssessment +
( revId ? '|oldid=' + revId : '' ) + '}}';

// Add biography banner if specified
if ( isBiography ) {
// Ensure we don't have duplicate biography tags
AFCH.removeFromArray( newWikiProjects, 'WikiProject Biography' );

talkTextPrefix += ( '\n{{WikiProject Biography|living=' +
( lifeStatus !== 'unknown' ? ( lifeStatus === 'living' ? 'yes' : 'no' ) : '' ) +
'|class=' + newAssessment + '|listas=' + subjectName + '}}' );
}

// Add disambiguation banner if needed
if ( newAssessment === 'disambig' &&
$.inArray( 'WikiProject Disambiguation', newWikiProjects ) === -1 ) {
newWikiProjects.push( 'WikiProject Disambiguation' );
}

// Add and remove WikiProjects
/** @var {Array} */
var wikiProjectsToAdd = newWikiProjects.filter( function ( newTemplateName ) {
return !existingWikiProjects.some( function ( existingTplObj ) {
return existingTplObj.templateName === newTemplateName;
} );
} );
/** @var {Array} */
var wikiProjectsToRemove = existingWikiProjects.filter( function ( existingTplObj ) {
return !newWikiProjects.some( function ( newTemplateName ) {
return existingTplObj.templateName === newTemplateName;
} );
} ).map( function ( templateObj ) {
return templateObj.realTemplateName || templateObj.templateName;
} );
if ( alreadyHasWPBio && !isBiography ) {
wikiProjectsToRemove.push( existingWPBioTemplateName || 'wikiproject biography' );
}

$.each( wikiProjectsToAdd, function ( _index, templateName ) {
talkTextPrefix += '\n{{' + templateName + '|class=' + newAssessment + '}}';
} );
$.each( wikiProjectsToRemove, function ( _index, templateName ) {
// Regex from https://stackoverflow.com/a/5306111/1757964
var sanitizedTemplateName = templateName.replace( /[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&' );
talkText = talkText.replace( new RegExp( '\\n?\\{\\{\\s*' + sanitizedTemplateName + '\\s*.+?\\}\\}', 'is' ), '' );
} );

// We prepend the text so that talk page content is not removed
// (e.g. pages in `Draft:` namespace with discussion)
talkText = talkTextPrefix + '\n\n' + talkText;

return {
talkText: talkText,
countOfWikiProjectsAdded: wikiProjectsToAdd.length,
countOfWikiProjectsRemoved: wikiProjectsToRemove.length
};
},

/**
* Returns the relative time that has elapsed between an oldDate and a nowDate
*
Expand Down
100 changes: 42 additions & 58 deletions src/modules/submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,28 @@
var deferred = $.Deferred(),
user = this.params.u;

// Recursively detect if the user has been renamed by checking the rename log
if ( user ) {
deferred.resolve( user );
AFCH.api.get( {
action: 'query',
list: 'logevents',
formatversion: 2,
letype: 'renameuser',
lelimit: 1,
letitle: 'User:' + user
} ).then( function ( resp ) {
var logevents = resp.query.logevents;

if ( logevents.length ) {
var newName = logevents[ 0 ].params.newuser;
this.params.u = newName;
this.getSubmitter().then( function ( user ) {
deferred.resolve( user );
} );
} else {
deferred.resolve( user );
}
}.bind( this ) );
} else {
this.page.getCreator().done( function ( user ) {
deferred.resolve( user );
Expand Down Expand Up @@ -2275,65 +2295,28 @@
// ---------

talkPage.getText().done( function ( talkText ) {
var talkTextPrefix = '';

// Add the AFC banner
talkTextPrefix += '{{subst:WPAFC/article|class=' + data.newAssessment +
( afchPage.additionalData.revId ? '|oldid=' + afchPage.additionalData.revId : '' ) + '}}';

// Add biography banner if specified
if ( data.isBiography ) {
// Ensure we don't have duplicate biography tags
AFCH.removeFromArray( data.newWikiProjects, 'WikiProject Biography' );

talkTextPrefix += ( '\n{{WikiProject Biography|living=' +
( data.lifeStatus !== 'unknown' ? ( data.lifeStatus === 'living' ? 'yes' : 'no' ) : '' ) +
'|class=' + data.newAssessment + '|listas=' + data.subjectName + '}}' );
}

if ( data.newAssessment === 'disambig' &&
$.inArray( 'WikiProject Disambiguation', data.newWikiProjects ) === -1 ) {
data.newWikiProjects.push( 'WikiProject Disambiguation' );
}

// Add and remove WikiProjects
var wikiProjectsToAdd = data.newWikiProjects.filter( function ( newTemplateName ) {
return !data.existingWikiProjects.some( function ( existingTplObj ) {
return existingTplObj.templateName === newTemplateName;
} );
} );
var wikiProjectsToRemove = data.existingWikiProjects.filter( function ( existingTplObj ) {
return !data.newWikiProjects.some( function ( newTemplateName ) {
return existingTplObj.templateName === newTemplateName;
} );
} ).map( function ( templateObj ) {
return templateObj.realTemplateName || templateObj.templateName;
} );
if ( data.alreadyHasWPBio && !data.isBiography ) {
wikiProjectsToRemove.push( data.existingWPBioTemplateName || 'wikiproject biography' );
}

$.each( wikiProjectsToAdd, function ( _index, templateName ) {
talkTextPrefix += '\n{{' + templateName + '|class=' + data.newAssessment + '}}';
} );
$.each( wikiProjectsToRemove, function ( _index, templateName ) {
// Regex from https://stackoverflow.com/a/5306111/1757964
var sanitizedTemplateName = templateName.replace( /[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&' );
talkText = talkText.replace( new RegExp( '\\n?\\{\\{\\s*' + sanitizedTemplateName + '\\s*.+?\\}\\}', 'is' ), '' );
} );

// We prepend the text so that talk page content is not removed
// (e.g. pages in `Draft:` namespace with discussion)
talkText = talkTextPrefix + '\n\n' + talkText;
var results = AFCH.addTalkPageBanners(
talkText,
data.newAssessment,
afchPage.additionalData.revId,
data.isBiography,
data.newWikiProjects,
data.lifeStatus,
data.subjectName,
data.existingWikiProjects,
data.alreadyHasWPBio,
data.existingWPBioTemplateName
);
talkText = results.talkText;

var summary = 'Placing [[Wikipedia:Articles for creation|Articles for creation]] banner';
if ( wikiProjectsToAdd.length > 0 ) {
summary += ', adding ' + wikiProjectsToAdd.length +
' WikiProject banner' + ( ( wikiProjectsToAdd.length === 1 ) ? '' : 's' );
if ( results.countOfWikiProjectsAdded > 0 ) {
summary += ', adding ' + results.countOfWikiProjectsAdded +
' WikiProject banner' + ( ( results.countOfWikiProjectsAdded === 1 ) ? '' : 's' );
}
if ( wikiProjectsToRemove.length > 0 ) {
summary += ', removing ' + wikiProjectsToRemove.length +
' WikiProject banner' + ( ( wikiProjectsToRemove.length === 1 ) ? '' : 's' );
if ( results.countOfWikiProjectsRemoved > 0 ) {
summary += ', removing ' + results.countOfWikiProjectsRemoved +
' WikiProject banner' + ( ( results.countOfWikiProjectsRemoved === 1 ) ? '' : 's' );
}

if ( comments && comments.length > 0 ) {
Expand Down Expand Up @@ -2378,7 +2361,8 @@

recentPage.edit( {
contents: newRecentText,
summary: 'Adding [[' + newPage + ']] to list of recent AfC creations'
summary: 'Adding [[' + newPage + ']] to list of recent AfC creations',
watchlist: 'nochange'
} );
} );

Expand Down
4 changes: 4 additions & 0 deletions src/templates/tpl-preferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<label for="logAfc" class="afch-label">Log acceptances, declines, and rejects</label>
<input type="checkbox" id="logAfc" class="afch-input" {{#logAfc}}checked{{/logAfc}} />
</div>
<div id="noWatchWrapper">
<label for="noWatch" class="afch-label">Do not add pages to watchlist</label>
<input type="checkbox" id="noWatch" class="afch-input" {{#noWatch}}checked{{/noWatch}} />
</div>
</div>
<!-- /preferences -->

Expand Down
Loading

0 comments on commit 3dbc4dd

Please sign in to comment.