MediaWiki:Gadget-twinkleprod.js: Perbedaan revisi

Repo at 5c1e7e3: Update from Github
(Repo at a491314: tracking branch 'upstream/master'; Don't insert a stray comma when endorsing prod (#585); Don't insert a stray comma when endorsing prod)
(Repo at 5c1e7e3: Update from Github)
 
// <nowiki>
 
 
(function($) {
 
 
* Active on: Existing articles, files, books which are not redirects,
* and user pages in [[:Category:Wikipedia books (user books)]]
* Config directives in: TwinkleConfig
*/
 
Twinkle.prod = function twinkleprod() {
if( ((([0, 6, 108].indexOf(mw.config.get('wgNamespaceNumber')) === -1) && (mw.config.get('wgNamespaceNumber') !== 2 || mw.config.get('wgCategories').indexOf('Wikipedia books (user books)') === -1) )
|| !mw.config.get('wgCurRevisionId') || Morebits.wiki.isPageRedirect() ) {
return;
}
 
Twinkle.addPortletLink( Twinkle.prod.callback, "'UP"', "'tw-prod"', "'Usulan penghapusan melalui WP:UP" ');
};
 
namespace = 'book';
break;
// no default
}
 
var Window = new Morebits.simpleWindow( 800, 410 );
Window.setTitle( "'Usulan Penghapusan (UP)" ');
Window.setScriptName( "'Twinkle" ');
 
var form = new Morebits.quickForm( Twinkle.prod.callback.evaluate );
 
if (namespace === 'article') {
Window.addFooterLink( "'Proposed deletion policy"', "'WP:PROD" ');
Window.addFooterLink( "'BLP PROD policy"', "'WP:BLPPROD" ');
} else if ( namespace === 'file' ) {
Window.addFooterLink( "'Proposed deletion policy"', "'WP:PROD" ');
} else { // if book
Window.addFooterLink( "'Proposed deletion (books) policy"', "'WP:BOOKPROD" ');
}
 
var field = form.append( {
type: 'field',
label: 'type UP',
id: 'prodtype_fieldset'
} );
 
field.append( {
type: 'radio',
name: 'prodtype',
event: Twinkle.prod.callback.prodtypechanged,
list: [
{
label: 'UP (usulan penghapusan)',
value: 'prod',
checked: true,
tooltip: 'Usulan penghapusan normal, per [[WP:UP]]'
},
{
label: 'Usulan penghapusan halaman tokoh yang masih hidup tanpa referensi',
value: 'prodblp',
tooltip: 'Usulan penghapusan biografi baru dari tokoh yang masih hidup'
}
]
} );
 
// Placeholder fieldset to be replaced in Twinkle.prod.callback.prodtypechanged
form.append( {
type: 'field',
name: 'parameters'
} );
 
Window.addFooterLink('Bantuan "Twinkle help"', "'WP:TW/DOC#prod" ');
 
form.append( { type: 'submit', label: 'Usulkan penghapusan' } );
 
var result = form.render();
Window.setContent( result );
Window.display();
 
// Hide fieldset for File and Book PROD types since only normal PROD is allowed
if (namespace !== 'article') {
$(result).find('#prodtype_fieldset').hide();
}
 
// Fake a change event on the first prod type radio, to initialize the type-dependent controls
var evt = document.createEvent( "'Event" ');
evt.initEvent( 'change', true, true );
result.prodtype[0].dispatchEvent( evt );
 
};
 
Twinkle.prod.callback.prodtypechanged = function(event) {
// prepare frame for prod type dependant controls
var field = new Morebits.quickForm.element( {
type: 'field',
label: 'Parameters',
name: 'parameters'
} );
// create prod type dependant controls
switch ( event.target.values ) {
case 'prod':
field.append( {
type: 'checkbox',
list: [
{
label: 'Beritahukan pembuat halaman jika memungkinkan',
value: 'notify',
name: 'notify',
tooltip: "'Templat pemberitahuan akan dikirimkan ke halaman pembicaraannya jika opsi ini dipilih."',
checked: true
}
]
} );
field.append( {
type: 'textarea',
name: 'reason',
label: 'Alasan usulan penghapusan:',
value: Twinkle.prod.defaultReason
} );
break;
 
}
 
field.append( {
type: 'checkbox',
list: [
{
label: 'Beritahukan pembuat halaman jika memungkinkan',
value: 'notify',
name: 'notify',
tooltip: 'Pembuat halaman harus diberitahukan.',
checked: true,
disabled: true
}
]
} );
// temp warning, can be removed down the line once BLPPROD is more established. Amalthea, May 2010.
var boldtext = document.createElement('b');
boldtext.appendChild(document.createTextNode('Ingatlah bahwa hanya biografi tokoh yang masih hidup tanpa referensi yang cocok untuk tag ini.'));
}
 
event.target.form.replaceChild( field.render(), $(event.target.form).find('fieldset[name="parameters"]')[0] );
};
 
var params = apiobj.params;
 
// Check talk page for templates indicating prior XfD or PROD
// Check existence of AfD, would be easier if mw.Title.exists() worked [[phab:T184953]]
var numTemplates = $(xmlDoc).find('templates tl').length;
var exists;
if (namespace === 'article'numTemplates) {
var template = $(xmlDoc).find('templates tl')[0].getAttribute('title');
var query = {
if (numTemplates === 1 && template === 'Template:Old prod') {
'action': 'query',
if (params.blp) {
'prop': 'revisions',
if (!confirm('Previous PROD nomination found on talk page. Do you still want to continue applying BLPPROD? ')) {
'titles': 'Wikipedia:Articles for deletion/' + Morebits.pageNameNorm
statelem.warn('Previous PROD found on talk page, aborted by user');
};
return;
var wikipedia_api = new Morebits.wiki.api('Checking for prior AfDs', query, function(apiobj) {
}
var xmlDoc = apiobj.responseXML;
statelem.info('Previous PROD found on talk page, continuing');
exists = $(xmlDoc).find('rev').attr('revid');
}); else {
statelem.warn('Previous PROD found on talk page, aborting procedure');
// Wait for API call to finish
wikipedia_api.post({
async: false
});
}
if (exists) {
statelem.warn( 'Previous AfD for this page title found, aborting procedure' );
return;
}
 
// Check talk page for category indicating prior PROD
var cats = $(xmlDoc).find('categories');
if(cats.length) {
if(params.blp) {
if( !confirm( 'Previous PROD nomination found on talk page. Do you still want to continue applying BLPPROD? ' ) ) {
statelem.warn( 'Previous PROD found on talk page, aborted by user' );
return;
} else {
statelem.info( 'Previous PROD found on talk page, continuing' );
}
 
// if there are multiple templates, at least one of them would be a prior xfd template
} else {
statelem.warn( 'Previous PRODXfD template found on talk page, aborting procedure' );
return;
}
}
 
var ts = new Morebits.wiki.page(mw.config.get('wgPageName'));
ts.setFollowRedirect(true); // for NPP, and also because redirects are ineligible for PROD
ts.setCallbackParameters(params);
ts.setLookupNonRedirectCreator(true); // Look for author of first non-redirect revision
ts.lookupCreation(Twinkle.prod.callbacks.creationInfo);
},
 
creationInfo: function(pageobj) {
var params = pageobj.getCallbackParameters();
params.initialContrib = pageobj.getCreator();
params.creation = pageobj.getCreationTimestamp();
 
Morebits.wiki.actionCompleted.redirect = mw.config.get('wgPageName');
Morebits.wiki.actionCompleted.notice = "'Tagging complete"';
 
var wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'), "'Tagging page"');
wikipedia_page.setFollowRedirect(true); // for NPP, and also because redirects are ineligible for PROD
wikipedia_page.setCallbackParameters(params);
var statelem = pageobj.getStatusElement();
 
if ( !pageobj.exists() ) {
statelem.error( "'Kelihatannya halaman ini tidak ada. Mungkin sudah dihapus." ');
return;
}
// Check for already existing deletion tags
var tag_re = /{{(?:db-?|delete|article for deletion\/dated|ffd\b)|#invoke:RfD/i;
if ( tag_re.test( text ) ) {
statelem.warn( 'Halaman sudah ditandai dengan templat hapus. Proses dihentikan.' );
return;
}
 
// Alert if article is at least three days old, not in Category:Living people, and BLPPROD is selected
if ( params.blp ) {
var isMoreThan3DaysOld = new Morebits.date(params.creation).add(3, 'days').isAfter(new Date(pageobj.getLoadTime()));
var blpcheck_re = /\[\[Category:Living people\]\]/i;
if ( !blpcheck_re.test( text) )&& isMoreThan3DaysOld) {
if ( ! confirm("'Please note that the article is not in Category:Living people and hence may be ineligible for BLPPROD. Are you sure you want to continue? \n\nYou may wish to add the category if you proceed, unless the article is about a recently deceased person." ') ) {
return;
}
 
// Remove tags that become superfluous with this action
text = text.replace(/{{\s*(userspace draft|mtc|(copy|move) to wikimedia commons|(copy |move )?to ?commons)\s*(\|(?:{{[^{}]*}}|[^{}])*)?}}\s*/gi, ""'');
var prod_re = /{{\s*(?:Prod blp|Proposed deletion|book-prod)\/dated(?: files)?\s*\|(?:{{[^{}]*}}|[^{}])*}}/i;
var summaryText;
if ( !prod_re.test( text ) ) {
// Notification to first contributor
if ( params.usertalk ) {
// Disallow warning yourself
var thispage = new Morebits.wiki.page(mw.config.get('wgPageName'));
if (params.initialContrib === mw.config.get('wgUserName')) {
thispage.setCallbackParameters(params);
statelem.warn('You (' + params.initialContrib + ') created this page; skipping user notification');
thispage.lookupCreator(Twinkle.prod.callbacks.userNotification);
if (Twinkle.getPref('logProdPages')) {
}
Twinkle.prod.callbacks.addToLog(params);
// If not notifying, log this PROD
}
else if( Twinkle.getPref('logProdPages') ) {
} else {
// [[Template:Proposed deletion notify]] supports File namespace
var notifyTemplate;
if (params.blp) {
notifyTemplate = 'prodwarningBLP';
} else if (params.book) {
notifyTemplate = 'bprodwarning';
} else {
notifyTemplate = 'proposed deletion notify';
}
var notifytext = '\n{{subst:' + notifyTemplate + '|1=' + Morebits.pageNameNorm + '|concern=' + params.reason + '}} ~~~~';
 
var usertalkpage = new Morebits.wiki.page('User talk:' + params.initialContrib, 'Notifying initial contributor (' + params.initialContrib + ')');
usertalkpage.setAppendText(notifytext);
usertalkpage.setEditSummary('Notification: proposed deletion of [[:' + Morebits.pageNameNorm + ']].' + Twinkle.getPref('summaryAd'));
usertalkpage.setCreateOption('recreate');
usertalkpage.setFollowRedirect(true);
usertalkpage.setCallbackParameters(params);
usertalkpage.append(function onNotifySuccess() {
// add nomination to the userspace log, if the user has enabled it
if (Twinkle.getPref('logProdPages')) {
params.logInitialContrib = params.initialContrib;
Twinkle.prod.callbacks.addToLog(params);
}
}, function onNotifyError() {
// if user could not be notified, log nomination without mentioning that notification was sent
if (Twinkle.getPref('logProdPages')) {
Twinkle.prod.callbacks.addToLog(params);
}
});
}
} else if (Twinkle.getPref('logProdPages')) { // If not notifying, log this PROD
Twinkle.prod.callbacks.addToLog(params);
}
if (params.blp) {
summaryText = "'Usulkan penghapusan artikel per [[WP:BLPPROD]]."';
text = "'{{subst:prod blp"' + (params.usertalk ? "'|help=off"' : ""'') + "'}}\n"' + text;
} else if (params.book) {
}
summaryText = 'Usulkan penghapusan buku per [[WP:BOOKPROD]].';
else if(params.book) {
text = '{{subst:book-prod|1=' + Morebits.string.formatReasonText(params.reason) + (params.usertalk ? '|help=off' : '') + '}}\n' + text;
summaryText = "Usulkan penghapusan buku per [[WP:BOOKPROD]].";
} else {
text = "{{subst:book-prod|1=" + Morebits.string.formatReasonText(params.reason) + (params.usertalk ? "|help=off" : "") + "}}\n" + text;
summaryText = 'Usulan penghapusan ' + namespace + ' per [[WP:PROD]].';
}
text = '{{subst:prod|1=' + Morebits.string.formatReasonText(params.reason) + (params.usertalk ? '|help=off' : '') + '}}\n' + text;
else {
summaryText = "Usulan penghapusan " + namespace + " per [[WP:PROD]].";
text = "{{subst:prod|1=" + Morebits.string.formatReasonText(params.reason) + (params.usertalk ? "|help=off" : "") + "}}\n" + text;
}
 
var talkpage = new Morebits.wiki.page(talktitle, 'Menambahkan {{Old prod}} di halaman pembicaraan');
talkpage.setPrependText(oldprodfull);
talkpage.setEditSummary('Menambahkan {{Old prod}} di halaman pembicaraan ' + Twinkle.getPref('summaryAd'));
talkpage.setFollowRedirect(true); // match behavior for page tagging
talkpage.setCreateOption('recreate');
talkpage.prepend();
} else { // already tagged for PROD, so try endorsing it
}
var prod2_re = /{{(?:Proposed deletion endorsed|prod-?2).*?}}/i;
else { // already tagged for PROD, so try endorsing it
if (prod2_re.test(text)) {
var prod2_re = /{{(?:Proposed deletion endorsed|prod-?2).*?}}/;
statelem.warn('Halaman sudah ditandai dengan {{proposed deletion}} dan {{proposed deletion endorsed}}, proses dihentikan');
if( prod2_re.test( text ) ) {
statelem.warn( 'Halaman sudah ditandai dengan {{proposed deletion}} dan {{proposed deletion endorsed}}, proses dihentikan' );
return;
}
var confirmtext = "'Tag {{proposed deletion}} sudah ada di halaman ini. \nApakah Anda ingin menambahkan tag {{proposed deletion endorsed}} disertai alasan Anda?"';
if (params.blp) {
confirmtext = "'Tag {{proposed deletion}} bukan BOH ditemukan di artikel. \nApakah Anda ingin menambahkan tag {{proposed deletion endorsed}} dengan alasan \"artikel adalah biografi tokoh yang masih hidup tanpa referensi\"?"';
// FIXME: this msg is shown even if it was a BLPPROD tag.
}
if ( !confirm( confirmtext ) ) {
statelem.warn( 'Dibatalkan oleh pengguna' );
return;
}
 
summaryText = "'Mendukung usulan penghapusan per [[WP:"' + (params.blp ? "'BLP"' : (params.book ? "'BOOK"' : "")'') + "'UP]]."';
text = text.replace( prod_re, text.match( prod_re ) + "'\n{{proposedProposed deletion endorsed|1="' + (params.blp ?
"'artikel adalah biografi tokoh yang masih hidup tanpa referensi"' :
Morebits.string.formatReasonText(params.reason)) + "'}}\n" ');
 
if ( Twinkle.getPref('logProdPages') ) {
params.logEndorsing = true;
Twinkle.prod.callbacks.addToLog(params);
}
}
 
// curate/patrol the page
if (Twinkle.getPref('markProdPagesAsPatrolled')) {
pageobj.triage();
}
 
pageobj.setCreateOption('nocreate');
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("Anda (" + initialContrib + ") membuat halaman ini; lewatkan pemberitahuan pengguna");
if (Twinkle.getPref("logProdPages")) {
Twinkle.prod.callbacks.addToLog(params);
}
return;
}
 
// [[Template:Proposed deletion notify]] supports File namespace
var notifyTemplate;
if(params.blp) {
notifyTemplate = 'prodwarningBLP';
} else if (params.book) {
notifyTemplate = 'bprodwarning';
} else {
notifyTemplate = 'proposed deletion notify';
}
var usertalkpage = new Morebits.wiki.page('User talk:' + initialContrib, "Memberitahukan kontributor awal (" + initialContrib + ")");
var notifytext = "\n{{subst:" + notifyTemplate + "|1=" + Morebits.pageNameNorm + "|concern=" + params.reason + "}} ~~~~";
usertalkpage.setAppendText(notifytext);
usertalkpage.setEditSummary("Pemberitahuan: Usulan penghapusan [[:" + Morebits.pageNameNorm + "]]." + Twinkle.getPref('summaryAd'));
usertalkpage.setCreateOption('recreate');
usertalkpage.setFollowRedirect(true);
usertalkpage.append(function onNotifySuccess() {
// add nomination to the userspace log, if the user has enabled it
if (Twinkle.getPref('logProdPages')) {
params.logInitialContrib = initialContrib;
Twinkle.prod.callbacks.addToLog(params);
}
}, function onNotifyError() {
// if user could not be notified, log nomination without mentioning that notification was sent
if (Twinkle.getPref('logProdPages')) {
Twinkle.prod.callbacks.addToLog(params);
}
});
},
 
addToLog: function(params) {
var wikipedia_pageusl = new Morebits.wiki.pageuserspaceLogger("User:" + mw.config.get('wgUserName') + "/" + Twinkle.getPref('prodLogPageName'), "Menambahkan entri ke log di ruang pengguna");
usl.initialText =
wikipedia_page.setCallbackParameters(params);
'Ini merupakan log semua tag [[WP:UP|usulan penghapusan]] yang diberikan atau didukung oleh pengguna ini dengan menggunakan modul UP [[WP:TW|Twinkle]].\n\n' +
wikipedia_page.load(Twinkle.prod.callbacks.saveLog);
'Apabila Anda tidak ingin menyimpan log ini, matikan di [[Wikipedia:Twinkle/Preferences|preferences panel]], dan ' +
},
'usulkan penghapusan cepat halaman ini dengan kriteria [[WP:KPC#U1|KPC U1]].\n';
 
var logText = '# [[:' + Morebits.pageNameNorm + ']]';
saveLog: function(pageobj) {
var summaryText;
var text = pageobj.getPageText();
// If a logged file is deleted but exists on commons, the wikilink will be blue, so provide a link to the log
var params = pageobj.getCallbackParameters();
logText += namespace === 'file' ? ' ([{{fullurl:Special:Log|page=' + mw.util.wikiUrlencode(mw.config.get('wgPageName')) + '}} log]): ' : ': ';
 
// add blurb if log page doesn't exist
if (!pageobj.exists()) {
text =
"Ini merupakan log semua tag [[WP:UP|usulan penghapusan]] yang diberikan atau didukung oleh pengguna ini dengan menggunakan modul UP [[WP:TW|Twinkle]].\n\n" +
"Apabila Anda tidak ingin menyimpan log ini, matikan di [[Wikipedia:Twinkle/Preferences|preferences panel]], dan " +
"usulkan penghapusan cepat halaman ini dengan kriteria [[WP:KPC#U1|KPC U1]].\n";
}
 
// create monthly header if it doesn't exist already
var date = new Date();
var headerRe = new RegExp("^==+\\s*" + date.getUTCMonthName() + "\\s+" + date.getUTCFullYear() + "\\s*==+", "m");
if (!headerRe.exec(text)) {
text += "\n\n=== " + date.getUTCMonthName() + " " + date.getUTCFullYear() + " ===";
}
 
var summarytext;
if (params.logEndorsing) {
textlogText += "\n# [[:" + Morebits.pageNameNorm + "]]: 'mendukung "' + (params.blp ? "'BLP "' : (params.book ? "'BOOK"' : "")'') + "UP'PROD. ~~~~~"';
if (params.reason) {
textlogText += "\n#* '''Alasan''': " + params.reason + "'\n"';
}
summarytextsummaryText = "'Mencatat dukungan nominasi penghapusan [[:"' + Morebits.pageNameNorm + "']]."';
} else {
textlogText += "\n# [[:" + Morebits.pageNameNorm + "]]: " + (params.blp ? "'BLP "' : (params.book ? "'BOOK"' : "")'') + "UP"'PROD';
if (params.logInitialContrib) {
textlogText += "'; memberitahukan {{user|"' + params.logInitialContrib + "'}}"';
}
textlogText += "' ~~~~~\n"';
if (!params.blp) {
textlogText += "#* '''Alasan''': " + params.reason + "'\n"';
}
summarytextsummaryText = "'Mencatat nominasi UP dari [[:"' + Morebits.pageNameNorm + "']]."';
}
 
usl.log(logText, summaryText + Twinkle.getPref('summaryAd'));
pageobj.setPageText(text);
 
pageobj.setEditSummary(summarytext + Twinkle.getPref('summaryAd'));
pageobj.setCreateOption("recreate");
pageobj.save();
}
 
};
 
var prodtype;
 
if ( namespace === 'article' ) {
var prodtypes = form.prodtype;
for( (var i = 0; i < prodtypes.length; i++ ) {
if ( prodtypes[i].checked ) {
prodtype = prodtypes[i].values;
break;
};
 
Morebits.simpleWindow.setButtonsEnabled( false );
Morebits.status.init( form );
 
var talk_title = new mw.Title(mw.config.get('wgPageName')).getTalkPage().getPrefixedText();
// Talk page templates for PROD-able discussions
var blocking_templates = 'Template:Old XfD multi|Template:Old MfD|Template:Oldffdfull|' + // Common prior XfD talk page templates
'Template:Oldpuffull|' + // Legacy prior XfD template
'Template:Olddelrev|' + // Prior DRV template
'Template:Old prod';
var query = {
'action': 'query',
'prop': 'categories',
'titles': talk_title,
'prop': 'templates',
'clcategories': 'Kategori:Usulan penghapusan yang selesai didiskusikan'
'tltemplates': blocking_templates
};
 
 
 
// </nowiki>