r22113 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22112‎ | r22113 | r22114 >
Date:18:01, 11 May 2007
Author:aaron
Status:old
Tags:
Comment:
*Updating links tables on review, some housekeeping
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
@@ -155,12 +155,13 @@
156156 public static function expandText( $text, $title ) {
157157 global $wgParser, $wgTitle;
158158
159 - if ( $text==false ) return;
 159+ if ( !$text ) return '';
160160
161161 $options = new ParserOptions;
162162 $options->setRemoveComments( true );
163163 $options->setMaxIncludeSize( self::MAX_INCLUDE_SIZE );
164164 $output = $wgParser->preprocess( $text, $title, $options );
 165+
165166 return $output;
166167 }
167168
@@ -275,52 +276,17 @@
276277 wfProfileIn( __METHOD__ );
277278
278279 $db = wfGetDB( DB_SLAVE );
279 - $result = $db->select(
280 - array('revision'),
281 - array('rev_id'),
 280+ $count = $db->selectField('revision',
 281+ 'COUNT(*)',
282282 array('rev_page' => $page_id, "rev_id > $from_rev"),
283283 __METHOD__ );
284 - // Return count of revisions
285 - return $db->numRows($result);
 284+
 285+ return $count;
286286 }
287 -
288 - /**
289 - * @param int $rev_id
290 - * Return an array output of the flags for a given revision
291 - */
292 - public function getFlagsForRevision( $rev_id ) {
293 - global $wgFlaggedRevTags;
294 -
295 - wfProfileIn( __METHOD__ );
296 - // Cached results?
297 - if ( isset($this->flags[$rev_id]) && $this->flags[$rev_id] )
298 - return $this->revflags[$rev_id];
299 - // Set all flags to zero
300 - $flags = array();
301 - foreach( array_keys($wgFlaggedRevTags) as $tag ) {
302 - $flags[$tag] = 0;
303 - }
304 - $db = wfGetDB( DB_SLAVE );
305 - // Grab all the tags for this revision
306 - $result = $db->select(
307 - array('flaggedrevtags'),
308 - array('frt_dimension', 'frt_value'),
309 - array('frt_rev_id' => $rev_id),
310 - __METHOD__ );
311 - // Iterate through each tag result
312 - while ( $row = $db->fetchObject($result) ) {
313 - $flags[$row->frt_dimension] = $row->frt_value;
314 - }
315 - // Try to cache results
316 - $this->flags[$rev_id] = true;
317 - $this->revflags[$rev_id] = $flags;
318 -
319 - return $flags;
320 - }
321287
322288 /**
323289 * static counterpart for getOverridingRev()
324 - */
 290+ */
325291 public static function getOverridingPageRev( $article ) {
326292 if ( !is_object($article) )
327293 return null;
@@ -351,6 +317,33 @@
352318 return $row;
353319 }
354320
 321+ /**
 322+ * static counterpart for getFlagsForRevision()
 323+ */
 324+ public static function getFlagsForPageRev( $rev_id ) {
 325+ global $wgFlaggedRevTags;
 326+
 327+ wfProfileIn( __METHOD__ );
 328+ // Set all flags to zero
 329+ $flags = array();
 330+ foreach( array_keys($wgFlaggedRevTags) as $tag ) {
 331+ $flags[$tag] = 0;
 332+ }
 333+ $db = wfGetDB( DB_SLAVE );
 334+ // Grab all the tags for this revision
 335+ $result = $db->select(
 336+ array('flaggedrevtags'),
 337+ array('frt_dimension', 'frt_value'),
 338+ array('frt_rev_id' => $rev_id),
 339+ __METHOD__ );
 340+ // Iterate through each tag result
 341+ while ( $row = $db->fetchObject($result) ) {
 342+ $flags[$row->frt_dimension] = $row->frt_value;
 343+ }
 344+
 345+ return $flags;
 346+ }
 347+
