MediaWiki:Common.js: Διαφορά μεταξύ των αναθεωρήσεων

Από τη Βικιπαίδεια, την ελεύθερη εγκυκλοπαίδεια
Περιεχόμενο που διαγράφηκε Περιεχόμενο που προστέθηκε
Krinkle (συζήτηση | συνεισφορές)
Remove addPortletLink shortcut. This already exists in the wiki software but this one is less reliable because mw.util isn't loaded by default. It can't be made asynchronous in this case because it has return value.
Krinkle (συζήτηση | συνεισφορές)
Γραμμή 38: Γραμμή 38:
}
}


/** Sysop Javascript *******************************************************
*
* Εισαγωγή javascript που αφορά διαχειριστές από το [[MediaWiki:Sysop.js]].
*/
function sysopFunctions() {
if ( mw.config.get('wgUserGroups') && !window.disableSysopJS ) {
for ( var g = 0; g < mw.config.get('wgUserGroups').length; ++g ) {
if ( mw.config.get('wgUserGroups')[g] == "sysop" ) {
importScript( "MediaWiki:Sysop.js" );
break;
}
}
}
}
$( sysopFunctions );
/** WikiMiniAtlas *******************************************************
/** WikiMiniAtlas *******************************************************
*
*

Έκδοση από την 23:39, 12 Απριλίου 2016

/**
 * 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' );
		}
	}
}

/** &withCSS= and &withJS= URL parameters *******
 * Allow to try custom scripts from MediaWiki space 
 * without editing personal .css or .js files
 */
var extraCSS = mw.util.getParamValue("withCSS");
if ( extraCSS && extraCSS.match(/^MediaWiki:[^&<>=%]*\.css$/) ) {
    importStylesheet(extraCSS);
}
var extraJS = mw.util.getParamValue("withJS");
if ( extraJS && extraJS.match(/^MediaWiki:[^&<>=%]*\.js$/) ) {
    importScript(extraJS);
}
 

// Αν είμαι στο Ειδικό:Upload να φορτωθεί το [[MediaWiki:Upload.js]]
if (mw.config.get('wgCanonicalSpecialPageName') == "Upload")  {
    importScript("MediaWiki:Upload.js");
}

/** WikiMiniAtlas *******************************************************
  *
  *  See [[Meta:WikiMiniAtlas]] for more information. 
  *  Maintainers: [[User:Dschwen]]
  */
( function () {
    var require_wikiminiatlas = false;
    var coord_filter = /geohack/;
    $( function () {
        $( 'a.external.text' ).each( function( key, link ) {
            if ( link.href && coord_filter.exec( link.href ) ) {
                require_wikiminiatlas = true;
                // break from loop
                return false;
            }
        } );
        if ( $( 'div.kmldata' ).length ) {
            require_wikiminiatlas = true;
        }
        if ( require_wikiminiatlas ) {
            mw.loader.load( '//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript' );
        }
    } );
} )();
 

/* Κώδικας ειδικά για Internet Explorer */
 
if (navigator.appName == "Microsoft Internet Explorer")
{
    /** Internet Explorer bug fix **************************************************
     *
     *  Description: Fixes IE horizontal scrollbar bug
     *  Maintainers: [[User:Tom-]]?
     */
 
    var oldWidth;
    var docEl = document.documentElement;
 
    function fixIEScroll()
    {
        if (!oldWidth || docEl.clientWidth > oldWidth)
            doFixIEScroll();
        else
            setTimeout(doFixIEScroll, 1);
 
        oldWidth = docEl.clientWidth;
    }
 
    function doFixIEScroll() {
        docEl.style.overflowX = (docEl.scrollWidth - docEl.clientWidth < 4) ? "hidden" : "";
    }
 
    document.attachEvent("onreadystatechange", fixIEScroll);
    document.attachEvent("onresize", fixIEScroll);
 
 
    /**
     * Remove need for CSS hacks regarding MSIE and IPA.
     */
 
    if (document.createStyleSheet) {
        document.createStyleSheet().addRule('.IPA', 'font-family: "Doulos SIL", "Charis SIL", Gentium, "DejaVu Sans", Code2000, "TITUS Cyberbit Basic", "Arial Unicode MS", "Lucida Sans Unicode", "Chrysanthi Unicode";');
    }
 
 
    //Import scripts specific to Internet Explorer 6
    if (navigator.appVersion.substr(22, 1) == "6")
    {
        importScript("MediaWiki:IE60Fixes.js");
    }
}

