Index: trunk/phase3/includes/api/ApiQueryRandom.php |
— | — | @@ -48,13 +48,13 @@ |
49 | 49 | $this->run($resultPageSet); |
50 | 50 | } |
51 | 51 | |
52 | | - protected function prepareQuery($randstr, $limit, $namespace, &$resultPageSet) { |
| 52 | + protected function prepareQuery($randstr, $limit, $namespace, &$resultPageSet, $redirect) { |
53 | 53 | $this->resetQueryParams(); |
54 | 54 | $this->addTables('page'); |
55 | 55 | $this->addOption('LIMIT', $limit); |
56 | 56 | $this->addWhereFld('page_namespace', $namespace); |
57 | 57 | $this->addWhereRange('page_random', 'newer', $randstr, null); |
58 | | - $this->addWhere(array('page_is_redirect' => 0)); |
| 58 | + $this->addWhereFld('page_is_redirect', $redirect); |
59 | 59 | $this->addOption('USE INDEX', 'page_random'); |
60 | 60 | if(is_null($resultPageSet)) |
61 | 61 | $this->addFields(array('page_id', 'page_title', 'page_namespace')); |
— | — | @@ -89,7 +89,8 @@ |
90 | 90 | $result = $this->getResult(); |
91 | 91 | $data = array(); |
92 | 92 | $this->pageIDs = array(); |
93 | | - $this->prepareQuery(wfRandom(), $params['limit'], $params['namespace'], $resultPageSet); |
| 93 | + |
| 94 | + $this->prepareQuery(wfRandom(), $params['limit'], $params['namespace'], $resultPageSet, $params['redirect']); |
94 | 95 | $count = $this->runQuery($data, $resultPageSet); |
95 | 96 | if($count < $params['limit']) |
96 | 97 | { |
— | — | @@ -97,7 +98,7 @@ |
98 | 99 | * for page_random. We'll just take the lowest ones, see |
99 | 100 | * also the comment in Title::getRandomTitle() |
100 | 101 | */ |
101 | | - $this->prepareQuery(0, $params['limit'] - $count, $params['namespace'], $resultPageSet); |
| 102 | + $this->prepareQuery(0, $params['limit'] - $count, $params['namespace'], $resultPageSet, $params['redirect']); |
102 | 103 | $this->runQuery($data, $resultPageSet); |
103 | 104 | } |
104 | 105 | |
— | — | @@ -129,13 +130,17 @@ |
130 | 131 | ApiBase :: PARAM_MAX => 10, |
131 | 132 | ApiBase :: PARAM_MAX2 => 20 |
132 | 133 | ), |
| 134 | + 'redirect' => array( |
| 135 | + ApiBase :: PARAM_TYPE => 'boolean', |
| 136 | + ), |
133 | 137 | ); |
134 | 138 | } |
135 | 139 | |
136 | 140 | public function getParamDescription() { |
137 | 141 | return array ( |
138 | 142 | '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' |
140 | 145 | ); |
141 | 146 | } |
142 | 147 | |