User:BryghtShadow/global.js

importArticles( {	type: 'script',	articles: [		// Regular scripts.		'u:dev:MediaWiki:ImportJSPage/code.js',		'u:dev:MediaWiki:MassNullEdit/code.js',		'u:dev:MediaWiki:ModulesLinkToModules.js',		'u:dev:MediaWiki:ThemeToggler.js'	] } );

var cfg = mw.config.get( [	'wgAction',	'wgCanonicalSpecialPageName',	'wgContentLanguage',	'wgNamespaceNumber',	'wgUserLanguage',	'wgTitle' ] );

/** * Helper function to load system messages **/ function getMessages( a ) { return mw.loader.using( "mediawiki.api" ).then( function {		var e = new mw.Api,			t = cfg.wgContentLanguage;		return t !== cfg.wgUserLanguage			? e.getMessages( a, { amlang: t } )			: e.loadMessagesIfMissing( a ).then( function  { return a.reduce( function ( e, t ) {					return e[ t ] = mw.message( t ).plain, e				}, {} ) } )	} ) }

/* * Add line numbers to `.mw-highlight-lines` where length exceeds 100 kB */ mw.hook('wikipage.content').add(function ($content) {	$('.mw-highlight.mw-highlight-lines pre').each(function (_, pre) { if ($('span', pre).length) return; var text = $(pre).text.trim; if (text.length <= 102400) return; $(pre).empty.append(text.split('\n').map(function (line, i) { var n = i + 1; return $(' ', { id: 'L-' + n }).append([				$('', { href: '#L-' + n }).append( $(' ', { class: 'linenos', 'data-line': n }) ),				line + '\n'			]); }));	}); }); /** * Editform access keys. **/ mw.hook( "wikipage.editform" ).add( function ( $ef ) {	// mutation observer	function n( o ) {		var c = o.id ? function ( t ) {			var e = document.getElementById( o.id );			e && o.ok( e, t )		} : function ( t ) {			var e = document.getElementsByClassName( o.cl )[ 0 ];			e && o.ok( e, t )		},		t = new MutationObserver( function ( t, e ) { c( e ) } ).observe( o.p || document, { subtree: !!o.st || !o.p,			childList: 1 } );		return c, t	}	// add accesskey to CodeEditor	n( { p: $ef[ 0 ], cl: "wikiEditor-ui-text", st: 1, ok: function ( t, e ) { e && e.disconnect, // add accesskey to Ace Editor n( {				p: t,				cl: "ace_text-input",				ok: function ( t, e ) {					t.setAttribute( "accesskey", "," )				}			} ), // add accesskey when CodeMirror's syntax highlight is enabled n( {				p: t,				cl: "noime",				ok: function ( t, e ) {					t.setAttribute( "accesskey", "," )				}			} ) }	} ),	// add accesskey to Scribunto console.	828 === cfg.wgNamespaceNumber && n( { p: document.getElementById( "mw-scribunto-console" ), id: "mw-scribunto-input", ok: function ( t, e ) { e && e.disconnect, t.setAttribute( "accesskey", "/" ) }	} ) } );

/** * Add Special:TrackingCategories backlink to tracking categories. **/ mw.loader.using( "mediawiki.Title", function {	var e, r, t, a,		n = "page-header__page-subtitle",		g = new mw.Title( "TrackingCategories", -1 ).getUrl;	14 === cfg.wgNamespaceNumber &&	/view|history/.test( cfg.wgAction ) &&	!$( "." + n + ' a[href="' + g + '"]' ).length &&	( e = "broken-file-category|cite-tracking-category-cite-error|deprecated-self-close-category|duplicate-args-category|expansion-depth-exceeded-category|expensive-parserfunction-category|hidden-category-category|index-category|magiclink-tracking-isbn|math-tracking-category-error|math-tracking-category-render-error|node-count-exceeded-category|noindex-category|post-expand-template-argument-category|post-expand-template-inclusion-category|restricted-displaytitle-ignored|scribunto-common-error-category|scribunto-module-with-errors-category|syntaxhighlight-error-category|template-loop-category|timeline-tracking-category".split( "|" ), r = "trackingcategories", e.push( r ), getMessages( e ).then( function( e ) {			Object.values( e ).includes( cfg.wgTitle ) &&			( t = e[ r ], ( e = ( a = $( "." + n ) ).length ) || ( a = $( " ", { class: n } ), $( ".page-header__main" ).append( a ) ), a.prepend( [					"&lt; ",					$( "", { href: g,						title: t,						text: t					} ),					e && " | "				] ) )		} )	) } );

// Add toggle to hide empty and disabled tracking categories $( function {	'use strict';	var buttonId = 'toggle-empty-tracking-categories';	if ( cfg.wgCanonicalSpecialPageName !== 'TrackingCategories' || $( '#' + buttonId ).length ) {		return;	}

$( '#mw-trackingcategories-table > tbody > tr' ).each( function ( _, tr ) {		var td = $( tr ).find( 'td.mw-trackingcategories-name' ),			emptySpans = td.find( '> span:contains("(empty)")' ),			allSpans = td.find( '> span' );		if ( td.text === 'Category is disabled' || emptySpans.length === allSpans.length ) {			$( tr ).addClass( 'category-is-empty' );		}	} );

mw.hook( 'dev.wds' ).add( function ( wds ) {		var styles = mw.util.addCSS( '.category-is-empty { display: none; }' ),			button = $( ' ' )				.attr( 'id', buttonId )				.addClass( 'wds-button empty-categories-toggle' )				.append( wds.icon( 'eye-small' ) );		button.click( function ( e ) { styles.disabled = !styles.disabled; var name = styles.disabled ? 'eye-small' : 'eye-crossed-small'; $( e.currentTarget ).html( wds.icon( name ) ); } );		$( '#firstHeading' ).append( button );	} ); importArticles( {		type: 'script',		articles: [			'u:dev:MediaWiki:WDSIcons/code.js'		]	} ); } );

// Temp fix for media in classic categories. $( function {	'use strict';	if ( cfg.wgNamespaceNumber !== 14 || $( '.wikia-gallery-item .gallerytext' ).length > 0 ) {		return;	}

mw.loader.using( [ 'mediawiki.util', 'mediawiki.Title' ], function {		const re = /^(.+?) \((\d+[^]+)\)$/;		mw.util.addCSS( '.galleryfilename { display: block; } ' );		mw.util.addCSS( '.galleryfilename-truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }' );		$( '.wikia-gallery-item' ).each( function ( _, item ) { var anchor = $( '.thumb .image', item ), m = re.exec( anchor.attr( 'title' ) ), name = m[1], size = m[2], filename = mw.Title.newFromFileName( name ), galleryText = $( ' ' ) .addClass( 'gallerytext' ), galleryFilename = $( '' ) .addClass( 'galleryfilename galleryfilename-truncate' ) .attr( 'href', anchor.attr( 'href' ) ) .attr( 'title', filename.getPrefixedText ) .text( name ); galleryText.append( [ galleryFilename, size ] ); $( item ).append( galleryText ); } );	} ); } );