Deciding on the shape of the contents of this string seems out of scope for this class. It just needs to return what is in the string and make sure to match anything that isn't the string value of the MW_VERSION constant. That means we need to capture from quote to quote. Change-Id: Iee734f8cb425be49601ee4211bb9c01f04164a3f
30 lines
707 B
PHP
30 lines
707 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', '([^']+)'/", $code, $matches );
|
|
|
|
if ( count( $matches ) !== 2 ) {
|
|
throw new RuntimeException( 'Could not extract the MediaWiki version from Defines.php' );
|
|
}
|
|
|
|
return $matches[1];
|
|
}
|
|
|
|
}
|