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