Benutzer:Tafkas/twinklespeedy.js
aus Wikipedia, der freien Enzyklopädie
Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.
- Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
- Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
- Internet Explorer/Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
- Opera: Strg+F5
//<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' )", "SL", "tw-csd", "Schnelllöschung gemäß WP:SLA", "");
mw.util.addPortletLink( chooseBox( 'tw-csd-reason', TwinkleConfig.toolboxButtons ), "javascript:twinklespeedy( 'reason' )", "SL ?", "tw-csd-reason", "Schnelllöschung mit Begründung", "");
} else {
mw.util.addPortletLink( chooseBox( 'tw-csd', TwinkleConfig.toolboxButtons ), "javascript:twinklespeedy( 'csd' )", "SLA", "tw-csd", "Schnelllöschantrag gemäß WP:SLA", "");
mw.util.addPortletLink( chooseBox( 'tw-csd-reason', TwinkleConfig.toolboxButtons ), "javascript:twinklespeedy( 'reason' )", "SLA ?", "tw-csd-reason", "Schnelllöschantrag mit Begründung", "");
}
}
$(twinkleSpeedyDelete);
function twinklespeedy( type ) {
twinklespeedy.type = type;
switch( type ) {
case 'csd':
twinklespeedy.Window = new SimpleWindow( 300, 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( 'commons', 'auf Commons' ) );
form.appendChild( createOption( 'urv', 'offensichtliche URV' ) );
form.appendChild( createOption( 'blu', 'BLU-User nach 14 Tagen' ) );
form.appendChild( document.createElement( 'hr' ) );
}
form.appendChild( createOption( 'keinartikel', 'kein Artikel' ) );
form.appendChild( createOption( 'unfug', 'Unfug' ) );
form.appendChild( createOption( 'wikitest', 'Tastaturtest' ) );
form.appendChild( createOption( 'linkspam', 'Linkspam' ) );
form.appendChild( createOption( 'werbung', 'Werbung' ) );
form.appendChild( createOption( 'irrelevant', 'Irrelevant' ) );
form.appendChild( createOption( 'bandspam', 'Bandspam' ) );
form.appendChild( document.createElement( 'hr' ) );
form.appendChild( createOption( 'wiedergänger', 'Wiedergänger' ) );
form.appendChild( createOption( 'redundant', 'Redundant' ) );
form.appendChild( document.createElement( 'hr' ) );
form.appendChild( createOption( 'keindisk', 'Keine Diskussion' ) );
form.appendChild( createOption( 'verwdisk', 'verwaiste Diskussionsseite' ) );
form.appendChild( document.createElement( 'hr' ) );
form.appendChild( createOption( 'unredir', 'unnötiger Redirect' ) );
form.appendChild( createOption( 'fsredir', 'Falschschreibredirect' ) );
form.appendChild( document.createElement( 'hr' ) );
form.appendChild( createOption( 'benutzer', 'Benutzerwunsch' ) );
twinklespeedy.Window.setContent( form );
twinklespeedy.Window.display();
break;
case 'reason':
var criteria = prompt( "Schnelllöschgrund" );
if( !criteria ) {
return; // User abort action
}
if( userIsInGroup( 'sysop' ) ) {
twinklespeedy.summary = "Schnelllöschung: " + criteria + "." + TwinkleConfig.deletionSummaryAd;
} else {
twinklespeedy.summary = "SLA+ (" + criteria + ")" + TwinkleConfig.summaryAd;
}
twinklespeedy.code = "{{löschen" + ( 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) {
/* Klasse Kurzbeschreibung Begründung (für den SLA) Kürzel
'keinartikel':'a1',
'unfug':'A1',
'wikitest':'A2',
'linkspam':'A3',
'werbung':'A4',
'irrelevant':'A5',
'bandspam':'A6',
'keindisk':'D1',
'verwdisk':'D2',
'unredir':'R1',
'fsredir':'R2',
'wiedergaenger':'M1',
'redundant':'M2',
'benutzer':'U1',
'commons':'B1',
'urv':'B2',
'blu':'B3'
*/
var convarr = {
'keinartikel':'a1',
'unfug':'A1',
'wikitest':'A2',
'linkspam':'A3',
'werbung':'A4',
'irrelevant':'A5',
'bandspam':'A6',
'keindisk':'D1',
'verwdisk':'D2',
'unredir':'R1',
'fsredir':'R2',
'wiedergaenger':'M1',
'redundant':'M2',
'benutzer':'U1',
'commons':'B1',
'urv':'B2',
'blu':'B3'
};
var reasarr = {
'keinartikel':'kein Artikel',
'unfug':'Unfug',
'wikitest':'Tastaturtest - dafür gibt es die [[Wikipedia:Spielwiese]]',
'linkspam':'Linkcontainer - bitte [[Wikipedia:Weblinks]] lesen',
'werbung':'Werbetext der keine enzyklopädisch verwertbaren Inhalte enthält',
'irrelevant':'Offensichtliche, im Artikel nachgewiesene Irrelevanz',
'bandspam':'Band entspricht nicht den [[Wikipedia:Relevanzkriterien]]',
'keindisk':'Keine sinnvolle Diskussion',
'verwdisk':'verwaiste Diskussionsseite',
'unredir':'unnötiger Redirect',
'fsredir':'Falschschreibredirect',
'wiedergänger':'Wiedergänger',
'redundant':'Redundant zu ',
'benutzer':'wird nicht mehr benötigt',
'commons':'jetzt auf Commons zu finden',
'urv':'Eindeutige Urheberrechtsverletzung, die auch mit Freigabe keinen brauchbaren Artikel darstellt',
'blu':'BLU-User erfolglos, keine Reaktion nach 14 Tagen'
};
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 = "Schnellgelöscht (" + reason + ")" + TwinkleConfig.deletionSummaryAd;
} else {
twinklespeedy.summary = "SLA+ (" + reason + ")" + TwinkleConfig.summaryAd;
switch( normalized ) {
case 'B1':
var date = new Date();
twinklespeedy.code = "{{" + "NowCommons" + "|month=" + date.getUTCMonthName() + "|day=" + date.getUTCDate() + "|year=" + date.getUTCFullYear() + "|1=" + wgPageName.replace( '_', ' ' ) + "}} " + "--\~\~\~\~";
break;
case 'M2':
url = prompt( 'Bitte den anderen Artikel angeben:','[[]]' );
if( url == null ) {
return;
}
twinklespeedy.code = "{{löschen|" + reason + url + " --\~\~\~\~" + "}}";
break;
default:
twinklespeedy.code = "{{löschen|" + reason + " --\~\~\~\~" + "}}" ;
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-?|SLA|löschen)\|?.*?\}\})/.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>