Merge "updater now shows the SQLite file being used"
[lhc/web/wiklou.git] / resources / mediawiki / mediawiki.util.js
index c697692..05ffcc0 100644 (file)
@@ -5,9 +5,7 @@
        'use strict';
 
        // Local cache and alias
-       var hideMessageTimeout,
-               messageBoxEvents = false,
-               util = {
+       var util = {
 
                /**
                 * Initialisation
                init: function () {
                        var profile, $tocTitle, $tocToggleLink, hideTocCookie;
 
-                       /* Set up $.messageBox */
-                       $.messageBoxNew( {
-                               id: 'mw-js-message',
-                               parent: '#content'
-                       } );
-
                        /* Set tooltipAccessKeyPrefix */
                        profile = $.client.profile();
 
                        }
 
                        /* Fill $content var */
-                       if ( $( '#bodyContent' ).length ) {
-                               // Vector, Monobook, Chick etc.
-                               util.$content = $( '#bodyContent' );
-
-                       } else if ( $( '#mw_contentholder' ).length ) {
-                               // Modern
-                               util.$content = $( '#mw_contentholder' );
+                       util.$content = ( function () {
+                               var i, l, $content, selectors;
+                               selectors = [
+                                       // The preferred standard for setting $content (class="mw-body")
+                                       // You may also use (class="mw-body mw-body-primary") if you use
+                                       // mw-body in multiple locations.
+                                       // Or class="mw-body-primary" if you want $content to be deeper
+                                       // in the dom than mw-body
+                                       '.mw-body-primary',
+                                       '.mw-body',
+
+                                       /* Legacy fallbacks for setting the content */
+                                       // Vector, Monobook, Chick, etc... based skins
+                                       '#bodyContent',
+
+                                       // Modern based skins
+                                       '#mw_contentholder',
+
+                                       // Standard, CologneBlue
+                                       '#article',
+
+                                       // #content is present on almost all if not all skins. Most skins (the above cases)
+                                       // have #content too, but as an outer wrapper instead of the article text container.
+                                       // The skins that don't have an outer wrapper do have #content for everything
+                                       // so it's a good fallback
+                                       '#content',
+
+                                       // If nothing better is found fall back to our bodytext div that is guaranteed to be here
+                                       '#mw-content-text',
+
+                                       // Should never happen... well, it could if someone is not finished writing a skin and has
+                                       // not inserted bodytext yet. But in any case <body> should always exist
+                                       'body'
+                               ];
+                               for ( i = 0, l = selectors.length; i < l; i++ ) {
+                                       $content = $( selectors[i] ).first();
+                                       if ( $content.length ) {
+                                               return $content;
+                                       }
+                               }
 
-                       } else if ( $( '#article' ).length ) {
-                               // Standard, CologneBlue
-                               util.$content = $( '#article' );
-
-                       } else {
-                               // #content is present on almost all if not all skins. Most skins (the above cases)
-                               // have #content too, but as an outer wrapper instead of the article text container.
-                               // The skins that don't have an outer wrapper do have #content for everything
-                               // so it's a good fallback
-                               util.$content = $( '#content' );
-                       }
+                               // Make sure we don't unset util.$content if it was preset and we don't find anything
+                               return util.$content;
+                       } )();
 
                        // Table of contents toggle
                        $tocTitle = $( '#toctitle' );
                 * @return mixed Parameter value or null.
                 */
                getParamValue: function ( param, url ) {
-                       url = url || document.location.href;
+                       if ( url === undefined ) {
+                               url = document.location.href;
+                       }
                        // Get last match, stop at hash
                        var     re = new RegExp( '^[^#]*[&?]' + $.escapeRE( param ) + '=([^&#]*)' ),
                                m = re.exec( url );
 
                /*
                 * @var jQuery
-                * A jQuery object that refers to the page-content element
+                * A jQuery object that refers to the content area element
                 * Populated by init().
                 */
                $content: null,
                        // just add it to the bottom of their 'sidebar' element as a fallback
                        switch ( mw.config.get( 'skin' ) ) {
                        case 'standard':
-                       case 'cologneblue':
                                $( '#quickbar' ).append( $link.after( '<br/>' ) );
                                return $link[0];
                        case 'nostalgia':
                 * Calling with no arguments, with an empty string or null will hide the message
                 *
                 * @param message {mixed} The DOM-element, jQuery object or HTML-string to be put inside the message box.
-                * @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.
+                * @depreceated Use mw.notify
                 */
-               jsMessage: function ( message, className ) {
-                       var $messageDiv = $( '#mw-js-message' );
-
+               jsMessage: function ( message ) {
                        if ( !arguments.length || message === '' || message === null ) {
-                               $messageDiv.empty().hide();
-                               stopHideMessageTimeout();
-                               return true; // Emptying and hiding message is intended behaviour, return true
-                       } else {
-                               // 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.
-                               if ( !$messageDiv.length ) {
-                                       $messageDiv = $( '<div id="mw-js-message"></div>' );
-                                       if ( util.$content.parent().length ) {
-                                               util.$content.parent().prepend( $messageDiv );
-                                       } else {
-                                               return false;
-                                       }
-                               }
-
-                               if ( !messageBoxEvents ) {
-                                       messageBoxEvents = true;
-                                       $messageDiv
-                                               .on( {
-                                                       'mouseenter': stopHideMessageTimeout,
-                                                       'mouseleave': startHideMessageTimeout,
-                                                       'click': hideMessage
-                                               } )
-                                               .on( 'click', 'a', function ( e ) {
-                                                       // Prevent links, even those that don't exist yet, from causing the
-                                                       // message box to close when clicked
-                                                       e.stopPropagation();
-                                               } );
-                               }
-
-                               if ( className ) {
-                                       $messageDiv.prop( 'className', 'mw-js-message-' + className );
-                               }
-
-                               if ( typeof message === 'object' ) {
-                                       $messageDiv.empty();
-                                       $messageDiv.append( message );
-                               } else {
-                                       $messageDiv.html( message );
-                               }
-
-                               $messageDiv.slideDown();
-                               startHideMessageTimeout();
                                return true;
                        }
+                       if ( typeof message !== 'object' ) {
+                               message = $.parseHTML( message );
+                       }
+                       mw.notify( message, { autoHide: true, tag: 'legacy' } );
+                       return true;
                },
 
                /**
                 * is determined by validation.
                 */
                validateEmail: function ( mailtxt ) {
-                       var rfc5322_atext, rfc1034_ldh_str, HTML5_email_regexp;
+                       var rfc5322Atext, rfc1034LdhStr, html5EmailRegexp;
 
                        if ( mailtxt === '' ) {
                                return null;
                                                 "|" / "}" /
                                                 "~"
                        */
-                       rfc5322_atext = "a-z0-9!#$%&'*+\\-/=?^_`{|}~";
+                       rfc5322Atext = 'a-z0-9!#$%&\'*+\\-/=?^_`{|}~';
 
                        /**
                         * Next define the RFC 1034 'ldh-str'
                         *      <let-dig-hyp> ::= <let-dig> | "-"
                         *      <let-dig> ::= <letter> | <digit>
                         */
-                       rfc1034_ldh_str = "a-z0-9\\-";
+                       rfc1034LdhStr = 'a-z0-9\\-';
 
-                       HTML5_email_regexp = new RegExp(
+                       html5EmailRegexp = new RegExp(
                                // start of string
                                '^'
                                +
                                // User part which is liberal :p
-                               '[' + rfc5322_atext + '\\.]+'
+                               '[' + rfc5322Atext + '\\.]+'
                                +
                                // 'at'
                                '@'
                                +
                                // Domain first part
-                               '[' + rfc1034_ldh_str + ']+'
+                               '[' + rfc1034LdhStr + ']+'
                                +
                                // Optional second part and following are separated by a dot
-                               '(?:\\.[' + rfc1034_ldh_str + ']+)*'
+                               '(?:\\.[' + rfc1034LdhStr + ']+)*'
                                +
                                // End of string
                                '$',
                                // RegExp is case insensitive
                                'i'
                        );
-                       return (null !== mailtxt.match( HTML5_email_regexp ) );
+                       return (null !== mailtxt.match( html5EmailRegexp ) );
                },
 
                /**
                }
        };
 
-       // Message auto-hide helpers
-       function hideMessage() {
-               $( '#mw-js-message' ).fadeOut( 'slow' );
-       }
-       function stopHideMessageTimeout() {
-               clearTimeout( hideMessageTimeout );
-       }
-       function startHideMessageTimeout() {
-               clearTimeout( hideMessageTimeout );
-               hideMessageTimeout = setTimeout( hideMessage, 5000 );
-       }
-
        mw.util = util;
 
 }( mediaWiki, jQuery ) );