r68496 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68495‎ | r68496 | r68497 >
Date:00:39, 24 June 2010
Author:aaron
Status:ok
Tags:
Comment:
* dependency injection for $wgUser in some places
* moved useSimpleUI/ignoreDefaultVersion to better class
* removed unused global
* other cleanups
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedArticle.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedArticleView.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevision.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.class.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/api/ApiReview.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/api/ApiStabilize.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/forms/PageStabilityForm.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/forms/RevisionReviewForm.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/specialpages/RevisionReview_body.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/specialpages/Stabilization_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedArticle.php
@@ -169,7 +169,7 @@
170170 * @return bool
171171 */
172172 public function stableVersionIsSynced() {
173 - global $wgUser, $wgMemc, $wgEnableParserCache, $wgParserCacheExpireTime;
 173+ global $wgMemc, $wgEnableParserCache, $wgParserCacheExpireTime;
174174 $srev = $this->getStableRev();
175175 if ( !$srev ) {
176176 return true;
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php
@@ -138,17 +138,6 @@
139139 }
140140
141141 /**
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 - /**
153142 * Allow auto-review edits directly to the stable version by reviewers?
154143 * (1 to allow auto-sighting; 2 for auto-quality; 3 for auto-pristine)
155144 * @returns bool
@@ -210,26 +199,8 @@
211200 public static function stableOnlyIfConfigured() {
212201 return self::forDefaultVersionOnly() && !self::isStableShownByDefault();
213202 }
214 -
 203+
215204 /**
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 - /**
234205 * Return the include handling configuration
235206 * @returns int
236207 */
@@ -257,17 +228,6 @@
258229 }
259230
260231 /**
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 - /**
272232 * Get the autoreview restriction levels available
273233 * @returns array
274234 */
@@ -410,17 +370,16 @@
411371
412372 /**
413373 * Returns true if a user can set $tag to $value.
 374+ * @param User $user
414375 * @param string $tag
415376 * @param int $value
416377 * @returns bool
417 - * @TODO: dependency inject the User?
418378 */
419 - public static function userCanSetTag( $tag, $value ) {
420 - global $wgUser;
 379+ public static function userCanSetTag( $user, $tag, $value ) {
421380 # Sanity check tag and value
422381 $levels = self::getTagLevels( $tag );
423382 $highest = count( $levels ) - 1;
424 - if( !$levels || $value < 0 || $value > $highest ) {
 383+ if ( !$levels || $value < 0 || $value > $highest ) {
425384 return false; // flag range is invalid
426385 }
427386 $restrictions = self::getTagRestrictions();
@@ -429,13 +388,13 @@
430389 return true;
431390 }
432391 # Validators always have full access
433 - if ( $wgUser->isAllowed( 'validate' ) ) {
 392+ if ( $user->isAllowed( 'validate' ) ) {
434393 return true;
435394 }
436395 # Check if this user has any right that lets him/her set
437396 # up to this particular value
438397 foreach ( $restrictions[$tag] as $right => $level ) {
439 - if ( $value <= $level && $level > 0 && $wgUser->isAllowed( $right ) ) {
 398+ if ( $value <= $level && $level > 0 && $user->isAllowed( $right ) ) {
440399 return true;
441400 }
442401 }
@@ -443,28 +402,26 @@
444403 }
445404
446405 /**
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
450409 * @param array $flags, suggested flags
451410 * @param array $oldflags, pre-existing flags
452411 * @returns bool
453 - * @TODO: dependency inject the User?
454412 */
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' ) ) {
458415 return false; // User is not able to review pages
459416 }
460417 # 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...
462419 foreach ( self::getDimensions() as $qal => $levels ) {
463420 $level = isset( $flags[$qal] ) ? $flags[$qal] : 0;
464421 $highest = count( $levels ) - 1; // highest valid level
465 - if ( !self::userCanSetTag( $qal, $level ) ) {
 422+ if ( !self::userCanSetTag( $user, $qal, $level ) ) {
466423 return false; // user cannot set proposed flag
467424 } elseif ( isset( $oldflags[$qal] )
468 - && !self::userCanSetTag( $qal, $oldflags[$qal] ) )
 425+ && !self::userCanSetTag( $user, $qal, $oldflags[$qal] ) )
469426 {
470427 return false; // user cannot change old flag
471428 }
@@ -474,12 +431,11 @@
475432
476433 /**
477434 * Check if a user can set the autoreview restiction level to $right
 435+ * @param User $user
478436 * @param string $right the level
479437 * @returns bool
480 - * @TODO: dependency inject the User?
481438 */
482 - public static function userCanSetAutoreviewLevel( $right ) {
483 - global $wgUser;
 439+ public static function userCanSetAutoreviewLevel( $user, $right ) {
484440 if ( $right == '' ) {
485441 return true; // no restrictions (none)
486442 }
@@ -489,10 +445,10 @@
490446 # Don't let them choose levels above their own rights
491447 if ( $right == 'sysop' ) {
492448 // special case, rewrite sysop to protect and editprotected
493 - if ( !$wgUser->isAllowed( 'protect' ) && !$wgUser->isAllowed( 'editprotected' ) ) {
 449+ if ( !$user->isAllowed( 'protect' ) && !$user->isAllowed( 'editprotected' ) ) {
494450 return false;
495451 }
496 - } else if ( !$wgUser->isAllowed( $right ) ) {
 452+ } elseif ( !$user->isAllowed( $right ) ) {
497453 return false;
498454 }
499455 return true;
@@ -1171,7 +1127,7 @@
11721128 array( 'fpc_page_id', 'fpc_select' ),
11731129 array( 'fpc_expiry < ' . $encCutoff ),
11741130 __METHOD__
1175 - // array( 'LOCK IN SHARE MODE' )
 1131+ // array( 'FOR UPDATE' )
11761132 );
11771133 while ( $row = $dbw->fetchObject( $ret ) ) {
11781134 // If FlaggedRevs got "turned off" for this page (due to not
@@ -1318,11 +1274,11 @@
13191275 /**
13201276 * Get minimum tags that are closest to $oldFlags
13211277 * given the site, page, and user rights limitations.
 1278+ * @param User $user
13221279 * @param array $oldFlags previous stable rev flags
1323 - * @TODO: dependency inject the User?
13241280 * @return mixed array or null
13251281 */
1326 - public static function getAutoReviewTags( array $oldFlags ) {
 1282+ public static function getAutoReviewTags( $user, array $oldFlags ) {
13271283 if ( !self::autoReviewEdits() ) {
13281284 return null; // shouldn't happen
13291285 }
@@ -1332,7 +1288,7 @@
13331289 $val = isset( $oldFlags[$tag] ) ? $oldFlags[$tag] : 1;
13341290 $val = min( $val, self::maxAutoReviewLevel( $tag ) );
13351291 # 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 ) ) {
13371293 $val--;
13381294 if ( $val <= 0 ) {
13391295 return null; // all tags vals must be > 0
@@ -1556,7 +1512,7 @@
15571513 if ( $user->isAllowed( 'bot' ) ) {
15581514 $flags = $oldSv->getTags(); // no change for bot edits
15591515 } else {
1560 - $flags = self::getAutoReviewTags( $oldSv->getTags() ); // account for perms
 1516+ $flags = self::getAutoReviewTags( $user, $oldSv->getTags() ); // account for perms
15611517 }
15621518 } else { // new page?
15631519 $flags = self::quickTags( FR_SIGHTED ); // use minimal level
Index: trunk/extensions/FlaggedRevs/forms/RevisionReviewForm.php
@@ -31,11 +31,12 @@
3232 protected $oflags = array();
3333 protected $inputLock = 0; # Disallow bad submissions
3434
 35+ protected $user = null;
3536 protected $skin = null;
3637
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();
4041 foreach ( FlaggedRevs::getTags() as $tag ) {
4142 $this->dims[$tag] = 0;
4243 }
@@ -118,8 +119,7 @@
119120 }
120121
121122 public function setNotes( $value ) {
122 - global $wgUser;
123 - if ( !FlaggedRevs::allowComments() || !$wgUser->isAllowed( 'validate' ) ) {
 123+ if ( !FlaggedRevs::allowComments() || !$this->user->isAllowed( 'validate' ) ) {
124124 $value = '';
125125 }
126126 $this->trySet( $this->notes, $value );
@@ -227,7 +227,7 @@
228228 }
229229 # Check permissions and validate
230230 # FIXME: invalid vs denied
231 - if ( !FlaggedRevs::userCanSetFlags( $this->dims, $this->oflags ) ) {
 231+ if ( !FlaggedRevs::userCanSetFlags( $this->user, $this->dims, $this->oflags ) ) {
232232 return 'review_denied';
233233 }
234234 return true;
@@ -277,7 +277,6 @@
278278 * @return mixed (true on success, error string on failure)
279279 */
280280 public function submit() {
281 - global $wgUser;
282281 if ( !$this->inputLock ) {
283282 throw new MWException( __CLASS__ . " input fields not set yet.\n");
284283 }
@@ -308,8 +307,8 @@
309308 }
310309 # Watch page if set to do so
311310 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 );
314313 }
315314 }
316315 return $status;
@@ -321,7 +320,7 @@
322321 * @returns true on success, array of errors on failure
323322 */
324323 private function approveRevision( $rev ) {
325 - global $wgUser, $wgMemc, $wgParser, $wgEnableParserCache;
 324+ global $wgMemc, $wgParser, $wgEnableParserCache;
326325 wfProfileIn( __METHOD__ );
327326
328327 $dbw = wfGetDB( DB_MASTER );
@@ -468,7 +467,7 @@
469468 $flaggedRevision = new FlaggedRevision( array(
470469 'fr_rev_id' => $rev->getId(),
471470 'fr_page_id' => $rev->getPage(),
472 - 'fr_user' => $wgUser->getId(),
 471+ 'fr_user' => $this->user->getId(),
473472 'fr_timestamp' => wfTimestampNow(),
474473 'fr_comment' => $this->notes,
475474 'fr_quality' => $quality,
@@ -491,7 +490,7 @@
492491 # Update the links tables as the stable version may now be the default page.
493492 # Try using the parser cache first since we didn't actually edit the current version.
494493 $parserCache = ParserCache::singleton();
495 - $poutput = $parserCache->get( $article, $wgUser );
 494+ $poutput = $parserCache->get( $article, $this->user );
496495 if ( !$poutput
497496 || !isset( $poutput->fr_newestTemplateID )
498497 || !isset( $poutput->fr_newestImageTime ) )
@@ -512,7 +511,7 @@
513512 # Update stable cache with the revision we reviewed.
514513 # Don't cache redirects; it would go unused and complicate things.
515514 if ( !Title::newFromRedirect( $text ) ) {
516 - FlaggedRevs::updatePageCache( $article, $wgUser, $stableOutput );
 515+ FlaggedRevs::updatePageCache( $article, $this->user, $stableOutput );
517516 }
518517 # We can set the sync cache key already
519518 $includesSynced = true;
@@ -529,12 +528,12 @@
530529 $wgMemc->set( $key, $data, $wgParserCacheExpireTime );
531530 } else {
532531 # Get the old stable cache
533 - $stableOutput = FlaggedRevs::getPageCache( $article, $wgUser );
 532+ $stableOutput = FlaggedRevs::getPageCache( $article, $this->user );
534533 # Clear the cache...(for page histories)
535534 $this->page->invalidateCache();
536535 if ( $stableOutput !== false ) {
537536 # 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 );
539538 }
540539 }
541540 # Update link tracking. This will trigger extraLinksUpdate()...
@@ -553,7 +552,7 @@
554553 * Removes flagged revision data for this page/id set
555554 */
556555 private function unapproveRevision( $frev ) {
557 - global $wgUser, $wgParser, $wgMemc;
 556+ global $wgParser, $wgMemc;
558557 wfProfileIn( __METHOD__ );
559558
560559 $dbw = wfGetDB( DB_MASTER );
@@ -579,7 +578,7 @@
580579 # Update the links tables as a new stable version
581580 # may now be the default page.
582581 $parserCache = ParserCache::singleton();
583 - $poutput = $parserCache->get( $article, $wgUser );
 582+ $poutput = $parserCache->get( $article, $this->user );
584583 if ( $poutput == false ) {
585584 $text = $article->getContent();
586585 $options = FlaggedRevs::makeParserOptions();
@@ -651,6 +650,7 @@
652651
653652 /**
654653 * Generates a brief review form for a page.
 654+ * @param User $user
655655 * @param FlaggedArticle $article
656656 * @param Revision $rev
657657 * @param array $templateIDs
@@ -659,15 +659,15 @@
660660 * @return mixed (string/false)
661661 */
662662 public static function buildQuickReview(
663 - FlaggedArticle $article, $rev, $templateIDs, $imageSHA1Keys, $stableDiff = false
 663+ $user, FlaggedArticle $article, Revision $rev,
 664+ $templateIDs, $imageSHA1Keys, $stableDiff = false
664665 ) {
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
669669 }
670670 $id = $rev->getId();
671 - $skin = $wgUser->getSkin();
 671+ $skin = $user->getSkin();
672672 # Do we need to get inclusion IDs from parser output?
673673 $getPOut = !( $templateIDs && $imageSHA1Keys );
674674
@@ -683,7 +683,7 @@
684684 $flags = $srev->getTags();
685685 # Check if user is allowed to renew the stable version.
686686 # If not, then get the flags for the new revision itself.
687 - if ( !FlaggedRevs::userCanSetFlags( $oldFlags ) ) {
 687+ if ( !FlaggedRevs::userCanSetFlags( $user, $oldFlags ) ) {
688688 $flags = $oldFlags;
689689 }
690690 $reviewNotes = $srev->getComment();
@@ -700,7 +700,7 @@
701701 $disabled = array();
702702 if ( !$article->getTitle()->quickUserCan( 'review' ) ||
703703 !$article->getTitle()->quickUserCan( 'edit' ) ||
704 - !FlaggedRevs::userCanSetFlags( $flags ) )
 704+ !FlaggedRevs::userCanSetFlags( $user, $flags ) )
705705 {
706706 $disabled = array( 'disabled' => 'disabled' );
707707 }
@@ -734,10 +734,10 @@
735735
736736 # Add main checkboxes/selects
737737 $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 );
739739 $form .= Xml::closeElement( 'span' );
740740 # Add review notes input
741 - if ( FlaggedRevs::allowComments() && $wgUser->isAllowed( 'validate' ) ) {
 741+ if ( FlaggedRevs::allowComments() && $user->isAllowed( 'validate' ) ) {
742742 $form .= "<div id='mw-fr-notebox'>\n";
743743 $form .= "<p>" . wfMsgHtml( 'revreview-notes' ) . "</p>\n";
744744 $params = array( 'name' => 'wpNotes', 'id' => 'wpNotes',
@@ -755,7 +755,7 @@
756756 # Current version: try parser cache
757757 if ( $rev->isCurrent() ) {
758758 $parserCache = ParserCache::singleton();
759 - $pOutput = $parserCache->get( $article, $wgUser );
 759+ $pOutput = $parserCache->get( $article, $user );
760760 }
761761 # Otherwise (or on cache miss), parse the rev text...
762762 if ( $pOutput == false ) {
@@ -766,7 +766,7 @@
767767 $pOutput = $wgParser->parse( $text, $title, $options );
768768 # Might as well save the cache while we're at it
769769 if ( $rev->isCurrent() && $wgEnableParserCache ) {
770 - $parserCache->save( $pOutput, $article, $wgUser );
 770+ $parserCache->save( $pOutput, $article, $user );
771771 }
772772 }
773773 $templateIDs = $pOutput->mTemplateIds;
@@ -802,7 +802,7 @@
803803 $form .= Xml::hidden( 'target', $article->getTitle()->getPrefixedDBKey() ) . "\n";
804804 $form .= Xml::hidden( 'oldid', $id ) . "\n";
805805 $form .= Xml::hidden( 'action', 'submit' ) . "\n";
806 - $form .= Xml::hidden( 'wpEditToken', $wgUser->editToken() ) . "\n";
 806+ $form .= Xml::hidden( 'wpEditToken', $user->editToken() ) . "\n";
807807 # Add review parameters
808808 $form .= Xml::hidden( 'templateParams', $templateParams ) . "\n";
809809 $form .= Xml::hidden( 'imageParams', $imageParams ) . "\n";
@@ -821,16 +821,17 @@
822822 }
823823
824824 /**
 825+ * @param User $user
825826 * @param array $flags, selected flags
826827 * @param bool $disabled, form disabled
827828 * @param bool $reviewed, rev already reviewed
828829 * @returns string
829830 * Generates a main tag inputs (checkboxes/radios/selects) for review form
830831 */
831 - private static function ratingInputs( $flags, $disabled, $reviewed ) {
 832+ private static function ratingInputs( $user, $flags, $disabled, $reviewed ) {
832833 $form = '';
833834 # Get all available tags for this page/user
834 - list( $labels, $minLevels ) = self::ratingFormTags( $flags );
 835+ list( $labels, $minLevels ) = self::ratingFormTags( $user, $flags );
835836 if ( $labels === false ) {
836837 $disabled = true; // a tag is unsettable
837838 }
@@ -905,13 +906,13 @@
906907 return $form;
907908 }
908909
909 - private static function ratingFormTags( $selected ) {
 910+ private static function ratingFormTags( $user, $selected ) {
910911 $labels = array();
911912 $minLevels = array();
912913 # Build up all levels available to user
913914 foreach ( FlaggedRevs::getDimensions() as $tag => $levels ) {
914915 if ( isset( $selected[$tag] ) &&
915 - !FlaggedRevs::userCanSetTag( $tag, $selected[$tag] ) )
 916+ !FlaggedRevs::userCanSetTag( $user, $tag, $selected[$tag] ) )
916917 {
917918 return array( false, false ); // form will have to be disabled
918919 }
@@ -919,7 +920,7 @@
920921 $minLevels[$tag] = false; // first non-zero level number
921922 foreach ( $levels as $i => $msg ) {
922923 # Some levels may be restricted or not applicable...
923 - if ( !FlaggedRevs::userCanSetTag( $tag, $i ) ) {
 924+ if ( !FlaggedRevs::userCanSetTag( $user, $tag, $i ) ) {
924925 continue; // skip this level
925926 } else if ( $i > 0 && !$minLevels[$tag] ) {
926927 $minLevels[$tag] = $i; // first non-zero level number
@@ -976,7 +977,6 @@
977978 }
978979
979980 public function approvalSuccessHTML( $showlinks = false ) {
980 - global $wgUser;
981981 # Show success message
982982 $form = "<div class='plainlinks'>";
983983 $form .= wfMsgExt( 'revreview-successful', 'parse',
@@ -985,14 +985,13 @@
986986 $this->page->getPrefixedUrl(), $this->getOldId() );
987987 $form .= "</div>";
988988 # Handy links to special pages
989 - if ( $showlinks && $wgUser->isAllowed( 'unreviewedpages' ) ) {
 989+ if ( $showlinks && $this->user->isAllowed( 'unreviewedpages' ) ) {
990990 $form .= $this->getSpecialLinks();
991991 }
992992 return $form;
993993 }
994994
995995 public function deapprovalSuccessHTML( $showlinks = false ) {
996 - global $wgUser;
997996 # Show success message
998997 $form = "<div class='plainlinks'>";
999998 $form .= wfMsgExt( 'revreview-successful2', 'parse',
@@ -1001,7 +1000,7 @@
10021001 $this->page->getPrefixedUrl(), $this->getOldId() );
10031002 $form .= "</div>";
10041003 # Handy links to special pages
1005 - if ( $showlinks && $wgUser->isAllowed( 'unreviewedpages' ) ) {
 1004+ if ( $showlinks && $this->user->isAllowed( 'unreviewedpages' ) ) {
10061005 $form .= $this->getSpecialLinks();
10071006 }
10081007 return $form;
Index: trunk/extensions/FlaggedRevs/forms/PageStabilityForm.php
@@ -28,11 +28,12 @@
2929 protected $oldExpiry = ''; # Old page config expiry (GMT)
3030 protected $inputLock = 0; # Disallow bad submissions
3131
 32+ protected $user = null;
3233 protected $skin = null;
3334
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();
3738 }
3839
3940 public function getPage() {
@@ -220,7 +221,6 @@
221222 * @return mixed (true on success, error string on failure)
222223 */
223224 public function submit() {
224 - global $wgUser;
225225 if ( !$this->inputLock ) {
226226 throw new MWException( __CLASS__ . " input fields not set yet.\n");
227227 }
@@ -266,7 +266,7 @@
267267 $article = new Article( $this->page );
268268 # Review this revision of the page...
269269 $ok = FlaggedRevs::autoReviewEdit(
270 - $article, $wgUser, $nullRev->getText(), $nullRev, $flags, true );
 270+ $article, $this->user, $nullRev->getText(), $nullRev, $flags, true );
271271 if( $ok ) {
272272 FlaggedRevs::markRevisionPatrolled( $nullRev ); // reviewed -> patrolled
273273 $invalidate = false; // links invalidated (with auto-reviewed)
@@ -360,12 +360,11 @@
361361 * (b) Unwatch if $watchThis is false
362362 */
363363 protected function updateWatchlist() {
364 - global $wgUser;
365364 # Apply watchlist checkbox value (may be NULL)
366365 if ( $this->watchThis === true ) {
367 - $wgUser->addWatch( $this->page );
 366+ $this->user->addWatch( $this->page );
368367 } elseif ( $this->watchThis === false ) {
369 - $wgUser->removeWatch( $this->page );
 368+ $this->user->removeWatch( $this->page );
370369 }
371370 }
372371
@@ -461,7 +460,7 @@
462461 {
463462 return 'stabilize_invalid_autoreview'; // invalid value
464463 }
465 - if ( !FlaggedRevs::userCanSetAutoreviewLevel( $this->autoreview ) ) {
 464+ if ( !FlaggedRevs::userCanSetAutoreviewLevel( $this->user, $this->autoreview ) ) {
466465 return 'stabilize_denied'; // invalid value
467466 }
468467 return true;
@@ -586,7 +585,7 @@
587586 return 'stabilize_invalid_level'; // double-check configuration
588587 }
589588 # Check autoreview restriction setting
590 - if ( !FlaggedRevs::userCanSetAutoreviewLevel( $this->autoreview ) ) {
 589+ if ( !FlaggedRevs::userCanSetAutoreviewLevel( $this->user, $this->autoreview ) ) {
591590 return 'stabilize_denied'; // invalid value
592591 }
593592 return true;
Index: trunk/extensions/FlaggedRevs/FlaggedRevision.php
@@ -384,10 +384,11 @@
385385 }
386386
387387 /**
 388+ * @param User $user
388389 * @return bool
389390 */
390 - public function userCanSetFlags() {
391 - return FlaggedRevs::userCanSetFlags( $this->mTags );
 391+ public function userCanSetFlags( $user ) {
 392+ return FlaggedRevs::userCanSetFlags( $user, $this->mTags );
392393 }
393394
394395 /**
Index: trunk/extensions/FlaggedRevs/specialpages/Stabilization_body.php
@@ -38,7 +38,7 @@
3939 # Set page title
4040 $this->setHeaders();
4141
42 - $this->form = new PageStabilityGeneralForm();
 42+ $this->form = new PageStabilityGeneralForm( $wgUser );
4343 $form = $this->form; // convenience
4444 # Target page
4545 $title = Title::newFromURL( $wgRequest->getVal( 'page', $par ) );
@@ -269,6 +269,7 @@
270270 }
271271
272272 protected function buildSelector( $selected ) {
 273+ global $wgUser;
273274 $allowedLevels = array();
274275 $levels = FlaggedRevs::getRestrictionLevels();
275276 array_unshift( $levels, '' ); // Add a "none" level
@@ -276,7 +277,7 @@
277278 # Don't let them choose levels they can't set,
278279 # but *show* them all when the form is disabled.
279280 if ( $this->form->isAllowed()
280 - && !FlaggedRevs::userCanSetAutoreviewLevel( $key ) )
 281+ && !FlaggedRevs::userCanSetAutoreviewLevel( $wgUser, $key ) )
281282 {
282283 continue;
283284 }
Index: trunk/extensions/FlaggedRevs/specialpages/RevisionReview_body.php
@@ -33,7 +33,7 @@
3434 }
3535 $this->setHeaders();
3636
37 - $this->form = new RevisionReviewForm();
 37+ $this->form = new RevisionReviewForm( $wgUser );
3838 $form = $this->form; // convenience
3939 # Our target page
4040 $this->page = Title::newFromURL( $wgRequest->getVal( 'target' ) );
@@ -137,7 +137,7 @@
138138 }
139139 $tags = FlaggedRevs::getDimensions();
140140 // Make review interface object
141 - $form = new RevisionReviewForm();
 141+ $form = new RevisionReviewForm( $wgUser );
142142 $title = null; // target page
143143 $editToken = ''; // edit token
144144 // Each ajax url argument is of the form param|val.
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php
@@ -2000,7 +2000,7 @@
20012001 } elseif ( !FlaggedRevs::inReviewNamespace( $article->getTitle() ) ) {
20022002 return true; // not a reviewable page
20032003 }
2004 - $form = new PageStabilityProtectForm();
 2004+ $form = new PageStabilityProtectForm( $wgUser );
20052005 $form->setPage( $article->getTitle() );
20062006 # Can the user actually do anything?
20072007 $isAllowed = $form->isAllowed();
@@ -2145,7 +2145,7 @@
21462146 } elseif ( wfReadOnly() || !$wgUser->isAllowed( 'stablesettings' ) ) {
21472147 return true; // user cannot change anything
21482148 }
2149 - $form = new PageStabilityProtectForm();
 2149+ $form = new PageStabilityProtectForm( $wgUser );
21502150 $form->setPage( $article->getTitle() ); // target page
21512151 $permission = $wgRequest->getVal( 'mwStabilityLevel' );
21522152 if ( $permission == "none" ) {
Index: trunk/extensions/FlaggedRevs/api/ApiReview.php
@@ -43,7 +43,7 @@
4444 $this->dieUsageMsg( array( 'blockedtext' ) );
4545 }
4646 // Construct submit form
47 - $form = new RevisionReviewForm();
 47+ $form = new RevisionReviewForm( $wgUser );
4848 $revid = (int)$params['revid'];
4949 $rev = Revision::newFromId( $revid );
5050 if ( !$rev ) {
Index: trunk/extensions/FlaggedRevs/api/ApiStabilize.php
@@ -70,9 +70,10 @@
7171 // Assumes $wgFlaggedRevsProtection is off
7272 class ApiStabilizeGeneral extends ApiStabilize {
7373 public function doExecute() {
 74+ global $wgUser;
7475 $params = $this->extractRequestParams();
7576
76 - $form = new PageStabilityGeneralForm();
 77+ $form = new PageStabilityGeneralForm( $wgUser );
7778 $form->setPage( $title ); # Our target page
7879 $form->setWatchThis( $params['watch'] ); # Watch this page
7980 $form->setReason( $params['reason'] ); # Reason
@@ -206,9 +207,10 @@
207208 // Assumes $wgFlaggedRevsProtection is on
208209 class ApiStabilizeProtect extends ApiStabilize {
209210 public function doExecute() {
 211+ global $wgUser;
210212 $params = $this->extractRequestParams();
211213
212 - $form = new PageStabilityProtectForm();
 214+ $form = new PageStabilityProtectForm( $wgUser );
213215 $form->setPage( $title ); # Our target page
214216 $form->setWatchThis( $params['watch'] ); # Watch this page
215217 $form->setReason( $params['reason'] ); # Reason
Index: trunk/extensions/FlaggedRevs/FlaggedArticleView.php
@@ -82,7 +82,7 @@
8383 $config = $this->article->getVisibilitySettings();
8484 # Does the stable version override the current one?
8585 if ( $config['override'] ) {
86 - if ( FlaggedRevs::ignoreDefaultVersion() ) {
 86+ if ( $this->showDraftByDefault() ) {
8787 return ( $wgRequest->getIntOrNull( 'stable' ) === 1 );
8888 }
8989 # Viewer sees stable by default
@@ -94,6 +94,36 @@
9595 return false;
9696 }
9797
 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+
98128 /**
99129 * Is this user shown the stable version by default for this page?
100130 * @returns bool
@@ -102,7 +132,7 @@
103133 $this->load();
104134 if ( $this->article->isReviewable() ) {
105135 $config = $this->article->getVisibilitySettings(); // page configuration
106 - return ( $config['override'] && !FlaggedRevs::ignoreDefaultVersion() );
 136+ return ( $config['override'] && !$this->showDraftByDefault() );
107137 }
108138 return false; // no stable
109139 }
@@ -161,7 +191,7 @@
162192 $msg = $quality ? 'revreview-quality-source' : 'revreview-basic-source';
163193 $tag = wfMsgExt( $msg, array( 'parseinline' ), $frev->getRevId(), $time );
164194 # Hide clutter
165 - if ( !FlaggedRevs::useSimpleUI() && !empty( $flags ) ) {
 195+ if ( !$this->useSimpleUI() && !empty( $flags ) ) {
166196 $tag .= FlaggedRevsXML::ratingToggle() .
167197 "<div id='mw-fr-revisiondetails' style='display:block;'>" .
168198 wfMsgHtml( 'revreview-oldrating' ) .
@@ -274,7 +304,7 @@
275305 }
276306 $encJS = ''; // JS events to use
277307 # Some checks for which tag CSS to use
278 - if ( FlaggedRevs::useSimpleUI() ) {
 308+ if ( $this->useSimpleUI() ) {
279309 $tagClass = 'flaggedrevs_short';
280310 # Collapse the box details on mouseOut
281311 $encJS .= ' onMouseOut="FlaggedRevs.onBoxMouseOut(event)"';
@@ -322,7 +352,7 @@
323353 }
324354 $icon = FlaggedRevsXML::draftStatusIcon();
325355 // Simple icon-based UI
326 - if ( FlaggedRevs::useSimpleUI() ) {
 356+ if ( $this->useSimpleUI() ) {
327357 // RTL langauges
328358 $rtl = $wgContLang->isRTL() ? " rtl" : "";
329359 $tag .= $prot . $icon . wfMsgExt( 'revreview-quick-none', array( 'parseinline' ) );
@@ -390,7 +420,7 @@
391421 } else if ( !$wgOut->isPrintable() && !( $this->article->lowProfileUI() && $synced ) ) {
392422 $revsSince = $this->article->getPendingRevCount();
393423 // Simple icon-based UI
394 - if ( FlaggedRevs::useSimpleUI() ) {
 424+ if ( $this->useSimpleUI() ) {
395425 if ( !$wgUser->getId() ) {
396426 $msgHTML = ''; // Anons just see simple icons
397427 } else if ( $synced ) {
@@ -472,7 +502,7 @@
473503 # notice has all this info already, so don't do this if we added that already.
474504 if ( !$wgOut->isPrintable() ) {
475505 // Simple icon-based UI
476 - if ( FlaggedRevs::useSimpleUI() ) {
 506+ if ( $this->useSimpleUI() ) {
477507 $icon = '';
478508 # For protection based configs, show lock only if it's not redundant.
479509 if ( $this->showRatingIcon() ) {
@@ -554,7 +584,7 @@
555585 if ( !$wgOut->isPrintable() && !( $this->article->lowProfileUI() && $synced ) ) {
556586 $revsSince = $this->article->getPendingRevCount();
557587 // Simple icon-based UI
558 - if ( FlaggedRevs::useSimpleUI() ) {
 588+ if ( $this->useSimpleUI() ) {
559589 $icon = '';
560590 # For protection based configs, show lock only if it's not redundant.
561591 if ( $this->showRatingIcon() ) {
@@ -1009,7 +1039,7 @@
10101040 $templateIDs = $wgOut->mTemplateIds;
10111041 $fileSHA1Keys = $wgOut->fr_ImageSHA1Keys;
10121042 }
1013 - $form = RevisionReviewForm::buildQuickReview( $this->article,
 1043+ $form = RevisionReviewForm::buildQuickReview( $wgUser, $this->article,
10141044 $rev, $templateIDs, $fileSHA1Keys, $this->isDiffFromStable );
10151045 # Diff action: place the form at the top of the page
10161046 if ( $wgRequest->getVal( 'diff' ) ) {
@@ -1526,7 +1556,7 @@
15271557 }
15281558 // If the edit was not autoreviewed, and the user can actually make a
15291559 // new stable version, then go to the diff...
1530 - if ( $frev->userCanSetFlags() ) {
 1560+ if ( $frev->userCanSetFlags( $wgUser ) ) {
15311561 $extraQuery .= $extraQuery ? '&' : '';
15321562 // Override diffonly setting to make sure the content is shown
15331563 $extraQuery .= 'oldid=' . $frev->getRevId() . '&diff=cur&diffonly=0&shownotice=1';

Status & tagging log