MediaWiki:Common.js: Difference between revisions

From WikiMSK

No edit summary
No edit summary
Tag: Manual revert
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
/**
* 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. */
/* Any JavaScript here will be loaded for all users on every page load. */
/*Remove the file size information on the gallery image for dynamicpagelist*/
/*Remove the file size information on the gallery image for dynamicpagelist*/
Line 15: Line 108:
     document.querySelectorAll('.gallerytext')[i].innerHTML = linkList[i];
     document.querySelectorAll('.gallerytext')[i].innerHTML = linkList[i];
}
}
var watchChanges = setInterval(function(){
var allEditors = $.fn.getVEInstances();
for(var editor of allEditors){
if(editor.target.getSurface().$element.find('.ve-ce-surface-focused').length){
var html = editor.target.getSurface().getHtml();
editor.target.$element.closest('.ve-area-wrapper').find('textarea').val(html);
}
}
},1000);
/* Toggle advanced search checkboxes;. to use in conjunction with css to hide it if using semantic mediawiki */
/*
const advancedSearchToggle = document.createElement("li");
advancedSearchToggle.className = "advancedSearchToggle";
const newContent = document.createTextNode("˅");
advancedSearchToggle.appendChild(newContent);
const searchTabs = document.querySelector(".search-types ul");
searchTabs.appendChild(advancedSearchToggle);
advancedSearchToggle.addEventListener("click", function() {
  var advancedSearchBox = document.getElementById("mw-searchoptions");
  if (advancedSearchBox.style.display == "none") {
    advancedSearchBox.style.display = "block";
  } else {
    advancedSearchBox.style.display = "none";
  }
});
*/

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];
	}