MediaWiki:Gadget-twinklebatchundelete.js: Perbedaan revisi

Repo at 5c1e7e3: Use Morebits.date .calendar to format protection confirmations/notes; Put sysop check first; overhaul action complete status messages
(Repo at a491314: Update from upstream)
(Repo at 5c1e7e3: Use Morebits.date .calendar to format protection confirmations/notes; Put sysop check first; overhaul action complete status messages)
 
// <nowiki>
 
 
(function($) {
 
 
* Mode of invocation: Tab ("Und-batch")
* Active on: Existing user and project pages
* Config directives in: TwinkleConfig
*/
 
 
Twinkle.batchundelete = function twinklebatchundelete() {
if( (!Morebits.userIsSysop || !mw.config.get("wgNamespaceNumber"'wgArticleId') !==|| mw.config.get("wgNamespaceIds").user &&
mw.config.get("'wgNamespaceNumber"') !== mw.config.get("'wgNamespaceIds"').projectuser ) ||&&
!mw.config.get("wgArticleId"'wgNamespaceNumber') !== mw.config.get('wgNamespaceIds').project)) {
return;
}
Twinkle.addPortletLink( Twinkle.batchundelete.callback, "'Und-batch"', "'tw-batch-undel"', "Undelete 'em all" );
if( Morebits.userIsInGroup( 'sysop' ) ) {
Twinkle.addPortletLink( Twinkle.batchundelete.callback, "Und-batch", "tw-batch-undel", "Undelete 'em all" );
}
};
 
Twinkle.batchundelete.callback = function twinklebatchundeleteCallback() {
var Window = new Morebits.simpleWindow( 600, 400 );
Window.setScriptName("'Twinkle"');
Window.setTitle("'Batch undelete"');
Window.addFooterLink('Bantuan "Twinkle help"', "'WP:TW/DOC#batchundelete" ');
 
var form = new Morebits.quickForm( Twinkle.batchundelete.callback.evaluate );
form.append( {
type: 'checkbox',
list: [
{
label: 'Restore talk pages of undeleted pages if they existed',
name: 'undel_talk',
value: 'undel_talk',
checked: true
}
]
} );
form.append( {
type: 'input',
name: 'reason',
label: 'Reason: ',
size: 60
} );
 
var statusdiv = document.createElement( 'div' );
statusdiv.style.padding = '15px'; // just so it doesn't look broken
Window.setContent(statusdiv);
'prop': 'info',
'inprop': 'protection',
'titles': mw.config.get("'wgPageName"'),
'gpllimit' : Twinkle.getPref('batchMax') // the max for sysops
};
var statelem = new Morebits.status("'Grabbing list of pages"');
var wikipedia_api = new Morebits.wiki.api( "'loading..."', query, function( apiobj ) {
var xml = apiobj.responseXML;
var $pages = $(xml).find('page[missing]');
var list = [];
$pages.each(function(index, page) {
var $page = $(page);
var title = $page.attr('title');
var $editprot = $page.find('pr[type="create"][level="sysop"]');
var isProtected = $editprot.length > 0;
 
list.push({
label: title + (isProtected ? ' (fully create protected' + ($editprot.attr('expiry') === 'infinity' ? ' indefinitely' : (', expires ' + $editprot.attr('expiry'))) + ')' : ''),
($editprot.attr('expiry') === 'infinity' ? ' indefinitely' : ', expires ' + new Morebits.date($editprot.attr('expiry')).calendar('utc') + ' (UTC)') + ')' : ''),
value: title,
checkedvalue: truetitle,
checked: true,
style: (isProtected ? 'color:red' : '')
});
});
});
apiobj.params.form.append({ type: 'header', label: 'Pages to undelete' });
apiobj.params.form.append({ type: 'header', label: 'Pages to undelete' });
apiobj.params.form.append({
type: 'button',
labeltype: "Select All"'button',
eventlabel: function(e)'Select {All',
event: function(e) {
$(Morebits.quickForm.getElements(e.target.form, 'pages')).prop('checked', true);
}
});
});
apiobj.params.form.append({
apiobj.params.form.append( {
type: 'button',
labeltype: "Deselect All"'button',
eventlabel: function(e)'Deselect {All',
event: function(e) {
$(Morebits.quickForm.getElements(e.target.form, 'pages')).prop('checked', false);
}
});
});
apiobj.params.form.append( {
apiobj.params.form.append( { type:'submit' } );
type: 'checkbox',
nametype: 'pagescheckbox',
listname: list'pages',
});list: list
});
apiobj.params.form.append( { type:'submit' } );
apiobj.params.form.append({ type: 'header', label: 'Pages to undeletesubmit' });
 
var result = apiobj.params.form.render();
apiobj.params.Window.setContent( result );
 
Morebits.checkboxShiftClickSupport(Morebits.quickForm.getElements(result, 'pages'));
}, statelem );
wikipedia_api.params = { form: form, Window: Window };
wikipedia_api.post();
};
 
