r57623 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57622‎ | r57623 | r57624 >
Date:19:20, 10 October 2009
Author:aaron
Status:ok
Tags:
Comment:
Fixed submission failure with config/checkbox interaction
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedArticle.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/flaggedrevs.js (modified) (history)
  • /trunk/extensions/FlaggedRevs/specialpages/RevisionReview_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -291,7 +291,7 @@
292292 $wgAvailableRights[] = 'stablesettings';
293293
294294 # Bump this number every time you change flaggedrevs.css/flaggedrevs.js
295 -$wgFlaggedRevStyleVersion = 60;
 295+$wgFlaggedRevStyleVersion = 61;
296296
297297 $wgExtensionFunctions[] = 'efLoadFlaggedRevs';
298298
Index: trunk/extensions/FlaggedRevs/FlaggedArticle.php
@@ -1563,7 +1563,8 @@
15641564 } else {
15651565 # If disable, use the current flags; if none, then use the min flag.
15661566 $i = $disabled ? $selected : $minLevel;
1567 - $attribs = array( 'class' => "fr-rating-option-$i", 'onchange' => "updateRatingForm()" ) + $toggle;
 1567+ $attribs = array( 'class' => "fr-rating-option-$i", 'onchange' => "updateRatingForm()" );
 1568+ $attribs = $attribs + $toggle + array('value' => $minLevel);
15681569 $form .= Xml::checkLabel( wfMsg( "revreview-$label[$i]" ), "wp$quality", "wp$quality",
15691570 ($selected == $i), $attribs ) . "\n";
15701571 }
Index: trunk/extensions/FlaggedRevs/specialpages/RevisionReview_body.php
@@ -759,16 +759,19 @@
760760 }
761761
762762 /**
763 - * Returns true if a user can do something
 763+ * Returns true if a user can set $tag to $value.
764764 * @param string $tag
765765 * @param int $value
 766+ * @param array $config (optional page config)
766767 * @returns bool
767768 */
768 - public static function userCan( $tag, $value, $config = array() ) {
 769+ public static function userCan( $tag, $value, $config = null ) {
769770 global $wgFlagRestrictions, $wgUser;
770 - # Levels may not apply for some pages
771 - if( $value > 0 && !self::levelAvailable( $tag, $value, $config ) )
 771+ # Levels may not apply for some pages.
 772+ # Skip this check if $config is not given.
 773+ if( !is_null($config) && !self::levelAvailable($tag,$value,$config) ) {
772774 return false;
 775+ }
773776 # No restrictions -> full access
774777 if( !isset($wgFlagRestrictions[$tag]) )
775778 return true;
@@ -794,30 +797,33 @@
795798 * @param array $config, visibility settings
796799 * @returns bool
797800 */
798 - public static function userCanSetFlags( $flags, $oldflags = array(), $config = array() ) {
 801+ public static function userCanSetFlags( $flags, $oldflags = array(), $config = null ) {
799802 global $wgUser;
800 - if( !$wgUser->isAllowed('review') ) {
801 - return false;
802 - }
 803+ if( !$wgUser->isAllowed('review') )
 804+ return false; // User is not able to review pages
803805 # Check if all of the required site flags have a valid value
804806 # that the user is allowed to set.
805807 foreach( FlaggedRevs::getDimensions() as $qal => $levels ) {
806808 $level = isset($flags[$qal]) ? $flags[$qal] : 0;
807809 $highest = count($levels) - 1; // highest valid level
808810 if( !self::userCan($qal,$level,$config) ) {
809 - return false;
 811+ return false; // user cannot set proposed flag
810812 } elseif( isset($oldflags[$qal]) && !self::userCan($qal,$oldflags[$qal]) ) {
811 - return false;
 813+ return false; // user cannot change old flag
812814 } elseif( $level < 0 || $level > $highest ) {
813 - return false;
 815+ return false; // flag range is invalid
814816 }
815817 }
816818 return true;
817819 }
818820
 821+ // Check if a given level for a tag is available in $config
819822 public static function levelAvailable( $tag, $val, $config ) {
820823 global $wgFlagAvailability;
821 - if( !array_key_exists('select',$config) ) return true;
 824+ if( $val == 0 )
 825+ return true; // unreviewed is always applicable
 826+ if( !array_key_exists('select',$config) )
 827+ return true; // missing config
822828 if( isset($wgFlagAvailability[$tag]) && isset($wgFlagAvailability[$tag][$val]) ) {
823829 $precedence = $wgFlagAvailability[$tag][$val];
824830 return ( $config['select'] === $precedence );
Index: trunk/extensions/FlaggedRevs/flaggedrevs.js
@@ -144,7 +144,7 @@
145145 } else if( inputs[i].type == "submit" ) {
146146 inputs[i].value = wgAjaxReview.sendingMsg;
147147 } else if( inputs[i].type == "checkbox" ) {
148 - args.push( inputs[i].name + "|" + (inputs[i].checked ? 1 : 0) );
 148+ args.push( inputs[i].name + "|" + (inputs[i].checked ? inputs[i].value : 0) );
149149 } else if( inputs[i].type != "radio" || inputs[i].checked ) {
150150 args.push( inputs[i].name + "|" + inputs[i].value );
151151 }

Status & tagging log