From: Timo Tijhof Date: Tue, 25 Feb 2020 01:28:12 +0000 (+0000) Subject: Provide MW_VERSION and soft-deprecate global $wgVersion X-Git-Tag: 1.31.7~12 X-Git-Url: http://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=0841683695523a707a6e91a932209df8dbcd0248 Provide MW_VERSION and soft-deprecate global $wgVersion Backported from a5d5ea82ca. Bug: T212738 Change-Id: I04628de4152dd5c72646813e08ff35e422e265a4 --- diff --git a/RELEASE-NOTES-1.31 b/RELEASE-NOTES-1.31 index ebdf5a764c..94ff63316c 100644 --- a/RELEASE-NOTES-1.31 +++ b/RELEASE-NOTES-1.31 @@ -4,6 +4,8 @@ THIS IS NOT A RELEASE YET === Changes since MediaWiki 1.31.6 === +* (T212738) Add the MW_VERSION constant, global $wgVersion is soft deprecated. + == MediaWiki 1.31.6 == This is a security and maintenance release of the MediaWiki 1.31 branch. diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 29e3366c87..eebd616a4b 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -70,8 +70,9 @@ $wgConfigRegistry = [ /** * MediaWiki version number * @since 1.2 + * @deprecated since 1.35; use the MW_VERSION constant instead */ -$wgVersion = '1.31.6'; +$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 087af39db4..b4140c3024 100644 --- a/includes/Defines.php +++ b/includes/Defines.php @@ -30,6 +30,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.31.6' ); + # Obsolete aliases /** * @deprecated since 1.28 diff --git a/includes/MediaWikiVersionFetcher.php b/includes/MediaWikiVersionFetcher.php index 913ae9a50d..5bfac45c7d 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 87a7dffde1..839f6aca01 100644 --- a/tests/phpunit/includes/MediaWikiVersionFetcherTest.php +++ b/tests/phpunit/includes/MediaWikiVersionFetcherTest.php @@ -16,7 +16,7 @@ class MediaWikiVersionFetcherTest extends PHPUnit\Framework\TestCase { public function testReturnsResult() { $versionFetcher = new MediaWikiVersionFetcher(); - $this->assertInternalType( 'string', $versionFetcher->fetchVersion() ); + $this->assertSame( MW_VERSION, $versionFetcher->fetchVersion() ); } }