MediaWiki:Common.js

Ut Wikiwurdboek

Opmerking: Nei it fêstlizzen kin it nedich wêze de oerslach fan jo blêder te leegjen, foar't de wizigings te sjen binne.

  • Firefox / Safari: Hâld Shift yntreaun wylst jo op Fernije klikke, of typ Ctrl-F5 of Ctrl-R (⌘-R op in Mac)
  • Google Chrome: Typ Ctrl-Shift-R (⌘-Shift-R op in Mac)
  • Internet Explorer / Edge: Hâld Ctrl yntreaun wylst jo Vernieuwen klikke, of typ Ctrl-F5
  • Opera: Typ Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
/* Alle javascript hjir wurdt laden foar eltsenien, alle kearen dat der in side ophelle wurdt. */

/*</pre>
==Wiktionary Customisation==
<pre>*/

/*</pre>
===WT:PREFS===
<pre>*/

// Disabling imports from user namespace. This is a security issue. Do not reinstate. -- [[User:Ladsgroup]]
/*if($.cookie('WiktPrefs') || wgPageName=="Wiktionary:Preferences"){
   importScript(':en:User:Connel_MacKenzie/custom.js');
}*/

/*</pre>
===Page specific extensions===
<pre>*/

/*</pre>
====Wiktionary:Main Page====
<pre>*/
// Hide the title and "Redirected from" (maybe we should keep the redirected from so's people update their bookmarks ;)
if ( mw.config.get('wgIsMainPage') && !( mw.config.get('wgAction') === 'view' || mw.config.get('wgAction') === 'submit' ) ) {
  mw.util.addCSS('.firstHeading {display: block !important;}');
  mw.util.addCSS('#contentSub {display: inline !important;}');
}

/*</pre>
====WT:CUSTOM====
<pre>*/

else if( mw.config.get('wgPageName')=='Help:Customizing_your_monobook' ){
    importScript('MediaWiki:CustomSearch.js');
}

/*</pre>
====Turn headings in comments into real headings on JavaScript source pages====
<pre>*/

else if ((mw.config.get('wgNamespaceNumber') == 2 || mw.config.get('wgNamespaceNumber') == 8) && mw.config.get('wgTitle').lastIndexOf('.js') != -1 && mw.config.get('wgAction') == 'view') {
    importScript('MediaWiki:JavascriptHeadings.js');
}

/*</pre>
====Make Citations: tabs ====
<pre>*/
/* Foar no útskeakele, oant der oerlis west hat.

function citations_tab(){
  
  var mt_caption = 'entry';
  var mt_title = 'View the content page [alt-c]';
  var ct_caption = 'citations';
  var ct_title = 'View the citations page';

  var lookup = new Object();
  var ct_class = '';
  var safeTitle = encodeURIComponent(mw.config.get('wgTitle').replace(/ /g,"_"));

  //Where to put Citations tab
  var insbef = document.getElementById('ca-edit');
  if(! insbef) insbef = document.getElementById('ca-viewsource');
  if(! insbef) return false;
  
  if( mw.config.get('wgCanonicalNamespace') == 'Citations' ){  
 
    //Remove accesskeys etc from Citations tab
    var ct = document.getElementById('ca-nstab-citations');
    ct.removeAttribute('accesskey');
    ct.setAttribute('title',ct_title);
    
    //Reset discussion tab to point to Talk:
    var dt = document.getElementById('ca-talk');
    
    for(var i=0;i<dt.childNodes.length;i++){
      var anc = dt.childNodes[i];
      if(anc.nodeName.toUpperCase()=='A'){
        anc.setAttribute('href',mw.config.get('wgArticlePath').replace("$1","Talk:"+safeTitle));
        lookup['Talk:'+mw.config.get('wgTitle')] = dt;
      }
    }
    if(dt.className) dt.className = dt.className.replace('new','');
    
    //Create main tab before citations tab
    mw.util.addPortletLink('p-cactions',mw.config.get('wgArticlePath').replace("$1",safeTitle),mt_caption,'ca-nstab-main',mt_title,null,ct)
    lookup[mw.config.get('wgTitle')] = document.getElementById('ca-nstab-main');
    
    //Move Citations tab to correct position
    var tabbar = ct.parentNode;
    tabbar.removeChild(ct);
    tabbar.insertBefore(ct,insbef);
    
  }else if( mw.config.get('wgCanonicalNamespace') == '' || mw.config.get('wgCanonicalNamespace') == 'Talk' ){
  
    mw.util.addPortletLink('p-cactions',mw.config.get('wgArticlePath').replace("$1",'Citations:'+safeTitle),ct_caption,'ca-nstab-citations',ct_title,null,insbef); 
    lookup['Citations:'+mw.config.get('wgTitle')]=document.getElementById('ca-nstab-citations');

  }else{ //Nothing to see here...
  
    return false;
  
  }
  
  //Now check for red pages
  var ajaxer = sajax_init_object();
  if(! ajaxer) return false;
  
  var url = wgScriptPath+ '/api.php?format=txt&action=query&prop=info&titles=';
  var spl = '';
  for(var page in lookup){
    url+=spl+encodeURIComponent(page);
    spl='|';
  }
  
  ajaxer.onreadystatechange = function(){
    if( ajaxer.readyState == 4 ){
      if( ajaxer.status == 200 ){
        var resps = ajaxer.responseText.split("Array\n");
        for(var i in resps){
          if(resps[i].indexOf('[missing]')>0 ){
            var start = resps[i].indexOf("[title] => ")+11;
            var end = resps[i].indexOf("\n",start);
            make_tab_red(lookup[resps[i].substr(start,end-start)]);
          }
        }
      }
    }
  }

  ajaxer.open("GET", url);
  ajaxer.send('');

  function make_tab_red(tab){

    tab.className = tab.className?'new':tab.className+' new';

    for( var i=0;i<tab.childNodes.length;i++ ){
      var lnk = tab.childNodes[i];    
      if(lnk.nodeName.toUpperCase() == 'A' ){
        var href = lnk.getAttribute('href');
        lnk.setAttribute('href',href+(href.indexOf('?')>0?'&':'?')+'action=edit');
      }
    }
  }
}

$( citations_tab );

Ein fan útskeakeling citations. */
/*</pre>

==URL Fixes==
<pre>*/

