r71059 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71058‎ | r71059 | r71060 >
Date:01:57, 14 August 2010
Author:kaldari
Status:ok (Comments)
Tags:
Comment:
fix to handle case of mIndexField including a table prefix
Modified paths:
  • /trunk/phase3/includes/Pager.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Pager.php
@@ -194,8 +194,11 @@
195195 function extractResultInfo( $offset, $limit, ResultWrapper $res ) {
196196 $numRows = $res->numRows();
197197 if ( $numRows ) {
 198+ # Remove any table prefix from index field
 199+ $indexColumn = end( explode( '.', $this->mIndexField ) );
 200+
198201 $row = $res->fetchRow();
199 - $firstIndex = $row[$this->mIndexField];
 202+ $firstIndex = $row[$indexColumn];
200203
201204 # Discard the extra result row if there is one
202205 if ( $numRows > $this->mLimit && $numRows > 1 ) {
@@ -205,7 +208,7 @@
206209 $this->mPastTheEndIndex = $this->mPastTheEndRow->$indexField;
207210 $res->seek( $numRows - 2 );
208211 $row = $res->fetchRow();
209 - $lastIndex = $row[$this->mIndexField];
 212+ $lastIndex = $row[$indexColumn];
210213 } else {
211214 $this->mPastTheEndRow = null;
212215 # Setting indexes to an empty string means that they will be
@@ -215,7 +218,7 @@
216219 $this->mPastTheEndIndex = '';
217220 $res->seek( $numRows - 1 );
218221 $row = $res->fetchRow();
219 - $lastIndex = $row[$this->mIndexField];
 222+ $lastIndex = $row[$indexColumn];
220223 }
221224 } else {
222225 $firstIndex = '';

Follow-up revisions

RevisionCommit summaryAuthorDate
r71098Fixed E_STRICT from r71059maxsem07:03, 15 August 2010
r71753fixing paging for campaign interface - requires deploy of r71059 and r71098kaldari22:01, 26 August 2010

Comments

#Comment by Kaldari (talk | contribs)   02:11, 14 August 2010

Explanation for this diff: If your query for the pagination results involves multiple tables, you may have to specify a table prefix for the index field. Once the query result is returned, however, you need to use just the field name as the key for the index. So you need two different index field variables: one for the query and one for the key. Rather than asking the implementer for both, it's easy enough just to create the key variable on the fly by chopping off the table prefix. This should also be completely backwards compatible with existing uses of the class.

Status & tagging log