extractRequestParams()); $randstr = wfRandom(); $data = array(); /* Build Basic Query (Yea it really sucks) */ $result = $this->getResult(); $pageSet = $this->getPageSet(); $titles = $pageSet->getTitles(); $data = array(); $this->addTables('page'); $this->addFields('*'); $this->addOption('LIMIT', $limit); $this->addWhereFld('page_namespace', $namespace); $this->addWhereRange('page_random','newer',$randstr,null); $this->addWhereIf('page_is_redirect != 0', true); $this->addOption('LIMIT', $limit + 1); $this->addOption('USE INDEX', 'page_random'); $this->addOption('ORDER BY', 'page_random'); $count = 0; $db = $this->getDB(); $res = $this->select(__METHOD__); while($row = $db->fetchObject($res)) { $vals = $this->extractRowInfo($row); if($vals) $data[] = $vals; } $db->freeResult($res); $result->setIndexedTagName($data, 'rn'); $result->addValue('query', $this->getModuleName(), $data); } private function wfRandom() { # The maximum random value is "only" 2^31-1, so get two random # values to reduce the chance of dupes $max = mt_getrandmax() + 1; $rand = number_format( (mt_rand() * $max + mt_rand()) / $max / $max, 12, '.', '' ); return $rand; } private function extractRowInfo($row) { $title = Title :: makeTitle($row->page_namespace, $row->page_title); $vals = array(); $vals['title'] = $title; $vals['ns'] = $row->page_namespace; $vals['id'] = $row->page_id; return $vals; } protected function getAllowedParams() { return array ( 'namespace' => array( ApiBase :: PARAM_TYPE => 'namespace', ApiBase :: PARAM_ISMULTI => true ), 'limit' => array ( ApiBase :: PARAM_TYPE => 'limit', ApiBase :: PARAM_MIN => 1, ApiBase :: PARAM_MAX => 10, ApiBase :: PARAM_MAX2 => 20 ), ); } protected function getParamDescription() { return array ( 'namespace' => "Return pagess in (this|these) namespace(s) only", 'limit' => 'limit how many random pages will be returned' ); } protected function getDescription() { return 'Get a set of Random Pages'; } protected function getExamples() { return 'api.php?action=query&list=random&rnnamespace=0&rnlimit=2'; } public function getVersion() { return __CLASS__ . ': $Id: ApiQueryRandom.php overlordq$'; } }