MediaWikiVersionFetcher.php 746 B

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