Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php |
— | — | @@ -510,6 +510,15 @@ |
511 | 511 | * @return Array |
512 | 512 | */ |
513 | 513 | public function getFlagsForRevision( $rev_id ) { |
| 514 | + return $this->getRevisionTags( $rev_id ); |
| 515 | + } |
| 516 | + |
| 517 | + /** |
| 518 | + * Get flags for a revision |
| 519 | + * @param int $rev_id |
| 520 | + * @return Array |
| 521 | + */ |
| 522 | + public function getRevisionTags( $rev_id ) { |
514 | 523 | # Set all flags to zero |
515 | 524 | $flags = array(); |
516 | 525 | foreach( array_keys($this->dimensions) as $tag ) { |
— | — | @@ -523,7 +532,9 @@ |
524 | 533 | __METHOD__ ); |
525 | 534 | # Iterate through each tag result |
526 | 535 | while( $row = $db->fetchObject($result) ) { |
527 | | - $flags[$row->frt_dimension] = $row->frt_value; |
| 536 | + # Add only currently recognized ones |
| 537 | + if( isset($flags[$row->frt_dimension]) ) |
| 538 | + $flags[$row->frt_dimension] = $row->frt_value; |
528 | 539 | } |
529 | 540 | return $flags; |
530 | 541 | } |
— | — | @@ -545,6 +556,9 @@ |
546 | 557 | public function isQuality( $flags ) { |
547 | 558 | global $wgFlaggedRevTags; |
548 | 559 | |
| 560 | + if( empty($flags) ) |
| 561 | + return false; |
| 562 | + |
549 | 563 | foreach( $wgFlaggedRevTags as $f => $v ) { |
550 | 564 | if( !isset($flags[$f]) || $v > $flags[$f] ) |
551 | 565 | return false; |
— | — | @@ -559,6 +573,9 @@ |
560 | 574 | public function isPristine( $flags ) { |
561 | 575 | global $wgFlaggedRevTags, $wgFlaggedRevValues; |
562 | 576 | |
| 577 | + if( empty($flags) ) |
| 578 | + return false; |
| 579 | + |
563 | 580 | foreach( $wgFlaggedRevTags as $f => $v ) { |
564 | 581 | if( !isset($flags[$f]) || $flags[$f] < $wgFlaggedRevValues ) |
565 | 582 | return false; |
Index: trunk/extensions/FlaggedRevs/FlaggedArticle.php |
— | — | @@ -90,10 +90,12 @@ |
91 | 91 | $msg = $quality ? 'revreview-newest-quality' : 'revreview-newest-basic'; |
92 | 92 | $tag .= wfMsgExt($msg, array('parseinline'), $tfrev->fr_rev_id, $time, $revs_since); |
93 | 93 | # Hide clutter |
94 | | - $tag .= ' <a id="mw-revisiontoggle" style="display:none;" href="javascript:toggleRevRatings()">' . |
95 | | - wfMsg('revreview-toggle') . '</a>'; |
96 | | - $tag .= '<span id="mw-revisionratings" style="display:block;">' . |
97 | | - wfMsg('revreview-oldrating') . $this->addTagRatings( $flags ) . '</span>'; |
| 94 | + if( !empty($flags) ) { |
| 95 | + $tag .= ' <a id="mw-revisiontoggle" style="display:none;" href="javascript:toggleRevRatings()">' . |
| 96 | + wfMsg('revreview-toggle') . '</a>'; |
| 97 | + $tag .= '<span id="mw-revisionratings" style="display:block;">' . |
| 98 | + wfMsg('revreview-oldrating') . $this->addTagRatings( $flags ) . '</span>'; |
| 99 | + } |
98 | 100 | } |
99 | 101 | } |
100 | 102 | // Viewing the page normally: override the page |
— | — | @@ -112,10 +114,12 @@ |
113 | 115 | } else { |
114 | 116 | $msg = $quality ? 'revreview-quality' : 'revreview-basic'; |
115 | 117 | $tag = wfMsgExt($msg, array('parseinline'), $vis_id, $time, $revs_since); |
116 | | - $tag .= ' <a id="mw-revisiontoggle" style="display:none;" href="javascript:toggleRevRatings()">' . |
117 | | - wfMsg('revreview-toggle') . '</a>'; |
118 | | - $tag .= '<span id="mw-revisionratings" style="display:block;">' . |
119 | | - $this->addTagRatings( $flags ) . '</span>'; |
| 118 | + if( !empty($flags) ) { |
| 119 | + $tag .= ' <a id="mw-revisiontoggle" style="display:none;" href="javascript:toggleRevRatings()">' . |
| 120 | + wfMsg('revreview-toggle') . '</a>'; |
| 121 | + $tag .= '<span id="mw-revisionratings" style="display:block;">' . |
| 122 | + $this->addTagRatings( $flags ) . '</span>'; |
| 123 | + } |
120 | 124 | } |
121 | 125 | } |
122 | 126 | # Try the stable page cache |
— | — | @@ -197,11 +201,13 @@ |
198 | 202 | $msg = $this->isQuality( $flags ) ? 'revreview-newest-quality' : 'revreview-newest-basic'; |
199 | 203 | $tag = wfMsgExt($msg, array('parseinline'), $tfrev->fr_rev_id, $time, $revs_since ); |
200 | 204 | # Hide clutter |
201 | | - $tag .= ' <a id="mw-revisiontoggle" style="display:none;" href="javascript:toggleRevRatings()">' . |
202 | | - wfMsg('revreview-toggle') . '</a>'; |
203 | | - $tag .= '<span id="mw-revisionratings" style="display:block;">' . |
204 | | - wfMsg('revreview-oldrating') . $this->addTagRatings( $flags ) . |
205 | | - '</span>'; |
| 205 | + if( !empty($flags) ) { |
| 206 | + $tag .= ' <a id="mw-revisiontoggle" style="display:none;" href="javascript:toggleRevRatings()">' . |
| 207 | + wfMsg('revreview-toggle') . '</a>'; |
| 208 | + $tag .= '<span id="mw-revisionratings" style="display:block;">' . |
| 209 | + wfMsg('revreview-oldrating') . $this->addTagRatings( $flags ) . |
| 210 | + '</span>'; |
| 211 | + } |
206 | 212 | $wgOut->addHTML( '<div id="mw-revisiontag" class="flaggedrevs_notice plainlinks">' . $tag . '</div>' ); |
207 | 213 | # If this will be autoreviewed, notify the user... |
208 | 214 | if( !$wgFlaggedRevsAutoReview ) |
— | — | @@ -617,15 +623,16 @@ |
618 | 624 | # Construct some tagging |
619 | 625 | $msg = $stable ? 'revreview-' : 'revreview-newest-'; |
620 | 626 | $msg .= $quality ? 'quality' : 'basic'; |
621 | | - $encRatingLabel = $stable ? '' : ' ' . wfMsgHtml('revreview-oldrating'); |
622 | 627 | |
623 | 628 | $box = ' <a id="mw-revisiontoggle" style="display:none;" href="javascript:toggleRevRatings()">' . |
624 | 629 | wfMsg('revreview-toggle') . '</a>'; |
625 | 630 | $box .= '<span id="mw-revisionratings">' . |
626 | | - wfMsgExt($msg, array('parseinline'), $tfrev->fr_rev_id, $time, $revs_since) . |
627 | | - $encRatingLabel . |
628 | | - self::addTagRatings( $flags, true, "{$tagClass}a" ) . |
629 | | - '</span>'; |
| 631 | + wfMsgExt($msg, array('parseinline'), $tfrev->fr_rev_id, $time, $revs_since); |
| 632 | + if( !empty($flags) ) { |
| 633 | + $encRatingLabel = $stable ? '' : ' ' . wfMsgHtml('revreview-oldrating'); |
| 634 | + $box .= $encRatingLabel . self::addTagRatings( $flags, true, "{$tagClass}a" ); |
| 635 | + } |
| 636 | + $box .= '</span>'; |
630 | 637 | |
631 | 638 | return $box; |
632 | 639 | } |
— | — | @@ -707,21 +714,8 @@ |
708 | 715 | # Cached results? |
709 | 716 | if( isset($this->flags[$rev_id]) && $this->flags[$rev_id] ) |
710 | 717 | return $this->revflags[$rev_id]; |
711 | | - # Set all flags to zero |
712 | | - $flags = array(); |
713 | | - foreach( array_keys($wgFlaggedRevTags) as $tag ) { |
714 | | - $flags[$tag] = 0; |
715 | | - } |
716 | | - # Grab all the tags for this revision |
717 | | - $dbr = wfGetDB( DB_SLAVE ); |
718 | | - $result = $dbr->select( 'flaggedrevtags', |
719 | | - array( 'frt_dimension', 'frt_value' ), |
720 | | - array( 'frt_rev_id' => $rev_id ), |
721 | | - __METHOD__ ); |
722 | | - # Iterate through each tag result |
723 | | - while( $row = $dbr->fetchObject($result) ) { |
724 | | - $flags[$row->frt_dimension] = $row->frt_value; |
725 | | - } |
| 718 | + # Get the flags |
| 719 | + $flags = $this->getRevisionTags( $rev_id ); |
726 | 720 | # Try to cache results |
727 | 721 | $this->flags[$rev_id] = true; |
728 | 722 | $this->revflags[$rev_id] = $flags; |