r24883 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24882‎ | r24883 | r24884 >
Date:20:18, 17 August 2007
Author:aaron
Status:old
Tags:
Comment:
*Remove comment box for editors
*Record SHA-1 stuff
*Some scope tweaks
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevsPage_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -428,7 +428,7 @@
429429 * @returns string
430430 * Generates a review box using a table using addTagRatings()
431431 */
432 - function prettyRatingBox( $tfrev, $flags, $revs_since, $simpleTag=false ) {
 432+ public function prettyRatingBox( $tfrev, $flags, $revs_since, $simpleTag=false ) {
433433 global $wgLang, $wgUser;
434434
435435 $box = '';
@@ -620,7 +620,6 @@
621621 // Only trigger on article view for content pages, not for protect/delete/hist
622622 if( !$article || !$article->exists() || !$article->mTitle->isContentPage() || $action !='view' )
623623 return true;
624 -
625624 // User must have review rights
626625 if( !$wgUser->isAllowed( 'review' ) )
627626 return true;
@@ -630,9 +629,8 @@
631630 if( $parserOutput ) {
632631 // Clear older, incomplete, cached versions
633632 // We need the IDs of templates and timestamps of images used
634 - if( !isset($parserOutput->mTemplateIds) || !isset($parserOutput->mImageTimestamps) ) {
 633+ if( !isset($parserOutput->mTemplateIds) || !isset($parserOutput->mImageSHA1Keys) )
635634 $article->mTitle->invalidateCache();
636 - }
637635 }
638636 return true;
639637 }
@@ -707,7 +705,10 @@
708706 wfProfileOut( $fname );
709707 return true;
710708 }
711 -
 709+
 710+ /**
 711+ * Select the desired templates based on the selected stable revision IDs
 712+ */
712713 static function parserFetchStableTemplate( $parser, $title, &$skip, &$id ) {
713714 // Trigger for stable version parsing only
714715 if( !isset($parser->isStable) || !$parser->isStable )
@@ -719,7 +720,7 @@
720721 array('ft_rev_id' => $parser->mRevisionId,
721722 'ft_namespace' => $title->getNamespace(), 'ft_title' => $title->getDBkey() ),
722723 __METHOD__ );
723 -
 724+
724725 if( !$id ) {
725726 if( $id === false )
726727 $parser->includesMatched = false; // May want to give an error
@@ -728,12 +729,14 @@
729730 }
730731 return true;
731732 }
732 -
 733+
 734+ /**
 735+ * Select the desired images based on the selected stable revision times/SHA-1s
 736+ */
733737 static function parserMakeStableImageLink( $parser, $nt, &$skip, &$time ) {
734738 // Trigger for stable version parsing only
735739 if( !isset($parser->isStable) || !$parser->isStable )
736740 return true;
737 -
738741 // Only called to make fr_text, right after template/image specifiers
739742 // are added to the DB. Slaves may not have it yet...
740743 $dbw = wfGetDB( DB_MASTER );
@@ -749,7 +752,10 @@
750753 }
751754 return true;
752755 }
753 -
 756+
 757+ /**
 758+ * Select the desired images based on the selected stable revision times/SHA-1s
 759+ */
754760 static function galleryFindStableFileTime( $ig, $nt, &$time ) {
755761 // Trigger for stable version parsing only
756762 if( !isset($ig->isStable) || !$ig->isStable )
@@ -763,7 +769,10 @@
764770
765771 return true;
766772 }
767 -
 773+
 774+ /**
 775+ * Flag of an image galley as stable
 776+ */
768777 static function parserMakeGalleryStable( $parser, $ig ) {
769778 // Trigger for stable version parsing only
770779 if( !isset($parser->isStable) || !$parser->isStable )
@@ -773,25 +782,32 @@
774783
775784 return true;
776785 }
777 -
 786+
 787+ /**
 788+ * Insert image timestamps/SHA-1 keys into parser output
 789+ */
778790 static function parserInjectImageTimestamps( $parser, &$text ) {
779 - $parser->mOutput->mImageTimestamps = array();
 791+ $parser->mOutput->mImageSHA1Keys = array();
780792 # Fetch the timestamps of the images
781793 if( !empty($parser->mOutput->mImages) ) {
782794 $dbr = wfGetDB( DB_SLAVE );
783 - $res = $dbr->select('image', array('img_name','img_timestamp'),
 795+ $res = $dbr->select('image', array('img_name','img_timestamp','img_sha1'),
784796 array('img_name IN(' . $dbr->makeList( array_keys($parser->mOutput->mImages) ) . ')'),
785 - __METHOD__ );
 797+ __METHOD__ );
786798
787799 while( $row = $dbr->fetchObject($res) ) {
788 - $parser->mOutput->mImageTimestamps[$row->img_name] = $row->img_timestamp;
 800+ $parser->mOutput->mImageSHA1Keys[$row->img_name] = array();
 801+ $parser->mOutput->mImageSHA1Keys[$row->img_name][$row->img_timestamp] = $row->img_sha1;
789802 }
790803 }
791804 return true;
792805 }
793 -
 806+
 807+ /**
 808+ * Insert image timestamps/SHA-1s into page output
 809+ */
