diff options
author | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
---|---|---|
committer | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
commit | fc7369835258467bf97eb64f184b93691f9a9fd5 (patch) | |
tree | daabd60089d2dd76d9f5fb416b005fbe159c799d /www/wiki/includes/MediaWikiVersionFetcher.php |
first commit
Diffstat (limited to 'www/wiki/includes/MediaWikiVersionFetcher.php')
-rw-r--r-- | www/wiki/includes/MediaWikiVersionFetcher.php | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/www/wiki/includes/MediaWikiVersionFetcher.php b/www/wiki/includes/MediaWikiVersionFetcher.php new file mode 100644 index 00000000..913ae9a5 --- /dev/null +++ b/www/wiki/includes/MediaWikiVersionFetcher.php @@ -0,0 +1,30 @@ +<?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 { + + /** + * Returns the MediaWiki version, in the format used by MediaWiki's wgVersion global. + * + * @return string + * @throws RuntimeException + */ + public function fetchVersion() { + $defaultSettings = file_get_contents( __DIR__ . '/DefaultSettings.php' ); + + $matches = []; + preg_match( "/wgVersion = '([0-9a-zA-Z\.\-]+)';/", $defaultSettings, $matches ); + + if ( count( $matches ) !== 2 ) { + throw new RuntimeException( 'Could not extract the MediaWiki version from DefaultSettings.php' ); + } + + return $matches[1]; + } + +} |