/** * Process Query Results * * @access private * @param object Mediawiki Result Object * @return array Array of Article objects. */ private function processQueryResults($result) { /*******************************/ /* Random Count Pick Generator */ /*******************************/ $randomCount = $this->parameters->getParameter('randomcount'); if ($randomCount > 0) { $nResults = $this->DB->numRows($result); //mt_srand() seeding was removed due to PHP 5.2.1 and above no longer generating the same sequence for the same seed. //Constrain the total amount of random results to not be greater than the total results. if ($randomCount > $nResults) { $randomCount = $nResults; } //This is 50% to 150% faster than the old while (true) version that could keep rechecking the same random key over and over again. //Generate pick numbers for results. $pick = range(1, $nResults); //Shuffle the pick numbers. shuffle($pick); //Select pick numbers from the beginning to the maximum of $randomCount. $pick = array_slice($pick, 0, $randomCount); } $articles = []; /**********************/ /* Article Processing */ /**********************/ $i = 0; while ($row = $result->fetchRow()) { $i++; //In random mode skip articles which were not chosen. if ($randomCount > 0 && !in_array($i, $pick)) { continue; } if ($this->parameters->getParameter('goal') == 'categories') { $pageNamespace = NS_CATEGORY; $pageTitle = $row['cl_to']; } elseif ($this->parameters->getParameter('openreferences')) { if (count($this->parameters->getParameter('imagecontainer')) > 0) { $pageNamespace = NS_FILE; $pageTitle = $row['il_to']; } else { //Maybe non-existing title $pageNamespace = $row['pl_namespace']; $pageTitle = $row['pl_title']; } } else { //Existing PAGE TITLE $pageNamespace = $row['page_namespace']; $pageTitle = $row['page_title']; } // if subpages are to be excluded: skip them if (!$this->parameters->getParameter('includesubpages') && strpos($pageTitle, '/') !== false) { continue; } $title = \Title::makeTitle($pageNamespace, $pageTitle); $thisTitle = $this->parser->getTitle(); //Block recursion from happening by seeing if this result row is the page the DPL query was ran from. if ($this->parameters->getParameter('skipthispage') && $thisTitle->equals($title)) { continue; } $articles[] = Article::newFromRow($row, $this->parameters, $title, $pageNamespace, $pageTitle); } $this->DB->freeResult($result); return $articles; }