//Πρόσθετα κουμπιά στη μπάρα του παραθύρου επεξεργασίας 

if (mwCustomEditButtons) {

mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "//upload.wikimedia.org/wikipedia/en/c/c8/Button_redirect.png",
    "speedTip": "Ανακατεύθυνση",
    "tagOpen": "#ΑΝΑΚΑΤΕΥΘΥΝΣΗ [[",
    "tagClose": "]]",
    "sampleText": "Άρθρο"} ;

mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "//upload.wikimedia.org/wikipedia/en/c/c9/Button_strike.png",
    "speedTip": "Διαγράμμιση",
    "tagOpen": "<s>",
    "tagClose": "</s>",
    "sampleText": "Εισαγωγή κειμένου"};

mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "//upload.wikimedia.org/wikipedia/en/e/ea/Button_align_left.png",
    "speedTip": "Στοίχιση αριστερά",
    "tagOpen": "<div style='text-align: left; direction: ltr; margin-left: 1em;'>\n",
    "tagClose": "\n</div>",
    "sampleText": "Εισαγωγή κειμένου"};

mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "//upload.wikimedia.org/wikipedia/commons/5/5f/Button_center.png",
    "speedTip": "Στοίχιση στο κέντρο",
    "tagOpen": "<div style='text-align: center;'>\n",
    "tagClose": "\n</div>",
    "sampleText": "Εισαγωγή κειμένου"};

mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "//upload.wikimedia.org/wikipedia/en/1/13/Button_enter.png",
    "speedTip": "Εισαγωγή παραγράφου",
    "tagOpen": "<br />\n",
    "tagClose": "",
    "sampleText": ""};

mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "//upload.wikimedia.org/wikipedia/en/8/80/Button_upper_letter.png",
    "speedTip": "Εκθέτης",
    "tagOpen": "<sup>",
    "tagClose": "</sup>",
    "sampleText": "Εισαγωγή κειμένου"};

mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "//upload.wikimedia.org/wikipedia/en/7/70/Button_lower_letter.png",
    "speedTip": "Δείκτης",
    "tagOpen": "<sub>",
    "tagClose": "</sub>",
    "sampleText": "Εισαγωγή κειμένου"};

mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "//upload.wikimedia.org/wikipedia/commons/5/58/Button_small.png",
    "speedTip": "Μικρά γράμματα",
    "tagOpen": "<small>",
    "tagClose": "</small>",
    "sampleText": "Εισαγωγή κειμένου"};

mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "//upload.wikimedia.org/wikipedia/en/f/fd/Button_blockquote.png",
    "speedTip": "Απόσπασμα κειμένου",
    "tagOpen": "<blockquote>\n",
    "tagClose": "\n</blockquote>",
    "sampleText": "Εισαγωγή κειμένου"};
}


/** Διαμόρφωση Κύριας Σελίδας *********************************************************
  *
  *   Προσθήκη συνδέσμου προς τον πλήρη κατάλογο των υπόλοιπων γλωσσών 
  */

if ($.inArray(mw.config.get('wgPageName'), ['\u03a0\u03cd\u03bb\u03b7:\u039a\u03cd\u03c1\u03b9\u03b1' , '\u03a3\u03c5\u03b6\u03ae\u03c4\u03b7\u03c3\u03b7_\u03c0\u03cd\u03bb\u03b7\u03c2:\u039a\u03cd\u03c1\u03b9\u03b1']) !== -1) {
    $(function () {
        mw.util.addPortletLink('p-lang', '//meta.wikimedia.org/wiki/List_of_Wikipedias',
                 'Πλήρης κατάλογος', 'interwiki-completelist', 'Πλήρης κατάλογος Βικιπαιδειών');
        var nstab = document.getElementById('ca-nstab-main');
        if (nstab && mw.config.get('wgUserLanguage')=='el') {
            while (nstab.firstChild) { nstab = nstab.firstChild; }
            nstab.nodeValue = 'Πύλη:Κύρια';
        }
    });
}


