r36034 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r36033‎ | r36034 | r36035 >
Date:17:39, 8 June 2008
Author:aaron
Status:old
Tags:
Comment:
* Add OldLocalFile::selectRows()
* Add LocalFile::getHistory hook
* Do file history quality query all at once rather than per file
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/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/filerepo/LocalFile.php (modified) (history)
  • /trunk/phase3/includes/filerepo/OldLocalFile.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -741,6 +741,14 @@
742742
743743 'LoadExtensionSchemaUpdates': called by maintenance/updaters.inc when upgrading database schema
744744
 745+'LocalFile::getHistory': called before file history query performed
 746+$file: the file
 747+$tables: tables
 748+$fields: select fields
 749+$conds: conditions
 750+$opts: query options
 751+$join_conds: JOIN conditions
 752+
745753 'LoginAuthenticateAudit': a login attempt for a valid user account either succeeded or failed.
746754 No return data is accepted; this hook is for auditing only.
747755 $user: the User object being authenticated against
Index: trunk/phase3/includes/filerepo/OldLocalFile.php
@@ -44,6 +44,29 @@
4545 return false;
4646 }
4747 }
 48+
 49+ /**
 50+ * Fields in the oldimage table
 51+ */
 52+ static function selectFields() {
 53+ return array(
 54+ 'oi_name',
 55+ 'oi_archive_name',
 56+ 'oi_size',
 57+ 'oi_width',
 58+ 'oi_height',
 59+ 'oi_metadata',
 60+ 'oi_bits',
 61+ 'oi_media_type',
 62+ 'oi_major_mime',
 63+ 'oi_minor_mime',
 64+ 'oi_description',
 65+ 'oi_user',
 66+ 'oi_user_text',
 67+ 'oi_timestamp',
 68+ 'oi_sha1',
 69+ );
 70+ }
4871
4972 /**
5073 * @param Title $title
Index: trunk/phase3/includes/filerepo/LocalFile.php
@@ -621,6 +621,9 @@
622622
623623 function getHistory($limit = null, $start = null, $end = null) {
624624 $dbr = $this->repo->getSlaveDB();
 625+ $tables = array('oldimage');
 626+ $join_conds = array();
 627+ $fields = OldLocalFile::selectFields();
625628 $conds = $opts = array();
626629 $conds[] = "oi_name = " . $dbr->addQuotes( $this->title->getDBKey() );
627630 if( $start !== null ) {
@@ -633,7 +636,10 @@
634637 $opts['LIMIT'] = $limit;
635638 }
636639 $opts['ORDER BY'] = 'oi_timestamp DESC';
637 - $res = $dbr->select('oldimage', '*', $conds, __METHOD__, $opts);
 640+
 641+ wfRunHooks( 'LocalFile::getHistory', array( &$this, &$tables, &$fields, &$conds, &$opts, &$join_conds ) );
 642+
 643+ $res = $dbr->select( $tables, $fields, $conds, __METHOD__, $opts, $join_conds );
638644 $r = array();
639645 while( $row = $dbr->fetchObject($res) ) {
640646 $r[] = OldLocalFile::newFromRow($row, $this->repo);
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -331,6 +331,7 @@
332332 # Mark of items in page history
333333 $wgHooks['PageHistoryPager::getQueryInfo'][] = 'FlaggedRevs::addToHistQuery';
334334 $wgHooks['PageHistoryLineEnding'][] = 'FlaggedRevs::addToHistLine';
 335+$wgHooks['LocalFile::getHistory'][] = 'FlaggedRevs::addToFileHistQuery';
335336 $wgHooks['ImagePageFileHistoryLine'][] = 'FlaggedRevs::addToFileHistLine';
336337 # Page review on edit
337338 $wgHooks['ArticleUpdateBeforeRedirect'][] = 'FlaggedRevs::injectReviewDiffURLParams';
Index: trunk/extensions/FlaggedRevs/FlaggedArticle.php
@@ -39,7 +39,7 @@
4040 }
4141 # For titles, attach instance to the title and give the instance an article parent
4242 if( $object instanceof Title ) {
43 - $article = new Article( $object );
 43+ $article = MediaWiki::articleFromTitle( $object );
4444 $article->flaggedRevsArticle = new FlaggedArticle( $article );
4545 $object->flaggedRevsArticle =& $article->flaggedRevsArticle;
4646 } else if( $object instanceof Article ) {
@@ -794,20 +794,21 @@
795795 * Add link to stable version of reviewed revisions
796796 */
797797 public function addToFileHistLine( $historyList, $file, &$s, &$css ) {
798 - global $wgUser;
799798 # Non-content pages cannot be validated. Stable version must exist.
800799 if( !$this->isReviewable() || !$this->getStableRev() )
801800 return true;
802 - # See if this is reviewed
803 - # fixme: O(N) DB queries
804 - $quality = wfGetDB(DB_SLAVE)->selectField( 'flaggedrevs', 'fr_quality',
805 - array( 'fr_img_sha1' => $file->getSha1(), 'fr_img_timestamp' => $file->getTimestamp() ),
806 - __METHOD__ );
807 - if( $quality === false ) {
808 - return true;
 801+ # Quality level for old versions selected all at once.
 802+ if( !$file->isOld() ) {
 803+ $quality = wfGetDB(DB_SLAVE)->selectField( 'flaggedrevs', 'fr_quality',
 804+ array( 'fr_img_sha1' => $file->getSha1(), 'fr_img_timestamp' => $file->getTimestamp() ),
 805+ __METHOD__ );
 806+ } else {
 807+ $quality = is_null($file->quality) ? false : $file->quality;
809808 }
810 - $css = FlaggedRevsXML::getQualityColor( $quality );
811 -
 809+ # If reviewed, class the line
 810+ if( $quality !== false ) {
 811+ $css = FlaggedRevsXML::getQualityColor( $quality );
 812+ }
812813 return true;
813814 }
814815
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php
@@ -2061,6 +2061,13 @@
20622062 return true;
20632063 }
20642064
 2065+ static function addToFileHistQuery( $file, &$tables, &$fields, &$conds, &$opts, &$join_conds ) {
 2066+ $tables[] = 'flaggedrevs';
 2067+ $fields[] = 'fr_quality';
 2068+ $join_conds['flaggedrevs'] = array( 'LEFT JOIN', 'oi_sha1 = fr_img_sha1 AND oi_timestamp = fr_img_timestamp' );
 2069+ return true;
 2070+ }
 2071+
20652072 static function addToHistLine( $history, $row, &$s ) {
20662073 return FlaggedArticle::getInstance( $history->getArticle(), true )->addToHistLine( $history, $row, $s );
20672074 }

Status & tagging log