r35231 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r35230‎ | r35231 | r35232 >
Date:16:47, 23 May 2008
Author:aaron
Status:old
Tags:
Comment:
* Add $wgFlaggedRevsVisible back. Made for third-party use.
* Add hook to JOIN for data for page history, rather than query spam
* Fix a panty load of E_STRICT errors
* Tweak variable name
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedArticle.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.class.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/phase3/includes/PageHistory.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/PageHistory.php
@@ -44,6 +44,10 @@
4545 function getArticle() {
4646 return $this->mArticle;
4747 }
 48+
 49+ function getTitle() {
 50+ return $this->mTitle;
 51+ }
4852
4953 /**
5054 * As we use the same small set of messages in various methods and that
@@ -595,12 +599,14 @@
596600 }
597601
598602 function getQueryInfo() {
599 - return array(
600 - 'tables' => 'revision',
 603+ $queryInfo = array(
 604+ 'tables' => array('revision'),
601605 'fields' => Revision::selectFields(),
602606 'conds' => array('rev_page' => $this->mPageHistory->mTitle->getArticleID() ),
603 - 'options' => array( 'USE INDEX' => 'page_timestamp' )
 607+ 'options' => array( 'USE INDEX' => array('revision','page_timestamp') )
604608 );
 609+ wfRunHooks( 'PageHistoryPager::getQueryInfo', array( &$this, &$queryInfo ) );
 610+ return $queryInfo;
605611 }
606612
607613 function getIndexField() {
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -19,7 +19,7 @@
2020 $wgExtensionCredits['specialpage'][] = array(
2121 'name' => 'Flagged Revisions',
2222 'author' => array( 'Aaron Schulz', 'Joerg Baach' ),
23 - 'version' => '1.061',
 23+ 'version' => '1.07',
2424 'url' => 'http://www.mediawiki.org/wiki/Extension:FlaggedRevs',
2525 'descriptionmsg' => 'flaggedrevs-desc',
2626 );
@@ -195,6 +195,11 @@
196196 # How many hours pending review is considering long?
197197 $wgFlaggedRevsLongPending = 3;
198198
 199+# Flagged revisions are always visible to users with rights below.
 200+# Use '*' for non-user accounts.
 201+$wgFlaggedRevsVisible = array();
 202+$wgFlaggedRevsTalkVisible = true;
 203+
199204 # End of configuration variables.
200205 #########
201206
@@ -289,6 +294,9 @@
290295 # Image version display
291296 $wgHooks['ImagePageFindFile'][] = 'FlaggedRevs::imagePageFindFile';
292297
 298+# Visibility - experimental
 299+$wgHooks['userCan'][] = 'FlaggedRevs::userCanView';
 300+
293301 # Main hooks, overrides pages content, adds tags, sets tabs and permalink
294302 $wgHooks['SkinTemplateTabs'][] = 'FlaggedRevs::setActionTabs';
295303 # Change last-modified footer
@@ -303,6 +311,7 @@
304312 $wgHooks['BeforePageDisplay'][] = 'FlaggedRevs::addReviewForm';
305313 $wgHooks['BeforePageDisplay'][] = 'FlaggedRevs::addVisibilityLink';
306314 # Mark of items in page history
 315+$wgHooks['PageHistoryPager::getQueryInfo'][] = 'FlaggedRevs::addToHistQuery';
307316 $wgHooks['PageHistoryLineEnding'][] = 'FlaggedRevs::addToHistLine';
308317 $wgHooks['ImagePageFileHistoryLine'][] = 'FlaggedRevs::addToFileHistLine';
309318 # Page review on edit
Index: trunk/extensions/FlaggedRevs/FlaggedArticle.php
@@ -725,8 +725,7 @@
726726 if( !$this->isReviewable() || !$this->getStableRev() )
727727 return true;
728728 $skin = $wgUser->getSkin();
729 - list($link,$class) = FlaggedRevs::makeStableVersionLink(
730 - $this->parent->getTitle(), $row->rev_id, $skin, wfGetDB( DB_SLAVE ) );
 729+ list($link,$class) = FlaggedRevs::markHistoryRow( $this->parent->getTitle(), $row, $skin );
731730 if( $link ) {
732731 $s = "<span class='$class'>$s</span> <small><strong>[$link]</strong></small>";
733732 }
@@ -736,7 +735,7 @@
737736 /**
738737 * Add link to stable version of reviewed revisions
739738 */
740 - public function addToFileHistLine( $historyList, $file, &$row, &$class ) {
 739+ public function addToFileHistLine( $historyList, $file, &$s, &$class ) {
741740 global $wgUser;
742741 # Non-content pages cannot be validated. Stable version must exist.
743742 if( !$this->isReviewable() || !$this->getStableRev() )
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php
@@ -764,25 +764,16 @@
765765 /**
766766 * Make stable version link and return the css
767767 * @param Title $title
768 - * @param int $rev_id
769 - * @param Database $db, optional
 768+ * @param Row $row, from history page
770769 * @returns array (string,string)
771770 */
772 - public static function makeStableVersionLink( $title, $rev_id, $skin, $db = NULL ) {
773 - $db = $db ? $db : wfGetDB( DB_SLAVE );
774 - $row = $db->selectRow( 'flaggedrevs',
775 - array( 'fr_quality', 'fr_user' ),
776 - array( 'fr_page_id' => $title->getArticleID(),
777 - 'fr_rev_id' => $rev_id ),
778 - __METHOD__,
779 - array( 'FORCE INDEX' => 'PRIMARY' )
780 - );
781 - if( $row ) {
 771+ public static function markHistoryRow( $title, $row, $skin ) {
 772+ if( isset($row->fr_quality) ) {
782773 $css = FlaggedRevsXML::getQualityColor( $row->fr_quality );
783774 $user = User::whois( $row->fr_user );
784775 $msg = ($row->fr_quality >= 1) ? 'hist-quality-user' : 'hist-stable-user';
785776 $st = $title->getPrefixedDBkey();
786 - $link = "<span class='plainlinks'>".wfMsgExt($msg,array('parseinline'),$st,$rev_id,$user)."</span>";
 777+ $link = "<span class='plainlinks'>".wfMsgExt($msg,array('parseinline'),$st,$row->rev_id,$user)."</span>";
787778 } else {
788779 return array("","");
789780 }
@@ -1509,6 +1500,40 @@
15101501 return true;
15111502 }
15121503
 1504+ /**
 1505+ * Allow users to view reviewed pages.
 1506+ */
 1507+ public static function userCanView( $title, $user, $action, $result ) {
 1508+ global $wgFlaggedRevsVisible, $wgFlaggedRevsTalkVisible, $wgTitle;
 1509+ # Assume $action may still not be set, in which case, treat it as 'view'...
 1510+ if( !$wgFlaggedRevsVisible || $action != 'read' )
 1511+ return true;
 1512+ # Admin may set this to false, rather than array()...
 1513+ $groups = $user->getGroups();
 1514+ $groups[] = '*';
 1515+ if( empty($wgFlaggedRevsVisible) || !array_intersect($groups,$wgFlaggedRevsVisible) )
 1516+ return true;
 1517+ # Is this a talk page?
 1518+ if( $wgFlaggedRevsTalkVisible && $title->isTalkPage() ) {
 1519+ $result = true;
 1520+ return true;
 1521+ }
 1522+ # See if there is a stable version. Also, see if, given the page
 1523+ # config and URL params, the page can be overriden.
 1524+ $flaggedArticle = FlaggedArticle::getInstance( $title );
 1525+ if( $wgTitle && $wgTitle->equals( $title ) && $flaggedArticle->getStableRev( true ) ) {
 1526+ // Cache stable version while we are at it.
 1527+ if( $flaggedArticle->pageOverride() ) {
 1528+ $result = true;
 1529+ }
 1530+ } else {
 1531+ if( self::getStablePageRev( $title ) ) {
 1532+ $result = true;
 1533+ }
 1534+ }
 1535+ return true;
 1536+ }
 1537+
15131538 /**
15141539 * When an edit is made by a reviewer, if the current revision is the stable
15151540 * version, try to automatically review it.
@@ -1939,16 +1964,16 @@
19401965
19411966 static function onArticleViewHeader( $article, &$outputDone, &$pcache ) {
19421967 $flaggedArticle = FlaggedArticle::getInstance( $article );
1943 - $flaggedArticle->maybeUpdateMainCache( &$outputDone, &$pcache );
1944 - $flaggedArticle->setPageContent( &$outputDone, &$pcache );
1945 - $flaggedArticle->addPatrolLink( &$outputDone, &$pcache );
 1968+ $flaggedArticle->maybeUpdateMainCache( $outputDone, $pcache );
 1969+ $flaggedArticle->setPageContent( $outputDone, $pcache );
 1970+ $flaggedArticle->addPatrolLink( $outputDone, $pcache );
19461971 return true;
19471972 }
19481973
19491974 static function setPermaLink( $skin, &$navUrls, &$revId, &$id ) {
19501975 global $wgArticle;
19511976 if ( $wgArticle ) {
1952 - FlaggedArticle::getInstance( $wgArticle )->setPermaLink( $skin, &$navUrls, &$revId, &$id );
 1977+ FlaggedArticle::getInstance( $wgArticle )->setPermaLink( $skin, $navUrls, $revId, $id );
19531978 }
19541979 return true;
19551980 }
@@ -1959,7 +1984,7 @@
19601985
19611986 static function addReviewForm( $out ) {
19621987 global $wgArticle;
1963 - if ( $out->isArticleRelated() ) {
 1988+ if ( $wgArticle && $out->isArticleRelated() ) {
19641989 FlaggedArticle::getInstance( $wgArticle )->addReviewForm( $out );
19651990 }
19661991 return true;
@@ -1967,23 +1992,34 @@
19681993
19691994 static function addVisibilityLink( $out ) {
19701995 global $wgArticle;
1971 - if ( $out->isArticleRelated() ) {
 1996+ if ( $wgArticle && $out->isArticleRelated() ) {
19721997 FlaggedArticle::getInstance( $wgArticle )->addVisibilityLink( $out );
19731998 }
19741999 return true;
19752000 }
19762001
 2002+ static function addToHistQuery( $pager, &$queryInfo ) {
 2003+ $flaggedArticle = FlaggedArticle::getInstance( $pager->mPageHistory->getTitle() );
 2004+ $pageID = $pager->mPageHistory->getTitle()->getArticleId();
 2005+ if( $flaggedArticle->isReviewable() ) {
 2006+ $queryInfo['tables'][] = 'flaggedrevs';
 2007+ $queryInfo['fields'][] = 'fr_quality';
 2008+ $queryInfo['fields'][] = 'fr_user';
 2009+ $queryInfo['join_conds']['flaggedrevs'] = array( 'LEFT JOIN', "fr_page_id = {$pageID} AND fr_rev_id = rev_id" );
 2010+ }
 2011+ return true;
 2012+ }
 2013+
19772014 static function addToHistLine( $history, $row, &$s ) {
1978 - return FlaggedArticle::getInstance( $history->getArticle() )->addToHistLine( $history, $row, &$s );
 2015+ return FlaggedArticle::getInstance( $history->getArticle() )->addToHistLine( $history, $row, $s );
19792016 }
19802017
1981 - static function addToFileHistLine( $historyList, $file, &$row, &$rowClass ) {
1982 - return FlaggedArticle::getInstance( $historyList->getImagePage() )
1983 - -> addToFileHistLine( $historyList, $file, &$row, &$rowClass );
 2018+ static function addToFileHistLine( $hist, $file, &$s, &$rowClass ) {
 2019+ return FlaggedArticle::getInstance( $hist->getImagePage() )->addToFileHistLine( $hist, $file, $s, $rowClass );
19842020 }
19852021
19862022 static function injectReviewDiffURLParams( $article, &$sectionAnchor, &$extraQuery ) {
1987 - return FlaggedArticle::getInstance( $article )->injectReviewDiffURLParams( &$sectionAnchor, &$extraQuery );
 2023+ return FlaggedArticle::getInstance( $article )->injectReviewDiffURLParams( $sectionAnchor, $extraQuery );
19882024 }
19892025
19902026 static function onDiffViewHeader( $diff, $oldRev, $newRev ) {

Status & tagging log