r26342 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r26341‎ | r26342 | r26343 >
Date:01:07, 3 October 2007
Author:aaron
Status:old
Tags:
Comment:
*Allow for no tags (just one level)
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedArticle.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -510,6 +510,15 @@
511511 * @return Array
512512 */
513513 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 ) {
514523 # Set all flags to zero
515524 $flags = array();
516525 foreach( array_keys($this->dimensions) as $tag ) {
@@ -523,7 +532,9 @@
524533 __METHOD__ );
525534 # Iterate through each tag result
526535 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;
528539 }
529540 return $flags;
530541 }
@@ -545,6 +556,9 @@
546557 public function isQuality( $flags ) {
547558 global $wgFlaggedRevTags;
548559
 560+ if( empty($flags) )
 561+ return false;
 562+
549563 foreach( $wgFlaggedRevTags as $f => $v ) {
550564 if( !isset($flags[$f]) || $v > $flags[$f] )
551565 return false;
@@ -559,6 +573,9 @@
560574 public function isPristine( $flags ) {
561575 global $wgFlaggedRevTags, $wgFlaggedRevValues;
562576
 577+ if( empty($flags) )
 578+ return false;
 579+
563580 foreach( $wgFlaggedRevTags as $f => $v ) {
564581 if( !isset($flags[$f]) || $flags[$f] < $wgFlaggedRevValues )
565582 return false;
Index: trunk/extensions/FlaggedRevs/FlaggedArticle.php
@@ -90,10 +90,12 @@
9191 $msg = $quality ? 'revreview-newest-quality' : 'revreview-newest-basic';
9292 $tag .= wfMsgExt($msg, array('parseinline'), $tfrev->fr_rev_id, $time, $revs_since);
9393 # 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+ }
98100 }
99101 }
100102 // Viewing the page normally: override the page
@@ -112,10 +114,12 @@
113115 } else {
114116 $msg = $quality ? 'revreview-quality' : 'revreview-basic';
115117 $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+ }
120124 }
121125 }
122126 # Try the stable page cache
@@ -197,11 +201,13 @@
198202 $msg = $this->isQuality( $flags ) ? 'revreview-newest-quality' : 'revreview-newest-basic';
199203 $tag = wfMsgExt($msg, array('parseinline'), $tfrev->fr_rev_id, $time, $revs_since );
200204 # 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+ }
206212 $wgOut->addHTML( '<div id="mw-revisiontag" class="flaggedrevs_notice plainlinks">' . $tag . '</div>' );
207213 # If this will be autoreviewed, notify the user...
208214 if( !$wgFlaggedRevsAutoReview )
@@ -617,15 +623,16 @@
618624 # Construct some tagging
619625 $msg = $stable ? 'revreview-' : 'revreview-newest-';
620626 $msg .= $quality ? 'quality' : 'basic';
621 - $encRatingLabel = $stable ? '' : ' ' . wfMsgHtml('revreview-oldrating');
622627
623628 $box = ' <a id="mw-revisiontoggle" style="display:none;" href="javascript:toggleRevRatings()">' .
624629 wfMsg('revreview-toggle') . '</a>';
625630 $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>';
630637
631638 return $box;
632639 }
@@ -707,21 +714,8 @@
708715 # Cached results?
709716 if( isset($this->flags[$rev_id]) && $this->flags[$rev_id] )
710717 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 );
726720 # Try to cache results
727721 $this->flags[$rev_id] = true;
728722 $this->revflags[$rev_id] = $flags;

Status & tagging log