wiki.techinc.nl/includes/MediaWikiVersionFetcher.php
Timo Tijhof a5d5ea82ca 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
2020-02-25 01:55:21 +00:00

30 lines
718 B
PHP

<?php
/**
* Provides access to MediaWiki's version without requiring MediaWiki (or anything else)
* being loaded first.
*
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
class MediaWikiVersionFetcher {
/**
* Get the MediaWiki version, extracted from the PHP source file where it is defined.
*
* @return string
* @throws RuntimeException
*/
public function fetchVersion() {
$code = file_get_contents( __DIR__ . '/Defines.php' );
$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 Defines.php' );
}
return $matches[1];
}
}