Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 25 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
ApiVersionInfo | |
0.00% |
0 / 25 |
|
0.00% |
0 / 4 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
20 | |||
getAllowedParams | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
getExamplesMessages | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Copyright (C) 2016, 2021 Kunal Mehta <legoktm@debian.org> |
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 3 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 |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | */ |
18 | namespace MediaWiki\VersionInfo; |
19 | |
20 | use ApiBase; |
21 | use ApiMain; |
22 | |
23 | class ApiVersionInfo extends ApiBase { |
24 | /** @inheritDoc */ |
25 | public function __construct( ApiMain $mainModule ) { |
26 | parent::__construct( $mainModule, 'mwversioninfo' ); |
27 | } |
28 | |
29 | /** @inheritDoc */ |
30 | public function execute() { |
31 | $params = $this->extractRequestParams(); |
32 | try { |
33 | $version = Version::newFromString( $params['version'] ); |
34 | } catch ( \Exception $e ) { |
35 | $this->dieWithError( 'Invalid MediaWiki version provided', 'invalidversion' ); |
36 | } |
37 | |
38 | $lookup = new ReleaseLookup(); |
39 | $info = $lookup->getLatestReleaseFor( $version ); |
40 | $result = $this->getResult(); |
41 | if ( $info ) { |
42 | if ( $info['version']->equals( $version ) ) { |
43 | // Up to date!! |
44 | $result->addValue( 'mwversioninfo', 'status', 'up-to-date' ); |
45 | } else { |
46 | $result->addValue( 'mwversioninfo', 'status', 'outdated' ); |
47 | $result->addValue( 'mwversioninfo', 'latest', $info['version']->getPrettyVersion() ); |
48 | } |
49 | } else { |
50 | // If we have no info about it, you're running an obsolete version |
51 | $latest = $lookup->getLatestRelease(); |
52 | $result->addValue( 'mwversioninfo', 'status', 'obsolete' ); |
53 | $result->addValue( 'mwversioninfo', 'latest', $latest['version']->getPrettyVersion() ); |
54 | } |
55 | } |
56 | |
57 | /** @inheritDoc */ |
58 | public function getAllowedParams() { |
59 | return [ |
60 | 'version' => [ |
61 | ApiBase::PARAM_TYPE => 'string', |
62 | ApiBase::PARAM_REQUIRED => true, |
63 | ], |
64 | ]; |
65 | } |
66 | |
67 | /** @inheritDoc */ |
68 | protected function getExamplesMessages() { |
69 | return [ |
70 | 'action=mwversioninfo&version=1.27' => 'apihelp-mwversioninfo-example', |
71 | ]; |
72 | } |
73 | } |