MediaWiki:Group-sysop.js

// /* Any JavaScript here will be loaded for sysops only */ $(function ($) {	// Opt-out	if ( window.disableSysopJS ) {		return;	}

// Animum's mass-deletion tool // from https://en.wikipedia.org/wiki/User:Animum/massdelete.js mw.loader.using(['mediawiki.api.edit', 'mediawiki.Title'], function {	"use strict";

var config = mw.config.get(['wgNamespaceNumber', 'wgTitle', 'wgUserGroups', 'skin']);

function removeBlanks(arr) { var ret = []; var i, len; for (i = 0, len = arr.length; i < len; i++) { var s = arr[i]; s = s.trim; if (s) { ret.push(s); }		}		return ret; }

function doMassDelete { document.getElementById("wpMassDeleteSubmit").disabled = true; var articles = document.getElementById("wpMassDeletePages").value.split("\n"); articles = removeBlanks(articles); if (!articles.length) { return; }		var api = new mw.Api, wpMassDeleteReasons = document.getElementById("wpMassDeleteReasons").value, wpMassDeleteReason = document.getElementById("wpMassDeleteReason").value, deleted = 0, failed = [], error = [], deferreds = [], reason = wpMassDeleteReasons == "other" ? wpMassDeleteReason : wpMassDeleteReasons + (wpMassDeleteReason ? " (" + wpMassDeleteReason + ")" : ""), onSuccess = function { deleted++; document.getElementById("wpMassDeleteSubmit").value = "(" + deleted + ")"; };

function makeDeleteFunc(article) { return function { return $.Deferred(function (deferred) {					var promise = api.post({ format: 'json', action: 'delete', title: article, reason: reason, token: mw.user.tokens.get('editToken') });					promise.done(onSuccess);					promise.fail(function (code, obj) { failed.push(article); error.push(obj.error.info); });					promise.always(function { deferred.resolve; });				});			};		}

// Make a chain of deferred objects. We chain them rather than execute them in		// parallel so that we don't make 1000 simultaneous delete requests and bring the // site down. We use deferred objects rather than the promise objects returned // from the API request so that the chain continues even if some articles gave // errors. var deferred = makeDeleteFunc(articles[0]); for (var i = 1, len = articles.length; i < len; i++) { deferred = deferred.then(makeDeleteFunc(articles[i])); }

// Show the output and do cleanup once all the requests are done. $.when(deferred).then(function {			document.getElementById("wpMassDeleteSubmit").value = "Done (" + deleted + ")";			if (failed.length) {				var $failedList = $('');				for(var x = 0; x < failed.length; x++) {					// Link the titles in the "failed" array					var $failedItem = $('');                                        $failedItem.text(failed[x]);					$failedItem.append(document.createTextNode(': ' + error[x]));					$failedList.append($failedItem);				}				$('#wpMassDeleteFailedContainer')					.append($(' '))					.append($('') .text('Failed deletions:') )					.append($failedList);			}		}); }	function massdeleteform { var bodyContent = (config.skin == "cologneblue" ? "article" : "bodyContent"); document.getElementsByTagName("h1")[0].textContent = "Animum's mass-deletion tool"; document.title = "Animum's mass-deletion tool - Wikipedia, the free encyclopedia"; document.getElementById(bodyContent).innerHTML = 'From Wikipedia, the free encyclopedia

' +			'' + 'If you abuse this tool, it\'s your fault, not mine.' + ' ' +			'

' +				'Pages to delete (one on each line, please): ' +					' ' + '

';					mw.notify( $( OCAreport ), { title: 'OneClickArchiver report!', tag: 'OCA', autoHide: false } ); }				var OCAerror = ' The following errors detected: ';				if ( errorLog.counter ) { OCAerror += '&bull; Unable to find |counter= Default value: 1 '; }				if ( errorLog.archiveName && errorLog.archiveName.search( 'defaulted to' ) !== -1 ) { OCAerror += '&bull; Unable to find |archive= Default value: ' + archiveName + ' '; }				if ( errorLog.archiveName && errorLog.archiveName.search( 'mismatch' ) !== -1 ) { OCAerror += '&bull; Archive name mismatch detected. '; }				if ( errorLog.headerLevel ) { OCAerror += ' Unable to find |headerlevel= Default value: 2 '; }				if ( errorLog.archiveHeader ) { OCAerror += ' Unable to find |archiveheader= Default value: "" '; }				if ( errorLog.maxArchiveSize ) { OCAerror += ' Unable to find |maxarchivesize= Default value: 153600 '; }				if ( errorLog.counter || errorLog.archiveName ) { OCAerror += ' &bull; Causing the script to abort. '; }				OCAerror += ' Please, see the documentation for details. ';				var archiverReport = mw.util.addPortletLink(					'p-cactions',					'#archiverNoLink',					'|Archive',					'pt-OCA-report',					'Report for why there are no |Archive links on this page',					null,					null				); $( archiverReport ).click( function ( e ) {					e.preventDefault;					mw.notify( $( OCAerror ), { title: 'OneClickArchiver errors!', tag: 'OCAerr', autoHide: false } );				} ); $( 'h' + headerLevel + ' span.mw-headline' ).each( function( i, val ) {					var sectionName = $( this ).text;					var editSectionUrl = $( this ).parent.find( '.editsection a:first' ).attr( 'href' );					var sectionReg = /&section=(.*)/;					var sectionRaw = sectionReg.exec( editSectionUrl );					if ( sectionRaw != null && sectionRaw[ 1 ].indexOf( 'T' ) < 0 ) {						var sectionNumber = parseInt( sectionRaw[ 1 ] );						if ( $( this ).parent.prop( 'tagName' ) === 'H' + headerLevel ) {

$( this ).parent( 'h' + headerLevel ).append( ' | <a id="' + sectionNumber +								'" href="#archiverLink" class="archiverLink">' + 'Archive' + '</a> ' );

$( this ).parent( 'h' + headerLevel ).find( 'a.archiverLink' ).click( function {

var mHeaders = ' Retrieving headers... ';								var mSection = 'retrieving section content...'; var mPosting = ' Content retrieved, performing edits...'; var mPosted = ' Archive appended... ';								var mCleared = ' Section cleared... ';								var mReloading = ' All done! <a href="#archiverLink" onClick="javascript:location.reload;" title="Reload page">Reloading</a>...';

$( 'body' ).append( '<div class="overlay" style="background-color: #000000; opacity: 0.4; position: fixed; top: 0px; left: 0px; width: 100%; height: 100%; z-index: 500;"> ' );

$( 'body' ).prepend( '<div class="arcProg" style="font-weight: bold; box-shadow: 7px 7px 5px #000000; font-size: 0.9em; line-height: 1.5em; z-index: 501; opacity: 1; position: fixed; width: 50%; left: 25%; top: 30%; background: #F7F7F7; border: #222222 ridge 1px; padding: 20px;"> ' );

$( '.arcProg' ).append( ' ' + mHeaders + ' ' );

$( '.arcProg' ).append( ' ' + 'Archive name ' + archiveName + ' found, ' + mSection + ' (' + archivePageSize + 'b) ' ); new mw.Api.post( {									action: 'query',									pageids: pageid,									rvsection: sectionNumber,									prop: 'revisions|info',									rvprop: 'content',									indexpageids: 1,								} ).done( function ( responseSection ) {									var sectionContent = responseSection.query.pages[ pageid ].revisions[ 0 ][ '*' ];									$( '.arcProg' ).append( ' ' + mPosting + ' ' );

var dnau = sectionContent.match( // ); if ( dnau === null || dnau === undefined ) { var dnauDate = Date.now; dnau = null; } else { dnau = dnau[ 1 ] + ':' + dnau[ 2 ] + ' ' + dnau[ 3 ] + ' ' + dnau[ 4 ] + ' ' + dnau[ 5 ]; var dnauDate = new Date( dnau ); dnauDate = dnauDate.valueOf; }

if ( dnauDate > Date.now ) { $( '.arcProg' ).remove; $( '.overlay' ).remove; var dnauAbortMsg = ' This section has been marked \"Do Not Archive Until\" ' + dnau + ', so archiving was aborted.

Please, see <a href="/wiki/User:Technical_13/Scripts/OneClickArchiver" title="User:Technical 13/Scripts/OneClickArchiver">the documentation</a> for details. ';										mw.notify( $( dnauAbortMsg ), { title: 'OneClickArchiver aborted!', tag: 'OCAdnau', autoHide: false } ); } else { var archiveAction = 'adding'; if ( archivePageSize <= 0 || ( archivePageSize >= maxArchiveSize && !errorLog.maxArchiveSize ) ) { sectionContent = archiveHeader + '\n\n' + sectionContent; archiveAction = 'creating' mPosted = ' Archive created... ';										} else { sectionContent = '\n\n

\n' + sectionContent; }

if ( dnau != null ) { sectionContent = sectionContent.replace( //g, '' ); }

new mw.Api.postWithEditToken({											action: 'edit',											title: archiveName,											appendtext: sectionContent,											summary: 'OneClickArchiver ' + archiveAction + ' ' + sectionName + ''										} ).done( function ( archived ) {											$( '.arcProg' ).append( ' ' + mPosted + ' ' );

new mw.Api.postWithEditToken({												action: 'edit',												section: sectionNumber,												pageid: pageid,												text: ,												summary: 'OneClickArchiver archived \ + sectionName + '\' to ' + archiveName + ''										} ).done( function {												$( '.arcProg' ).append( ' ' + mCleared + ' ' );												if ( archivePageSize >= maxArchiveSize && !errorLog.maxArchiveSize ) {													var mUpdated = ' Counter updated... ';													new mw.Api.postWithEditToken({ action: 'edit', section: 0, pageid: pageid, text: content0.replace( oldCounter, newCounter ), summary: 'OneClickArchiver updating counter.' } ).done( function { $( '.arcProg' ).append( ' ' + mUpdated + ' ' ); $( '.arcProg' ).append( ' ' + mReloading + ' ' ); location.reload; } );												} else {													$( '.arcProg' ).append( ' ' + mReloading + ' ' );													location.reload;												}											} ); } );									}								} );							} );						}					}				} ); 			} );		} );	} } ); } );