355348 public function addTagRatings( $flags ) {
356349 global $wgFlaggedRevTags;
357350 $tag = "<p>";
@@ -518,24 +511,24 @@
519512 __METHOD__ );
520513 }
521514
522 - function extraLinksUpdate( &$article ) {
 515+ public static function extraLinksUpdate( &$article ) {
523516 $fname = 'FlaggedRevs::extraLinksUpdate';
524517 wfProfileIn( $fname );
525518 # Check if this page has a stable version
526 - $sv = $this->getOverridingPageRev( $article );
 519+ $sv = self::getOverridingPageRev( $article );
527520 if ( !$sv ) return;
528521 # Retrieve the text
529 - $text = $this->getFlaggedRevText( $sv->fr_rev_id );
 522+ $text = self::getFlaggedRevText( $sv->fr_rev_id );
530523 # Parse the revision
531524 $options = ParserOptions::newFromUser($wgUser);
532 - $poutput = $this->parseStableText( $article->mTitle, $text, $sv->fr_rev_id, $options, $sv->fr_timestamp );
533 -
 525+ $poutput = self::parseStableText( $article->mTitle, $text, $sv->fr_rev_id, $options, $sv->fr_timestamp );
 526+
534527 # Update the links tables to include these
535528 # We want the UNION of links between the current
536529 # and stable version. Therefore, we only care about
537530 # links that are in the stable version and not the regular one.
538531 $u = new LinksUpdate( $article->mTitle, $poutput );
539 -
 532+
540533 # Page links
541534 $existing = $u->getExistingLinks();
542535 $u->incrTableUpdate( 'pagelinks', 'pl', array(),
@@ -579,9 +572,8 @@
580573 if ( $u->mRecursive ) {
581574 $u->queueRecursiveJobs();
582575 }
583 -
 576+
584577 wfProfileOut( $fname );
585 -
586578 }
587579
588580 /**
@@ -643,7 +635,7 @@
644636 return;
645637 // Grab page and rev ids
646638 $pageid = $article->getId();
647 - $revid = ( $article->mRevision ) ? $article->mRevision->mId : $article->getLatest();
 639+ $revid = $article->mRevision ? $article->mRevision->mId : $article->getLatest();
648640 // There must be a valid rev ID
649641 if( !$revid ) return;
650642
@@ -661,7 +653,7 @@
662654 } else if( !is_null($tfrev) ) {
663655 global $wgParser, $wgLang;
664656 // Get flags and date
665 - $flags = parent::getFlagsForRevision( $tfrev->fr_rev_id );
 657+ $flags = $this->getFlagsForRevision( $tfrev->fr_rev_id );
666658 $time = $wgLang->timeanddate( wfTimestamp(TS_MW, $tfrev->fr_timestamp), true );
667659 // Looking at some specific old rev or if flagged revs override only for anons
668660 if( !$this->pageOverride() ) {
@@ -673,7 +665,7 @@
674666 $oldid = ($revid > $tfrev->fr_rev_id) ? $tfrev->fr_rev_id : $revid;
675667 $diff = ($revid > $tfrev->fr_rev_id) ? $revid : $tfrev->fr_rev_id;
676668 # Is this revision flagged?
677 - $flags2 = parent::getFlagsForRevision( $revid );
 669+ $flags2 = $this->getFlagsForRevision( $revid );
678670 $app = false;
679671 foreach ( $flags2 as $f => $v ) {
680672 if ( $v > 0 ) $app=true;
@@ -756,7 +748,7 @@
757749 if( is_object($tfrev) ) {
758750 global $wgParser, $wgLang;
759751 $time = $wgLang->timeanddate( wfTimestamp(TS_MW, $tfrev->fr_timestamp), true );
760 - $flags = parent::getFlagsForRevision( $tfrev->fr_rev_id );
 752+ $flags = $this->getFlagsForRevision( $tfrev->fr_rev_id );
761753 # Looking at some specific old rev
762754 if( $wgRequest->getVal('oldid') ) {
763755 if( $revid==$tfrev->fr_rev_id ) {
@@ -766,7 +758,7 @@
767759 $oldid = ($revid > $tfrev->fr_rev_id) ? $tfrev->fr_rev_id : $revid;
768760 $diff = ($revid > $tfrev->fr_rev_id) ? $revid : $tfrev->fr_rev_id;
769761 # Is this revision flagged?
770 - $flags2 = parent::getFlagsForRevision( $revid );
 762+ $flags2 = $this->getFlagsForRevision( $revid );
771763 $app = false;
772764 foreach ( $flags2 as $f => $v ) {
773765 if ( $v > 0 ) $app=true;
@@ -789,7 +781,7 @@
790782 $wgOut->addHTML( '<div class="flaggedrevs_tag1 plainlinks">' . $tag . '</div><br/>' );
791783 }
792784 }
793 -
 785+
794786 function addReviewForm( &$out ) {
795787 global $wgArticle, $action;
796788
@@ -805,101 +797,7 @@
806798 // Note: overrides are never done when viewing with "oldid="
807799 $this->addQuickReview( $revId, false );
808800 }
809 -
810 - /**
811 - * Get latest quality rev, if not, the latest reviewed one
812 - */
813 - function getOverridingRev( $article=NULL ) {
814 - if( !$row = $this->getLatestQualityRev( $article ) ) {
815 - if( !$row = $this->getLatestStableRev( $article ) ) {
816 - return null;
817 - }
818 - }
819 - return $row;
820 - }
821801
822 - /**
823 - * Get latest flagged revision that meets requirments
824 - * per the $wgFlaggedRevTags variable
825 - * This passes rev_deleted revisions
826 - * This is based on the current article and caches results
827 - * Accepts an argument because of the fact that the article
828 - * object for edit mode is part of the editform; insert only
829 - * the article object for the current page!
830 - * @output array ( rev, flags )
831 - */
832 - function getLatestQualityRev( $article=NULL ) {
833 - global $wgArticle;
834 -
835 - wfProfileIn( __METHOD__ );
836 -
837 - $article = $article ? $article : $wgArticle;
838 - $title = $article->getTitle();
839 - // Cached results available?
840 - if ( isset($this->stablefound) ) {
841 - return ( $this->stablefound ) ? $this->stablerev : null;
842 - }
843 - $dbr = wfGetDB( DB_SLAVE );
844 - // Skip deleted revisions
845 - $result = $dbr->select(
846 - array('flaggedrevs', 'revision'),
847 - array('fr_rev_id', 'fr_user', 'fr_timestamp', 'fr_comment', 'rev_timestamp'),
848 - array('fr_namespace' => $title->getNamespace(), 'fr_title' => $title->getDBkey(), 'fr_quality >= 1',
849 - 'fr_rev_id = rev_id', 'rev_page' => $article->getId(), 'rev_deleted=0'),
850 - __METHOD__,
851 - array('ORDER BY' => 'fr_rev_id DESC', 'LIMIT' => 1 ) );
852 - // Do we have one?
853 - if ( $row = $dbr->fetchObject($result) ) {
854 - $this->stablefound = true;
855 - $this->stablerev = $row;
856 - return $row;
857 - } else {
858 - $this->stablefound = false;
859 - return null;
860 - }
861 - }
862 -
863 - /**
864 - * Get latest flagged revision
865 - * This passes rev_deleted revisions
866 - * This is based on the current article and caches results
867 - * Accepts an argument because of the fact that the article
868 - * object for edit mode is part of the editform; insert only
869 - * the article object for the current page!
870 - * The cache here doesn't make sense for arbitrary articles
871 - * @output array ( rev, flags )
872 - */
873 - function getLatestStableRev( $article=NULL ) {
874 - global $wgArticle;
875 -
876 - wfProfileIn( __METHOD__ );
877 -
878 - $article = $article ? $article : $wgArticle;
879 - $title = $article->getTitle();
880 - // Cached results available?
881 - if ( isset($this->latestfound) ) {
882 - return ( $this->latestfound ) ? $this->latestrev : NULL;
883 - }
884 - $dbr = wfGetDB( DB_SLAVE );
885 - // Skip deleted revisions
886 - $result = $dbr->select(
887 - array('flaggedrevs', 'revision'),
888 - array('fr_rev_id', 'fr_user', 'fr_timestamp', 'fr_comment', 'rev_timestamp'),
889 - array('fr_namespace' => $title->getNamespace(), 'fr_title' => $title->getDBkey(),
890 - 'fr_rev_id = rev_id', 'rev_page' => $article->getId(), 'rev_deleted=0'),
891 - __METHOD__,
892 - array('ORDER BY' => 'fr_rev_id DESC', 'LIMIT' => 1 ) );
893 - // Do we have one?
894 - if ( $row = $dbr->fetchObject($result) ) {
895 - $this->latestfound = true;
896 - $this->latestrev = $row;
897 - return $row;
898 - } else {
899 - $this->latestfound = false;
900 - return null;
901 - }
902 - }
903 -
904802 function setPermaLink( &$sktmp, &$nav_urls, &$oldid, &$revid ) {
905803 global $wgArticle, $wgTitle, $action;
906804 // Only trigger on article view, not for protect/delete/hist
@@ -963,14 +861,14 @@
964862 }
965863
966864 function addQuickReview( $id, $ontop=false ) {
967 - global $wgOut, $wgTitle, $wgUser, $wgScript, $wgFlaggedRevComments, $wgArticle, $wgRequest;
 865+ global $wgOut, $wgTitle, $wgUser, $wgFlaggedRevComments, $wgArticle, $wgRequest;
968866 // Hack, we don't want two forms!
969867 if( isset($this->formCount) && $this->formCount > 0 ) return;
970868 $this->formCount = 1;
971869
972870 if( !$wgUser->isAllowed( 'review' ) ) return;
973871 // Already flagged?
974 - $flags = parent::getFlagsForRevision( $id );
 872+ $flags = $this->getFlagsForRevision( $id );
975873
976874 $reviewtitle = SpecialPage::getTitleFor( 'Revisionreview' );
977875 $action = $reviewtitle->escapeLocalUrl( 'action=submit' );
@@ -1050,8 +948,136 @@
1051949 '</strong></small></tt>';
1052950 }
1053951 }
1054 - }
 952+ }
