/**
  * Pre-fill the link cache
  *
  * @param DatabaseBase $db
  * @param ResultWrapper $res
  */
 function preprocessResults($db, $res)
 {
     if ($res->numRows() > 0) {
         $linkBatch = new LinkBatch();
         foreach ($res as $row) {
             $linkBatch->add($row->namespace, $row->title);
         }
         $res->seek(0);
         $linkBatch->execute();
     }
 }
 /**
  * Run a LinkBatch to pre-cache LinkCache information,
  * like page existence and information for stub color and redirect hints.
  * This should be done for live data and cached data.
  *
  * @param IDatabase $db
  * @param ResultWrapper $res
  */
 public function preprocessResults($db, $res)
 {
     if (!$res->numRows()) {
         return;
     }
     $batch = new LinkBatch();
     foreach ($res as $row) {
         $batch->add($row->namespace, $row->title);
     }
     $batch->execute();
     $res->seek(0);
 }
 /**
  * Fetch user page links and cache their existence
  *
  * @param IDatabase $db
  * @param ResultWrapper $res
  */
 function preprocessResults($db, $res)
 {
     if (!$res->numRows()) {
         return;
     }
     $batch = new LinkBatch();
     foreach ($res as $row) {
         $batch->add(NS_CATEGORY, $row->title);
     }
     $batch->execute();
     // Back to start for display
     $res->seek(0);
 }
 /**
  * @param IDatabase $db
  * @param ResultWrapper $res
  */
 function preprocessResults($db, $res)
 {
     # There's no point doing a batch check if we aren't caching results;
     # the page must exist for it to have been pulled out of the table
     if (!$this->isCached() || !$res->numRows()) {
         return;
     }
     $batch = new LinkBatch();
     foreach ($res as $row) {
         $batch->add($row->namespace, $row->title);
     }
     $batch->execute();
     $res->seek(0);
 }
Example #5
0
 /**
  * Cache page existence for performance
  *
  * @param IDatabase $db
  * @param ResultWrapper $res
  */
 function preprocessResults($db, $res)
 {
     if (!$res->numRows()) {
         return;
     }
     $batch = new LinkBatch();
     foreach ($res as $row) {
         $batch->add($row->namespace, $row->title);
         $batch->addObj($this->getRedirectTarget($row));
     }
     $batch->execute();
     // Back to start for display
     $res->seek(0);
 }
Example #6
0
 /**
  * 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;
     }
 }
Example #7
0
	/**
	 * Get the formatted result list. Calls getStartBody(), formatRow() and
	 * getEndBody(), concatenates the results and returns them.
	 *
	 * @return String
	 */
	public function getBody() {
		if ( !$this->mQueryDone ) {
			$this->doQuery();
		}

		if ( $this->mResult->numRows() ) {
			# Do any special query batches before display
			$this->doBatchLookups();
		}

		# Don't use any extra rows returned by the query
		$numRows = min( $this->mResult->numRows(), $this->mLimit );

		$s = $this->getStartBody();
		if ( $numRows ) {
			if ( $this->mIsBackwards ) {
				for ( $i = $numRows - 1; $i >= 0; $i-- ) {
					$this->mResult->seek( $i );
					$row = $this->mResult->fetchObject();
					$s .= $this->formatRow( $row );
				}
			} else {
				$this->mResult->seek( 0 );
				for ( $i = 0; $i < $numRows; $i++ ) {
					$row = $this->mResult->fetchObject();
					$s .= $this->formatRow( $row );
				}
			}
		} else {
			$s .= $this->getEmptyBody();
		}
		$s .= $this->getEndBody();
		return $s;
	}
Example #8
0
 /**
  * Partition a DB result with backlinks in it into batches
  * @param ResultWrapper $res Database result
  * @param int $batchSize
  * @param bool $isComplete Whether $res includes all the backlinks
  * @throws MWException
  * @return array
  */
 protected function partitionResult($res, $batchSize, $isComplete = true)
 {
     $batches = array();
     $numRows = $res->numRows();
     $numBatches = ceil($numRows / $batchSize);
     for ($i = 0; $i < $numBatches; $i++) {
         if ($i == 0 && $isComplete) {
             $start = false;
         } else {
             $rowNum = $i * $batchSize;
             $res->seek($rowNum);
             $row = $res->fetchObject();
             $start = (int) $row->page_id;
         }
         if ($i == $numBatches - 1 && $isComplete) {
             $end = false;
         } else {
             $rowNum = min($numRows - 1, ($i + 1) * $batchSize - 1);
             $res->seek($rowNum);
             $row = $res->fetchObject();
             $end = (int) $row->page_id;
         }
         # Sanity check order
         if ($start && $end && $start > $end) {
             throw new MWException(__METHOD__ . ': Internal error: query result out of order');
         }
         $batches[] = array($start, $end);
     }
     return array('numRows' => $numRows, 'batches' => $batches);
 }
 /**
  * Initialize total values so we can figure out percentages later.
  *
  * @param IDatabase $dbr
  * @param ResultWrapper $res
  */
 public function preprocessResults($dbr, $res)
 {
     $this->totalCount = $this->totalBytes = 0;
     foreach ($res as $row) {
         $mediaStats = $this->splitFakeTitle($row->title);
         $this->totalCount += isset($mediaStats[2]) ? $mediaStats[2] : 0;
         $this->totalBytes += isset($mediaStats[3]) ? $mediaStats[3] : 0;
     }
     $res->seek(0);
 }
Example #10
0
 /**
  * Creates a new LinkBatch object, adds all pages from the passed ResultWrapper (MUST include
  * title and optional the namespace field) and executes the batch. This operation will pre-cache
  * LinkCache information like page existence and information for stub color and redirect hints.
  *
  * @param ResultWrapper $res The ResultWrapper object to process. Needs to include the title
  *  field and namespace field, if the $ns parameter isn't set.
  * @param null $ns Use this namespace for the given titles in the ResultWrapper object,
  *  instead of the namespace value of $res.
  */
 protected function executeLBFromResultWrapper(ResultWrapper $res, $ns = null)
 {
     if (!$res->numRows()) {
         return;
     }
     $batch = new LinkBatch();
     foreach ($res as $row) {
         $batch->add($ns !== null ? $ns : $row->namespace, $row->title);
     }
     $batch->execute();
     $res->seek(0);
 }
 /**
  * Cache page content model and gender distinction for performance
  *
  * @param IDatabase $db
  * @param ResultWrapper $res
  */
 function preprocessResults($db, $res)
 {
     if (!$res->numRows()) {
         return;
     }
     $batch = new LinkBatch();
     foreach ($res as $row) {
         $batch->add($row->namespace, $row->title);
         if (isset($row->nsb)) {
             // lazy loaded when using cached results
             $batch->add($row->nsb, $row->tb);
         }
         if (isset($row->iwc) && !$row->iwc) {
             // lazy loaded when using cached result, not added when interwiki link
             $batch->add($row->nsc, $row->tc);
         }
     }
     $batch->execute();
     // Back to start for display
     $res->seek(0);
 }