Merge "Update article count when pages are moved"
[lhc/web/wiklou.git] / includes / MediaWikiVersionFetcher.php
1 <?php
2
3 /**
4 * Provides access to MediaWiki's version without requiring MediaWiki (or anything else)
5 * being loaded first.
6 *
7 * @licence GNU GPL v2+
8 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
9 */
10 class MediaWikiVersionFetcher {
11
12 /**
13 * Returns the MediaWiki version, in the format used by MediaWiki's wgVersion global.
14 *
15 * @return string
16 * @throws RuntimeException
17 */
18 public function fetchVersion() {
19 $defaultSettings = file_get_contents( __DIR__ . '/DefaultSettings.php' );
20
21 $matches = array();
22 preg_match( "/wgVersion = '([0-9a-zA-Z\.\-]+)';/", $defaultSettings, $matches );
23
24 if ( count( $matches ) !== 2 ) {
25 throw new RuntimeException( 'Could not extract the MediaWiki version from DefaultSettings.php' );
26 }
27
28 return $matches[1];
29 }
30
31 }