Merge "Update docs/hooks.txt for ShowSearchHitTitle"
[mediawiki.git] / includes / MediaWikiVersionFetcher.php
blob913ae9a50d64e8672c3d1b0a3a67c05236dcf1d2
1 <?php
3 /**
4 * Provides access to MediaWiki's version without requiring MediaWiki (or anything else)
5 * being loaded first.
7 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
8 */
9 class MediaWikiVersionFetcher {
11 /**
12 * Returns the MediaWiki version, in the format used by MediaWiki's wgVersion global.
14 * @return string
15 * @throws RuntimeException
17 public function fetchVersion() {
18 $defaultSettings = file_get_contents( __DIR__ . '/DefaultSettings.php' );
20 $matches = [];
21 preg_match( "/wgVersion = '([0-9a-zA-Z\.\-]+)';/", $defaultSettings, $matches );
23 if ( count( $matches ) !== 2 ) {
24 throw new RuntimeException( 'Could not extract the MediaWiki version from DefaultSettings.php' );
27 return $matches[1];