Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 30 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
ApiDeleteGlobalAccount | |
0.00% |
0 / 30 |
|
0.00% |
0 / 6 |
110 | |
0.00% |
0 / 1 |
execute | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
30 | |||
getAllowedParams | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
getExamplesMessages | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
mustBePosted | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isWriteMode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
needsToken | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Created on Oct 21, 2012 |
4 | * |
5 | * CentralAuth extension |
6 | * |
7 | * Copyright (C) 2012 Alex Monk (krenair@gmail.com) |
8 | * |
9 | * This program is free software; you can redistribute it and/or modify |
10 | * it under the terms of the GNU General Public License as published by |
11 | * the Free Software Foundation; either version 2 of the License, or |
12 | * (at your option) any later version. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License along |
20 | * with this program; if not, write to the Free Software Foundation, Inc., |
21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
22 | * http://www.gnu.org/copyleft/gpl.html |
23 | */ |
24 | |
25 | namespace MediaWiki\Extension\CentralAuth\Api; |
26 | |
27 | use ApiBase; |
28 | use MediaWiki\Extension\CentralAuth\User\CentralAuthUser; |
29 | use Wikimedia\ParamValidator\ParamValidator; |
30 | |
31 | /** |
32 | * API module to delete a global account. |
33 | * |
34 | * @ingroup API |
35 | * @ingroup Extensions |
36 | */ |
37 | class ApiDeleteGlobalAccount extends ApiBase { |
38 | public function execute() { |
39 | // Heavily based on code from SpecialCentralAuth::doSubmit |
40 | $this->checkUserRightsAny( 'centralauth-unmerge' ); |
41 | |
42 | $params = $this->extractRequestParams(); |
43 | |
44 | $globalUser = CentralAuthUser::getPrimaryInstanceByName( $params['user'] ); |
45 | if ( !$globalUser->exists() || |
46 | ( $globalUser->isSuppressed() && !$this->getAuthority()->isAllowed( 'centralauth-suppress' ) ) |
47 | ) { |
48 | $this->dieWithError( [ 'nosuchusershort', wfEscapeWikitext( $globalUser->getName() ) ] ); |
49 | |
50 | } |
51 | |
52 | $status = $globalUser->adminDelete( $params['reason'], $this->getUser() ); |
53 | if ( $status->isGood() ) { |
54 | $this->getResult()->addValue( null, $this->getModuleName(), [ |
55 | 'user' => $globalUser->getName(), |
56 | 'reason' => $params['reason'] |
57 | ] ); |
58 | } else { |
59 | $error = $this->getErrorFormatter()->arrayFromStatus( $status ); |
60 | $this->getResult()->addValue( 'error', null, $error ); |
61 | } |
62 | } |
63 | |
64 | /** @inheritDoc */ |
65 | public function getAllowedParams() { |
66 | return [ |
67 | 'user' => [ |
68 | ParamValidator::PARAM_TYPE => 'string', |
69 | ParamValidator::PARAM_REQUIRED => true |
70 | ], |
71 | 'reason' => [ |
72 | ParamValidator::PARAM_TYPE => 'string', |
73 | ], |
74 | ]; |
75 | } |
76 | |
77 | /** @inheritDoc */ |
78 | protected function getExamplesMessages() { |
79 | return [ |
80 | 'action=deleteglobalaccount&user=Example&reason=Because+I+can' |
81 | => 'apihelp-deleteglobalaccount-example-1', |
82 | ]; |
83 | } |
84 | |
85 | /** @inheritDoc */ |
86 | public function mustBePosted() { |
87 | return true; |
88 | } |
89 | |
90 | /** @inheritDoc */ |
91 | public function isWriteMode() { |
92 | return true; |
93 | } |
94 | |
95 | /** @inheritDoc */ |
96 | public function needsToken() { |
97 | return 'deleteglobalaccount'; |
98 | } |
99 | } |