Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php |
— | — | @@ -335,9 +335,9 @@ |
336 | 336 | # Load review UI |
337 | 337 | $wgAutoloadClasses['RevisionReview'] = $dir . 'specialpages/RevisionReview_body.php'; |
338 | 338 | # Load protection/stability UI |
339 | | -$wgAutoloadClasses['FlaggedRevsConfigForm'] = $dir . 'forms/FlaggedRevsConfigForm.php'; |
340 | | -$wgAutoloadClasses['PageStabilityForm'] = $dir . 'forms/FlaggedRevsConfigForm.php'; |
341 | | -$wgAutoloadClasses['PageStabilityProtectForm'] = $dir . 'forms/FlaggedRevsConfigForm.php'; |
| 339 | +$wgAutoloadClasses['PageStabilityForm'] = $dir . 'forms/PageStabilityForm.php'; |
| 340 | +$wgAutoloadClasses['PageStabilityGeneralForm'] = $dir . 'forms/PageStabilityForm.php'; |
| 341 | +$wgAutoloadClasses['PageStabilityProtectForm'] = $dir . 'forms/PageStabilityForm.php'; |
342 | 342 | |
343 | 343 | # Load reviewed versions UI |
344 | 344 | $wgAutoloadClasses['ReviewedVersions'] = $dir . 'specialpages/ReviewedVersions_body.php'; |
Index: trunk/extensions/FlaggedRevs/forms/FlaggedRevsConfigForm.php |
— | — | @@ -1,645 +0,0 @@ |
2 | | -<?php |
3 | | -if ( !defined( 'MEDIAWIKI' ) ) { |
4 | | - echo "FlaggedRevs extension\n"; |
5 | | - exit( 1 ); |
6 | | -} |
7 | | -/** |
8 | | - * Class containing stability settings form business logic |
9 | | - * |
10 | | - * Usage: (a) set ALL form params before doing anything else |
11 | | - * (b) call ready() when all params are set |
12 | | - * (c) check isAllowed() before calling submit() as needed |
13 | | - */ |
14 | | -abstract class FlaggedRevsConfigForm |
15 | | -{ |
16 | | - /* Form parameters which can be user given */ |
17 | | - protected $target = null; # Target page text |
18 | | - protected $watchThis = null; # Watch checkbox |
19 | | - protected $reviewThis = null; # Auto-review option... |
20 | | - protected $reason = ''; # Custom/extra reason |
21 | | - protected $reasonSelection = ''; # Reason dropdown key |
22 | | - protected $expiry = ''; # Custom expiry |
23 | | - protected $expirySelection = ''; # Expiry dropdown key |
24 | | - protected $override = -1; # Default version |
25 | | - protected $autoreview = ''; # Autoreview restrictions... |
26 | | - |
27 | | - protected $page = false; # Target page obj (of $target) |
28 | | - protected $oldConfig = array(); # Old page config |
29 | | - protected $oldExpiry = ''; # Old page config expiry (GMT) |
30 | | - |
31 | | - protected $inputLock = 0; # Disallow bad submissions |
32 | | - |
33 | | - public function getTarget() { |
34 | | - return $this->target; |
35 | | - } |
36 | | - |
37 | | - public function setTarget( $value ) { |
38 | | - $this->trySet( $this->target, $value ); |
39 | | - $this->page = Title::newFromURL( $this->target ); |
40 | | - } |
41 | | - |
42 | | - public function getWatchThis() { |
43 | | - return $this->watchThis; |
44 | | - } |
45 | | - |
46 | | - public function setWatchThis( $value ) { |
47 | | - $this->trySet( $this->watchThis, $value ); |
48 | | - } |
49 | | - |
50 | | - public function getReason() { |
51 | | - return $this->reason; |
52 | | - } |
53 | | - |
54 | | - public function setReason( $value ) { |
55 | | - $this->trySet( $this->reason, $value ); |
56 | | - } |
57 | | - |
58 | | - public function getReasonSelection() { |
59 | | - return $this->reasonSelection; |
60 | | - } |
61 | | - |
62 | | - public function setReasonSelection( $value ) { |
63 | | - $this->trySet( $this->reasonSelection, $value ); |
64 | | - } |
65 | | - |
66 | | - public function getExpiry() { |
67 | | - return $this->expiry; |
68 | | - } |
69 | | - |
70 | | - public function setExpiry( $value ) { |
71 | | - $this->trySet( $this->expiry, $value ); |
72 | | - } |
73 | | - |
74 | | - public function getExpirySelection() { |
75 | | - return $this->expirySelection; |
76 | | - } |
77 | | - |
78 | | - public function setExpirySelection( $value ) { |
79 | | - $this->trySet( $this->expirySelection, $value ); |
80 | | - } |
81 | | - |
82 | | - public function getAutoreview() { |
83 | | - return $this->autoreview; |
84 | | - } |
85 | | - |
86 | | - public function setAutoreview( $value ) { |
87 | | - $this->trySet( $this->autoreview, $value ); |
88 | | - } |
89 | | - |
90 | | - /** |
91 | | - * Set a member field to a value if the fields are unlocked |
92 | | - */ |
93 | | - protected function trySet( &$field, $value ) { |
94 | | - if ( $this->inputLock ) { |
95 | | - throw new MWException( "FlaggedRevsConfigForm fields cannot be set anymore.\n"); |
96 | | - } else { |
97 | | - $field = $value; // submission locked => still allowing input |
98 | | - } |
99 | | - } |
100 | | - |
101 | | - /** |
102 | | - * Signal that inputs are starting |
103 | | - */ |
104 | | - public function start() { |
105 | | - $this->inputLock = 0; |
106 | | - } |
107 | | - |
108 | | - /** |
109 | | - * Signal that inputs are done and load old config |
110 | | - * @return mixed (true on success, error string on target failure) |
111 | | - */ |
112 | | - public function ready() { |
113 | | - $this->inputLock = 1; |
114 | | - $status = $this->checkTarget(); |
115 | | - if ( $status !== true ) { |
116 | | - return $status; // bad target |
117 | | - } |
118 | | - $this->loadOldConfig(); // current settings from DB |
119 | | - return $status; |
120 | | - } |
121 | | - |
122 | | - /* |
123 | | - * Preload existing page settings (e.g. from GET request). |
124 | | - * @return mixed (true on success, error string on failure) |
125 | | - */ |
126 | | - public function preloadSettings() { |
127 | | - if ( !$this->inputLock ) { |
128 | | - throw new MWException( "FlaggedRevsConfigForm input fields not set yet.\n"); |
129 | | - } |
130 | | - $status = $this->checkTarget(); |
131 | | - if ( $status !== true ) { |
132 | | - return $status; // bad target |
133 | | - } |
134 | | - return $this->reallyPreloadSettings(); // load the params... |
135 | | - } |
136 | | - |
137 | | - /* |
138 | | - * @return mixed (true on success, error string on failure) |
139 | | - */ |
140 | | - protected function reallyPreloadSettings() { |
141 | | - return true; |
142 | | - } |
143 | | - |
144 | | - /* |
145 | | - * Verify and clean up parameters (e.g. from POST request). |
146 | | - * @return mixed (true on success, error string on failure) |
147 | | - */ |
148 | | - protected function checkSettings() { |
149 | | - $status = $this->checkTarget(); |
150 | | - if ( $status !== true ) { |
151 | | - return $status; // bad target |
152 | | - } |
153 | | - $status = $this->reallyCheckSettings(); // check other params... |
154 | | - return $status; |
155 | | - } |
156 | | - |
157 | | - /* |
158 | | - * @return mixed (true on success, error string on failure) |
159 | | - */ |
160 | | - protected function reallyCheckSettings() { |
161 | | - return true; |
162 | | - } |
163 | | - |
164 | | - /* |
165 | | - * Check that the target page is valid |
166 | | - * @return mixed (true on success, error string on failure) |
167 | | - */ |
168 | | - protected function checkTarget() { |
169 | | - $this->page = Title::newFromURL( $this->target ); |
170 | | - if ( is_null( $this->page ) ) { |
171 | | - return 'stabilize_page_invalid'; |
172 | | - } elseif ( !$this->page->exists() ) { |
173 | | - return 'stabilize_page_notexists'; |
174 | | - } elseif ( !FlaggedRevs::inReviewNamespace( $this->page ) ) { |
175 | | - return 'stabilize_page_unreviewable'; |
176 | | - } |
177 | | - return true; |
178 | | - } |
179 | | - |
180 | | - protected function loadOldConfig() { |
181 | | - # Get the current page config and GMT expiry |
182 | | - $this->oldConfig = FlaggedRevs::getPageVisibilitySettings( $this->page, FR_MASTER ); |
183 | | - $this->oldExpiry = $this->oldConfig['expiry'] === 'infinity' |
184 | | - ? 'infinite' |
185 | | - : wfTimestamp( TS_RFC2822, $this->oldConfig['expiry'] ); |
186 | | - } |
187 | | - |
188 | | - /* |
189 | | - * Gets the target page Obj |
190 | | - * @return mixed (Title or null) |
191 | | - */ |
192 | | - public function getPage() { |
193 | | - if ( !$this->inputLock ) { |
194 | | - throw new MWException( "FlaggedRevsConfigForm input fields not set yet.\n"); |
195 | | - } |
196 | | - return $this->page; |
197 | | - } |
198 | | - |
199 | | - /* |
200 | | - * Gets the current config expiry in GMT (or 'infinite') |
201 | | - * @return string |
202 | | - */ |
203 | | - public function getOldExpiryGMT() { |
204 | | - if ( !$this->inputLock ) { |
205 | | - throw new MWException( "FlaggedRevsConfigForm input fields not set yet.\n"); |
206 | | - } |
207 | | - return $this->oldExpiry; |
208 | | - } |
209 | | - |
210 | | - /* |
211 | | - * Can the user change the settings for this page? |
212 | | - * Note: if the current autoreview restriction is too high for this user |
213 | | - * then this will return false. Useful for form selectors. |
214 | | - * @return bool |
215 | | - */ |
216 | | - public function isAllowed() { |
217 | | - # Users who cannot edit or review the page cannot set this |
218 | | - return ( $this->page |
219 | | - && $this->page->userCan( 'stablesettings' ) |
220 | | - && $this->page->userCan( 'edit' ) |
221 | | - && $this->page->userCan( 'review' ) |
222 | | - ); |
223 | | - } |
224 | | - |
225 | | - /** |
226 | | - * Submit the form parameters for the page config to the DB. |
227 | | - * Note: caller is responsible for permission checks. |
228 | | - * |
229 | | - * @return mixed (true on success, error string on failure) |
230 | | - */ |
231 | | - public function submit() { |
232 | | - global $wgUser; |
233 | | - if ( !$this->inputLock ) { |
234 | | - throw new MWException( "FlaggedRevsConfigForm input fields not set yet.\n"); |
235 | | - } |
236 | | - $status = $this->checkSettings(); |
237 | | - if ( $status !== true ) { |
238 | | - return $status; // cannot submit - broken params |
239 | | - } |
240 | | - # Are we are going back to site defaults? |
241 | | - $reset = $this->newConfigIsReset(); |
242 | | - # Parse and cleanup the expiry time given... |
243 | | - if ( $reset || $this->expiry == 'infinite' || $this->expiry == 'indefinite' ) { |
244 | | - $this->expiry = Block::infinity(); // normalize to 'infinity' |
245 | | - } else { |
246 | | - # Convert GNU-style date, on error returns -1 for PHP <5.1 and false for PHP >=5.1 |
247 | | - $this->expiry = strtotime( $this->expiry ); |
248 | | - if ( $this->expiry < 0 || $this->expiry === false ) { |
249 | | - return 'stabilize_expiry_invalid'; |
250 | | - } |
251 | | - # Convert date to MW timestamp format |
252 | | - $this->expiry = wfTimestamp( TS_MW, $this->expiry ); |
253 | | - if ( $this->expiry < wfTimestampNow() ) { |
254 | | - return 'stabilize_expiry_old'; |
255 | | - } |
256 | | - } |
257 | | - # Update the DB row with the new config... |
258 | | - $changed = $this->updateConfigRow( $reset ); |
259 | | - # Log if this actually changed anything... |
260 | | - if ( $changed ) { |
261 | | - # Update logs and make a null edit |
262 | | - $nullRev = $this->updateLogsAndHistory( $reset ); |
263 | | - # Null edit may have been autoreviewed already |
264 | | - $frev = FlaggedRevision::newFromTitle( $this->page, $nullRev->getId(), FR_MASTER ); |
265 | | - # We may need to invalidate the page links after changing the stable version. |
266 | | - # Only do so if not already done, such as by an auto-review of the null edit. |
267 | | - $invalidate = !$frev; |
268 | | - # Check if this null edit is to be reviewed... |
269 | | - if ( !$frev && $this->reviewThis ) { |
270 | | - $flags = null; |
271 | | - $article = new Article( $this->page ); |
272 | | - # Review this revision of the page... |
273 | | - $ok = FlaggedRevs::autoReviewEdit( |
274 | | - $article, $wgUser, $nullRev->getText(), $nullRev, $flags, true ); |
275 | | - if( $ok ) { |
276 | | - FlaggedRevs::markRevisionPatrolled( $nullRev ); // reviewed -> patrolled |
277 | | - $invalidate = false; // links invalidated (with auto-reviewed) |
278 | | - } |
279 | | - } |
280 | | - # Update the links tables as the stable version may now be the default page... |
281 | | - if ( $invalidate ) { |
282 | | - FlaggedRevs::titleLinksUpdate( $this->page ); |
283 | | - } |
284 | | - } |
285 | | - # Apply watchlist checkbox value (may be NULL) |
286 | | - $this->updateWatchlist(); |
287 | | - # Take this opportunity to purge out expired configurations |
288 | | - FlaggedRevs::purgeExpiredConfigurations(); |
289 | | - return true; |
290 | | - } |
291 | | - |
292 | | - /* |
293 | | - * Do history & log updates: |
294 | | - * (a) Add a new stability log entry |
295 | | - * (b) Add a null edit like the log entry |
296 | | - * @return Revision |
297 | | - */ |
298 | | - protected function updateLogsAndHistory( $reset ) { |
299 | | - global $wgContLang; |
300 | | - $article = new Article( $this->page ); |
301 | | - $latest = $this->page->getLatestRevID( GAID_FOR_UPDATE ); |
302 | | - # Config may have changed to allow stable versions. |
303 | | - # Refresh tracking to account for any hidden reviewed versions... |
304 | | - $frev = FlaggedRevision::newFromStable( $this->page, FR_MASTER ); |
305 | | - if ( $frev ) { |
306 | | - FlaggedRevs::updateStableVersion( $article, $frev->getRevision(), $latest ); |
307 | | - } else { |
308 | | - FlaggedRevs::clearTrackingRows( $article->getId() ); |
309 | | - } |
310 | | - # Insert stability log entry... |
311 | | - $log = new LogPage( 'stable' ); |
312 | | - if ( $reset ) { |
313 | | - $log->addEntry( 'reset', $this->page, $this->reason ); |
314 | | - $type = "stable-logentry-reset"; |
315 | | - $settings = ''; // no level, expiry info |
316 | | - } else { |
317 | | - $params = $this->getLogParams(); |
318 | | - $log->addEntry( 'config', $this->page, $this->reason, |
319 | | - FlaggedRevsLogs::collapseParams( $params ) ); |
320 | | - $type = "stable-logentry-config"; |
321 | | - // Settings message in text form (e.g. [x=a,y=b,z]) |
322 | | - $settings = FlaggedRevsLogs::stabilitySettings( $params, true /*content*/ ); |
323 | | - } |
324 | | - # Build null-edit comment...<action: reason [settings] (expiry)> |
325 | | - $comment = $wgContLang->ucfirst( |
326 | | - wfMsgForContent( $type, $this->page->getPrefixedText() ) ); // action |
327 | | - if ( $this->reason != '' ) { |
328 | | - $comment .= wfMsgForContent( 'colon-separator' ) . $this->reason; // add reason |
329 | | - } |
330 | | - if ( $settings != '' ) { |
331 | | - $comment .= " {$settings}"; // add settings |
332 | | - } |
333 | | - # Insert a null revision... |
334 | | - $dbw = wfGetDB( DB_MASTER ); |
335 | | - $nullRev = Revision::newNullRevision( $dbw, $article->getId(), $comment, true ); |
336 | | - $nullRevId = $nullRev->insertOn( $dbw ); |
337 | | - # Update page record and touch page |
338 | | - $article->updateRevisionOn( $dbw, $nullRev, $latest ); |
339 | | - wfRunHooks( 'NewRevisionFromEditComplete', array( $article, $nullRev, $latest ) ); |
340 | | - # Return null Revision object for autoreview check |
341 | | - return $nullRev; |
342 | | - } |
343 | | - |
344 | | - /* |
345 | | - * Checks if new config is the same as the site default |
346 | | - * @return bool |
347 | | - */ |
348 | | - protected function newConfigIsReset() { |
349 | | - return false; |
350 | | - } |
351 | | - |
352 | | - /* |
353 | | - * Get assoc. array of log params |
354 | | - * @return array |
355 | | - */ |
356 | | - protected function getLogParams() { |
357 | | - return array(); |
358 | | - } |
359 | | - |
360 | | - /* |
361 | | - * (a) Watch page if $watchThis is true |
362 | | - * (b) Unwatch if $watchThis is false |
363 | | - */ |
364 | | - protected function updateWatchlist() { |
365 | | - global $wgUser; |
366 | | - # Apply watchlist checkbox value (may be NULL) |
367 | | - if ( $this->watchThis === true ) { |
368 | | - $wgUser->addWatch( $this->page ); |
369 | | - } elseif ( $this->watchThis === false ) { |
370 | | - $wgUser->removeWatch( $this->page ); |
371 | | - } |
372 | | - } |
373 | | - |
374 | | - protected function loadExpiry() { |
375 | | - # Custom expiry takes precedence |
376 | | - if ( $this->expiry == '' ) { |
377 | | - $this->expiry = $this->expirySelection; |
378 | | - if ( $this->expiry == 'existing' ) { |
379 | | - $this->expiry = $this->oldExpiry; |
380 | | - } |
381 | | - } |
382 | | - } |
383 | | - |
384 | | - protected function loadReason() { |
385 | | - # Custom reason takes precedence |
386 | | - if ( $this->reasonSelection != 'other' ) { |
387 | | - $comment = $this->reasonSelection; // start with dropdown reason |
388 | | - if ( $this->reason != '' ) { |
389 | | - # Append custom reason |
390 | | - $comment .= wfMsgForContent( 'colon-separator' ) . $this->reason; |
391 | | - } |
392 | | - } else { |
393 | | - $comment = $this->reason; // just use custom reason |
394 | | - } |
395 | | - $this->reason = $comment; |
396 | | - } |
397 | | - |
398 | | - // Same JS used for expiry for either $wgFlaggedRevsProtection case |
399 | | - public static function addProtectionJS() { |
400 | | - global $wgOut; |
401 | | - $wgOut->addScript( |
402 | | - "<script type=\"text/javascript\"> |
403 | | - function onFRChangeExpiryDropdown() { |
404 | | - document.getElementById('mwStabilizeExpiryOther').value = ''; |
405 | | - } |
406 | | - function onFRChangeExpiryField() { |
407 | | - document.getElementById('mwStabilizeExpirySelection').value = 'othertime'; |
408 | | - } |
409 | | - </script>" |
410 | | - ); |
411 | | - } |
412 | | -} |
413 | | - |
414 | | -// Assumes $wgFlaggedRevsProtection is off |
415 | | -class PageStabilityForm extends FlaggedRevsConfigForm { |
416 | | - /* Form parameters which can be user given */ |
417 | | - public $select = -1; # Precedence |
418 | | - |
419 | | - public function getReviewThis() { |
420 | | - return $this->reviewThis; |
421 | | - } |
422 | | - |
423 | | - public function setReviewThis( $value ) { |
424 | | - $this->trySet( $this->reviewThis, $value ); |
425 | | - } |
426 | | - |
427 | | - public function getPrecedence() { |
428 | | - return $this->select; |
429 | | - } |
430 | | - |
431 | | - public function setPrecedence( $value ) { |
432 | | - $this->trySet( $this->select, $value ); |
433 | | - } |
434 | | - |
435 | | - public function getOverride() { |
436 | | - return $this->override; |
437 | | - } |
438 | | - |
439 | | - public function setOverride( $value ) { |
440 | | - $this->trySet( $this->override, $value ); |
441 | | - } |
442 | | - |
443 | | - protected function reallyPreloadSettings() { |
444 | | - $this->select = $this->oldConfig['select']; |
445 | | - $this->override = $this->oldConfig['override']; |
446 | | - $this->autoreview = $this->oldConfig['autoreview']; |
447 | | - $this->expiry = $this->oldExpiry; |
448 | | - $this->expirySelection = 'existing'; |
449 | | - $this->watchThis = $this->page->userIsWatching(); |
450 | | - return true; |
451 | | - } |
452 | | - |
453 | | - protected function reallyCheckSettings() { |
454 | | - $this->loadReason(); |
455 | | - $this->loadExpiry(); |
456 | | - $this->override = $this->override ? 1 : 0; // default version settings is 0 or 1 |
457 | | - if ( !FlaggedRevs::isValidPrecedence( $this->select ) ) { |
458 | | - return 'stabilize_invalid_precedence'; // invalid precedence value |
459 | | - } |
460 | | - // Check autoreview restriction setting |
461 | | - if ( !FlaggedRevs::userCanSetAutoreviewLevel( $this->autoreview ) ) { |
462 | | - return 'stabilize_invalid_autoreview'; // invalid value |
463 | | - } |
464 | | - return true; |
465 | | - } |
466 | | - |
467 | | - protected function getLogParams() { |
468 | | - return array( |
469 | | - 'override' => $this->override, |
470 | | - 'autoreview' => $this->autoreview, |
471 | | - 'expiry' => $this->expiry, // TS_MW/infinity |
472 | | - 'precedence' => $this->select |
473 | | - ); |
474 | | - } |
475 | | - |
476 | | - // Return current config array |
477 | | - public function getOldConfig() { |
478 | | - if ( !$this->inputLock ) { |
479 | | - throw new MWException( "FlaggedRevsConfigForm input fields not set yet.\n"); |
480 | | - } |
481 | | - return $this->oldConfig; |
482 | | - } |
483 | | - |
484 | | - // returns whether row changed |
485 | | - protected function updateConfigRow( $reset ) { |
486 | | - $changed = false; |
487 | | - $dbw = wfGetDB( DB_MASTER ); |
488 | | - # If setting to site default values and there is a row then erase it |
489 | | - if ( $reset ) { |
490 | | - $dbw->delete( 'flaggedpage_config', |
491 | | - array( 'fpc_page_id' => $this->page->getArticleID() ), |
492 | | - __METHOD__ |
493 | | - ); |
494 | | - $changed = ( $dbw->affectedRows() != 0 ); // did this do anything? |
495 | | - # Otherwise, add/replace row if we are not just setting it to the site default |
496 | | - } elseif ( !$reset ) { |
497 | | - $dbExpiry = Block::encodeExpiry( $this->expiry, $dbw ); |
498 | | - # Get current config... |
499 | | - $oldRow = $dbw->selectRow( 'flaggedpage_config', |
500 | | - array( 'fpc_select', 'fpc_override', 'fpc_level', 'fpc_expiry' ), |
501 | | - array( 'fpc_page_id' => $this->page->getArticleID() ), |
502 | | - __METHOD__, |
503 | | - 'FOR UPDATE' |
504 | | - ); |
505 | | - # Check if this is not the same config as the existing row (if any) |
506 | | - $changed = self::configIsDifferent( $oldRow, |
507 | | - $this->select, $this->override, $this->autoreview, $dbExpiry ); |
508 | | - # If the new config is different, replace the old row... |
509 | | - if ( $changed ) { |
510 | | - $dbw->replace( 'flaggedpage_config', |
511 | | - array( 'PRIMARY' ), |
512 | | - array( |
513 | | - 'fpc_page_id' => $this->page->getArticleID(), |
514 | | - 'fpc_select' => (int)$this->select, |
515 | | - 'fpc_override' => (int)$this->override, |
516 | | - 'fpc_level' => $this->autoreview, |
517 | | - 'fpc_expiry' => $dbExpiry |
518 | | - ), |
519 | | - __METHOD__ |
520 | | - ); |
521 | | - } |
522 | | - } |
523 | | - return $changed; |
524 | | - } |
525 | | - |
526 | | - protected function newConfigIsReset() { |
527 | | - return ( $this->select == FlaggedRevs::getPrecedence() |
528 | | - && $this->override == FlaggedRevs::isStableShownByDefault() |
529 | | - && $this->autoreview == '' ); |
530 | | - } |
531 | | - |
532 | | - // Checks if new config is different than the existing row |
533 | | - protected function configIsDifferent( $oldRow, $select, $override, $autoreview, $dbExpiry ) { |
534 | | - if( !$oldRow ) { |
535 | | - return true; // no previous config |
536 | | - } |
537 | | - return ( $oldRow->fpc_select != $select // ...precedence changed, or... |
538 | | - || $oldRow->fpc_override != $override // ...override changed, or... |
539 | | - || $oldRow->fpc_level != $autoreview // ...autoreview level changed, or... |
540 | | - || $oldRow->fpc_expiry != $dbExpiry // ...expiry changed |
541 | | - ); |
542 | | - } |
543 | | -} |
544 | | - |
545 | | -// Assumes $wgFlaggedRevsProtection is on |
546 | | -class PageStabilityProtectForm extends FlaggedRevsConfigForm { |
547 | | - protected function reallyPreloadSettings() { |
548 | | - $this->autoreview = $this->oldConfig['autoreview']; // protect level |
549 | | - $this->expiry = $this->oldExpiry; |
550 | | - $this->expirySelection = 'existing'; |
551 | | - $this->watchThis = $this->page->userIsWatching(); |
552 | | - return true; |
553 | | - } |
554 | | - |
555 | | - protected function reallyCheckSettings() { |
556 | | - $this->loadReason(); |
557 | | - $this->loadExpiry(); |
558 | | - # Autoreview only when protecting currently unprotected pages |
559 | | - $this->reviewThis = ( FlaggedRevs::getProtectionLevel( $this->oldConfig ) == 'none' ); |
560 | | - # Check autoreview restriction setting |
561 | | - if ( !FlaggedRevs::userCanSetAutoreviewLevel( $this->autoreview ) ) { |
562 | | - return 'stabilize_invalid_level'; // invalid value |
563 | | - } |
564 | | - # Autoreview restriction => use stable |
565 | | - # No autoreview restriction => site default |
566 | | - $this->override = ( $this->autoreview != '' ) |
567 | | - ? 1 // edits require review before being published |
568 | | - : (int)FlaggedRevs::isStableShownByDefault(); // site default |
569 | | - # Check that settings are a valid protection level... |
570 | | - $newConfig = array( |
571 | | - 'override' => $this->override, |
572 | | - 'autoreview' => $this->autoreview |
573 | | - ); |
574 | | - if ( FlaggedRevs::getProtectionLevel( $newConfig ) == 'invalid' ) { |
575 | | - return 'stabilize_invalid_level'; // double-check configuration |
576 | | - } |
577 | | - return true; |
578 | | - } |
579 | | - |
580 | | - // Doesn't include 'precedence'; checked in FlaggedRevsLogs |
581 | | - protected function getLogParams() { |
582 | | - return array( |
583 | | - 'override' => $this->override, // in case of site changes |
584 | | - 'autoreview' => $this->autoreview, |
585 | | - 'expiry' => $this->expiry // TS_MW/infinity |
586 | | - ); |
587 | | - } |
588 | | - |
589 | | - protected function updateConfigRow( $reset ) { |
590 | | - $changed = false; |
591 | | - $dbw = wfGetDB( DB_MASTER ); |
592 | | - # If setting to site default values and there is a row then erase it |
593 | | - if ( $reset ) { |
594 | | - $dbw->delete( 'flaggedpage_config', |
595 | | - array( 'fpc_page_id' => $this->page->getArticleID() ), |
596 | | - __METHOD__ |
597 | | - ); |
598 | | - $changed = ( $dbw->affectedRows() != 0 ); // did this do anything? |
599 | | - # Otherwise, add/replace row if we are not just setting it to the site default |
600 | | - } elseif ( !$reset ) { |
601 | | - $dbExpiry = Block::encodeExpiry( $this->expiry, $dbw ); |
602 | | - # Get current config... |
603 | | - $oldRow = $dbw->selectRow( 'flaggedpage_config', |
604 | | - array( 'fpc_override', 'fpc_level', 'fpc_expiry' ), |
605 | | - array( 'fpc_page_id' => $this->page->getArticleID() ), |
606 | | - __METHOD__, |
607 | | - 'FOR UPDATE' |
608 | | - ); |
609 | | - # Check if this is not the same config as the existing row (if any) |
610 | | - $changed = self::configIsDifferent( $oldRow, |
611 | | - $this->override, $this->autoreview, $dbExpiry ); |
612 | | - # If the new config is different, replace the old row... |
613 | | - if ( $changed ) { |
614 | | - $dbw->replace( 'flaggedpage_config', |
615 | | - array( 'PRIMARY' ), |
616 | | - array( |
617 | | - 'fpc_page_id' => $this->page->getArticleID(), |
618 | | - 'fpc_select' => -1, // ignored |
619 | | - 'fpc_override' => (int)$this->override, |
620 | | - 'fpc_level' => $this->autoreview, |
621 | | - 'fpc_expiry' => $dbExpiry |
622 | | - ), |
623 | | - __METHOD__ |
624 | | - ); |
625 | | - } |
626 | | - } |
627 | | - return $changed; |
628 | | - } |
629 | | - |
630 | | - protected function newConfigIsReset() { |
631 | | - # For protection config, just ignore the fpc_select column |
632 | | - return ( $this->autoreview == '' ); |
633 | | - } |
634 | | - |
635 | | - // Checks if new config is different than the existing row |
636 | | - protected function configIsDifferent( $oldRow, $override, $autoreview, $dbExpiry ) { |
637 | | - if ( !$oldRow ) { |
638 | | - return true; // no previous config |
639 | | - } |
640 | | - # For protection config, just ignore the fpc_select column |
641 | | - return ( $oldRow->fpc_override != $override // ...override changed, or... |
642 | | - || $oldRow->fpc_level != $autoreview // ...autoreview level changed, or... |
643 | | - || $oldRow->fpc_expiry != $dbExpiry // ...expiry changed |
644 | | - ); |
645 | | - } |
646 | | -} |
\ No newline at end of file |
Index: trunk/extensions/FlaggedRevs/forms/PageStabilityForm.php |
— | — | @@ -0,0 +1,645 @@ |
| 2 | +<?php |
| 3 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 4 | + echo "FlaggedRevs extension\n"; |
| 5 | + exit( 1 ); |
| 6 | +} |
| 7 | +/** |
| 8 | + * Class containing stability settings form business logic |
| 9 | + * |
| 10 | + * Usage: (a) set ALL form params before doing anything else |
| 11 | + * (b) call ready() when all params are set |
| 12 | + * (c) check isAllowed() before calling submit() as needed |
| 13 | + */ |
| 14 | +abstract class PageStabilityForm |
| 15 | +{ |
| 16 | + /* Form parameters which can be user given */ |
| 17 | + protected $target = null; # Target page text |
| 18 | + protected $watchThis = null; # Watch checkbox |
| 19 | + protected $reviewThis = null; # Auto-review option... |
| 20 | + protected $reason = ''; # Custom/extra reason |
| 21 | + protected $reasonSelection = ''; # Reason dropdown key |
| 22 | + protected $expiry = ''; # Custom expiry |
| 23 | + protected $expirySelection = ''; # Expiry dropdown key |
| 24 | + protected $override = -1; # Default version |
| 25 | + protected $autoreview = ''; # Autoreview restrictions... |
| 26 | + |
| 27 | + protected $page = false; # Target page obj (of $target) |
| 28 | + protected $oldConfig = array(); # Old page config |
| 29 | + protected $oldExpiry = ''; # Old page config expiry (GMT) |
| 30 | + |
| 31 | + protected $inputLock = 0; # Disallow bad submissions |
| 32 | + |
| 33 | + public function getTarget() { |
| 34 | + return $this->target; |
| 35 | + } |
| 36 | + |
| 37 | + public function setTarget( $value ) { |
| 38 | + $this->trySet( $this->target, $value ); |
| 39 | + $this->page = Title::newFromURL( $this->target ); |
| 40 | + } |
| 41 | + |
| 42 | + public function getWatchThis() { |
| 43 | + return $this->watchThis; |
| 44 | + } |
| 45 | + |
| 46 | + public function setWatchThis( $value ) { |
| 47 | + $this->trySet( $this->watchThis, $value ); |
| 48 | + } |
| 49 | + |
| 50 | + public function getReason() { |
| 51 | + return $this->reason; |
| 52 | + } |
| 53 | + |
| 54 | + public function setReason( $value ) { |
| 55 | + $this->trySet( $this->reason, $value ); |
| 56 | + } |
| 57 | + |
| 58 | + public function getReasonSelection() { |
| 59 | + return $this->reasonSelection; |
| 60 | + } |
| 61 | + |
| 62 | + public function setReasonSelection( $value ) { |
| 63 | + $this->trySet( $this->reasonSelection, $value ); |
| 64 | + } |
| 65 | + |
| 66 | + public function getExpiry() { |
| 67 | + return $this->expiry; |
| 68 | + } |
| 69 | + |
| 70 | + public function setExpiry( $value ) { |
| 71 | + $this->trySet( $this->expiry, $value ); |
| 72 | + } |
| 73 | + |
| 74 | + public function getExpirySelection() { |
| 75 | + return $this->expirySelection; |
| 76 | + } |
| 77 | + |
| 78 | + public function setExpirySelection( $value ) { |
| 79 | + $this->trySet( $this->expirySelection, $value ); |
| 80 | + } |
| 81 | + |
| 82 | + public function getAutoreview() { |
| 83 | + return $this->autoreview; |
| 84 | + } |
| 85 | + |
| 86 | + public function setAutoreview( $value ) { |
| 87 | + $this->trySet( $this->autoreview, $value ); |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * Set a member field to a value if the fields are unlocked |
| 92 | + */ |
| 93 | + protected function trySet( &$field, $value ) { |
| 94 | + if ( $this->inputLock ) { |
| 95 | + throw new MWException( __CLASS__ . " fields cannot be set anymore.\n"); |
| 96 | + } else { |
| 97 | + $field = $value; // submission locked => still allowing input |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + /** |
| 102 | + * Signal that inputs are starting |
| 103 | + */ |
| 104 | + public function start() { |
| 105 | + $this->inputLock = 0; |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * Signal that inputs are done and load old config |
| 110 | + * @return mixed (true on success, error string on target failure) |
| 111 | + */ |
| 112 | + public function ready() { |
| 113 | + $this->inputLock = 1; |
| 114 | + $status = $this->checkTarget(); |
| 115 | + if ( $status !== true ) { |
| 116 | + return $status; // bad target |
| 117 | + } |
| 118 | + $this->loadOldConfig(); // current settings from DB |
| 119 | + return $status; |
| 120 | + } |
| 121 | + |
| 122 | + /* |
| 123 | + * Preload existing page settings (e.g. from GET request). |
| 124 | + * @return mixed (true on success, error string on failure) |
| 125 | + */ |
| 126 | + public function preloadSettings() { |
| 127 | + if ( !$this->inputLock ) { |
| 128 | + throw new MWException( __CLASS__ . " input fields not set yet.\n"); |
| 129 | + } |
| 130 | + $status = $this->checkTarget(); |
| 131 | + if ( $status !== true ) { |
| 132 | + return $status; // bad target |
| 133 | + } |
| 134 | + return $this->reallyPreloadSettings(); // load the params... |
| 135 | + } |
| 136 | + |
| 137 | + /* |
| 138 | + * @return mixed (true on success, error string on failure) |
| 139 | + */ |
| 140 | + protected function reallyPreloadSettings() { |
| 141 | + return true; |
| 142 | + } |
| 143 | + |
| 144 | + /* |
| 145 | + * Verify and clean up parameters (e.g. from POST request). |
| 146 | + * @return mixed (true on success, error string on failure) |
| 147 | + */ |
| 148 | + protected function checkSettings() { |
| 149 | + $status = $this->checkTarget(); |
| 150 | + if ( $status !== true ) { |
| 151 | + return $status; // bad target |
| 152 | + } |
| 153 | + $status = $this->reallyCheckSettings(); // check other params... |
| 154 | + return $status; |
| 155 | + } |
| 156 | + |
| 157 | + /* |
| 158 | + * @return mixed (true on success, error string on failure) |
| 159 | + */ |
| 160 | + protected function reallyCheckSettings() { |
| 161 | + return true; |
| 162 | + } |
| 163 | + |
| 164 | + /* |
| 165 | + * Check that the target page is valid |
| 166 | + * @return mixed (true on success, error string on failure) |
| 167 | + */ |
| 168 | + protected function checkTarget() { |
| 169 | + $this->page = Title::newFromURL( $this->target ); |
| 170 | + if ( is_null( $this->page ) ) { |
| 171 | + return 'stabilize_page_invalid'; |
| 172 | + } elseif ( !$this->page->exists() ) { |
| 173 | + return 'stabilize_page_notexists'; |
| 174 | + } elseif ( !FlaggedRevs::inReviewNamespace( $this->page ) ) { |
| 175 | + return 'stabilize_page_unreviewable'; |
| 176 | + } |
| 177 | + return true; |
| 178 | + } |
| 179 | + |
| 180 | + protected function loadOldConfig() { |
| 181 | + # Get the current page config and GMT expiry |
| 182 | + $this->oldConfig = FlaggedRevs::getPageVisibilitySettings( $this->page, FR_MASTER ); |
| 183 | + $this->oldExpiry = $this->oldConfig['expiry'] === 'infinity' |
| 184 | + ? 'infinite' |
| 185 | + : wfTimestamp( TS_RFC2822, $this->oldConfig['expiry'] ); |
| 186 | + } |
| 187 | + |
| 188 | + /* |
| 189 | + * Gets the target page Obj |
| 190 | + * @return mixed (Title or null) |
| 191 | + */ |
| 192 | + public function getPage() { |
| 193 | + if ( !$this->inputLock ) { |
| 194 | + throw new MWException( __CLASS__ . " input fields not set yet.\n"); |
| 195 | + } |
| 196 | + return $this->page; |
| 197 | + } |
| 198 | + |
| 199 | + /* |
| 200 | + * Gets the current config expiry in GMT (or 'infinite') |
| 201 | + * @return string |
| 202 | + */ |
| 203 | + public function getOldExpiryGMT() { |
| 204 | + if ( !$this->inputLock ) { |
| 205 | + throw new MWException( __CLASS__ . " input fields not set yet.\n"); |
| 206 | + } |
| 207 | + return $this->oldExpiry; |
| 208 | + } |
| 209 | + |
| 210 | + /* |
| 211 | + * Can the user change the settings for this page? |
| 212 | + * Note: if the current autoreview restriction is too high for this user |
| 213 | + * then this will return false. Useful for form selectors. |
| 214 | + * @return bool |
| 215 | + */ |
| 216 | + public function isAllowed() { |
| 217 | + # Users who cannot edit or review the page cannot set this |
| 218 | + return ( $this->page |
| 219 | + && $this->page->userCan( 'stablesettings' ) |
| 220 | + && $this->page->userCan( 'edit' ) |
| 221 | + && $this->page->userCan( 'review' ) |
| 222 | + ); |
| 223 | + } |
| 224 | + |
| 225 | + /** |
| 226 | + * Submit the form parameters for the page config to the DB. |
| 227 | + * Note: caller is responsible for permission checks. |
| 228 | + * |
| 229 | + * @return mixed (true on success, error string on failure) |
| 230 | + */ |
| 231 | + public function submit() { |
| 232 | + global $wgUser; |
| 233 | + if ( !$this->inputLock ) { |
| 234 | + throw new MWException( __CLASS__ . " input fields not set yet.\n"); |
| 235 | + } |
| 236 | + $status = $this->checkSettings(); |
| 237 | + if ( $status !== true ) { |
| 238 | + return $status; // cannot submit - broken params |
| 239 | + } |
| 240 | + # Are we are going back to site defaults? |
| 241 | + $reset = $this->newConfigIsReset(); |
| 242 | + # Parse and cleanup the expiry time given... |
| 243 | + if ( $reset || $this->expiry == 'infinite' || $this->expiry == 'indefinite' ) { |
| 244 | + $this->expiry = Block::infinity(); // normalize to 'infinity' |
| 245 | + } else { |
| 246 | + # Convert GNU-style date, on error returns -1 for PHP <5.1 and false for PHP >=5.1 |
| 247 | + $this->expiry = strtotime( $this->expiry ); |
| 248 | + if ( $this->expiry < 0 || $this->expiry === false ) { |
| 249 | + return 'stabilize_expiry_invalid'; |
| 250 | + } |
| 251 | + # Convert date to MW timestamp format |
| 252 | + $this->expiry = wfTimestamp( TS_MW, $this->expiry ); |
| 253 | + if ( $this->expiry < wfTimestampNow() ) { |
| 254 | + return 'stabilize_expiry_old'; |
| 255 | + } |
| 256 | + } |
| 257 | + # Update the DB row with the new config... |
| 258 | + $changed = $this->updateConfigRow( $reset ); |
| 259 | + # Log if this actually changed anything... |
| 260 | + if ( $changed ) { |
| 261 | + # Update logs and make a null edit |
| 262 | + $nullRev = $this->updateLogsAndHistory( $reset ); |
| 263 | + # Null edit may have been autoreviewed already |
| 264 | + $frev = FlaggedRevision::newFromTitle( $this->page, $nullRev->getId(), FR_MASTER ); |
| 265 | + # We may need to invalidate the page links after changing the stable version. |
| 266 | + # Only do so if not already done, such as by an auto-review of the null edit. |
| 267 | + $invalidate = !$frev; |
| 268 | + # Check if this null edit is to be reviewed... |
| 269 | + if ( !$frev && $this->reviewThis ) { |
| 270 | + $flags = null; |
| 271 | + $article = new Article( $this->page ); |
| 272 | + # Review this revision of the page... |
| 273 | + $ok = FlaggedRevs::autoReviewEdit( |
| 274 | + $article, $wgUser, $nullRev->getText(), $nullRev, $flags, true ); |
| 275 | + if( $ok ) { |
| 276 | + FlaggedRevs::markRevisionPatrolled( $nullRev ); // reviewed -> patrolled |
| 277 | + $invalidate = false; // links invalidated (with auto-reviewed) |
| 278 | + } |
| 279 | + } |
| 280 | + # Update the links tables as the stable version may now be the default page... |
| 281 | + if ( $invalidate ) { |
| 282 | + FlaggedRevs::titleLinksUpdate( $this->page ); |
| 283 | + } |
| 284 | + } |
| 285 | + # Apply watchlist checkbox value (may be NULL) |
| 286 | + $this->updateWatchlist(); |
| 287 | + # Take this opportunity to purge out expired configurations |
| 288 | + FlaggedRevs::purgeExpiredConfigurations(); |
| 289 | + return true; |
| 290 | + } |
| 291 | + |
| 292 | + /* |
| 293 | + * Do history & log updates: |
| 294 | + * (a) Add a new stability log entry |
| 295 | + * (b) Add a null edit like the log entry |
| 296 | + * @return Revision |
| 297 | + */ |
| 298 | + protected function updateLogsAndHistory( $reset ) { |
| 299 | + global $wgContLang; |
| 300 | + $article = new Article( $this->page ); |
| 301 | + $latest = $this->page->getLatestRevID( GAID_FOR_UPDATE ); |
| 302 | + # Config may have changed to allow stable versions. |
| 303 | + # Refresh tracking to account for any hidden reviewed versions... |
| 304 | + $frev = FlaggedRevision::newFromStable( $this->page, FR_MASTER ); |
| 305 | + if ( $frev ) { |
| 306 | + FlaggedRevs::updateStableVersion( $article, $frev->getRevision(), $latest ); |
| 307 | + } else { |
| 308 | + FlaggedRevs::clearTrackingRows( $article->getId() ); |
| 309 | + } |
| 310 | + # Insert stability log entry... |
| 311 | + $log = new LogPage( 'stable' ); |
| 312 | + if ( $reset ) { |
| 313 | + $log->addEntry( 'reset', $this->page, $this->reason ); |
| 314 | + $type = "stable-logentry-reset"; |
| 315 | + $settings = ''; // no level, expiry info |
| 316 | + } else { |
| 317 | + $params = $this->getLogParams(); |
| 318 | + $log->addEntry( 'config', $this->page, $this->reason, |
| 319 | + FlaggedRevsLogs::collapseParams( $params ) ); |
| 320 | + $type = "stable-logentry-config"; |
| 321 | + // Settings message in text form (e.g. [x=a,y=b,z]) |
| 322 | + $settings = FlaggedRevsLogs::stabilitySettings( $params, true /*content*/ ); |
| 323 | + } |
| 324 | + # Build null-edit comment...<action: reason [settings] (expiry)> |
| 325 | + $comment = $wgContLang->ucfirst( |
| 326 | + wfMsgForContent( $type, $this->page->getPrefixedText() ) ); // action |
| 327 | + if ( $this->reason != '' ) { |
| 328 | + $comment .= wfMsgForContent( 'colon-separator' ) . $this->reason; // add reason |
| 329 | + } |
| 330 | + if ( $settings != '' ) { |
| 331 | + $comment .= " {$settings}"; // add settings |
| 332 | + } |
| 333 | + # Insert a null revision... |
| 334 | + $dbw = wfGetDB( DB_MASTER ); |
| 335 | + $nullRev = Revision::newNullRevision( $dbw, $article->getId(), $comment, true ); |
| 336 | + $nullRevId = $nullRev->insertOn( $dbw ); |
| 337 | + # Update page record and touch page |
| 338 | + $article->updateRevisionOn( $dbw, $nullRev, $latest ); |
| 339 | + wfRunHooks( 'NewRevisionFromEditComplete', array( $article, $nullRev, $latest ) ); |
| 340 | + # Return null Revision object for autoreview check |
| 341 | + return $nullRev; |
| 342 | + } |
| 343 | + |
| 344 | + /* |
| 345 | + * Checks if new config is the same as the site default |
| 346 | + * @return bool |
| 347 | + */ |
| 348 | + protected function newConfigIsReset() { |
| 349 | + return false; |
| 350 | + } |
| 351 | + |
| 352 | + /* |
| 353 | + * Get assoc. array of log params |
| 354 | + * @return array |
| 355 | + */ |
| 356 | + protected function getLogParams() { |
| 357 | + return array(); |
| 358 | + } |
| 359 | + |
| 360 | + /* |
| 361 | + * (a) Watch page if $watchThis is true |
| 362 | + * (b) Unwatch if $watchThis is false |
| 363 | + */ |
| 364 | + protected function updateWatchlist() { |
| 365 | + global $wgUser; |
| 366 | + # Apply watchlist checkbox value (may be NULL) |
| 367 | + if ( $this->watchThis === true ) { |
| 368 | + $wgUser->addWatch( $this->page ); |
| 369 | + } elseif ( $this->watchThis === false ) { |
| 370 | + $wgUser->removeWatch( $this->page ); |
| 371 | + } |
| 372 | + } |
| 373 | + |
| 374 | + protected function loadExpiry() { |
| 375 | + # Custom expiry takes precedence |
| 376 | + if ( $this->expiry == '' ) { |
| 377 | + $this->expiry = $this->expirySelection; |
| 378 | + if ( $this->expiry == 'existing' ) { |
| 379 | + $this->expiry = $this->oldExpiry; |
| 380 | + } |
| 381 | + } |
| 382 | + } |
| 383 | + |
| 384 | + protected function loadReason() { |
| 385 | + # Custom reason takes precedence |
| 386 | + if ( $this->reasonSelection != 'other' ) { |
| 387 | + $comment = $this->reasonSelection; // start with dropdown reason |
| 388 | + if ( $this->reason != '' ) { |
| 389 | + # Append custom reason |
| 390 | + $comment .= wfMsgForContent( 'colon-separator' ) . $this->reason; |
| 391 | + } |
| 392 | + } else { |
| 393 | + $comment = $this->reason; // just use custom reason |
| 394 | + } |
| 395 | + $this->reason = $comment; |
| 396 | + } |
| 397 | + |
| 398 | + // Same JS used for expiry for either $wgFlaggedRevsProtection case |
| 399 | + public static function addProtectionJS() { |
| 400 | + global $wgOut; |
| 401 | + $wgOut->addScript( |
| 402 | + "<script type=\"text/javascript\"> |
| 403 | + function onFRChangeExpiryDropdown() { |
| 404 | + document.getElementById('mwStabilizeExpiryOther').value = ''; |
| 405 | + } |
| 406 | + function onFRChangeExpiryField() { |
| 407 | + document.getElementById('mwStabilizeExpirySelection').value = 'othertime'; |
| 408 | + } |
| 409 | + </script>" |
| 410 | + ); |
| 411 | + } |
| 412 | +} |
| 413 | + |
| 414 | +// Assumes $wgFlaggedRevsProtection is off |
| 415 | +class PageStabilityGeneralForm extends PageStabilityForm { |
| 416 | + /* Form parameters which can be user given */ |
| 417 | + public $select = -1; # Precedence |
| 418 | + |
| 419 | + public function getReviewThis() { |
| 420 | + return $this->reviewThis; |
| 421 | + } |
| 422 | + |
| 423 | + public function setReviewThis( $value ) { |
| 424 | + $this->trySet( $this->reviewThis, $value ); |
| 425 | + } |
| 426 | + |
| 427 | + public function getPrecedence() { |
| 428 | + return $this->select; |
| 429 | + } |
| 430 | + |
| 431 | + public function setPrecedence( $value ) { |
| 432 | + $this->trySet( $this->select, $value ); |
| 433 | + } |
| 434 | + |
| 435 | + public function getOverride() { |
| 436 | + return $this->override; |
| 437 | + } |
| 438 | + |
| 439 | + public function setOverride( $value ) { |
| 440 | + $this->trySet( $this->override, $value ); |
| 441 | + } |
| 442 | + |
| 443 | + protected function reallyPreloadSettings() { |
| 444 | + $this->select = $this->oldConfig['select']; |
| 445 | + $this->override = $this->oldConfig['override']; |
| 446 | + $this->autoreview = $this->oldConfig['autoreview']; |
| 447 | + $this->expiry = $this->oldExpiry; |
| 448 | + $this->expirySelection = 'existing'; |
| 449 | + $this->watchThis = $this->page->userIsWatching(); |
| 450 | + return true; |
| 451 | + } |
| 452 | + |
| 453 | + protected function reallyCheckSettings() { |
| 454 | + $this->loadReason(); |
| 455 | + $this->loadExpiry(); |
| 456 | + $this->override = $this->override ? 1 : 0; // default version settings is 0 or 1 |
| 457 | + if ( !FlaggedRevs::isValidPrecedence( $this->select ) ) { |
| 458 | + return 'stabilize_invalid_precedence'; // invalid precedence value |
| 459 | + } |
| 460 | + // Check autoreview restriction setting |
| 461 | + if ( !FlaggedRevs::userCanSetAutoreviewLevel( $this->autoreview ) ) { |
| 462 | + return 'stabilize_invalid_autoreview'; // invalid value |
| 463 | + } |
| 464 | + return true; |
| 465 | + } |
| 466 | + |
| 467 | + protected function getLogParams() { |
| 468 | + return array( |
| 469 | + 'override' => $this->override, |
| 470 | + 'autoreview' => $this->autoreview, |
| 471 | + 'expiry' => $this->expiry, // TS_MW/infinity |
| 472 | + 'precedence' => $this->select |
| 473 | + ); |
| 474 | + } |
| 475 | + |
| 476 | + // Return current config array |
| 477 | + public function getOldConfig() { |
| 478 | + if ( !$this->inputLock ) { |
| 479 | + throw new MWException( __CLASS__ . " input fields not set yet.\n"); |
| 480 | + } |
| 481 | + return $this->oldConfig; |
| 482 | + } |
| 483 | + |
| 484 | + // returns whether row changed |
| 485 | + protected function updateConfigRow( $reset ) { |
| 486 | + $changed = false; |
| 487 | + $dbw = wfGetDB( DB_MASTER ); |
| 488 | + # If setting to site default values and there is a row then erase it |
| 489 | + if ( $reset ) { |
| 490 | + $dbw->delete( 'flaggedpage_config', |
| 491 | + array( 'fpc_page_id' => $this->page->getArticleID() ), |
| 492 | + __METHOD__ |
| 493 | + ); |
| 494 | + $changed = ( $dbw->affectedRows() != 0 ); // did this do anything? |
| 495 | + # Otherwise, add/replace row if we are not just setting it to the site default |
| 496 | + } elseif ( !$reset ) { |
| 497 | + $dbExpiry = Block::encodeExpiry( $this->expiry, $dbw ); |
| 498 | + # Get current config... |
| 499 | + $oldRow = $dbw->selectRow( 'flaggedpage_config', |
| 500 | + array( 'fpc_select', 'fpc_override', 'fpc_level', 'fpc_expiry' ), |
| 501 | + array( 'fpc_page_id' => $this->page->getArticleID() ), |
| 502 | + __METHOD__, |
| 503 | + 'FOR UPDATE' |
| 504 | + ); |
| 505 | + # Check if this is not the same config as the existing row (if any) |
| 506 | + $changed = self::configIsDifferent( $oldRow, |
| 507 | + $this->select, $this->override, $this->autoreview, $dbExpiry ); |
| 508 | + # If the new config is different, replace the old row... |
| 509 | + if ( $changed ) { |
| 510 | + $dbw->replace( 'flaggedpage_config', |
| 511 | + array( 'PRIMARY' ), |
| 512 | + array( |
| 513 | + 'fpc_page_id' => $this->page->getArticleID(), |
| 514 | + 'fpc_select' => (int)$this->select, |
| 515 | + 'fpc_override' => (int)$this->override, |
| 516 | + 'fpc_level' => $this->autoreview, |
| 517 | + 'fpc_expiry' => $dbExpiry |
| 518 | + ), |
| 519 | + __METHOD__ |
| 520 | + ); |
| 521 | + } |
| 522 | + } |
| 523 | + return $changed; |
| 524 | + } |
| 525 | + |
| 526 | + protected function newConfigIsReset() { |
| 527 | + return ( $this->select == FlaggedRevs::getPrecedence() |
| 528 | + && $this->override == FlaggedRevs::isStableShownByDefault() |
| 529 | + && $this->autoreview == '' ); |
| 530 | + } |
| 531 | + |
| 532 | + // Checks if new config is different than the existing row |
| 533 | + protected function configIsDifferent( $oldRow, $select, $override, $autoreview, $dbExpiry ) { |
| 534 | + if( !$oldRow ) { |
| 535 | + return true; // no previous config |
| 536 | + } |
| 537 | + return ( $oldRow->fpc_select != $select // ...precedence changed, or... |
| 538 | + || $oldRow->fpc_override != $override // ...override changed, or... |
| 539 | + || $oldRow->fpc_level != $autoreview // ...autoreview level changed, or... |
| 540 | + || $oldRow->fpc_expiry != $dbExpiry // ...expiry changed |
| 541 | + ); |
| 542 | + } |
| 543 | +} |
| 544 | + |
| 545 | +// Assumes $wgFlaggedRevsProtection is on |
| 546 | +class PageStabilityProtectForm extends PageStabilityForm { |
| 547 | + protected function reallyPreloadSettings() { |
| 548 | + $this->autoreview = $this->oldConfig['autoreview']; // protect level |
| 549 | + $this->expiry = $this->oldExpiry; |
| 550 | + $this->expirySelection = 'existing'; |
| 551 | + $this->watchThis = $this->page->userIsWatching(); |
| 552 | + return true; |
| 553 | + } |
| 554 | + |
| 555 | + protected function reallyCheckSettings() { |
| 556 | + $this->loadReason(); |
| 557 | + $this->loadExpiry(); |
| 558 | + # Autoreview only when protecting currently unprotected pages |
| 559 | + $this->reviewThis = ( FlaggedRevs::getProtectionLevel( $this->oldConfig ) == 'none' ); |
| 560 | + # Check autoreview restriction setting |
| 561 | + if ( !FlaggedRevs::userCanSetAutoreviewLevel( $this->autoreview ) ) { |
| 562 | + return 'stabilize_invalid_level'; // invalid value |
| 563 | + } |
| 564 | + # Autoreview restriction => use stable |
| 565 | + # No autoreview restriction => site default |
| 566 | + $this->override = ( $this->autoreview != '' ) |
| 567 | + ? 1 // edits require review before being published |
| 568 | + : (int)FlaggedRevs::isStableShownByDefault(); // site default |
| 569 | + # Check that settings are a valid protection level... |
| 570 | + $newConfig = array( |
| 571 | + 'override' => $this->override, |
| 572 | + 'autoreview' => $this->autoreview |
| 573 | + ); |
| 574 | + if ( FlaggedRevs::getProtectionLevel( $newConfig ) == 'invalid' ) { |
| 575 | + return 'stabilize_invalid_level'; // double-check configuration |
| 576 | + } |
| 577 | + return true; |
| 578 | + } |
| 579 | + |
| 580 | + // Doesn't include 'precedence'; checked in FlaggedRevsLogs |
| 581 | + protected function getLogParams() { |
| 582 | + return array( |
| 583 | + 'override' => $this->override, // in case of site changes |
| 584 | + 'autoreview' => $this->autoreview, |
| 585 | + 'expiry' => $this->expiry // TS_MW/infinity |
| 586 | + ); |
| 587 | + } |
| 588 | + |
| 589 | + protected function updateConfigRow( $reset ) { |
| 590 | + $changed = false; |
| 591 | + $dbw = wfGetDB( DB_MASTER ); |
| 592 | + # If setting to site default values and there is a row then erase it |
| 593 | + if ( $reset ) { |
| 594 | + $dbw->delete( 'flaggedpage_config', |
| 595 | + array( 'fpc_page_id' => $this->page->getArticleID() ), |
| 596 | + __METHOD__ |
| 597 | + ); |
| 598 | + $changed = ( $dbw->affectedRows() != 0 ); // did this do anything? |
| 599 | + # Otherwise, add/replace row if we are not just setting it to the site default |
| 600 | + } elseif ( !$reset ) { |
| 601 | + $dbExpiry = Block::encodeExpiry( $this->expiry, $dbw ); |
| 602 | + # Get current config... |
| 603 | + $oldRow = $dbw->selectRow( 'flaggedpage_config', |
| 604 | + array( 'fpc_override', 'fpc_level', 'fpc_expiry' ), |
| 605 | + array( 'fpc_page_id' => $this->page->getArticleID() ), |
| 606 | + __METHOD__, |
| 607 | + 'FOR UPDATE' |
| 608 | + ); |
| 609 | + # Check if this is not the same config as the existing row (if any) |
| 610 | + $changed = self::configIsDifferent( $oldRow, |
| 611 | + $this->override, $this->autoreview, $dbExpiry ); |
| 612 | + # If the new config is different, replace the old row... |
| 613 | + if ( $changed ) { |
| 614 | + $dbw->replace( 'flaggedpage_config', |
| 615 | + array( 'PRIMARY' ), |
| 616 | + array( |
| 617 | + 'fpc_page_id' => $this->page->getArticleID(), |
| 618 | + 'fpc_select' => -1, // ignored |
| 619 | + 'fpc_override' => (int)$this->override, |
| 620 | + 'fpc_level' => $this->autoreview, |
| 621 | + 'fpc_expiry' => $dbExpiry |
| 622 | + ), |
| 623 | + __METHOD__ |
| 624 | + ); |
| 625 | + } |
| 626 | + } |
| 627 | + return $changed; |
| 628 | + } |
| 629 | + |
| 630 | + protected function newConfigIsReset() { |
| 631 | + # For protection config, just ignore the fpc_select column |
| 632 | + return ( $this->autoreview == '' ); |
| 633 | + } |
| 634 | + |
| 635 | + // Checks if new config is different than the existing row |
| 636 | + protected function configIsDifferent( $oldRow, $override, $autoreview, $dbExpiry ) { |
| 637 | + if ( !$oldRow ) { |
| 638 | + return true; // no previous config |
| 639 | + } |
| 640 | + # For protection config, just ignore the fpc_select column |
| 641 | + return ( $oldRow->fpc_override != $override // ...override changed, or... |
| 642 | + || $oldRow->fpc_level != $autoreview // ...autoreview level changed, or... |
| 643 | + || $oldRow->fpc_expiry != $dbExpiry // ...expiry changed |
| 644 | + ); |
| 645 | + } |
| 646 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/FlaggedRevs/forms/PageStabilityForm.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 647 | + native |
Index: trunk/extensions/FlaggedRevs/specialpages/Stabilization_body.php |
— | — | @@ -36,7 +36,7 @@ |
37 | 37 | $this->setHeaders(); |
38 | 38 | $this->sk = $wgUser->getSkin(); |
39 | 39 | |
40 | | - $this->form = new PageStabilityForm(); |
| 40 | + $this->form = new PageStabilityGeneralForm(); |
41 | 41 | $form = $this->form; // convenience |
42 | 42 | # Target page |
43 | 43 | $form->setTarget( $wgRequest->getVal( 'page', $par ) ); |
Index: trunk/extensions/FlaggedRevs/api/ApiStabilize.php |
— | — | @@ -49,7 +49,7 @@ |
50 | 50 | // TODO: factory function? |
51 | 51 | $form = FlaggedRevs::useProtectionLevels() |
52 | 52 | ? new PageStabilityProtectForm() |
53 | | - : new PageStabilityForm(); |
| 53 | + : new PageStabilityGeneralForm(); |
54 | 54 | |
55 | 55 | $form->setTarget( $title ); # Our target page |
56 | 56 | $form->setWatchThis( $params['watch'] ); # Watch this page |