$( document ).ready( function () {
	var title = $.trim($('#mw-nstab').data('nstab'));
	if ( title !== '' ) {
		$('#ca-nstab-' + ( mw.config.get('wgCanonicalNamespace').toLowerCase() || 'main' )).find('a').text(title);
	}
});

/** 
  *   Αστεράκι στα αξιόλογα interwiki
  */
mw.loader.load('//en.wikipedia.org/w/index.php?title=MediaWiki:Gadget-featured-articles-links.js&action=raw&ctype=text/javascript');


/* Test if an element has a certain class **************************************
 *
 * Description: Uses regular expressions and caching for better performance.
 * Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
 */
 
var hasClass = (function () {
    var reCache = {};
    return function (element, className) {
        return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
    };
})();
 
 
 
/**
 * Collapsible tables *********************************************************
 *
 * Description: Allows tables to be collapsed, showing only the header. See
 *              [[Wikipedia:NavFrame]].
 * Maintainers: [[User:R. Koot]]
 */
 
var autoCollapse = 2;
var collapseCaption = 'απόκρυψη';
var expandCaption = 'εμφάνιση';
 
window.collapseTable = function ( tableIndex ) {
    var Button = document.getElementById( 'collapseButton' + tableIndex );
    var Table = document.getElementById( 'collapsibleTable' + tableIndex );
 
    if ( !Table || !Button ) {
        return false;
    }
 
    var Rows = Table.rows;
    var i;
 
    if ( Button.firstChild.data === collapseCaption ) {
        for ( i = 1; i < Rows.length; i++ ) {
            Rows[i].style.display = 'none';
        }
        Button.firstChild.data = expandCaption;
    } else {
        for ( i = 1; i < Rows.length; i++ ) {
            Rows[i].style.display = Rows[0].style.display;
        }
        Button.firstChild.data = collapseCaption;
    }
};
 
function createCollapseButtons() {
    var tableIndex = 0;
    var NavigationBoxes = {};
    var Tables = document.getElementsByTagName( 'table' );
    var i;
 
    function handleButtonLink( index, e ) {
        window.collapseTable( index );
        e.preventDefault();
    }
 
    for ( i = 0; i < Tables.length; i++ ) {
        if ( $( Tables[i] ).hasClass( 'collapsible' ) ) {
 
            /* only add button and increment count if there is a header row to work with */
            var HeaderRow = Tables[i].getElementsByTagName( 'tr' )[0];
            if ( !HeaderRow ) continue;
            var Header = HeaderRow.getElementsByTagName( 'th' )[0];
            if ( !Header ) continue;
 
            NavigationBoxes[ tableIndex ] = Tables[i];
            Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex );
 
            var Button     = document.createElement( 'span' );
            var ButtonLink = document.createElement( 'a' );
            var ButtonText = document.createTextNode( collapseCaption );
 
            Button.className = 'collapseButton';  /* Styles are declared in Common.css */
 
            ButtonLink.style.color = Header.style.color;
            ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );
            ButtonLink.setAttribute( 'href', '#' );
            $( ButtonLink ).on( 'click', $.proxy( handleButtonLink, ButtonLink, tableIndex ) );
            ButtonLink.appendChild( ButtonText );
 
            Button.appendChild( document.createTextNode( '[' ) );
            Button.appendChild( ButtonLink );
            Button.appendChild( document.createTextNode( ']' ) );
 
            Header.insertBefore( Button, Header.firstChild );
            tableIndex++;
        }
    }
 
    for ( i = 0;  i < tableIndex; i++ ) {
        if ( $( NavigationBoxes[i] ).hasClass( 'collapsed' ) || ( tableIndex >= autoCollapse && $( NavigationBoxes[i] ).hasClass( 'autocollapse' ) ) ) {
            window.collapseTable( i );
        } 
        else if ( $( NavigationBoxes[i] ).hasClass ( 'innercollapse' ) ) {
            var element = NavigationBoxes[i];
            while ((element = element.parentNode)) {
                if ( $( element ).hasClass( 'outercollapse' ) ) {
                    window.collapseTable ( i );
                    break;
                }
            }
        }
    }
}
 
