MediaWiki:Common.js

/** * Keep code in MediaWiki:Common.js to a minimum as it is unconditionally * loaded for all users on every wiki page. If possible create a gadget that is * enabled by default instead of adding it here (since gadgets are fully * optimized ResourceLoader modules with possibility to add dependencies etc.) * * Since Common.js isn't a gadget, there is no place to declare its * dependencies, so we have to lazy load them with mw.loader.using on demand and * then execute the rest in the callback. In most cases these dependencies will * be loaded (or loading) already and the callback will not be delayed. In case a * dependency hasn't arrived yet it'll make sure those are loaded before this. */

/*jslint browser: true, vars: true, plusplus:true */ /*globals mw, $, importStylesheet, importScript*/ "use strict"; /** The JavaScript contained here will be applied to all skins.



/** * Tampilkan tombol "Sunting deskripsi" di Warung Kopi (Bantuan) untuk autoconfirmed * Secara baku, tombol tersebut disembunyikan lewat MediaWiki:Common.css * * Pemelihara: Pengguna:Kenrick95 */ function hideEditDescription { if (mw.config.get('wgPageName') === "Wikipedia:Warung_Kopi_(Bantuan)"	 && mw.config.get('wgUserGroups').indexOf("autoconfirmed") > -1) { var styleTag = $(' .flow-ui-boardDescriptionWidget-editButton { visibility: visible !important; } '); $('html > head').append(styleTag); } } mw.hook('wikipage.content').add(hideEditDescription);

/** Sembunyikan tombol daftar ************************************************ * *  Deskripsi:  Menyembunyikan tombol "Bergabung menjadi kontributor" *             di Halaman Utama, MediaWiki:Nocreatetext * 			 jika telah masuk log * Pemelihara: Pengguna:Kenrick95 */ function hideSignup { if (($(".idwp-signup-button").length > 0) && (mw.config.get('wgUserName') !== null)) { $(".idwp-signup-button").hide; } } mw.hook('wikipage.content').add(hideSignup);

/** InterProject ******************************************************* * *  Deskripsi:  Membuat pranala-pranala di menu samping (seperti interwiki) *             ke proyek-proyek Wikimedia yang lain *             Lihat Templat:Interproyek. * Pemelihara: Admin */

function iProject { if (document.getElementById("interProyek")) { mw.loader.using('mediawiki.util').done(function {			mw.util.addCSS('#interProyek {display: none; speak: none;}');		}); var iProjectText = ' Proyek lain<\/h3> ' + $("#interProyek").html + ' '; $("#mw-panel").append(iProjectText); $("#p-ipj").addClass("portal"); $("#p-ipj").addClass("expanded"); $("#p-ipj").attr("role", "navigation"); } } $(iProject);

