User:Mercury~enwiki/AzaToth/twinklespeedy.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:Mercury~enwiki/AzaToth/twinklespeedy. |
//<nowiki>
// If TwinkleConfig aint exist.
if( typeof( TwinkleConfig ) == 'undefined' ) {
TwinkleConfig = {};
}
/**
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.deletionSummaryAd (string)
If ad should be added or not to deletion summary, default [[WP:TWINKLE|TWINKLE]]
*/
if( typeof( TwinkleConfig.deletionSummaryAd ) == 'undefined' ) {
TwinkleConfig.deletionSummaryAd = " using [[WP:TWINKLE|TW]]";
}
/**
TwinkleConfig.watchSpeedyPages (array)
What types of actions that should result in forced addition to watchlist
*/
if( typeof( TwinkleConfig.watchSpeedyPages ) == 'undefined' ) {
TwinkleConfig.watchSpeedyPages = [ 'g3', 'g5', 'g10', 'g11', 'g12' ];
}
/**
TwinkleConfig.markSpeedyPagesAsMinor (boolean)
If, when applying speedy template to page, to mark the edit as minor, default true
*/
if( typeof( TwinkleConfig.markSpeedyPagesAsMinor ) == 'undefined' ) {
TwinkleConfig.markSpeedyPagesAsMinor = true;
}
/**
TwinkleConfig.openUserTalkPageOnSpeedyDelete (array)
What types of actions that should result user talk page to be opened
*/
if( typeof( TwinkleConfig.openUserTalkPageOnSpeedyDelete ) == 'undefined' ) {
TwinkleConfig.openUserTalkPageOnSpeedyDelete = [ 'g1', 'g2', 'g10', 'g11', 'g12', 'a1', 'a7', 'i3', 'i4', 'i5', 'i6', 'i7', 'u3', 't1' ];
}
/**
TwinkleConfig.userTalkPageMode may take arguments:
'window': open a new window, remmenber the opened window
'tab': opens in a new tab, if possible.
'blank': force open in a new window, even if a such window exist
*/
if( typeof( TwinkleConfig.userTalkPageMode ) == 'undefined' ) {
TwinkleConfig.userTalkPageMode = 'window';
}
/**
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 = false;
}
/**
TwinkleConfig.toolboxButtons (string)
If id defined in this array, the button of the action is located inthe toolbox instead of in
the actions bar.
*/
if( typeof( TwinkleConfig.toolboxButtons ) == 'undefined' ) {
TwinkleConfig.toolboxButtons = [];
}
function twinkleSpeedyDelete() {
if( wgNamespaceNumber < 0 || wgCurRevisionId == false ) {
return;
}
if( userIsInGroup( 'sysop' ) ) {
mw.util.addPortletLink( chooseBox( 'tw-csd', TwinkleConfig.toolboxButtons ), "javascript:twinklespeedy( 'csd' )", "db (csd)", "tw-csd", "Speedy delete according to WP:CSD", "");
mw.util.addPortletLink( chooseBox( 'tw-csd-reason', TwinkleConfig.toolboxButtons ), "javascript:twinklespeedy( 'reason' )", "db (reason)", "tw-csd-reason", "Speedy deletion with reason", "");
} else {
mw.util.addPortletLink( chooseBox( 'tw-csd', TwinkleConfig.toolboxButtons ), "javascript:twinklespeedy( 'csd' )", "db (csd)", "tw-csd", "Request speedy deletion according to WP:CSD", "");
mw.util.addPortletLink( chooseBox( 'tw-csd-reason', TwinkleConfig.toolboxButtons ), "javascript:twinklespeedy( 'reason' )", "db (reason)", "tw-csd-reason", "Request speedy deletion with reason", "");
}
}
$(twinkleSpeedyDelete);
function twinklespeedy( type ) {
twinklespeedy.type = type;
switch( type ) {
case 'csd':
twinklespeedy.Window = new SimpleWindow( 800, 400 );
twinklespeedy.Window.setTitle( "Choose criteria for speedy deletion" );
function createOption( value, text ) {
var div = document.createElement( 'div' );
var input = document.createElement( 'input' );
input.setAttribute( 'value', value );
input.setAttribute( 'name', 'csd' );
input.setAttribute( 'id', 'wp' + value );
input.setAttribute( 'type', 'radio' );
var label = document.createElement( 'label' );
label.setAttribute( 'for', 'wp' + 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 );
if( wgNamespaceNumber == 6 ) {
form.appendChild( createOption( 'redundantimage', 'I1: Same or better image exists on Wikipedia (not for now on Commons).' ) );
form.appendChild( createOption( 'noimage', 'I2: Corrupt or empty image.' ) );
form.appendChild( createOption( 'noncom', 'I3: "No commercial use" or "by permission" images uploaded after target date.' ) );
form.appendChild( createOption( 'unksource', 'I4: Lack of licensing.' ) );
form.appendChild( createOption( 'unfree', 'I5: Unused copyright image.' ) );
form.appendChild( createOption( 'norat', 'I6: Image with fair use tag but no fair use rationale.' ) );
form.appendChild( createOption( 'badfairuse', 'I7: Bad fair use rationale - image tagged for fair use under a rationale that is patently irrelevant to the actual image.' ) );
form.appendChild( createOption( 'nowcommons', 'I8: Images available as bit-for-bit identical copies on the Wikimedia Commons,' ) );
form.appendChild( document.createElement( 'hr' ) );
}
form.appendChild( createOption( 'nonsense', 'G1: Patent nonsense.' ) );
form.appendChild( createOption( 'test', 'G2: Test page.' ) );
form.appendChild( createOption( 'vandalism', 'G3: Vandalism.' ) );
form.appendChild( createOption( 'pagemove', 'G3: Nonsense redirects that are created from the cleanup of page move vandalism.' ) );
form.appendChild( createOption( 'repost', 'G4: Copies of material that was previously deleted after an XfD discussion.' ) );
form.appendChild( createOption( 'banned', 'G5: Contributions made by a banned user.' ) );
form.appendChild( createOption( 'histmerge', 'G6: History merge.' ) );
form.appendChild( createOption( 'move', 'G6: Making way for a noncontroversial move.' ) );
form.appendChild( createOption( 'afd', 'G6: An admin has closed an Articles for deletion debate as a "delete".' ) );
form.appendChild( createOption( 'g6', 'G6: Other non-controversial "housekeeping" tasks' ) );
form.appendChild( createOption( 'author', 'G7: Speedy request by only editor.' ) );
form.appendChild( createOption( 'blanked', 'G7: Page blanked by only editor.' ) );
form.appendChild( createOption( 'talk', 'G8: Talk page of a deleted or nonexistent page.' ) );
form.appendChild( createOption( 'attack', 'G10: Attack page intended to disparage its subject.' ) );
form.appendChild( createOption( 'spam', 'G11: Pages that exist only to promote a company, product, or service.' ) );
form.appendChild( createOption( 'copyvio', 'G12: Blatant copyright violation.' ) );
form.appendChild( document.createElement( 'hr' ) );
form.appendChild( createOption( 'nocontext', 'A1: Very short articles without context.' ) );
form.appendChild( createOption( 'foreign', 'A2: Foreign language article duplicated on other Wikimedia project.' ) );
form.appendChild( createOption( 'nocontent', 'A3: No content other than external links of whatever kind, or an attempt to contact subject of article.' ) );
form.appendChild( createOption( 'transwiki', 'A5: Transwikification completed.' ) );
form.appendChild( createOption( 'bio', 'A7: Non-notable biography / article about a person, group, company, or website that does not assert the notability of the subject.' ) );
form.appendChild( createOption( 'band', 'A7: Article about a band, singer, musician, or musical ensemble that does not assert the importance or significance of the subject.' ) );
form.appendChild( createOption( 'club', 'A7: Article about a club that does not assert the importance or significance of the subject.' ) );
form.appendChild( createOption( 'inc', 'A7: Article about a company or corporation that does not assert the importance or significance of the subject.' ) );
form.appendChild( createOption( 'web', 'A7: Article about a web site, blog, online forum, webcomic, podcast, or similar web content that does not assert the importance or significance of its subject.' ) );
form.appendChild( document.createElement( 'hr' ) );
form.appendChild( createOption( 'redirnone', 'R1: Redirect to non-existent page.' ) );
form.appendChild( createOption( 'rediruser', 'R2: Redirect to user page.' ) );
form.appendChild( createOption( 'redirtypo', 'R3: Redirect that is a result of an implausible typo.' ) );
form.appendChild( document.createElement( 'hr' ) );
form.appendChild( createOption( 'catempty', 'C1: Category that is empty for at least four days and has never contained anything other than links to parent categories.' ) );
form.appendChild( createOption( 'catfd', 'C3: Category that is used solely by a template that has been deleted.' ) );
form.appendChild( document.createElement( 'hr' ) );
form.appendChild( createOption( 'userreq', 'U1: User\'s subpage requested to be deleted by the user with whom it is associated.' ) );
form.appendChild( createOption( 'nouser', 'U2: Userpages of users who do not exist.' ) );
form.appendChild( createOption( 'u3', 'U3: A gallery in the userspace which consists of mainly fair use images.' ) );
form.appendChild( document.createElement( 'hr' ) );
form.appendChild( createOption( 'disparage', 'T1: Templates that are divisive and inflammatory.' ) );
form.appendChild( document.createElement( 'hr' ) );
form.appendChild( createOption( 'emptyportal', 'P2: Underpopulated portal.' ) );
twinklespeedy.Window.setContent( form );
twinklespeedy.Window.display();
break;
case 'reason':
var criteria = prompt( "Enter reason for speedy deletion" );
if( !criteria ) {
return; // User abort action
}
if( userIsInGroup( 'sysop' ) ) {
twinklespeedy.summary = "Speedy deletion, with reason: " + criteria + "." + TwinkleConfig.deletionSummaryAd;
} else {
twinklespeedy.summary = "Requesting speedy deletion." + TwinkleConfig.summaryAd;
}
twinklespeedy.code = "{{d" + "b" + ( criteria ? '|' + criteria : '' ) + "}}";
Status.init( document.getElementById('bodyContent') );
Status.status( 'Grabbing page' );
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 = {
'nonsense': 'g1',
'test': 'g2',
'vandalism': 'g3',
'pagemove': 'g3',
'repost': 'g4',
'banned': 'g5',
'histmerge': 'g6',
'move': 'g6',
'afd': 'g6',
'g6': 'g6',
'author': 'g7',
'blanked': 'g7',
'talk': 'g8',
'attack': 'g10',
'spam': 'g11',
'copyvio': 'g12',
'nocontext': 'a1',
'foreign': 'a2',
'nocontent': 'a3',
'transwiki': 'a5',
'bio': 'a7',
'inc': 'a7',
'web': 'a7',
'band': 'a7',
'club': 'a7',
'redirnone': 'r1',
'rediruser': 'r2',
'redirtypo': 'r3',
'redundantimage': 'i1',
'noimage': 'i2',
'noncom': 'i3',
'unksource': 'i4',
'unfree': 'i5',
'norat': 'i6',
'badfairuse': 'i7',
'nowcommons': 'i8',
'catempty': 'c1',
'catfd': 'c3',
'userreq': 'u1',
'nouser': 'u2',
'u3': 'u3',
'disparage': 't1',
'emptyportal': 'p2'
};
var reasarr = {
'nonsense': 'was patent nonsense: an unsalvageably incoherent page with no meaningful content',
'test': 'was a test page',
'vandalism': 'was pure vandalism',
'pagemove': 'was a redirect created during cleanup of page move vandalism',
'repost': 'was a copy of material previously deleted per XfD',
'banned': 'was a contribution was made by a banned user',
'histmerge': 'temporary deletion in order to merge page histories',
'move': 'making way for a non-controversial move',
'afd': 'deleting page per result of AfD discussion',
'g6': 'non-controversial housekeeping deletion',
'author': 'only editor requested deletion',
'blanked': 'only editor has blanked the page',
'talk': 'was a talk page whose corresponding page does not exist',
'attack': 'was a attack page intented to disparage its subject',
'spam': 'was blatant advertising, used only to promote someone or something',
'copyvio': 'was a blatant copyright infringement',
'nocontext': 'was a very short article providing little or no context',
'foreign': 'was a foreign language article that exists on another Wikimedia project',
'nocontent': 'had no content whatsoever except possibly links elsewhere, a rephrasing of the title, and/or attempts to correspond',
'transwiki': 'was properly transwikified elsewhere',
'bio': 'was an article about a real person, group of people, band, club, company, or web content that didn\'t assert the importance or significance of its subject',
'web': 'was an article about a web site, blog, online forum, webcomic, podcast, or similar web content that didn\'t assert the importance or significance of its subject.',
'inc': 'was an article about a company or corporation that didn\'t assert the importance or significance of its subject.',
'club': 'was an article about a club that didn\'t assert the importance or significance of the subject.',
'band': 'was an article about a band, singer, musician, or musical ensemble that didn\'t assert the importance or significance of the subject.',
'redirnone': 'was a redirect to an non-existent page',
'rediruser': 'was a redirect to the Talk:, User: or User talk: space',
'redirtypo': 'was a redirect based on an implausible typo',
'redundantimage': 'a same or better image exists on Wikipedia',
'noimage': 'was a corrupt or empty image',
'noncom': 'was licensed as "for non-commercial use only", "non-derivative use" or "used with permission", uploaded on or after May 19, 2005, and no assertion of fair use was provided',
'unksource': 'was an image lacking sources or licensing information for more than seven days',
'unfree': 'was an unfree image that wasn\'t been used for more than seven days',
'norat': 'was an image with fair use tag but no fair use rationale for more than seven days',
'badfairuse': 'was an image with an invalid fair use rationale and the uploader was notified more than 48 hours ago',
'nowcommons': 'was an image available as a bit-for-bit identical copy on the Wikimedia Commons',
'catempty': 'was an empty category for at least four days',
'catfd': 'was a category solely populated from a now deleted template',
'userreq': 'was a user page whose user requested deletion',
'nouser': 'was a user page of a user that did not exist',
'u3': 'was a gallery in the user space which consisted mostly of fair use images',
'disparage': 'was an divisive and inflammatory template',
'emptyportal': 'was an underpopulated portal'
};
var value = e.target.value;
var normalized = convarr[ value ];
twinklespeedy.watch = TwinkleConfig.watchSpeedyPages.indexOf( normalized ) != -1;
twinklespeedy.usertalk = TwinkleConfig.openUserTalkPageOnSpeedyDelete.indexOf( normalized ) != -1;
var reason = reasarr[ value ];
if( userIsInGroup( 'sysop' ) ) {
twinklespeedy.summary = "Speedy deleted per ([[WP:CSD#" + normalized + "|CSD " + normalized + "]]), " + reason + "." + TwinkleConfig.deletionSummaryAd;
} else {
twinklespeedy.summary = "Requesting speedy deletion ([[WP:CSD#" + normalized + "|CSD " + normalized + "]])." + TwinkleConfig.summaryAd;
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( 'Grabbing page' );
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;
}
// when we grabbed the page, it wasn't there
if( editXML.responseText.indexOf( 'var wgCurRevisionId = false;' ) != -1 ) {
Status.error( "It seems that the page doesn't exists, perhaps it has already been deleted'" );
return;
}
var doc = editXML.responseXML;
var form;
if( userIsInGroup( 'sysop' ) ) {
Status.status( 'Deleting page...' );
form = doc.getElementById( 'deleteconfirm' );
form.style.display = 'none';
doc.getElementById( 'wpReason' ).value = twinklespeedy.summary;
if( twinklespeedy.watch ) {
doc.getElementById( 'wpWatch' ).checked = true;
}
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 = {
'wpWatch': ( twinklespeedy.watch ? true : talkdoc.getElementById( 'wpWatch' ).checked ),
'wpReason': "Speedy deleted per ([[WP:CSD#g8|CSD g8]]), was a talk page of deleted page." + TwinkleConfig.deletionSummaryAd,
'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( 'No delete form for talk page found, won\'t try to delete talk page' );
}
}
} 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 apply CSD template?" ) ) {
return;
}
Status.status( 'Submitting form...' );
textbox.value = twinklespeedy.code + "\n" + textbox.value;
doc.getElementById( 'wpSummary' ).value = twinklespeedy.summary;
if( TwinkleConfig.markSpeedyPagesAsMinor ) {
doc.getElementById( 'wpMinoredit' ).checked = true;
}
if( twinklespeedy.watch ) {
doc.getElementById( 'wpWatchthis' ).checked = true;
}
}
twinklespeedy.form = form;
if( twinklespeedy.usertalk ) {
Status.status( 'Getting data for first contributor' );
var query = {
'action': 'query',
'prop': 'revisions',
'titles': wgPageName,
'rvlimit': 1,
'rvprop': 'user',
'rvdir': 'newer',
'format': 'xml'
}
userTalkXML = sajax_init_object();
userTalkXML.overrideMimeType('text/xml');
userTalkXML.onreadystatechange = twinklespeedyCallbackUserTalk;
userTalkXML.open( 'GET' , wgServer + wgScriptPath + '/api.php?' + QueryString.create( query ), true );
userTalkXML.send( null );
} else {
document.getElementById('globalWrapper').appendChild( twinklespeedy.form )
twinklespeedy.form.submit();
}
}
function twinklespeedyCallbackUserTalk() {
if ( userTalkXML.readyState != 4 ){
Status.progress( '.' );
return;
}
if( userTalkXML.status != 200 ){
Status.error( 'Bad status , bailing out' );
return;
}
var user = userTalkXML.responseXML.documentElement.getElementsByTagName('rev')[0].getAttribute('user');
Status.status( 'Opening user talk page' );
var query = {
'title': 'User talk:' + user,
'action': 'edit',
'vanarticle': wgPageName.replace(/_/g, ' '),
}
switch( TwinkleConfig.userTalkPageMode ) {
case 'tab':
window.open( wgServer + wgScriptPath + '/index.php?' + QueryString.create( query ), '_tab' );
break;
case 'blank':
window.open( wgServer + wgScriptPath + '/index.php?' + QueryString.create( query ), '_blank', 'location=no,toolbar=no,status=no,directories=no,scrollbars=yes,width=1200,height=800' );
break;
case 'window':
default :
window.open( wgServer + wgScriptPath + '/index.php?' + QueryString.create( query ), 'twinklewarnwindow', 'location=no,toolbar=no,status=no,directories=no,scrollbars=yes,width=1200,height=800' );
break;
}
document.getElementById('globalWrapper').appendChild( twinklespeedy.form )
twinklespeedy.form.submit();
}
//</nowiki>