merging latest master
[lhc/web/wiklou.git] / skins / common / wikibits.js
index 81cad57..6526e8b 100644 (file)
@@ -1,4 +1,7 @@
-// MediaWiki JavaScript support functions
+/**
+ * MediaWiki legacy wikibits
+ */
+( function ( mw ) {
 
 window.clientPC = navigator.userAgent.toLowerCase(); // Get client info
 window.is_gecko = /gecko/.test( clientPC ) &&
@@ -46,9 +49,6 @@ if ( /msie ([0-9]{1,}[\.0-9]{0,})/.exec( clientPC ) != null
        ie6_bugs = true;
 }
 
-// Global external objects used by this script.
-/*extern ta, stylepath, skin */
-
 // add any onload functions in this hook (please don't hard-code any events in the xhtml source)
 window.doneOnloadHook = undefined;
 
@@ -66,9 +66,8 @@ window.addOnloadHook = function( hookFunct ) {
 };
 
 window.importScript = function( page ) {
-       // TODO: might want to introduce a utility function to match wfUrlencode() in PHP
-       var uri = wgScript + '?title=' +
-               encodeURIComponent(page.replace(/ /g,'_')).replace(/%2F/ig,'/').replace(/%3A/ig,':') +
+       var uri = mw.config.get( 'wgScript' ) + '?title=' +
+               mw.util.wikiUrlencode( page ) +
                '&action=raw&ctype=text/javascript';
        return importScriptURI( uri );
 };
@@ -87,7 +86,7 @@ window.importScriptURI = function( url ) {
 };
 
 window.importStylesheet = function( page ) {
-       return importStylesheetURI( wgScript + '?action=raw&ctype=text/css&title=' + encodeURIComponent( page.replace(/ /g,'_') ) );
+       return importStylesheetURI( mw.config.get( 'wgScript' ) + '?action=raw&ctype=text/css&title=' + mw.util.wikiUrlencode( page ) );
 };
 
 window.importStylesheetURI = function( url, media ) {
@@ -116,20 +115,20 @@ window.appendCSS = function( text ) {
 };
 
 // Special stylesheet links for Monobook only (see bug 14717)
-if ( typeof stylepath != 'undefined' && skin == 'monobook' ) {
+var skinpath = mw.config.get( 'stylepath' ) + '/' + mw.config.get( 'skin' );
+if ( mw.config.get( 'skin' ) === 'monobook' ) {
        if ( opera6_bugs ) {
-               importStylesheetURI( stylepath + '/' + skin + '/Opera6Fixes.css' );
+               importStylesheetURI( skinpath + '/Opera6Fixes.css' );
        } else if ( opera7_bugs ) {
-               importStylesheetURI( stylepath + '/' + skin + '/Opera7Fixes.css' );
+               importStylesheetURI( skinpath + '/Opera7Fixes.css' );
        } else if ( opera95_bugs ) {
-               importStylesheetURI( stylepath + '/' + skin + '/Opera9Fixes.css' );
+               importStylesheetURI( skinpath + '/Opera9Fixes.css' );
        } else if ( ff2_bugs ) {
-               importStylesheetURI( stylepath + '/' + skin + '/FF2Fixes.css' );
+               importStylesheetURI( skinpath + '/FF2Fixes.css' );
        }
 }
 
-
-if ( 'wgBreakFrames' in window && window.wgBreakFrames ) {
+if ( mw.config.get( 'wgBreakFrames' ) ) {
        // Un-trap us from framesets
        if ( window.top != window ) {
                window.top.location = window.location;
@@ -319,7 +318,7 @@ window.addPortletLink = function( portlet, href, text, id, tooltip, accesskey, n
                link.setAttribute( 'title', tooltip );
        }
        if ( accesskey && tooltip ) {
-               updateTooltipAccessKeys( new Array( link ) );
+               updateTooltipAccessKeys( [link] );
        }
 
        if ( nextnode && nextnode.parentNode == node ) {
@@ -367,11 +366,6 @@ window.getInnerText = function( el ) {
        return str;
 };
 
-/* Dummy for deprecated function */
-window.ta = [];
-window.akeytt = function( doId ) {
-};
-
 window.checkboxes = undefined;
 window.lastCheckbox = undefined;
 
@@ -445,7 +439,7 @@ window.checkboxClickHandler = function( e ) {
        From http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/
 */
 window.getElementsByClassName = function( oElm, strTagName, oClassNames ) {
-       var arrReturnElements = new Array();
+       var arrReturnElements = [];
        if ( typeof( oElm.getElementsByClassName ) == 'function' ) {
                /* Use a native implementation where possible FF3, Saf3.2, Opera 9.5 */
                var arrNativeReturn = oElm.getElementsByClassName( oClassNames );
@@ -460,7 +454,7 @@ window.getElementsByClassName = function( oElm, strTagName, oClassNames ) {
                return arrReturnElements;
        }
        var arrElements = ( strTagName == '*' && oElm.all ) ? oElm.all : oElm.getElementsByTagName( strTagName );
-       var arrRegExpClassNames = new Array();
+       var arrRegExpClassNames = [];
        if( typeof oClassNames == 'object' ) {
                for( var i = 0; i < oClassNames.length; i++ ) {
                        arrRegExpClassNames[arrRegExpClassNames.length] =
@@ -521,55 +515,14 @@ window.redirectToFragment = function( fragment ) {
  * Add a cute little box at the top of the screen to inform the user of
  * something, replacing any preexisting message.
  *
- * @param message String -or- Dom Object  HTML to be put inside the right div
- * @param className String   Used in adding a class; should be different for each
- *   call to allow CSS/JS to hide different boxes.  null = no class used.
- * @return Boolean       True on success, false on failure
+ * @deprecated since 1.17 Use mw.util.jsMessage instead.
+ * @param {String|HTMLElement} message To be put inside the message box.
+ * @param {String} className Used in adding a class; Can be used to selectively
+ *  apply CSS to a certain category of messages.  null = no class used.
+ * @return {Boolean} True on success, false on failure
  */
-window.jsMsg = function( message, className ) {
-       if ( !document.getElementById ) {
-               return false;
-       }
-       // We special-case skin structures provided by the software.  Skins that
-       // choose to abandon or significantly modify our formatting can just define
-       // an mw-js-message div to start with.
-       var messageDiv = document.getElementById( 'mw-js-message' );
-       if ( !messageDiv ) {
-               messageDiv = document.createElement( 'div' );
-               if ( document.getElementById( 'column-content' )
-               && document.getElementById( 'content' ) ) {
-                       // MonoBook, presumably
-                       document.getElementById( 'content' ).insertBefore(
-                               messageDiv,
-                               document.getElementById( 'content' ).firstChild
-                       );
-               } else if ( document.getElementById( 'content' )
-               && document.getElementById( 'article' ) ) {
-                       // Non-Monobook but still recognizable (old-style)
-                       document.getElementById( 'article').insertBefore(
-                               messageDiv,
-                               document.getElementById( 'article' ).firstChild
-                       );
-               } else {
-                       return false;
-               }
-       }
-
-       messageDiv.setAttribute( 'id', 'mw-js-message' );
-       messageDiv.style.display = 'block';
-       if( className ) {
-               messageDiv.setAttribute( 'class', 'mw-js-message-' + className );
-       }
-
-       if ( typeof message === 'object' ) {
-               while ( messageDiv.hasChildNodes() ) { // Remove old content
-                       messageDiv.removeChild( messageDiv.firstChild );
-               }
-               messageDiv.appendChild( message ); // Append new content
-       } else {
-               messageDiv.innerHTML = message;
-       }
-       return true;
+window.jsMsg = function () {
+       return mw.util.jsMessage.apply( mw.util, arguments );
 };
 
 /**
@@ -581,7 +534,7 @@ window.jsMsg = function( message, className ) {
 window.injectSpinner = function( element, id ) {
        var spinner = document.createElement( 'img' );
        spinner.id = 'mw-spinner-' + id;
-       spinner.src = stylepath + '/common/images/spinner.gif';
+       spinner.src = mw.config.get( 'stylepath' ) + '/common/images/spinner.gif';
        spinner.alt = spinner.title = '...';
        if( element.nextSibling ) {
                element.parentNode.insertBefore( spinner, element.nextSibling );
@@ -612,9 +565,6 @@ window.runOnloadHook = function() {
        // might cause the function to terminate prematurely
        doneOnloadHook = true;
 
-       updateTooltipAccessKeys( null );
-       setupCheckboxShiftClick();
-
        // Run any added-on functions
        for ( var i = 0; i < onloadFuncts.length; i++ ) {
                onloadFuncts[i]();
@@ -669,5 +619,7 @@ window.removeHandler = function( element, remove, handler ) {
 hookEvent( 'load', runOnloadHook );
 
 if ( ie6_bugs ) {
-       importScriptURI( stylepath + '/common/IEFixes.js' );
-}
\ No newline at end of file
+       importScriptURI( mw.config.get( 'stylepath' ) + '/common/IEFixes.js' );
+}
+
+}( mediaWiki ) );