/** * Extract some useful data from the result object for use by * the navigation bar, put it into $this */ function extractResultInfo($offset, $limit, ResultWrapper $res) { $numRows = $res->numRows(); if ($numRows) { $row = $res->fetchRow(); $firstIndex = $row[$this->mIndexField]; # Discard the extra result row if there is one if ($numRows > $this->mLimit && $numRows > 1) { $res->seek($numRows - 1); $this->mPastTheEndRow = $res->fetchObject(); $indexField = $this->mIndexField; $this->mPastTheEndIndex = $this->mPastTheEndRow->{$indexField}; $res->seek($numRows - 2); $row = $res->fetchRow(); $lastIndex = $row[$this->mIndexField]; } else { $this->mPastTheEndRow = null; # Setting indexes to an empty string means that they will be # omitted if they would otherwise appear in URLs. It just so # happens that this is the right thing to do in the standard # UI, in all the relevant cases. $this->mPastTheEndIndex = ''; $res->seek($numRows - 1); $row = $res->fetchRow(); $lastIndex = $row[$this->mIndexField]; } } else { $firstIndex = ''; $lastIndex = ''; $this->mPastTheEndRow = null; $this->mPastTheEndIndex = ''; } if ($this->mIsBackwards) { $this->mIsFirst = $numRows < $limit; $this->mIsLast = $offset == ''; $this->mLastShown = $firstIndex; $this->mFirstShown = $lastIndex; } else { $this->mIsFirst = $offset == ''; $this->mIsLast = $numRows < $limit; $this->mLastShown = $lastIndex; $this->mFirstShown = $firstIndex; } }
/** * Invalidate a set of IDs, right now */ function invalidateIDs(ResultWrapper $res) { global $wgUseFileCache, $wgUseSquid; if ($res->numRows() == 0) { return; } $dbw =& wfGetDB(DB_MASTER); $timestamp = $dbw->timestamp(); $done = false; while (!$done) { # Get all IDs in this query into an array $ids = array(); for ($i = 0; $i < $this->mRowsPerQuery; $i++) { $row = $res->fetchRow(); if ($row) { $ids[] = $row[0]; } else { $done = true; break; } } if (!count($ids)) { break; } # Update page_touched $dbw->update('page', array('page_touched' => $timestamp), array('page_id IN (' . $dbw->makeList($ids) . ')'), __METHOD__); # Update squid if ($wgUseSquid || $wgUseFileCache) { $titles = Title::newFromIDs($ids); if ($wgUseSquid) { $u = SquidUpdate::newFromTitles($titles); $u->doUpdate(); } # Update file cache if ($wgUseFileCache) { foreach ($titles as $title) { $cm = new CacheManager($title); @unlink($cm->fileCacheName()); } } } } }
/** * Extract some useful data from the result object for use by * the navigation bar, put it into $this * * @param $isFirst bool: False if there are rows before those fetched (i.e. * if a "previous" link would make sense) * @param $limit Integer: exact query limit * @param $res ResultWrapper */ function extractResultInfo( $isFirst, $limit, ResultWrapper $res ) { $numRows = $res->numRows(); if ( $numRows ) { # Remove any table prefix from index field $parts = explode( '.', $this->mIndexField ); $indexColumn = end( $parts ); $row = $res->fetchRow(); $firstIndex = $row[$indexColumn]; # Discard the extra result row if there is one if ( $numRows > $this->mLimit && $numRows > 1 ) { $res->seek( $numRows - 1 ); $this->mPastTheEndRow = $res->fetchObject(); $this->mPastTheEndIndex = $this->mPastTheEndRow->$indexColumn; $res->seek( $numRows - 2 ); $row = $res->fetchRow(); $lastIndex = $row[$indexColumn]; } else { $this->mPastTheEndRow = null; # Setting indexes to an empty string means that they will be # omitted if they would otherwise appear in URLs. It just so # happens that this is the right thing to do in the standard # UI, in all the relevant cases. $this->mPastTheEndIndex = ''; $res->seek( $numRows - 1 ); $row = $res->fetchRow(); $lastIndex = $row[$indexColumn]; } } else { $firstIndex = ''; $lastIndex = ''; $this->mPastTheEndRow = null; $this->mPastTheEndIndex = ''; } if ( $this->mIsBackwards ) { $this->mIsFirst = ( $numRows < $limit ); $this->mIsLast = $isFirst; $this->mLastShown = $firstIndex; $this->mFirstShown = $lastIndex; } else { $this->mIsFirst = $isFirst; $this->mIsLast = ( $numRows < $limit ); $this->mLastShown = $lastIndex; $this->mFirstShown = $firstIndex; } }
/** * Invalidate a set of IDs, right now */ public function invalidateIDs(ResultWrapper $res) { global $wgUseFileCache, $wgUseSquid; if ($res->numRows() == 0) { return; } // sanity check $dbw = wfGetDB(DB_MASTER); $timestamp = $dbw->timestamp(); $done = false; while (!$done) { # Get all IDs in this query into an array $ids = array(); for ($i = 0; $i < $this->mRowsPerQuery; $i++) { $row = $res->fetchRow(); if ($row) { $ids[] = $row[0]; } else { $done = true; break; } } if (count($ids) == 0) { break; } # Update page_touched $dbw->update('page', array('page_touched' => $timestamp), array('page_id' => $ids), __METHOD__); # Update static caches if ($wgUseSquid || $wgUseFileCache) { $titles = Title::newFromIDs($ids); # Update squid cache if ($wgUseSquid) { $u = SquidUpdate::newFromTitles($titles); $u->doUpdate(); } # Update file cache if ($wgUseFileCache) { foreach ($titles as $title) { HTMLFileCache::clearFileCache($title); } } } } }