794810 static function outputInjectImageTimestamps( $out, $parserOutput ) {
795 - $out->mImageTimestamps = $parserOutput->mImageTimestamps;
 811+ $out->mImageSHA1Keys = $parserOutput->mImageSHA1Keys;
796812
797813 return true;
798814 }
@@ -802,7 +818,6 @@
803819 */
804820 public static function injectReviewDiffURLParams( $article, &$sectionanchor, &$extraq ) {
805821 global $wgReviewChangesAfterEdit, $wgFlaggedRevs, $wgUser;
806 -
807822 # Was this already autoreviewed?
808823 if( $wgFlaggedRevs->skipReviewDiff )
809824 return true;
@@ -932,12 +947,15 @@
933948 }
934949 }
935950 # Image -> timestamp mapping
936 - foreach( $poutput->mImageTimestamps as $dbkey => $timestamp ) {
937 - $imgset[] = array(
938 - 'fi_rev_id' => $rev->getId(),
939 - 'fi_name' => $dbkey,
940 - 'fi_img_timestamp' => $timestamp
941 - );
 951+ foreach( $poutput->mImageTimestamps as $dbkey => $timeAndSHA1 ) {
 952+ foreach( $timeAndSHA1 as $time => $sha1 ) {
 953+ $imgset[] = array(
 954+ 'fi_rev_id' => $rev->getId(),
 955+ 'fi_name' => $img_title->getDBKey(),
 956+ 'fi_img_timestamp' => $timestamp,
 957+ 'fr_img_sha1' => $sha1
 958+ );
 959+ }
942960 }
943961
944962 $dbw = wfGetDB( DB_MASTER );
@@ -1515,14 +1533,14 @@
15161534 $form .= $options;
15171535 $form .= "</select>\n";
15181536 }
1519 - if( $wgFlaggedRevComments ) {
 1537+ if( $wgFlaggedRevComments && $wgUser->isAllowed( 'validate' ) ) {
15201538 $form .= "<br/><p>" . wfMsgHtml( 'revreview-notes' ) . "</p>" .
15211539 "<p><textarea tabindex='1' name='wpNotes' id='wpNotes' rows='2' cols='80' style='width:100%'></textarea>" .
15221540 "</p>\n";
15231541 }
15241542
15251543 $imageParams = $templateParams = '';
1526 - if( !isset($out->mTemplateIds) || !isset($out->mImageTimestamps) ) {
 1544+ if( !isset($out->mTemplateIds) || !isset($out->mImageSHA1Keys) ) {
15271545 return; // something went terribly wrong...
15281546 }
15291547 // Hack, add NS:title -> rev ID mapping
@@ -1534,17 +1552,20 @@
15351553 }
15361554 $form .= Xml::hidden( 'templateParams', $templateParams ) . "\n";
15371555 // Hack, image -> timestamp mapping
1538 - foreach( $out->mImageTimestamps as $dbkey => $timestamp ) {
1539 - $imageParams .= $dbkey . "|" . $timestamp . "#";
 1556+ foreach( $out->mImageSHA1Keys as $dbkey => $timeAndSHA1 ) {
 1557+ foreach( $timeAndSHA1 as $time => $sha1 ) {
 1558+ $imageParams .= $dbkey . "|" . $time . "#" . $sha1 . "#";
 1559+ }
15401560 }
1541 - $form .= Xml::hidden( 'imageParams', $imageParams ) . "\n";
 1561+ $form .= Xml::hidden( 'imageParams', $imageParams ) . "\n";
15421562
15431563 $watchLabel = wfMsgExt('watchthis', array('parseinline'));
15441564 $watchAttribs = array('accesskey' => wfMsg( 'accesskey-watch' ), 'id' => 'wpWatchthis');
15451565 $watchChecked = ( $wgFlaggedRevsWatch && $wgUser->getOption( 'watchdefault' ) || $wgTitle->userIsWatching() );
 1566+ // Not much to say unless you are a validator
 1567+ if( $wgUser->isAllowed( 'validate' ) )
 1568+ $form .= "<p>".wfInputLabel( wfMsgHtml( 'revreview-log' ), 'wpReason', 'wpReason', 60 )."</p>\n";
15461569
1547 - $form .= "<p>".wfInputLabel( wfMsgHtml( 'revreview-log' ), 'wpReason', 'wpReason', 60 )."</p>\n";
1548 -
15491570 $form .= "<p>&nbsp;&nbsp;&nbsp;".Xml::check( 'wpWatchthis', $watchChecked, $watchAttribs );
15501571 $form .= "&nbsp;<label for='wpWatchthis'".$skin->tooltipAndAccesskey('watch').">{$watchLabel}</label>";
15511572
Index: trunk/extensions/FlaggedRevs/FlaggedRevsPage_body.php
@@ -58,9 +58,11 @@
5959 $this->templateParams = $wgRequest->getVal( 'templateParams' );
6060 $this->imageParams = $wgRequest->getVal( 'imageParams' );
6161 // Log comment
62 - $this->comment = $wgRequest->getText( 'wpReason' );
63 - // Additional notes
64 - $this->notes = $wgFlaggedRevs->allowComments() ? $wgRequest->getText('wpNotes') : '';
 62+ $this->comment = $wgUser->isAllowed('validate') ?
 63+ $wgRequest->getText( 'wpReason' ) : '';
 64+ // Additional notes (displayed at bottom of page)
 65+ $this->notes = ($wgFlaggedRevs->allowComments() && $wgUser->isAllowed('validate')) ?
 66+ $wgRequest->getText('wpNotes') : '';
6567 // Get the revision's current flags, if any
6668 $this->oflags = $wgFlaggedRevs->getFlagsForRevision( $this->oldid );
6769 // Get our accuracy/quality dimensions
@@ -160,9 +162,6 @@
161163 $formradios[$tag][] = array( "revreview-$tag-$i", "wp$tag", $i );
162164 }
163165 }
164 - $items = array(
165 - wfInputLabel( wfMsgHtml( 'revreview-log' ), 'wpReason', 'wpReason', 60 ),
166 - wfSubmitButton( wfMsgHtml( 'revreview-submit' ) ) );
167166 $hidden = array(
168167 wfHidden( 'wpEditToken', $wgUser->editToken() ),
169168 wfHidden( 'target', $this->page->getPrefixedText() ),
@@ -193,15 +192,17 @@
194193 }
195194 $form .= '</tr></table></fieldset>';
196195 // Add box to add live notes to a flagged revision
197 - if( $wgFlaggedRevComments ) {
 196+ if( $wgFlaggedRevComments && $wgUser->isAllowed( 'validate' ) ) {
198197 $form .= "<fieldset><legend>" . wfMsgHtml( 'revreview-notes' ) . "</legend>" .
199198 "<textarea tabindex='1' name='wpNotes' id='wpNotes' rows='3' cols='80' style='width:100%'>$this->notes</textarea>" .
200199 "</fieldset>";
201200 }
 201+ // Not much to say unless you are a validator
 202+ if( $wgUser->isAllowed( 'validate' ) )
 203+ $form .= '<p>'.wfInputLabel( wfMsgHtml( 'revreview-log' ), 'wpReason', 'wpReason', 60 ).'</p>';
202204
203 - foreach( $items as $item ) {
204 - $form .= '<p>' . $item . '</p>';
205 - }
 205+ $form .= '<p>'.wfSubmitButton( wfMsgHtml( 'revreview-submit' ) ).'</p>';
 206+
206207 foreach( $hidden as $item ) {
207208 $form .= $item;
208209 }
@@ -328,22 +329,25 @@
329330 $imageMap = explode('#',trim($this->imageParams) );
330331 foreach( $imageMap as $image ) {
331332 if( !$image ) continue;
332 - $m = explode('|',$image,2);
 333+ $m = explode('|',$image,3);
 334+ # Expand our parameters ... <name>#<timestamp>#<key>
 335+ if( !isset($m[0]) || !isset($m[1]) || !isset($m[2]) || !$m[0] )
 336+ continue;
333337
334 - if( !isset($m[0]) || !isset($m[1]) || !$m[0] ) continue;
 338+ list($dbkey,$timestamp,$key) = $m;
335339
336 - list($dbkey,$timestamp) = $m;
 340+ if( in_array($dbkey,$images) ) continue; // No dups!
337341
338 - if( in_array($dbkey,$images) ) continue; // No dups!
339342 $images[] = $dbkey;
340343
341 - $img_title = Title::makeTitle( NS_IMAGE, $dbkey ); // Normalize this to be sure...
 344+ $img_title = Title::makeTitle( NS_IMAGE, $dbkey ); // Normalize
342345 if( is_null($img_title) ) continue; // Page must exist!
343346
344347 $imgset[] = array(
345348 'fi_rev_id' => $rev->getId(),
346349 'fi_name' => $img_title->getDBKey(),
347 - 'fi_img_timestamp' => $timestamp
 350+ 'fi_img_timestamp' => $timestamp,
 351+ 'fr_img_sha1' => $key
348352 );
349353 }
350354
@@ -813,4 +817,3 @@
814818 return( "{$link} {$stxt}" );
815819 }
816820 }
817 -

Status & tagging log