r40686 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40685‎ | r40686 | r40687 >
Date:23:30, 9 September 2008
Author:soxred93
Status:old
Tags:
Comment:
Add rnredirect parameter, to get a random redirect instead of a random page
Modified paths:
  • /trunk/phase3/includes/api/ApiQueryRandom.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryRandom.php
@@ -48,13 +48,13 @@
4949 $this->run($resultPageSet);
5050 }
5151
52 - protected function prepareQuery($randstr, $limit, $namespace, &$resultPageSet) {
 52+ protected function prepareQuery($randstr, $limit, $namespace, &$resultPageSet, $redirect) {
5353 $this->resetQueryParams();
5454 $this->addTables('page');
5555 $this->addOption('LIMIT', $limit);
5656 $this->addWhereFld('page_namespace', $namespace);
5757 $this->addWhereRange('page_random', 'newer', $randstr, null);
58 - $this->addWhere(array('page_is_redirect' => 0));
 58+ $this->addWhereFld('page_is_redirect', $redirect);
5959 $this->addOption('USE INDEX', 'page_random');
6060 if(is_null($resultPageSet))
6161 $this->addFields(array('page_id', 'page_title', 'page_namespace'));
@@ -89,7 +89,8 @@
9090 $result = $this->getResult();
9191 $data = array();
9292 $this->pageIDs = array();
93 - $this->prepareQuery(wfRandom(), $params['limit'], $params['namespace'], $resultPageSet);
 93+
 94+ $this->prepareQuery(wfRandom(), $params['limit'], $params['namespace'], $resultPageSet, $params['redirect']);
9495 $count = $this->runQuery($data, $resultPageSet);
9596 if($count < $params['limit'])
9697 {
@@ -97,7 +98,7 @@
9899 * for page_random. We'll just take the lowest ones, see
99100 * also the comment in Title::getRandomTitle()
100101 */
101 - $this->prepareQuery(0, $params['limit'] - $count, $params['namespace'], $resultPageSet);
 102+ $this->prepareQuery(0, $params['limit'] - $count, $params['namespace'], $resultPageSet, $params['redirect']);
102103 $this->runQuery($data, $resultPageSet);
103104 }
104105
@@ -129,13 +130,17 @@
130131 ApiBase :: PARAM_MAX => 10,
131132 ApiBase :: PARAM_MAX2 => 20
132133 ),
 134+ 'redirect' => array(
 135+ ApiBase :: PARAM_TYPE => 'boolean',
 136+ ),
133137 );
134138 }
135139
136140 public function getParamDescription() {
137141 return array (
138142 'namespace' => 'Return pages in these namespaces only',
139 - 'limit' => 'Limit how many random pages will be returned'
 143+ 'limit' => 'Limit how many random pages will be returned',
 144+ 'redirect' => 'Load a random redirect instead of a random page'
140145 );
141146 }
142147

Follow-up revisions

RevisionCommit summaryAuthorDate
r40699Tweaks for r40686, r40687:...catrope13:30, 10 September 2008