Provide MW_VERSION and soft-deprecate global $wgVersion
authorTimo Tijhof <krinklemail@gmail.com>
Tue, 25 Feb 2020 01:28:12 +0000 (01:28 +0000)
committerTimo Tijhof <krinklemail@gmail.com>
Tue, 25 Feb 2020 02:20:16 +0000 (02:20 +0000)
Backported from a5d5ea82ca.

Bug: T212738
Change-Id: I04628de4152dd5c72646813e08ff35e422e265a4

RELEASE-NOTES-1.34
includes/DefaultSettings.php
includes/Defines.php
includes/MediaWikiVersionFetcher.php
tests/phpunit/includes/MediaWikiVersionFetcherTest.php

index fdd6220..a5e1adf 100644 (file)
@@ -6,6 +6,8 @@ THIS IS NOT A RELEASE YET
 
 === Changes since MediaWiki 1.34.0 ===
 
+* (T212738) Add the MW_VERSION constant, global $wgVersion is soft deprecated.
+
 == MediaWiki 1.34.0 ==
 
 === Changes since MediaWiki 1.34.0-rc.1 ===
index a6dbe4b..98738d7 100644 (file)
@@ -71,8 +71,9 @@ $wgConfigRegistry = [
 /**
  * MediaWiki version number
  * @since 1.2
+ * @deprecated since 1.35; use the MW_VERSION constant instead
  */
-$wgVersion = '1.34.0';
+$wgVersion = MW_VERSION;
 
 /**
  * Name of the site. It must be changed in LocalSettings.php
index 0269ab6..7ea5102 100644 (file)
@@ -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.34.0' );
+
 # Obsolete aliases
 
 /** @{
index 913ae9a..5bfac45 100644 (file)
@@ -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];
index 8f0a44d..2f33206 100644 (file)
@@ -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() );
        }
 
 }