From 5a855c8625be77687f72deecbb5c7e0b66de094b Mon Sep 17 00:00:00 2001 From: Florian Schmidt Date: Sat, 3 Dec 2016 18:46:48 +0100 Subject: [PATCH] registration: Don't let extensions load late 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 | 4 ++- includes/registration/ExtensionRegistry.php | 27 +++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/includes/Setup.php b/includes/Setup.php index 9f722afd86..f6631eadb9 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -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 ) ) { diff --git a/includes/registration/ExtensionRegistry.php b/includes/registration/ExtensionRegistry.php index b5c70e984b..70d247b7ec 100644 --- a/includes/registration/ExtensionRegistry.php +++ b/includes/registration/ExtensionRegistry.php @@ -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 * -- 2.20.1