summaryrefslogtreecommitdiff
path: root/includes/api/ApiQueryRandom.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/api/ApiQueryRandom.php')
-rw-r--r--includes/api/ApiQueryRandom.php26
1 files changed, 15 insertions, 11 deletions
diff --git a/includes/api/ApiQueryRandom.php b/includes/api/ApiQueryRandom.php
index e7b8bf46..73c4a81c 100644
--- a/includes/api/ApiQueryRandom.php
+++ b/includes/api/ApiQueryRandom.php
@@ -62,7 +62,7 @@ if (!defined('MEDIAWIKI')) {
$this->addFields($resultPageSet->getPageTableFields());
}
- protected function runQuery(&$data, &$resultPageSet) {
+ protected function runQuery(&$resultPageSet) {
$db = $this->getDB();
$res = $this->select(__METHOD__);
$count = 0;
@@ -73,7 +73,14 @@ if (!defined('MEDIAWIKI')) {
// Prevent duplicates
if(!in_array($row->page_id, $this->pageIDs))
{
- $data[] = $this->extractRowInfo($row);
+ $fit = $this->getResult()->addValue(
+ array('query', $this->getModuleName()),
+ null, $this->extractRowInfo($row));
+ if(!$fit)
+ # We can't really query-continue a random list.
+ # Return an insanely high value so
+ # $count < $limit is false
+ return 1E9;
$this->pageIDs[] = $row->page_id;
}
}
@@ -87,11 +94,10 @@ if (!defined('MEDIAWIKI')) {
public function run($resultPageSet = null) {
$params = $this->extractRequestParams();
$result = $this->getResult();
- $data = array();
$this->pageIDs = array();
$this->prepareQuery(wfRandom(), $params['limit'], $params['namespace'], $resultPageSet, $params['redirect']);
- $count = $this->runQuery($data, $resultPageSet);
+ $count = $this->runQuery($resultPageSet);
if($count < $params['limit'])
{
/* We got too few pages, we probably picked a high value
@@ -99,21 +105,19 @@ if (!defined('MEDIAWIKI')) {
* also the comment in Title::getRandomTitle()
*/
$this->prepareQuery(0, $params['limit'] - $count, $params['namespace'], $resultPageSet, $params['redirect']);
- $this->runQuery($data, $resultPageSet);
+ $this->runQuery($resultPageSet);
}
if(is_null($resultPageSet)) {
- $result->setIndexedTagName($data, 'page');
- $result->addValue('query', $this->getModuleName(), $data);
+ $result->setIndexedTagName_internal(array('query', $this->getModuleName()), 'page');
}
}
private function extractRowInfo($row) {
$title = Title::makeTitle($row->page_namespace, $row->page_title);
$vals = array();
- $vals['title'] = $title->getPrefixedText();
- $vals['ns'] = $row->page_namespace;
- $vals['id'] = $row->page_id;
+ $vals['id'] = intval($row->page_id);
+ ApiQueryBase::addTitleInfo($vals, $title);
return $vals;
}
@@ -157,4 +161,4 @@ if (!defined('MEDIAWIKI')) {
public function getVersion() {
return __CLASS__ . ': $Id: ApiQueryRandom.php overlordq$';
}
-}
+} \ No newline at end of file