Twinkle.batchundelete.callback.evaluate = function( event ) {
Morebits.wiki.actionCompleted.notice = 'StatusBatch undeletion is now complete';
Morebits.wiki.actionCompleted.postfix = 'batch undeletion is now complete';
 
var numProtected = $(Morebits.quickForm.getElements(event.target, 'pages')).filter(function(index, element) {
return element.checked && element.nextElementSibling.style.color === 'red';
}).length;
if (numProtected > 0 && !confirm("'You are about to undelete "' + numProtected + "' fully create protected page(s). Are you sure?"')) {
return;
}
 
var pages = event.target.getChecked( 'pages' );
var reason = event.target.reason.value;
var undel_talk = event.target.reason.value;
if ( ! reason ) {
alert("'You need to give a reason, you cabal crony!"');
return;
}
Morebits.simpleWindow.setButtonsEnabled(false);
Morebits.status.init( event.target );
 
if ( !pages ) {
Morebits.status.error( 'Error', 'nothing to undelete, aborting' );
return;
}
 
 
var pageUndeleter = new Morebits.batchOperation("'Undeleting pages"');
pageUndeleter.setOption("'chunkSize"', Twinkle.getPref('batchUndeleteChunks'));
pageUndeleter.setOption("'preserveIndividualStatusLines"', true);
pageUndeleter.setPageList(pages);
pageUndeleter.run(function(pageName) {
};
 
var wikipedia_page = new Morebits.wiki.page( pageName, 'Undeleting page ' + pageName );
wikipedia_page.setCallbackParameters(params);
wikipedia_page.setEditSummary(reason + Twinkle.getPref('deletionSummaryAd'));
// this stupid parameter name is a temporary thing until I implement an overhaul
// of Morebits.wiki.* callback parameters
doExtras: function( thingWithParameters ) {
var params = thingWithParameters.parent ? thingWithParameters.parent.getCallbackParameters() :
thingWithParameters.getCallbackParameters();
var query, wikipedia_api;
 
if ( params.undel_talk ) {
var talkpagename = new mw.Title(params.page).getTalkPage().getPrefixedText();
if (talkpagename !== params.page) {
'titles': talkpagename
};
wikipedia_api = new Morebits.wiki.api( 'Checking talk page for deleted revisions', query, Twinkle.batchundelete.callbacks.undeleteTalk );
wikipedia_api.params = params;
wikipedia_api.params.talkPage = talkpagename;
}
},
undeleteTalk: function( apiobj ) {
var xml = apiobj.responseXML;
var exists = $(xml).find('page:not([missing])').length > 0;
var delrevs = $(xml).find('rev').attr('revid');
 
if ( exists || !delrevs ) {
// page exists or has no deleted revisions; forget about it
return;
}
 
var page = new Morebits.wiki.page(apiobj.params.talkPage, "'Undeleting talk page of "' + apiobj.params.page);
page.setEditSummary("'Undeleting [[Help:Talk page|talk page]] of \""' + apiobj.params.page + '"\""' + Twinkle.getPref('deletionSummaryAd'));
page.undeletePage();
}
 
 
// </nowiki>