User:Steel359/twinkle.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:Steel359/twinkle. |
// This is a slightly modified version of [[User:AzaToth/twinklespeedy.js]]. All credit goes to him for writing the script.
// <pre>
// If TwinkleConfig doesn't exist.
if( typeof( TwinkleConfig ) == 'undefined' ) {
TwinkleConfig = function() {};
}
/**
TwinkleConfig.addAdToSummary
If [[WP:TWINKLE|TWINKLE]] should be added or not to summary
*/
if( typeof( TwinkleConfig.addAdToSummary ) == 'undefined' ) {
TwinkleConfig.addAdToSummary = false;
}
/**
TwinkleConfig.addAdToDeletionSummary
If [[WP:TWINKLE|TWINKLE]] should be added or not to the deletion summary (admin only)
*/
if( typeof( TwinkleConfig.addAdToDeletionSummary ) == 'undefined' ) {
TwinkleConfig.addAdToDeletionSummary = false;
}
/**
TwinkleConfig.watchSpeedyPages (array)
What types of actions that should result in forced addition to watchlist
*/
if( typeof( TwinkleConfig.watchSpeedyPages ) == 'undefined' ) {
TwinkleConfig.watchSpeedyPages = [];
}
/**
TwinkleConfig.deleteTalkPageOnDelete
If talk page if exists should also be deleted (CSD G8) when spedying a page (admin only)
*/
if( typeof( TwinkleConfig.deleteTalkPageOnDelete ) == 'undefined' ) {
TwinkleConfig.deleteTalkPageOnDelete = true;
}
function twinkleSpeedyDelete() {
if( wgNamespaceNumber < 0 || wgCurRevisionId == false ) {
return;
}
if( userIsInGroup( 'sysop' ) ) {
addPortletLink('p-cactions', "javascript:twinklespeedy( 'csd' )", "speedy", "ca-db0", "Speedy delete using Twinkle javascript", "");
addPortletLink('p-cactions', "javascript:twinklespeedy( 'reason' )", "speedy (reason)", "ca-db0", "Speedy delete with reason", "");
}
}
addOnloadHook(twinkleSpeedyDelete);
function twinklespeedy( type ) {
twinklespeedy.type = type;
switch( type ) {
case 'csd':
twinklespeedy.Window = new SimpleWindow(100, 430 );
twinklespeedy.Window.setTitle( "" );
function createOption( value, text ) {
var div = document.createElement( 'div' );
var input = document.createElement( 'input' );
input.value = value;
input.name = 'csd';
input.id = 'wp' + value;
input.type = 'radio';
var label = document.createElement( 'label' );
label.setAttribute( 'for', value );
label.appendChild( document.createTextNode( text ) );
div.appendChild( input );
div.appendChild( label );
return div;
}
var form = document.createElement( 'form' );
form.addEventListener( 'change', twinklespeedy.csd, true );
form.appendChild( createOption( 'A7', 'CSD A7' ) );
form.appendChild( createOption( 'A7/G11', 'CSD A7/G11' ) );
form.appendChild( createOption( 'G11', 'CSD G11' ) );
form.appendChild( createOption( 'G8', 'CSD G8' ) );
form.appendChild( document.createElement( 'hr' ) );
form.appendChild( createOption( 'A1', 'CSD A1' ) );
form.appendChild( createOption( 'A3', 'CSD A3' ) );
form.appendChild( createOption( 'G1', 'CSD G1' ) );
form.appendChild( createOption( 'G4', 'CSD G4' ) );
form.appendChild( createOption( 'G7', 'CSD G7' ) );
form.appendChild( createOption( 'G10', 'CSD G10' ) );
form.appendChild( createOption( 'G12', 'CSD G12' ) );
form.appendChild( document.createElement( 'hr' ) );
form.appendChild( createOption( 'OR', 'Essay' ) );
form.appendChild( createOption( 'Orph', 'Orphaned' ) );
form.appendChild( createOption( 'Neo', 'Neologism' ) );
form.appendChild( createOption( 'Ball', 'Crystal ball' ) );
form.appendChild( createOption( 'none', '<No reason>' ) );
form.appendChild( document.createElement( 'hr' ) );
form.appendChild( createOption( 'R1', 'CSD R1' ) );
form.appendChild( createOption( 'R2', 'CSD R2' ) );
form.appendChild( createOption( 'I3', 'CSD I3' ) );
form.appendChild( createOption( 'G3', 'CSD G3' ) );
twinklespeedy.Window.setContent( form );
twinklespeedy.Window.display();
break;
case 'reason':
var criteria = prompt( "" );
if( !criteria ) {
return; // User abort action
}
if( userIsInGroup( 'sysop' ) ) {
twinklespeedy.summary = "" + criteria + "" + ( TwinkleConfig.addAdToDeletionSummary ? ' [[WP:TWINKLE|TWINKLE]].' : '');
} else {
twinklespeedy.summary = "Requesting speedy deletion." + ( TwinkleConfig.addAdToSummary ? ' [[WP:TWINKLE|TWINKLE]]' : '');
}
twinklespeedy.code = "{{d" + "b" + ( criteria ? '|' + criteria : '' ) + "}}";
Status.init( document.getElementById('bodyContent') );
Status.status( 'Running script' );
editXML = sajax_init_object();
editXML.overrideMimeType('text/xml');
if( userIsInGroup( 'sysop' ) ) {
editXML.open( 'GET' , wgServer + wgScriptPath + '/index.php?' + QueryString.create( { 'title': wgPageName, 'action': 'delete' } ), true);
} else {
editXML.open( 'GET' , wgServer + wgScriptPath + '/index.php?' + QueryString.create( { 'title': wgPageName, 'action': 'submit' } ), true);
}
editXML.onreadystatechange = twinklespeedyCallback;
editXML.send( null );
break;
}
}
twinklespeedy.csd = function(e) {
var convarr = {
'A7': '[[WP:CSD|CSD A7]] (not notable)',
'A7/G11': '[[WP:CSD|CSD A7/G11]] (spam, not notable)',
'G11': '[[WP:CSD|CSD G11]] (spam)',
'G8': '[[WP:CSD|CSD G8]] (orphaned talk page)',
'A1': '[[WP:CSD|CSD A1]] (no context)',
'A3': '[[WP:CSD|CSD A3]] (empty)',
'G1': '[[WP:CSD|CSD G1]] (nonsense)',
'G4': '[[WP:CSD|CSD G4]] (recreation of material deleted per [[WP:XFD|XfD]])',
'G7': '[[WP:CSD|CSD G7]] (author request)',
'G10': '[[WP:CSD|CSD G10]] (attack page)',
'G12': '[[WP:CSD|CSD G12]] (copyvio)',
'OR': 'Essay',
'Orph': 'Orphaned',
'Neo': 'Neologism',
'Ball': 'Crystal ball',
'none': '',
'R1': '[[WP:CSD|CSD R1]] (broken redirect)',
'R2': '[[WP:CSD|CSD R2]] (redirect to userspace)',
'I3': '[[WP:CSD|CSD I3]] (bad image license)',
'G3': '[[WP:CSD|CSD G3]] (vandalism)',
};
var reasarr = {
'A7': '',
'A7/G11': '',
'G11': '',
'G8': '',
'A1': '',
'A3': '',
'G1': '',
'G4': '',
'G7': '',
'G10': '',
'G12': '',
'OR': '',
'Orph': '',
'Neo': '',
'Ball': '',
'none': '',
'R1': '',
'R2': '',
'I3': '',
'G3': '',
};
var value = e.target.value;
var normalized = convarr[ value ];
twinklespeedy.watch = TwinkleConfig.watchSpeedyPages.indexOf( normalized ) != -1;
var reason = reasarr[ value ];
if( userIsInGroup( 'sysop' ) ) {
twinklespeedy.summary = "" + normalized + "" + reason + "" + ( TwinkleConfig.addAdToDeletionSummary ? ' [[WP:TWINKLE|TWINKLE]]' : '');
} else {
twinklespeedy.summary = "Requesting speedy deletion ([[WP:CSD#" + normalized + "|CSD " + normalized + "]])." + ( TwinkleConfig.addAdToSummary ? ' [[WP:TWINKLE|TWINKLE]]' : '');
switch( normalized ) {
case 'i8':
var date = new Date();
twinklespeedy.code = "{{" + "NowCommons" + "|month=" + date.getUTCMonthName() + "|day=" + date.getUTCDate() + "|year=" + date.getUTCFullYear() + "|1=" + wgPageName.replace( '_', ' ' ) + "}}";
break;
case 'g12':
url = prompt( 'Please enter url if available, including the http://' );
if( url == null ) {
return;
}
twinklespeedy.code = "{{d" + "b-" + value + "|url=" + url + "}}";
break;
case 'i1':
img = prompt( 'enter the image this is redundant to, excluding the Image: prefix' );
if( img == null ) {
return;
}
twinklespeedy.code = "{{d" + "b-" + value + "|1=" + img + "}}";
break;
default:
twinklespeedy.code = "{{d" + "b-" + value + "}}";
break;
}
}
twinklespeedy.Window.close();
Status.init( document.getElementById('bodyContent') );
Status.status( 'Running script' );
editXML = sajax_init_object();
editXML.overrideMimeType('text/xml');
if( userIsInGroup( 'sysop' ) ) {
editXML.open( 'GET' , wgServer + wgScriptPath + '/index.php?' + QueryString.create( { 'title': wgPageName, 'action': 'delete' } ), true);
} else {
editXML.open( 'GET' , wgServer + wgScriptPath + '/index.php?' + QueryString.create( { 'title': wgPageName, 'action': 'submit' } ), true);
}
editXML.onreadystatechange = twinklespeedyCallback;
editXML.send( null );
}
function twinklespeedyCallback() {
if ( editXML.readyState != 4 ){
Status.progress('.');
return;
}
if( editXML.status != 200 ){
Status.error('Bad status , bailing out');
return;
}
Status.progress('');
// when we grabbed the page, it wasn't there
if( editXML.responseText.indexOf( 'var wgCurRevisionId = false;' ) != -1 ) {
Status.error( "Page doesn't exist." );
return;
}
var doc = editXML.responseXML;
var form;
if( userIsInGroup( 'sysop' ) ) {
Status.status( 'Deleting...' );
form = doc.getElementById( 'deleteconfirm' );
form.style.display = 'none';
doc.getElementById( 'wpReason' ).value = twinklespeedy.summary;
if( TwinkleConfig.deleteTalkPageOnDelete && wgNamespaceNumber % 2 == 0 && document.getElementById( 'ca-talk' ).className != 'new' ) {
Status.status( 'Deleting talk page...' );
var talk_page = namespaces[ wgNamespaceNumber + 1 ] + ':' + wgTitle;
var query = {
'title': talk_page,
'action': 'delete',
};
talkPageXML = sajax_init_object();
talkPageXML.overrideMimeType('text/xml');
talkPageXML.open( 'GET' , wgServer + wgScriptPath + '/index.php?' + QueryString.create( query ), false);
talkPageXML.send( null );
var talkdoc = talkPageXML.responseXML;
if( talkdoc.getElementById( 'deleteconfirm' ) ) {
var postData = {
'wpReason': "[[WP:CSD|CSD G8]] (orphaned talk page)",
'wpEditToken': talkdoc.getElementsByTagName('form')[0].wpEditToken.value
}
talkPageXML = sajax_init_object();
talkPageXML.overrideMimeType('text/xml');
talkPageXML.open( 'POST' , wgServer + wgScriptPath + '/index.php?' + QueryString.create( query ), false);
talkPageXML.setRequestHeader('Content-type','application/x-www-form-urlencoded');
talkPageXML.send( QueryString.create( postData ) );
} else {
Status.warn( 'Talk page already deleted.' );
}
}
} else {
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 tag = /(\{\{(?:db-?|delete)\|?.*?\}\})/.exec( text );
if( tag ) {
Status.warn( [ htmlNode( 'strong', tag[0] ) , " is alread placed on the page." ] )
return;
}
var xfd = /(\{\{(?:[aitcm]fd|md1)[^{}]*?\}\})/i.exec( text );
if( xfd && !confirm( "The deletion related template " + xfd[0] + " is already present on the page, do you still want to revert?" ) ) {
return;
}
Status.progress('');
Status.status( 'Submitting form...' );
textbox.value = twinklespeedy.code + "\n" + textbox.value;
doc.getElementById( 'wpSummary' ).value = twinklespeedy.summary;
doc.getElementById( 'wpMinoredit' ).checked = true;
if( twinklespeedy.watch ) {
doc.getElementById( 'wpWatchthis' ).checked = true;
}
}
document.getElementById('globalWrapper').appendChild( form );
form.submit();
Status.progress('');
}