Fix Setup.php file-scope test
authorBrad Jorsch <bjorsch@wikimedia.org>
Thu, 4 Oct 2018 20:34:28 +0000 (16:34 -0400)
committerBrad Jorsch <bjorsch@wikimedia.org>
Thu, 4 Oct 2018 20:40:15 +0000 (16:40 -0400)
Way back in r8196, a test was added to assert that Setup.php is being
included at file scope.[1] That test was broken when I633a6ff23 moved the
inclusion of DefaultSettings.php into Setup.php itself.

This fixes the test by having it directly set a variable and see if that
variable is a global. Yes, there's several ways to bypass it, but we're
just trying to avoid accidents here rather than trying to be foolproof.

[1]: Or really, in the same scope as DefaultSettings.php. But it
intended to be checking for file scope.

Change-Id: I9b5f15bf01c2903e8d44d85c54465d90c047cb51

includes/Setup.php

index 43bc2d8..bdfce62 100644 (file)
@@ -35,6 +35,14 @@ if ( !defined( 'MEDIAWIKI' ) ) {
        exit( 1 );
 }
 
+// Check to see if we are at the file scope
+$wgScopeTest = 'MediaWiki Setup.php scope test';
+if ( !isset( $GLOBALS['wgScopeTest'] ) || $GLOBALS['wgScopeTest'] !== $wgScopeTest ) {
+       echo "Error, Setup.php must be included from the file scope.\n";
+       die( 1 );
+}
+unset( $wgScopeTest );
+
 /**
  * Pre-config setup: Before loading LocalSettings.php
  */
@@ -118,12 +126,6 @@ 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 ) ) {
-       echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
-       die( 1 );
-}
-
 mb_internal_encoding( 'UTF-8' );
 
 // Set the configured locale on all requests for consisteny