1055953
 954+ /**
 955+ * Get latest quality rev, if not, the latest reviewed one
 956+ */
 957+ function getOverridingRev( $article=NULL ) {
 958+ if( !$row = $this->getLatestQualityRev( $article ) ) {
 959+ if( !$row = $this->getLatestStableRev( $article ) ) {
 960+ return null;
 961+ }
 962+ }
 963+ return $row;
 964+ }
 965+
 966+ /**
 967+ * Get latest flagged revision that meets requirments
 968+ * per the $wgFlaggedRevTags variable
 969+ * This passes rev_deleted revisions
 970+ * This is based on the current article and caches results
 971+ * Accepts an argument because of the fact that the article
 972+ * object for edit mode is part of the editform; insert only
 973+ * the article object for the current page!
 974+ * @output array ( rev, flags )
 975+ */
 976+ function getLatestQualityRev( $article=NULL ) {
 977+ global $wgArticle;
 978+
 979+ wfProfileIn( __METHOD__ );
 980+
 981+ $article = $article ? $article : $wgArticle;
 982+ $title = $article->getTitle();
 983+ // Cached results available?
 984+ if ( isset($this->stablefound) ) {
 985+ return ( $this->stablefound ) ? $this->stablerev : null;
 986+ }
 987+ $dbr = wfGetDB( DB_SLAVE );
 988+ // Skip deleted revisions
 989+ $result = $dbr->select(
 990+ array('flaggedrevs', 'revision'),
 991+ array('fr_rev_id', 'fr_user', 'fr_timestamp', 'fr_comment', 'rev_timestamp'),
 992+ array('fr_namespace' => $title->getNamespace(), 'fr_title' => $title->getDBkey(), 'fr_quality >= 1',
 993+ 'fr_rev_id = rev_id', 'rev_page' => $article->getId(), 'rev_deleted=0'),
 994+ __METHOD__,
 995+ array('ORDER BY' => 'fr_rev_id DESC', 'LIMIT' => 1 ) );
 996+ // Do we have one?
 997+ if ( $row = $dbr->fetchObject($result) ) {
 998+ $this->stablefound = true;
 999+ $this->stablerev = $row;
 1000+ return $row;
 1001+ } else {
 1002+ $this->stablefound = false;
 1003+ return null;
 1004+ }
 1005+ }
 1006+
 1007+ /**
 1008+ * Get latest flagged revision
 1009+ * This passes rev_deleted revisions
 1010+ * This is based on the current article and caches results
 1011+ * Accepts an argument because of the fact that the article
 1012+ * object for edit mode is part of the editform; insert only
 1013+ * the article object for the current page!
 1014+ * The cache here doesn't make sense for arbitrary articles
 1015+ * @output array ( rev, flags )
 1016+ */
 1017+ function getLatestStableRev( $article=NULL ) {
 1018+ global $wgArticle;
 1019+
 1020+ wfProfileIn( __METHOD__ );
 1021+
 1022+ $article = $article ? $article : $wgArticle;
 1023+ $title = $article->getTitle();
 1024+ // Cached results available?
 1025+ if ( isset($this->latestfound) ) {
 1026+ return ( $this->latestfound ) ? $this->latestrev : NULL;
 1027+ }
 1028+ $dbr = wfGetDB( DB_SLAVE );
 1029+ // Skip deleted revisions
 1030+ $result = $dbr->select(
 1031+ array('flaggedrevs', 'revision'),
 1032+ array('fr_rev_id', 'fr_user', 'fr_timestamp', 'fr_comment', 'rev_timestamp'),
 1033+ array('fr_namespace' => $title->getNamespace(), 'fr_title' => $title->getDBkey(),
 1034+ 'fr_rev_id = rev_id', 'rev_page' => $article->getId(), 'rev_deleted=0'),
 1035+ __METHOD__,
 1036+ array('ORDER BY' => 'fr_rev_id DESC', 'LIMIT' => 1 ) );
 1037+ // Do we have one?
 1038+ if ( $row = $dbr->fetchObject($result) ) {
 1039+ $this->latestfound = true;
 1040+ $this->latestrev = $row;
 1041+ return $row;
 1042+ } else {
 1043+ $this->latestfound = false;
 1044+ return null;
 1045+ }
 1046+ }
 1047+
 1048+ /**
 1049+ * @param int $rev_id
 1050+ * Return an array output of the flags for a given revision
 1051+ */
 1052+ public function getFlagsForRevision( $rev_id ) {
 1053+ global $wgFlaggedRevTags;
 1054+
 1055+ wfProfileIn( __METHOD__ );
 1056+ // Cached results?
 1057+ if ( isset($this->flags[$rev_id]) && $this->flags[$rev_id] )
 1058+ return $this->revflags[$rev_id];
 1059+ // Set all flags to zero
 1060+ $flags = array();
 1061+ foreach( array_keys($wgFlaggedRevTags) as $tag ) {
 1062+ $flags[$tag] = 0;
 1063+ }
 1064+ $db = wfGetDB( DB_SLAVE );
 1065+ // Grab all the tags for this revision
 1066+ $result = $db->select(
 1067+ array('flaggedrevtags'),
 1068+ array('frt_dimension', 'frt_value'),
 1069+ array('frt_rev_id' => $rev_id),
 1070+ __METHOD__ );
 1071+ // Iterate through each tag result
 1072+ while ( $row = $db->fetchObject($result) ) {
 1073+ $flags[$row->frt_dimension] = $row->frt_value;
 1074+ }
 1075+ // Try to cache results
 1076+ $this->flags[$rev_id] = true;
 1077+ $this->revflags[$rev_id] = $flags;
 1078+
 1079+ return $flags;
 1080+ }
 1081+