/**
 * doRedirect will redirect if a did you mean box is found, and create a 
 * "redirected from X" if a rdfrom is passed in the get parameters
 * The first half is an ugly workaround for Bugzilla:3339, :(
 * The second half is an ugly workaround for not having serverware support :(
**/

/*</pre>
===Did you mean ____ redirects===
<pre>*/

function doRedirect() {
  var dym = document.getElementById('did-you-mean');
  var wiktDYMfrom= window.location.href.replace(/^(.+[&\?]rdfrom=([^&]+).*|.*)?$/,"$2");
  var wiktRndLang= window.location.href.replace(/^(.+[&\?]rndLang=([^&]+).*|.*)?$/,"$2");

// REDIRECTED FROM
  if( window.location.href.indexOf('rdfrom=')!=-1 ) {
    var insertPosition= document.getElementById("siteSub");
    var div=document.createElement("div");
    if(insertPosition){
      div.setAttribute("id","contentSub");
      var tt=document.createElement('tt');
      var lnk =document.createElement('a');
      lnk.setAttribute("href",mw.config.get('wgArticlePath').replace("$1",wiktDYMfrom)+ '?redirect=no');
      lnk.className="new"; //As they are redlinks
      lnk.appendChild(document.createTextNode(decodeURI(wiktDYMfrom)));
      tt.appendChild(lnk);
      div.appendChild(document.createTextNode("(Auto-redirected from "));
      div.appendChild(tt);
      div.appendChild(document.createTextNode(")"));
      insertPosition.parentNode.insertBefore(div,insertPosition.nextSibling);
      } else {
        alert('No insertposition');
      }

// DID YOU MEAN
    }else{
      if( dym 
          && !window.location.href.match(/[&\?]redirect=no/)
          && ($.cookie('WiktionaryDisableAutoRedirect') != 'true')
        ) {
      var target = dym.firstChild.title;
      var pagetitle = document.getElementsByTagName('h1')[0].firstChild.nodeValue;

      if( pagetitle != target 
          && pagetitle.toLowerCase().replace(/[^a-z]/g, "") == target.toLowerCase().replace(/[^a-z]/g, "")
          && pagetitle.search(/Editing /g) == -1
          && !(document.getElementById('contentSub') && document.getElementById('contentSub').innerHTML.indexOf("Redirected from")>=0) // does contentSub always exist
        ) {
        document.location = mw.config.get('wgArticlePath').replace("$1",encodeURIComponent(target.replace(/\ /g, "_")))
                          + '?rdfrom=' + encodeURIComponent(pagetitle.replace(/ /g,"_"))
                          + '&redirect=no';
      }
    }
  }

// Random page in a given language
  if( window.location.href.indexOf('rndLang=')!=-1 ) {
    var newloc = window.location.href;
    if (newloc.indexOf("#") != -1) {
      document.location = newloc.substring(0, newloc.indexOf('?rndLang=') );
    }
    var insertPosition= document.getElementById("siteSub");
    var div=document.createElement("div");
    if(insertPosition){
      div.setAttribute("id","contentSub");
      var tt = document.createElement('tt');
      var lnk = document.createElement('a');
      lnk.href = "http://connelm.homelinux.com/cgi-bin/randompage?lang=" + wiktRndLang ;
      lnk.appendChild( document.createTextNode(wiktRndLang) );
      tt.appendChild(lnk);
      var tt2=document.createElement('tt');
      var lnk2 =document.createElement('a');
      lnk2.href = "http://tools.wikimedia.de/~cmackenzie/rnd-wikt.html" ;
      lnk2.appendChild(document.createTextNode("Random"));
      tt2.appendChild(lnk2);
      div.appendChild( document.createTextNode("(") );
      div.appendChild(tt2);
      div.appendChild( document.createTextNode(" term in ") );
      div.appendChild(tt);
      div.appendChild(document.createTextNode(", described in English)"));
      insertPosition.parentNode.insertBefore(div,insertPosition.nextSibling);
      } else {
        alert('No insertposition');
      }
  }
}

