Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 63 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
ApiStabilizeGeneral | |
0.00% |
0 / 63 |
|
0.00% |
0 / 6 |
110 | |
0.00% |
0 / 1 |
doExecute | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
12 | |||
defaultFromKey | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
getAllowedParams | |
0.00% |
0 / 24 |
|
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\Api\ApiBase; |
24 | use MediaWiki\MediaWikiServices; |
25 | use Wikimedia\ParamValidator\ParamValidator; |
26 | |
27 | /** |
28 | * API module to stabilize pages |
29 | * Assumes $wgFlaggedRevsProtection is off |
30 | * |
31 | * @ingroup FlaggedRevs |
32 | */ |
33 | class ApiStabilizeGeneral extends ApiStabilize { |
34 | public function doExecute() { |
35 | $params = $this->extractRequestParams(); |
36 | $user = $this->getUser(); |
37 | |
38 | $form = new PageStabilityGeneralForm( $user ); |
39 | $form->setTitle( $this->title ); # Our target page |
40 | $form->setReasonExtra( $params['reason'] ); # Reason |
41 | $form->setReasonSelection( 'other' ); # Reason dropdown |
42 | $form->setExpiryCustom( $params['expiry'] ); # Expiry |
43 | $form->setExpirySelection( 'other' ); # Expiry dropdown |
44 | $restriction = $params['autoreview']; |
45 | |
46 | // Fill in config fields from URL params |
47 | $form->setOverride( $this->defaultFromKey( $params['default'] ) ); |
48 | |
49 | $form->setReviewThis( $params['review'] ); # Auto-review option |
50 | |
51 | if ( $restriction == 'none' ) { |
52 | $restriction = ''; // 'none' => '' |
53 | } |
54 | |
55 | $form->setAutoreview( $restriction ); # Autoreview restriction |
56 | $form->ready(); |
57 | |
58 | $status = $form->submit(); // true/error message key |
59 | if ( $status !== true ) { |
60 | $this->dieWithError( $status ); |
61 | } |
62 | |
63 | # Output success line with the title and config parameters |
64 | $res = []; |
65 | $res['title'] = $this->title->getPrefixedText(); |
66 | $res['default'] = $params['default']; |
67 | $res['autoreview'] = $params['autoreview']; |
68 | $res['expiry'] = MediaWikiServices::getInstance()->getContentLanguage() |
69 | ->formatExpiry( $form->getExpiry(), TS_ISO_8601 ); |
70 | $this->getResult()->addValue( null, $this->getModuleName(), $res ); |
71 | } |
72 | |
73 | /** |
74 | * @param string $key |
75 | * @return int|null |
76 | */ |
77 | private function defaultFromKey( $key ) { |
78 | if ( $key == 'stable' ) { |
79 | return 1; |
80 | } elseif ( $key == 'latest' ) { |
81 | return 0; |
82 | } |
83 | |
84 | return null; // bad key? |
85 | } |
86 | |
87 | /** |
88 | * @inheritDoc |
89 | */ |
90 | protected function getAllowedParams() { |
91 | // Replace '' with more readable 'none' in autoreview restiction levels |
92 | $autoreviewLevels = [ ...FlaggedRevs::getRestrictionLevels(), 'none' ]; |
93 | $pars = [ |
94 | 'default' => [ |
95 | ParamValidator::PARAM_REQUIRED => true, |
96 | ParamValidator::PARAM_TYPE => [ 'latest', 'stable' ], |
97 | ], |
98 | 'autoreview' => [ |
99 | ParamValidator::PARAM_TYPE => $autoreviewLevels, |
100 | ParamValidator::PARAM_DEFAULT => 'none', |
101 | ], |
102 | 'expiry' => [ |
103 | ParamValidator::PARAM_DEFAULT => 'infinite', |
104 | ApiBase::PARAM_HELP_MSG => 'apihelp-stabilize-param-expiry-general', |
105 | ], |
106 | 'reason' => '', |
107 | 'review' => false, |
108 | ]; |
109 | |
110 | $pars += [ |
111 | 'title' => [ |
112 | ParamValidator::PARAM_REQUIRED => true, |
113 | ApiBase::PARAM_HELP_MSG => 'apihelp-stabilize-param-title-general', |
114 | ], |
115 | ]; |
116 | return $pars; |
117 | } |
118 | |
119 | /** |
120 | * @return string |
121 | */ |
122 | protected function getSummaryMessage() { |
123 | return "apihelp-{$this->getModulePath()}-summary-general"; |
124 | } |
125 | |
126 | /** |
127 | * @inheritDoc |
128 | */ |
129 | protected function getExtendedDescription() { |
130 | return [ [ |
131 | "apihelp-{$this->getModulePath()}-extended-description-general", |
132 | 'api-help-no-extended-description', |
133 | ] ]; |
134 | } |
135 | |
136 | /** |
137 | * @inheritDoc |
138 | */ |
139 | protected function getExamplesMessages() { |
140 | return [ |
141 | 'action=stabilize&title=Test&default=stable&reason=Test&token=123ABC' |
142 | => 'apihelp-stabilize-example-general', |
143 | ]; |
144 | } |
145 | } |