มีเดียวิกิ:Common.js

จาก วิกิตำรา

หมายเหตุ: หลังจากบันทึกแล้ว, คุณต้องล้างแคชของเบราเซอร์เสียก่อน จึงจะเห็นการเปลี่ยนแปลง: Mozilla: กด reload(หรือ ctrl-r), IE / Opera: ctrl-f5, Safari: cmd-r, Konqueror ctrl-r.

/**
 * Redirect User:Name/skin.js and skin.css to the current skin's pages
 * (unless the 'skin' page really exists)
 * @source: //www.mediawiki.org/wiki/Snippets/Redirect_skin.js
 * @rev: 2
 */
if ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgNamespaceNumber' ) == 2 ) {
	var titleParts = mw.config.get( 'wgPageName' ).split( '/' );
	// Make sure there was a part before and after the slash
	// And that the latter is 'skin.js' or 'skin.css'
	if ( titleParts.length == 2 ) {
		var userSkinPage = titleParts.shift() + '/' + mw.config.get( 'skin' );
		if ( titleParts.slice(-1) == 'skin.js' ) {
			window.location.href = mw.util.getUrl( userSkinPage + '.js' );
		} else if ( titleParts.slice(-1) == 'skin.css' ) {
			window.location.href = mw.util.getUrl( userSkinPage + '.css' );
		}
	}
}

/** Preview before save changes *************************************************************
 *
 *  Description: Force IP to preview before saving changes.
 *               Copyright Marc Mongenet, 2006. Modified by Jutiphan to apply only article namespace
 *  Maintainers: [[User:Jutiphan]], [[User:Geonuch]]
 *  Source [[mediawiki:Manual:Force preview]]
 */
var permittedGroups = ["user"];

function forcePreview()
{
  if( mw.config.get('wgAction') != "edit") return;
  if( mw.config.get('wgUserGroups') === null) {
    mw.config.get('wgUserGroups') = [];
  }
  if ( mw.config.get( "wgUserGroups" ).filter(function(group) {
    return permittedGroups.indexOf(group) > -1;
  }).length ) return;
  var saveButton = document.getElementById("wpSave");
  if( !saveButton )
    return;
  saveButton.disabled = true;
  saveButton.value = "กดแสดงตัวอย่างเพื่อตรวจสอบความถูกต้องก่อนบันทึก";
  saveButton.style.fontWeight = "normal";
  document.getElementById("wpPreview").style.fontWeight = "bold";
}

$(forcePreview);

/*
 * Use Gadgets whenever possible to minimize loading for all users for every page.
 * Wait for mediawiki.util to be ready because some things assume its availability.
 */
mw.loader.using( 'mediawiki.util', function() {	
	// Page specific - lynchpin for [[Help:Dialog|dialog]] [[Category:Dialog javascript pages]]
	importScript( 'MediaWiki:Common.js/w/' + mw.config.get( 'wgPageName' ) );

	// Imported scripts
	importScript('MediaWiki:Common.js/Relics.js');
	importScript('MediaWiki:Common.js/ExtraTools.js');
	importScript('MediaWiki:Common.js/CollapseElements.js');
	importScript('MediaWiki:Common.js/NavigationTabs.js');
	importScript('MediaWiki:Common.js/Displaytitle.js');
	importScript('MediaWiki:Common.js/tabs.js');
	importScript('MediaWiki:Common.js/top.js');
	importScript('MediaWiki:Common.js/Categories.js');
	importScript('MediaWiki:Common.js/use.js');
	importScript('MediaWiki:Common.js/Slideshows.js');
// DO NOT ADD CODE BELOW THIS LINE
});