From a5d5ea82cad38a67b31e52fe471a978f09ae6069 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Tue, 25 Feb 2020 01:28:12 +0000 Subject: [PATCH] Provide MW_VERSION and deprecate fake global $wgVersion $wgVersion is not a configuration variable, it should never be changed at run-time. While we've gone in the route of class constants for most constants, this one will not benefit from class-autoloading since it needs to be present from the very beginning. MW_VERSION is named similarly as PHP_VERSION, and $wgVersion is now soft-deprecated. Bug: T212738 Change-Id: I04628de4152dd5c72646813e08ff35e422e265a4 --- RELEASE-NOTES-1.35 | 1 + includes/DefaultSettings.php | 3 ++- includes/Defines.php | 9 +++++++++ includes/MediaWikiVersionFetcher.php | 8 ++++---- tests/phpunit/includes/MediaWikiVersionFetcherTest.php | 3 +-- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/RELEASE-NOTES-1.35 b/RELEASE-NOTES-1.35 index e2c13d9490f..fbb08342dfd 100644 --- a/RELEASE-NOTES-1.35 +++ b/RELEASE-NOTES-1.35 @@ -451,6 +451,7 @@ because of Phabricator reports. - getAllContentFormats - protected $handler (not need anymore) - cleanupHandlersCache (not need anymore) +* (T212738) The $wgVersion global is deprecated; instead, use MW_VERSION. * $wgMemc is deprecated, use MediaWikiServices::getInstance()->getLocalServerObjectCache() instead. * ImagePage::getImageLimitsFromOptions() is deprecated. Use static function diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index e60f53f428a..7c748c03aa1 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -71,8 +71,9 @@ $wgConfigRegistry = [ /** * MediaWiki version number * @since 1.2 + * @deprecated since 1.35; use the MW_VERSION constant instead */ -$wgVersion = '1.35.0-alpha'; +$wgVersion = MW_VERSION; /** * Name of the site. It must be changed in LocalSettings.php diff --git a/includes/Defines.php b/includes/Defines.php index 0269ab60299..01793bbf05b 100644 --- a/includes/Defines.php +++ b/includes/Defines.php @@ -29,6 +29,15 @@ use Wikimedia\Rdbms\IDatabase; * @defgroup Constants MediaWiki constants */ +/** + * The running version of MediaWiki. + * + * This replaces the the $wgVersion global found in earlier versions. + * + * @since 1.35 + */ +define( 'MW_VERSION', '1.35.0-alpha' ); + # Obsolete aliases /** @{ diff --git a/includes/MediaWikiVersionFetcher.php b/includes/MediaWikiVersionFetcher.php index 913ae9a50d6..5bfac45c7d5 100644 --- a/includes/MediaWikiVersionFetcher.php +++ b/includes/MediaWikiVersionFetcher.php @@ -9,19 +9,19 @@ class MediaWikiVersionFetcher { /** - * Returns the MediaWiki version, in the format used by MediaWiki's wgVersion global. + * Get the MediaWiki version, extracted from the PHP source file where it is defined. * * @return string * @throws RuntimeException */ public function fetchVersion() { - $defaultSettings = file_get_contents( __DIR__ . '/DefaultSettings.php' ); + $code = file_get_contents( __DIR__ . '/Defines.php' ); $matches = []; - preg_match( "/wgVersion = '([0-9a-zA-Z\.\-]+)';/", $defaultSettings, $matches ); + preg_match( "/define\( 'MW_VERSION', '([0-9a-zA-Z\.\-]+)'/", $code, $matches ); if ( count( $matches ) !== 2 ) { - throw new RuntimeException( 'Could not extract the MediaWiki version from DefaultSettings.php' ); + throw new RuntimeException( 'Could not extract the MediaWiki version from Defines.php' ); } return $matches[1]; diff --git a/tests/phpunit/includes/MediaWikiVersionFetcherTest.php b/tests/phpunit/includes/MediaWikiVersionFetcherTest.php index 8f0a44dc05b..2f3320620ae 100644 --- a/tests/phpunit/includes/MediaWikiVersionFetcherTest.php +++ b/tests/phpunit/includes/MediaWikiVersionFetcherTest.php @@ -13,9 +13,8 @@ class MediaWikiVersionFetcherTest extends \MediaWikiIntegrationTestCase { public function testReturnsResult() { - global $wgVersion; $versionFetcher = new MediaWikiVersionFetcher(); - $this->assertSame( $wgVersion, $versionFetcher->fetchVersion() ); + $this->assertSame( MW_VERSION, $versionFetcher->fetchVersion() ); } }