Index: trunk/extensions/FlaggedRevs/FlaggedArticle.php |
— | — | @@ -169,7 +169,7 @@ |
170 | 170 | * @return bool |
171 | 171 | */ |
172 | 172 | public function stableVersionIsSynced() { |
173 | | - global $wgUser, $wgMemc, $wgEnableParserCache, $wgParserCacheExpireTime; |
| 173 | + global $wgMemc, $wgEnableParserCache, $wgParserCacheExpireTime; |
174 | 174 | $srev = $this->getStableRev(); |
175 | 175 | if ( !$srev ) { |
176 | 176 | return true; |
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php |
— | — | @@ -138,17 +138,6 @@ |
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
142 | | - * Should this be using a simple icon-based UI? |
143 | | - * Check the user's preferences first, using the site settings as the default. |
144 | | - * @TODO: dependency inject the User? |
145 | | - * @returns bool |
146 | | - */ |
147 | | - public static function useSimpleUI() { |
148 | | - global $wgUser, $wgSimpleFlaggedRevsUI; |
149 | | - return $wgUser->getOption( 'flaggedrevssimpleui', intval( $wgSimpleFlaggedRevsUI ) ); |
150 | | - } |
151 | | - |
152 | | - /** |
153 | 142 | * Allow auto-review edits directly to the stable version by reviewers? |
154 | 143 | * (1 to allow auto-sighting; 2 for auto-quality; 3 for auto-pristine) |
155 | 144 | * @returns bool |
— | — | @@ -210,26 +199,8 @@ |
211 | 200 | public static function stableOnlyIfConfigured() { |
212 | 201 | return self::forDefaultVersionOnly() && !self::isStableShownByDefault(); |
213 | 202 | } |
214 | | - |
| 203 | + |
215 | 204 | /** |
216 | | - * Should this user ignore the site and page default version settings? |
217 | | - * @TODO: dependency inject the User? |
218 | | - * @returns bool |
219 | | - */ |
220 | | - public static function ignoreDefaultVersion() { |
221 | | - global $wgFlaggedRevsExceptions, $wgUser; |
222 | | - # Viewer sees current by default (editors, insiders, ect...) ? |
223 | | - foreach ( $wgFlaggedRevsExceptions as $group ) { |
224 | | - if ( $group == 'user' ) { |
225 | | - return ( !$wgUser->isAnon() ); |
226 | | - } elseif ( in_array( $group, $wgUser->getGroups() ) ) { |
227 | | - return true; |
228 | | - } |
229 | | - } |
230 | | - return false; |
231 | | - } |
232 | | - |
233 | | - /** |
234 | 205 | * Return the include handling configuration |
235 | 206 | * @returns int |
236 | 207 | */ |
— | — | @@ -257,17 +228,6 @@ |
258 | 229 | } |
259 | 230 | |
260 | 231 | /** |
261 | | - * Get the appropriate PageStabilityForm depending on whether protection |
262 | | - * levels are being used |
263 | | - * @return PageStabilityForm |
264 | | - */ |
265 | | - public static function getPageStabilityForm() { |
266 | | - return FlaggedRevs::useProtectionLevels() ? |
267 | | - new PageStabilityProtectForm() : |
268 | | - new PageStabilityGeneralForm(); |
269 | | - } |
270 | | - |
271 | | - /** |
272 | 232 | * Get the autoreview restriction levels available |
273 | 233 | * @returns array |
274 | 234 | */ |
— | — | @@ -410,17 +370,16 @@ |
411 | 371 | |
412 | 372 | /** |
413 | 373 | * Returns true if a user can set $tag to $value. |
| 374 | + * @param User $user |
414 | 375 | * @param string $tag |
415 | 376 | * @param int $value |
416 | 377 | * @returns bool |
417 | | - * @TODO: dependency inject the User? |
418 | 378 | */ |
419 | | - public static function userCanSetTag( $tag, $value ) { |
420 | | - global $wgUser; |
| 379 | + public static function userCanSetTag( $user, $tag, $value ) { |
421 | 380 | # Sanity check tag and value |
422 | 381 | $levels = self::getTagLevels( $tag ); |
423 | 382 | $highest = count( $levels ) - 1; |
424 | | - if( !$levels || $value < 0 || $value > $highest ) { |
| 383 | + if ( !$levels || $value < 0 || $value > $highest ) { |
425 | 384 | return false; // flag range is invalid |
426 | 385 | } |
427 | 386 | $restrictions = self::getTagRestrictions(); |
— | — | @@ -429,13 +388,13 @@ |
430 | 389 | return true; |
431 | 390 | } |
432 | 391 | # Validators always have full access |
433 | | - if ( $wgUser->isAllowed( 'validate' ) ) { |
| 392 | + if ( $user->isAllowed( 'validate' ) ) { |
434 | 393 | return true; |
435 | 394 | } |
436 | 395 | # Check if this user has any right that lets him/her set |
437 | 396 | # up to this particular value |
438 | 397 | foreach ( $restrictions[$tag] as $right => $level ) { |
439 | | - if ( $value <= $level && $level > 0 && $wgUser->isAllowed( $right ) ) { |
| 398 | + if ( $value <= $level && $level > 0 && $user->isAllowed( $right ) ) { |
440 | 399 | return true; |
441 | 400 | } |
442 | 401 | } |
— | — | @@ -443,28 +402,26 @@ |
444 | 403 | } |
445 | 404 | |
446 | 405 | /** |
447 | | - * Returns true if a user can set $flags. |
448 | | - * This checks if the user has the right to review |
449 | | - * to the given levels for each tag. |
| 406 | + * Returns true if a user can set $flags for a revision via review. |
| 407 | + * Requires the same for $oldflags if given. |
| 408 | + * @param User $user |
450 | 409 | * @param array $flags, suggested flags |
451 | 410 | * @param array $oldflags, pre-existing flags |
452 | 411 | * @returns bool |
453 | | - * @TODO: dependency inject the User? |
454 | 412 | */ |
455 | | - public static function userCanSetFlags( $flags, $oldflags = array() ) { |
456 | | - global $wgUser; |
457 | | - if ( !$wgUser->isAllowed( 'review' ) ) { |
| 413 | + public static function userCanSetFlags( $user, array $flags, $oldflags = array() ) { |
| 414 | + if ( !$user->isAllowed( 'review' ) ) { |
458 | 415 | return false; // User is not able to review pages |
459 | 416 | } |
460 | 417 | # Check if all of the required site flags have a valid value |
461 | | - # that the user is allowed to set. |
| 418 | + # that the user is allowed to set... |
462 | 419 | foreach ( self::getDimensions() as $qal => $levels ) { |
463 | 420 | $level = isset( $flags[$qal] ) ? $flags[$qal] : 0; |
464 | 421 | $highest = count( $levels ) - 1; // highest valid level |
465 | | - if ( !self::userCanSetTag( $qal, $level ) ) { |
| 422 | + if ( !self::userCanSetTag( $user, $qal, $level ) ) { |
466 | 423 | return false; // user cannot set proposed flag |
467 | 424 | } elseif ( isset( $oldflags[$qal] ) |
468 | | - && !self::userCanSetTag( $qal, $oldflags[$qal] ) ) |
| 425 | + && !self::userCanSetTag( $user, $qal, $oldflags[$qal] ) ) |
469 | 426 | { |
470 | 427 | return false; // user cannot change old flag |
471 | 428 | } |
— | — | @@ -474,12 +431,11 @@ |
475 | 432 | |
476 | 433 | /** |
477 | 434 | * Check if a user can set the autoreview restiction level to $right |
| 435 | + * @param User $user |
478 | 436 | * @param string $right the level |
479 | 437 | * @returns bool |
480 | | - * @TODO: dependency inject the User? |
481 | 438 | */ |
482 | | - public static function userCanSetAutoreviewLevel( $right ) { |
483 | | - global $wgUser; |
| 439 | + public static function userCanSetAutoreviewLevel( $user, $right ) { |
484 | 440 | if ( $right == '' ) { |
485 | 441 | return true; // no restrictions (none) |
486 | 442 | } |
— | — | @@ -489,10 +445,10 @@ |
490 | 446 | # Don't let them choose levels above their own rights |
491 | 447 | if ( $right == 'sysop' ) { |
492 | 448 | // special case, rewrite sysop to protect and editprotected |
493 | | - if ( !$wgUser->isAllowed( 'protect' ) && !$wgUser->isAllowed( 'editprotected' ) ) { |
| 449 | + if ( !$user->isAllowed( 'protect' ) && !$user->isAllowed( 'editprotected' ) ) { |
494 | 450 | return false; |
495 | 451 | } |
496 | | - } else if ( !$wgUser->isAllowed( $right ) ) { |
| 452 | + } elseif ( !$user->isAllowed( $right ) ) { |
497 | 453 | return false; |
498 | 454 | } |
499 | 455 | return true; |
— | — | @@ -1171,7 +1127,7 @@ |
1172 | 1128 | array( 'fpc_page_id', 'fpc_select' ), |
1173 | 1129 | array( 'fpc_expiry < ' . $encCutoff ), |
1174 | 1130 | __METHOD__ |
1175 | | - // array( 'LOCK IN SHARE MODE' ) |
| 1131 | + // array( 'FOR UPDATE' ) |
1176 | 1132 | ); |
1177 | 1133 | while ( $row = $dbw->fetchObject( $ret ) ) { |
1178 | 1134 | // If FlaggedRevs got "turned off" for this page (due to not |
— | — | @@ -1318,11 +1274,11 @@ |
1319 | 1275 | /** |
1320 | 1276 | * Get minimum tags that are closest to $oldFlags |
1321 | 1277 | * given the site, page, and user rights limitations. |
| 1278 | + * @param User $user |
1322 | 1279 | * @param array $oldFlags previous stable rev flags |
1323 | | - * @TODO: dependency inject the User? |
1324 | 1280 | * @return mixed array or null |
1325 | 1281 | */ |
1326 | | - public static function getAutoReviewTags( array $oldFlags ) { |
| 1282 | + public static function getAutoReviewTags( $user, array $oldFlags ) { |
1327 | 1283 | if ( !self::autoReviewEdits() ) { |
1328 | 1284 | return null; // shouldn't happen |
1329 | 1285 | } |
— | — | @@ -1332,7 +1288,7 @@ |
1333 | 1289 | $val = isset( $oldFlags[$tag] ) ? $oldFlags[$tag] : 1; |
1334 | 1290 | $val = min( $val, self::maxAutoReviewLevel( $tag ) ); |
1335 | 1291 | # Dial down the level to one the user has permission to set |
1336 | | - while ( !self::userCanSetTag( $tag, $val ) ) { |
| 1292 | + while ( !self::userCanSetTag( $user, $tag, $val ) ) { |
1337 | 1293 | $val--; |
1338 | 1294 | if ( $val <= 0 ) { |
1339 | 1295 | return null; // all tags vals must be > 0 |
— | — | @@ -1556,7 +1512,7 @@ |
1557 | 1513 | if ( $user->isAllowed( 'bot' ) ) { |
1558 | 1514 | $flags = $oldSv->getTags(); // no change for bot edits |
1559 | 1515 | } else { |
1560 | | - $flags = self::getAutoReviewTags( $oldSv->getTags() ); // account for perms |
| 1516 | + $flags = self::getAutoReviewTags( $user, $oldSv->getTags() ); // account for perms |
1561 | 1517 | } |
1562 | 1518 | } else { // new page? |
1563 | 1519 | $flags = self::quickTags( FR_SIGHTED ); // use minimal level |
Index: trunk/extensions/FlaggedRevs/forms/RevisionReviewForm.php |
— | — | @@ -31,11 +31,12 @@ |
32 | 32 | protected $oflags = array(); |
33 | 33 | protected $inputLock = 0; # Disallow bad submissions |
34 | 34 | |
| 35 | + protected $user = null; |
35 | 36 | protected $skin = null; |
36 | 37 | |
37 | | - public function __construct() { |
38 | | - global $wgUser; |
39 | | - $this->skin = $wgUser->getSkin(); |
| 38 | + public function __construct( $user ) { |
| 39 | + $this->user = $user; |
| 40 | + $this->skin = $user->getSkin(); |
40 | 41 | foreach ( FlaggedRevs::getTags() as $tag ) { |
41 | 42 | $this->dims[$tag] = 0; |
42 | 43 | } |
— | — | @@ -118,8 +119,7 @@ |
119 | 120 | } |
120 | 121 | |
121 | 122 | public function setNotes( $value ) { |
122 | | - global $wgUser; |
123 | | - if ( !FlaggedRevs::allowComments() || !$wgUser->isAllowed( 'validate' ) ) { |
| 123 | + if ( !FlaggedRevs::allowComments() || !$this->user->isAllowed( 'validate' ) ) { |
124 | 124 | $value = ''; |
125 | 125 | } |
126 | 126 | $this->trySet( $this->notes, $value ); |
— | — | @@ -227,7 +227,7 @@ |
228 | 228 | } |
229 | 229 | # Check permissions and validate |
230 | 230 | # FIXME: invalid vs denied |
231 | | - if ( !FlaggedRevs::userCanSetFlags( $this->dims, $this->oflags ) ) { |
| 231 | + if ( !FlaggedRevs::userCanSetFlags( $this->user, $this->dims, $this->oflags ) ) { |
232 | 232 | return 'review_denied'; |
233 | 233 | } |
234 | 234 | return true; |
— | — | @@ -277,7 +277,6 @@ |
278 | 278 | * @return mixed (true on success, error string on failure) |
279 | 279 | */ |
280 | 280 | public function submit() { |
281 | | - global $wgUser; |
282 | 281 | if ( !$this->inputLock ) { |
283 | 282 | throw new MWException( __CLASS__ . " input fields not set yet.\n"); |
284 | 283 | } |
— | — | @@ -308,8 +307,8 @@ |
309 | 308 | } |
310 | 309 | # Watch page if set to do so |
311 | 310 | if ( $status === true ) { |
312 | | - if ( $wgUser->getOption( 'flaggedrevswatch' ) && !$this->page->userIsWatching() ) { |
313 | | - $wgUser->addWatch( $this->page ); |
| 311 | + if ( $this->user->getOption( 'flaggedrevswatch' ) && !$this->page->userIsWatching() ) { |
| 312 | + $this->user->addWatch( $this->page ); |
314 | 313 | } |
315 | 314 | } |
316 | 315 | return $status; |
— | — | @@ -321,7 +320,7 @@ |
322 | 321 | * @returns true on success, array of errors on failure |
323 | 322 | */ |
324 | 323 | private function approveRevision( $rev ) { |
325 | | - global $wgUser, $wgMemc, $wgParser, $wgEnableParserCache; |
| 324 | + global $wgMemc, $wgParser, $wgEnableParserCache; |
326 | 325 | wfProfileIn( __METHOD__ ); |
327 | 326 | |
328 | 327 | $dbw = wfGetDB( DB_MASTER ); |
— | — | @@ -468,7 +467,7 @@ |
469 | 468 | $flaggedRevision = new FlaggedRevision( array( |
470 | 469 | 'fr_rev_id' => $rev->getId(), |
471 | 470 | 'fr_page_id' => $rev->getPage(), |
472 | | - 'fr_user' => $wgUser->getId(), |
| 471 | + 'fr_user' => $this->user->getId(), |
473 | 472 | 'fr_timestamp' => wfTimestampNow(), |
474 | 473 | 'fr_comment' => $this->notes, |
475 | 474 | 'fr_quality' => $quality, |
— | — | @@ -491,7 +490,7 @@ |
492 | 491 | # Update the links tables as the stable version may now be the default page. |
493 | 492 | # Try using the parser cache first since we didn't actually edit the current version. |
494 | 493 | $parserCache = ParserCache::singleton(); |
495 | | - $poutput = $parserCache->get( $article, $wgUser ); |
| 494 | + $poutput = $parserCache->get( $article, $this->user ); |
496 | 495 | if ( !$poutput |
497 | 496 | || !isset( $poutput->fr_newestTemplateID ) |
498 | 497 | || !isset( $poutput->fr_newestImageTime ) ) |
— | — | @@ -512,7 +511,7 @@ |
513 | 512 | # Update stable cache with the revision we reviewed. |
514 | 513 | # Don't cache redirects; it would go unused and complicate things. |
515 | 514 | if ( !Title::newFromRedirect( $text ) ) { |
516 | | - FlaggedRevs::updatePageCache( $article, $wgUser, $stableOutput ); |
| 515 | + FlaggedRevs::updatePageCache( $article, $this->user, $stableOutput ); |
517 | 516 | } |
518 | 517 | # We can set the sync cache key already |
519 | 518 | $includesSynced = true; |
— | — | @@ -529,12 +528,12 @@ |
530 | 529 | $wgMemc->set( $key, $data, $wgParserCacheExpireTime ); |
531 | 530 | } else { |
532 | 531 | # Get the old stable cache |
533 | | - $stableOutput = FlaggedRevs::getPageCache( $article, $wgUser ); |
| 532 | + $stableOutput = FlaggedRevs::getPageCache( $article, $this->user ); |
534 | 533 | # Clear the cache...(for page histories) |
535 | 534 | $this->page->invalidateCache(); |
536 | 535 | if ( $stableOutput !== false ) { |
537 | 536 | # Reset stable cache if it existed, since we know it is the same. |
538 | | - FlaggedRevs::updatePageCache( $article, $wgUser, $stableOutput ); |
| 537 | + FlaggedRevs::updatePageCache( $article, $this->user, $stableOutput ); |
539 | 538 | } |
540 | 539 | } |
541 | 540 | # Update link tracking. This will trigger extraLinksUpdate()... |
— | — | @@ -553,7 +552,7 @@ |
554 | 553 | * Removes flagged revision data for this page/id set |
555 | 554 | */ |
556 | 555 | private function unapproveRevision( $frev ) { |
557 | | - global $wgUser, $wgParser, $wgMemc; |
| 556 | + global $wgParser, $wgMemc; |
558 | 557 | wfProfileIn( __METHOD__ ); |
559 | 558 | |
560 | 559 | $dbw = wfGetDB( DB_MASTER ); |
— | — | @@ -579,7 +578,7 @@ |
580 | 579 | # Update the links tables as a new stable version |
581 | 580 | # may now be the default page. |
582 | 581 | $parserCache = ParserCache::singleton(); |
583 | | - $poutput = $parserCache->get( $article, $wgUser ); |
| 582 | + $poutput = $parserCache->get( $article, $this->user ); |
584 | 583 | if ( $poutput == false ) { |
585 | 584 | $text = $article->getContent(); |
586 | 585 | $options = FlaggedRevs::makeParserOptions(); |
— | — | @@ -651,6 +650,7 @@ |
652 | 651 | |
653 | 652 | /** |
654 | 653 | * Generates a brief review form for a page. |
| 654 | + * @param User $user |
655 | 655 | * @param FlaggedArticle $article |
656 | 656 | * @param Revision $rev |
657 | 657 | * @param array $templateIDs |
— | — | @@ -659,15 +659,15 @@ |
660 | 660 | * @return mixed (string/false) |
661 | 661 | */ |
662 | 662 | public static function buildQuickReview( |
663 | | - FlaggedArticle $article, $rev, $templateIDs, $imageSHA1Keys, $stableDiff = false |
| 663 | + $user, FlaggedArticle $article, Revision $rev, |
| 664 | + $templateIDs, $imageSHA1Keys, $stableDiff = false |
664 | 665 | ) { |
665 | | - global $wgUser, $wgRequest; |
666 | | - # The revision must be valid and public |
667 | | - if ( !$rev || $rev->isDeleted( Revision::DELETED_TEXT ) ) { |
668 | | - return false; |
| 666 | + global $wgRequest; |
| 667 | + if ( $rev->isDeleted( Revision::DELETED_TEXT ) ) { |
| 668 | + return false; # The revision must be valid and public |
669 | 669 | } |
670 | 670 | $id = $rev->getId(); |
671 | | - $skin = $wgUser->getSkin(); |
| 671 | + $skin = $user->getSkin(); |
672 | 672 | # Do we need to get inclusion IDs from parser output? |
673 | 673 | $getPOut = !( $templateIDs && $imageSHA1Keys ); |
674 | 674 | |
— | — | @@ -683,7 +683,7 @@ |
684 | 684 | $flags = $srev->getTags(); |
685 | 685 | # Check if user is allowed to renew the stable version. |
686 | 686 | # If not, then get the flags for the new revision itself. |
687 | | - if ( !FlaggedRevs::userCanSetFlags( $oldFlags ) ) { |
| 687 | + if ( !FlaggedRevs::userCanSetFlags( $user, $oldFlags ) ) { |
688 | 688 | $flags = $oldFlags; |
689 | 689 | } |
690 | 690 | $reviewNotes = $srev->getComment(); |
— | — | @@ -700,7 +700,7 @@ |
701 | 701 | $disabled = array(); |
702 | 702 | if ( !$article->getTitle()->quickUserCan( 'review' ) || |
703 | 703 | !$article->getTitle()->quickUserCan( 'edit' ) || |
704 | | - !FlaggedRevs::userCanSetFlags( $flags ) ) |
| 704 | + !FlaggedRevs::userCanSetFlags( $user, $flags ) ) |
705 | 705 | { |
706 | 706 | $disabled = array( 'disabled' => 'disabled' ); |
707 | 707 | } |
— | — | @@ -734,10 +734,10 @@ |
735 | 735 | |
736 | 736 | # Add main checkboxes/selects |
737 | 737 | $form .= Xml::openElement( 'span', array( 'id' => 'mw-fr-ratingselects' ) ); |
738 | | - $form .= self::ratingInputs( $flags, (bool)$disabled, (bool)$frev ); |
| 738 | + $form .= self::ratingInputs( $user, $flags, (bool)$disabled, (bool)$frev ); |
739 | 739 | $form .= Xml::closeElement( 'span' ); |
740 | 740 | # Add review notes input |
741 | | - if ( FlaggedRevs::allowComments() && $wgUser->isAllowed( 'validate' ) ) { |
| 741 | + if ( FlaggedRevs::allowComments() && $user->isAllowed( 'validate' ) ) { |
742 | 742 | $form .= "<div id='mw-fr-notebox'>\n"; |
743 | 743 | $form .= "<p>" . wfMsgHtml( 'revreview-notes' ) . "</p>\n"; |
744 | 744 | $params = array( 'name' => 'wpNotes', 'id' => 'wpNotes', |
— | — | @@ -755,7 +755,7 @@ |
756 | 756 | # Current version: try parser cache |
757 | 757 | if ( $rev->isCurrent() ) { |
758 | 758 | $parserCache = ParserCache::singleton(); |
759 | | - $pOutput = $parserCache->get( $article, $wgUser ); |
| 759 | + $pOutput = $parserCache->get( $article, $user ); |
760 | 760 | } |
761 | 761 | # Otherwise (or on cache miss), parse the rev text... |
762 | 762 | if ( $pOutput == false ) { |
— | — | @@ -766,7 +766,7 @@ |
767 | 767 | $pOutput = $wgParser->parse( $text, $title, $options ); |
768 | 768 | # Might as well save the cache while we're at it |
769 | 769 | if ( $rev->isCurrent() && $wgEnableParserCache ) { |
770 | | - $parserCache->save( $pOutput, $article, $wgUser ); |
| 770 | + $parserCache->save( $pOutput, $article, $user ); |
771 | 771 | } |
772 | 772 | } |
773 | 773 | $templateIDs = $pOutput->mTemplateIds; |
— | — | @@ -802,7 +802,7 @@ |
803 | 803 | $form .= Xml::hidden( 'target', $article->getTitle()->getPrefixedDBKey() ) . "\n"; |
804 | 804 | $form .= Xml::hidden( 'oldid', $id ) . "\n"; |
805 | 805 | $form .= Xml::hidden( 'action', 'submit' ) . "\n"; |
806 | | - $form .= Xml::hidden( 'wpEditToken', $wgUser->editToken() ) . "\n"; |
| 806 | + $form .= Xml::hidden( 'wpEditToken', $user->editToken() ) . "\n"; |
807 | 807 | # Add review parameters |
808 | 808 | $form .= Xml::hidden( 'templateParams', $templateParams ) . "\n"; |
809 | 809 | $form .= Xml::hidden( 'imageParams', $imageParams ) . "\n"; |
— | — | @@ -821,16 +821,17 @@ |
822 | 822 | } |
823 | 823 | |
824 | 824 | /** |
| 825 | + * @param User $user |
825 | 826 | * @param array $flags, selected flags |
826 | 827 | * @param bool $disabled, form disabled |
827 | 828 | * @param bool $reviewed, rev already reviewed |
828 | 829 | * @returns string |
829 | 830 | * Generates a main tag inputs (checkboxes/radios/selects) for review form |
830 | 831 | */ |
831 | | - private static function ratingInputs( $flags, $disabled, $reviewed ) { |
| 832 | + private static function ratingInputs( $user, $flags, $disabled, $reviewed ) { |
832 | 833 | $form = ''; |
833 | 834 | # Get all available tags for this page/user |
834 | | - list( $labels, $minLevels ) = self::ratingFormTags( $flags ); |
| 835 | + list( $labels, $minLevels ) = self::ratingFormTags( $user, $flags ); |
835 | 836 | if ( $labels === false ) { |
836 | 837 | $disabled = true; // a tag is unsettable |
837 | 838 | } |
— | — | @@ -905,13 +906,13 @@ |
906 | 907 | return $form; |
907 | 908 | } |
908 | 909 | |
909 | | - private static function ratingFormTags( $selected ) { |
| 910 | + private static function ratingFormTags( $user, $selected ) { |
910 | 911 | $labels = array(); |
911 | 912 | $minLevels = array(); |
912 | 913 | # Build up all levels available to user |
913 | 914 | foreach ( FlaggedRevs::getDimensions() as $tag => $levels ) { |
914 | 915 | if ( isset( $selected[$tag] ) && |
915 | | - !FlaggedRevs::userCanSetTag( $tag, $selected[$tag] ) ) |
| 916 | + !FlaggedRevs::userCanSetTag( $user, $tag, $selected[$tag] ) ) |
916 | 917 | { |
917 | 918 | return array( false, false ); // form will have to be disabled |
918 | 919 | } |
— | — | @@ -919,7 +920,7 @@ |
920 | 921 | $minLevels[$tag] = false; // first non-zero level number |
921 | 922 | foreach ( $levels as $i => $msg ) { |
922 | 923 | # Some levels may be restricted or not applicable... |
923 | | - if ( !FlaggedRevs::userCanSetTag( $tag, $i ) ) { |
| 924 | + if ( !FlaggedRevs::userCanSetTag( $user, $tag, $i ) ) { |
924 | 925 | continue; // skip this level |
925 | 926 | } else if ( $i > 0 && !$minLevels[$tag] ) { |
926 | 927 | $minLevels[$tag] = $i; // first non-zero level number |
— | — | @@ -976,7 +977,6 @@ |
977 | 978 | } |
978 | 979 | |
979 | 980 | public function approvalSuccessHTML( $showlinks = false ) { |
980 | | - global $wgUser; |
981 | 981 | # Show success message |
982 | 982 | $form = "<div class='plainlinks'>"; |
983 | 983 | $form .= wfMsgExt( 'revreview-successful', 'parse', |
— | — | @@ -985,14 +985,13 @@ |
986 | 986 | $this->page->getPrefixedUrl(), $this->getOldId() ); |
987 | 987 | $form .= "</div>"; |
988 | 988 | # Handy links to special pages |
989 | | - if ( $showlinks && $wgUser->isAllowed( 'unreviewedpages' ) ) { |
| 989 | + if ( $showlinks && $this->user->isAllowed( 'unreviewedpages' ) ) { |
990 | 990 | $form .= $this->getSpecialLinks(); |
991 | 991 | } |
992 | 992 | return $form; |
993 | 993 | } |
994 | 994 | |
995 | 995 | public function deapprovalSuccessHTML( $showlinks = false ) { |
996 | | - global $wgUser; |
997 | 996 | # Show success message |
998 | 997 | $form = "<div class='plainlinks'>"; |
999 | 998 | $form .= wfMsgExt( 'revreview-successful2', 'parse', |
— | — | @@ -1001,7 +1000,7 @@ |
1002 | 1001 | $this->page->getPrefixedUrl(), $this->getOldId() ); |
1003 | 1002 | $form .= "</div>"; |
1004 | 1003 | # Handy links to special pages |
1005 | | - if ( $showlinks && $wgUser->isAllowed( 'unreviewedpages' ) ) { |
| 1004 | + if ( $showlinks && $this->user->isAllowed( 'unreviewedpages' ) ) { |
1006 | 1005 | $form .= $this->getSpecialLinks(); |
1007 | 1006 | } |
1008 | 1007 | return $form; |
Index: trunk/extensions/FlaggedRevs/forms/PageStabilityForm.php |
— | — | @@ -28,11 +28,12 @@ |
29 | 29 | protected $oldExpiry = ''; # Old page config expiry (GMT) |
30 | 30 | protected $inputLock = 0; # Disallow bad submissions |
31 | 31 | |
| 32 | + protected $user = null; |
32 | 33 | protected $skin = null; |
33 | 34 | |
34 | | - public function __construct() { |
35 | | - global $wgUser; |
36 | | - $this->skin = $wgUser->getSkin(); |
| 35 | + public function __construct( $user ) { |
| 36 | + $this->user = $user; |
| 37 | + $this->skin = $user->getSkin(); |
37 | 38 | } |
38 | 39 | |
39 | 40 | public function getPage() { |
— | — | @@ -220,7 +221,6 @@ |
221 | 222 | * @return mixed (true on success, error string on failure) |
222 | 223 | */ |
223 | 224 | public function submit() { |
224 | | - global $wgUser; |
225 | 225 | if ( !$this->inputLock ) { |
226 | 226 | throw new MWException( __CLASS__ . " input fields not set yet.\n"); |
227 | 227 | } |
— | — | @@ -266,7 +266,7 @@ |
267 | 267 | $article = new Article( $this->page ); |
268 | 268 | # Review this revision of the page... |
269 | 269 | $ok = FlaggedRevs::autoReviewEdit( |
270 | | - $article, $wgUser, $nullRev->getText(), $nullRev, $flags, true ); |
| 270 | + $article, $this->user, $nullRev->getText(), $nullRev, $flags, true ); |
271 | 271 | if( $ok ) { |
272 | 272 | FlaggedRevs::markRevisionPatrolled( $nullRev ); // reviewed -> patrolled |
273 | 273 | $invalidate = false; // links invalidated (with auto-reviewed) |
— | — | @@ -360,12 +360,11 @@ |
361 | 361 | * (b) Unwatch if $watchThis is false |
362 | 362 | */ |
363 | 363 | protected function updateWatchlist() { |
364 | | - global $wgUser; |
365 | 364 | # Apply watchlist checkbox value (may be NULL) |
366 | 365 | if ( $this->watchThis === true ) { |
367 | | - $wgUser->addWatch( $this->page ); |
| 366 | + $this->user->addWatch( $this->page ); |
368 | 367 | } elseif ( $this->watchThis === false ) { |
369 | | - $wgUser->removeWatch( $this->page ); |
| 368 | + $this->user->removeWatch( $this->page ); |
370 | 369 | } |
371 | 370 | } |
372 | 371 | |
— | — | @@ -461,7 +460,7 @@ |
462 | 461 | { |
463 | 462 | return 'stabilize_invalid_autoreview'; // invalid value |
464 | 463 | } |
465 | | - if ( !FlaggedRevs::userCanSetAutoreviewLevel( $this->autoreview ) ) { |
| 464 | + if ( !FlaggedRevs::userCanSetAutoreviewLevel( $this->user, $this->autoreview ) ) { |
466 | 465 | return 'stabilize_denied'; // invalid value |
467 | 466 | } |
468 | 467 | return true; |
— | — | @@ -586,7 +585,7 @@ |
587 | 586 | return 'stabilize_invalid_level'; // double-check configuration |
588 | 587 | } |
589 | 588 | # Check autoreview restriction setting |
590 | | - if ( !FlaggedRevs::userCanSetAutoreviewLevel( $this->autoreview ) ) { |
| 589 | + if ( !FlaggedRevs::userCanSetAutoreviewLevel( $this->user, $this->autoreview ) ) { |
591 | 590 | return 'stabilize_denied'; // invalid value |
592 | 591 | } |
593 | 592 | return true; |
Index: trunk/extensions/FlaggedRevs/FlaggedRevision.php |
— | — | @@ -384,10 +384,11 @@ |
385 | 385 | } |
386 | 386 | |
387 | 387 | /** |
| 388 | + * @param User $user |
388 | 389 | * @return bool |
389 | 390 | */ |
390 | | - public function userCanSetFlags() { |
391 | | - return FlaggedRevs::userCanSetFlags( $this->mTags ); |
| 391 | + public function userCanSetFlags( $user ) { |
| 392 | + return FlaggedRevs::userCanSetFlags( $user, $this->mTags ); |
392 | 393 | } |
393 | 394 | |
394 | 395 | /** |
Index: trunk/extensions/FlaggedRevs/specialpages/Stabilization_body.php |
— | — | @@ -38,7 +38,7 @@ |
39 | 39 | # Set page title |
40 | 40 | $this->setHeaders(); |
41 | 41 | |
42 | | - $this->form = new PageStabilityGeneralForm(); |
| 42 | + $this->form = new PageStabilityGeneralForm( $wgUser ); |
43 | 43 | $form = $this->form; // convenience |
44 | 44 | # Target page |
45 | 45 | $title = Title::newFromURL( $wgRequest->getVal( 'page', $par ) ); |
— | — | @@ -269,6 +269,7 @@ |
270 | 270 | } |
271 | 271 | |
272 | 272 | protected function buildSelector( $selected ) { |
| 273 | + global $wgUser; |
273 | 274 | $allowedLevels = array(); |
274 | 275 | $levels = FlaggedRevs::getRestrictionLevels(); |
275 | 276 | array_unshift( $levels, '' ); // Add a "none" level |
— | — | @@ -276,7 +277,7 @@ |
277 | 278 | # Don't let them choose levels they can't set, |
278 | 279 | # but *show* them all when the form is disabled. |
279 | 280 | if ( $this->form->isAllowed() |
280 | | - && !FlaggedRevs::userCanSetAutoreviewLevel( $key ) ) |
| 281 | + && !FlaggedRevs::userCanSetAutoreviewLevel( $wgUser, $key ) ) |
281 | 282 | { |
282 | 283 | continue; |
283 | 284 | } |
Index: trunk/extensions/FlaggedRevs/specialpages/RevisionReview_body.php |
— | — | @@ -33,7 +33,7 @@ |
34 | 34 | } |
35 | 35 | $this->setHeaders(); |
36 | 36 | |
37 | | - $this->form = new RevisionReviewForm(); |
| 37 | + $this->form = new RevisionReviewForm( $wgUser ); |
38 | 38 | $form = $this->form; // convenience |
39 | 39 | # Our target page |
40 | 40 | $this->page = Title::newFromURL( $wgRequest->getVal( 'target' ) ); |
— | — | @@ -137,7 +137,7 @@ |
138 | 138 | } |
139 | 139 | $tags = FlaggedRevs::getDimensions(); |
140 | 140 | // Make review interface object |
141 | | - $form = new RevisionReviewForm(); |
| 141 | + $form = new RevisionReviewForm( $wgUser ); |
142 | 142 | $title = null; // target page |
143 | 143 | $editToken = ''; // edit token |
144 | 144 | // Each ajax url argument is of the form param|val. |
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php |
— | — | @@ -2000,7 +2000,7 @@ |
2001 | 2001 | } elseif ( !FlaggedRevs::inReviewNamespace( $article->getTitle() ) ) { |
2002 | 2002 | return true; // not a reviewable page |
2003 | 2003 | } |
2004 | | - $form = new PageStabilityProtectForm(); |
| 2004 | + $form = new PageStabilityProtectForm( $wgUser ); |
2005 | 2005 | $form->setPage( $article->getTitle() ); |
2006 | 2006 | # Can the user actually do anything? |
2007 | 2007 | $isAllowed = $form->isAllowed(); |
— | — | @@ -2145,7 +2145,7 @@ |
2146 | 2146 | } elseif ( wfReadOnly() || !$wgUser->isAllowed( 'stablesettings' ) ) { |
2147 | 2147 | return true; // user cannot change anything |
2148 | 2148 | } |
2149 | | - $form = new PageStabilityProtectForm(); |
| 2149 | + $form = new PageStabilityProtectForm( $wgUser ); |
2150 | 2150 | $form->setPage( $article->getTitle() ); // target page |
2151 | 2151 | $permission = $wgRequest->getVal( 'mwStabilityLevel' ); |
2152 | 2152 | if ( $permission == "none" ) { |
Index: trunk/extensions/FlaggedRevs/api/ApiReview.php |
— | — | @@ -43,7 +43,7 @@ |
44 | 44 | $this->dieUsageMsg( array( 'blockedtext' ) ); |
45 | 45 | } |
46 | 46 | // Construct submit form |
47 | | - $form = new RevisionReviewForm(); |
| 47 | + $form = new RevisionReviewForm( $wgUser ); |
48 | 48 | $revid = (int)$params['revid']; |
49 | 49 | $rev = Revision::newFromId( $revid ); |
50 | 50 | if ( !$rev ) { |
Index: trunk/extensions/FlaggedRevs/api/ApiStabilize.php |
— | — | @@ -70,9 +70,10 @@ |
71 | 71 | // Assumes $wgFlaggedRevsProtection is off |
72 | 72 | class ApiStabilizeGeneral extends ApiStabilize { |
73 | 73 | public function doExecute() { |
| 74 | + global $wgUser; |
74 | 75 | $params = $this->extractRequestParams(); |
75 | 76 | |
76 | | - $form = new PageStabilityGeneralForm(); |
| 77 | + $form = new PageStabilityGeneralForm( $wgUser ); |
77 | 78 | $form->setPage( $title ); # Our target page |
78 | 79 | $form->setWatchThis( $params['watch'] ); # Watch this page |
79 | 80 | $form->setReason( $params['reason'] ); # Reason |
— | — | @@ -206,9 +207,10 @@ |
207 | 208 | // Assumes $wgFlaggedRevsProtection is on |
208 | 209 | class ApiStabilizeProtect extends ApiStabilize { |
209 | 210 | public function doExecute() { |
| 211 | + global $wgUser; |
210 | 212 | $params = $this->extractRequestParams(); |
211 | 213 | |
212 | | - $form = new PageStabilityProtectForm(); |
| 214 | + $form = new PageStabilityProtectForm( $wgUser ); |
213 | 215 | $form->setPage( $title ); # Our target page |
214 | 216 | $form->setWatchThis( $params['watch'] ); # Watch this page |
215 | 217 | $form->setReason( $params['reason'] ); # Reason |
Index: trunk/extensions/FlaggedRevs/FlaggedArticleView.php |
— | — | @@ -82,7 +82,7 @@ |
83 | 83 | $config = $this->article->getVisibilitySettings(); |
84 | 84 | # Does the stable version override the current one? |
85 | 85 | if ( $config['override'] ) { |
86 | | - if ( FlaggedRevs::ignoreDefaultVersion() ) { |
| 86 | + if ( $this->showDraftByDefault() ) { |
87 | 87 | return ( $wgRequest->getIntOrNull( 'stable' ) === 1 ); |
88 | 88 | } |
89 | 89 | # Viewer sees stable by default |
— | — | @@ -94,6 +94,36 @@ |
95 | 95 | return false; |
96 | 96 | } |
97 | 97 | |
| 98 | + /** |
| 99 | + * Should this be using a simple icon-based UI? |
| 100 | + * Check the user's preferences first, using the site settings as the default. |
| 101 | + * @returns bool |
| 102 | + */ |
| 103 | + public function useSimpleUI() { |
| 104 | + global $wgUser, $wgSimpleFlaggedRevsUI; |
| 105 | + return $wgUser->getOption( 'flaggedrevssimpleui', intval( $wgSimpleFlaggedRevsUI ) ); |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * Should this user see the current revision by default? |
| 110 | + * Note: intended for users that probably edit |
| 111 | + * @returns bool |
| 112 | + */ |
| 113 | + public function showDraftByDefault() { |
| 114 | + global $wgFlaggedRevsExceptions, $wgUser; |
| 115 | + # Viewer sees current by default (editors, insiders, ect...) ? |
| 116 | + foreach ( $wgFlaggedRevsExceptions as $group ) { |
| 117 | + if ( $group == 'user' ) { |
| 118 | + if ( $wgUser->getId() ) { |
| 119 | + return true; |
| 120 | + } |
| 121 | + } elseif ( in_array( $group, $wgUser->getGroups() ) ) { |
| 122 | + return true; |
| 123 | + } |
| 124 | + } |
| 125 | + return false; |
| 126 | + } |
| 127 | + |
98 | 128 | /** |
99 | 129 | * Is this user shown the stable version by default for this page? |
100 | 130 | * @returns bool |
— | — | @@ -102,7 +132,7 @@ |
103 | 133 | $this->load(); |
104 | 134 | if ( $this->article->isReviewable() ) { |
105 | 135 | $config = $this->article->getVisibilitySettings(); // page configuration |
106 | | - return ( $config['override'] && !FlaggedRevs::ignoreDefaultVersion() ); |
| 136 | + return ( $config['override'] && !$this->showDraftByDefault() ); |
107 | 137 | } |
108 | 138 | return false; // no stable |
109 | 139 | } |
— | — | @@ -161,7 +191,7 @@ |
162 | 192 | $msg = $quality ? 'revreview-quality-source' : 'revreview-basic-source'; |
163 | 193 | $tag = wfMsgExt( $msg, array( 'parseinline' ), $frev->getRevId(), $time ); |
164 | 194 | # Hide clutter |
165 | | - if ( !FlaggedRevs::useSimpleUI() && !empty( $flags ) ) { |
| 195 | + if ( !$this->useSimpleUI() && !empty( $flags ) ) { |
166 | 196 | $tag .= FlaggedRevsXML::ratingToggle() . |
167 | 197 | "<div id='mw-fr-revisiondetails' style='display:block;'>" . |
168 | 198 | wfMsgHtml( 'revreview-oldrating' ) . |
— | — | @@ -274,7 +304,7 @@ |
275 | 305 | } |
276 | 306 | $encJS = ''; // JS events to use |
277 | 307 | # Some checks for which tag CSS to use |
278 | | - if ( FlaggedRevs::useSimpleUI() ) { |
| 308 | + if ( $this->useSimpleUI() ) { |
279 | 309 | $tagClass = 'flaggedrevs_short'; |
280 | 310 | # Collapse the box details on mouseOut |
281 | 311 | $encJS .= ' onMouseOut="FlaggedRevs.onBoxMouseOut(event)"'; |
— | — | @@ -322,7 +352,7 @@ |
323 | 353 | } |
324 | 354 | $icon = FlaggedRevsXML::draftStatusIcon(); |
325 | 355 | // Simple icon-based UI |
326 | | - if ( FlaggedRevs::useSimpleUI() ) { |
| 356 | + if ( $this->useSimpleUI() ) { |
327 | 357 | // RTL langauges |
328 | 358 | $rtl = $wgContLang->isRTL() ? " rtl" : ""; |
329 | 359 | $tag .= $prot . $icon . wfMsgExt( 'revreview-quick-none', array( 'parseinline' ) ); |
— | — | @@ -390,7 +420,7 @@ |
391 | 421 | } else if ( !$wgOut->isPrintable() && !( $this->article->lowProfileUI() && $synced ) ) { |
392 | 422 | $revsSince = $this->article->getPendingRevCount(); |
393 | 423 | // Simple icon-based UI |
394 | | - if ( FlaggedRevs::useSimpleUI() ) { |
| 424 | + if ( $this->useSimpleUI() ) { |
395 | 425 | if ( !$wgUser->getId() ) { |
396 | 426 | $msgHTML = ''; // Anons just see simple icons |
397 | 427 | } else if ( $synced ) { |
— | — | @@ -472,7 +502,7 @@ |
473 | 503 | # notice has all this info already, so don't do this if we added that already. |
474 | 504 | if ( !$wgOut->isPrintable() ) { |
475 | 505 | // Simple icon-based UI |
476 | | - if ( FlaggedRevs::useSimpleUI() ) { |
| 506 | + if ( $this->useSimpleUI() ) { |
477 | 507 | $icon = ''; |
478 | 508 | # For protection based configs, show lock only if it's not redundant. |
479 | 509 | if ( $this->showRatingIcon() ) { |
— | — | @@ -554,7 +584,7 @@ |
555 | 585 | if ( !$wgOut->isPrintable() && !( $this->article->lowProfileUI() && $synced ) ) { |
556 | 586 | $revsSince = $this->article->getPendingRevCount(); |
557 | 587 | // Simple icon-based UI |
558 | | - if ( FlaggedRevs::useSimpleUI() ) { |
| 588 | + if ( $this->useSimpleUI() ) { |
559 | 589 | $icon = ''; |
560 | 590 | # For protection based configs, show lock only if it's not redundant. |
561 | 591 | if ( $this->showRatingIcon() ) { |
— | — | @@ -1009,7 +1039,7 @@ |
1010 | 1040 | $templateIDs = $wgOut->mTemplateIds; |
1011 | 1041 | $fileSHA1Keys = $wgOut->fr_ImageSHA1Keys; |
1012 | 1042 | } |
1013 | | - $form = RevisionReviewForm::buildQuickReview( $this->article, |
| 1043 | + $form = RevisionReviewForm::buildQuickReview( $wgUser, $this->article, |
1014 | 1044 | $rev, $templateIDs, $fileSHA1Keys, $this->isDiffFromStable ); |
1015 | 1045 | # Diff action: place the form at the top of the page |
1016 | 1046 | if ( $wgRequest->getVal( 'diff' ) ) { |
— | — | @@ -1526,7 +1556,7 @@ |
1527 | 1557 | } |
1528 | 1558 | // If the edit was not autoreviewed, and the user can actually make a |
1529 | 1559 | // new stable version, then go to the diff... |
1530 | | - if ( $frev->userCanSetFlags() ) { |
| 1560 | + if ( $frev->userCanSetFlags( $wgUser ) ) { |
1531 | 1561 | $extraQuery .= $extraQuery ? '&' : ''; |
1532 | 1562 | // Override diffonly setting to make sure the content is shown |
1533 | 1563 | $extraQuery .= 'oldid=' . $frev->getRevId() . '&diff=cur&diffonly=0&shownotice=1'; |