MediaWiki:Common.js

維基文庫,自由的圖書館

注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
  • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
  • Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
  • Opera:Ctrl-F5
/*
以下內容(除註明外)修改自 https://en.wikisource.org/w/index.php?title=MediaWiki:Common.js&oldid=5003314
*/



/**
 * 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, $, importStylesheet, importScript */
/* jshint curly:false eqnull:true, strict:false, browser:true, */
 
mw.loader.using( ['mediawiki.util', 'jquery.client'], function () {
/* Begin of mw.loader.using callback */
 
/**
 * Scripts imported from wikisource.org
 * see [[oldwikisource:Wikisource:Shared Scripts]] for details
 */
mw.loader.load('https://wikisource.org/w/index.php?title=MediaWiki:InterWikiTransclusion.js&action=raw&ctype=text/javascript ');


/*
----------------------------------------------------------------
以下內容複製自中文維基百科
*/

/*
==定期強制用戶更新cache==
*/
 
if( (""+mw.config.get('wgUserGroups')).indexOf("user")!=-1 && (mw.config.get('wgAction')=="view") ){
 var today=new Date();
 
 if(!$.cookie("lastload") || isNaN($.cookie("lastload")) ){
  $.cookie("lastload", today.getTime());
 }else{
 
  if( today.getTime()-$.cookie("lastload") >= 7*24*60*60*1000 ){
   $.cookie("lastload", today.getTime());
   if( $.cookie("lastload")==today.getTime() ) window.location.reload(true);
  }else if( today.getTime()-$.cookie("lastload") < 0 ){
   $.cookie("lastload", today.getTime());
  }
 
 }
 
}
 
/*
== 中文處理 ==
 
*/
 
//返回繁簡字串
 
function wgULS(hans,hant,cn,tw,hk,sg,zh){
	ret = {
		'zh-hans':hans||cn||sg,
		'zh-hant':hant||tw||hk,
		'zh-cn':cn||hans||sg,
		'zh-sg':sg||hans||cn,
		'zh-tw':tw||hant||hk,
		'zh-hk':hk||hant||tw
	};
	if (ret[mw.config.get('wgUserLanguage')])
		return ret[mw.config.get('wgUserLanguage')];
	else
		return zh||hant||hans||cn||tw||hk||sg;//保證每一語言有值
}
 
function wgUVS(hans,hant,cn,tw,hk,sg,zh){
	ret = {
		'zh-hans':hans||cn||sg,
		'zh-hant':hant||tw||hk,
		'zh-cn':cn||hans||sg,
		'zh-sg':sg||hans||cn,
		'zh-tw':tw||hant||hk,
		'zh-hk':hk||hant||tw
	};
	if (ret[mw.config.get('wgUserVariant')])
		return ret[mw.config.get('wgUserVariant')];
	else
		return zh||hant||hans||cn||tw||hk||sg;//保證每一語言有值
}
 
/* 當需要時載入對應的 scripts */
 
if (mw.config.get('wgAction') == "edit" || mw.config.get('wgAction') == "submit") //scripts specific to editing pages
{
    importScript("MediaWiki:Common.js/edit.js");
}

/*
複製自中文維基百科內容結束
----------------------------------------------------------------
*/
 
/**
 * @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
 * @revision 2017-05-16
 */
mw.loader.using( ['mediawiki.util'], function () {
	var extraCSS = mw.util.getParamValue( 'withCSS' ),
		extraJS = mw.util.getParamValue( 'withJS' );

	if ( extraCSS ) {
		// WARNING: DO NOT REMOVE THIS "IF" - REQUIRED FOR SECURITY (against XSS/CSRF attacks)
		if ( /^MediaWiki:[^&<>=%#]*\.css$/.test( extraCSS ) ) {
			mw.loader.load( '/w/index.php?title=' + encodeURIComponent( 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 ) {
		// WARNING: DO NOT REMOVE THIS "IF" - REQUIRED FOR SECURITY (against XSS/CSRF attacks)
		if ( /^MediaWiki:[^&<>=%#]*\.js$/.test( extraJS ) ) {
			mw.loader.load( '/w/index.php?title=' + encodeURIComponent( extraJS ) + '&action=raw&ctype=text/javascript' );
		} else {
			mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
		}
	}
});
 
/**
 * Load CSS and JS files temporarily through URL.
 * &use=File1.css|File2.css|File3.js
 *
 * Required modules: mediawiki.util
 * @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL#Load_multiple_files
 * @revision 2014-05-31
 */
mw.loader.using( ['mediawiki.util'], function () {
	var files = mw.util.getParamValue( 'use' ), user, FileRE, ExtRE, path;

	if ( !files ) {
		return;
	}

	user = mw.RegExp.escape( mw.config.get( 'wgUserName', '' ) );
	FileRE = new RegExp( '^(?:MediaWiki:' + ( user ? '|User:' + user + '/' : '' ) + ')[^&<>=%#]*\\.(js|css)$' );
	ExtRE = new RegExp( '^ext\\.[^,]+$' );
	path = mw.config.get('wgServer')
		+ mw.config.get('wgScript')
		+ '?action=raw&ctype=text/';

	$.each( files.split( '|' ), function(k, v) {
		var f = $.trim( v ), what = FileRE.exec( f ) || ['', ''];
		switch ( what[1] ) {
			case  'js':
				mw.loader.load( path + 'javascript&title=' + encodeURIComponent(f) );
				break;
			case 'css':
				mw.loader.load( path + 'css&title=' + encodeURIComponent(f) );
				break;
			default:
				if ( ExtRE.exec( f ) ) {
					mw.loader.load(f);
				}
		}
	});
});
 
/*
 * port from [[:he:mediawiki:common.js]] for [[mediawiki:edittools]] -Steve
 */
/* פונקציה שמשמשת לאיפשור ניקוד ב[[מדיה ויקי:edittools]] */
function nikud(){
 if (document.getElementById('edit-templates')!=null){
  for(var i=0; a = document.getElementsByTagName("span")[i]; i++) {
  if(a.className == "nikud") {
   a.onclick=function(){insertTags('', this.title, '');return false;};
   }
  }
 }
}
$(nikud);
 
/**
 * Icons on the top right of the article title
 * See also CSS
 *
 * @source: www.mediawiki.org/wiki/Snippets/Top_icons
 * @rev: 4
 */
jQuery( document ).ready( function ( $ ) {
        $( '.Top_icon_raw' )
                .removeClass( 'Top_icon_raw' )
                .addClass( 'Top_icon_dynamic' )
                .prependTo( '#firstHeading' );
} );
/* End of mw.loader.using callback */
} );
/* DO NOT ADD CODE BELOW THIS LINE */