User:Maantietäjä/common.js

// #### CHANGE SOME LINKS #### $.when($.ready).then(function{	var customTarget;	if(mw.config.get( 'skin' ) === 'vector'){		// define where to add the personal menu		customTarget = '#p-personal UL';		$('LI#pt-maantietaja-xtools A').html(' xtools ');	}	else if(mw.config.get( 'skin' ) === 'timeless'){		// define where to add the personal menu		customTarget = 'DIV#pt-maantietaja-box-p-cactions DIV.mw-portlet-body UL';		// add a headline	}

if( typeof customTarget !== 'undefined' ){	// #### ADD SOME LINKS TO THE INTERFACE #### if( mw.config.get( 'skin' ) !== 'timeless' ){ $(customTarget).prepend('—');	// prepend, thus in reverse order }		$(customTarget).prepend('xtools'); } });

mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Maantietäjä/edittools.js&action=raw&ctype=text/javascript');

importScript('User:RedWarn/.js'); // Backlink: User:RedWarn/.js importScript('User:Awesome Aasim/rcpatrol.js'); // Backlink: User:Awesome Aasim/rcpatrol.js importScript('User:The Earwig/copyvios.js'); // Backlink: User:The Earwig/copyvios.js importScript('User:Evad37/MoveToDraft.js'); // Backlink: User:Evad37/MoveToDraft importScript('User:Lourdes/PageCuration.js'); // Linkback: User:Lourdes/PageCuration.js importScript( 'User:Enterprisey/cv-revdel.js' ); // Backlink: User:Enterprisey/cv-revdel.js importScript('User:DannyS712/Logs.js'); // Backlink: User:DannyS712/Logs.js importScript('User:Bradv/SearchLinks.js'); // Backlink: User:Bradv/SearchLinks.js importScript('User:Danski454/stubsearch.js'); // Backlink: User:Danski454/stubsearch.js importScript('User:Insertcleverphrasehere/copyvios.js'); // Backlink: User:Insertcleverphrasehere/copyvios.js importScript('User:SD0001/W-Ping.js'); // Backlink: User:SD0001/W-Ping.js

importScript( 'User:Enterprisey/script-installer.js' ); // Backlink: User:Enterprisey/script-installer.js importScript('User:Enterprisey/cv-revdel.js'); // Backlink: User:Enterprisey/cv-revdel.js importScript('User:Jackmcbarn/editProtectedHelper.js'); // Backlink: User:Jackmcbarn/editProtectedHelper.js importScript('User:Enterprisey/reply-link.js'); // Backlink: User:Enterprisey/reply-link.js importScript('User:Music1201/QuickLinks.js'); // Backlink: User:Music1201/QuickLinks.js importScript('User:DannyS712/SATG.js'); // Backlink: User:DannyS712/SATG.js importScript('User:Evad37/rater.js'); // Backlink: User:Evad37/rater.js importScript('User:Gary/nominations viewer.js'); // Backlink: User:Gary/nominations viewer.js importScript('User:AndyZ/peerreviewer.js'); // Backlink: User:AndyZ/peerreviewer.js importScript('User:Caorongjin/wordcount.js'); // Backlink: User:Caorongjin/wordcount.js importScript('User:Ohconfucius/script/MOSNUM dates.js'); // Backlink: User:Ohconfucius/script/MOSNUM dates.js importScript('User:Headbomb/unreliable.js'); // Backlink: User:Headbomb/unreliable.js importScript('User:GregU/dashes.js'); // Backlink: User:GregU/dashes.js importScript('User:Σ/Testing facility/Archiver.js'); // Backlink: User:Σ/Testing facility/Archiver.js importScript('Wikipedia:AutoEd/complete.js'); // Backlink: AutoEd/complete.js importScript('User:Writ Keeper/Scripts/teahouseUtility.js'); // Backlink: User:Writ Keeper/Scripts/teahouseUtility.js importScript('User:Evad37/MoveToDraft.js'); // Backlink: User:Evad37/MoveToDraft.js importScript('User:SD0001/DYK-helper.js'); // Backlink: User:SD0001/DYK-helper.js importScript("User:Writ Keeper/Scripts/orangeBar.js"); importScript('User:Evad37/duplinks-alt.js'); // Backlink: User:Evad37/duplinks-alt.js importScript('User:DannyS712/DiscussionCloser.js'); // Backlink: User:DannyS712/DiscussionCloser.js importScript('User:Writ Keeper/Scripts/peerReviewCloser.js'); // Backlink: User:Writ Keeper/Scripts/peerReviewCloser.js importScript('User:Writ Keeper/Scripts/massRevdel.js'); // Backlink: User:Writ Keeper/Scripts/massRevdel.js importScript('User:MusikAnimal/responseHelper.js'); // Backlink: User:MusikAnimal/responseHelper.js importScript('User:Mr. Stradivarius/gadgets/SpamUserPage.js'); // Backlink: User:Mr. Stradivarius/gadgets/SpamUserPage.js importScript('User:GeneralNotability/ip-ext-info.js'); // Backlink: User:GeneralNotability/ip-ext-info.js importScript('User:Enterprisey/unblock-review.js'); // Backlink: User:Enterprisey/unblock-review.js importScript('User:Enterprisey/link-deleted-revs.js'); // Backlink: User:Enterprisey/link-deleted-revs.js importScript('User:Writ Keeper/Scripts/massRollback.js'); // Backlink: User:Writ Keeper/Scripts/massRollback.js importScript('User:Bradv/endlesscontribs.js'); // Backlink: User:Bradv/endlesscontribs.js importScript('User:MusikAnimal/userRightsManager.js'); // Backlink: User:MusikAnimal/userRightsManager.js

mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Krinkle/Tools/Global_SUL.js&action=raw&ctype=text/javascript'); mw.loader.load( '//zh.wikipedia.org/w/index.php?title=User:小躍/member-online.js&action=raw&ctype=text/javascript' ); $( document ).ready( function {	'use strict';

var api, $undoLink, $ntitle, specialPage, userGroups, SHOW_ROLLBACK_EDIT_COUNT, modules, diffOnRb, botMode;

$undoLink = $( 'ul#pagehistory li:first-child span.mw-history-undo' ); $ntitle = $( '#mw-diff-ntitle2' ); specialPage = mw.config.get( 'wgCanonicalSpecialPageName' ); if (		$undoLink.length === 0 &&		( $ntitle.length === 0 || $( '#differences-nextlink' ).length > 0 ) &&		[			'Contributions',			'Watchlist',			'Recentchanges',			'Recentchangeslinked'		].indexOf( specialPage ) === -1	) { return;// no [rollback] button to insert }	// TODO: auto-patrol reverted changes

userGroups = mw.config.get( 'wgUserGroups' ); if ( userGroups.indexOf( 'rollbacker' ) !== -1 || userGroups.indexOf( 'sysop' ) !== -1 ) { return;// user is rollbacker, no need for these buttons }

// https://www.mediawiki.org/wiki/Manual:$wgShowRollbackEditCount SHOW_ROLLBACK_EDIT_COUNT = 10;

modules = [ 'mediawiki.api', 'mediawiki.jqueryMsg' ]; diffOnRb = ( mw.user.options.get( 'norollbackdiff' ) !== 1 ); if ( diffOnRb ) { modules.push( 'mediawiki.diff.styles' ); }	botMode = mw.util.getParamValue( 'bot' );

function loadMessages( messages ) { return api.get( {			action: 'query',			formatversion: 2,			meta: 'allmessages',			amlang: mw.config.get( 'wgUserLanguage' ),			ammessages: messages		} ) .done( function ( data ) {			$.each( data.query.allmessages, function ( i, e ) { mw.messages.set( e.name, e.content ); } );		} );	}

function showLatestDiff( pageTitle ) { api.get( {			action: 'query',			formatversion: 2,			prop: 'revisions',			titles: pageTitle,			rvdiffto: 'prev',			rvlimit: 1		} ).done( function ( rev ) {			$( '#mw-content-text' ).append( ' '			);		} );	}

function pushHistory( url ) { window.history.pushState( { path: window.location.href }, '', url ); }

function onGotRevisions( rbl, pageTitle, lastEditor, undoRevid, data ) { var page, revision, rbSummary, rbSuccess, rbPostConfig; $.each( data.query.allmessages, function ( i, e ) {			mw.messages.set( e.name, e.content );		} ); page = data.query.pages[ 0 ]; if ( page.revisions === undefined || page.revisions.length === 0 ) { // the last editor of the page is its single one pushHistory( rbl.href ); $( '#firstHeading' ).text( mw.message( 'rollbackfailed' ).text ); $( '#p-views ul>li' ).removeClass( 'selected' ); $( '#contentSub' ).empty; $( '#mw-content-text' ).text( mw.message( 'cantrollback' ).text ); return; }		revision = page.revisions[ 0 ]; rbSummary = prompt( "Summary: (optional, 'h' for a summary with uesrname hidden)", window.defaultRollbackSummary || "" ); if (rbSummary === null) { // abort by clicking cancel return; } else if (rbSummary === 'h') { rbSummary = 'Restore to the last revision'; } else { rbSummary = rbSummary || mw.message( 'revertpage', revision.user, lastEditor ).text; }		rbSuccess = mw.message( 'rollback-success', lastEditor, revision.user ).text; rbPostConfig = { action: 'edit', undo: undoRevid, undoafter: revision.revid, title: pageTitle, summary: rbSummary, minor: 1 };		if ( botMode !== null ) { rbPostConfig.bot = botMode; }		api.postWithToken( 'csrf', rbPostConfig ) .done( function {			pushHistory( rbl.href );			$( '#p-views ul>li' ).removeClass( 'selected' );			$( '#contentSub' ).empty;			$( '#firstHeading' ).text( mw.message( 'actioncomplete' ).text );			$( '#mw-content-text' ).empty.append( $( ' ' ).text( rbSuccess ) )			.append( $( ' ' ).attr( 'id', 'mw-returnto' ).html(					mw.message( 'returnto', '' + pageTitle.replace( /_/g, ' ' ) + '' ).text				) );			if ( diffOnRb ) {				showLatestDiff( pageTitle );			}		} ) .fail( function ( code, data ) {			pushHistory( rbl.href );			$( '#firstHeading' ).text( mw.message( 'rollbackfailed' ).text );			$( '#mw-content-text' ).text( data && data.error && data.error.info ? data.error.info : '' );		} ); }

function onRbLinkClick( rbl, pageTitle, lastEditor, undoRevid ) { api.get( {			// require the revision id and the user name			// of the last revision not made by the last user			action: 'query',			formatversion: 2,			prop: 'revisions',			rvlimit: 1,			titles: pageTitle,			rvexcludeuser: lastEditor,			rvprop: 'ids|user',			meta: 'allmessages',			amlang: mw.config.get( 'wgContentLanguage' ),			ammessages: 'revertpage'		} ) .done( onGotRevisions.bind( null, rbl, pageTitle, lastEditor, undoRevid ) ); }

function getRbLink( pageTitle, lastEditor, undoRevid, rbLinkHrefConfig, rbLinkText ) { return $( '' ) .attr( {			href: mw.util.wikiScript + '?' + $.param( rbLinkHrefConfig ),			title: mw.message( 'tooltip-rollback' ).text		} ) .text( rbLinkText ) .click( function ( event ) {			event.preventDefault;			onRbLinkClick( this, pageTitle, lastEditor, undoRevid );		} ) .appendTo( $( ' ' ).addClass( 'mw-rollback-link' ) ).parent; }

function getRbLinkFromRevisions( pageTitle, lastEditor, data ) { var page, rbEdits, undoRevid, rbLinkText, rbLinkHrefConfig; if (			data === undefined ||			data.query === undefined ||			data.query.pages === undefined ||			data.query.pages.length !== 1		) { return null; }		page = data.query.pages[ 0 ]; if ( page.revisions === undefined || page.revisions.length === 0 ) { return null; }		rbEdits = null; undoRevid = page.revisions[ 0 ].revid; $.each( page.revisions, function ( i, rev ) {			if ( rev.user.replace( / /g, '_' ) !== lastEditor.replace( / /g, '_' ) ) {				rbEdits = i;				return false;			}		} ); rbLinkText = mw.message( 'rollbacklink' ).text; if ( rbEdits === null ) { if ( page.revisions.length === SHOW_ROLLBACK_EDIT_COUNT + 1 ) { rbLinkText = mw.message( 'rollbacklinkcount-morethan', SHOW_ROLLBACK_EDIT_COUNT ).text; } else { return null; }		} else { rbLinkText = mw.message( 'rollbacklinkcount', rbEdits ).text; }		rbLinkHrefConfig = { title: pageTitle, action: 'rollback', user: lastEditor, token: mw.user.tokens.get( 'editToken' ) };		if ( botMode !== null ) { rbLinkHrefConfig.bot = botMode; }		return getRbLink( pageTitle, lastEditor, undoRevid, rbLinkHrefConfig, rbLinkText ); }

function createRbLink( pageTitle, lastEditor ) { return api.get( {			// get the latest SHOW_ROLLBACK_EDIT_COUNT + 1 editors			action: 'query',			formatversion: 2,			prop: 'revisions',			rvlimit: SHOW_ROLLBACK_EDIT_COUNT + 1,			titles: pageTitle,			rvprop: 'ids|user'		} ) .then( function ( data ) {			var rbl = getRbLinkFromRevisions( pageTitle, lastEditor, data );			if ( rbl === null ) {				return $.Deferred.reject;			}			return rbl;		} ); }

function getUserFromLink( $link ) { if ( $link.hasClass( 'mw-anonuserlink' ) ) { // Works also for shortened IPv6 addresses return $link.attr( 'title' ).split( '/' )[ 1 ]; }		return $link.text; }

function getPageFromLink( $li ) { var $diffLink = $li.find( 'a[href*="&diff="]' ); if ( $diffLink.length === 1 ) { return mw.util.getParamValue( 'title', $diffLink.attr( 'href' ) ); }		return null; }

function historyMode { var $history = $( 'ul#pagehistory' ); if ( $history.length === 0 ) { return true; }		createRbLink(			mw.config.get( 'wgPageName' ),			getUserFromLink( $history.find( 'li:first-child span.history-user a.mw-userlink' ).first )		) .done( function ( $rbLink ) {			$rbLink.insertBefore( $undoLink ).after( ' | ' );		} ); }

function diffMode { if ( $ntitle.length === 0 ) { return true; }		createRbLink(			mw.config.get( 'wgPageName' ),			getUserFromLink( $ntitle.find( 'a.mw-userlink' ).first )		) .done( function ( $rbLink ) {			$ntitle.append( '  ', $rbLink );		} ); }

function contributionsMode { var lastEditor; if ( specialPage !== 'Contributions' ) { return true; }		lastEditor = mw.util.getParamValue( 'target' ); if ( lastEditor === null ) { lastEditor = mw.config.get( 'wgPageName' ).split( '/' )[ 1 ]; }		$( '.ns-special ul li' ).each( function {			var pageTitle,				$li = $( this ),				$uctop = $li.find( '.mw-uctop' );			if ( $uctop.length === 1 && $li.find( '.newpage' ).length === 0 ) {				// only top edits, excluding new pages				pageTitle = getPageFromLink( $li );				if ( pageTitle === null ) {					pageTitle = $li.find( '.mw-contributions-title' ).text;				}				createRbLink( pageTitle, lastEditor )				.done( function ( $rbLink ) { $uctop.after( ' ', $rbLink ); } );			}		} );	}

function changesListMode { var seen; if ( [ 'Watchlist', 'Recentchanges', 'Recentchangeslinked' ].indexOf( specialPage ) === -1 ) { return true; }		seen = Object.create( null ); $( '.ns-special ul li' ).each( function {			var $li = $( this ),				pageTitle = getPageFromLink( $li );

if ( pageTitle === null ) { pageTitle = $li.find( '.mw-changeslist-title' ).text; }

if ( seen[ pageTitle ] !== undefined ) { // not the latest edit to this page return; }			seen[ pageTitle ] = true;

createRbLink( pageTitle, getUserFromLink( $li.find( '.mw-userlink' ) ) ) .done( function ( $rbLink ) {				$li.append( ' ', $rbLink );			} ); } );	}

function onMessagesLoaded { // The chain stops as soon as one of the functions takes care of adding rollback links return historyMode && diffMode && contributionsMode && changesListMode; }

function onModulesLoaded { api = new mw.Api; loadMessages( [			'rollback-success',			'rollbacklink',			'rollbacklinkcount',			'rollbacklinkcount-morethan',			'action-rollback',			'tooltip-rollback',			'cantrollback',			'actioncomplete',			'rollbackfailed',			'returnto'		] ) .done( onMessagesLoaded ); }	mw.loader.using( modules, onModulesLoaded ); } );

importScript('User:Lourdes/PageCuration.js'); // Linkback: User:Lourdes/PageCuration.js importScript('User:Writ Keeper/Scripts/massRollback.js'); // Backlink: User:Writ Keeper/Scripts/massRollback.js importScript('User:RedWarn/.js'); // Backlink: User:RedWarn/.js importScript('User:Equazcion/OneClickArchiver.js'); // Backlink: User:Equazcion/OneClickArchiver.js importScript( 'User:Evad37/MoveToDraft.js' ); // Backlink: User:Evad37/MoveToDraft importScript('User:Enterprisey/reply-link.js'); // Backlink: User:Enterprisey/reply-link.js importScript('User:Smith609/citations.js'); // Backlink: User:Smith609/citations.js importScript('User:Enterprisey/cv-revdel.js');