User:Syunsyunminmin/Twinkle/twinklexfd.js: Difference between revisions

From Test Wiki
no edit summary
No edit summary
No edit summary
 
Line 160: Line 160:
});
});


form.append({
type: 'checkbox',
list: [
{
label: 'Notify page creator if possible',
value: 'notify',
name: 'notifycreator',
tooltip: "A notification template will be placed on the creator's talk page if this is true.",
checked: true
}
]
});
form.append({
form.append({
type: 'field',
type: 'field',
Line 210: Line 198:
} else if (mw.config.get('wgIsRedirect')) {
} else if (mw.config.get('wgIsRedirect')) {
text = 'Please use RfD for redirects.';
text = 'Please use RfD for redirects.';
}
break;
case 'tfd':
if (namespace === 10 && /-stub$/.test(Morebits.pageNameNorm)) {
text = 'Use CfD for stub templates.';
} else if (Morebits.pageNameNorm.indexOf('Template:User ') === 0) {
text = 'Please use MfD for userboxes';
}
break;
case 'cfd':
if ([ 10, 14 ].indexOf(namespace) === -1) {
text = 'CfD is only for categories and stub templates.';
}
break;
case 'cfds':
if (namespace !== 14) {
text = 'CfDS is only for categories.';
}
break;
case 'ffd':
if (namespace !== 6) {
text = 'FFD is selected but this page doesn\'t look like a file!';
}
}
break;
break;
Line 360: Line 326:
'.select2-selection__choice__remove { font-size: 130%; }'
'.select2-selection__choice__remove { font-size: 130%; }'
);
);
break;
case 'tfd':
work_area = new Morebits.quickForm.element({
type: 'field',
label: 'Templates for discussion',
name: 'work_area'
});
var templateOrModule = mw.config.get('wgPageContentModel') === 'Scribunto' ? 'module' : 'template';
work_area.append({
type: 'select',
label: 'Choose type of action wanted:',
name: 'xfdcat',
event: function(e) {
var target = e.target,
tfdtarget = target.form.tfdtarget;
// add/remove extra input box
if (target.value === 'tfm' && !tfdtarget) {
tfdtarget = new Morebits.quickForm.element({
name: 'tfdtarget',
type: 'input',
label: 'Other ' + templateOrModule + ' to be merged:',
tooltip: 'Required. Should not include the ' + Morebits.string.toUpperCaseFirstChar(templateOrModule) + ': namespace prefix.',
required: true
});
target.parentNode.appendChild(tfdtarget.render());
} else {
$(Morebits.quickForm.getElementContainer(tfdtarget)).remove();
tfdtarget = null;
}
},
list: [
{ type: 'option', label: 'Deletion', value: 'tfd', selected: true },
{ type: 'option', label: 'Merge', value: 'tfm' }
]
});
work_area.append({
type: 'select',
name: 'templatetype',
label: 'Deletion tag display style:',
tooltip: 'Which <code>type=</code> parameter to pass to the TfD tag template.',
list: templateOrModule === 'module' ? [
{ type: 'option', value: 'module', label: 'Module', selected: true }
] : [
{ type: 'option', value: 'standard', label: 'Standard', selected: true },
{ type: 'option', value: 'sidebar', label: 'Sidebar/infobox', selected: $('.infobox').length },
{ type: 'option', value: 'inline', label: 'Inline template', selected: $('.mw-parser-output > p .Inline-Template').length },
{ type: 'option', value: 'tiny', label: 'Tiny inline' },
{ type: 'option', value: 'disabled', label: 'Disabled' }
]
});
work_area.append({
type: 'checkbox',
list: [
{
label: 'Wrap deletion tag with &lt;noinclude&gt; (for substituted templates only)',
value: 'noinclude',
name: 'noinclude',
tooltip: 'Will wrap the deletion tag in &lt;noinclude&gt; tags, so that it won\'t get substituted along with the template.',
disabled: templateOrModule === 'module',
checked: !!$('.box-Subst_only').length // Default to checked if page carries {{subst only}}
}
]
});
work_area.append({
type: 'checkbox',
list: [
{
label: 'Notify talk pages of affected user scripts',
value: 'devpages',
name: 'devpages',
tooltip: 'A notification will be sent to Twinkle, AWB, and Ultraviolet\'s talk pages if those user scripts are marked as using this template.',
checked: true
}
]
});
appendReasonBox();
work_area = work_area.render();
old_area.parentNode.replaceChild(work_area, old_area);
break;
case 'mfd':
work_area = new Morebits.quickForm.element({
type: 'field',
label: 'Miscellany for deletion',
name: 'work_area'
});
work_area.append({
type: 'checkbox',
list: [
{
label: 'Wrap deletion tag with &lt;noinclude&gt;',
value: 'noinclude',
name: 'noinclude',
tooltip: 'Will wrap the deletion tag in &lt;noinclude&gt; tags, so that it won\'t transclude. Select this option for userboxes.'
}
]
});
if ((mw.config.get('wgNamespaceNumber') === 2 /* User: */ || mw.config.get('wgNamespaceNumber') === 3 /* User talk: */) && mw.config.exists('wgRelevantUserName')) {
work_area.append({
type: 'checkbox',
list: [
{
label: 'Notify owner of userspace (if they are not the page creator)',
value: 'notifyuserspace',
name: 'notifyuserspace',
tooltip: 'If the user in whose userspace this page is located is not the page creator (for example, the page is a rescued article stored as a userspace draft), notify the userspace owner as well.',
checked: true
}
]
});
}
appendReasonBox();
work_area = work_area.render();
old_area.parentNode.replaceChild(work_area, old_area);
break;
case 'ffd':
work_area = new Morebits.quickForm.element({
type: 'field',
label: 'Discussion venues for files',
name: 'work_area'
});
appendReasonBox();
work_area = work_area.render();
old_area.parentNode.replaceChild(work_area, old_area);
break;
case 'cfd':
work_area = new Morebits.quickForm.element({
type: 'field',
label: 'Categories for discussion',
name: 'work_area'
});
var isCategory = mw.config.get('wgNamespaceNumber') === 14;
work_area.append({
type: 'select',
label: 'Choose type of action wanted:',
name: 'xfdcat',
event: function(e) {
var value = e.target.value,
cfdtarget = e.target.form.cfdtarget,
cfdtarget2 = e.target.form.cfdtarget2;
// update enabled status
cfdtarget.disabled = value === 'cfd' || value === 'sfd-t';
if (isCategory) {
// update label
if (value === 'cfs') {
Morebits.quickForm.setElementLabel(cfdtarget, 'Target categories: ');
} else if (value === 'cfc') {
Morebits.quickForm.setElementLabel(cfdtarget, 'Target article: ');
} else {
Morebits.quickForm.setElementLabel(cfdtarget, 'Target category: ');
}
// add/remove extra input box
if (value === 'cfs') {
if (cfdtarget2) {
cfdtarget2.disabled = false;
$(cfdtarget2).show();
} else {
cfdtarget2 = document.createElement('input');
cfdtarget2.setAttribute('name', 'cfdtarget2');
cfdtarget2.setAttribute('type', 'text');
cfdtarget2.setAttribute('required', 'true');
cfdtarget.parentNode.appendChild(cfdtarget2);
}
} else {
$(cfdtarget2).prop('disabled', true);
$(cfdtarget2).hide();
}
} else { // Update stub template label
Morebits.quickForm.setElementLabel(cfdtarget, 'Target stub template: ');
}
},
list: isCategory ? [
{ type: 'option', label: 'Deletion', value: 'cfd', selected: true },
{ type: 'option', label: 'Merge', value: 'cfm' },
{ type: 'option', label: 'Renaming', value: 'cfr' },
{ type: 'option', label: 'Split', value: 'cfs' },
{ type: 'option', label: 'Convert into article', value: 'cfc' }
] : [
{ type: 'option', label: 'Stub Deletion', value: 'sfd-t', selected: true },
{ type: 'option', label: 'Stub Renaming', value: 'sfr-t' }
]
});
work_area.append({
type: 'input',
name: 'cfdtarget',
label: 'Target category:', // default, changed above
disabled: true,
required: true, // only when enabled
value: ''
});
appendReasonBox();
work_area = work_area.render();
old_area.parentNode.replaceChild(work_area, old_area);
break;
case 'cfds':
work_area = new Morebits.quickForm.element({
type: 'field',
label: 'Categories for speedy renaming',
name: 'work_area'
});
work_area.append({
type: 'select',
label: 'C2 sub-criterion:',
name: 'xfdcat',
tooltip: 'See WP:CFDS for full explanations.',
list: [
{ type: 'option', label: 'C2A: Typographic and spelling fixes', value: 'C2A', selected: true },
{ type: 'option', label: 'C2B: Naming conventions and disambiguation', value: 'C2B' },
{ type: 'option', label: 'C2C: Consistency with names of similar categories', value: 'C2C' },
{ type: 'option', label: 'C2D: Rename to match article name', value: 'C2D' },
{ type: 'option', label: 'C2E: Author request', value: 'C2E' },
{ type: 'option', label: 'C2F: One eponymous article', value: 'C2F' }
]
});
work_area.append({
type: 'input',
name: 'cfdstarget',
label: 'New name:',
value: '',
required: true
});
appendReasonBox();
work_area = work_area.render();
old_area.parentNode.replaceChild(work_area, old_area);
break;
break;


