diff options
26 files changed, 51 insertions, 69 deletions
diff --git a/docs/hooks.txt b/docs/hooks.txt index df89bac3c166..d75a265c6035 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -3360,7 +3360,7 @@ Special:Upload. &$form: The SpecialUpload object 'SpecialVersionVersionUrl': Called when building the URL for Special:Version. -$wgVersion: Current $wgVersion for you to use +$version: Current MediaWiki version &$versionUrl: Raw url to link to (eg: release notes) 'SpecialWatchlistGetNonRevisionTypes': Called when building sql query for diff --git a/includes/NoLocalSettings.php b/includes/NoLocalSettings.php index f6f4cd3a3ef7..88dc01aa49fd 100644 --- a/includes/NoLocalSettings.php +++ b/includes/NoLocalSettings.php @@ -48,11 +48,10 @@ $templateParser = new TemplateParser(); # Render error page if no LocalSettings file can be found try { - global $wgVersion; echo $templateParser->processTemplate( 'NoLocalSettings', [ - 'wgVersion' => ( $wgVersion ?? 'VERSION' ), + 'version' => ( defined( MW_VERSION ) ? MW_VERSION : 'VERSION' ), 'path' => $path, 'localSettingsExists' => file_exists( MW_CONFIG_FILE ), 'installerStarted' => $installerStarted diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 5edaadf276dd..bfd41de6a204 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -3412,8 +3412,6 @@ class OutputPage extends ContextSource { * @return array Array in format "link name or number => 'link html'". */ public function getHeadLinksArray() { - global $wgVersion; - $tags = []; $config = $this->getConfig(); @@ -3421,7 +3419,7 @@ class OutputPage extends ContextSource { $tags['meta-generator'] = Html::element( 'meta', [ 'name' => 'generator', - 'content' => "MediaWiki $wgVersion", + 'content' => 'MediaWiki ' . MW_VERSION, ] ); if ( $config->get( 'ReferrerPolicy' ) !== false ) { diff --git a/includes/Pingback.php b/includes/Pingback.php index 7df719431a0b..c63522a6acb5 100644 --- a/includes/Pingback.php +++ b/includes/Pingback.php @@ -57,7 +57,7 @@ class Pingback { public function __construct( Config $config = null, LoggerInterface $logger = null ) { $this->config = $config ?: RequestContext::getMain()->getConfig(); $this->logger = $logger ?: LoggerFactory::getInstance( __CLASS__ ); - $this->key = 'Pingback-' . $this->config->get( 'Version' ); + $this->key = 'Pingback-' . MW_VERSION; } /** @@ -144,7 +144,7 @@ class Pingback { public function getSystemInfo() { $event = [ 'database' => $this->config->get( 'DBtype' ), - 'MediaWiki' => $this->config->get( 'Version' ), + 'MediaWiki' => MW_VERSION, 'PHP' => PHP_VERSION, 'OS' => PHP_OS . ' ' . php_uname( 'r' ), 'arch' => PHP_INT_SIZE === 8 ? 64 : 32, diff --git a/includes/api/ApiQuerySiteinfo.php b/includes/api/ApiQuerySiteinfo.php index 4bfd899909d0..761e14c77dea 100644 --- a/includes/api/ApiQuerySiteinfo.php +++ b/includes/api/ApiQuerySiteinfo.php @@ -139,7 +139,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { $logo = ResourceLoaderSkinModule::getAvailableLogos( $config ); $data['logo'] = wfExpandUrl( $logo['1x'], PROTO_RELATIVE ); - $data['generator'] = "MediaWiki {$config->get( 'Version' )}"; + $data['generator'] = 'MediaWiki ' . MW_VERSION; $data['phpversion'] = PHP_VERSION; $data['phpsapi'] = PHP_SAPI; diff --git a/includes/changes/AtomFeed.php b/includes/changes/AtomFeed.php index a4ce0c127816..1115fdd1256b 100644 --- a/includes/changes/AtomFeed.php +++ b/includes/changes/AtomFeed.php @@ -44,7 +44,6 @@ class AtomFeed extends ChannelFeed { * Outputs a basic header for Atom 1.0 feeds. */ function outHeader() { - global $wgVersion; $this->outXmlHeader(); // Manually escaping rather than letting Mustache do it because Mustache // uses htmlentities, which does not work with XML @@ -56,7 +55,7 @@ class AtomFeed extends ChannelFeed { 'selfUrl' => $this->getSelfUrl(), 'timestamp' => $this->xmlEncode( $this->formatTime( wfTimestampNow() ) ), 'description' => $this->getDescription(), - 'version' => $this->xmlEncode( $wgVersion ), + 'version' => $this->xmlEncode( MW_VERSION ), ]; print $this->templateParser->processTemplate( 'AtomHeader', $templateParams ); } diff --git a/includes/debug/MWDebug.php b/includes/debug/MWDebug.php index c625b4ed3b28..d4714a8a3bff 100644 --- a/includes/debug/MWDebug.php +++ b/includes/debug/MWDebug.php @@ -540,7 +540,6 @@ class MWDebug { return []; } - global $wgVersion; $request = $context->getRequest(); $branch = GitInfo::currentBranch(); @@ -551,7 +550,7 @@ class MWDebug { } return [ - 'mwVersion' => $wgVersion, + 'mwVersion' => MW_VERSION, 'phpEngine' => 'PHP', 'phpVersion' => PHP_VERSION, 'gitRevision' => GitInfo::headSHA1(), diff --git a/includes/debug/logger/monolog/WikiProcessor.php b/includes/debug/logger/monolog/WikiProcessor.php index dc3c1f249fcd..71fe325e4369 100644 --- a/includes/debug/logger/monolog/WikiProcessor.php +++ b/includes/debug/logger/monolog/WikiProcessor.php @@ -36,10 +36,9 @@ class WikiProcessor { * @return array */ public function __invoke( array $record ) { - global $wgVersion; $record['extra']['host'] = wfHostname(); $record['extra']['wiki'] = WikiMap::getWikiIdFromDbDomain( WikiMap::getCurrentWikiDbDomain() ); - $record['extra']['mwversion'] = $wgVersion; + $record['extra']['mwversion'] = MW_VERSION; $record['extra']['reqId'] = \WebRequest::getRequestId(); if ( wfIsCLI() && isset( $_SERVER['argv'] ) ) { $record['extra']['cli_argv'] = implode( ' ', $_SERVER['argv'] ); diff --git a/includes/export/XmlDumpWriter.php b/includes/export/XmlDumpWriter.php index 3e5d28ebaec0..c634cedbb18b 100644 --- a/includes/export/XmlDumpWriter.php +++ b/includes/export/XmlDumpWriter.php @@ -175,8 +175,7 @@ class XmlDumpWriter { * @return string */ function generator() { - global $wgVersion; - return Xml::element( 'generator', [], "MediaWiki $wgVersion" ); + return Xml::element( 'generator', [], 'MediaWiki ' . MW_VERSION ); } /** diff --git a/includes/http/HttpRequestFactory.php b/includes/http/HttpRequestFactory.php index 98c9d913a0d1..c1334d87f8be 100644 --- a/includes/http/HttpRequestFactory.php +++ b/includes/http/HttpRequestFactory.php @@ -52,7 +52,7 @@ class HttpRequestFactory { * Note: this should only be used when the target URL is trusted, * to avoid attacks on intranet services accessible by HTTP. * - userAgent A user agent, if you want to override the default - * MediaWiki/$wgVersion + * "MediaWiki/{MW_VERSION}". * - logger A \Psr\Logger\LoggerInterface instance for debug logging * - username Username for HTTP Basic Authentication * - password Password for HTTP Basic Authentication @@ -163,8 +163,6 @@ class HttpRequestFactory { * @return string */ public function getUserAgent() { - global $wgVersion; - - return "MediaWiki/$wgVersion"; + return 'MediaWiki/' . MW_VERSION; } } diff --git a/includes/installer/LocalSettingsGenerator.php b/includes/installer/LocalSettingsGenerator.php index de3118dcff9e..2de47bb041ea 100644 --- a/includes/installer/LocalSettingsGenerator.php +++ b/includes/installer/LocalSettingsGenerator.php @@ -307,8 +307,9 @@ class LocalSettingsGenerator { $platformSettings = ''; } + $version = MW_VERSION; return "<?php -# This file was automatically generated by the MediaWiki {$GLOBALS['wgVersion']} +# This file was automatically generated by the MediaWiki {$version} # installer. If you make manual changes, please keep track in case you # need to recreate them later. # diff --git a/includes/installer/WebInstaller.php b/includes/installer/WebInstaller.php index de1053d0973a..7a5c5bdc3efd 100644 --- a/includes/installer/WebInstaller.php +++ b/includes/installer/WebInstaller.php @@ -372,7 +372,7 @@ class WebInstaller extends Installer { return md5( serialize( [ 'local path' => dirname( __DIR__ ), 'url' => $url, - 'version' => $GLOBALS['wgVersion'] + 'version' => MW_VERSION ] ) ); } diff --git a/includes/installer/WebInstallerOutput.php b/includes/installer/WebInstallerOutput.php index 983f15b66aa8..4a482a714cca 100644 --- a/includes/installer/WebInstallerOutput.php +++ b/includes/installer/WebInstallerOutput.php @@ -346,8 +346,7 @@ class WebInstallerOutput { } public function outputTitle() { - global $wgVersion; - echo wfMessage( 'config-title', $wgVersion )->escaped(); + echo wfMessage( 'config-title', MW_VERSION )->escaped(); } /** diff --git a/includes/installer/WebInstallerReleaseNotes.php b/includes/installer/WebInstallerReleaseNotes.php index 99520ce16c61..5eb59586c593 100644 --- a/includes/installer/WebInstallerReleaseNotes.php +++ b/includes/installer/WebInstallerReleaseNotes.php @@ -26,10 +26,8 @@ class WebInstallerReleaseNotes extends WebInstallerDocument { * @return string */ protected function getFileName() { - global $wgVersion; - - if ( !preg_match( '/^(\d+)\.(\d+).*/i', $wgVersion, $result ) ) { - throw new MWException( 'Variable $wgVersion has an invalid value.' ); + if ( !preg_match( '/^(\d+)\.(\d+).*/i', MW_VERSION, $result ) ) { + throw new MWException( 'Constant MW_VERSION has an invalid value.' ); } return 'RELEASE-NOTES-' . $result[1] . '.' . $result[2]; diff --git a/includes/installer/WebInstallerUpgrade.php b/includes/installer/WebInstallerUpgrade.php index ab2e6c4de78f..359606d1b3d5 100644 --- a/includes/installer/WebInstallerUpgrade.php +++ b/includes/installer/WebInstallerUpgrade.php @@ -83,7 +83,7 @@ class WebInstallerUpgrade extends WebInstallerPage { $this->startForm(); $this->addHTML( $this->parent->getInfoBox( - wfMessage( 'config-can-upgrade', $GLOBALS['wgVersion'] )->plain() ) ); + wfMessage( 'config-can-upgrade', MW_VERSION )->plain() ) ); $this->endForm(); return null; diff --git a/includes/registration/ExtensionRegistry.php b/includes/registration/ExtensionRegistry.php index 88140110ffb1..0051097f57f3 100644 --- a/includes/registration/ExtensionRegistry.php +++ b/includes/registration/ExtensionRegistry.php @@ -18,7 +18,7 @@ use Wikimedia\ScopedCallback; class ExtensionRegistry { /** - * "requires" key that applies to MediaWiki core/$wgVersion + * "requires" key that applies to MediaWiki core */ public const MEDIAWIKI_CORE = 'MediaWiki'; @@ -191,11 +191,10 @@ class ExtensionRegistry { } private function makeCacheKey( BagOStuff $cache, $component, ...$extra ) { - global $wgVersion; // Everything we vary the cache on $vary = [ 'registration' => self::CACHE_VERSION, - 'mediawiki' => $wgVersion, + 'mediawiki' => MW_VERSION, 'abilities' => $this->getAbilities(), 'checkDev' => $this->checkDev, 'queue' => $this->queued, @@ -310,7 +309,6 @@ class ExtensionRegistry { * @return VersionChecker */ private function buildVersionChecker() { - global $wgVersion; // array to optionally specify more verbose error messages for // missing abilities $abilityErrors = [ @@ -318,7 +316,7 @@ class ExtensionRegistry { ]; return new VersionChecker( - $wgVersion, + MW_VERSION, PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION, get_loaded_extensions(), $this->getAbilities(), diff --git a/includes/registration/VersionChecker.php b/includes/registration/VersionChecker.php index 41e37e1e8007..d92aee532528 100644 --- a/includes/registration/VersionChecker.php +++ b/includes/registration/VersionChecker.php @@ -31,12 +31,12 @@ use Composer\Semver\VersionParser; */ class VersionChecker { /** - * @var Constraint|bool representing $wgVersion + * @var Constraint|bool representing MediaWiki core */ private $coreVersion = false; /** - * @var Constraint|bool representing PHP version + * @var Constraint|bool representing the PHP engine */ private $phpVersion = false; diff --git a/includes/resourceloader/ResourceLoader.php b/includes/resourceloader/ResourceLoader.php index 94e7f2712e8f..a7c807338f71 100644 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@ -1948,7 +1948,7 @@ MESSAGE; 'wgServerName' => $conf->get( 'ServerName' ), 'wgUserLanguage' => $context->getLanguage(), 'wgContentLanguage' => $contLang->getCode(), - 'wgVersion' => $conf->get( 'Version' ), + 'wgVersion' => MW_VERSION, 'wgEnableAPI' => true, // Deprecated since MW 1.32 'wgEnableWriteAPI' => true, // Deprecated since MW 1.32 'wgFormattedNamespaces' => $contLang->getFormattedNamespaces(), diff --git a/includes/specials/SpecialVersion.php b/includes/specials/SpecialVersion.php index 32f2b38842cc..567930720612 100644 --- a/includes/specials/SpecialVersion.php +++ b/includes/specials/SpecialVersion.php @@ -287,14 +287,14 @@ class SpecialVersion extends SpecialPage { * @return mixed */ public static function getVersion( $flags = '', $lang = null ) { - global $wgVersion, $IP; + global $IP; $gitInfo = self::getGitHeadSha1( $IP ); if ( !$gitInfo ) { - $version = $wgVersion; + $version = MW_VERSION; } elseif ( $flags === 'nodb' ) { $shortSha1 = substr( $gitInfo, 0, 7 ); - $version = "$wgVersion ($shortSha1)"; + $version = MW_VERSION . " ($shortSha1)"; } else { $shortSha1 = substr( $gitInfo, 0, 7 ); $msg = wfMessage( 'parentheses' ); @@ -302,7 +302,7 @@ class SpecialVersion extends SpecialPage { $msg->inLanguage( $lang ); } $shortSha1 = $msg->params( $shortSha1 )->escaped(); - $version = "$wgVersion $shortSha1"; + $version = MW_VERSION . ' ' . $shortSha1; } return $version; @@ -311,18 +311,16 @@ class SpecialVersion extends SpecialPage { /** * Return a wikitext-formatted string of the MediaWiki version with a link to * the Git SHA1 of head if available. - * The fallback is just $wgVersion + * The fallback is just MW_VERSION. * * @return mixed */ public static function getVersionLinked() { - global $wgVersion; - $gitVersion = self::getVersionLinkedGit(); if ( $gitVersion ) { $v = $gitVersion; } else { - $v = $wgVersion; // fallback + $v = MW_VERSION; // fallback } return $v; @@ -331,21 +329,20 @@ class SpecialVersion extends SpecialPage { /** * @return string */ - private static function getwgVersionLinked() { - global $wgVersion; + private static function getMWVersionLinked() { $versionUrl = ""; - if ( Hooks::run( 'SpecialVersionVersionUrl', [ $wgVersion, &$versionUrl ] ) ) { + if ( Hooks::run( 'SpecialVersionVersionUrl', [ MW_VERSION, &$versionUrl ] ) ) { $versionParts = []; - preg_match( "/^(\d+\.\d+)/", $wgVersion, $versionParts ); + preg_match( "/^(\d+\.\d+)/", MW_VERSION, $versionParts ); $versionUrl = "https://www.mediawiki.org/wiki/MediaWiki_{$versionParts[1]}"; } - return "[$versionUrl $wgVersion]"; + return '[' . $versionUrl . ' ' . MW_VERSION . ']'; } /** - * @since 1.22 Returns the HEAD date in addition to the sha1 and link - * @return bool|string Global wgVersion + HEAD sha1 stripped to the first 7 chars + * @since 1.22 Includes the date of the Git HEAD commit + * @return bool|string MW version and Git HEAD (SHA1 stripped to the first 7 chars) * with link and date, or false on failure */ private static function getVersionLinkedGit() { @@ -369,7 +366,7 @@ class SpecialVersion extends SpecialPage { $shortSHA1 .= Html::element( 'br' ) . $wgLang->timeanddate( $gitHeadCommitDate, true ); } - return self::getwgVersionLinked() . " $shortSHA1"; + return self::getMWVersionLinked() . " $shortSHA1"; } /** diff --git a/includes/templates/NoLocalSettings.mustache b/includes/templates/NoLocalSettings.mustache index 118f439e4244..7f14f9af36bf 100644 --- a/includes/templates/NoLocalSettings.mustache +++ b/includes/templates/NoLocalSettings.mustache @@ -2,7 +2,7 @@ <html lang="en" dir="ltr"> <head> <meta charset="UTF-8" /> - <title>MediaWiki {{wgVersion}}</title> + <title>MediaWiki {{version}}</title> <style media="screen"> body { color: #000; @@ -19,7 +19,7 @@ <body> <img src="{{path}}resources/assets/mediawiki.png" alt="The MediaWiki logo" /> - <h1>MediaWiki {{wgVersion}}</h1> + <h1>MediaWiki {{version}}</h1> <div class="error"> {{#localSettingsExists}} <p>LocalSettings.php not readable.</p> diff --git a/maintenance/language/dumpMessages.php b/maintenance/language/dumpMessages.php index 84208ce774eb..a29a96b9c55d 100644 --- a/maintenance/language/dumpMessages.php +++ b/maintenance/language/dumpMessages.php @@ -39,8 +39,6 @@ class DumpMessages extends Maintenance { } public function execute() { - global $wgVersion; - $messages = []; foreach ( array_keys( MediaWikiServices::getInstance() ->getLocalisationCache() @@ -48,7 +46,7 @@ class DumpMessages extends Maintenance { ) { $messages[$key] = wfMessage( $key )->text(); } - $this->output( "MediaWiki $wgVersion language file\n" ); + $this->output( "MediaWiki " . MW_VERSION . " language file\n" ); $this->output( serialize( $messages ) ); } } diff --git a/maintenance/update.php b/maintenance/update.php index aa8d295b2eb6..270b4a4ee031 100755 --- a/maintenance/update.php +++ b/maintenance/update.php @@ -77,7 +77,7 @@ class UpdateMediaWiki extends Maintenance { } public function execute() { - global $wgVersion, $wgLang, $wgAllowSchemaUpdates, $wgMessagesDirs; + global $wgLang, $wgAllowSchemaUpdates, $wgMessagesDirs; if ( !$wgAllowSchemaUpdates && !( $this->hasOption( 'force' ) @@ -113,7 +113,7 @@ class UpdateMediaWiki extends Maintenance { define( 'MW_UPDATER', true ); - $this->output( "MediaWiki {$wgVersion} Updater\n\n" ); + $this->output( 'MediaWiki ' . MW_VERSION . " Updater\n\n" ); wfWaitForSlaves(); diff --git a/tests/phpunit/documentation/ReleaseNotesTest.php b/tests/phpunit/documentation/ReleaseNotesTest.php index acbb04a6e0e3..6976e604a606 100644 --- a/tests/phpunit/documentation/ReleaseNotesTest.php +++ b/tests/phpunit/documentation/ReleaseNotesTest.php @@ -12,7 +12,7 @@ class ReleaseNotesTest extends MediaWikiTestCase { * @coversNothing */ public function testReleaseNotesFilesExistAndAreNotMalformed() { - global $wgVersion, $IP; + global $IP; $notesFiles = glob( "$IP/RELEASE-NOTES-*" ); @@ -22,11 +22,11 @@ class ReleaseNotesTest extends MediaWikiTestCase { 'Repo has at least one Release Notes file.' ); - $versionParts = explode( '.', explode( '-', $wgVersion )[0] ); + $versionParts = explode( '.', explode( '-', MW_VERSION )[0] ); $this->assertContains( "$IP/RELEASE-NOTES-$versionParts[0].$versionParts[1]", $notesFiles, - 'Repo has a Release Notes file for the current $wgVersion.' + 'Repo has a Release Notes file for the current MW_VERSION.' ); foreach ( $notesFiles as $index => $fileName ) { diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php index fbdf5fa4767f..bb434e23d88f 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php @@ -625,7 +625,7 @@ class ResourceLoaderFileModuleTest extends ResourceLoaderTestCase { ], [ 'name' => 'config.json', 'config' => [ 'Sitename', - 'wgVersion' => 'Version', + 'server' => 'ServerName', ] ], ] ], @@ -651,7 +651,7 @@ class ResourceLoaderFileModuleTest extends ResourceLoaderTestCase { 'type' => 'data', 'content' => [ 'Sitename' => $config->get( 'Sitename' ), - 'wgVersion' => $config->get( 'Version' ), + 'server' => $config->get( 'ServerName' ), ] ] ], diff --git a/tests/phpunit/integration/includes/db/DatabaseSqliteTest.php b/tests/phpunit/integration/includes/db/DatabaseSqliteTest.php index c11718f67497..65a11cfee28b 100644 --- a/tests/phpunit/integration/includes/db/DatabaseSqliteTest.php +++ b/tests/phpunit/integration/includes/db/DatabaseSqliteTest.php @@ -335,7 +335,7 @@ class DatabaseSqliteTest extends \MediaWikiIntegrationTestCase { * @coversNothing */ public function testUpgrades() { - global $IP, $wgVersion; + global $IP; // Versions tested $versions = [ @@ -364,7 +364,7 @@ class DatabaseSqliteTest extends \MediaWikiIntegrationTestCase { sort( $currentTables ); foreach ( $versions as $version ) { - $versions = "upgrading from $version to $wgVersion"; + $versions = "upgrading from $version to " . MW_VERSION; $db = $this->prepareTestDB( $version ); $tables = $this->getTables( $db ); $this->assertEquals( $currentTables, $tables, "Different tables $versions" ); diff --git a/tests/phpunit/unit/includes/registration/VersionCheckerTest.php b/tests/phpunit/unit/includes/registration/VersionCheckerTest.php index f47517a1d4b0..dd4fc3b4ec94 100644 --- a/tests/phpunit/unit/includes/registration/VersionCheckerTest.php +++ b/tests/phpunit/unit/includes/registration/VersionCheckerTest.php @@ -16,7 +16,7 @@ class VersionCheckerTest extends MediaWikiUnitTestCase { public static function provideMediaWikiCheck() { return [ - // [ $wgVersion, constraint, expected ] + // [ MediaWiki version, constraint, expected ] [ '1.25alpha', '>= 1.26', false ], [ '1.25.0', '>= 1.26', false ], [ '1.26alpha', '>= 1.26', true ], |