Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 24
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
Version
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 3
56
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 canExecuteWithoutLocalSettings
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
30
1<?php
2/**
3 * Prints the version of MediaWiki.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup Maintenance
22 * @author Derick Alangi
23 * @since 1.36
24 */
25
26namespace MediaWiki\Maintenance;
27
28use Maintenance;
29use MediaWiki\Utils\GitInfo;
30
31require_once __DIR__ . '/Maintenance.php';
32
33/**
34 * @ingroup Maintenance
35 */
36class Version extends Maintenance {
37    public function __construct() {
38        parent::__construct();
39        $this->addDescription( 'Prints the current version of MediaWiki' );
40    }
41
42    public function canExecuteWithoutLocalSettings(): bool {
43        return true;
44    }
45
46    public function execute() {
47        if ( !defined( 'MW_VERSION' ) ) {
48            $this->fatalError( "MediaWiki version not defined or unknown" );
49        }
50
51        global $IP;
52        $contentLang = $this->getServiceContainer()->getContentLanguage();
53
54        $version = MW_VERSION;
55        $strictVersion = substr( $version, 0, 4 );
56        $isLTS = false;
57
58        // See: https://www.mediawiki.org/wiki/Topic:U4u94htjqupsosea
59        if ( $strictVersion >= '1.19' ) {
60            $x = (float)explode( '.', $strictVersion )[1];
61            $isLTS = ( $x - 19 ) % 4 === 0;
62        }
63
64        // Get build date and append if available
65        $gitInfo = new GitInfo( $IP );
66        $gitHeadCommitDate = $gitInfo->getHeadCommitDate();
67        $buildDate = $contentLang->timeanddate( (string)$gitHeadCommitDate, true );
68
69        $text = "MediaWiki version: " . $version;
70        if ( $isLTS ) {
71            $text .= " LTS";
72        }
73        if ( $buildDate ) {
74            $text .= " (built: $buildDate)";
75        }
76
77        $this->output( $text . "\n" );
78    }
79}
80
81$maintClass = Version::class;
82require_once RUN_MAINTENANCE_IF_MAIN;