Example #1
0
 /**
  * @param ResultWrapper $queryResult
  * @return GWTUser[]
  */
 private function materializeList($queryResult)
 {
     $list = array();
     while ($obj = $queryResult->fetchObject()) {
         $list[] = $this->materialize($obj);
     }
     return $list;
 }
 protected function loadFromRows(ResultWrapper $res)
 {
     $ret = array();
     while ($row = $res->fetchObject()) {
         unset($grp);
         unset($ver);
         // experiment
         $e_id = $row->e_id;
         if (!isset($ret[$e_id])) {
             $ret[$e_id] = array('id' => $row->e_id, 'name' => $row->e_name, 'description' => $row->e_description, 'versions' => array(), 'groups' => array());
         }
         $exp =& $ret[$e_id];
         // group
         $g_id = $row->g_id;
         if ($g_id && !isset($exp['groups'][$g_id])) {
             $exp['groups'][$g_id] = array('experiment_id' => $e_id, 'id' => $row->g_id, 'name' => $row->g_name, 'description' => $row->g_description);
         }
         if ($g_id) {
             $grp =& $exp['groups'][$g_id];
         }
         // version
         $v_id = $row->v_id;
         if ($v_id && !isset($exp['versions'][$v_id])) {
             $exp['versions'][$v_id] = array('experiment_id' => $e_id, 'id' => $row->v_id, 'start_time' => $row->v_start_time, 'end_time' => $row->v_end_time, 'ga_slot' => $row->v_ga_slot, 'control_group_id' => $row->v_control_group_id, 'group_ranges' => array());
         }
         if ($v_id) {
             $ver =& $exp['versions'][$v_id];
         }
         // group ranges
         if ($g_id && $v_id && $row->r_group_id) {
             // row in group_ranges found
             if (!isset($ver['group_ranges'][$g_id])) {
                 $ver['group_ranges'][$g_id] = array('version_id' => $v_id, 'group_id' => $g_id, 'ranges' => $row->r_ranges);
             }
         }
     }
     return $ret;
 }
Example #3
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 #4
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 #5
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);
 }
 /**
  * Format and output report results using the given information plus
  * OutputPage
  *
  * @param OutputPage $out OutputPage to print to
  * @param Skin $skin User skin to use
  * @param IDatabase $dbr Database (read) connection to use
  * @param ResultWrapper $res Result pointer
  * @param int $num Number of available result rows
  * @param int $offset Paging offset
  */
 protected function outputResults($out, $skin, $dbr, $res, $num, $offset)
 {
     global $wgContLang;
     if ($num > 0) {
         $html = array();
         if (!$this->listoutput) {
             $html[] = $this->openList($offset);
         }
         # $res might contain the whole 1,000 rows, so we read up to
         # $num [should update this to use a Pager]
         // @codingStandardsIgnoreStart Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
         for ($i = 0; $i < $num && ($row = $res->fetchObject()); $i++) {
             // @codingStandardsIgnoreEnd
             $line = $this->formatResult($skin, $row);
             if ($line) {
                 $attr = isset($row->usepatrol) && $row->usepatrol && $row->patrolled == 0 ? ' class="not-patrolled"' : '';
                 $html[] = $this->listoutput ? $line : "<li{$attr}>{$line}</li>\n";
             }
         }
         # Flush the final result
         if ($this->tryLastResult()) {
             $row = null;
             $line = $this->formatResult($skin, $row);
             if ($line) {
                 $attr = isset($row->usepatrol) && $row->usepatrol && $row->patrolled == 0 ? ' class="not-patrolled"' : '';
                 $html[] = $this->listoutput ? $line : "<li{$attr}>{$line}</li>\n";
             }
         }
         if (!$this->listoutput) {
             $html[] = $this->closeList();
         }
         $html = $this->listoutput ? $wgContLang->listToText($html) : implode('', $html);
         $out->addHTML($html);
     }
 }
 /**
  * Runs through a query result set dumping page and revision records.
  * The result set should be sorted/grouped by page to avoid duplicate
  * page records in the output.
  *
  * The result set will be freed once complete. Should be safe for
  * streaming (non-buffered) queries, as long as it was made on a
  * separate database connection not managed by LoadBalancer; some
  * blob storage types will make queries to pull source data.
  *
  * @param ResultWrapper $resultset
  * @access private
  */
 function outputStream($resultset)
 {
     $last = null;
     while ($row = $resultset->fetchObject()) {
         if (is_null($last) || $last->page_namespace != $row->page_namespace || $last->page_title != $row->page_title) {
             if (isset($last)) {
                 $this->closePage($last);
             }
             $this->openPage($row);
             $last = $row;
         }
         $this->dumpRev($row);
     }
     if (isset($last)) {
         $this->closePage($last);
     }
     $resultset->free();
 }
Example #8
0
 /**
  * Fill in member variables from a result wrapper
  */
 function loadFromResult(ResultWrapper $res, $killExpired = true)
 {
     $ret = false;
     if (0 != $res->numRows()) {
         # Get first block
         $row = $res->fetchObject();
         $this->initFromRow($row);
         if ($killExpired) {
             # If requested, delete expired rows
             do {
                 $killed = $this->deleteIfExpired();
                 if ($killed) {
                     $row = $res->fetchObject();
                     if ($row) {
                         $this->initFromRow($row);
                     }
                 }
             } while ($killed && $row);
             # If there were any left after the killing finished, return true
             if ($row) {
                 $ret = true;
             }
         } else {
             $ret = true;
         }
     }
     $res->free();
     return $ret;
 }
Example #9
0
 /**
  * Runs through a query result set dumping page and revision records.
  * The result set should be sorted/grouped by page to avoid duplicate
  * page records in the output.
  *
  * The result set will be freed once complete. Should be safe for
  * streaming (non-buffered) queries, as long as it was made on a
  * separate database connection not managed by LoadBalancer; some
  * blob storage types will make queries to pull source data.
  *
  * @param ResultWrapper $resultset
  * @access private
  */
 function outputStream($resultset)
 {
     $last = null;
     while ($row = $resultset->fetchObject()) {
         if (is_null($last) || $last->page_namespace != $row->page_namespace || $last->page_title != $row->page_title) {
             if (isset($last)) {
                 $output = $this->writer->closePage();
                 $this->sink->writeClosePage($output);
             }
             $output = $this->writer->openPage($row);
             $this->sink->writeOpenPage($row, $output);
             $last = $row;
         }
         $output = $this->writer->writeRevision($row, $this->parse);
         $this->sink->writeRevision($row, $output);
     }
     if (isset($last)) {
         $output = $this->author_list . $this->writer->closePage();
         $this->sink->writeClosePage($output);
     }
     $resultset->free();
 }
 private static function tableFromResult(ResultWrapper $res)
 {
     $articles = array();
     while ($row = $res->fetchObject($res)) {
         $articles[intval($row->page_id)] = array('page_id' => $row->page_id);
     }
     return $articles;
 }