From 06a0dec05723eb6a6604421e134345a5abe115a5 Mon Sep 17 00:00:00 2001 From: Fomafix Date: Tue, 16 May 2017 06:43:09 +0200 Subject: [PATCH] Initialize mw.util.$content in mediawiki.util 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 | 4 -- resources/src/mediawiki/mediawiki.util.js | 84 ++++++++++++----------- resources/src/mediawiki/page/startup.js | 1 - 3 files changed, 45 insertions(+), 44 deletions(-) diff --git a/resources/Resources.php b/resources/Resources.php index 4c9934dfec..2f1ed48d2c 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -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', diff --git a/resources/src/mediawiki/mediawiki.util.js b/resources/src/mediawiki/mediawiki.util.js index b7bbc66919..4844e21498 100644 --- a/resources/src/mediawiki/mediawiki.util.js +++ b/resources/src/mediawiki/mediawiki.util.js @@ -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 */ /** @@ -206,10 +170,10 @@ /** * 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. @@ -565,6 +529,48 @@ 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; diff --git a/resources/src/mediawiki/page/startup.js b/resources/src/mediawiki/page/startup.js index 076357a40c..9655fa499d 100644 --- a/resources/src/mediawiki/page/startup.js +++ b/resources/src/mediawiki/page/startup.js @@ -4,7 +4,6 @@ $( function () { var $diff; - mw.util.init(); /** * Fired when wiki content is being added to the DOM -- 2.20.1