$(doRedirect);

/*</pre>
===Fix Wikified section titles===
<pre>*/

//[[Link]]
if (/\.5B/.test(window.location.href)) {
  var url=window.location.href.replace(/.5B.5B:/g,"").replace(/.5B/g, "").replace(/.5D/g, "");
  window.location = url;
}

// {temp|template}
if (/\.7B\.7Btemp\.7C(.*?)\.7D\.7D/.test(window.location.href)) {
  var url=window.location.href.replace(/\.7B\.7Btemp.7C/g, ".7B.7B");
  window.location = url;
}

/** Change Special:Search to use a drop-down menu *******************************************************
   *
   *  Description: Change Special:Search to use a drop-down menu, with the default being
   *               the internal MediaWiki engine
   *  Created and maintained by: [[User:Gracenotes]]
   */
 
 if (mw.config.get('wgCanonicalSpecialPageName') == "Search") {
         var searchEngines = [];
         $(SpecialSearchEnhanced);
 }
 
 function SpecialSearchEnhanced() {
         var createOption = function(site, action, mainQ, addQ, addV) {
                 var opt = document.createElement('option');
                 opt.appendChild(document.createTextNode(site));
                 searchEngines[searchEngines.length] = [action, mainQ, addQ, addV];
                 return opt;
         };
 
         if (document.forms['powersearch'])
         var searchForm = document.forms['powersearch'];
         if (document.forms['search'])
         var searchForm = document.forms['search'];
 
         if (searchForm.lsearchbox) {
             var searchBox = searchForm.lsearchbox;
         } else {
             var searchBox = searchForm.search;
         }
         var selectBox = document.createElement('select');
         selectBox.id = 'searchEngine';
         searchForm.onsubmit = function() {
                 var optSelected = searchEngines[document.getElementById('searchEngine').selectedIndex];
                 searchForm.action = optSelected[0];
	             searchBox.name = optSelected[1];
                 searchForm.title.value = optSelected[3];
                 searchForm.title.name = optSelected[2];
         };
         selectBox.appendChild(createOption('MediaWiki search', wgScriptPath + '/index.php', 'search', 'title', 'Special:Search'));
         selectBox.appendChild(createOption('Google', 'http://www.google.com/search', 'q', 'sitesearch', 'en.wiktionary.org'));
         selectBox.appendChild(createOption('Yahoo', 'http://search.yahoo.com/search', 'p', 'vs', 'en.wiktionary.org'));
         selectBox.appendChild(createOption('Windows Live', 'http://search.live.com/results.aspx', 'q', 'q1', 'site:http://en.wiktionary.org'));
         searchBox.style.marginLeft = '0px';
         if (document.getElementById('loadStatus')) {
             var lStat = document.getElementById('loadStatus');
         } else {
             var lStat = searchForm.fulltext;
         }
         lStat.parentNode.insertBefore(selectBox, lStat);
 }