မီဒီယာဝီကီ:Gadget-twinklexfd.js
မှတ်ချက်။ လွှင့်တင်လိုက်ပြီးသည့်နောက် ပြောင်းလဲမှုများ မြင်ရနိုင်ရန် သင့်အနေဖြင့် ဘရောက်ဇာ၏ cache အား ဖြတ်ကျော်နိုင်ရန် လိုအပ်ပါသည်။
- Firefox / Safari: Reload ကို နှိပ်နေစဉ်အတွင်း Shift ကို ဖိထားပါ၊ သို့မဟုတ် Ctrl-F5 သို့ Ctrl-R (Mac တွင် ⌘-R) ကို နှိပ်ပါ။
- Google Chrome: Ctrl-Shift-R (Mac တွင် ⌘-Shift-R) ကို နှိပ်ပါ။
- Internet Explorer / Edge: Refresh ကို နှိပ်နေစဉ်အတွင်း Ctrl ကို ဖိထားပါ၊ သို့မဟုတ် Ctrl-F5 ကို နှိပ်ပါ။
- Opera: Menu → Settings (Mac တွင် Opera → Preferences) သို့ သွားပြီး Privacy & security → Clear browsing data → Cached images and files ကို ပြုလုပ်ပါ။
//<nowiki>
(function($){
/*
****************************************
*** twinklexfd.js: XFD module
****************************************
* Mode of invocation: Tab ("نبح")
* Active on: Existing, non-special pages, except for file pages with no local (non-Commons) file which are not redirects
* Config directives in: TwinkleConfig
*/
Twinkle.xfd = function twinklexfd() {
// Disable on:
// * special pages
// * non-existent pages
// * files on Commons, whether there is a local page or not (unneeded local pages of files on Commons are eligible for CSD F2)
// * file pages without actual files (these are eligible for CSD G8)
if ( mw.config.get('wgNamespaceNumber') < 0 || !mw.config.get('wgArticleId') || (mw.config.get('wgNamespaceNumber') === 6 && (document.getElementById('mw-sharedupload') || (!document.getElementById('mw-imagepage-section-filehistory') && !Morebits.wiki.isPageRedirect()))) ) {
return;
}
Twinkle.addPortletLink( Twinkle.xfd.callback, "نبح", "tw-xfd", "نظرخواهی برای حذف" );
};
Twinkle.xfd.num2order = function twinklexfdNum2order( num ) {
switch( num ) {
case 1: return '';
case 2: return 'دوم';
case 3: return 'سوم';
default: return num + 'ام';
}
};
Twinkle.xfd.currentRationale = null;
// error callback on Morebits.status.object
Twinkle.xfd.printRationale = function twinklexfdPrintRationale() {
if (Twinkle.xfd.currentRationale) {
Morebits.status.printUserText(Twinkle.xfd.currentRationale, "Your deletion rationale is provided below, which you can copy and paste into a new XFD dialog if you wish to try again:");
// only need to print the rationale once
Twinkle.xfd.currentRationale = null;
}
};
Twinkle.xfd.callback = function twinklexfdCallback() {
var Window = new Morebits.simpleWindow( 600, 350 );
Window.setTitle( "نامزد کردن برای حذف (فح)" );
Window.setScriptName( "توینکل" );
Window.addFooterLink( "دربارهٔ نظرخواهیهای حذف", "وپ:فح" );
Window.addFooterLink( "راهنمای توینکل", "WP:TW/DOC#xfd" );
var form = new Morebits.quickForm( Twinkle.xfd.callback.evaluate );
var categories = form.append( {
type: 'select',
name: 'category',
label: 'محل بحث در مورد حذف:',
tooltip: 'پس از فعال شدن، بر پایهٔ فضای نامی که در آن هستید، یک گزینهٔ پیشفرض انتخاب میشود. این پیشفرض باید مناسبترین باشد',
event: Twinkle.xfd.callback.change_category
} );
categories.append( {
type: 'option',
label: 'نظرخواهی حذف مقالهها',
selected: mw.config.get('wgNamespaceNumber') === 0, // Main namespace
value: 'afd'
} );
categories.append( {
type: 'option',
label: 'نظرخواهی حذف الگوها',
selected: mw.config.get('wgNamespaceNumber') === 10, // Template namespace
value: 'tfd'
} );
categories.append( {
type: 'option',
label: 'نظرخواهی حذف پروندهها/پروندههای احتمالاً ناآزاد',
selected: mw.config.get('wgNamespaceNumber') === 6, // File namespace
value: 'ffd'
} );
categories.append( {
type: 'option',
label: 'نظرخواهی حذف مقالهها',
selected: mw.config.get('wgNamespaceNumber') === 14, // Category namespace
value: 'cfd'
} );
categories.append( {
type: 'option',
label: 'نظرخواهی برای تغییر نام ردهها',
value: 'cfds'
} );
categories.append( {
type: 'option',
label: 'نظرخواهی حذف متفرقه',
selected: [ 0, 6, 10, 14 ].indexOf( mw.config.get('wgNamespaceNumber') ) === -1,
value: 'mfd'
} );
categories.append( {
type: 'option',
label: 'نظرخواهی حذف تغییرمسیرها',
selected: Morebits.wiki.isPageRedirect(),
value: 'rfd'
} );
form.append( {
type: 'checkbox',
list: [
{
label: 'درصورت امکان سازنده مقاله را نیز مطلع کن',
value: 'notify',
name: 'notify',
tooltip: "یک الگوی آگاهسازی در صفحهٔ بحث ایجادگر قرار خواهد گرفت اگر این گزینه فعال باشد.",
checked: true
}
]
}
);
form.append( {
type: 'field',
label:'محل کار',
name: 'work_area'
} );
form.append( { type:'submit' } );
var result = form.render();
Window.setContent( result );
Window.display();
// We must init the controls
var evt = document.createEvent( "Event" );
evt.initEvent( 'change', true, true );
result.category.dispatchEvent( evt );
};
Twinkle.xfd.previousNotify = true;
Twinkle.xfd.callback.change_category = function twinklexfdCallbackChangeCategory(e) {
var value = e.target.value;
var form = e.target.form;
var old_area = Morebits.quickForm.getElements(e.target.form, "work_area")[0];
var work_area = null;
var oldreasontextbox = form.getElementsByTagName('textarea')[0];
var oldreason = (oldreasontextbox ? oldreasontextbox.value : '');
var appendReasonBox = function twinklexfdAppendReasonBox() {
work_area.append( {
type: 'textarea',
name: 'xfdreason',
label: 'دلیل: ',
value: oldreason,
tooltip: 'میتوانید در دلیل خود از دستور زبان ویکی استفاده کنید. توینکل به صورت خودکار متن شما را امضا میکند.'
} );
// TODO possible future "preview" link here
};
switch( value ) {
case 'afd':
work_area = new Morebits.quickForm.element( {
type: 'field',
label: 'نظرخواهی برای حذف',
name: 'work_area'
} );
work_area.append( {
type: 'checkbox',
list: [
{
label: 'قراردادن برچسب حذف در میان <noinclude>',
value: 'noinclude',
name: 'noinclude',
tooltip: 'قرار دادن برچسب حذف در میان <noinclude> زیاد متداول نیست و برای جلوگیری از انتقال برچسب به صفحههای دیگر کاربرد دارد. '
}
]
} );
var afd_category = work_area.append( {
type:'select',
name:'xfdcat',
label:'مشخص کنید که این نامزد متعلق به کدام رده است:'
} );
afd_category.append( { type:'option', label:'نامعلوم', value:'?', selected:true } );
afd_category.append( { type:'option', label:'رسانه و موسیقی', value:'M' } );
afd_category.append( { type:'option', label:'شرکت، سازمان یا محصول', value:'O' } );
afd_category.append( { type:'option', label:'زندگینامهای', value:'B' } );
afd_category.append( { type:'option', label:'مسائل اجتماعی', value:'S' } );
afd_category.append( { type:'option', label:'وب یا اینترنت', value:'W' } );
afd_category.append( { type:'option', label:'بازیها یا ورزشها', value:'G' } );
afd_category.append( { type:'option', label:'علم و فناوری', value:'T' } );
afd_category.append( { type:'option', label:'داستان و هنر', value:'F' } );
afd_category.append( { type:'option', label:'مکانها و ترابری', value:'P' } );
afd_category.append( { type:'option', label:'موضوع تشخیصناپذیر یا غیرقابل طبقهبندی', value:'I' } );
afd_category.append( { type:'option', label:'بحثی که هنوز طبقهبندی نشده', value:'U' } );
appendReasonBox();
work_area = work_area.render();
old_area.parentNode.replaceChild( work_area, old_area );
break;
case 'tfd':
work_area = new Morebits.quickForm.element( {
type: 'field',
label: 'نظرخواهی حذف الگوها',
name: 'work_area'
} );
work_area.append( {
type: 'div',
label: 'الگوهای خرد و جعبههای کاربری در نظرخواهی حذف الگوها بررسی نمیشوند. الگوهای خرد به نظرخواهی حذف ردهها و جعبههای کاربری به نظرخواهی حذف متفرقه میروند.'
} );
var tfd_category = work_area.append( {
type: 'select',
label: 'عمل دلخواه را انتخاب کنید: ',
name: 'xfdcat',
event: function(e) {
var target = e.target;
// add/remove extra input box
if( target.value === 'tfm' && !target.form.xfdtarget ) { //$(target.parentNode).find("input[name='xfdtarget']").length === 0 ) {
var xfdtarget = new Morebits.quickForm.element( {
name: 'xfdtarget',
type: 'input',
label: 'الگوی دیگر برای ادغام: '
} );
target.parentNode.appendChild(xfdtarget.render());
} else {
$(Morebits.quickForm.getElementContainer(target.form.xfdtarget)).remove();
target.form.xfdtarget = null;
//$(target.parentNode).find("input[name='xfdtarget']").remove();
}
}
} );
tfd_category.append( { type: 'option', label: 'Deletion', value: 'tfd', selected: true } );
tfd_category.append( { type: 'option', label: 'Merge', value: 'tfm' } );
work_area.append( {
type: 'checkbox',
list: [
{
label: 'برچسب حذف درونخطی',
value: 'tfdinline',
name: 'tfdinline',
tooltip: 'Use {{tfd|type=inline}} to tag the page instead of {{tfd}}. Good for inline templates (those that appear amongst the words of text).',
checked: false
},
{
label: 'برچسب حذف را در <noinclude> بپیچان (تنها برای الگوهای جاینشینشونده)',
value: 'noinclude',
name: 'noinclude',
tooltip: 'Will wrap the deletion tag in <noinclude> tags, so that it won\'t get substituted along with the template.'
}
]
} );
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: 'متفرقه برای حذف',
name: 'work_area'
} );
work_area.append( {
type: 'checkbox',
list: [
{
label: 'قراردادن برچسب حذف در میان <noinclude>',
value: 'noinclude',
name: 'noinclude',
tooltip: 'Will wrap the deletion tag in <noinclude> 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: */) {
work_area.append( {
type: 'checkbox',
list: [
{
label: 'همچنین اگر مالک فضای نام سازندهٔ این صفحه نیست، او را نیز مطلع کن',
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'
} );
work_area.append( {
type: 'radio',
name: 'ffdvenue',
event: Twinkle.xfd.callback.ffdvenue_change,
list: [
{
label: 'نظرخواهی حذف پرونده',
value: 'ffd',
tooltip: 'General deletion discussion',
checked: mw.config.get('wgNamespaceNumber') === 6
},
{
label: 'پرونده احتمالاً غیر آزاد',
value: 'puf',
tooltip: 'File has disputed source or licensing information'
},
{
label: 'Non-free content review',
value: 'nfcr',
tooltip: 'File\'s compliance with non-free content criteria ([[WP:NFCC]]) is disputed. User notification does not occur for NFCR, as it is not deemed relevant.',
checked: mw.config.get('wgNamespaceNumber') !== 6
}
]
} );
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: 'نظرخواهی حذف رده',
name: 'work_area'
} );
var cfd_category = work_area.append( {
type: 'select',
label: 'عمل دلخواه را انتخاب کنید: ',
name: 'xfdcat',
event: function(e) {
var value = e.target.value;
var target = e.target.form.xfdtarget;
// update enabled status
if( value === 'cfd' ) {
target.disabled = true;
} else {
target.disabled = false;
}
// update label
if( value === 'cfs' ) {
target.previousSibling.textContent = "رده هدف: ";
} else if( value === 'cfc' ) {
target.previousSibling.textContent = "مقاله هدف: ";
} else {
target.previousSibling.textContent = "رده هدف: ";
}
// add/remove extra input box
if( value === 'cfs' && $(target.parentNode).find("input[name='xfdtarget2']").length === 0 ) {
var xfdtarget2 = document.createElement("input");
xfdtarget2.setAttribute("name", "xfdtarget2");
xfdtarget2.setAttribute("type", "text");
target.parentNode.appendChild(xfdtarget2);
} else {
$(target.parentNode).find("input[name='xfdtarget2']").remove();
}
}
} );
cfd_category.append( { type: 'option', label: 'حذف', value: 'cfd', selected: true } );
cfd_category.append( { type: 'option', label: 'ادغام', value: 'cfm' } );
cfd_category.append( { type: 'option', label: 'تغییر نام', value: 'cfr' } );
cfd_category.append( { type: 'option', label: 'تفکیک', value: 'cfs' } );
cfd_category.append( { type: 'option', label: 'تبدیل به مقاله', value: 'cfc' } );
work_area.append( {
type: 'input',
name: 'xfdtarget',
label: 'صفحه هدف: ',
disabled: true,
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: 'نظرخواهی تغییر نام رده',
name: 'work_area'
} );
var cfds_category = work_area.append( {
type: 'select',
label: 'زیر معیار ر۲: ',
name: 'xfdcat',
tooltip: 'See WP:CFDS for full explanations.',
event: function(e) {
var value = e.target.value;
var target = e.target.form.xfdtarget;
if( value === 'cfd' ) {
target.disabled = true;
} else {
target.disabled = false;
}
}
} );
cfds_category.append( { type: 'option', label: 'C2A: Typographic and spelling fixes', value: 'C2A', selected: true } );
cfds_category.append( { type: 'option', label: 'C2B: Naming conventions and disambiguation', value: 'C2B' } );
cfds_category.append( { type: 'option', label: 'C2C: Consistency with names of similar categories', value: 'C2C' } );
cfds_category.append( { type: 'option', label: 'C2D: Rename to match article name', value: 'C2D' } );
cfds_category.append( { type: 'option', label: 'C2E: Author request', value: 'C2E' } );
work_area.append( {
type: 'input',
name: 'xfdtarget',
label: 'نام جدید: ',
value: ''
} );
appendReasonBox();
work_area = work_area.render();
old_area.parentNode.replaceChild( work_area, old_area );
break;
case 'rfd':
work_area = new Morebits.quickForm.element( {
type: 'field',
label: 'Redirects for discussion',
name: 'work_area'
} );
appendReasonBox();
work_area = work_area.render();
old_area.parentNode.replaceChild( work_area, old_area );
break;
default:
work_area = new Morebits.quickForm.element( {
type: 'field',
label: 'هیچچیز برای هرچیز',
name: 'work_area'
} );
work_area = work_area.render();
old_area.parentNode.replaceChild( work_area, old_area );
break;
}
// No creator notification for CFDS
if (value === "cfds") {
Twinkle.xfd.previousNotify = form.notify.checked;
form.notify.checked = false;
form.notify.disabled = true;
} else {
form.notify.checked = Twinkle.xfd.previousNotify;
form.notify.disabled = false;
}
};
Twinkle.xfd.callback.ffdvenue_change = function twinklexfdCallbackFfdvenueChange(e) {
if (e.target.values === "nfcr") {
e.target.form.notify.disabled = true;
e.target.form.notify.checked = false;
} else {
e.target.form.notify.disabled = false;
e.target.form.notify.checked = true;
}
};
Twinkle.xfd.callbacks = {
afd: {
main: function(apiobj) {
var xmlDoc = apiobj.responseXML;
var titles = $(xmlDoc).find('allpages p');
// 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].getAttribute('title');
// First, simple test, is there an instance with this exact name?
if( title === 'ویکیپدیا:نظرخواهی برای حذف/' + Morebits.pageNameNorm ) {
number = Math.max( number, 1 );
continue;
}
var order_re = new RegExp( '^' +
window.RegExp.escape( 'ویکیپدیا:نظرخواهی برای حذف/' + Morebits.pageNameNorm, true ) +
'\\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 = Twinkle.xfd.num2order( parseInt( number, 10 ) + 1);
apiobj.params.numbering = number > 0 ? ' (' + apiobj.params.number + ')' : '';
}
apiobj.params.discussionpage = 'ویکیپدیا:نظرخواهی برای حذف/' + Morebits.pageNameNorm + apiobj.params.numbering;
Morebits.status.info( "Next discussion page", "[[" + apiobj.params.discussionpage + "]]" );
// Updating data for the action completed event
Morebits.wiki.actionCompleted.redirect = apiobj.params.discussionpage;
Morebits.wiki.actionCompleted.notice = "نامزد کردن کامل شد، در حال انتقال به صفحه نظرخواهی";
// Tagging article
var wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'), "افزودن برچسب حذف به مقاله");
wikipedia_page.setFollowRedirect(true); // should never be needed, but if the article is moved, we would want to follow the redirect
wikipedia_page.setCallbackParameters(apiobj.params);
wikipedia_page.load(Twinkle.xfd.callbacks.afd.taggingArticle);
},
// Tagging needs to happen before everything else: this means we can check if there is an AfD tag already on the page
taggingArticle: function(pageobj) {
var text = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
var statelem = pageobj.getStatusElement();
if (!pageobj.exists()) {
statelem.error("به نظر میرسد که این صفحه قبلاً حذف شده است.");
return;
}
// Check for existing AfD tag, for the benefit of new page patrollers
var textNoAfd = text.replace(/\{\{\s*(Article for deletion\/dated|پیشنهاد حذف|AfDM)\s*(\|(?:\{\{[^{}]*\}\}|[^{}])*)?\}\}\s*/g, "");
if (text !== textNoAfd) {
if (confirm("مقاله دارای برچسب حذف سریع است آیا قصد جایگزینی آن با نظرخواهی برای حذف دارید؟. \nبا زدن دکمه تائید برچسب نظرخواهی برای حذف جایگزین میگردد.")) {
text = textNoAfd;
} else {
statelem.error("مقاله برای نظرخواهی حذف پیشنهاد شدهاست درخواست شما لغو شد.");
window.location.reload();
return;
}
}
// Now we know we want to go ahead with it, trigger the other AJAX requests
// Starting discussion page
var wikipedia_page = new Morebits.wiki.page(params.discussionpage, "ایجاد صفحه نظرخواهی حذف مقاله");
wikipedia_page.setCallbackParameters(params);
wikipedia_page.load(Twinkle.xfd.callbacks.afd.discussionPage);
// Today's list
var date = new Date();
wikipedia_page = new Morebits.wiki.page('ویکیپدیا:نظرخواهی برای حذف', "افزودن نظرخواهی به فهرست نظرخواهیها");
wikipedia_page.setFollowRedirect(true);
wikipedia_page.setCallbackParameters(params);
wikipedia_page.load(Twinkle.xfd.callbacks.afd.todaysList);
// Notification to first contributor
if (params.usertalk) {
var thispage = new Morebits.wiki.page(mw.config.get('wgPageName'));
thispage.setCallbackParameters(params);
thispage.lookupCreator(Twinkle.xfd.callbacks.afd.userNotification);
}
// Remove some tags that should always be removed on AfD.
text = text.replace(/\{\{\s*(dated prod|dated prod blp|Prod blp\/dated|حذف زماندار|حذف زمان\u200cدار|حذف سریع|حذف زماندار|Proposed deletion\/dated|prod2|Proposed deletion endorsed|New unreviewed article|Unreviewed|Userspace draft)\s*(\|(?:\{\{[^{}]*\}\}|[^{}])*)?\}\}\s*/ig, "");
// Then, test if there are speedy deletion-related templates on the article.
var textNoSd = text.replace(/\{\{\s*(db(-\w*)?|delete|حذف زماندار|حذف زمان\u200cدار|حذف سریع|حذف زماندار|(?:hang|hold)[\- ]?on)\s*(\|(?:\{\{[^{}]*\}\}|[^{}])*)?\}\}\s*/ig, "");
if (text !== textNoSd && confirm("برچسب حذف زماندار در مقاله یافت شدهاست آیا باید این برچسب جایگزین شود؟")) {
text = textNoSd;
}
pageobj.setPageText((params.noinclude ? "<noinclude>{{" : "{{") + (params.number === '' ? "subst:afd|help=off" : ('subst:afdx|' +
params.number + "|help=off")) + (params.noinclude ? "}}</noinclude>\n" : "}}\n") + text);
pageobj.setEditSummary("برای حذف نامزد شد؛ بنگرید به [[" + params.discussionpage + "]]." + Twinkle.getPref('summaryAd'));
switch (Twinkle.getPref('xfdWatchPage')) {
case 'yes':
pageobj.setWatchlist(true);
break;
case 'no':
pageobj.setWatchlistFromPreferences(false);
break;
default:
pageobj.setWatchlistFromPreferences(true);
break;
}
pageobj.setCreateOption('nocreate');
pageobj.save();
},
discussionPage: function(pageobj) {
var params = pageobj.getCallbackParameters();
pageobj.setPageText("{{subst:afd2|text=" + Morebits.string.formatReasonText(params.reason) +
" ~~~~|pg=" + Morebits.pageNameNorm + "|cat=" + params.xfdcat + "}}\n");
pageobj.setEditSummary("ساخت صفحهٔ نظرخواهی حذف برای [[" + Morebits.pageNameNorm + "]]." + Twinkle.getPref('summaryAd'));
switch (Twinkle.getPref('xfdWatchDiscussion')) {
case 'yes':
pageobj.setWatchlist(true);
break;
case 'no':
pageobj.setWatchlistFromPreferences(false);
break;
default:
pageobj.setWatchlistFromPreferences(true);
break;
}
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 old_text = pageobj.getPageText() + "\n"; // MW strips trailing blanks, but we like them, so we add a fake one
var params = pageobj.getCallbackParameters();
var statelem = pageobj.getStatusElement();
var text = old_text.replace(/\n*(<\!-- توینکل -->)\n*/, "\n{{subst:afd3|pg=" + Morebits.pageNameNorm + params.numbering + "}}\n" + "$1");
if( text === old_text ) {
var linknode = document.createElement('a');
linknode.setAttribute("href", mw.util.getUrl("Wikipedia:Twinkle/Fixing AFD") + "?action=purge" );
linknode.appendChild(document.createTextNode('How to fix AFD'));
statelem.error( [ 'Could not find the target spot for the discussion. To fix this problem, please see ', linknode, '.' ] );
return;
}
pageobj.setPageText(text);
pageobj.setEditSummary("افزودن [[" + params.discussionpage + "]]." + Twinkle.getPref('summaryAd'));
switch (Twinkle.getPref('xfdWatchList')) {
case 'yes':
pageobj.setWatchlist(true);
break;
case 'no':
pageobj.setWatchlistFromPreferences(false);
break;
default:
pageobj.setWatchlistFromPreferences(true);
break;
}
pageobj.setCreateOption('recreate');
pageobj.save();
},
userNotification: function(pageobj) {
var params = pageobj.getCallbackParameters();
var initialContrib = pageobj.getCreator();
// Disallow warning yourself
if (initialContrib === mw.config.get('wgUserName')) {
pageobj.getStatusElement().warn("You (" + initialContrib + ") created this page; skipping user notification");
return;
}
var usertalkpage = new Morebits.wiki.page('User talk:' + initialContrib, "آگاهسازی نخستین مشارکت کننده (" + initialContrib + ")");
var notifytext = "\n{{subst:AFDWarning|1=" + Morebits.pageNameNorm + ( params.numbering !== '' ? '|order= ' + params.numbering : '' ) + "}} ~~~~";
usertalkpage.setAppendText(notifytext);
usertalkpage.setEditSummary("آگاهسازی: فهرستشدن در [[وپ:نبح|نظرخواهی برای حذف]]؛ مقاله: [[" + Morebits.pageNameNorm + "]]." + Twinkle.getPref('summaryAd'));
usertalkpage.setCreateOption('recreate');
switch (Twinkle.getPref('xfdWatchUser')) {
case 'yes':
usertalkpage.setWatchlist(true);
break;
case 'no':
usertalkpage.setWatchlistFromPreferences(false);
break;
default:
usertalkpage.setWatchlistFromPreferences(true);
break;
}
usertalkpage.setFollowRedirect(true);
usertalkpage.append();
}
},
tfd: {
taggingTemplate: function(pageobj) {
var text = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
pageobj.setPageText((params.noinclude ? "<noinclude>" : "") + "{{subst:template for discussion|help=off|" +
(params.tfdinline ? "type=inline|" : "") + mw.config.get('wgTitle') + (params.noinclude ? "}}</noinclude>" : "}}\n") + text);
pageobj.setEditSummary("برای حذف نامزد شد؛ بنگرید به [[" + params.logpage + "#" + Morebits.pageNameNorm + "]]." + Twinkle.getPref('summaryAd'));
switch (Twinkle.getPref('xfdWatchPage')) {
case 'yes':
pageobj.setWatchlist(true);
break;
case 'no':
pageobj.setWatchlistFromPreferences(false);
break;
default:
pageobj.setWatchlistFromPreferences(true);
break;
}
pageobj.setCreateOption('nocreate');
pageobj.save();
},
taggingTemplateForMerge: function(pageobj) {
var text = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
pageobj.setPageText((params.noinclude ? "<noinclude>" : "") + "{{subst:tfm|help=off|" +
(params.tfdinline ? "type=inline|1=" : "1=") + params.otherTemplateName.replace(/^Template:/, "") +
(params.noinclude ? "}}</noinclude>" : "}}\n") + text);
pageobj.setEditSummary("نامزدی برای حذفِ [[" + params.otherTemplateName + "]]؛ بنگرید به [[" +
params.logpage + "#" + Morebits.pageNameNorm + "]]." + Twinkle.getPref('summaryAd'));
switch (Twinkle.getPref('xfdWatchPage')) {
case 'yes':
pageobj.setWatchlist(true);
break;
case 'no':
pageobj.setWatchlistFromPreferences(false);
break;
default:
pageobj.setWatchlistFromPreferences(true);
break;
}
pageobj.setCreateOption('nocreate');
pageobj.save();
},
todaysList: function(pageobj) {
var old_text = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
var statelem = pageobj.getStatusElement();
var added_data = "";
switch( params.xfdcat ) {
case 'tfd':
added_data = "{{subst:tfd2|text=" + Morebits.string.formatReasonText(params.reason) +
" ~~~~|1=" + mw.config.get('wgTitle') + "}}";
break;
case 'tfm':
added_data = "{{subst:tfm2|text=" + Morebits.string.formatReasonText(params.reason) +
" ~~~~|1=" + mw.config.get('wgTitle') + "|2=" + params.target + "}}";
break;
default:
alert("twinklexfd in todaysList: unknown TFD action");
break;
}
var 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("افزودن [[الگو:" + mw.config.get('wgTitle') + "]]." + Twinkle.getPref('summaryAd'));
switch (Twinkle.getPref('xfdWatchDiscussion')) {
case 'yes':
pageobj.setWatchlist(true);
break;
case 'no':
pageobj.setWatchlistFromPreferences(false);
break;
default:
pageobj.setWatchlistFromPreferences(true);
break;
}
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
});
},
userNotification: function(pageobj) {
var initialContrib = pageobj.getCreator();
var params = pageobj.getCallbackParameters();
// Disallow warning yourself
if (initialContrib === mw.config.get('wgUserName')) {
pageobj.getStatusElement().warn("You (" + initialContrib + ") created this page; skipping user notification");
return;
}
var usertalkpage = new Morebits.wiki.page('User talk:' + initialContrib, "آگاهسازی نخستین مشارکت کننده (" + initialContrib + ")");
var notifytext = "\n";
switch (params.xfdcat) {
case 'tfd':
notifytext += "{{subst:tfdnotice|1=" + mw.config.get('wgTitle') + "}} ~~~~";
break;
case 'tfm':
notifytext += "{{subst:tfmnotice|1=" + mw.config.get('wgTitle') + "|2=" + params.target + "}} ~~~~";
break;
default:
alert("twinklexfd in userNotification: unknown TFD action");
break;
}
usertalkpage.setAppendText(notifytext);
usertalkpage.setEditSummary("آگاهسازی: نامزدی در [[وپ:نبح|نظرخواهی برای حذف الگوها]] برای [[" + pageobj.getPageName() + "]]." + Twinkle.getPref('summaryAd'));
usertalkpage.setCreateOption('recreate');
switch (Twinkle.getPref('xfdWatchUser')) {
case 'yes':
usertalkpage.setWatchlist(true);
break;
case 'no':
usertalkpage.setWatchlistFromPreferences(false);
break;
default:
usertalkpage.setWatchlistFromPreferences(true);
break;
}
usertalkpage.setFollowRedirect(true);
usertalkpage.append();
}
},
mfd: {
main: function(apiobj) {
var xmlDoc = apiobj.responseXML;
var titles = $(xmlDoc).find('allpages p');
// 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].getAttribute('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( '^' +
window.RegExp.escape( 'Wikipedia:Miscellany for deletion/' + Morebits.pageNameNorm, true ) +
'\\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 = Twinkle.xfd.num2order( parseInt( number, 10 ) + 1);
apiobj.params.numbering = number > 0 ? ' (' + apiobj.params.number + ')' : '';
}
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 = "نامزد کردن کامل شد، در حال انتقال به صفحه بحث";
// Discussion page
wikipedia_page = new Morebits.wiki.page(apiobj.params.discussionpage, "ایجاد صفحه نظرخواهی حذف");
wikipedia_page.setCallbackParameters(apiobj.params);
wikipedia_page.load(Twinkle.xfd.callbacks.mfd.discussionPage);
// Today's list
wikipedia_page = new Morebits.wiki.page("ویکیپدیا:نظرخواهی برای حذف", "افزودن نظرخواهی به فهرست نظرخواهیها");
//wikipedia_page.setPageSection(2);
// pageSection has been disabled - the API seems to throw up with nonexistent edit conflicts
// it can be turned on again once the problem is fixed, to save bandwidth
//wikipedia_page.setFollowRedirect(true);
wikipedia_page.setCallbackParameters(apiobj.params);
wikipedia_page.load(Twinkle.xfd.callbacks.mfd.todaysList);
// Notification to first contributor, and notification to owner of userspace (if applicable and required)
if (apiobj.params.usertalk) {
var thispage = new Morebits.wiki.page(mw.config.get('wgPageName'));
thispage.setCallbackParameters(apiobj.params);
thispage.lookupCreator(Twinkle.xfd.callbacks.mfd.userNotification);
}
},
taggingPage: function(pageobj) {
var text = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
pageobj.setPageText((params.noinclude ? "<noinclude>" : "") + "{{" + ((params.number === '') ? "mfd}}\n" : ('mfdx|' + params.number + "}}\n")) +
(params.noinclude ? "</noinclude>" : "") + text);
pageobj.setEditSummary("برای حذف نامزد شد؛ بنگرید به [[" + params.discussionpage + "]]." + Twinkle.getPref('summaryAd'));
switch (Twinkle.getPref('xfdWatchPage')) {
case 'yes':
pageobj.setWatchlist(true);
break;
case 'no':
pageobj.setWatchlistFromPreferences(false);
break;
default:
pageobj.setWatchlistFromPreferences(true);
break;
}
pageobj.setCreateOption('nocreate');
pageobj.save();
},
discussionPage: function(pageobj) {
var params = pageobj.getCallbackParameters();
pageobj.setPageText("{{subst:mfd2|text=" + Morebits.string.formatReasonText(params.reason) +
" ~~~~|pg=" + Morebits.pageNameNorm + "}}\n");
pageobj.setEditSummary("ساخت صفحهٔ نظرخواهی حذف برای [[" + Morebits.pageNameNorm + "]]." + Twinkle.getPref('summaryAd'));
switch (Twinkle.getPref('xfdWatchDiscussion')) {
case 'yes':
pageobj.setWatchlist(true);
break;
case 'no':
pageobj.setWatchlistFromPreferences(false);
break;
default:
pageobj.setWatchlistFromPreferences(true);
break;
}
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 Date();
var date_header = "===" + date.getUTCMonthName() + ' ' + date.getUTCDate() + ', ' + date.getUTCFullYear() + "===\n";
var date_header_regex = new RegExp( "(===\\s*" + date.getUTCMonthName() + '\\s+' + date.getUTCDate() + ',\\s+' + date.getUTCFullYear() + "\\s*===)" );
var new_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" + new_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 + new_data + "\n\n===");
}
pageobj.setPageText(text);
pageobj.setEditSummary("افزودن [[" + params.discussionpage + "]]." + Twinkle.getPref('summaryAd'));
switch (Twinkle.getPref('xfdWatchList')) {
case 'yes':
pageobj.setWatchlist(true);
break;
case 'no':
pageobj.setWatchlistFromPreferences(false);
break;
default:
pageobj.setWatchlistFromPreferences(true);
break;
}
pageobj.setCreateOption('recreate');
pageobj.save();
},
userNotification: function(pageobj) {
var initialContrib = pageobj.getCreator();
var params = pageobj.getCallbackParameters();
// Disallow warning yourself
if (initialContrib === mw.config.get('wgUserName')) {
pageobj.getStatusElement().warn("You (" + initialContrib + ") created this page; skipping user notification");
} else {
// Really notify the creator
Twinkle.xfd.callbacks.mfd.userNotificationMain(params, initialContrib, "آگاهسازی نخستین مشارکت کننده");
}
// Also notify the user who owns the subpage if they are not the creator
if (params.notifyuserspace) {
var userspaceOwner = ((mw.config.get('wgTitle').indexOf('/') === -1) ? mw.config.get('wgTitle') : mw.config.get('wgTitle').substring(0, mw.config.get('wgTitle').indexOf('/')));
if (userspaceOwner !== initialContrib) {
Twinkle.xfd.callbacks.mfd.userNotificationMain(params, userspaceOwner, "آگاهسازی صاحب فضای کاربری");
}
}
},
userNotificationMain: function(params, initialContrib, actionName)
{
var usertalkpage = new Morebits.wiki.page('User talk:' + initialContrib, actionName + " (" + initialContrib + ")");
var notifytext = "\n{{subst:MFDWarning|1=" + Morebits.pageNameNorm + ( params.numbering !== '' ? '|order= ' + params.numbering : '' ) + "}} ~~~~";
usertalkpage.setAppendText(notifytext);
usertalkpage.setEditSummary("آگاهسازی: فهرستشدن در نظرخواهی حذف؛ صفحه: [[" + Morebits.pageNameNorm + "]]." + Twinkle.getPref('summaryAd'));
usertalkpage.setCreateOption('recreate');
switch (Twinkle.getPref('xfdWatchUser')) {
case 'yes':
usertalkpage.setWatchlist(true);
break;
case 'no':
usertalkpage.setWatchlistFromPreferences(false);
break;
default:
usertalkpage.setWatchlistFromPreferences(true);
break;
}
usertalkpage.setFollowRedirect(true);
usertalkpage.append();
}
},
ffd: {
main: function(pageobj) {
// this is coming in from lookupCreator...!
var params = pageobj.getCallbackParameters();
var initialContrib = pageobj.getCreator();
params.uploader = initialContrib;
// Adding discussion
var wikipedia_page = new Morebits.wiki.page(params.logpage, "افزودن نظرخواهی به فهرست نظرخواهیها");
wikipedia_page.setFollowRedirect(true);
wikipedia_page.setCallbackParameters(params);
wikipedia_page.load(Twinkle.xfd.callbacks.ffd.todaysList);
// Notification to first contributor
if (params.usertalk) {
// Disallow warning yourself
if (initialContrib === mw.config.get('wgUserName')) {
pageobj.getStatusElement().warn("You (" + initialContrib + ") created this page; skipping user notification");
} else {
var usertalkpage = new Morebits.wiki.page('User talk:' + initialContrib, "Notifying initial contributor (" + initialContrib + ")");
var notifytext = "\n{{subst:idw|1=" + mw.config.get('wgTitle') + "}}";
usertalkpage.setAppendText(notifytext);
usertalkpage.setEditSummary("آگاهسازی: فهرستشدن در نظرخواهی برای حذف؛ صفحه: [[" + Morebits.pageNameNorm + "]]." + Twinkle.getPref('summaryAd'));
usertalkpage.setCreateOption('recreate');
switch (Twinkle.getPref('xfdWatchUser')) {
case 'yes':
usertalkpage.setWatchlist(true);
break;
case 'no':
usertalkpage.setWatchlistFromPreferences(false);
break;
default:
usertalkpage.setWatchlistFromPreferences(true);
break;
}
usertalkpage.setFollowRedirect(true);
usertalkpage.append();
}
}
},
taggingImage: function(pageobj) {
var text = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
text = text.replace(/\{\{(mtc|(copy |move )?to ?commons|move to wikimedia commons|copy to wikimedia commons)[^}]*\}\}/gi, "");
pageobj.setPageText("{{ffd|log=" + params.date + "}}\n" + text);
pageobj.setEditSummary("برای حذف نامزد شد؛ بنگرید به [[" + params.logpage + "#" + Morebits.pageNameNorm + "]]." + Twinkle.getPref('summaryAd'));
switch (Twinkle.getPref('xfdWatchPage')) {
case 'yes':
pageobj.setWatchlist(true);
break;
case 'no':
pageobj.setWatchlistFromPreferences(false);
break;
default:
pageobj.setWatchlistFromPreferences(true);
break;
}
pageobj.setCreateOption('recreate'); // it might be possible for a file to exist without a description page
pageobj.save();
},
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, but it sometimes breaks down)
if (!pageobj.exists()) {
text = "{{subst:Ffd log}}";
}
pageobj.setPageText(text + "\n{{subst:ffd2|Reason=" + Morebits.string.formatReasonText(params.reason) +
"|Uploader=" + params.uploader + "|1=" + mw.config.get('wgTitle') + "}} ~~~~");
pageobj.setEditSummary("افزودن [[" + Morebits.pageNameNorm + "]]." + Twinkle.getPref('summaryAd'));
switch (Twinkle.getPref('xfdWatchDiscussion')) {
case 'yes':
pageobj.setWatchlist(true);
break;
case 'no':
pageobj.setWatchlistFromPreferences(false);
break;
default:
pageobj.setWatchlistFromPreferences(true);
break;
}
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
});
}
},
puf: {
taggingImage: function(pageobj) {
var text = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
text = text.replace(/\{\{(mtc|(copy |move )?to ?commons|move to wikimedia commons|copy to wikimedia commons)[^}]*\}\}/gi, "");
pageobj.setPageText("{{puf|help=off|log=" + params.date + "}}\n" + text);
pageobj.setEditSummary("فهرست شد در [[وپ:نبح|پروندههای احتمالاً ناآزاد]]: [[" + params.logpage + "#" + Morebits.pageNameNorm + "]]." + Twinkle.getPref('summaryAd'));
switch (Twinkle.getPref('xfdWatchPage')) {
case 'yes':
pageobj.setWatchlist(true);
break;
case 'no':
pageobj.setWatchlistFromPreferences(false);
break;
default:
pageobj.setWatchlistFromPreferences(true);
break;
}
pageobj.setCreateOption('recreate'); // it might be possible for a file to exist without a description page
pageobj.save();
},
todaysList: function(pageobj) {
var text = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
pageobj.setPageText(text + "\n{{subst:puf2|reason=" + Morebits.string.formatReasonText(params.reason) +
"|image=" + mw.config.get('wgTitle') + "}} ~~~~");
pageobj.setEditSummary("افزودن [[" + Morebits.pageNameNorm + "]]." + Twinkle.getPref('summaryAd'));
switch (Twinkle.getPref('xfdWatchDiscussion')) {
case 'yes':
pageobj.setWatchlist(true);
break;
case 'no':
pageobj.setWatchlistFromPreferences(false);
break;
default:
pageobj.setWatchlistFromPreferences(true);
break;
}
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
});
},
userNotification: function(pageobj) {
var initialContrib = pageobj.getCreator();
// Disallow warning yourself
if (initialContrib === mw.config.get('wgUserName')) {
pageobj.getStatusElement().warn("You (" + initialContrib + ") created this page; skipping user notification");
return;
}
var usertalkpage = new Morebits.wiki.page('User talk:' + initialContrib, "Notifying initial contributor (" + initialContrib + ")");
var notifytext = "\n{{subst:idw-puf|1=" + mw.config.get('wgTitle') + "}} ~~~~";
usertalkpage.setAppendText(notifytext);
usertalkpage.setEditSummary("Notification: listing at [[WP:PUF|possibly unfree files]] of [[" + Morebits.pageNameNorm + "]]." + Twinkle.getPref('summaryAd'));
usertalkpage.setCreateOption('recreate');
switch (Twinkle.getPref('xfdWatchUser')) {
case 'yes':
usertalkpage.setWatchlist(true);
break;
case 'no':
usertalkpage.setWatchlistFromPreferences(false);
break;
default:
usertalkpage.setWatchlistFromPreferences(true);
break;
}
usertalkpage.setFollowRedirect(true);
usertalkpage.append();
}
},
// NOTE: NFCR doesn't have any callbacks here, everything happens in callback.evaluate
cfd: {
taggingCategory: function(pageobj) {
var text = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
var added_data = "";
var editsummary = "";
switch( params.xfdcat ) {
case 'cfd':
added_data = "{{subst:cfd}}";
editsummary = "Category being considered for deletion; see [[" + params.logpage + "#" + Morebits.pageNameNorm + "]].";
break;
case 'cfm':
added_data = "{{subst:cfm|" + params.target + "}}";
editsummary = "Category being considered for merging; see [[" + params.logpage + "#" + Morebits.pageNameNorm + "]].";
break;
case 'cfr':
added_data = "{{subst:cfr|" + params.target + "}}";
editsummary = "Category being considered for renaming; see [[" + params.logpage + "#" + Morebits.pageNameNorm + "]].";
break;
case 'cfs':
added_data = "{{subst:cfs|" + params.target + "|" + params.target2 + "}}";
editsummary = "Category being considered for splitting; see [[" + params.logpage + "#" + Morebits.pageNameNorm + "]].";
break;
case 'cfc':
added_data = "{{subst:cfc|" + params.target + "}}";
editsummary = "Category being considered for conversion to an article; see [[" + params.logpage + "#" + Morebits.pageNameNorm + "]].";
break;
default:
alert("twinklexfd in taggingCategory(): unknown CFD action");
break;
}
pageobj.setPageText(added_data + "\n" + text);
pageobj.setEditSummary(editsummary + Twinkle.getPref('summaryAd'));
switch (Twinkle.getPref('xfdWatchPage')) {
case 'yes':
pageobj.setWatchlist(true);
break;
case 'no':
pageobj.setWatchlistFromPreferences(false);
break;
default:
pageobj.setWatchlistFromPreferences(true);
break;
}
pageobj.setCreateOption('recreate'); // since categories can be populated without an actual page at that title
pageobj.save();
},
todaysList: function(pageobj) {
var old_text = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
var statelem = pageobj.getStatusElement();
var added_data = "";
var editsummary = "";
switch( params.xfdcat ) {
case 'cfd':
added_data = "{{subst:cfd2|text=" + Morebits.string.formatReasonText(params.reason) +
" ~~~~|1=" + mw.config.get('wgTitle') + "}}";
editsummary = "Added delete nomination of [[:" + Morebits.pageNameNorm + "]].";
break;
case 'cfm':
added_data = "{{subst:cfm2|text=" + Morebits.string.formatReasonText(params.reason) +
" ~~~~|1=" + mw.config.get('wgTitle') + "|2=" + params.target + "}}";
editsummary = "Added merge nomination of [[:" + Morebits.pageNameNorm + "]].";
break;
case 'cfr':
added_data = "{{subst:cfr2|text=" + Morebits.string.formatReasonText(params.reason) +
" ~~~~|1=" + mw.config.get('wgTitle') + "|2=" + params.target + "}}";
editsummary = "Added rename nomination of [[:" + Morebits.pageNameNorm + "]].";
break;
case 'cfs':
added_data = "{{subst:cfs2|text=" + Morebits.string.formatReasonText(params.reason) +
" ~~~~|1=" + mw.config.get('wgTitle') + "|2=" + params.target + "|3=" + params.target2 + "}}";
editsummary = "Added split nomination of [[:" + Morebits.pageNameNorm + "]].";
break;
case 'cfc':
added_data = "{{subst:cfc2|text=" + Morebits.string.formatReasonText(params.reason) +
" ~~~~|1=" + mw.config.get('wgTitle') + "|2=" + params.target + "}}";
editsummary = "Added convert nomination of [[:" + Morebits.pageNameNorm + "]].";
break;
default:
alert("twinklexfd in todaysList: unknown CFD action");
break;
}
var 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(editsummary + Twinkle.getPref('summaryAd'));
switch (Twinkle.getPref('xfdWatchDiscussion')) {
case 'yes':
pageobj.setWatchlist(true);
break;
case 'no':
pageobj.setWatchlistFromPreferences(false);
break;
default:
pageobj.setWatchlistFromPreferences(true);
break;
}
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
});
},
userNotification: function(pageobj) {
var initialContrib = pageobj.getCreator();
// Disallow warning yourself
if (initialContrib === mw.config.get('wgUserName')) {
pageobj.getStatusElement().warn("You (" + initialContrib + ") created this page; skipping user notification");
return;
}
var usertalkpage = new Morebits.wiki.page('User talk:' + initialContrib, "Notifying initial contributor (" + initialContrib + ")");
var notifytext = "\n{{subst:CFDNote|1=" + Morebits.pageNameNorm + "}} ~~~~";
usertalkpage.setAppendText(notifytext);
usertalkpage.setEditSummary("Notification: listing at [[WP:CFD|categories for discussion]] of [[" + Morebits.pageNameNorm + "]]." + Twinkle.getPref('summaryAd'));
usertalkpage.setCreateOption('recreate');
switch (Twinkle.getPref('xfdWatchUser')) {
case 'yes':
usertalkpage.setWatchlist(true);
break;
case 'no':
usertalkpage.setWatchlistFromPreferences(false);
break;
default:
usertalkpage.setWatchlistFromPreferences(true);
break;
}
usertalkpage.setFollowRedirect(true);
usertalkpage.append();
}
},
cfds: {
taggingCategory: function(pageobj) {
var text = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
pageobj.setPageText("{{subst:cfr-speedy|1=" + params.target + "}}\n" + text);
pageobj.setEditSummary("Nominated for speedy renaming; see [[WP:CFDS|Categories for discussion/Speedy]]." + Twinkle.getPref('summaryAd'));
switch (Twinkle.getPref('xfdWatchPage')) {
case 'yes':
pageobj.setWatchlist(true);
break;
case 'no':
pageobj.setWatchlistFromPreferences(false);
break;
default:
pageobj.setWatchlistFromPreferences(true);
break;
}
pageobj.setCreateOption('recreate'); // since categories can be populated without an actual page at that title
pageobj.save();
},
addToList: function(pageobj) {
var old_text = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
var statelem = pageobj.getStatusElement();
var newcatname = (/^Category:/.test(params.target) ? params.target : ("Category:" + params.target));
var text = old_text.replace( 'BELOW THIS LINE -->', "BELOW THIS LINE -->\n* [[:" + Morebits.pageNameNorm + "]] to [[:" +
newcatname + "]]\u00A0\u2013 " + params.xfdcat + (params.reason ? (": " + Morebits.string.formatReasonText(params.reason)) : ".") +
" ~~~~" );
// U+00A0 NO-BREAK SPACE; U+2013 EN RULE
if( text === old_text ) {
statelem.error( 'failed to find target spot for the discussion' );
return;
}
pageobj.setPageText(text);
pageobj.setEditSummary("افزودن [[" + Morebits.pageNameNorm + "]]." + Twinkle.getPref('summaryAd'));
switch (Twinkle.getPref('xfdWatchDiscussion')) {
case 'yes':
pageobj.setWatchlist(true);
break;
case 'no':
pageobj.setWatchlistFromPreferences(false);
break;
default:
pageobj.setWatchlistFromPreferences(true);
break;
}
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: {
// This is a callback from an API request, which gets the target of the redirect
findTargetCallback: function(apiobj) {
var xmlDoc = apiobj.responseXML;
var target = $(xmlDoc).find('redirects r').first().attr('to');
if( !target ) {
apiobj.statelem.error( "This page is currently not a redirect, aborting" );
return;
}
apiobj.params.target = target;
Twinkle.xfd.callbacks.rfd.main(apiobj.params);
},
main: function(params) {
var date = new Date();
params.logpage = 'Wikipedia:Redirects for discussion/Log/' + date.getUTCFullYear() + ' ' + date.getUTCMonthName() + ' ' + date.getUTCDate();
// Tagging redirect
var wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'), "Adding deletion tag to redirect");
wikipedia_page.setFollowRedirect(false);
wikipedia_page.setCallbackParameters(params);
wikipedia_page.load(Twinkle.xfd.callbacks.rfd.taggingRedirect);
// 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
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.rfd.todaysList);
// Notifying initial contributor
if (params.usertalk) {
var thispage = new Morebits.wiki.page(mw.config.get('wgPageName'));
thispage.setCallbackParameters(params);
thispage.lookupCreator(Twinkle.xfd.callbacks.rfd.userNotification);
}
},
taggingRedirect: function(pageobj) {
var text = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
pageobj.setPageText("{{subst:rfd|content=\n" + text + "\n}}");
pageobj.setEditSummary("فهرست شد: [[" + params.logpage + "#" + Morebits.pageNameNorm + "]]." + Twinkle.getPref('summaryAd'));
switch (Twinkle.getPref('xfdWatchPage')) {
case 'yes':
pageobj.setWatchlist(true);
break;
case 'no':
pageobj.setWatchlistFromPreferences(false);
break;
default:
pageobj.setWatchlistFromPreferences(true);
break;
}
pageobj.setCreateOption('nocreate');
pageobj.save();
},
todaysList: function(pageobj) {
var old_text = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
var statelem = pageobj.getStatusElement();
var text = old_text.replace( /(<\!-- Add new entries directly below this line\.? -->)/, "$1\n{{subst:rfd2|text=" +
Morebits.string.formatReasonText(params.reason) + "|redirect="+ Morebits.pageNameNorm + "|target=" +
params.target + "}} ~~~~\n" );
if( text === old_text ) {
statelem.error( 'failed to find target spot for the discussion' );
return;
}
pageobj.setPageText(text);
pageobj.setEditSummary("افزودن [[" + Morebits.pageNameNorm + "]]." + Twinkle.getPref('summaryAd'));
switch (Twinkle.getPref('xfdWatchDiscussion')) {
case 'yes':
pageobj.setWatchlist(true);
break;
case 'no':
pageobj.setWatchlistFromPreferences(false);
break;
default:
pageobj.setWatchlistFromPreferences(true);
break;
}
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
});
},
userNotification: function(pageobj) {
var initialContrib = pageobj.getCreator();
// Disallow warning yourself
if (initialContrib === mw.config.get('wgUserName')) {
pageobj.getStatusElement().warn("You (" + initialContrib + ") created this page; skipping user notification");
return;
}
var usertalkpage = new Morebits.wiki.page('User talk:' + initialContrib, "Notifying initial contributor (" + initialContrib + ")");
var notifytext = "\n{{subst:RFDNote|1=" + Morebits.pageNameNorm + "}} ~~~~";
usertalkpage.setAppendText(notifytext);
usertalkpage.setEditSummary("آگاهسازی: فهرستشدن در [[:en:WP:RFD|نظرخواهی برای حذف]]، صفحه: [[" + Morebits.pageNameNorm + "]]." + Twinkle.getPref('summaryAd'));
usertalkpage.setCreateOption('recreate');
switch (Twinkle.getPref('xfdWatchUser')) {
case 'yes':
usertalkpage.setWatchlist(true);
break;
case 'no':
usertalkpage.setWatchlistFromPreferences(false);
break;
default:
usertalkpage.setWatchlistFromPreferences(true);
break;
}
usertalkpage.setFollowRedirect(true);
usertalkpage.append();
}
}
};
Twinkle.xfd.callback.evaluate = function(e) {
var type = e.target.category.value;
var usertalk = e.target.notify.checked;
var reason = e.target.xfdreason.value;
var xfdcat, xfdtarget, xfdtarget2, ffdvenue, noinclude, tfdinline, notifyuserspace;
if( type === "afd" || type === "cfd" || type === "cfds" || type === "tfd" ) {
xfdcat = e.target.xfdcat.value;
}
if( type === "cfd" || type === "cfds" ) {
xfdtarget = e.target.xfdtarget.value;
if (e.target.xfdtarget2) {
xfdtarget2 = e.target.xfdtarget2.value;
}
}
if( type === 'ffd' ) {
var ffdvenues = e.target.ffdvenue;
for( var i = 0; i < ffdvenues.length; i++ )
{
if( !ffdvenues[i].checked ) {
continue;
}
ffdvenue = ffdvenues[i].values;
break;
}
}
if( type === "afd" || type === "mfd" || type === "tfd" ) {
noinclude = e.target.noinclude.checked;
}
if( type === 'tfd' ) {
tfdinline = e.target.tfdinline.checked;
if (e.target.xfdtarget) {
xfdtarget = e.target.xfdtarget.value;
}
}
if( type === 'mfd' ) {
notifyuserspace = e.target.notifyuserspace && e.target.notifyuserspace.checked;
}
Morebits.simpleWindow.setButtonsEnabled( false );
Morebits.status.init( e.target );
Twinkle.xfd.currentRationale = reason;
Morebits.status.onError(Twinkle.xfd.printRationale);
if( !type ) {
Morebits.status.error( 'Error', 'no action given' );
return;
}
var query, wikipedia_page, wikipedia_api, logpage, params;
var date = new Date();
switch( type ) {
case 'afd': // AFD
query = {
'action': 'query',
'list': 'allpages',
'apprefix': 'نظرخواهی برای حذف/' + Morebits.pageNameNorm,
'apnamespace': 4,
'apfilterredir': 'nonredirects',
'aplimit': Morebits.userIsInGroup( 'sysop' ) ? 5000 : 500
};
wikipedia_api = new Morebits.wiki.api( 'Tagging article with deletion tag', query, Twinkle.xfd.callbacks.afd.main );
wikipedia_api.params = { usertalk:usertalk, reason:reason, noinclude:noinclude, xfdcat:xfdcat };
wikipedia_api.post();
break;
case 'tfd': // TFD
Morebits.wiki.addCheckpoint();
if (xfdtarget) {
xfdtarget = Morebits.string.toUpperCaseFirstChar(xfdtarget.replace(/^\:?Template\:/i, ''));
} else {
xfdtarget = '';
}
logpage = 'Wikipedia:Templates for discussion/Log/' + date.getUTCFullYear() + ' ' + date.getUTCMonthName() + ' ' + date.getUTCDate();
params = { tfdinline: tfdinline, logpage: logpage, noinclude: noinclude, xfdcat: xfdcat, target: xfdtarget, reason: reason };
// Tagging template(s)
if (xfdcat === "tfm") {
// Tag this template
wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'), "Tagging this template with merge tag");
wikipedia_page.setFollowRedirect(true);
params.otherTemplateName = "Template:" + xfdtarget;
wikipedia_page.setCallbackParameters(params);
wikipedia_page.load(Twinkle.xfd.callbacks.tfd.taggingTemplateForMerge);
// Tag other template
wikipedia_page = new Morebits.wiki.page("Template:" + xfdtarget, "Tagging other template with merge tag");
wikipedia_page.setFollowRedirect(true);
params = $.extend(params);
params.otherTemplateName = Morebits.pageNameNorm;
wikipedia_page.setCallbackParameters(params);
wikipedia_page.load(Twinkle.xfd.callbacks.tfd.taggingTemplateForMerge);
} 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.taggingTemplate);
}
// Updating data for the action completed event
Morebits.wiki.actionCompleted.redirect = logpage;
Morebits.wiki.actionCompleted.notice = "Nomination completed, now redirecting to today's log";
// Adding discussion
wikipedia_page = new Morebits.wiki.page(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 contributor
if (usertalk) {
var thispage = new Morebits.wiki.page(mw.config.get('wgPageName'));
thispage.setCallbackParameters(params);
thispage.lookupCreator(Twinkle.xfd.callbacks.tfd.userNotification);
// Nice try, but what if the two page creators are the same user?
// Also, other XFD types don't do this... yet!
//if (xfdcat === "tfm") {
// thispage = new Morebits.wiki.page("Template:" + xfdtarget);
// thispage.setCallbackParameters(params);
// thispage.lookupCreator(Twinkle.xfd.callbacks.tfd.userNotification);
//}
}
Morebits.wiki.removeCheckpoint();
break;
case 'mfd': // MFD
query = {
'action': 'query',
'list': 'allpages',
'apprefix': 'نظرخواهی برای حذف/' + Morebits.pageNameNorm,
'apnamespace': 4,
'apfilterredir': 'nonredirects',
'aplimit': Morebits.userIsInGroup( 'sysop' ) ? 5000 : 500
};
wikipedia_api = new Morebits.wiki.api( "Looking for prior nominations of this page", query, Twinkle.xfd.callbacks.mfd.main );
wikipedia_api.params = { usertalk: usertalk, notifyuserspace: notifyuserspace, reason: reason, noinclude: noinclude, xfdcat: xfdcat };
wikipedia_api.post();
break;
case 'ffd': // FFD/PUF/NFCR
var dateString = date.getUTCFullYear() + ' ' + date.getUTCMonthName() + ' ' + date.getUTCDate();
logpage = 'Wikipedia:Files for deletion/' + dateString;
params = { usertalk: usertalk, reason: reason, date: dateString, logpage: logpage };
Morebits.wiki.addCheckpoint();
switch( ffdvenue ) {
case 'puf':
params.logpage = logpage = 'Wikipedia:Possibly unfree files/' + dateString;
// Updating data for the action completed event
Morebits.wiki.actionCompleted.redirect = logpage;
Morebits.wiki.actionCompleted.notice = "Nomination completed, now redirecting to today's list";
// Tagging file
wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'), "Tagging file with PUF tag");
wikipedia_page.setFollowRedirect(true);
wikipedia_page.setCallbackParameters(params);
wikipedia_page.load(Twinkle.xfd.callbacks.puf.taggingImage);
// Adding discussion
wikipedia_page = new Morebits.wiki.page(params.logpage, "افزودن نظرخواهی به فهرست نظرخواهیها");
wikipedia_page.setFollowRedirect(true);
wikipedia_page.setCallbackParameters(params);
wikipedia_page.load(Twinkle.xfd.callbacks.puf.todaysList);
// Notification to first contributor
if (usertalk) {
wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'));
wikipedia_page.setCallbackParameters(params);
wikipedia_page.lookupCreator(Twinkle.xfd.callbacks.puf.userNotification);
}
Morebits.wiki.removeCheckpoint();
break;
case 'nfcr':
// Updating data for the action completed event
Morebits.wiki.actionCompleted.redirect = "Wikipedia:Non-free content review";
Morebits.wiki.actionCompleted.notice = "Nomination completed, now redirecting to the discussion page";
// Tagging file
if (mw.config.get('wgNamespaceNumber') === 6) {
wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'), "Tagging file with review tag");
wikipedia_page.setFollowRedirect(true);
wikipedia_page.setPrependText("{{non-free review}}\n");
wikipedia_page.setEditSummary("این پرونده" +
" برای بازبینی فهرست شده است: [[:en:Wikipedia:Non-free content review#" + Morebits.pageNameNorm + "]]." + Twinkle.getPref('summaryAd'));
switch (Twinkle.getPref('xfdWatchPage')) {
case 'yes':
wikipedia_page.setWatchlist(true);
break;
case 'no':
wikipedia_page.setWatchlistFromPreferences(false);
break;
default:
wikipedia_page.setWatchlistFromPreferences(true);
break;
}
wikipedia_page.setCreateOption('recreate'); // it might be possible for a file to exist without a description page
wikipedia_page.prepend();
}
// Adding discussion
wikipedia_page = new Morebits.wiki.page("Wikipedia:Non-free content review", "Adding discussion to the NFCR page");
wikipedia_page.setFollowRedirect(true);
wikipedia_page.setAppendText("\n\n== [[:" + Morebits.pageNameNorm + "]] ==\n\n" +
Morebits.string.formatReasonText(params.reason) + " ~~~~");
wikipedia_page.setEditSummary("افزودن [[" + Morebits.pageNameNorm + "]]." + Twinkle.getPref('summaryAd'));
switch (Twinkle.getPref('xfdWatchDiscussion')) {
case 'yes':
wikipedia_page.setWatchlist(true);
break;
case 'no':
wikipedia_page.setWatchlistFromPreferences(false);
break;
default:
wikipedia_page.setWatchlistFromPreferences(true);
break;
}
wikipedia_page.setCreateOption('recreate');
wikipedia_page.append(function() {
Twinkle.xfd.currentRationale = null; // any errors from now on do not need to print the rationale, as it is safely saved on-wiki
});
// can't notify user on NFCR, so don't
Morebits.wiki.removeCheckpoint();
break;
default:
// 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 file
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);
// Contributor specific edits
wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'));
wikipedia_page.setCallbackParameters(params);
wikipedia_page.lookupCreator(Twinkle.xfd.callbacks.ffd.main);
break;
}
Morebits.wiki.removeCheckpoint();
break;
case 'cfd':
Morebits.wiki.addCheckpoint();
if( xfdtarget ) {
xfdtarget = xfdtarget.replace( /^\:?Category\:/i, '' );
} else {
xfdtarget = '';
}
if( xfdtarget2 ) {
xfdtarget2 = xfdtarget2.replace( /^\:?Category\:/i, '' );
}
logpage = 'Wikipedia:Categories for discussion/Log/' + date.getUTCFullYear() + ' ' + date.getUTCMonthName() + ' ' + date.getUTCDate();
params = { reason: reason, xfdcat: xfdcat, target: xfdtarget, target2: xfdtarget2, logpage: logpage };
// Updating data for the action completed event
Morebits.wiki.actionCompleted.redirect = logpage;
Morebits.wiki.actionCompleted.notice = "Nomination completed, now redirecting to today's log";
// Tagging category
wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'), "Tagging category with deletion tag");
wikipedia_page.setCallbackParameters(params);
wikipedia_page.load(Twinkle.xfd.callbacks.cfd.taggingCategory);
// Adding discussion to list
wikipedia_page = new Morebits.wiki.page(logpage, "افزودن نظرخواهی به فهرست نظرخواهیها");
//wikipedia_page.setPageSection(2);
// pageSection has been disabled - the API seems to throw up with nonexistent edit conflicts
// it can be turned on again once the problem is fixed, to save bandwidth
//wikipedia_page.setFollowRedirect(true);
wikipedia_page.setCallbackParameters(params);
wikipedia_page.load(Twinkle.xfd.callbacks.cfd.todaysList);
// Notification to first contributor
if (usertalk) {
wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'));
wikipedia_page.setCallbackParameters(params);
wikipedia_page.lookupCreator(Twinkle.xfd.callbacks.cfd.userNotification);
}
Morebits.wiki.removeCheckpoint();
break;
case 'cfds':
xfdtarget = xfdtarget.replace( /^\:?Category\:/, '' );
logpage = "Wikipedia:Categories for discussion/Speedy";
params = { reason: reason, xfdcat: xfdcat, target: xfdtarget };
// 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.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.setCallbackParameters(params);
wikipedia_page.load(Twinkle.xfd.callbacks.cfds.addToList);
break;
case 'rfd':
params = { usertalk: usertalk, reason: reason };
if (document.getElementById("softredirect")) {
// For soft redirects, skip straight to the callback
params.target = document.getElementById("softredirect").textContent.replace(/^\:+/, "");
Twinkle.xfd.callbacks.rfd.main(params);
} else {
// Find current target of redirect
query = {
'action': 'query',
'titles': mw.config.get('wgPageName'),
'redirects': true
};
wikipedia_api = new Morebits.wiki.api( "Finding target of redirect", query, Twinkle.xfd.callbacks.rfd.findTargetCallback );
wikipedia_api.params = params;
wikipedia_api.post();
}
break;
default:
alert("twinklexfd: unknown XFD discussion venue");
break;
}
};
})(jQuery);
//</nowiki>