10561082 }
10571083
10581084 $flaggedrevs = new FlaggedRevs();
Index: trunk/extensions/FlaggedRevs/FlaggedRevsPage.body.php
@@ -43,7 +43,7 @@
4444 // Additional notes
4545 $this->notes = ($wgFlaggedRevComments) ? $wgRequest->getText('wpNotes') : '';
4646 // Get the revision's current flags, if any
47 - $this->oflags = FlaggedRevs::getFlagsForRevision( $this->oldid );
 47+ $this->oflags = FlaggedRevs::getFlagsForPageRev( $this->oldid );
4848 // Get our accuracy/quality dimensions
4949 $this->dims = array();
5050 $this->upprovedTags = 0;
@@ -289,6 +289,10 @@
290290 // Update the article review log
291291 $this->updateLog( $this->page, $this->dims, $this->comment, $this->oldid, true );
292292
 293+ # Update our links if needed
 294+ $article = new Article( $this->page );
 295+ FlaggedRevs::extraLinksUpdate( $article );
 296+
293297 # Clear the cache...
294298 $this->page->invalidateCache();
295299 # Purge squid for this page only
@@ -320,6 +324,10 @@
321325 // Update the article review log
322326 $this->updateLog( $this->page, $this->dims, $this->comment, $this->oldid, false );
323327
 328+ # Update our links if needed
 329+ $article = new Article( $this->page );
 330+ FlaggedRevs::extraLinksUpdate( $article );
 331+
324332 # Clear the cache...
325333 $this->page->invalidateCache();
326334 # Purge squid for this page only
@@ -435,7 +443,7 @@
436444 // Modifier instance
437445 $RevFlagging = new FlaggedRevs();
438446 // Get flags and date
439 - $flags = $RevFlagging->getFlagsForRevision( $frev->fr_rev_id );
 447+ $flags = FlaggedRevs::getFlagsForPageRev( $frev->fr_rev_id );
440448 $time = $wgLang->timeanddate( wfTimestamp(TS_MW, $frev->fr_timestamp), true );
441449 // We will be looking at the reviewed revision...
442450 $tag = wfMsgExt('revreview-static', array('parse'), urlencode($page->getPrefixedText()), $time, $page->getPrefixedText());