User:Ryalla~simplewiki/salt.js

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
// <pre>
 
$(saltPageTab);
 
var saltTarget = "Wikipedia:Protected titles/Twinkle";
 
function saltPageTab() {
 if( wgCurRevisionId != false || wgNamespaceNumber < 0 || ! userIsInGroup( 'sysop' ) ) {
 return;
 }
 mw.util.addPortletLink('p-cactions', "javascript:saltPage()", "salt", "ca-salt", "Salt this page using cascading protection", "");
}
 
function saltPage() {
 Status.init( document.getElementById('bodyContent') );
 editXML = sajax_init_object();
 editXML.overrideMimeType('text/xml');
 var query = {
 'title': saltTarget,
 'action': 'submit'
 }
 Status.status( 'Finding page...' );
 editXML.open( 'GET' , mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + QueryString.create( query ) , false);
 
 editXML.send( null );
 
 var doc = editXML.responseXML;
 var form = doc.getElementById( 'editform' );
 var title = wgPageName.replace( /_/g, ' ' );
 
 var text = form.wpTextbox1.value;
 
 if( text.match( new RegExp( RegExp.escape(title) ) ) ) {
 Status.info( 'Already salted.' );
 return;
 }
 
 text += '*{{:' + title + '}} ([[Special:Undelete/' + title + '|history]]) ~~~~';
 
 var postData = {
 'wpSummary': 'Adding [[' + title + ']]',
 'wpWatchthis': form.wpWatchthis.checked,
 'wpStarttime': form.wpStarttime.value,
 'wpEdittime': form.wpEdittime.value,
 'wpEditToken': form.wpEditToken.value,
 'wpAutoSummary': form.wpAutoSummary.value,
 'wpTextbox1': text
 }
 
 Status.status( 'Adding ' + title + '...' );
 
 editXML = sajax_init_object();
 editXML.overrideMimeType('text/xml');
 editXML.open( 'POST' , mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + QueryString.create( query ) , false);
 editXML.setRequestHeader('Content-type','application/x-www-form-urlencoded');
 editXML.send( QueryString.create( postData ) );
 
 Status.info( 'Salted.' );
 
}
 
// </pre>