r61957 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61956‎ | r61957 | r61958 >
Date:23:30, 3 February 2010
Author:tstarling
Status:deferred (Comments)
Tags:
Comment:
Fix for r58399 (missing index on change_tag table), using the patch from bug 22032 by Gurch, but altered to respect $wgOldChangeTagsIndex.
Modified paths:
  • /trunk/phase3/includes/api/ApiQueryLogEvents.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryRecentChanges.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryRevisions.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryUserContributions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryRecentChanges.php
@@ -114,7 +114,7 @@
115115 */
116116 $db = $this->getDB();
117117 $this->addTables( 'recentchanges' );
118 - $index = 'rc_timestamp'; // May change
 118+ $index['recentchanges'] = 'rc_timestamp'; // May change
119119 $this->addWhereRange( 'rc_timestamp', $params['dir'], $params['start'], $params['end'] );
120120 $this->addWhereFld( 'rc_namespace', $params['namespace'] );
121121 $this->addWhereFld( 'rc_deleted', 0 );
@@ -161,7 +161,7 @@
162162 if ( !is_null( $params['user'] ) )
163163 {
164164 $this->addWhereFld( 'rc_user_text', $params['user'] );
165 - $index = 'rc_user_text';
 165+ $index['recentchanges'] = 'rc_user_text';
166166 }
167167
168168 if ( !is_null( $params['excludeuser'] ) )
@@ -227,10 +227,13 @@
228228 $this->addTables( 'change_tag' );
229229 $this->addJoinConds( array( 'change_tag' => array( 'INNER JOIN', array( 'rc_id=ct_rc_id' ) ) ) );
230230 $this->addWhereFld( 'ct_tag' , $params['tag'] );
 231+ global $wgOldChangeTagsIndex;
 232+ $index['change_tag'] = $wgOldChangeTagsIndex ? 'ct_tag' : 'change_tag_tag_id';
231233 }
 234+
232235 $this->token = $params['token'];
233236 $this->addOption( 'LIMIT', $params['limit'] + 1 );
234 - $this->addOption( 'USE INDEX', array( 'recentchanges' => $index ) );
 237+ $this->addOption( 'USE INDEX', $index );
235238
236239 $count = 0;
237240 /* Perform the actual query. */
Index: trunk/phase3/includes/api/ApiQueryLogEvents.php
@@ -69,7 +69,7 @@
7070 'page' => array( 'LEFT JOIN',
7171 array( 'log_namespace=page_namespace',
7272 'log_title=page_title' ) ) ) );
73 - $index = 'times'; // default, may change
 73+ $index['logging'] = 'times'; // default, may change
7474
7575 $this->addFields( array (
7676 'log_type',
@@ -97,11 +97,13 @@
9898 $this->addTables( 'change_tag' );
9999 $this->addJoinConds( array( 'change_tag' => array( 'INNER JOIN', array( 'log_id=ct_log_id' ) ) ) );
100100 $this->addWhereFld( 'ct_tag', $params['tag'] );
 101+ global $wgOldChangeTagsIndex;
 102+ $index['change_tag'] = $wgOldChangeTagsIndex ? 'ct_tag' : 'change_tag_tag_id';
101103 }
102104
103105 if ( !is_null( $params['type'] ) ) {
104106 $this->addWhereFld( 'log_type', $params['type'] );
105 - $index = 'type_time';
 107+ $index['logging'] = 'type_time';
106108 }
107109
108110 $this->addWhereRange( 'log_timestamp', $params['dir'], $params['start'], $params['end'] );
@@ -115,7 +117,7 @@
116118 if ( !$userid )
117119 $this->dieUsage( "User name $user not found", 'param_user' );
118120 $this->addWhereFld( 'log_user', $userid );
119 - $index = 'user_time';
 121+ $index['logging'] = 'user_time';
120122 }
121123
122124 $title = $params['title'];
@@ -127,10 +129,10 @@
128130 $this->addWhereFld( 'log_title', $titleObj->getDBkey() );
129131
130132 // Use the title index in preference to the user index if there is a conflict
131 - $index = is_null( $user ) ? 'page_time' : array( 'page_time', 'user_time' );
 133+ $index['logging'] = is_null( $user ) ? 'page_time' : array( 'page_time', 'user_time' );
