User:Murph9000/common.js

/** * jQuery 1.11 bug fix. * Fixed in 1.12.1 or later. * https://github.com/jquery/jquery/issues/2100 * * If jQuery.ready.promise is first called after the DOMContentLoaded, * it will incorrectly delay until readyState === 'complete' / 'load' event, * as a workaround for MS-IE garbage. * * It is supposed to align with readyState === 'interactive' / DOMContentLoaded. * * The following makes everything using $.ready incompatible with some * versions of MS-IE that I don't give a damn about, and effectively * kills off the jQuery workaround for the MS garbage. * * Use this at your own risk! * * Use MS browsers at your own risk! */ if ( jQuery.fn.jquery < "1.12" ) { // Bug fixed in jQuery 1.12, function removed in jQuery 3 // Kick off the DOM ready check even if the user does not jQuery.ready.promise; } // Kick jQuery.ready when real standards-compliant browsers are ready if ( !jQuery.isReady && document.readyState === 'interactive' ) { console.info( 'Kicking jQuery.ready, MS-IE garbage sucks!' ); // Handle it asynchronously setTimeout( jQuery.ready ); }

/** * Main immediately-invoked function expression */ ( function ( mw, $ ) {	'use strict';	var FILE = 'common.js';	console.info( FILE + ': Starting' );	console.time( FILE );	console.time( FILE + ':load' );	console.time( FILE + ':ready' );	console.time( FILE + ':UI' );

var conf = mw.config.get( [			'wgAction',			'wgCanonicalSpecialPageName',			'wgEditMessage',			'wgFormattedNamespaces',			'wgIsArticle',			'wgIsProbablyEditable',			'wgNamespaceIds',			'wgNamespaceNumber',			'wgPageName',			'wgTitle',			'wgUserName',		] ), preloadModules = new Set( [			'mediawiki.util',			'jquery.spinner'		] );

if ( conf.wgCanonicalSpecialPageName === 'Blankpage' ) { // User:Murph9000/pagetriagestats-topreviewers.js		preloadModules .add( 'mediawiki.Title' ) .add( 'mediawiki.api' ) .add( 'mediawiki.api' ) .add( 'mediawiki.jqueryMsg' ) .add( 'mediawiki.util' ) .add( 'jquery.spinner' ) ;	}	// User:Murph9000/rollback-toggle.js	preloadModules .add( 'mediawiki.api' ) .add( 'mediawiki.api' ) .add( 'mediawiki.storage' ) .add( 'mediawiki.user' ) .add( 'mediawiki.util' ) ;	if ( conf.wgNamespaceNumber >= 0 ) { // User:Murph9000/t-copyvios.js		preloadModules .add( 'mediawiki.Uri' ) ;	}	mw.loader.load( Array.from( preloadModules ) ); if ( conf.wgIsArticle && 		 conf.wgIsProbablyEditable && 		 conf.wgAction === 'view' ) { // One of the bigger gadgets (mw.loader.inspect reports "76.5 KiB"), // and it's actually a proxy for a remote load from Commons. // If enabled in preferences, it adds a significant chunk of time to		// every page load, even on pages where it does not provide any // functionality. mw.loader.load( 'ext.gadget.HotCat' ); }

mw.loader.using( [ 'mediawiki.util' ] ).done( function {		function loadPage( page, type ) {			mw.loader.load( mw.util.getUrl( page, { action: 'raw', ctype: type } ), type );		}		function loadScript( page ) {			loadPage( page, 'text/javascript' );		}		function loadStyle( page ) {			loadPage( page, 'text/css' );		}

if ( conf.wgCanonicalSpecialPageName === 'Blankpage' ) { loadScript( 'User:Murph9000/pagetriagestats-topreviewers.js' ); }		loadScript( 'User:Murph9000/rollback-toggle.js' ); if ( conf.wgNamespaceNumber >= 0 ) { loadScript( 'User:Murph9000/t-copyvios.js' ); }		//loadScript( 'User:Writ Keeper/Scripts/teahouseUtility.js' ); // Gives one-click option to add Teahouse invitation or talkback to a user //loadScript( 'User:Writ Keeper/Scripts/teahouseTalkback.js' ); // Adds Talkback reminder when you save an edit at the Teahouse //loadScript( 'User:Writ Keeper/Scripts/teahouseTalkbackLink.js' ); // Adds a talkback link to signatures on the Teahouse //loadScript( 'User:Ocaasi/WikiLoveinstallscript.js' ); // Adds Teahouse Badges to WikiLove console.timeEnd( FILE + ':load' ); } );

$.when(		mw.loader.using( [ 'mediawiki.util' ] ),		$.ready	).done( function {		console.timeEnd( FILE + ':ready' );

var	portletLink, $nRecentChanges = $( '#n-recentchanges' ), re_PDNE = / \(page does not exist\)$/;

function isTalk( index ) { // This is how MWNamespace::isTalk does it			return index > 0 && index % 2; }

function isProjectTalkTitle( title ) { var projectTalkTitles = [ 'Help desk', 'Teahouse', 'Administrator intervention against vandalism', 'Administrators\' noticeboard', 'Administrators\' noticeboard/Edit warring', 'Administrators\' noticeboard/Incidents', 'Biographies of living persons/Noticeboard', 'Bot owners\' noticeboard', 'Conflict of interest/Noticeboard', 'Dispute resolution noticeboard', 'Editor assistance/Requests', 'External links/Noticeboard', 'Fringe theories/Noticeboard', 'Neutral point of view/Noticeboard', 'New pages patrol/Noticeboard', 'No original research/Noticeboard', 'Reliable sources/Noticeboard', 'Requests for page protection', ];			return projectTalkTitles.includes( title ) || title.match(					/^(Articles|Miscellany) for deletion/				) || title.match(					/^(Categories|Files|Redirects|Templates) for discussion/				) || title.startsWith( 'Requests for' ) || title.startsWith( 'Sockpuppet investigations' ) || title.startsWith( 'Village pump' ); }

mw.util.addPortletLink(			'p-interaction',			'//tools.wmflabs.org/copypatrol/en',			'CopyPatrol',			'n-copypatrol',			null,			null,			$nRecentChanges		);

mw.util.addPortletLink(			'p-interaction',			mw.util.getUrl( 'Special:NewPages' ),			'New pages',			'n-newpages',			null,			null,			$nRecentChanges		);

mw.util.addPortletLink(			'p-interaction',			mw.util.getUrl( 'Special:NewPagesFeed' ),			'New pages feed',			'n-newpagesfeed',			null,			null,			$nRecentChanges		);

mw.util.addPortletLink(			'p-interaction',			mw.util.getUrl( 'Special:Contributions', { contribs: 'newbie' } ),			'Newbie contribs',			'n-contribs-newbie',			null,			null,			$nRecentChanges		);

// Adds a link to pending changes to the interaction sidebar mw.util.addPortletLink(			'p-interaction',			mw.util.getUrl( 'Special:PendingChanges' ),			'Pending changes',			'n-pendingchanges',			null,			null,			$nRecentChanges		);

// Adds a link to recent changes with ORES filter configuration // Full URL generated by using the UI: // /wiki/Special:RecentChanges?damaging=maybebad%3Blikelybad%3Bverylikelybad&goodfaith=maybebad%3Blikelybad%3Bverylikelybad&hideliu=0&hideanons=0&userExpLevel=&hidemyself=0&hidebyothers=0&hidebots=1&hidehumans=0&hideminor=0&hidemajor=0&hidepageedits=0&hidenewpages=0&hidecategorization=1&hideWikibase=1&hidelog=0&highlight=1&damaging__verylikelybad_color=c5&damaging__likelybad_color=c4&damaging__maybebad_color=c3&damaging__likelygood_color=c1&goodfaith__verylikelybad_color=c5&goodfaith__likelybad_color=c4&goodfaith__maybebad_color=c3&goodfaith__likelygood_color=c2 // Stripped down URL used below, omitting: // &hideliu=0&hideanons=0&userExpLevel=&hidemyself=0&hidebyothers=0&hidebots=1&hidehumans=0&hideminor=0&hidemajor=0&hidepageedits=0&hidenewpages=0&hidecategorization=1&hideWikibase=1&hidelog=0 mw.util.addPortletLink(			'p-interaction',			mw.util.getUrl( 'Special:RecentChanges', { damaging: 'maybebad;likelybad;verylikelybad', goodfaith: 'maybebad;likelybad;verylikelybad', highlight: 1, damaging__likelygood_color: 'c1', damaging__maybebad_color: 'c3', damaging__likelybad_color: 'c4', damaging__verylikelybad_color: 'c5', goodfaith__likelygood_color: 'c2', goodfaith__maybebad_color: 'c3', goodfaith__likelybad_color: 'c4', goodfaith__verylikelybad_color: 'c5', } ),			'Recent changes (ORES)',			'n-recentchanges-ores',			'A list of recent changes in the wiki, with ORES filter enabled',			null,			$nRecentChanges.next		);

portletLink = mw.util.addPortletLink(			'p-tb',			null,			'Enhance rollback',			't-page-rollback',			'Enhance rollback links by using asynchronous API requests, ' +			'rather than navigating to an action page.'		); $( portletLink ).on( 'click', 'a', function ( e ) {			var $spinner,				$link = $( this );

// Remove event handler $( e.delegateTarget ).off( 'click' );

mw.loader.using( 'jquery.spinner' ).then( function {				$spinner = $.createSpinner( { size: 'small', type: 'inline' } );				$link.after( $spinner );

return mw.loader.using( 'mediawiki.page.rollback' ); } ).then( function { mw.notify( 'Enhance rollback', {					title: mw.msg( 'actioncomplete' )				} );

// Remove link container $( e.delegateTarget ).remove; } );

e.preventDefault; } );

if ( conf.wgUserName ) { var $ptSandbox = $( '#pt-sandbox' ), myPageName = conf.wgFormattedNamespaces[2]+':'+conf.wgUserName, myPageUrl = mw.util.getUrl( myPageName );

mw.util.addPortletLink(				'p-personal',				myPageUrl + '/common.css',				'CSS',				'pt-css',				'Your CSS',				null,				$ptSandbox			); mw.util.addPortletLink(				'p-personal',				myPageUrl + '/common.js',				'JS',				'pt-js',				'Your JavaScript',				null,				$ptSandbox			); mw.util.addPortletLink(				'p-personal',				myPageUrl + '/Notes',				'Notes',				'pt-notes',				'Your notes',				null,				$ptSandbox			);

if ( conf.wgAction == 'view' ) { var globalLink; switch ( conf.wgPageName ) { case myPageName + '/common.css': globalLink = document.createElement( 'a' ); globalLink.className = 'external'; globalLink.href = '//meta.wikimedia.org/wiki/' + myPageName + '/global.css'; globalLink.textContent = 'global.css'; break; case myPageName + '/common.js': globalLink = document.createElement( 'a' ); globalLink.className = 'external'; globalLink.href = '//meta.wikimedia.org/wiki/' + myPageName + '/global.js'; globalLink.textContent = 'global.js'; break; }				if ( globalLink ) { var contentSub = document.getElementById( 'contentSub' ); var spanElement = document.createElement( 'span' ); spanElement.className = 'global'; spanElement.appendChild( globalLink ); contentSub.appendChild( spanElement ); }			}		}

/*var element = document.getElementById( 'pt-betafeatures' ); if ( element ) { element.remove; }*/

console.timeEnd(FILE + ':UI');

if ( conf.wgAction == 'view' &&			( isTalk( conf.wgNamespaceNumber ) || ( conf.wgNamespaceNumber === conf.wgNamespaceIds.project &&				isProjectTalkTitle( conf.wgTitle )			 ) )		) {			console.time( FILE + ':talk-contribs' ); $( '#mw-content-text a[title^="User talk:"]',				document.getElementById( 'bodyContent' )			).each( function {				// Handle custom sigs which moved the brackets inside the link				if ( this.textContent.toLowerCase == '(talk)' ) {					this.parentNode.insertBefore( new Text( '(' ), this ); if (this.nextSibling) { this.parentNode.insertBefore( new Text( ')' ), this.nextSibling);					} else {						this.parentNode.appendChild( new Text( ')' )); }					this.textContent = 'talk'; }				if (this.previousSibling && this.nextSibling &&					this.previousSibling.nodeType === Node.TEXT_NODE &&					this.nextSibling.nodeType === Node.TEXT_NODE &&					this.previousSibling.textContent.endsWith( '(' ) && this.nextSibling.textContent.startsWith( ')' )) {					var username = this.getAttribute( 'title' ).substr( 10 ); if ( this.classList.contains( 'new' ) ) { username = username.replace( re_PDNE, '' ); }					var contribs_page = 'Special:Contributions/' + username; var contribs_element = document.createElement( 'a' ); contribs_element.href = mw.util.getUrl( contribs_page ); contribs_element.title = contribs_page; contribs_element.textContent = 'contribs'; this.parentNode.insertBefore( contribs_element, this.nextSibling ); this.parentNode.insertBefore( new Text( ' | ' ), this.nextSibling ); }			});			console.timeEnd( FILE + ':talk-contribs' );		}		/*if (conf.wgAction == 'edit' && conf.wgEditMessage == 'editingsection' && conf.wgNamespaceNumber === 0 && conf.wgPageName.match(/^\d+.*_season$/)) {			var textbox = document.getElementById('wpTextbox1');			var summary = document.getElementById('wpSummary');			var minor = document.getElementById('wpMinoredit');			if (textbox.type != 'textarea') {				console.error(FILE + ': wpTextbox1 is not a textarea!', textbox);				return;			}			var re = /\{\{Navbar-header\|([^|]*)\|\}\}/i;			if (textbox.value.match(re)) {				textbox.value = textbox.value.replace(re, '$1');				summary.value += 'Inappropriate usage of \{\{Navbar-header\}\}, generating invalid VTE links. It is not suitable for use within articles, only inside templates.';				minor.checked = true;				console.log(FILE + ': Removed bad \{\{Navbar-header\}\} usage');			}		}*/	} ); console.timeEnd( FILE ); if ( conf.wgCanonicalSpecialPageName === 'Search' ) { $.when(			mw.loader.using( 'jquery.makeCollapsible' ),			$.ready		).done( function {			var $mwInterwikiResults = $( '#mw-interwiki-results' );			$mwInterwikiResults.addClass( 'mw-collapsible mw-collapsed' )				.find( '.iw-results' ).addClass( 'mw-collapsible-content' );			$mwInterwikiResults.makeCollapsible;		} ); } } )( mediaWiki, jQuery );