MediaWiki:Common.js: Difference between revisions

From WikiMSK

No edit summary
Tag: Reverted
No edit summary
Tag: Manual revert
 
Line 14: Line 14:
/* global mw, $ */
/* global mw, $ */
/* jshint strict:false, browser:true */
/* jshint strict:false, browser:true */
// Add a link to the sidebar visible only for administrators
mw.loader.using(['mediawiki.util', 'mediawiki.api']).then(function() {
    var api = new mw.Api();
    api.getUserInfo({ prop: 'groups' }).done(function(data) {
        var userGroups = data.query.userinfo.groups;
        if (userGroups.indexOf('sysop') !== -1) { // 'sysop' is the group name for administrators
            var adminLinkText = 'Editors Corner'; // Replace this with the desired link text
            var adminLinkURL = 'https://wikimsk.org/wiki/Admin:Editors_Corner'; // Replace this with the desired link URL
            var adminLinkID = 'admin-editorscorner';
            mw.util.addPortletLink(
                'site-navigation',
                adminLinkURL,
                adminLinkText,
                adminLinkID,
                'Admin-only link',
                null,
                '#site-navigation #p-General .mw-portlet-body ul:first-child li:last'
            );
        }
    });
});


mw.loader.using( [ 'mediawiki.util' ] ).done( function () {
mw.loader.using( [ 'mediawiki.util' ] ).done( function () {

Latest revision as of 14:39, 27 March 2023

/**
 * 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.
 */

/* global mw, $ */
/* jshint strict:false, browser:true */

mw.loader.using( [ 'mediawiki.util' ] ).done( function () {
	/* Begin of mw.loader.using callback */

	/**
	 * Main Page layout fixes
	 *
	 * Description: Adds an additional link to the complete list of languages available.
	 * Maintainers: [[User:AzaToth]], [[User:R. Koot]], [[User:Alex Smotrov]]
	 */
	if ( mw.config.get( 'wgPageName' ) === 'Main_Page' || mw.config.get( 'wgPageName' ) === 'Talk:Main_Page' ) {
		$( function () {
			mw.util.addPortletLink( 'p-lang', '//meta.wikimedia.org/wiki/List_of_Wikipedias',
				'Complete list', 'interwiki-completelist', 'Complete list of Wikipedias' );
		} );
	}

	/**
	 * Map addPortletLink to mw.util
	 * @deprecated: Use mw.util.addPortletLink instead.
	 */
	mw.log.deprecate( window, 'addPortletLink', mw.util.addPortletLink, 'Use mw.util.addPortletLink instead' );

	/**
	 * Extract a URL parameter from the current URL
	 * @deprecated: Use mw.util.getParamValue with proper escaping
	 */
	mw.log.deprecate( window, 'getURLParamValue', mw.util.getParamValue, 'Use mw.util.getParamValue instead' );

	/**
	 * Test if an element has a certain class
	 * @deprecated:  Use $(element).hasClass() instead.
	 */
	mw.log.deprecate( window, 'hasClass', function ( element, className ) {
		return $( element ).hasClass( className );
	}, 'Use jQuery.hasClass() instead' );

	/**
	 * @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
	 * @rev 6
	 */
	var extraCSS = mw.util.getParamValue( 'withCSS' ),
		extraJS = mw.util.getParamValue( 'withJS' );

	if ( extraCSS ) {
		if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) {
			mw.loader.load( '/w/index.php?title=' + extraCSS + '&action=raw&ctype=text/css', 'text/css' );
		} else {
			mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
		}
	}

	if ( extraJS ) {
		if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
			mw.loader.load( '/w/index.php?title=' + extraJS + '&action=raw&ctype=text/javascript' );
		} else {
			mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
		}
	}

/**
 * ImageStacks
 * Maintainer: [[User:Hellerhoff]], [[User:DieBuche]]
 */
// Only load if page contains template
mw.hook( 'wikipage.content' ).add( function ( $content ) {
    if ( $content.find( 'div.ImageStack' ).length ) mw.loader.load( 'ext.gadget.ImageStack' );
} );



	}

	/* End of mw.loader.using callback */
 );
/* DO NOT ADD CODE BELOW THIS LINE */


/* Any JavaScript here will be loaded for all users on every page load. */
/*Remove the file size information on the gallery image for dynamicpagelist*/
	var galleryText = document.querySelectorAll('.gallerytext');
	var linkList = [];
	
	for (i = 0; i < galleryText.length; i++) {
	var pageLink = galleryText[i].innerHTML;
	var endLinkIndex = pageLink.indexOf("</a>");
	pageLink = pageLink.slice(0,endLinkIndex);
    pageLink += "</a></p>";
    linkList.push(pageLink);
	}
    
    for (i = 0; i < galleryText.length; i++) {
    document.querySelectorAll('.gallerytext')[i].innerHTML = linkList[i];
	}