MediaWiki  master
version.php
Go to the documentation of this file.
1 <?php
26 require_once __DIR__ . '/Maintenance.php';
27 
31 class Version extends Maintenance {
32  public function __construct() {
33  parent::__construct();
34  $this->addDescription( 'Prints the current version of MediaWiki' );
35  }
36 
37  public function execute() {
38  if ( !defined( 'MW_VERSION' ) ) {
39  $this->fatalError( "MediaWiki version not defined or unknown" );
40  }
41 
42  global $IP;
43  $contentLang = \MediaWiki\MediaWikiServices::getInstance()->getContentLanguage();
44 
45  $version = MW_VERSION;
46  $strictVersion = substr( $version, 0, 4 );
47  $isLTS = false;
48 
49  // See: https://www.mediawiki.org/wiki/Topic:U4u94htjqupsosea
50  if ( $strictVersion >= '1.19' ) {
51  $x = (float)explode( '.', $strictVersion )[1];
52  $isLTS = ( $x - 19 ) % 4 === 0;
53  }
54 
55  // Get build date and append if available
56  $gitInfo = new GitInfo( $IP );
57  $gitHeadCommitDate = $gitInfo->getHeadCommitDate();
58  $buildDate = $contentLang->timeanddate( $gitHeadCommitDate, true );
59 
60  $text = "MediaWiki version: " . $version;
61  if ( $isLTS ) {
62  $text .= " LTS";
63  }
64  if ( $buildDate ) {
65  $text .= " (built: $buildDate)";
66  }
67 
68  $this->output( $text . "\n" );
69  }
70 }
71 
72 $maintClass = Version::class;
73 require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance\fatalError
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Definition: Maintenance.php:486
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:327
MW_VERSION
const MW_VERSION
The running version of MediaWiki.
Definition: Defines.php:35
Version
Definition: version.php:31
$maintClass
$maintClass
Definition: version.php:72
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:55
Version\__construct
__construct()
Default constructor.
Definition: version.php:32
GitInfo
@newable
Definition: GitInfo.php:34
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:433
Version\execute
execute()
Do the actual work.
Definition: version.php:37
$IP
$IP
Definition: WebStart.php:49