registration: Don't let extensions load late
authorFlorian Schmidt <florian.schmidt.stargatewissen@gmail.com>
Sat, 3 Dec 2016 17:46:48 +0000 (18:46 +0100)
committerKunal Mehta <legoktm@member.fsf.org>
Sun, 4 Dec 2016 10:12:37 +0000 (02:12 -0800)
We want all extensions to be queued together and load at the same time
so in the future we can properly evaluate dependencies as a whole. If
extensions load late, they would bypass this, potentially causing
issues.

Bug: T117277
Change-Id: I09b306bd6f6ccf4210f36be0118e7f17f2c3d264

includes/Setup.php
includes/registration/ExtensionRegistry.php

index 9f722af..f6631ea 100644 (file)
@@ -36,8 +36,10 @@ if ( !defined( 'MEDIAWIKI' ) ) {
 $fname = 'Setup.php';
 $ps_setup = Profiler::instance()->scopedProfileIn( $fname );
 
-// If any extensions are still queued, force load them
+// Load queued extensions
 ExtensionRegistry::getInstance()->loadFromQueue();
+// Don't let any other extensions load
+ExtensionRegistry::getInstance()->finish();
 
 // Check to see if we are at the file scope
 if ( !isset( $wgVersion ) ) {
index b5c70e9..70d247b 100644 (file)
@@ -59,6 +59,13 @@ class ExtensionRegistry {
         */
        protected $queued = [];
 
+       /**
+        * Whether we are done loading things
+        *
+        * @var bool
+        */
+       private $finished = false;
+
        /**
         * Items in the JSON file that aren't being
         * set as globals
@@ -114,12 +121,23 @@ class ExtensionRegistry {
                $this->queued[$path] = $mtime;
        }
 
+       /**
+        * @throws MWException If the queue is already marked as finished (no further things should
+        *  be loaded then).
+        */
        public function loadFromQueue() {
                global $wgVersion;
                if ( !$this->queued ) {
                        return;
                }
 
+               if ( $this->finished ) {
+                       throw new MWException(
+                               "The following paths tried to load late: "
+                               . implode( ', ', array_keys( $this->queued ) )
+                       );
+               }
+
                // A few more things to vary the cache on
                $versions = [
                        'registration' => self::CACHE_VERSION,
@@ -164,6 +182,15 @@ class ExtensionRegistry {
                $this->queued = [];
        }
 
+       /**
+        * After this is called, no more extensions can be loaded
+        *
+        * @since 1.29
+        */
+       public function finish() {
+               $this->finished = true;
+       }
+
        /**
         * Process a queue of extensions and return their extracted data
         *