/** * @source en:MediaWiki:Common.js, 2019-07-26, updated by Kenrick95 * Collapsible tables; reimplemented with mw-collapsibe * Styling is also in place to avoid FOUC * * Allows tables to be collapsed, showing only the header. See Help:Collapsing. * @version 3.0.0 (2018-05-20) * @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTables.js * @author User:R. Koot * @author User:Krinkle * @author User:TheDJ * @deprecated Since MediaWiki 1.20: Use class="mw-collapsible" instead which * is supported in MediaWiki core. Shimmable since MediaWiki 1.32 */ function makeCollapsibleMwCollapsible( $content ) { var $tables = $content .find( 'table.collapsible:not(.mw-collapsible)' ) .addClass( 'mw-collapsible' );

$.each( $tables, function( index, table ) {		// mw.log.warn( 'This page is using the deprecated class collapsible. Please replace it with mw-collapsible.');		if( $( table ).hasClass( 'collapsed') ) {			$( table ).addClass( 'mw-collapsed' );			// mw.log.warn( 'This page is using the deprecated class collapsed. Please replace it with mw-collapsed.');		}	} ); if( $tables.length > 0 ) { mw.loader.using( 'jquery.makeCollapsible' ).then( function {			$tables.makeCollapsible;		} ); } } mw.hook( 'wikipage.content' ).add( makeCollapsibleMwCollapsible );

/** * @source en:MediaWiki:Common.js, 2019-07-26, updated by Kenrick95 * Add support to mw-collapsible for autocollapse, innercollapse and outercollapse * * Maintainers: TheDJ */ function mwCollapsibleSetup( $collapsibleContent ) { var $element, $toggle, autoCollapseThreshold = 2; $.each( $collapsibleContent, function (index, element) {		$element = $( element );		if ( $element.hasClass( 'collapsible' ) ) {			$element.find('tr:first > th:first').prepend( $element.find('tr:first > * > .mw-collapsible-toggle'));		}		if ( $collapsibleContent.length >= autoCollapseThreshold && $element.hasClass( 'autocollapse' ) ) {			$element.data( 'mw-collapsible' ).collapse;		} else if ( $element.hasClass( 'innercollapse' ) ) {			if ( $element.parents( '.outercollapse' ).length > 0 ) {				$element.data( 'mw-collapsible' ).collapse;			}		}		// because of colored backgrounds, style the link in the text color		// to ensure accessible contrast		$toggle = $element.find( '.mw-collapsible-toggle' );		if ( $toggle.length ) {			// Make the toggle inherit text color			if( $toggle.parent[0].style.color ) {				$toggle.find( 'a' ).css( 'color', 'inherit' );			}		}	} ); }

mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup );

/** * Dynamic Navigation Bars (experimental) * * Description: See NavFrame. * Maintainers: UNMAINTAINED */ var collapseCaption = 'sembunyikan'; var expandCaption = 'tampilkan'; /* set up the words in your language */ var navigationBarHide = '[' + collapseCaption + ']'; var navigationBarShow = '[' + expandCaption + ']';

/** * Shows and hides content and picture (if available) of navigation bars * Parameters: *    indexNavigationBar: the index of navigation bar to be toggled **/ window.toggleNavigationBar = function (indexNavigationBar, event) { var NavToggle = document.getElementById('NavToggle' + indexNavigationBar); var NavFrame = document.getElementById('NavFrame' + indexNavigationBar); var NavChild;

if (!NavFrame || !NavToggle) { return false; }

/* if shown now */ if (NavToggle.firstChild.data === navigationBarHide) { for (NavChild = NavFrame.firstChild; NavChild !== null; NavChild = NavChild.nextSibling) { if ($(NavChild).hasClass('NavContent') || $(NavChild).hasClass('NavPic')) { NavChild.style.display = 'none'; }       }        NavToggle.firstChild.data = navigationBarShow;

/* if hidden now */ } else if (NavToggle.firstChild.data === navigationBarShow) { for (NavChild = NavFrame.firstChild; NavChild !== null; NavChild = NavChild.nextSibling) { if ($(NavChild).hasClass('NavContent') || $(NavChild).hasClass('NavPic')) { NavChild.style.display = 'block'; }       }        NavToggle.firstChild.data = navigationBarHide; }

event.preventDefault; }; /** * @source en:MediaWiki:Common.js, 2019-07-26, updated by Kenrick95 * Adds show/hide-button to navigation bars. * * @param {jQuery} $content */ function createNavigationBarToggleButton( $content ) { var i, j, navChild, navToggle, navToggleText, isCollapsed, indexNavigationBar = 0; // Iterate over all -elements var $divs = $content.find( 'div.NavFrame:not(.mw-collapsible)' ); $divs.each( function ( i, navFrame ) {		indexNavigationBar++;		navToggle = document.createElement( 'a' );		navToggle.className = 'NavToggle';		navToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );		navToggle.setAttribute( 'href', '#' );		$( navToggle ).on( 'click', $.proxy( toggleNavigationBar, null, indexNavigationBar ) );

isCollapsed = $( navFrame ).hasClass( 'collapsed' ); /**		 * Check if any children are already hidden. This loop is here for backwards compatibility: * the old way of making NavFrames start out collapsed was to manually add style="display:none" * to all the NavPic/NavContent elements. Since this was bad for accessibility (no way to make		 * the content visible without JavaScript support), the new recommended way is to add the class * "collapsed" to the NavFrame itself, just like with collapsible tables. */		for ( navChild = navFrame.firstChild; navChild !== null && !isCollapsed; navChild = navChild.nextSibling ) { if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) { if ( navChild.style.display === 'none' ) { isCollapsed = true; }			}		}		if ( isCollapsed ) { for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) { if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) { navChild.style.display = 'none'; }			}		}		navToggleText = document.createTextNode( isCollapsed ? navigationBarShow : navigationBarHide ); navToggle.appendChild( navToggleText );

// Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked) for ( j = 0; j < navFrame.childNodes.length; j++ ) { if ( $( navFrame.childNodes[j] ).hasClass( 'NavHead' ) ) { navToggle.style.color = navFrame.childNodes[j].style.color; navFrame.childNodes[j].appendChild( navToggle ); }		}		navFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar ); } ); }

mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );

/** Portlet tambahan/Jumlah suntingan ******************************************************* *  *  Deskripsi:  Menambah tombol/portlet tambahan berupa jumlah suntingan pengguna *             Letak: di bawah menu Konribusi di halaman pengguna *               *  Pemelihara: Pengguna:Kenrick95 */ function addEditcountPortlet { if (document.getElementById("t-contributions")) { var sText = 'Statistik pengguna'; var sLink = '//tools.wmflabs.org/xtools-ec/?' + 'project=' + mw.config.get('wgServerName') + '&user=' + mw.config.get('wgRelevantUserName'); mw.loader.using('mediawiki.util').done(function {        	mw.util.addPortletLink( 'p-tb', sLink, sText, 't-editcount', 'Jumlah suntingan pengguna' );		});   } } mw.hook( 'wikipage.content' ).add( addEditcountPortlet );

/** Notice di Bak pasir dan Pembicaraan Wikipedia:Bak pasir ******* *  *  Deskripsi:  Menambah notice-box di Bak pasir dan *             Pembicaraan Wikipedia:Bak pasir *               *  Pemelihara: Pengguna:Bennylin */ function sandboxNotice { var notice = document.createElement('div'); document.getElementById('bodyContent').insertBefore(notice, document.getElementById('contentSub').nextSibling); $.get(       '//id.wikipedia.org/w/index.php?title=Templat:Bakpasir&action=render',        function (data) {            notice.innerHTML = data;        }    ); } if (["view", "edit", "submit"].indexOf(mw.config.get('wgAction')) > -1 &&	["Wikipedia:Bak_pasir", "Pembicaraan_Wikipedia:Bak_pasir"].indexOf(mw.config.get('wgPageName')) > -1) { sandboxNotice; } /** Notice di halaman-halaman pembicaraan ******* *  *  Deskripsi:  Menambah notice-box di ruang nama 1 *               *  Pemelihara: Pengguna:Bennylin */ function talkpageNotice { var notice = document.createElement('div'); var jumpToNav = document.getElementById('jump-to-nav'); if ( !jumpToNav ) return; document.getElementById('bodyContent').insertBefore(   	notice,    	jumpToNav.nextSibling    ); $.get(       '//id.wikipedia.org/w/index.php?title=Templat:Talkheader/core&action=render',        function (data) {            notice.innerHTML = data;        }    ); } if (mw.config.get('wgAction').match(/edit|submit/)) { $(function {        if (document.getElementsByTagName('body')[0].className.match(/ns-1 /)) {            return talkpageNotice;        }    }); }

/** Magic editintros **************************************************** * * Deskripsi:  Menambahkan editintro di halaman disambiguasi, halaman BLP, dan halaman lain yang diperlukan. * Pemelihara: User:RockMFR (en.wikipedia.org/wiki/MediaWiki:Common.js) */

function addEditIntro( name ) { $( '.mw-editsection, #ca-edit' ).find( 'a' ).each( function ( i, el ) {       el.href = $( this ).attr( 'href' ) + '&editintro=' + name;    } ); }

if ( mw.config.get( 'wgNamespaceNumber' ) === 0 ) { $( function {        if ( document.getElementById( 'disambigbox' ) ) {            addEditIntro( 'Template:Disambig_editintro' );        }    } );

$( function {        var cats = mw.config.get('wgCategories');        if ( !cats ) {            return;        }        if ( $.inArray( 'Orang hidup', cats ) !== -1 || $.inArray( 'Semua orang hidup', cats ) !== -1 ) {            addEditIntro( 'Template:BLP_editintro' );        }    } ); }

/** * @source en:MediaWiki:Common.js, 2019-07-26, updated by Kenrick95 * WikiMiniAtlas * * Description: WikiMiniAtlas is a popup click and drag world map. *             This script causes all of our coordinate links to display the WikiMiniAtlas popup button. *             The script itself is located on meta because it is used by many projects. *             See WikiMiniAtlas for more information. * Note - use of this service is recommended to be repalced with mw:Help:Extension:Kartographer */ ( function {	var require_wikiminiatlas = false;	var coord_filter = /geohack/;	$( function  { $( 'a.external.text' ).each( function( key, link ) {			if ( link.href && coord_filter.exec( link.href ) ) {				require_wikiminiatlas = true;				// break from loop				return false;			}		} ); if ( $( 'div.kmldata' ).length ) { require_wikiminiatlas = true; }		if ( require_wikiminiatlas ) { mw.loader.load( '//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript' ); }	} ); } );

/** * Réécriture des titres * * Fonction utilisée par Modèle:Titre incorrect * * La fonction cherche un bandeau de la forme * *   titre * * * Un élément comportant id="DisableRealTitle" désactive la fonction */ function rewritePageH1 { var realTitleBanner = document.getElementById('RealTitleBanner'); if (realTitleBanner) { if (!document.getElementById('DisableRealTitle')) { var realTitle = document.getElementById('RealTitle'); var h1 = document.getElementById('firstHeading'); if (!h1) { h1 = document.getElementsByTagName('h1')[0]; // Nostalgia, Standard }           var realH1 = getTextContent(h1); // ERROR: undefined getTextContent if (realTitle && h1) { var titleText = realTitle.innerHTML; if (titleText === '') { h1.style.display = 'none'; } else { h1.innerHTML = titleText; }

realTitleBanner.style.display = 'none'; var avert = document.createElement('p'); avert.style.fontSize = '80%'; avert.innerHTML = 'Judul yang akan digunakan untuk membuat sebuah pranala internal: ' + realH1.HTMLize + ''; insertAfter(h1.parentNode, avert, h1); // ERROR: undefined insertAfter }       }    } } // Results from Wikidata // if (mw.config.get('wgCanonicalSpecialPageName') === 'Search' || (mw.config.get('wgArticleId') === 0 && mw.config.get('wgCanonicalSpecialPageName') === false)) { mw.loader.load("//en.wikipedia.org/w/index.php?title=MediaWiki:Wdsearch.js&action=raw&ctype=text/javascript"); }

/** * Description: Lazy-load mediawiki.ui.button module when .mw-ui-button is present; extended for mediawiki.ui.input too * Maintainers: User:Edokter. Imported from en.wikipedia.org */ mw.hook('wikipage.content').add(function {    if ((mw.loader.getState('mediawiki.ui.button') === 'registered') && ($('.mw-ui-button').length)) {        mw.loader.load('mediawiki.ui.button');    }    if ((mw.loader.getState('mediawiki.ui.input') === 'registered') && ($('.mw-ui-input').length)) {        mw.loader.load('mediawiki.ui.input');    } });

/** * @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL * @rev 6 */ mw.loader.using('mediawiki.util').done(function {	var extraCSS = mw.util.getParamValue('withCSS'),	    extraJS = mw.util.getParamValue('withJS');	if (extraCSS) {	    if (extraCSS.match(/^MediaWiki:[^&<>=%#]*\.css$/)) {	        importStylesheet(extraCSS);	    } else {	        mw.notify('Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' });	    }	}	if (extraJS) {	    if (extraJS.match(/^MediaWiki:[^&<>=%#]*\.js$/)) {	        importScript(extraJS);	    } else {	        mw.notify('Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' });	    }	} });