mw.hook( 'wikipage.content' ).add( createCollapseButtons );
 
/**
 * Dynamic Navigation Bars (experimental)
 *
 * Description: See [[Wikipedia:NavFrame]].
 * Maintainers: UNMAINTAINED
 */
 
/* set up the words in your language */
var NavigationBarHide = '[' + collapseCaption + ']';
var NavigationBarShow = '[' + expandCaption + ']';
 
/**
 * Shows and hides content and picture (if available) of navigation bars
 * Parameters:
 *     indexNavigationBar: the index of navigation bar to be toggled
 **/
window.toggleNavigationBar = function ( indexNavigationBar, event ) {
    var NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
    var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
    var NavChild;
 
    if ( !NavFrame || !NavToggle ) {
        return false;
    }
 
    /* if shown now */
    if ( NavToggle.firstChild.data === NavigationBarHide ) {
        for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
            if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
                NavChild.style.display = 'none';
            }
        }
    NavToggle.firstChild.data = NavigationBarShow;
 
    /* if hidden now */
    } else if ( NavToggle.firstChild.data === NavigationBarShow ) {
        for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
            if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
                NavChild.style.display = 'block';
            }
        }
        NavToggle.firstChild.data = NavigationBarHide;
    }
 
    event.preventDefault();
};
 
/* adds show/hide-button to navigation bars */
function createNavigationBarToggleButton() {
    var indexNavigationBar = 0;
    var NavFrame;
    var NavChild;
    /* iterate over all < div >-elements */
    var divs = document.getElementsByTagName( 'div' );
    for ( var i = 0; (NavFrame = divs[i]); i++ ) {
        /* if found a navigation bar */
        if ( $( NavFrame ).hasClass( 'NavFrame' ) ) {
 
            indexNavigationBar++;
            var NavToggle = document.createElement( 'a' );
            NavToggle.className = 'NavToggle';
            NavToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
            NavToggle.setAttribute( 'href', '#' );
            $( NavToggle ).on( 'click', $.proxy( window.toggleNavigationBar, window, indexNavigationBar ) );
 
            var isCollapsed = $( NavFrame ).hasClass( 'collapsed' );
            /**
             * Check if any children are already hidden.  This loop is here for backwards compatibility:
             * the old way of making NavFrames start out collapsed was to manually add style="display:none"
             * to all the NavPic/NavContent elements.  Since this was bad for accessibility (no way to make
             * the content visible without JavaScript support), the new recommended way is to add the class
             * "collapsed" to the NavFrame itself, just like with collapsible tables.
             */
            for ( NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling ) {
                if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
                    if ( NavChild.style.display === 'none' ) {
                        isCollapsed = true;
                    }
                }
            }
            if ( isCollapsed ) {
                for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
                    if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
                        NavChild.style.display = 'none';
                    }
                }
            }
            var NavToggleText = document.createTextNode( isCollapsed ? NavigationBarShow : NavigationBarHide );
            NavToggle.appendChild( NavToggleText );
 
            /* Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked) */
            for( var j = 0; j < NavFrame.childNodes.length; j++ ) {
                if ( $( NavFrame.childNodes[j] ).hasClass( 'NavHead' ) ) {
                    NavToggle.style.color = NavFrame.childNodes[j].style.color;
                    NavFrame.childNodes[j].appendChild( NavToggle );
                }
            }
            NavFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
        }
    }
}
 
mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );

// END Dynamic Navigation Bars
// ============================================================


/** Magic editintros ****************************************************
 *
 *  Description: Adds editintros on disambiguation pages and BLP pages.
 *  Maintainers: [[User:RockMFR]]
 */

function addEditIntro(name)
{
  var el = document.getElementById('ca-edit');
  if (!el)
    return;
  el = el.getElementsByTagName('a')[0];
  if (el)
    el.href += '&editintro=' + name;
}


if (mw.config.get('wgNamespaceNumber') == 0) {
  $(function(){
    if (document.getElementById('disambig'))
      addEditIntro('Template:Disambig_editintro');
  });
}

/**
 * Description: Stay on the secure server as much as possible
 * Maintainers: [[User:TheDJ]]
 */
