User:Radar33/twinkle/speedylogaddon.js

/// Code taken from User:Timotheus Canens/twinklespeedy.js, modified from User:AzaToth/twinklespeedy.js

// If TwinkleConfig aint exist. if( typeof( TwinkleConfig ) == 'undefined' ) { TwinkleConfig = {}; }

/** TwinkleConfig.noLogOnSpeedyNomination (array) What types of actions that should not be logged in the CSD log. Default is U1 (user request). */ if( typeof( TwinkleConfig.noLogOnSpeedyNomination ) == 'undefined' ) { TwinkleConfig.noLogOnSpeedyNomination = ['u1']; }

/** TwinkleConfig.neverLogSpeedyNomination (boolean) Whether speedy nomination should be logged at all, default false. */ if( typeof( TwinkleConfig.neverLogSpeedyNomination ) == 'undefined' ) { TwinkleConfig.neverLogSpeedyNomination = false; }

/** TwinkleConfig.speedyLogPageName (string) The name of the userspace subpage in which speedy nominations should be logged. Default "CSDlog". */ if( typeof( TwinkleConfig. speedyLogPageName ) == 'undefined' ) { TwinkleConfig.speedyLogPageName = "CSDlog"; }

//if User:AzaToth/twinklespeedy.js is updated, double check the following function, and add /*       lognomination: (TwinkleConfig.noLogOnSpeedyNomination.indexOf( normalized ) == -1) && (!TwinkleConfig.neverLogSpeedyNomination) //into the "var params" array

twinklespeedy.callback.evaluateUser = function twinklespeedyCallbackEvaluateUser(e) { wgPageName = wgPageName.replace( /_/g, ' ' ); // for queen/king/whatever and country! var value = e.target.value; if (value == 'multiple') {       e.target.form.style.display = "none"; // give the user a cue that the dialog is being changed twinklespeedy.targetdialogcontent = e.target.form.parentNode; // make this accessible in scopeless setTimeout setTimeout("twinklespeedy.initDialog(twinklespeedy.callback.doMultiple, false, twinklespeedy.targetdialogcontent)", 150); return; }   if (value == 'multiple-finish') value = 'multiple'; else {       // clear these out, whatever the case, to avoid errors twinklespeedy.dbmultipleCriteria = []; twinklespeedy.dbmultipleParameters = []; }   var normalized = twinklespeedy.normalizeHash[ value ];

// analyse each db-multiple criterion to determine whether to watch the page/notify the creator var watchPage = false; if (value == 'multiple') {       for (var i in twinklespeedy.dbmultipleCriteria) {           if (typeof twinklespeedy.dbmultipleCriteria[i] == 'string' &&                 TwinkleConfig.watchSpeedyPages.indexOf(twinklespeedy.dbmultipleCriteria[i]) != -1) {               watchPage = true; break; }       }    }    else watchPage = TwinkleConfig.watchSpeedyPages.indexOf(normalized) != -1; var notifyuser = false; if (value == 'multiple') {       for (var i in twinklespeedy.dbmultipleCriteria) {           if (typeof twinklespeedy.dbmultipleCriteria[i] == 'string' &&                 TwinkleConfig.notifyUserOnSpeedyDeletionNomination.indexOf(twinklespeedy.dbmultipleCriteria[i]) != -1) {               notifyuser = true; break; }       }    }    else notifyuser = (TwinkleConfig.notifyUserOnSpeedyDeletionNomination.indexOf(normalized) != -1) && e.target.form.notify.checked; var params = { value: value, normalized: normalized, watch: watchPage, usertalk: notifyuser, rcid: QueryString.exists( 'rcid' ) ? QueryString.get( 'rcid' ) : '', wgCanonicalNamespace : wgCanonicalNamespace, // begin add-on (with addition of comma above       lognomination: (TwinkleConfig.noLogOnSpeedyNomination.indexOf( normalized ) == -1) && (!TwinkleConfig.neverLogSpeedyNomination) // end add-on    };

Status.init( e.target.form );

Wikipedia.actionCompleted.redirect = wgPageName; Wikipedia.actionCompleted.notice = "Tagging complete";

var query = { 'action': 'query', 'titles': wgPageName }

var wikipedia_api = new Wikipedia.api( 'Checking if page exists', query, twinklespeedy.callbacks.user.main ); wikipedia_api.params = params; wikipedia_api.post; }

