User:Rei-artur/monobook.js
From Wikipedia
Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: hold Ctrl while clicking Refresh, or press Ctrl-F5; Konqueror:: simply click the Reload button, or press F5; Opera users may need to completely clear their cache in Tools→Preferences.
document.write('<script type="text/javascript" src="'
+ 'http://test.wikipedia.org/w/index.php?title=User:Steel359/enscripts.js'
+ '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
// If TwinkleConfig aint exist.
if( typeof( TwinkleConfig ) == 'undefined' ) {
TwinkleConfig = function() {};
}
/**
TwinkleConfig.summaryAd (string)
If ad should be added or not to summary, default [[WP:TWINKLE|TWINKLE]]
*/
if( typeof( TwinkleConfig.summaryAd ) == 'undefined' ) {
TwinkleConfig.summaryAd = " using [[WP:TWINKLE|TW]]";
}
/**
TwinkleConfig.protectionSummaryAd (string)
If ad should be added or not to protection summary, default [[WP:TWINKLE|TWINKLE]]
*/
if( typeof( TwinkleConfig.protectionSummaryAd ) == 'undefined' ) {
TwinkleConfig.protectionSummaryAd = " using [[WP:TWINKLE|TW]]";
}
function twinkleProtectButton() {
if( wgNamespaceNumber < 0 || wgCurRevisionId == false ) {
return;
}
if( userIsInGroup( 'sysop' ) ) {
addPortletLink('p-cactions', "javascript:twinkleprotect()", "twinkleprotect", "tw-rpp", "Protect page", "");
} else {
addPortletLink('p-cactions', "javascript:twinkleprotect()", "rpp", "tw-rpp", "Request page protection", "");
}
}
addOnloadHook(twinkleProtectButton);
function twinkleprotect() {
twinkleprotect.Window = new SimpleWindow( 250, 190 );
twinkleprotect.Window.setTitle( "Twinkleprotect javascript" );
function createLabel( data ) {
var label = document.createElement( 'label' );
label.setAttribute( 'for', data.target );
label.appendChild( document.createTextNode( data.label ) );
return label;
}
function createOption( data ) {
var option = document.createElement( 'option' );
option.setAttribute( 'value', data.value );
if( data.selected ) {
option.setAttribute( 'selected', 'selected' );
}
option.setAttribute( 'label', data.label );
option.appendChild( document.createTextNode( data.label ) );
return option;
}
function createOptGroup( label ) {
var optgroup = document.createElement( 'optgroup' );
optgroup.setAttribute( 'label', label );
return optgroup;
}
function createInput( data ) {
var div = document.createElement( data.elem || 'span' );
var input = document.createElement( 'input' );
input.setAttribute( 'value', data.value );
input.setAttribute( 'name', data.name );
input.setAttribute( 'id', data.id );
input.setAttribute( 'type', data.type );
if( data.size ) {
input.setAttribute( 'size', data.size );
}
if( data.checked ) {
input.setAttribute( 'checked', 'checked' );
}
if( data.diabled ) {
input.setAttribute( 'disabled', 'disabled' );
}
if( data.event && data.type == 'button' ){
input.addEventListener( 'click', data.event, true );
}
if( data.type == 'button' || data.type == 'submit' || data.type == 'reset' ) {
div.appendChild( input );
} else {
var label = document.createElement( 'label' );
label.setAttribute( 'for', data.id );
label.appendChild( document.createTextNode( data.text ) );
if( [ 'radio', 'checkbox' ].indexOf( data.type ) != -1 ) {
div.appendChild( input );
div.appendChild( label );
} else {
div.appendChild( label );
div.appendChild( input );
}
}
return div;
}
twinkleprotect.form = document.createElement( 'form' );
twinkleprotect.form.setAttribute( 'action', 'javascript:void(0);');
twinkleprotect.form.addEventListener( 'submit',twinkleprotect.evaluate , true );
var main_choices = document.createElement( 'select' );
main_choices.setAttribute('name', 'main_choices');
main_choices.setAttribute('id', 'twProtMainChoices');
var full = createOptGroup( 'Full protection' );
full.appendChild( createOption( { label: 'Dispute', selected: true, value: 'full_dispute' } ) );
full.appendChild( createOption( { label: 'Vandalism', value: 'full_vandalism' } ) );
full.appendChild( createOption( { label: 'High traffic', value: 'full_traffic' } ) );
full.appendChild( createOption( { label: 'High visible template', value: 'full_template' } ) );
full.appendChild( createOption( { label: 'User talk of banned user', value: 'full_usertalk' } ) );
full.appendChild( createOption( { label: 'Privacy', value: 'full_privacy' } ) );
var semi = createOptGroup( 'Semi-protection' );
semi.appendChild( createOption( { label: 'High traffic', value: 'semi_traffic' } ) );
semi.appendChild( createOption( { label: 'User talk of banned user', value: 'semi_usertalk' } ) );
semi.appendChild( createOption( { label: 'Spambot target', value: 'semi_spambot' } ) );
semi.appendChild( createOption( { label: 'Other semiprotection', value: 'semi_semi' } ) );
var other = createOptGroup( 'Other' );
other.appendChild( createOption( { label: 'Move-protection', value: 'move' } ) );
other.appendChild( createOption( { label: 'Unprotection', value: 'un' } ) );
main_choices.appendChild( full );
main_choices.appendChild( semi );
main_choices.appendChild( other );
main_choices.addEventListener( 'change',twinkleprotect.defaultnoinclude , true );
var choices = document.createElement( 'fieldset' );
var choices_legend = document.createElement( 'legend' );
choices_legend.appendChild( document.createTextNode( 'Protection specifics' ) );
choices.appendChild( document.createElement( 'br' ) );
choices.appendChild( choices_legend );
choices.appendChild( main_choices );
choices.appendChild( createInput( {
id:'twProtNoinclude',
name:'noinclude',
type:'checkbox',
text:'<noinclude> tags?',
checked:(wgNamespaceNumber==10)
}) );
choices.appendChild( document.createElement( 'br' ) );
choices.appendChild( createInput( {
id:'twProtCascade',
name:'cascade',
type:'checkbox',
text:'Enable cascade protection',
checked:(wgNamespaceNumber==0)
}) );
var expiry = document.createElement( 'select' );
expiry.setAttribute('name', 'expiry');
expiry.setAttribute('id', 'twProtExpiry');
expiry.appendChild( createOption( { label: '1 hour', value: '1 hour' } ) );
expiry.appendChild( createOption( { label: '3 hours', value: '3 hours' } ) );
expiry.appendChild( createOption( { label: '6 hours', value: '6 hours' } ) );
expiry.appendChild( createOption( { label: '12 hours', value: '12 hours' } ) );
expiry.appendChild( createOption( { label: '1 day', value: '1 day' } ) );
expiry.appendChild( createOption( { label: '2 days', value: '2 days' } ) );
expiry.appendChild( createOption( { label: '3 days', value: '3 days' } ) );
expiry.appendChild( createOption( { label: '5 days', value: '5 days' } ) );
expiry.appendChild( createOption( { label: '1 week', value: '1 week' } ) );
expiry.appendChild( createOption( { label: '2 weeks', value: '2 weeks' } ) );
expiry.appendChild( createOption( { label: '3 weeks', value: '3 weeks' } ) );
expiry.appendChild( createOption( { label: '4 weeks', value: '4 weeks' } ) );
expiry.appendChild( createOption( { label: '5 weeks', value: '5 weeks' } ) );
expiry.appendChild( createOption( { label: '6 weeks', value: '6 weeks' } ) );
expiry.appendChild( createOption( { label: '10 weeks', value: '10 weeks' } ) );
expiry.appendChild( createOption( { label: 'indefinite', selected: true, value: null } ) );
choices.appendChild( document.createElement( 'br' ) );
choices.appendChild( createLabel( { target:'twProtExpiry', label:'Expiry' } ) );
choices.appendChild( expiry );
twinkleprotect.main_choices = main_choices;
twinkleprotect.form.appendChild( choices );
twinkleprotect.form.appendChild( createInput( {
id:'twProtReason',
value:'',
text:'Reason ',
type:'text',
name:'rppreason',
size:30
} ) );
twinkleprotect.form.appendChild( createInput( {
id:'twProtSubmit',
value:'Submit report',
name:'submit',
type:'submit'
} ) );
twinkleprotect.Window.setContent( twinkleprotect.form );
twinkleprotect.Window.display();
}
twinkleprotect.defaultnoinclude = function(e) {
if( twinkleprotect.form.main_choices.value == 'un' ) {
twinkleprotect.form.noinclude.disabled = true;
twinkleprotect.form.cascade.disabled = true;
twinkleprotect.form.expiry.disabled = true;
} else {
twinkleprotect.form.noinclude.disabled = false;
twinkleprotect.form.cascade.disabled = false;
twinkleprotect.form.expiry.disabled = false;
}
if( twinkleprotect.form.main_choices.value == 'full_template' ) {
twinkleprotect.form.noinclude.checked = true;
} else {
twinkleprotect.form.noinclude.checked = false;
}
}
twinkleprotect.evaluate = function(e) {
twinkleprotect.type = twinkleprotect.form.main_choices.value;
if( twinkleprotect.type == null ) {
Status.error( 'no action given' );
return;
}
twinkleprotect.noinclude = twinkleprotect.form.noinclude.checked;
twinkleprotect.cascade = twinkleprotect.form.cascade.checked;
twinkleprotect.reason = twinkleprotect.form.rppreason.value;
twinkleprotect.expiry = twinkleprotect.form.expiry.value;
Status.init( twinkleprotect.form );
if( userIsInGroup( 'sysop' ) ) {
Status.status( 'Running script...' );
protXML = sajax_init_object();
protXML.overrideMimeType('text/xml');
var query = {
'title': wgPageName,
'action': 'protect'
}
protXML.open( 'GET' , wgServer + wgScriptPath + '/index.php?' + QueryString.create( query ), true);
protXML.onreadystatechange = twinkleprotect.sysopProtect1;
protXML.send( null );
} else {
Status.status( 'Grabbing WP:RFPP' );
editXML = sajax_init_object();
editXML.overrideMimeType('text/xml');
var query = {
'title': 'Wikipedia:Requests for page protection',
'action': 'submit'
};
editXML.open( 'GET' , wgServer + wgScriptPath + '/index.php?' + QueryString.create( query ), true);
editXML.onreadystatechange = twinkleprotect.callback;
editXML.send( null );
}
}
twinkleprotect.sysopProtect1 = function() {
if ( protXML.readyState != 4 ){
Status.progress('.');
return;
}
if( protXML.status != 200 ){
Status.error('Bad status, bailing out');
return;
}
var doc = protXML.responseXML;
var editToken = doc.getElementsByTagName('form')[0].wpEditToken.value;
Status.status( 'Protecting page...' );
var edit, move, tag, reason;
switch( twinkleprotect.type ) {
case 'full_dispute':
edit = 'sysop';
move = 'sysop';
reason = 'Full protection: Dispute';
break;
case 'full_vandalism':
edit = 'sysop';
move = 'sysop';
reason = 'Full protection: Vandalism';
break;
case 'full_traffic':
edit = 'sysop';
move = 'sysop';
reason = 'Full protection: High-traffic page';
break;
case 'full_template':
edit = 'sysop';
move = 'sysop';
reason = 'Full protection: High-visible template';
break;
case 'full_usertalk':
edit = 'sysop';
move = 'sysop';
reason = 'Full protection: User talk of banned user';
break;
case 'full_privacy':
edit = 'sysop';
move = 'sysop';
reason = 'Full protection: Privacy concern';
break;
case 'semi_traffic':
edit = 'autoconfirmed';
move = 'autoconfirmed';
reason = 'Semi-protection: High-traffic page';
break;
case 'semi_usertalk':
edit = 'autoconfirmed';
move = 'autoconfirmed';
reason = 'Semi-protection: User talk of banned user';
break;
case 'semi_spambot':
edit = 'autoconfirmed';
move = 'autoconfirmed';
reason = 'Semi-protection: Spambot target';
break;
case 'semi_semi':
edit = 'autoconfirmed';
move = 'autoconfirmed';
reason = 'Semi-protection';
break;
case 'move':
edit = '';
move = 'sysop';
reason = 'Move-protection';
break;
case 'un':
default:
edit = '';
move = '';
reason = 'Unprotection';
break;
}
twinkleprotect.tag = tag;
if( twinkleprotect.reason ) {
reason += ', ' + twinkleprotect.reason;
}
reason += '.';
twinkleprotect.reason = reason;
var postData = {
'wpEditToken': editToken,
'mwProtect-level-edit': edit,
'mwProtect-level-move': move,
'mwProtect-reason': reason + TwinkleConfig.protectionSummaryAd
};
if( twinkleprotect.expiry != null && twinkleprotect.type != 'un') {
postData['mwProtect-expiry'] = twinkleprotect.expiry;
}
if( twinkleprotect.cascade && twinkleprotect.type != 'un') {
postData['mwProtect-cascade'] = true;
}
var query = {
'title': wgPageName,
'action': 'protect'
}
if( twinkleprotect.type == 'un' ) {
protXML = sajax_init_object();
protXML.overrideMimeType('text/xml');
protXML.open( 'POST' , wgServer + wgScriptPath + '/index.php?' + QueryString.create( query ), true);
protXML.setRequestHeader('Content-type','application/x-www-form-urlencoded');
protXML.send( QueryString.create( postData ) );
Status.status( 'Adding appropriate temlate to protected page' );
query = {
'title': wgPageName,
'action': 'submit'
}
editXML = sajax_init_object();
editXML.overrideMimeType('text/xml');
editXML.open( 'GET' , wgServer + wgScriptPath + '/index.php?' + QueryString.create( query ), false);
editXML.send( null );
var doc = editXML.responseXML;
var form = doc.getElementById( 'editform' );
form.style.display = 'none';
var text = form.wpTextbox1.value;
var summary = form.wpSummary.value;
var checkre = /\s*(?:<noinclude>)?\s*\{\{\s*(protected|(?:t|v|s|p-|usertalk-v|usertalk-s|sb|move)protected(?:2)?|protected template|privacy protection)\s*?\}\}\s*(?:<\/noinclude>)?\s*/gi;
text = text.replace( checkre, '' ); // Remove all old templates
summary = 'Unprotecting page'
var postData = {
'wpMinoredit': form.wpMinoredit.unchecked,
'wpWatchthis': form.wpWatchthis.unchecked,
'wpStarttime': form.wpStarttime.value,
'wpEdittime': form.wpEdittime.value,
'wpAutoSummary': form.wpAutoSummary.value,
'wpEditToken': form.wpEditToken.value,
'wpSummary': summary,
'wpTextbox1': text
};
editXML = sajax_init_object();
editXML.overrideMimeType('text/xml');
editXML.open( 'POST' , wgServer + wgScriptPath + '/index.php?' + QueryString.create( query ), false);
editXML.setRequestHeader('Content-type','application/x-www-form-urlencoded');
editXML.send( QueryString.create( postData ) );
Status.status('Protection successful, opening page history...');
window.location = wgServer + wgScriptPath + '/index.php?' + QueryString.create( {'title':wgPageName,'action':'history'} );
} else {
var postData = {
'wpMinoredit': form.wpMinoredit.unchecked,
'wpWatchthis': form.wpWatchthis.unchecked,
'wpStarttime': form.wpStarttime.value,
'wpEdittime': form.wpEdittime.value,
'wpAutoSummary': form.wpAutoSummary.value,
'wpEditToken': form.wpEditToken.value,
'wpSummary': summary,
'wpTextbox1': text
};
editXML = sajax_init_object();
editXML.overrideMimeType('text/xml');
editXML.open( 'POST' , wgServer + wgScriptPath + '/index.php?' + QueryString.create( query ), false);
editXML.setRequestHeader('Content-type','application/x-www-form-urlencoded');
editXML.send( QueryString.create( postData ) );
Status.status('Protection successful, opening page history...');
window.location = wgServer + wgScriptPath + '/index.php?' + QueryString.create( {'title':wgPageName,'action':'history'} );
}
twinkleprotect.callback = function() {
if ( editXML.readyState != 4 ){
Status.progress('.');
return;
}
if( editXML.status != 200 ){
Status.error('Bad status, bailing out');
return;
}
var doc = editXML.responseXML;
var form;
form = doc.getElementById( 'editform' );
form.style.display = 'none';
var textbox = doc.getElementById( 'wpTextbox1' );
var text = textbox.value;
Status.status( 'Checking for tags on the page...' );
var rppRe = new RegExp( '====.*?' + RegExp.escape( wgPageName, true ) + '.*?====', 'm' );
var tag = rppRe.exec( text );
if( tag ) {
Status.warn( [ htmlNode( 'strong', tag[0] ) , " is alread placed on the page." ] )
return false;
}
var ns2tag = {
'0' : 'la',
'1' : 'lat',
'2' : 'lu',
'3' : 'lut',
'4' : 'lw',
'5' : 'lwt',
'6' : 'li',
'7' : 'lit',
'8' : 'lm',
'9' : 'lmt',
'10': 'lt',
'11': 'ltt',
'12': 'lh',
'13': 'lht',
'14': 'lc',
'15': 'lct',
'100': 'lp',
'101': 'lpt'
};
var type = twinkleprotect.type;
if( type == null ) {
Status.error( 'no type specified, aborting,');
return;
}
var typename, reason;
switch( type ) {
case 'full_dispute':
case 'full_vandalism':
case 'full_traffic':
case 'full_template':
case 'full_usertalk':
case 'full_privacy':
typename = 'full protection';
break;
case 'semi_traffic':
case 'semi_usertalk':
case 'semi_spambot':
case 'semi_semi':
typename = 'semi-protection';
break;
case 'move':
typename = 'move-protection';
break;
case 'un':
typename = 'unprotection';
break;
default:
return;
}
var newtag = (
'==== {{' +
ns2tag[ wgNamespaceNumber ] +
'|' +
wgTitle +
'}} ====' +
"\n'''" +
typename +
"''' " +
( twinkleprotect.cascade ? " '''+cascade''', " : '' ) +
( twinkleprotect.expiry ? " '''+expiry " + twinkleprotect.expiry + "''', " : '' ) +
twinkleprotect.reason +
' ~~' +
'~~'
);
Status.info( newtag );
if( type == 'un' ) {
var str = "==Current requests for unprotection==\n{{Wikipedia:Requests for page protection/URheading}}";
textbox.value = textbox.value.replace( str, str + "\n" + newtag + "\n" );
} else {
var str = "==Current requests for protection==\n{{Wikipedia:Requests for page protection/PRheading}}";
textbox.value = textbox.value.replace( str, str + "\n" + newtag + "\n" );
}
Status.status( 'Submitting form...' );
doc.getElementById( 'wpSummary' ).value = "Requesting " + typename + ' of [[' + wgPageName.replace('_', ' ') + ']].' + TwinkleConfig.summaryAd;
doc.getElementById( 'wpMinoredit' ).checked = true;
document.getElementById('globalWrapper').appendChild( form );
form.submit();
}