if ( mw.config.get('wgServer') == 'https://secure.wikimedia.org' ) {
    /* Old secure server */
    importScript( 'MediaWiki:Common.js/secure.js');
} else if( document.location && document.location.protocol && document.location.protocol == "https:" ) {
  /* New secure servers */
  importScript('MediaWiki:Common.js/secure new.js');
}


 
/**
 * Verwendung von OpenStreetMap in Wikipedia.
 * (c) 2008 by Magnus Manske, Released under GPL

//mediawiki.util is used by openStreetMapToggle
mw.loader.using( [ 'mediawiki.util' ], function() { $( function() {
  var c = $( '#coordinates' );
  if ( !c.length ) {
   return;
  }
 
  var a = c.find( 'a' );
  var geohack = false;
  for (var i = 0; i < a.length; i++) {
    var h = a[i].href;
    if (!h.match(/geohack/)) continue;
    if (h.match(/skyhack/)) continue;
    if (h.match(/_globe:/)) continue; // no OSM for moon, mars, etc
    geohack = true;
    break;
  }
  if ( !geohack ) {
   return;
  }
 
  var separator = $( document.createElement( 'span' ) );
  separator.text( ' · ' );
  separator.attr( 'class', 'noprint coordinates-separator' );
  c.append( separator );
  var img = $( document.createElement( 'img' ) );
  img.attr( {
   'src': '//upload.wikimedia.org/wikipedia/commons/thumb/c/c9/OpenStreetMapLogo.png/17px-OpenStreetMapLogo.png',
   'width': '17px',
   'height': '17px'
  } );
  var a = $( document.createElement( 'a' ) );
  a.attr( {
   'href': '#',
   'title': 'Εμφάνιση συντεταγμένων στον χάρτη του OpenStreetMap',
   'class': 'noprint osm-icon-coordinates'
  } );
  a.click( openStreetMapToggle );
  a.append( img );
  c.append( a );
})});
// The function to toggle
function openStreetMapToggle() {
  var c = $( '#coordinates' );
  if ( !c.length) {
   return;
  }
  var cs = $( '#contentSub' );
  var osm = $( '#openstreetmap' );
 
  if ( cs.length && osm.length ) {
   if ( osm.css( 'display' ) === 'none' ) {
    osm.css( 'display', 'block' );
   } else {
    osm.css( 'display', 'none' );
   }
   return false;
  }
 
  var found_link = false;
  var a = c.find( 'a' );
  var h;
  for (var i = 0; i < a.length; i++) {
   h = a[i].href;
   if (!h.match(/geohack/)) continue;
   found_link = true;
   break;
  }
  if ( !found_link ) {
   return; // No geohack link found
  }
 
  h = h.split('params=')[1];
 
  var url = '//toolserver.org/~kolossos/openlayers/kml-on-ol.php?lang=el&uselang='
          + mw.util.rawurlencode( mw.config.get( 'wgUserLanguage' ) )
          + '&params=' + h
          + '&title=' + mw.util.wikiUrlencode( mw.config.get( 'wgTitle' ) );
 
  var iframe = $( document.createElement( 'iframe' ) );
  iframe.attr( 'id', 'openstreetmap' );
  iframe.css({
   'width': '100%',
   'height': '350px',
   'clear': 'both'
  });
  iframe.attr( 'src', url );
  cs.append( iframe );
  return false;
}
 */
 
/**
 * δημιουργία συνδέσμου "προσθήκη θέματος" στην τελευταία ενότητα
 */
$( function() {
 var newSectionLink = $( '#ca-addsection a' );
 if( newSectionLink.length ) {
  var link = newSectionLink.clone(); //create a copy
  //avoid duplicate accesskey
  link.removeAttr( 'accesskey' ).attr( 'title', function ( index, oldTitle ) {
   return oldTitle.replace( /\s*\[.*\]\s*$/, '' );
  } );
  //add it within the brackets
  var lastEditsectionLink = $( 'span.mw-editsection:last a:last' );
  lastEditsectionLink.after( link );
  lastEditsectionLink.after( ' | ' ); //see [[MediaWiki:Pipe-separator]]
 }
});


mw.loader.load("//en.wikipedia.org/w/index.php?title=MediaWiki:Wdsearch.js&action=raw&ctype=text/javascript");