// if User:AzaToth/twinklespeedy.js is updated, double check the following function, and add /*   else if( self.params.lognomination ) { var query = { 'title': 'User:' + wgUserName +'/' + TwinkleConfig.speedyLogPageName, 'action': 'submit' };       var wikipedia_wiki = new Wikipedia.wiki( 'Logging CSD nomination', query, twinklespeedy.callbacks.user.userLog ); wikipedia_wiki.params = self.params; wikipedia_wiki.get; } // after the "if( self.params.usertalk ) {" block

twinklespeedy.callbacks.user.tagPage = function( self ) { form = this.responseXML.getElementById( 'editform' );

var text = form.wpTextbox1.value;

self.statelem.status( 'Checking for tags on the page...' );

// check for existing deletion tags var tag = /(\{\{\s*(?:db|delete|db-.*?)(?:\||\s*\}\}))/.exec( text ); if( tag ) { self.statelem.error( [ htmlNode( 'strong', tag[0] ), " is already placed on the page." ] ) return; }

var xfd = /(\{\{(?:[rsaiftcm]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; }   var code; var parameters; if (self.params.normalized == 'multiple') {       code = "\{\{db-multiple"; for (var i in twinklespeedy.dbmultipleCriteria) if (typeof twinklespeedy.dbmultipleCriteria[i] == 'string') code += "|" + twinklespeedy.dbmultipleCriteria[i].toUpperCase; for (var i in twinklespeedy.dbmultipleParameters) if (typeof twinklespeedy.dbmultipleParameters[i] == 'string') code += "|" + i + "=" + twinklespeedy.dbmultipleParameters[i]; code += "\}\}"; self.params.utparams = []; }   else {       parameters = twinklespeedy.getParameters(self.params.value, self.params.normalized, self.statelem); if (!parameters) return; code = "\{\{db-" + self.params.value; for (var i in parameters) if (typeof parameters[i] == 'string') code += "|" + i + "=" + parameters[i]; code += "\}\}"; self.params.utparams = twinklespeedy.getUserTalkParameters(self.params.normalized, parameters); }

if( TwinkleConfig.markSpeedyPagesAsPatrolled && self.params.rcid != '' ) { // extract patrol token from "Mark page as patrolled" link on page var patrollinkmatch = /token=(.+)%2B%5C$/.exec($('.patrollink a').attr('href')); if (patrollinkmatch) { var patroltoken = patrollinkmatch[1] + "+\\"; var patrolstat = new Status("Marking page as patrolled", "Doing..."); (Wikipedia.numberOfActionsLeft)++;

var query = { 'title': wgPageName, 'action': 'markpatrolled', 'rcid': self.params.rcid, 'token': patroltoken };

jQuery.ajax( {               context: patrolstat,                type: 'GET',                url: mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php',                 data: QueryString.create(query),                dataType: 'xml',                success: function(xml, textStatus, jqXHR) {                    this.info(textStatus);                    Wikipedia.actionCompleted;                },                error: function(jqXHR, textStatus, errorThrown) {                    if (textStatus == "parsererror") { // kludge for Firefox 4.0b12                        this.info("Done");                        Wikipedia.actionCompleted;                    } else {                        this.error(textStatus + ': ' + errorThrown + ' occurred while trying to mark as patrolled.');                    }                }            } ); }   }

// Notification to first contributor var query = { 'action': 'query', 'prop': 'revisions', 'titles': wgPageName, 'rvlimit': 1, 'rvprop': 'user', 'rvdir': 'newer' }   var callback = function( self ) { var xmlDoc = self.responseXML; var user = xmlDoc.evaluate( '//rev/@user', xmlDoc, null, XPathResult.STRING_TYPE, null ).stringValue; if( wgPageName != ( 'User talk:' + user ) ) { var query = { 'title': 'User talk:' + user, 'action': 'submit' };           var wikipedia_wiki = new Wikipedia.wiki( 'Notifying of initial contributor (' + user + ')', query, twinklespeedy.callbacks.user.userNotification ); wikipedia_wiki.params = self.params; wikipedia_wiki.get; } else { Status.info( 'Info', 'Current page is initial contributor\'s talk page, aborting notification' ); }   }

if( self.params.usertalk ) { var wikipedia_api = new Wikipedia.api( 'Grabbing data of initial contributor', query, callback ); wikipedia_api.params = self.params; wikipedia_api.post; } // begin add-on else if( self.params.lognomination ) { var query = { 'title': 'User:' + wgUserName +'/' + TwinkleConfig.speedyLogPageName, 'action': 'submit' };       var wikipedia_wiki = new Wikipedia.wiki( 'Logging CSD nomination', query, twinklespeedy.callbacks.user.userLog ); wikipedia_wiki.params = self.params; wikipedia_wiki.get; } // end add-on

//wrap SD template in noinclude tags if we are in template space. //won't work with userboxes in userspace, or any other transcluded page outside template space if (self.params.wgCanonicalNamespace == "Template") code = " " + code + " ";

//Remove tags that become superfluous with this action text = text.replace(/{\{\s*(New unreviewed article|Userspace draft)\s*(\|(?:|[^{}])*)?}}\s*/ig, "");

// Generate edit summary for edit var editsummary; switch (self.params.normalized) {       case 'db': editsummary = 'Requesting speedy deletion with rationale \"' + parameters["1"] + '\".'; break; case 'multiple': editsummary = 'Requesting speedy deletion (';           for (var i in twinklespeedy.dbmultipleCriteria)                if (typeof twinklespeedy.dbmultipleCriteria[i] == 'string')                    editsummary += 'CSD ' + twinklespeedy.dbmultipleCriteria[i].toUpperCase + ', ';            editsummary = editsummary.substr(0, editsummary.length - 2); // remove trailing comma            editsummary += ').'; break; default: editsummary = "Requesting speedy deletion (CSD " + self.params.normalized.toUpperCase + ")."; break; }

var postData = { 'wpMinoredit': TwinkleConfig.markSpeedyPagesAsMinor ? '' : undefined, 'wpWatchthis': (self.params.watch || form.wpWatchthis.checked ) ? '' : undefined, 'wpStarttime': form.wpStarttime.value, 'wpEdittime': form.wpEdittime.value, 'wpAutoSummary': form.wpAutoSummary.value, 'wpEditToken': form.wpEditToken.value, 'wpSection': '', 'wpSummary': editsummary + TwinkleConfig.summaryAd, 'wpTextbox1': code + ((self.params.normalized == 'g10' || twinklespeedy.dbmultipleCriteria.indexOf('g10') != -1) ?           '' : ("\n" + text) ) // cause attack pages to be blanked };   self.post( postData ); }

twinklespeedy.callbacks.user.userLog = function( self ) { var form = self.responseXML.getElementById( 'editform' ); var text = form.wpTextbox1.value; var date = new Date; var headerRe = new RegExp( "^==+\\s*(?:" + date.getUTCMonthName + '|' + date.getUTCMonthNameAbbrev + ")\\s+" + date.getUTCFullYear + "\\s*==+", 'm' ); if( !headerRe.exec( text ) ) { Status.info( 'Info', 'Will create a new level 2 heading for the date, as none was found for this month' ); var heading = date.getUTCMonthName + " " + date.getUTCFullYear; text += " \n== " + heading + " ==\n "; text += " \n; " + heading + " \n \n"; }   text += "* " + wgPageName + ": CSD " + self.params.normalized.toUpperCase + " (\{\{tl|db-" + self.params.value + "\}\})"; if ( typeof (self.params.notifieduser) != 'undefined') text += "; notified: \{\{user|" + self.params.notifieduser + "\}\}"; text += " \~\~\~\~\~"; var postData = { 'wpMinoredit': form.wpMinoredit.checked ? '' : undefined, 'wpWatchthis': form.wpWatchthis.checked ? '' : undefined, 'wpStarttime': form.wpStarttime.value, 'wpEdittime': form.wpEdittime.value, 'wpAutoSummary': form.wpAutoSummary.value, 'wpEditToken': form.wpEditToken.value, 'wpSection': '', 'wpSummary': 'Logging speedy deletion nomination of \[\[:' + wgPageName + '\]\].' + TwinkleConfig.summaryAd, 'wpTextbox1': text };   self.post( postData ); }