Debian Codegraph @

maintenance/Version.php

raw symbols SCIP
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
26 namespace MediaWiki\Maintenance;
27
28 use MediaWiki\Utils\GitInfo;
29
30 // @codeCoverageIgnoreStart
31 require_once __DIR__ . '/Maintenance.php';
32 // @codeCoverageIgnoreEnd
33
34 /**
35 * @ingroup Maintenance
36 */
37 class Version extends Maintenance {
38 public function __construct() {
39 parent::__construct();
40 $this->addDescription( 'Prints the current version of MediaWiki' );
41 }
42
43 public function canExecuteWithoutLocalSettings(): bool {
44 return true;
45 }
46
47 public function execute() {
48 if ( !defined( 'MW_VERSION' ) ) {
49 $this->fatalError( "MediaWiki version not defined or unknown" );
50 }
51
52 global $IP;
53 $contentLang = $this->getServiceContainer()->getContentLanguage();
54
55 $version = MW_VERSION;
56 $strictVersion = substr( $version, 0, 4 );
57 $isLTS = false;
58
59 // See: https://www.mediawiki.org/wiki/Topic:U4u94htjqupsosea
60 if ( $strictVersion >= '1.19' ) {
61 $x = (float)explode( '.', $strictVersion )[1];
62 $isLTS = ( $x - 19 ) % 4 === 0;
63 }
64
65 // Get build date and append if available
66 $gitInfo = new GitInfo( $IP );
67 $gitHeadCommitDate = $gitInfo->getHeadCommitDate();
68 $buildDate = $contentLang->timeanddate( (string)$gitHeadCommitDate, true );
69
70 $text = "MediaWiki version: " . $version;
71 if ( $isLTS ) {
72 $text .= " LTS";
73 }
74 if ( $buildDate ) {
75 $text .= " (built: $buildDate)";
76 }
77
78 $this->output( $text . "\n" );
79 }
80 }
81
82 // @codeCoverageIgnoreStart
83 $maintClass = Version::class;
84 require_once RUN_MAINTENANCE_IF_MAIN;
85 // @codeCoverageIgnoreEnd