From: X! Date: Tue, 9 Sep 2008 23:30:29 +0000 (+0000) Subject: Add rnredirect parameter, to get a random redirect instead of a random page X-Git-Tag: 1.31.0-rc.0~45389 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/?a=commitdiff_plain;h=3ddb14efa3916b0db422f524d510f0924c0ca7dd;p=lhc%2Fweb%2Fwiklou.git Add rnredirect parameter, to get a random redirect instead of a random page --- diff --git a/includes/api/ApiQueryRandom.php b/includes/api/ApiQueryRandom.php index 046157a662..08fb2d4605 100644 --- a/includes/api/ApiQueryRandom.php +++ b/includes/api/ApiQueryRandom.php @@ -48,13 +48,13 @@ if (!defined('MEDIAWIKI')) { $this->run($resultPageSet); } - protected function prepareQuery($randstr, $limit, $namespace, &$resultPageSet) { + protected function prepareQuery($randstr, $limit, $namespace, &$resultPageSet, $redirect) { $this->resetQueryParams(); $this->addTables('page'); $this->addOption('LIMIT', $limit); $this->addWhereFld('page_namespace', $namespace); $this->addWhereRange('page_random', 'newer', $randstr, null); - $this->addWhere(array('page_is_redirect' => 0)); + $this->addWhereFld('page_is_redirect', $redirect); $this->addOption('USE INDEX', 'page_random'); if(is_null($resultPageSet)) $this->addFields(array('page_id', 'page_title', 'page_namespace')); @@ -89,7 +89,8 @@ if (!defined('MEDIAWIKI')) { $result = $this->getResult(); $data = array(); $this->pageIDs = array(); - $this->prepareQuery(wfRandom(), $params['limit'], $params['namespace'], $resultPageSet); + + $this->prepareQuery(wfRandom(), $params['limit'], $params['namespace'], $resultPageSet, $params['redirect']); $count = $this->runQuery($data, $resultPageSet); if($count < $params['limit']) { @@ -97,7 +98,7 @@ if (!defined('MEDIAWIKI')) { * for page_random. We'll just take the lowest ones, see * also the comment in Title::getRandomTitle() */ - $this->prepareQuery(0, $params['limit'] - $count, $params['namespace'], $resultPageSet); + $this->prepareQuery(0, $params['limit'] - $count, $params['namespace'], $resultPageSet, $params['redirect']); $this->runQuery($data, $resultPageSet); } @@ -129,13 +130,17 @@ if (!defined('MEDIAWIKI')) { ApiBase :: PARAM_MAX => 10, ApiBase :: PARAM_MAX2 => 20 ), + 'redirect' => array( + ApiBase :: PARAM_TYPE => 'boolean', + ), ); } public function getParamDescription() { return array ( 'namespace' => 'Return pages in these namespaces only', - 'limit' => 'Limit how many random pages will be returned' + 'limit' => 'Limit how many random pages will be returned', + 'redirect' => 'Load a random redirect instead of a random page' ); }