「MediaWiki:Common.js」:修訂間差異

出自竹園Wiki
跳至導覽 跳至搜尋
無編輯摘要
(-gtag)
 
(未顯示同一使用者於中間所作的 6 次修訂)
行 247: 行 247:
mw.loader.load( ['ext.bootstrap.grid'] );
mw.loader.load( ['ext.bootstrap.grid'] );


/* UTC Clock */
/* Global site tag (gtag.js) - Google Analytics */
mw.loader.load('//www.mediawiki.org/w/index.php?title=MediaWiki:Gadget-UTCLiveClock.js&action=raw&ctype=text/javascript');
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());


/* 提示 */
gtag('config', 'UA-74641884-5');
mw.hook( 'wikipage.content' ).add( function () {
mw.loader.load("https://www.googletagmanager.com/gtag/js?id=UA-74641884-5");
setTimeout(function (){

var btnLabel = mw.message('wikibase-statementlistview-add').text();
mw.loader.load('//www.mediawiki.org/w/index.php?title=MediaWiki:Gadget-UTCLiveClock.js&action=raw&ctype=text/javascript');
var tip = $('<small>').css('float', 'left').text('(新增請用下方「'+btnLabel+'」按鈕)');
$('#P25 .wikibase-edittoolbar-container').append(tip);
$('#P28 .wikibase-edittoolbar-container').append(tip);
}, 3000);
});

於 2023年1月25日 (三) 15:29 的最新修訂

/*
所有用戶在加載任何頁面時,這裡的JavaScript都會加載
*/

mw.log.deprecate( window, 'JSConfig', {} );

mw.loader.using(['mediawiki.util', 'ext.gadget.site-lib'], function () {
  (function ($, mw) {

    /* 當需要時載入對應的 scripts */
    if (mw.config.get('wgAction') == "edit" || mw.config.get('wgAction') == "submit" || mw.config.get('wgCanonicalSpecialPageName') == 'Search') { // scripts specific to editing pages
      importScript('MediaWiki:Common.js/edit.js');
    }

    // wiki URL
    window.wgProjectURL = {
      en: '//en.wikipedia.org',
      de: '//de.wikipedia.org',
      fr: '//fr.wikipedia.org',
      pl: '//pl.wikipedia.org',
      ja: '//ja.wikipedia.org',
      it: '//it.wikipedia.org',
      nl: '//nl.wikipedia.org',
      pt: '//pt.wikipedia.org',
      es: '//es.wikipedia.org',
      sv: '//sv.wikipedia.org',
      // 僅列前十名其它語言百科
      m: '//meta.wikimedia.org',
      b: '//zh.wikibooks.org',
      q: '//zh.wikiquote.org',
      n: '//zh.wikinews.org',
      wikt: '//zh.wiktionary.org',
      mw: '//www.mediawiki.org',
      commons: '//commons.wikimedia.org'
    };

    /** 將頁面名稱轉換為URL
     *
     * @param page 頁面名稱
     * @param paras 附加後綴對像,用空對像{}做參數可以取得源碼
     */
    window.getWikiPath = function (page, paras) {
      var reg = /^[a-z]+:/;
      var pre = page.match(reg);
      pre = pre && wgProjectURL[pre[0].replace(/:$/, '').toLowerCase()];
      if (pre) {
        page = page.replace(reg, '');
      } else {
        pre = mw.config.get('wgServer');
      } // 保障沒有相對路徑,以照顧在線代理。
      var url = pre + mw.config.get('wgScript') + '?title=' + encodeURI(page.replace(' ', '_'));
      if (typeof paras == 'object') {
        paras.ctype = paras.ctype || 'text';
        paras.action = paras.action || 'raw';
        for (var k in paras) {
          url += '&' + k + '=' + paras[k];
        }
      }
      return url;
    };

    /**
     * Helper script for .hlist class in Common.css
     * Add pseudo-selector class to last-child list items in IE8
     * @source mediawiki.org/wiki/Snippets/Horizontal_lists
     * @revision 6 (2014-08-23)
     * @author [[User:Edokter]]
     */
    var profile = $.client.profile();
    if ( profile.name === 'msie' && profile.versionNumber === 8 ) {
        mw.hook( 'wikipage.content' ).add( function ( $content ) {
            $content.find( '.hlist' ).find( 'dd:last-child, dt:last-child, li:last-child' )
                .addClass( 'hlist-last-child' );
        } );
    }

    /* Fixes for Windows XP font rendering */
    if (navigator.appVersion.search(/windows nt 5/i) != -1) {
        mw.util.addCSS('.IPA {font-family: "Lucida Sans Unicode", "Arial Unicode MS";} ' + 
                       '.Unicode {font-family: "Arial Unicode MS", "Lucida Sans Unicode";}');
    }
    

    // 修正摺疊後定位變化
    $(function () {
      if (location.hash) {
        location.href = location.hash;
      }
    });

    /** metaBox
     *
     * Funcionament de la Plantilla:Metacaixa
     * Implementat per: Usuari:Peleguer.
     * Actualitzat per Joanjoc seguint les indicacions d'en Martorell
     */
    function MetaCaixaInit() {
      // S'executa al carregar-se la pagina, si hi ha metacaixes,
      // s'assignen els esdeveniments als botons
      //alert("MetaCaixaInit");
      var i = 0; // Inicialitzem comptador de caixes
      for (i = 0; i <= 9; i++) {
        var vMc = document.getElementById("mc" + i);
        if (!vMc) break;
        //alert("MetaCaixaInit, trobada Metacaixa mc"+i);
        var j = 1; // Inicialitzem comptador de botons dins de la caixa
        var vPsIni = 0; // Pestanya visible inicial
        for (j = 1; j <= 9; j++) {
          var vBt = document.getElementById("mc" + i + "bt" + j);
          if (!vBt) break;
          //alert("MetaCaixaInit, trobat boto mc"+i+"bt"+j);
          vBt.onclick = MetaCaixaMostraPestanya; // A cada boto assignem l'esdeveniment onclick
          //alert (vBt.className);
          if (vBt.className == "mcBotoSel") vPsIni = j; // Si tenim un boto seleccionat, en guardem l'index
        }
        //alert ("mc="+i+", ps="+j+", psini="+vPsIni );
        if (vPsIni === 0) { // Si no tenim cap boto seleccionat, n'agafem un aleatoriament
          vPsIni = 1 + Math.floor((j - 1) * Math.random());
          //alert ("Activant Pestanya a l'atzar; _mc"+i+"bt"+vPsIni +"_");
          document.getElementById("mc" + i + "ps" + vPsIni).style.display = "block";
          document.getElementById("mc" + i + "ps" + vPsIni).style.visibility = "visible";
          document.getElementById("mc" + i + "bt" + vPsIni).className = "mcBotoSel";
        }
      }
    }

    function MetaCaixaMostraPestanya() {
      // S'executa al clicar una pestanya,
      // aquella es fa visible i les altres s'oculten
      var vMcNom = this.id.substr(0, 3); // A partir del nom del boto, deduïm el nom de la caixa
      var vIndex = this.id.substr(5, 1); // I l'index
      var i = 1;
      for (i = 1; i <= 9; i++) { // busquem totes les pestanyes d'aquella caixa
        //alert(vMcNom+"ps"+i);
        var vPsElem = document.getElementById(vMcNom + "ps" + i);
        if (!vPsElem) break;
        if (vIndex == i) { // Si es la pestanya bona la mostrem i canviem la classe de boto
          vPsElem.style.display = "block";
          vPsElem.style.visibility = "visible";
          document.getElementById(vMcNom + "bt" + i).className = "mcBotoSel";
        } else { // Sino, l'ocultem i canviem la classe de boto
          vPsElem.style.display = "none";
          vPsElem.style.visibility = "hidden";
          document.getElementById(vMcNom + "bt" + i).className = "mcBoto";
        }
      }
      return false; // evitem la recarrega de la pagina
    }
    $(MetaCaixaInit);

    /* 智能討論頁編輯(新建) */
    $(function () {
      var catalk = $('#ca-talk');
      if (catalk.hasClass('new') && mw.config.get('wgNamespaceNumber') != 2) {
        var a = $('a:first', catalk);
        a.attr('href', a.attr('href') + '&section=new');
      }
    });

/**
 * Magic editintros ****************************************************
 *
 * Description: Adds editintros on disambiguation pages and BLP pages.
 * Maintainers: [[User:RockMFR]]
 */
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( '人物', cats ) !== -1 ) {
            addEditIntro( 'Template:BLP_editintro' );
        }
    } );
}

    /* 引用錯誤標籤名字解碼 */
    $(function () {
      $('.anchordecodeme').each(function () {
        $(this).text(decodeURIComponent($(this).text().replace(/\.([0-9A-F]{2})/g, '%$1')));
      });
    });

    /** &withCSS= and &withJS= URL parameters
     * Allow to try custom scripts from MediaWiki space 
     * without editing personal .css or .js files
     */