Line 744: Line 475:
if (params.rfdtarget) {
if (params.rfdtarget) {
text += '|target=' + params.rfdtarget + (params.section ? '#' + params.section : '');
text += '|target=' + params.rfdtarget + (params.section ? '#' + params.section : '');
} else if (params.tfdtarget) {
text += '|2=' + params.tfdtarget;
} else if (params.cfdtarget) {
text += '|2=' + params.cfdtarget;
if (params.cfdtarget2) {
text += '|3=' + params.cfdtarget2;
}
} else if (params.uploader) {
text += '|Uploader=' + params.uploader;
}
}


Line 779: Line 501:
var venue = params.venue;
var venue = params.venue;


// Remove CfD or TfD namespace prefixes if given
if (venue === 'rfd') { // Find the target
if (params.tfdtarget) {
params.tfdtarget = utils.stripNs(params.tfdtarget);
} else if (params.cfdtarget) {
params.cfdtarget = utils.stripNs(params.cfdtarget);
if (params.cfdtarget2) {
params.cfdtarget2 = utils.stripNs(params.cfdtarget2);
}
} else if (params.cfdstarget) { // Add namespace if not given (CFDS)
params.cfdstarget = utils.addNs(params.cfdstarget, 14);
}
 
if (venue === 'ffd') {
// Fetch the uploader
var page = new Morebits.wiki.page(mw.config.get('wgPageName'));
page.lookupCreation(function() {
params.uploader = page.getCreator();
Twinkle.xfd.callbacks.showPreview(form, venue, params);
});
} else if (venue === 'rfd') { // Find the target
Twinkle.xfd.callbacks.rfd.findTarget(params, function(params) {
Twinkle.xfd.callbacks.rfd.findTarget(params, function(params) {
Twinkle.xfd.callbacks.showPreview(form, venue, params);
Twinkle.xfd.callbacks.showPreview(form, venue, params);
});
});
} else if (venue === 'cfd') { // Swap in CfD subactions
Twinkle.xfd.callbacks.showPreview(form, params.xfdcat, params);
} else {
} else {
Twinkle.xfd.callbacks.showPreview(form, venue, params);
Twinkle.xfd.callbacks.showPreview(form, venue, params);
Line 819: Line 520:
* being undertaken. Required if not notifying a user talk page.
* being undertaken. Required if not notifying a user talk page.
*/
*/
notifyUser: function(params, notifyTarget, noLog, actionName) {
// Ensure items with User talk or no namespace prefix both end
// up at user talkspace as expected, but retain the
// prefix-less username for addToLog
notifyTarget = mw.Title.newFromText(notifyTarget, 3);
var targetNS = notifyTarget.getNamespaceId();
var usernameOrTarget = notifyTarget.getRelativeText(3);
notifyTarget = notifyTarget.toText();
if (targetNS === 3) {
// Disallow warning yourself
if (usernameOrTarget === mw.config.get('wgUserName')) {
Morebits.status.warn('You (' + usernameOrTarget + ') created this page; skipping user notification');
 
// if we thought we would notify someone but didn't,
// then jump to logging.
Twinkle.xfd.callbacks.addToLog(params, null);
return;
}
// Default is notifying the initial contributor, but MfD also
// notifies userspace page owner
actionName = actionName || 'Notifying initial contributor (' + usernameOrTarget + ')';
}
 
var notifytext = '\n{{subst:' + params.venue + ' notice';
// Venue-specific parameters
switch (params.venue) {
case 'afd':
case 'mfd':
notifytext += params.numbering !== '' ? '|order=&#32;' + params.numbering : '';
break;
case 'tfd':
if (params.xfdcat === 'tfm') {
notifytext = '\n{{subst:Tfm notice|2=' + params.tfdtarget;
}
break;
case 'cfd':
notifytext += '|action=' + params.action + (mw.config.get('wgNamespaceNumber') === 10 ? '|stub=yes' : '');
break;
default: // ffd, rfd
break;
}
notifytext += '|1=' + Morebits.pageNameNorm + '}} ~~~~';
 
// Link to the venue; object used here rather than repetitive items in switch
var venueNames = {
afd: 'Articles for deletion',
tfd: 'Templates for discussion',
mfd: 'Miscellany for deletion',
cfd: 'Categories for discussion',
ffd: 'Files for discussion',
rfd: 'Redirects for discussion'
};
var editSummary = 'Notification: [[' + params.discussionpage + '|listing]] of [[:' +
Morebits.pageNameNorm + ']] at [[WP:' + venueNames[params.venue] + ']].';
 
var usertalkpage = new Morebits.wiki.page(notifyTarget, actionName);
usertalkpage.setAppendText(notifytext);
usertalkpage.setEditSummary(editSummary);
usertalkpage.setCreateOption('recreate');
// Different pref for RfD target notifications
if (params.venue === 'rfd' && targetNS !== 3) {
usertalkpage.setWatchlist(Twinkle.getPref('xfdWatchRelated'));
} else {
usertalkpage.setWatchlist(Twinkle.getPref('xfdWatchUser'));
}
usertalkpage.setFollowRedirect(true, false);
 
if (noLog) {
usertalkpage.append();
} else {
usertalkpage.append(function onNotifySuccess() {
// Don't treat RfD target or MfD userspace owner as initialContrib in log
if (!params.notifycreator) {
notifyTarget = null;
}
// add this nomination to the user's userspace log
Twinkle.xfd.callbacks.addToLog(params, usernameOrTarget);
}, function onNotifyError() {
// if user could not be notified, log nomination without mentioning that notification was sent
Twinkle.xfd.callbacks.addToLog(params, null);
});
}
},
addToLog: function(params, initialContrib) {
addToLog: function(params, initialContrib) {
if (!Twinkle.getPref('logXfdNominations') || Twinkle.getPref('noLogOnXfdNomination').indexOf(params.venue) !== -1) {
if (!Twinkle.getPref('logXfdNominations') || Twinkle.getPref('noLogOnXfdNomination').indexOf(params.venue) !== -1) {
Line 925: Line 544:


switch (params.venue) {
switch (params.venue) {
case 'tfd':
if (params.xfdcat === 'tfm') {
appendText += ' (merge)';
if (params.tfdtarget) {
var contentModel = mw.config.get('wgPageContentModel') === 'Scribunto' ? 'Module:' : 'Template:';
appendText += '; Other ' + contentModel.toLowerCase() + ' [[';
if (!new RegExp('^:?' + Morebits.namespaceRegex([10, 828]) + ':', 'i').test(params.tfdtarget)) {
appendText += contentModel;
}
appendText += params.tfdtarget + ']]';
}
}
break;
case 'mfd':
if (params.notifyuserspace && params.userspaceOwner && params.userspaceOwner !== initialContrib) {
appendText += '; notified {{user|1=' + params.userspaceOwner + '}}';
}
break;
case 'cfd':
appendText += ' (' + utils.toTLACase(params.xfdcat) + ')';
if (params.cfdtarget) {
var categoryOrTemplate = params.xfdcat.charAt(0) === 's' ? 'Template:' : ':Category:';
appendText += '; ' + params.action + ' to [[' + categoryOrTemplate + params.cfdtarget + ']]';
if (params.xfdcat === 'cfs' && params.cfdtarget2) {
appendText += ', [[' + categoryOrTemplate + params.cfdtarget2 + ']]';
}
}
break;
case 'cfds':
appendText += ' (' + utils.toTLACase(params.xfdcat) + ')';
// Ensure there's more than just 'Category:'
if (params.cfdstarget && params.cfdstarget.length > 9) {
appendText += '; New name: [[:' + params.cfdstarget + ']]';
}
break;
case 'rfd':
case 'rfd':
if (params.rfdtarget) {
if (params.rfdtarget) {
Line 979: Line 563:
default: // afd or ffd
default: // afd or ffd
break;
break;
}
if (initialContrib && params.notifycreator) {
appendText += '; notified {{user|1=' + initialContrib + '}}';
}
}
appendText += ' ~~~~~';
appendText += ' ~~~~~';
Line 1,179: Line 759:
}
}
},
},
tfd: {
main: function(pageobj) {
var params = pageobj.getCallbackParameters();
var date = new Morebits.date(pageobj.getLoadTime());
params.logpage = 'Wikipedia:Templates for discussion/Log/' + date.format('YYYY MMMM D', 'utc'),
params.discussionpage = params.logpage + '#' + Morebits.pageNameNorm;
// Add log/discussion page params to the already-loaded page object
pageobj.setCallbackParameters(params);
// Defined here rather than below to reduce duplication
var watchModule, watch_query;
if (params.scribunto) {
var watchPref = Twinkle.getPref('xfdWatchPage');
// action=watch has no way to rely on user
// preferences (T262912), so we do it manually.
// The watchdefault pref appears to reliably return '1' (string),
// but that's not consistent among prefs so might as well be "correct"
watchModule = watchPref !== 'no' && (watchPref !== 'default' || !!parseInt(mw.user.options.get('watchdefault'), 10));
if (watchModule) {
watch_query = {
action: 'watch',
titles: [ mw.config.get('wgPageName') ],
token: mw.user.tokens.get('watchToken')
};
// Only add the expiry if page is unwatched or already temporarily watched
if (pageobj.getWatched() !== true && watchPref !== 'default' && watchPref !== 'yes') {
watch_query.expiry = watchPref;
}
}
}
// Tagging template(s)/module(s)
if (params.xfdcat === 'tfm') { // Merge
var wikipedia_otherpage;
if (params.scribunto) {
wikipedia_otherpage = new Morebits.wiki.page(params.otherTemplateName + '/doc', 'Tagging other module documentation with merge tag');
// Watch tagged module pages as well
if (watchModule) {
watch_query.titles.push(params.otherTemplateName);
new Morebits.wiki.api('Adding Modules to watchlist', watch_query).post();
}
} else {
wikipedia_otherpage = new Morebits.wiki.page(params.otherTemplateName, 'Tagging other template with merge tag');
}
// Tag this template/module
Twinkle.xfd.callbacks.tfd.taggingTemplateForMerge(pageobj);
// Tag other template/module
wikipedia_otherpage.setFollowRedirect(true);
var otherParams = $.extend({}, params);
otherParams.otherTemplateName = Morebits.pageNameNorm;
wikipedia_otherpage.setCallbackParameters(otherParams);
wikipedia_otherpage.load(Twinkle.xfd.callbacks.tfd.taggingTemplateForMerge);
} else { // delete
if (params.scribunto && Twinkle.getPref('xfdWatchPage') !== 'no') {
// Watch tagged module page as well
if (watchModule) {
new Morebits.wiki.api('Adding Module to watchlist', watch_query).post();
}
}
Twinkle.xfd.callbacks.tfd.taggingTemplate(pageobj);
}
// Updating data for the action completed event
Morebits.wiki.actionCompleted.redirect = params.logpage;
Morebits.wiki.actionCompleted.notice = "Nomination completed, now redirecting to today's log";
// Adding discussion
var wikipedia_page = new Morebits.wiki.page(params.logpage, "Adding discussion to today's log");
wikipedia_page.setFollowRedirect(true);
wikipedia_page.setCallbackParameters(params);
wikipedia_page.load(Twinkle.xfd.callbacks.tfd.todaysList);
// Notification to first contributors
if (params.notifycreator) {
var involvedpages = [];
var seenusers = [];
involvedpages.push(new Morebits.wiki.page(mw.config.get('wgPageName')));
if (params.xfdcat === 'tfm') {
if (params.scribunto) {
involvedpages.push(new Morebits.wiki.page('Module:' + params.tfdtarget));
} else {
involvedpages.push(new Morebits.wiki.page('Template:' + params.tfdtarget));
}
}
involvedpages.forEach(function(page) {
page.setCallbackParameters(params);
page.lookupCreation(function(innerpage) {
var username = innerpage.getCreator();
if (seenusers.indexOf(username) === -1) {
seenusers.push(username);
// Only log once on merge nominations, for the initial template
Twinkle.xfd.callbacks.notifyUser(innerpage.getCallbackParameters(), username,
params.xfdcat === 'tfm' && innerpage.getPageName() !== Morebits.pageNameNorm);
}
});
});
// or, if not notifying, add this nomination to the user's userspace log without the initial contributor's name
} else {
Twinkle.xfd.callbacks.addToLog(params, null);
}
// Notify developer(s) of script(s) that use(s) the nominated template
if (params.devpages) {
var inCategories = mw.config.get('wgCategories');
var categoryNotificationPageMap = {
'Templates used by Twinkle': 'Wikipedia talk:Twinkle',
'Templates used by AutoWikiBrowser': 'Wikipedia talk:AutoWikiBrowser',
'Templates used by Ultraviolet': 'Wikipedia talk:Ultraviolet'
};
$.each(categoryNotificationPageMap, function(category, page) {
if (inCategories.indexOf(category) !== -1) {
Twinkle.xfd.callbacks.notifyUser(params, page, true, 'Notifying ' + page + ' of template nomination');
}
});
}
},
taggingTemplate: function(pageobj) {
var text = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
params.tagText = '{{subst:template for discussion|help=off' + (params.templatetype !== 'standard' ? '|type=' + params.templatetype : '') + '}}';
if (pageobj.getContentModel() === 'sanitized-css') {
params.tagText = '/* ' + params.tagText + ' */';
} else {
if (params.noinclude) {
params.tagText = '<noinclude>' + params.tagText + '</noinclude>';
}
params.tagText += params.templatetype === 'standard' || params.templatetype === 'sidebar' || params.templatetype === 'disabled' ? '\n' : ''; // No newline for inline
}
if (pageobj.canEdit() && ['wikitext', 'sanitized-css'].indexOf(pageobj.getContentModel()) !== -1) {
pageobj.setPageText(params.tagText + text);
pageobj.setEditSummary('Nominated for deletion; see [[:' + params.discussionpage + ']]. ([[Help:Twinkle|Twinkle]]使用)');
pageobj.setWatchlist(Twinkle.getPref('xfdWatchPage'));
if (params.scribunto) {
pageobj.setCreateOption('recreate'); // Module /doc might not exist
}
pageobj.save();
} else {
Twinkle.xfd.callbacks.autoEditRequest(pageobj, params);
}
},
taggingTemplateForMerge: function(pageobj) {
var text = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
params.tagText = '{{subst:tfm|help=off|' + (params.templatetype !== 'standard' ? 'type=' + params.templatetype + '|' : '') +
'1=' + params.otherTemplateName.replace(new RegExp('^' + Morebits.namespaceRegex([10, 828]) + ':'), '') + '}}';
if (pageobj.getContentModel() === 'sanitized-css') {
params.tagText = '/* ' + params.tagText + ' */';
} else {
if (params.noinclude) {
params.tagText = '<noinclude>' + params.tagText + '</noinclude>';
}
params.tagText += params.templatetype === 'standard' || params.templatetype === 'sidebar' || params.templatetype === 'disabled' ? '\n' : ''; // No newline for inline
}
if (pageobj.canEdit() && ['wikitext', 'sanitized-css'].indexOf(pageobj.getContentModel()) !== -1) {
pageobj.setPageText(params.tagText + text);
pageobj.setEditSummary('Listed for merging with [[:' + params.otherTemplateName + ']]; see [[:' + params.discussionpage + ']]. ([[Help:Twinkle|Twinkle]]使用)');
pageobj.setWatchlist(Twinkle.getPref('xfdWatchPage'));
if (params.scribunto) {
pageobj.setCreateOption('recreate'); // Module /doc might not exist
}
pageobj.save();
} else {
Twinkle.xfd.callbacks.autoEditRequest(pageobj, params);
}
},
todaysList: function(pageobj) {
var params = pageobj.getCallbackParameters();
var statelem = pageobj.getStatusElement();
var added_data = Twinkle.xfd.callbacks.getDiscussionWikitext(params.xfdcat, params);
var text;
// add date header if the log is found to be empty (a bot should do this automatically)
if (!pageobj.exists()) {
text = '{{subst:TfD log}}\n' + added_data;
} else {
var old_text = pageobj.getPageText();
text = old_text.replace('-->', '-->\n' + added_data);
if (text === old_text) {
statelem.error('failed to find target spot for the discussion');
return;
}
}
pageobj.setPageText(text);
pageobj.setEditSummary('Adding ' + (params.xfdcat === 'tfd' ? 'deletion nomination' : 'merge listing') + ' of [[:' + Morebits.pageNameNorm + ']]. ([[Help:Twinkle|Twinkle]]使用)');
pageobj.setWatchlist(Twinkle.getPref('xfdWatchDiscussion'));
pageobj.setCreateOption('recreate');
pageobj.save(function() {
Twinkle.xfd.currentRationale = null;  // any errors from now on do not need to print the rationale, as it is safely saved on-wiki
});
}
},
mfd: {
main: function(apiobj) {
var response = apiobj.getResponse();
var titles = response.query.allpages;
// There has been no earlier entries with this prefix, just go on.
if (titles.length <= 0) {
apiobj.params.numbering = apiobj.params.number = '';
} else {
var number = 0;
for (var i = 0; i < titles.length; ++i) {
var title = titles[i].title;
// First, simple test, is there an instance with this exact name?
if (title === 'Wikipedia:Miscellany for deletion/' + Morebits.pageNameNorm) {
number = Math.max(number, 1);
continue;
}
var order_re = new RegExp('^' +
Morebits.string.escapeRegExp('Wikipedia:Miscellany for deletion/' + Morebits.pageNameNorm) +
'\\s*\\(\\s*(\\d+)(?:(?:th|nd|rd|st) nom(?:ination)?)?\\s*\\)\\s*$');
var match = order_re.exec(title);
// No match; A non-good value
if (!match) {
continue;
}
// A match, set number to the max of current
number = Math.max(number, Number(match[1]));
}
apiobj.params.number = utils.num2order(parseInt(number, 10) + 1);
apiobj.params.numbering = number > 0 ? ' (' + apiobj.params.number + ' nomination)' : '';
}
apiobj.params.discussionpage = 'Wikipedia:Miscellany for deletion/' + Morebits.pageNameNorm + apiobj.params.numbering;
apiobj.statelem.info('next in order is [[' + apiobj.params.discussionpage + ']]');
// Tagging page
var wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'), 'Tagging page with deletion tag');
wikipedia_page.setFollowRedirect(true);  // should never be needed, but if the page is moved, we would want to follow the redirect
wikipedia_page.setCallbackParameters(apiobj.params);
wikipedia_page.load(Twinkle.xfd.callbacks.mfd.taggingPage);
// Updating data for the action completed event
Morebits.wiki.actionCompleted.redirect = apiobj.params.discussionpage;
Morebits.wiki.actionCompleted.notice = 'Nomination completed, now redirecting to the discussion page';
// Discussion page
wikipedia_page = new Morebits.wiki.page(apiobj.params.discussionpage, 'Creating deletion discussion page');
wikipedia_page.setCallbackParameters(apiobj.params);
wikipedia_page.load(Twinkle.xfd.callbacks.mfd.discussionPage);
// Today's list
wikipedia_page = new Morebits.wiki.page('Wikipedia:Miscellany for deletion', "Adding discussion to today's list");
wikipedia_page.setPageSection(2);
wikipedia_page.setFollowRedirect(true);
wikipedia_page.setCallbackParameters(apiobj.params);
wikipedia_page.load(Twinkle.xfd.callbacks.mfd.todaysList);
// Notification to first contributor and/or notification to owner of userspace
if (apiobj.params.notifycreator || apiobj.params.notifyuserspace) {
var thispage = new Morebits.wiki.page(mw.config.get('wgPageName'));
thispage.setCallbackParameters(apiobj.params);
thispage.lookupCreation(Twinkle.xfd.callbacks.mfd.sendNotifications);
// or, if not notifying, add this nomination to the user's userspace log without the initial contributor's name
} else {
Twinkle.xfd.callbacks.addToLog(apiobj.params, null);
}
},
taggingPage: function(pageobj) {
var text = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
params.tagText = '{{' + (params.number === '' ? 'mfd' : 'mfdx|' + params.number) + '|help=off}}';
if (['javascript', 'css', 'sanitized-css'].indexOf(mw.config.get('wgPageContentModel')) !== -1) {
params.tagText = '/* ' + params.tagText + ' */\n';
} else {
params.tagText += '\n';
if (params.noinclude) {
params.tagText = '<noinclude>' + params.tagText + '</noinclude>';
}
}
if (pageobj.canEdit() && ['wikitext', 'javascript', 'css', 'sanitized-css'].indexOf(pageobj.getContentModel()) !== -1) {
pageobj.setPageText(params.tagText + text);
pageobj.setEditSummary('Nominated for deletion; see [[:' + params.discussionpage + ']]. ([[Help:Twinkle|Twinkle]]使用)');
pageobj.setWatchlist(Twinkle.getPref('xfdWatchPage'));
pageobj.setCreateOption('nocreate');
pageobj.save();
} else {
Twinkle.xfd.callbacks.autoEditRequest(pageobj, params);
}
},
discussionPage: function(pageobj) {
var params = pageobj.getCallbackParameters();
pageobj.setPageText(Twinkle.xfd.callbacks.getDiscussionWikitext('mfd', params));
pageobj.setEditSummary('Creating deletion discussion page for [[:' + Morebits.pageNameNorm + ']]. ([[Help:Twinkle|Twinkle]]使用)');
pageobj.setWatchlist(Twinkle.getPref('xfdWatchDiscussion'));
pageobj.setCreateOption('createonly');
pageobj.save(function() {
Twinkle.xfd.currentRationale = null;  // any errors from now on do not need to print the rationale, as it is safely saved on-wiki
});
},
todaysList: function(pageobj) {
var text = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
var statelem = pageobj.getStatusElement();
var date = new Morebits.date(pageobj.getLoadTime());
var date_header = date.format('===MMMM D, YYYY===\n', 'utc');
var date_header_regex = new RegExp(date.format('(===[\\s]*MMMM[\\s]+D,[\\s]+YYYY[\\s]*===)', 'utc'));
var added_data = '{{subst:mfd3|pg=' + Morebits.pageNameNorm + params.numbering + '}}';
if (date_header_regex.test(text)) { // we have a section already
statelem.info('Found today\'s section, proceeding to add new entry');
text = text.replace(date_header_regex, '$1\n' + added_data);
} else { // we need to create a new section
statelem.info('No section for today found, proceeding to create one');
text = text.replace('===', date_header + added_data + '\n\n===');
}
pageobj.setPageText(text);
pageobj.setEditSummary('Adding [[:' + params.discussionpage + ']]. ([[Help:Twinkle|Twinkle]]使用)');
pageobj.setWatchlist(Twinkle.getPref('xfdWatchList'));
pageobj.setCreateOption('recreate');
pageobj.save();
},
sendNotifications: function(pageobj) {
var initialContrib = pageobj.getCreator();
var params = pageobj.getCallbackParameters();
// Notify the creator
if (params.notifycreator) {
Twinkle.xfd.callbacks.notifyUser(params, initialContrib);
}
// Notify the user who owns the subpage if they are not the creator
params.userspaceOwner = mw.config.get('wgRelevantUserName');
if (params.notifyuserspace) {
if (params.userspaceOwner !== initialContrib) {
// Don't log if notifying creator above, will log then
Twinkle.xfd.callbacks.notifyUser(params, params.userspaceOwner, params.notifycreator, 'Notifying owner of userspace (' + params.userspaceOwner + ')');
} else if (!params.notifycreator) {
// If we thought we would notify the owner but didn't,
// then we need to log if we didn't notify the creator
// Twinkle.xfd.callbacks.addToLog(params, null);
Twinkle.xfd.callbacks.addToLog(params, initialContrib);
}
}
}
},
ffd: {
taggingImage: function(pageobj) {
var text = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
var date = new Morebits.date(pageobj.getLoadTime()).format('YYYY MMMM D', 'utc');
params.logpage = 'Wikipedia:Files for discussion/' + date;
params.discussionpage = params.logpage + '#' + Morebits.pageNameNorm;
params.tagText = '{{ffd|log=' + date + '|help=off}}\n';
if (pageobj.canEdit()) {
text = text.replace(/\{\{(mtc|(copy |move )?to ?commons|move to wikimedia commons|copy to wikimedia commons)[^}]*\}\}/gi, '');
pageobj.setPageText(params.tagText + text);
pageobj.setEditSummary('Listed for discussion at [[:' + params.discussionpage + ']]. ([[Help:Twinkle|Twinkle]]使用)');
pageobj.setWatchlist(Twinkle.getPref('xfdWatchPage'));
pageobj.setCreateOption('recreate');  // it might be possible for a file to exist without a description page
pageobj.save();
} else {
Twinkle.xfd.callbacks.autoEditRequest(pageobj, params);
}
// Updating data for the action completed event
Morebits.wiki.actionCompleted.redirect = params.logpage;
Morebits.wiki.actionCompleted.notice = 'Nomination completed, now redirecting to the discussion page';
// Contributor specific edits
var wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'));
wikipedia_page.setCallbackParameters(params);
wikipedia_page.lookupCreation(Twinkle.xfd.callbacks.ffd.main);
},
main: function(pageobj) {
// this is coming in from lookupCreation...!
var params = pageobj.getCallbackParameters();
var initialContrib = pageobj.getCreator();
params.uploader = initialContrib;
// Adding discussion
var wikipedia_page = new Morebits.wiki.page(params.logpage, "Adding discussion to today's list");
wikipedia_page.setFollowRedirect(true);
wikipedia_page.setCallbackParameters(params);
wikipedia_page.load(Twinkle.xfd.callbacks.ffd.todaysList);
// Notification to first contributor
if (params.notifycreator) {
Twinkle.xfd.callbacks.notifyUser(params, initialContrib);
// or, if not notifying, add this nomination to the user's userspace log without the initial contributor's name
} else {
Twinkle.xfd.callbacks.addToLog(params, null);
}
},
todaysList: function(pageobj) {
var text = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
// add date header if the log is found to be empty (a bot should do this automatically)
if (!pageobj.exists()) {
text = '{{subst:FfD log}}';
}
pageobj.setPageText(text + '\n\n' + Twinkle.xfd.callbacks.getDiscussionWikitext('ffd', params));
pageobj.setEditSummary('Adding [[:' + Morebits.pageNameNorm + ']]. ([[Help:Twinkle|Twinkle]]使用)');
pageobj.setWatchlist(Twinkle.getPref('xfdWatchDiscussion'));
pageobj.setCreateOption('recreate');
pageobj.save(function() {
Twinkle.xfd.currentRationale = null;  // any errors from now on do not need to print the rationale, as it is safely saved on-wiki
});
}
},
cfd: {
main: function(pageobj) {
var params = pageobj.getCallbackParameters();
var date = new Morebits.date(pageobj.getLoadTime());
params.logpage = 'Wikipedia:Categories for discussion/Log/' + date.format('YYYY MMMM D', 'utc');
params.discussionpage = params.logpage + '#' + Morebits.pageNameNorm;
// Add log/discussion page params to the already-loaded page object
pageobj.setCallbackParameters(params);
// Tagging category
Twinkle.xfd.callbacks.cfd.taggingCategory(pageobj);
// Updating data for the action completed event
Morebits.wiki.actionCompleted.redirect = params.logpage;
Morebits.wiki.actionCompleted.notice = "Nomination completed, now redirecting to today's log";
// Adding discussion to list
var wikipedia_page = new Morebits.wiki.page(params.logpage, "Adding discussion to today's list");
wikipedia_page.setFollowRedirect(true);
wikipedia_page.setCallbackParameters(params);
wikipedia_page.load(Twinkle.xfd.callbacks.cfd.todaysList);
// Notification to first contributor
if (params.notifycreator) {
wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'));
wikipedia_page.setCallbackParameters(params);
wikipedia_page.lookupCreation(function(pageobj) {
Twinkle.xfd.callbacks.notifyUser(pageobj.getCallbackParameters(), pageobj.getCreator());
});
// or, if not notifying, add this nomination to the user's userspace log without the initial contributor's name
} else {
Twinkle.xfd.callbacks.addToLog(params, null);
}
},
taggingCategory: function(pageobj) {
var text = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
params.tagText = '{{subst:' + params.xfdcat;
var editsummary = (mw.config.get('wgNamespaceNumber') === 14 ? 'Category' : 'Stub template') +
' being considered for ' + params.action;
switch (params.xfdcat) {
case 'cfd':
case 'sfd-t':
break;
case 'cfc':
editsummary += ' to an article';
// falls through
case 'cfm':
case 'cfr':
case 'sfr-t':
params.tagText += '|' + params.cfdtarget;
break;
case 'cfs':
params.tagText += '|' + params.cfdtarget + '|' + params.cfdtarget2;
break;
default:
alert('twinklexfd in taggingCategory(): unknown CFD action');
break;
}
params.tagText += '}}\n';
editsummary += '; see [[:' + params.discussionpage + ']].';
if (pageobj.canEdit()) {
pageobj.setPageText(params.tagText + text);
pageobj.setEditSummary(editsummary);
pageobj.setWatchlist(Twinkle.getPref('xfdWatchPage'));
pageobj.setCreateOption('recreate');  // since categories can be populated without an actual page at that title
pageobj.save();
} else {
Twinkle.xfd.callbacks.autoEditRequest(pageobj, params);
}
},
todaysList: function(pageobj) {
var params = pageobj.getCallbackParameters();
var statelem = pageobj.getStatusElement();
var added_data = Twinkle.xfd.callbacks.getDiscussionWikitext(params.xfdcat, params);
var text;
// add date header if the log is found to be empty (a bot should do this automatically)
if (!pageobj.exists()) {
text = '{{subst:CfD log}}\n' + added_data;
} else {
var old_text = pageobj.getPageText();
text = old_text.replace('below this line -->', 'below this line -->\n' + added_data);
if (text === old_text) {
statelem.error('failed to find target spot for the discussion');
return;
}
}
pageobj.setPageText(text);
pageobj.setEditSummary('Adding ' + params.action + ' nomination of [[:' + Morebits.pageNameNorm + ']]. ([[Help:Twinkle|Twinkle]]使用)');
pageobj.setWatchlist(Twinkle.getPref('xfdWatchDiscussion'));
pageobj.setCreateOption('recreate');
pageobj.save(function() {
Twinkle.xfd.currentRationale = null;  // any errors from now on do not need to print the rationale, as it is safely saved on-wiki
});
}
},
cfds: {
taggingCategory: function(pageobj) {
var text = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
params.tagText = '{{subst:cfr-speedy|1=' + params.cfdstarget.replace(/^:?Category:/, '') + '}}\n';
if (pageobj.canEdit()) {
pageobj.setPageText(params.tagText + text);
pageobj.setEditSummary('Listed for speedy renaming; see [[WP:CFDS|Categories for discussion/Speedy]]. ([[Help:Twinkle|Twinkle]]使用)');
pageobj.setWatchlist(Twinkle.getPref('xfdWatchPage'));
pageobj.setCreateOption('recreate');  // since categories can be populated without an actual page at that title
pageobj.save(function() {
// No user notification for CfDS, so just add this nomination to the user's userspace log
Twinkle.xfd.callbacks.addToLog(params, null);
});
} else {
Twinkle.xfd.callbacks.autoEditRequest(pageobj, params);
// No user notification for CfDS, so just add this nomination to the user's userspace log
Twinkle.xfd.callbacks.addToLog(params, null);
}
},
addToList: function(pageobj) {
var old_text = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
var statelem = pageobj.getStatusElement();
var text = old_text.replace('BELOW THIS LINE -->', 'BELOW THIS LINE -->\n' + Twinkle.xfd.callbacks.getDiscussionWikitext('cfds', params));
if (text === old_text) {
statelem.error('failed to find target spot for the discussion');
return;
}
pageobj.setPageText(text);
pageobj.setEditSummary('Adding [[:' + Morebits.pageNameNorm + ']]. ([[Help:Twinkle|Twinkle]]使用)');
pageobj.setWatchlist(Twinkle.getPref('xfdWatchDiscussion'));
pageobj.setCreateOption('recreate');
pageobj.save(function() {
Twinkle.xfd.currentRationale = null;  // any errors from now on do not need to print the rationale, as it is safely saved on-wiki
});
}
},


rfd: {
rfd: {
Line 1,988: Line 984:
wikipedia_api.params = params;
wikipedia_api.params = params;
wikipedia_api.post();
wikipedia_api.post();
break;
case 'tfd': // TFD
if (params.tfdtarget) { // remove namespace name
params.tfdtarget = utils.stripNs(params.tfdtarget);
}
// Modules can't be tagged, TfD instructions are to place on /doc subpage
params.scribunto = mw.config.get('wgPageContentModel') === 'Scribunto';
if (params.xfdcat === 'tfm') { // Merge
// Tag this template/module
if (params.scribunto) {
wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName') + '/doc', 'Tagging this module documentation with merge tag');
params.otherTemplateName = 'Module:' + params.tfdtarget;
} else {
wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'), 'Tagging this template with merge tag');
params.otherTemplateName = 'Template:' + params.tfdtarget;
}
} else { // delete
if (params.scribunto) {
wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName') + '/doc', 'Tagging module documentation with deletion tag');
} else {
wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'), 'Tagging template with deletion tag');
}
}
wikipedia_page.setFollowRedirect(true);  // should never be needed, but if the page is moved, we would want to follow the redirect
wikipedia_page.setCallbackParameters(params);
wikipedia_page.load(Twinkle.xfd.callbacks.tfd.main);
break;
case 'mfd': // MFD
query = {
action: 'query',
list: 'allpages',
apprefix: 'Miscellany for deletion/' + Morebits.pageNameNorm,
apnamespace: 4,
apfilterredir: 'nonredirects',
aplimit: 'max', // 500 is max for normal users, 5000 for bots and sysops
format: 'json'
};
wikipedia_api = new Morebits.wiki.api('Looking for prior nominations of this page', query, Twinkle.xfd.callbacks.mfd.main);
wikipedia_api.params = params;
wikipedia_api.post();
break;
case 'ffd': // FFD
// Tagging file
// A little out of order with this coming before 'main',
// but tagging doesn't need the uploader parameter,
// while everything else does, so tag then get the uploader
wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'), 'Adding deletion tag to file page');
wikipedia_page.setFollowRedirect(true);
wikipedia_page.setCallbackParameters(params);
wikipedia_page.load(Twinkle.xfd.callbacks.ffd.taggingImage);
break;
case 'cfd':
if (params.cfdtarget) {
params.cfdtarget = utils.stripNs(params.cfdtarget);
} else {
params.cfdtarget = ''; // delete
}
if (params.cfdtarget2) { // split
params.cfdtarget2 = utils.stripNs(params.cfdtarget2);
}
// Used for customized actions in edit summaries and the notification template
var summaryActions = {
'cfd': 'deletion',
'sfd-t': 'deletion',
'cfm': 'merging',
'cfr': 'renaming',
'sfr-t': 'renaming',
'cfs': 'splitting',
'cfc': 'conversion'
};
params.action = summaryActions[params.xfdcat];
// Tagging category
wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'), 'Tagging category with ' + params.action + ' tag');
wikipedia_page.setFollowRedirect(true); // should never be needed, but if the page is moved, we would want to follow the redirect
wikipedia_page.setCallbackParameters(params);
wikipedia_page.load(Twinkle.xfd.callbacks.cfd.main);
break;
case 'cfds':
// add namespace name if missing
params.cfdstarget = utils.addNs(params.cfdstarget, 14);
var logpage = 'Wikipedia:Categories for discussion/Speedy';
// Updating data for the action completed event
Morebits.wiki.actionCompleted.redirect = logpage;
Morebits.wiki.actionCompleted.notice = 'Nomination completed, now redirecting to the discussion page';
// Tagging category
wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'), 'Tagging category with rename tag');
wikipedia_page.setFollowRedirect(true);
wikipedia_page.setCallbackParameters(params);
wikipedia_page.load(Twinkle.xfd.callbacks.cfds.taggingCategory);
// Adding discussion to list
wikipedia_page = new Morebits.wiki.page(logpage, 'Adding discussion to the list');
wikipedia_page.setFollowRedirect(true);
wikipedia_page.setCallbackParameters(params);
wikipedia_page.load(Twinkle.xfd.callbacks.cfds.addToList);
break;
break;


284

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.