Index: trunk/extensions/FlaggedRevs/FlaggedArticle.php |
— | — | @@ -1514,68 +1514,9 @@ |
1515 | 1515 | 'id' => 'fr-rating-controls') ); |
1516 | 1516 | $toggle = array(); |
1517 | 1517 | } |
1518 | | - $size = count(FlaggedRevs::getDimensions(),1) - count(FlaggedRevs::getDimensions()); |
1519 | | - |
| 1518 | + # Add main checkboxes/selects |
1520 | 1519 | $form .= Xml::openElement( 'span', array('id' => 'mw-ratingselects') ); |
1521 | | - # Loop through all different flag types |
1522 | | - foreach( FlaggedRevs::getDimensions() as $quality => $levels ) { |
1523 | | - $label = array(); // applicable levels |
1524 | | - $minLevel = 1; // first non-zero level number |
1525 | | - # Get current flag values or default if none |
1526 | | - $selected = ( isset($flags[$quality]) && $flags[$quality] > 0 ) ? |
1527 | | - $flags[$quality] : 1; |
1528 | | - # Disabled form? Set the selected item label |
1529 | | - if( $disabled ) { |
1530 | | - $label[$selected] = $levels[$selected]; |
1531 | | - # Collect all quality levels of a flag current user can set |
1532 | | - } else { |
1533 | | - foreach( $levels as $i => $name ) { |
1534 | | - # Some levels may be restricted or not applicable... |
1535 | | - if( !RevisionReview::userCan($quality,$i,$config) ) { |
1536 | | - $minLevel++; // bump first non-zero level number |
1537 | | - if( $selected == $i ) $selected++; // bump default |
1538 | | - continue; // skip this level |
1539 | | - } |
1540 | | - $label[$i] = $name; |
1541 | | - } |
1542 | | - } |
1543 | | - $numLevels = count( $label ); |
1544 | | - $form .= Xml::openElement( 'span', array('class' => 'fr-rating-options') ) . "\n"; |
1545 | | - $form .= "<b>" . Xml::tags( 'label', array( 'for' => "wp$quality" ), FlaggedRevs::getTagMsg( $quality ) ) . ":</b>\n"; |
1546 | | - # If the sum of qualities of all flags is above 6, use drop down boxes |
1547 | | - # 6 is an arbitrary value choosen according to screen space and usability |
1548 | | - if( $size > 6 ) { |
1549 | | - $attribs = array( 'name' => "wp$quality", 'id' => "wp$quality", 'onchange' => "updateRatingForm()" ) + $toggle; |
1550 | | - $form .= Xml::openElement( 'select', $attribs ); |
1551 | | - foreach( $label as $i => $name ) { |
1552 | | - $optionClass = array( 'class' => "fr-rating-option-$i" ); |
1553 | | - $form .= Xml::option( FlaggedRevs::getTagMsg($name), $i, ($i == $selected), $optionClass )."\n"; |
1554 | | - } |
1555 | | - $form .= Xml::closeElement('select')."\n"; |
1556 | | - # If there are more than two levels, current user gets radio buttons |
1557 | | - } elseif( $numLevels > 2 ) { |
1558 | | - foreach( $label as $i => $name ) { |
1559 | | - $attribs = array( 'class' => "fr-rating-option-$i", 'onchange' => "updateRatingForm()" ); |
1560 | | - $form .= Xml::radioLabel( FlaggedRevs::getTagMsg($name), "wp$quality", $i, "wp$quality".$i, |
1561 | | - ($i == $selected), $attribs ) . "\n"; |
1562 | | - } |
1563 | | - # Otherwise make checkboxes (two levels available for current user) |
1564 | | - } else { |
1565 | | - # If disable, use the current flags; if none, then use the min flag. |
1566 | | - $i = $disabled ? $selected : $minLevel; |
1567 | | - $attribs = array( 'class' => "fr-rating-option-$i", 'onchange' => "updateRatingForm()" ); |
1568 | | - $attribs = $attribs + $toggle + array('value' => $minLevel); |
1569 | | - $form .= Xml::checkLabel( wfMsg( "revreview-$label[$i]" ), "wp$quality", "wp$quality", |
1570 | | - ($selected == $i), $attribs ) . "\n"; |
1571 | | - } |
1572 | | - $form .= Xml::closeElement( 'span' ); |
1573 | | - } |
1574 | | - # If there were none, make one checkbox to approve/unapprove |
1575 | | - if( FlaggedRevs::dimensionsEmpty() ) { |
1576 | | - $form .= Xml::openElement( 'span', array('class' => 'fr-rating-options') ) . "\n"; |
1577 | | - $form .= Xml::checkLabel( wfMsg( "revreview-approved" ), "wpApprove", "wpApprove", 1 ) . "\n"; |
1578 | | - $form .= Xml::closeElement( 'span' ); |
1579 | | - } |
| 1520 | + $form .= FlaggedRevsXml::ratingInputs( $flags, $config, $disabled ); |
1580 | 1521 | $form .= Xml::closeElement( 'span' ); |
1581 | 1522 | |
1582 | 1523 | if( FlaggedRevs::allowComments() && $wgUser->isAllowed( 'validate' ) ) { |
Index: trunk/extensions/FlaggedRevs/FlaggedRevsXML.php |
— | — | @@ -242,4 +242,79 @@ |
243 | 243 | " onclick='toggleRevRatings()' title='" . wfMsgHtml('revreview-toggle-title') . "' >" . |
244 | 244 | wfMsg( 'revreview-toggle' ) . "</a>"; |
245 | 245 | } |
| 246 | + |
| 247 | + /** |
| 248 | + * @param array $flags, selected flags |
| 249 | + * @param array $config, page config |
| 250 | + * @param bool $disabled, form disabled |
| 251 | + * @returns string |
| 252 | + * Generates a main tag inputs (checkboxes/radios/selects) for review form |
| 253 | + */ |
| 254 | + public static function ratingInputs( $flags, $config, $disabled ) { |
| 255 | + $form = ''; |
| 256 | + $toggle = $disabled ? array( 'disabled' => "disabled" ) : array(); |
| 257 | + $size = count(FlaggedRevs::getDimensions(),1) - count(FlaggedRevs::getDimensions()); |
| 258 | + # Loop through all different flag types |
| 259 | + foreach( FlaggedRevs::getDimensions() as $quality => $levels ) { |
| 260 | + $label = array(); // applicable tag levels |
| 261 | + $minLevel = 1; // first non-zero level number |
| 262 | + # Get current flag values or default if none |
| 263 | + $selected = ( isset($flags[$quality]) && $flags[$quality] > 0 ) ? |
| 264 | + $flags[$quality] : 1; |
| 265 | + # Disabled form? Set the selected item label |
| 266 | + if( $disabled ) { |
| 267 | + $label[$selected] = $levels[$selected]; |
| 268 | + # Collect all quality levels of a flag current user can set |
| 269 | + } else { |
| 270 | + foreach( $levels as $i => $name ) { |
| 271 | + # Some levels may be restricted or not applicable... |
| 272 | + if( !RevisionReview::userCan($quality,$i,$config) ) { |
| 273 | + if( $selected == $i ) $selected++; // bump default |
| 274 | + continue; // skip this level |
| 275 | + } else if( $i > 0 ) { |
| 276 | + $minLevel = $i; // first non-zero level number |
| 277 | + } |
| 278 | + $label[$i] = $name; |
| 279 | + } |
| 280 | + } |
| 281 | + $numLevels = count( $label ); |
| 282 | + $form .= Xml::openElement( 'span', array('class' => 'fr-rating-options') ) . "\n"; |
| 283 | + $form .= "<b>" . Xml::tags( 'label', array( 'for' => "wp$quality" ), |
| 284 | + FlaggedRevs::getTagMsg( $quality ) ) . ":</b>\n"; |
| 285 | + # If the sum of qualities of all flags is above 6, use drop down boxes |
| 286 | + # 6 is an arbitrary value choosen according to screen space and usability |
| 287 | + if( $size > 6 ) { |
| 288 | + $attribs = array( 'name' => "wp$quality", 'id' => "wp$quality", 'onchange' => "updateRatingForm()" ) + $toggle; |
| 289 | + $form .= Xml::openElement( 'select', $attribs ); |
| 290 | + foreach( $label as $i => $name ) { |
| 291 | + $optionClass = array( 'class' => "fr-rating-option-$i" ); |
| 292 | + $form .= Xml::option( FlaggedRevs::getTagMsg($name), $i, ($i == $selected), $optionClass )."\n"; |
| 293 | + } |
| 294 | + $form .= Xml::closeElement('select')."\n"; |
| 295 | + # If there are more than two levels, current user gets radio buttons |
| 296 | + } elseif( $numLevels > 2 ) { |
| 297 | + foreach( $label as $i => $name ) { |
| 298 | + $attribs = array( 'class' => "fr-rating-option-$i", 'onchange' => "updateRatingForm()" ); |
| 299 | + $form .= Xml::radioLabel( FlaggedRevs::getTagMsg($name), "wp$quality", $i, "wp$quality".$i, |
| 300 | + ($i == $selected), $attribs ) . "\n"; |
| 301 | + } |
| 302 | + # Otherwise make checkboxes (two levels available for current user) |
| 303 | + } else { |
| 304 | + # If disable, use the current flags; if none, then use the min flag. |
| 305 | + $i = $disabled ? $selected : $minLevel; |
| 306 | + $attribs = array( 'class' => "fr-rating-option-$i", 'onchange' => "updateRatingForm()" ); |
| 307 | + $attribs = $attribs + $toggle + array('value' => $minLevel); |
| 308 | + $form .= Xml::checkLabel( wfMsg( "revreview-{$label[$i]}" ), "wp$quality", "wp$quality", |
| 309 | + ($selected == $i), $attribs ) . "\n"; |
| 310 | + } |
| 311 | + $form .= Xml::closeElement( 'span' ); |
| 312 | + } |
| 313 | + # If there were none, make one checkbox to approve/unapprove |
| 314 | + if( FlaggedRevs::dimensionsEmpty() ) { |
| 315 | + $form .= Xml::openElement( 'span', array('class' => 'fr-rating-options') ) . "\n"; |
| 316 | + $form .= Xml::checkLabel( wfMsg( "revreview-approved" ), "wpApprove", "wpApprove", 1 ) . "\n"; |
| 317 | + $form .= Xml::closeElement( 'span' ); |
| 318 | + } |
| 319 | + return $form; |
| 320 | + } |
246 | 321 | } |