resourceloader: Create mediawiki.base.js and move mw.inspect to it
authorTimo Tijhof <krinklemail@gmail.com>
Wed, 30 May 2018 17:44:29 +0000 (18:44 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Wed, 30 May 2018 17:44:29 +0000 (18:44 +0100)
As a first step to splitting the 'mediawiki' module, start by
splitting the file. The two files (like the other files in the
same directory) are still concatenated and run at the same time.

The only difference being that the private variables aren't available,
and it forces us to think about not being able to call the methods
during initialisation given the base file will execute after the
main one, making its methods not yet available during the split
time between the two.

From the perspective of regular modules, this changes nothing
as it will still load as one atomic unit defining the same public
API as before.

Bug: T192623
Change-Id: I552ae02e49c4d30070e166a504f454e334e8e75e

resources/Resources.php
resources/src/mediawiki/mediawiki.base.js [new file with mode: 0644]
resources/src/mediawiki/mediawiki.js

index e624dc3..b32bbcd 100644 (file)
@@ -856,6 +856,7 @@ return [
                        'resources/src/mediawiki/mediawiki.js',
                        'resources/src/mediawiki/mediawiki.requestIdleCallback.js',
                        'resources/src/mediawiki/mediawiki.errorLogger.js',
+                       'resources/src/mediawiki/mediawiki.base.js',
                ],
                'debugScripts' => 'resources/src/mediawiki/mediawiki.log.js',
                'targets' => [ 'desktop', 'mobile' ],
diff --git a/resources/src/mediawiki/mediawiki.base.js b/resources/src/mediawiki/mediawiki.base.js
new file mode 100644 (file)
index 0000000..b68d779
--- /dev/null
@@ -0,0 +1,34 @@
+/*!
+ * This file is currently loaded as part of the 'mediawiki' module and therefore
+ * concatenated to mediawiki.js and executed at the same time. This file exists
+ * to help prepare for splitting up the 'mediawiki' module.
+ * This effort is tracked at https://phabricator.wikimedia.org/T192623
+ *
+ * In short:
+ *
+ * - mediawiki.js will be reduced to the minimum needed to define mw.loader and
+ *   mw.config, and then moved to its own private "mediawiki.loader" module that
+ *   can be embedded within the StartupModule response.
+ *
+ * - mediawiki.base.js and other files in this directory will remain part of the
+ *   "mediawiki" module, and will remain a default/implicit dependency for all
+ *   regular modules, just like jquery and wikibits already are.
+ */
+/* globals mw */
+( function () {
+       /**
+        * @class mw
+        * @singleton
+        */
+
+       /**
+        * @inheritdoc mw.inspect#runReports
+        * @method
+        */
+       mw.inspect = function () {
+               var args = arguments;
+               mw.loader.using( 'mediawiki.inspect', function () {
+                       mw.inspect.runReports.apply( mw.inspect, args );
+               } );
+       };
+}() );
index b00cbff..a2af443 100644 (file)
                                        return registry[ moduleName ].module.exports;
                                },
 
-                               /**
-                                * @inheritdoc mw.inspect#runReports
-                                * @method
-                                */
-                               inspect: function () {
-                                       var args = slice.call( arguments );
-                                       mw.loader.using( 'mediawiki.inspect', function () {
-                                               mw.inspect.runReports.apply( mw.inspect, args );
-                                       } );
-                               },
-
                                /**
                                 * On browsers that implement the localStorage API, the module store serves as a
                                 * smart complement to the browser cache. Unlike the browser cache, the module store