Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php |
— | — | @@ -403,7 +403,8 @@ |
404 | 404 | $wgAPIModules['review'] = 'ApiReview'; |
405 | 405 | # Stability config module for API |
406 | 406 | $wgAutoloadClasses['ApiStabilize'] = $dir . 'api/ApiStabilize.php'; |
407 | | -$wgAPIModules['stabilize'] = 'ApiStabilize'; |
| 407 | +$wgAutoloadClasses['ApiStabilizeGeneral'] = $dir . 'api/ApiStabilize.php'; |
| 408 | +$wgAutoloadClasses['ApiStabilizeProtect'] = $dir . 'api/ApiStabilize.php'; |
408 | 409 | |
409 | 410 | # New user preferences |
410 | 411 | $wgDefaultUserOptions['flaggedrevssimpleui'] = (int)$wgSimpleFlaggedRevsUI; |
— | — | @@ -580,8 +581,11 @@ |
581 | 582 | } |
582 | 583 | |
583 | 584 | function efSetFlaggedRevsConditionalAPIModules() { |
584 | | - global $wgAPIListModules; |
585 | | - if ( !FlaggedRevs::stableOnlyIfConfigured() ) { |
| 585 | + global $wgAPIModules, $wgAPIListModules; |
| 586 | + if ( FlaggedRevs::stableOnlyIfConfigured() ) { |
| 587 | + $wgAPIModules['stabilize'] = 'ApiStabilizeProtect'; |
| 588 | + } else { |
| 589 | + $wgAPIModules['stabilize'] = 'ApiStabilizeGeneral'; |
586 | 590 | $wgAPIListModules['reviewedpages'] = 'ApiQueryReviewedpages'; |
587 | 591 | $wgAPIListModules['unreviewedpages'] = 'ApiQueryUnreviewedpages'; |
588 | 592 | } |
Index: trunk/extensions/FlaggedRevs/api/ApiStabilize.php |
— | — | @@ -26,9 +26,9 @@ |
27 | 27 | * |
28 | 28 | * @ingroup FlaggedRevs |
29 | 29 | */ |
30 | | -class ApiStabilize extends ApiBase { |
| 30 | +abstract class ApiStabilize extends ApiBase { |
31 | 31 | public function execute() { |
32 | | - global $wgUser, $wgContLang; |
| 32 | + global $wgUser; |
33 | 33 | $params = $this->extractRequestParams(); |
34 | 34 | |
35 | 35 | if ( !isset( $params['title'] ) ) { |
— | — | @@ -47,63 +47,78 @@ |
48 | 48 | $this->dieUsageMsg( reset( $errors ) ); |
49 | 49 | } |
50 | 50 | |
51 | | - $form = FlaggedRevs::getPageStabilityForm(); |
| 51 | + $this->doExecute(); // child class |
| 52 | + } |
52 | 53 | |
| 54 | + public function mustBePosted() { |
| 55 | + return true; |
| 56 | + } |
| 57 | + |
| 58 | + public function isWriteMode() { |
| 59 | + return true; |
| 60 | + } |
| 61 | + |
| 62 | + public function getTokenSalt() { |
| 63 | + return ''; |
| 64 | + } |
| 65 | + |
| 66 | + public function getVersion() { |
| 67 | + return __CLASS__ . ': $Id$'; |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +// Assumes $wgFlaggedRevsProtection is off |
| 72 | +class ApiStabilizeGeneral extends ApiStabilize { |
| 73 | + public function doExecute() { |
| 74 | + $params = $this->extractRequestParams(); |
| 75 | + |
| 76 | + $form = new PageStabilityGeneralForm(); |
53 | 77 | $form->setPage( $title ); # Our target page |
54 | 78 | $form->setWatchThis( $params['watch'] ); # Watch this page |
55 | 79 | $form->setReason( $params['reason'] ); # Reason |
56 | 80 | $form->setReasonSelection( 'other' ); # Reason dropdown |
57 | 81 | $form->setExpiry( $params['expiry'] ); # Expiry |
58 | 82 | $form->setExpirySelection( 'other' ); # Expiry dropdown |
59 | | - if ( FlaggedRevs::useProtectionLevels() ) { |
60 | | - $restriction = $params['protectlevel']; |
| 83 | + $restriction = $params['autoreview']; |
| 84 | + // Fill in config fields from URL params |
| 85 | + $form->setPrecedence( $this->precendenceFromKey( $params['precedence'] ) ); |
| 86 | + if ( $params['default'] === null ) { |
| 87 | + // Default version setting not optional |
| 88 | + $this->dieUsageMsg( array( 'missingparam', 'default' ) ); |
61 | 89 | } else { |
62 | | - $restriction = $params['autoreview']; |
63 | | - // Fill in config fields from URL params |
64 | | - $form->setPrecedence( $this->precendenceFromKey( $params['precedence'] ) ); |
65 | | - if ( $params['default'] === null ) { |
66 | | - // Default version setting not optional |
67 | | - $this->dieUsageMsg( array( 'missingparam', 'default' ) ); |
68 | | - } else { |
69 | | - $form->setOverride( $this->defaultFromKey( $params['default'] ) ); |
70 | | - } |
71 | | - $form->setReviewThis( $params['review'] ); # Auto-review option |
| 90 | + $form->setOverride( $this->defaultFromKey( $params['default'] ) ); |
72 | 91 | } |
| 92 | + $form->setReviewThis( $params['review'] ); # Auto-review option |
73 | 93 | if ( $restriction == 'none' ) { |
74 | 94 | $restriction = ''; // 'none' => '' |
75 | 95 | } |
76 | 96 | $form->setAutoreview( $restriction ); # Autoreview restriction |
77 | 97 | $form->ready(); |
78 | | - |
| 98 | + |
79 | 99 | $status = $form->submit(); // true/error message key |
80 | 100 | if ( $status !== true ) { |
81 | 101 | $this->dieUsage( wfMsg( $status ) ); |
82 | 102 | } |
83 | | - |
| 103 | + |
84 | 104 | # Output success line with the title and config parameters |
85 | 105 | $res = array(); |
86 | 106 | $res['title'] = $title->getPrefixedText(); |
87 | | - if ( FlaggedRevs::useProtectionLevels() ) { |
88 | | - $res['protectlevel'] = $params['protectlevel']; |
89 | | - } else { |
90 | | - $res['default'] = $params['default']; |
91 | | - $res['precedence'] = $params['precedence']; |
92 | | - $res['autoreview'] = $params['autoreview']; |
93 | | - } |
| 107 | + $res['default'] = $params['default']; |
| 108 | + $res['precedence'] = $params['precedence']; |
| 109 | + $res['autoreview'] = $params['autoreview']; |
94 | 110 | $res['expiry'] = $form->getExpiry(); |
95 | 111 | $this->getResult()->addValue( null, $this->getModuleName(), $res ); |
96 | 112 | } |
97 | | - |
| 113 | + |
98 | 114 | protected function defaultFromKey( $key ) { |
99 | 115 | if ( $key == 'stable' ) { |
100 | 116 | return 1; |
101 | 117 | } else if ( $key == 'latest' ) { |
102 | 118 | return 0; |
103 | 119 | } |
104 | | - // bad key? |
105 | | - return null; |
| 120 | + return null; // bad key? |
106 | 121 | } |
107 | | - |
| 122 | + |
108 | 123 | protected function precendenceFromKey( $key ) { |
109 | 124 | if ( $key == 'pristine' ) { |
110 | 125 | return FLAGGED_VIS_PRISTINE; |
— | — | @@ -112,10 +127,9 @@ |
113 | 128 | } else if ( $key == 'latest' ) { |
114 | 129 | return FLAGGED_VIS_LATEST; |
115 | 130 | } |
116 | | - // bad key? |
117 | | - return null; |
| 131 | + return null; // bad key? |
118 | 132 | } |
119 | | - |
| 133 | + |
120 | 134 | protected function keyFromPrecendence( $precedence ) { |
121 | 135 | if ( $precedence == FLAGGED_VIS_PRISTINE ) { |
122 | 136 | return 'pristine'; |
— | — | @@ -124,83 +138,55 @@ |
125 | 139 | } else if ( $precedence == FLAGGED_VIS_LATEST ) { |
126 | 140 | return 'lastest'; |
127 | 141 | } |
128 | | - // bad key? |
129 | | - return null; |
| 142 | + return null; // bad key? |
130 | 143 | } |
131 | 144 | |
132 | | - public function mustBePosted() { |
133 | | - return true; |
134 | | - } |
135 | | - |
136 | | - public function isWriteMode() { |
137 | | - return true; |
138 | | - } |
139 | | - |
140 | 145 | public function getAllowedParams() { |
141 | 146 | // Replace '' with more readable 'none' in autoreview restiction levels |
142 | 147 | $autoreviewLevels = FlaggedRevs::getRestrictionLevels(); |
143 | 148 | $autoreviewLevels[] = 'none'; |
144 | | - if ( FlaggedRevs::useProtectionLevels() ) { |
145 | | - $pars = array( |
146 | | - 'protectlevel' => array( |
147 | | - ApiBase :: PARAM_TYPE => $autoreviewLevels, |
148 | | - ApiBase :: PARAM_DFLT => 'none', |
149 | | - ) |
150 | | - ); |
151 | | - } else { |
152 | | - $pars = array( |
153 | | - 'default' => array( |
154 | | - ApiBase :: PARAM_TYPE => array( 'latest', 'stable' ), |
155 | | - ApiBase :: PARAM_DFLT => null, |
156 | | - ), |
157 | | - 'precedence' => array( |
158 | | - ApiBase :: PARAM_TYPE => array( 'pristine', 'quality', 'latest' ), |
159 | | - ApiBase :: PARAM_DFLT => $this->keyFromPrecendence( FlaggedRevs::getPrecedence() ) |
160 | | - ), |
161 | | - 'autoreview' => array( |
162 | | - ApiBase :: PARAM_TYPE => $autoreviewLevels, |
163 | | - ApiBase :: PARAM_DFLT => 'none', |
164 | | - ), |
165 | | - ); |
166 | | - } |
167 | | - $pars += array( |
168 | | - 'expiry' => 'infinite', |
169 | | - 'reason' => '', |
170 | | - 'review' => false, |
171 | | - 'watch' => null, |
172 | | - 'token' => null, |
173 | | - 'title' => null, |
| 149 | + $pars = array( |
| 150 | + 'default' => array( |
| 151 | + ApiBase :: PARAM_TYPE => array( 'latest', 'stable' ), |
| 152 | + ApiBase :: PARAM_DFLT => null, |
| 153 | + ), |
| 154 | + 'precedence' => array( |
| 155 | + ApiBase :: PARAM_TYPE => array( 'pristine', 'quality', 'latest' ), |
| 156 | + ApiBase :: PARAM_DFLT => $this->keyFromPrecendence( FlaggedRevs::getPrecedence() ) |
| 157 | + ), |
| 158 | + 'autoreview' => array( |
| 159 | + ApiBase :: PARAM_TYPE => $autoreviewLevels, |
| 160 | + ApiBase :: PARAM_DFLT => 'none', |
| 161 | + ), |
| 162 | + 'expiry' => 'infinite', |
| 163 | + 'reason' => '', |
| 164 | + 'review' => false, |
| 165 | + 'watch' => null, |
| 166 | + 'token' => null, |
| 167 | + 'title' => null, |
174 | 168 | ); |
175 | 169 | return $pars; |
176 | 170 | } |
177 | 171 | |
178 | 172 | public function getParamDescription() { |
179 | | - if ( FlaggedRevs::useProtectionLevels() ) { |
180 | | - $desc = array( |
181 | | - 'protectlevel' => 'The review protection level', |
182 | | - ); |
183 | | - } else { |
184 | | - $desc = array( |
185 | | - 'default' => 'Default revision to show', |
186 | | - 'precedence' => 'What stable revision should be shown', |
187 | | - 'autoreview' => 'Auto-review restriction', |
188 | | - ); |
189 | | - } |
190 | | - $desc += array( |
191 | | - 'expiry' => 'Stabilization expiry', |
| 173 | + return array( |
| 174 | + 'default' => 'Default revision to show', |
| 175 | + 'precedence' => 'How the stable version is selected by precedence', |
| 176 | + 'autoreview' => 'Auto-review restriction', |
| 177 | + 'expiry' => 'Expiry for these settings', |
192 | 178 | 'title' => 'Title of page to be stabilized', |
193 | 179 | 'reason' => 'Reason', |
194 | 180 | 'review' => 'Review this page', |
195 | 181 | 'watch' => 'Watch this page', |
196 | | - 'token' => 'An edit token retrieved through prop=info', |
| 182 | + 'token' => 'An edit token retrieved through prop=info' |
197 | 183 | ); |
198 | | - return $desc; |
199 | 184 | } |
200 | 185 | |
201 | 186 | public function getDescription() { |
202 | | - return 'Change page stabilization settings.'; |
| 187 | + return 'Change page stability settings.'; |
203 | 188 | } |
204 | | - |
| 189 | + |
| 190 | + // @TODO: fill in stabilize_* values from PageStabilityGeneralForm |
205 | 191 | public function getPossibleErrors() { |
206 | 192 | return array_merge( parent::getPossibleErrors(), array( |
207 | 193 | array( 'missingparam', 'title' ), |
— | — | @@ -209,23 +195,93 @@ |
210 | 196 | array( 'code' => 'invalidtitle', 'info' => 'Invalid title given.' ), |
211 | 197 | array( 'code' => 'invalidtitle', 'info' => 'Target page does not exist.' ), |
212 | 198 | array( 'code' => 'invalidtitle', 'info' => 'Title given does not correspond to a reviewable page.' ), |
213 | | - array( 'code' => 'badprotectlevel', 'info' => 'Invalid protection level given.' ), |
214 | | - array( 'code' => 'invalidconfig', 'info' => 'Invalid config parameters given. The precendence level may beyond your rights.' ), |
215 | 199 | ) ); |
216 | 200 | } |
217 | | - |
218 | | - public function getTokenSalt() { |
219 | | - return ''; |
220 | | - } |
221 | 201 | |
222 | 202 | protected function getExamples() { |
223 | | - if ( FlaggedRevs::useProtectionLevels() ) |
224 | | - return 'api.php?action=stabilize&title=Test&protectlevel=none&reason=Test&token=123ABC'; |
225 | | - else |
226 | | - return 'api.php?action=stabilize&title=Test&default=stable&reason=Test&token=123ABC'; |
| 203 | + return 'api.php?action=stabilize&title=Test&default=stable&reason=Test&token=123ABC'; |
227 | 204 | } |
| 205 | +} |
228 | 206 | |
229 | | - public function getVersion() { |
230 | | - return __CLASS__ . ': $Id$'; |
| 207 | +// Assumes $wgFlaggedRevsProtection is on |
| 208 | +class ApiStabilizeProtect extends ApiStabilize { |
| 209 | + public function doExecute() { |
| 210 | + $params = $this->extractRequestParams(); |
| 211 | + |
| 212 | + $form = new PageStabilityProtectForm(); |
| 213 | + $form->setPage( $title ); # Our target page |
| 214 | + $form->setWatchThis( $params['watch'] ); # Watch this page |
| 215 | + $form->setReason( $params['reason'] ); # Reason |
| 216 | + $form->setReasonSelection( 'other' ); # Reason dropdown |
| 217 | + $form->setExpiry( $params['expiry'] ); # Expiry |
| 218 | + $form->setExpirySelection( 'other' ); # Expiry dropdown |
| 219 | + $restriction = $params['protectlevel']; |
| 220 | + if ( $restriction == 'none' ) { |
| 221 | + $restriction = ''; // 'none' => '' |
| 222 | + } |
| 223 | + $form->setAutoreview( $restriction ); # Autoreview restriction |
| 224 | + $form->ready(); |
| 225 | + |
| 226 | + $status = $form->submit(); // true/error message key |
| 227 | + if ( $status !== true ) { |
| 228 | + $this->dieUsage( wfMsg( $status ) ); |
| 229 | + } |
| 230 | + |
| 231 | + # Output success line with the title and config parameters |
| 232 | + $res = array(); |
| 233 | + $res['title'] = $title->getPrefixedText(); |
| 234 | + $res['protectlevel'] = $params['protectlevel']; |
| 235 | + $res['expiry'] = $form->getExpiry(); |
| 236 | + $this->getResult()->addValue( null, $this->getModuleName(), $res ); |
231 | 237 | } |
232 | | -} |
| 238 | + |
| 239 | + public function getAllowedParams() { |
| 240 | + // Replace '' with more readable 'none' in autoreview restiction levels |
| 241 | + $autoreviewLevels = FlaggedRevs::getRestrictionLevels(); |
| 242 | + $autoreviewLevels[] = 'none'; |
| 243 | + return array( |
| 244 | + 'protectlevel' => array( |
| 245 | + ApiBase :: PARAM_TYPE => $autoreviewLevels, |
| 246 | + ApiBase :: PARAM_DFLT => 'none', |
| 247 | + ), |
| 248 | + 'expiry' => 'infinite', |
| 249 | + 'reason' => '', |
| 250 | + 'review' => false, |
| 251 | + 'watch' => null, |
| 252 | + 'token' => null, |
| 253 | + 'title' => null, |
| 254 | + ); |
| 255 | + } |
| 256 | + |
| 257 | + public function getParamDescription() { |
| 258 | + return array( |
| 259 | + 'protectlevel' => 'The review-protection level', |
| 260 | + 'expiry' => 'Review-protection expiry', |
| 261 | + 'title' => 'Title of page to be review-protected', |
| 262 | + 'reason' => 'Reason', |
| 263 | + 'review' => 'Review this page', |
| 264 | + 'watch' => 'Watch this page', |
| 265 | + 'token' => 'An edit token retrieved through prop=info', |
| 266 | + ); |
| 267 | + } |
| 268 | + |
| 269 | + public function getDescription() { |
| 270 | + return 'Configure review-protection settings.'; |
| 271 | + } |
| 272 | + |
| 273 | + // @TODO: fill in stabilize_* values from PageStabilityProtectForm |
| 274 | + public function getPossibleErrors() { |
| 275 | + return array_merge( parent::getPossibleErrors(), array( |
| 276 | + array( 'missingparam', 'title' ), |
| 277 | + array( 'missingparam', 'token' ), |
| 278 | + array( 'missingparam', 'default' ), |
| 279 | + array( 'code' => 'invalidtitle', 'info' => 'Invalid title given.' ), |
| 280 | + array( 'code' => 'invalidtitle', 'info' => 'Target page does not exist.' ), |
| 281 | + array( 'code' => 'invalidtitle', 'info' => 'Title given does not correspond to a reviewable page.' ), |
| 282 | + ) ); |
| 283 | + } |
| 284 | + |
| 285 | + protected function getExamples() { |
| 286 | + return 'api.php?action=stabilize&title=Test&protectlevel=none&reason=Test&token=123ABC'; |
| 287 | + } |
| 288 | +} |
\ No newline at end of file |