Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 28 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
ApiQueryGlobalRenameStatus | |
0.00% |
0 / 28 |
|
0.00% |
0 / 5 |
72 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
addUser | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 | |||
getAllowedParams | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
getExamplesMessages | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | namespace MediaWiki\Extension\CentralAuth\Api; |
22 | |
23 | use MediaWiki\Api\ApiQuery; |
24 | use MediaWiki\Api\ApiQueryBase; |
25 | use MediaWiki\Api\ApiResult; |
26 | use MediaWiki\Extension\CentralAuth\GlobalRename\GlobalRenameFactory; |
27 | use MediaWiki\Extension\CentralAuth\GlobalRename\GlobalRenameUserStatus; |
28 | use Wikimedia\ParamValidator\ParamValidator; |
29 | |
30 | /** |
31 | * API module equivalent of Special:GlobalRenameStatus |
32 | */ |
33 | class ApiQueryGlobalRenameStatus extends ApiQueryBase { |
34 | |
35 | private GlobalRenameFactory $globalRenameFactory; |
36 | |
37 | public function __construct( |
38 | ApiQuery $queryModule, |
39 | string $moduleName, |
40 | GlobalRenameFactory $globalRenameFactory |
41 | ) { |
42 | parent::__construct( $queryModule, $moduleName, 'grs' ); |
43 | $this->globalRenameFactory = $globalRenameFactory; |
44 | } |
45 | |
46 | /** |
47 | * If a 'user' parameter is provided, get the details for that |
48 | * user, otherwise output details for all current renames |
49 | */ |
50 | public function execute() { |
51 | $params = $this->extractRequestParams(); |
52 | if ( $params['user'] ) { |
53 | $this->addUser( $params['user'] ); |
54 | } else { |
55 | $renames = GlobalRenameUserStatus::getInProgressRenames( $this->getUser() ); |
56 | foreach ( $renames as $user ) { |
57 | $this->addUser( $user ); |
58 | } |
59 | } |
60 | } |
61 | |
62 | /** |
63 | * Look up and add info for a rename |
64 | * |
65 | * @param string $name Username (old or new) |
66 | */ |
67 | private function addUser( $name ) { |
68 | $statuses = $this->globalRenameFactory->newGlobalRenameUserStatus( $name ); |
69 | $names = $statuses->getNames(); |
70 | if ( !$names ) { |
71 | return; |
72 | } |
73 | $info = [ |
74 | 'from' => $names[0], |
75 | 'to' => $names[1], |
76 | 'status' => $statuses->getStatuses(), |
77 | ]; |
78 | ApiResult::setArrayType( $info['status'], 'assoc' ); |
79 | $this->getResult()->addValue( [ 'query', 'globalrenamestatus' ], $name, $info ); |
80 | } |
81 | |
82 | /** |
83 | * @see ApiBase::getAllowedParams() |
84 | * @return array[] |
85 | */ |
86 | public function getAllowedParams() { |
87 | return [ |
88 | 'user' => [ |
89 | ParamValidator::PARAM_TYPE => 'user', |
90 | ] |
91 | ]; |
92 | } |
93 | |
94 | /** @inheritDoc */ |
95 | protected function getExamplesMessages() { |
96 | return [ |
97 | 'action=query&meta=globalrenamestatus' |
98 | => 'apihelp-query+globalrenamestatus-example-1', |
99 | ]; |
100 | } |
101 | } |