Initialize mw.util.$content in mediawiki.util
authorFomafix <fomafix@googlemail.com>
Tue, 16 May 2017 04:43:09 +0000 (06:43 +0200)
committerKrinkle <krinklemail@gmail.com>
Tue, 23 May 2017 13:44:20 +0000 (13:44 +0000)
This avoids the public method mw.util.init().

Add a noop function and a deprecation warning to mw.util.init().

The dependency to module 'mediawiki.page.startup' is not necessary anymore
for using mw.util.$content.

Change-Id: Ib8ca3f9afa43de0ff0bb87569dd2ddfddf2a69b8

resources/Resources.php
resources/src/mediawiki/mediawiki.util.js
resources/src/mediawiki/page/startup.js

index 4c9934d..2f1ed48 100644 (file)
@@ -1150,7 +1150,6 @@ return [
                ],
                'scripts' => 'resources/src/mediawiki/mediawiki.notification.js',
                'dependencies' => [
-                       'mediawiki.page.startup',
                        'mediawiki.util',
                ],
                'targets' => [ 'desktop', 'mobile' ],
@@ -1477,7 +1476,6 @@ return [
                'scripts' => 'resources/src/mediawiki.action/mediawiki.action.view.dblClickEdit.js',
                'dependencies' => [
                        'mediawiki.util',
-                       'mediawiki.page.startup',
                        'user.options',
                ],
        ],
@@ -1666,7 +1664,6 @@ return [
        ],
        'mediawiki.page.startup' => [
                'scripts' => 'resources/src/mediawiki/page/startup.js',
-               'dependencies' => 'mediawiki.util',
                'targets' => [ 'desktop', 'mobile' ],
        ],
        'mediawiki.page.patrol.ajax' => [
@@ -1689,7 +1686,6 @@ return [
        'mediawiki.page.watch.ajax' => [
                'scripts' => 'resources/src/mediawiki/page/watch.js',
                'dependencies' => [
-                       'mediawiki.page.startup',
                        'mediawiki.api.watch',
                        'mediawiki.notify',
                        'mediawiki.util',
index b7bbc66..4844e21 100644 (file)
@@ -8,42 +8,6 @@
         */
        var util = {
 
-               /**
-                * Initialisation
-                * (don't call before document ready)
-                */
-               init: function () {
-                       util.$content = ( function () {
-                               var i, l, $node, selectors;
-
-                               selectors = [
-                                       // The preferred standard is 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 use mw-body deeper in the DOM.
-                                       '.mw-body-primary',
-                                       '.mw-body',
-
-                                       // If the skin has no such class, fall back to the parser output
-                                       '#mw-content-text',
-
-                                       // Should never happen... well, it could if someone is not finished writing a
-                                       // skin and has not yet inserted bodytext yet.
-                                       'body'
-                               ];
-
-                               for ( i = 0, l = selectors.length; i < l; i++ ) {
-                                       $node = $( selectors[ i ] );
-                                       if ( $node.length ) {
-                                               return $node.first();
-                                       }
-                               }
-
-                               // Preserve existing customized value in case it was preset
-                               return util.$content;
-                       }() );
-               },
-
                /* Main body */
 
                /**
                /**
                 * The content wrapper of the skin (e.g. `.mw-body`).
                 *
-                * Populated on document ready by #init. To use this property,
+                * Populated on document ready. To use this property,
                 * wait for `$.ready` and be sure to have a module dependency on
-                * `mediawiki.util` and `mediawiki.page.startup` which will ensure
-                * your document ready handler fires after #init.
+                * `mediawiki.util` which will ensure
+                * your document ready handler fires after initialization.
                 *
                 * Because of the lazy-initialised nature of this property,
                 * you're discouraged from using it.
                return true;
        }, 'Use mw.notify instead.' );
 
+       /**
+        * Initialisation of mw.util.$content
+        */
+       function init() {
+               util.$content = ( function () {
+                       var i, l, $node, selectors;
+
+                       selectors = [
+                               // The preferred standard is 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 use mw-body deeper in the DOM.
+                               '.mw-body-primary',
+                               '.mw-body',
+
+                               // If the skin has no such class, fall back to the parser output
+                               '#mw-content-text'
+                       ];
+
+                       for ( i = 0, l = selectors.length; i < l; i++ ) {
+                               $node = $( selectors[ i ] );
+                               if ( $node.length ) {
+                                       return $node.first();
+                               }
+                       }
+
+                       // Should never happen... well, it could if someone is not finished writing a
+                       // skin and has not yet inserted bodytext yet.
+                       return $( 'body' );
+               }() );
+       }
+
+       /**
+        * Former public initialisation. Now a no-op function.
+        *
+        * @method util_init
+        * @deprecated since 1.30
+        */
+       mw.log.deprecate( util, 'init', $.noop, 'Remove the call of mw.util.init().', 'mw.util.init' );
+
+       $( init );
+
        mw.util = util;
        module.exports = util;
 
index 076357a..9655fa4 100644 (file)
@@ -4,7 +4,6 @@
 
        $( function () {
                var $diff;
-               mw.util.init();
 
                /**
                 * Fired when wiki content is being added to the DOM