Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 50 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
ApiStabilizeProtect | |
0.00% |
0 / 50 |
|
0.00% |
0 / 5 |
56 | |
0.00% |
0 / 1 |
doExecute | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
12 | |||
getAllowedParams | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
2 | |||
getSummaryMessage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getExtendedDescription | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getExamplesMessages | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Created on Sep 19, 2009 |
4 | * |
5 | * API module for MediaWiki's FlaggedRevs extension |
6 | * |
7 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. |
11 | * |
12 | * This program is distributed in the hope that it will be useful, |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * GNU General Public License for more details. |
16 | * |
17 | * You should have received a copy of the GNU General Public License along |
18 | * with this program; if not, write to the Free Software Foundation, Inc., |
19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
20 | * http://www.gnu.org/copyleft/gpl.html |
21 | */ |
22 | |
23 | use MediaWiki\MediaWikiServices; |
24 | use Wikimedia\ParamValidator\ParamValidator; |
25 | |
26 | /** |
27 | * API module to stabilize pages |
28 | * Assumes $wgFlaggedRevsProtection is on |
29 | * |
30 | * @ingroup FlaggedRevs |
31 | */ |
32 | class ApiStabilizeProtect extends ApiStabilize { |
33 | public function doExecute() { |
34 | $params = $this->extractRequestParams(); |
35 | $user = $this->getUser(); |
36 | |
37 | $form = new PageStabilityProtectForm( $user ); |
38 | $form->setTitle( $this->title ); # Our target page |
39 | $form->setReasonExtra( $params['reason'] ); # Reason |
40 | $form->setReasonSelection( 'other' ); # Reason dropdown |
41 | $form->setExpiryCustom( $params['expiry'] ); # Expiry |
42 | $form->setExpirySelection( 'other' ); # Expiry dropdown |
43 | |
44 | $restriction = $params['protectlevel']; |
45 | if ( $restriction == 'none' ) { |
46 | $restriction = ''; // 'none' => '' |
47 | } |
48 | |
49 | $form->setAutoreview( $restriction ); # Autoreview restriction |
50 | $form->ready(); |
51 | |
52 | $status = $form->submit(); // true/error message key |
53 | if ( $status !== true ) { |
54 | $this->dieWithError( $status ); |
55 | } |
56 | |
57 | # Output success line with the title and config parameters |
58 | $res = []; |
59 | $res['title'] = $this->title->getPrefixedText(); |
60 | $res['protectlevel'] = $params['protectlevel']; |
61 | $res['expiry'] = MediaWikiServices::getInstance()->getContentLanguage() |
62 | ->formatExpiry( $form->getExpiry(), TS_ISO_8601 ); |
63 | $this->getResult()->addValue( null, $this->getModuleName(), $res ); |
64 | } |
65 | |
66 | /** |
67 | * @inheritDoc |
68 | */ |
69 | protected function getAllowedParams() { |
70 | // Replace '' with more readable 'none' in autoreview restiction levels |
71 | $autoreviewLevels = [ ...FlaggedRevs::getRestrictionLevels(), 'none' ]; |
72 | $params = [ |
73 | 'protectlevel' => [ |
74 | ParamValidator::PARAM_TYPE => $autoreviewLevels, |
75 | ParamValidator::PARAM_DEFAULT => 'none', |
76 | ], |
77 | 'expiry' => [ |
78 | ParamValidator::PARAM_DEFAULT => 'infinite', |
79 | ApiBase::PARAM_HELP_MSG => 'apihelp-stabilize-param-expiry-protect', |
80 | ], |
81 | 'reason' => '', |
82 | ]; |
83 | |
84 | $params += [ |
85 | 'title' => [ |
86 | ParamValidator::PARAM_REQUIRED => true, |
87 | ApiBase::PARAM_HELP_MSG => 'apihelp-stabilize-param-title-protect', |
88 | ], |
89 | ]; |
90 | |
91 | return $params; |
92 | } |
93 | |
94 | /** |
95 | * @return string |
96 | */ |
97 | protected function getSummaryMessage() { |
98 | return "apihelp-{$this->getModulePath()}-summary-protect"; |
99 | } |
100 | |
101 | /** |
102 | * @inheritDoc |
103 | */ |
104 | protected function getExtendedDescription() { |
105 | return [ [ |
106 | "apihelp-{$this->getModulePath()}-extended-description-protect", |
107 | 'api-help-no-extended-description', |
108 | ] ]; |
109 | } |
110 | |
111 | /** |
112 | * @inheritDoc |
113 | */ |
114 | protected function getExamplesMessages() { |
115 | return [ |
116 | 'action=stabilize&title=Test&protectlevel=none&reason=Test&token=123ABC' |
117 | => 'apihelp-stabilize-example-protect', |
118 | ]; |
119 | } |
120 | } |