/**
 * @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$/ ) ) {
        importStylesheet( extraCSS );
    } else {
        mw.notify( '只允許從MediaWiki名字空間加載。', { title: '無效的withCSS值' } );
    }
}

if ( extraJS ) {
    if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
        importScript( extraJS );
    } else {
        mw.notify( '只允許從MediaWiki名字空間加載。', { title: '無效的withJS值' } );
    }
}


    /* 頁面歷史加&hilight=高亮 */
    {
       var hilight = mw.util.getParamValue('hilight');
       if (mw.config.get('wgAction') === 'history' && hilight) {
          $.each(hilight.split(','), function (_, v) {
             $('input[name=oldid][value=' + v + ']').parent().addClass('not-patrolled');
          });
       }
    }

  })(jQuery, mediaWiki);
});

/* Check for any client-side simplified/traditional Chinese conversion */
/* This routine must be placed here to make sure the field is inserted in time */
$('#antispam-container').append(
    $('<input type="text" />').attr({
        id: 'wpAntiConv',
        value: '\u6c49\u6f22'
    })
);

mw.loader.load( ['ext.bootstrap.grid'] );

/* UTC Clock */
mw.loader.load('//www.mediawiki.org/w/index.php?title=MediaWiki:Gadget-UTCLiveClock.js&action=raw&ctype=text/javascript');

/* 提示 */
mw.hook( 'wikipage.content' ).add( function () {
	setTimeout(function (){
		var btnLabel = mw.message('wikibase-statementlistview-add').text();
		var tip = $('<small>').css('float', 'left').text('(新增請用下方「'+btnLabel+'」按鈕)');
		$('#P25 .wikibase-edittoolbar-container').append(tip);
		$('#P28 .wikibase-edittoolbar-container').append(tip);
	}, 3000);
});