132134 }
133135
134 - $this->addOption( 'USE INDEX', array( 'logging' => $index ) );
 136+ $this->addOption( 'USE INDEX', $index );
135137
136138 // Paranoia: avoid brute force searches (bug 17342)
137139 if ( !is_null( $title ) ) {
Index: trunk/phase3/includes/api/ApiQueryRevisions.php
@@ -157,6 +157,8 @@
158158 $this->addTables( 'change_tag' );
159159 $this->addJoinConds( array( 'change_tag' => array( 'INNER JOIN', array( 'rev_id=ct_rev_id' ) ) ) );
160160 $this->addWhereFld( 'ct_tag' , $params['tag'] );
 161+ global $wgOldChangeTagsIndex;
 162+ $index['change_tag'] = $wgOldChangeTagsIndex ? 'ct_tag' : 'change_tag_tag_id';
161163 }
162164
163165 if ( isset( $prop['content'] ) || !is_null( $this->difftotext ) ) {
@@ -295,6 +297,7 @@
296298 ApiBase :: dieDebug( __METHOD__, 'param validation?' );
297299
298300 $this->addOption( 'LIMIT', $limit + 1 );
 301+ $this->addOption( 'USE INDEX', $index );
299302
300303 $data = array ();
301304 $count = 0;
Index: trunk/phase3/includes/api/ApiQueryUserContributions.php
@@ -238,7 +238,6 @@
239239 }
240240
241241 $this->addTables( $tables );
242 - $this->addOption( 'USE INDEX', $index );
243242 $this->addFieldsIf( 'rev_page', $this->fld_ids );
244243 $this->addFieldsIf( 'rev_id', $this->fld_ids || $this->fld_flags );
245244 $this->addFieldsIf( 'page_latest', $this->fld_flags );
@@ -260,7 +259,11 @@
261260 $this->addTables( 'change_tag' );
262261 $this->addJoinConds( array( 'change_tag' => array( 'INNER JOIN', array( 'rev_id=ct_rev_id' ) ) ) );
263262 $this->addWhereFld( 'ct_tag', $this->params['tag'] );
 263+ global $wgOldChangeTagsIndex;
 264+ $index['change_tag'] = $wgOldChangeTagsIndex ? 'ct_tag' : 'change_tag_tag_id';
264265 }
 266+
 267+ $this->addOption( 'USE INDEX', $index );
265268 }
266269
267270 /**
@@ -390,6 +393,7 @@
391394 '!patrolled',
392395 )
393396 ),
 397+ 'tag' => null,
394398 );
395399 }
396400
@@ -406,6 +410,7 @@
407411 'prop' => 'Include additional pieces of information',
408412 'show' => array( 'Show only items that meet this criteria, e.g. non minor edits only: show=!minor',
409413 'NOTE: if show=patrolled or show=!patrolled is set, revisions older than $wgRCMaxAge won\'t be shown', ),
 414+ 'tag' => 'Only list revisions tagged with this tag',
410415 );
411416 }
412417

Follow-up revisions

RevisionCommit summaryAuthorDate
r61976Followup r61957, define $indexdemon14:55, 4 February 2010
r62011Fix for r61957: initialise array variables explicitly.tstarling04:40, 5 February 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r58399API: (bug 19004) Add support for tags. Patch by Matthew Brittoncatrope10:42, 1 November 2009

Comments

#Comment by Raymond (talk | contribs)   07:04, 4 February 2010

Seen at translatewiki:

PHP Notice: Undefined variable: index in /www/w/includes/api/ApiQueryRevisions.php on line 300

#Comment by 😂 (talk | contribs)   14:57, 4 February 2010

Fixed in r61957

#Comment by Gurch (talk | contribs)   17:37, 4 February 2010

Oops... yeah, that may need doing for the other affected files too.

#Comment by Tim Starling (talk | contribs)   04:32, 5 February 2010

ApiQueryRecentChanges.php and ApiQueryLogEvents.php are not affected because PHP does not issue a notice when you use an element of an unset variable on the left side of an assignment, probably as an unintended consequence of its support for code like:

$a = array();
$a[0][0] = true;

I'll fix it anyway.

Status & tagging log