Ejemplo n.º 1
0
 private function run($resultPageSet = null)
 {
     wfProfileIn($this->getModuleProfileName() . '-getDB');
     $db =& $this->getDB();
     wfProfileOut($this->getModuleProfileName() . '-getDB');
     wfProfileIn($this->getModuleProfileName() . '-parseParams');
     $limit = $from = $namespace = $filterredir = $prefix = null;
     extract($this->extractRequestParams());
     $this->addTables('page');
     if (!$this->addWhereIf('page_is_redirect = 1', $filterredir === 'redirects')) {
         $this->addWhereIf('page_is_redirect = 0', $filterredir === 'nonredirects');
     }
     $this->addWhereFld('page_namespace', $namespace);
     if (isset($from)) {
         $this->addWhere('page_title>=' . $db->addQuotes(ApiQueryBase::titleToKey($from)));
     }
     if (isset($prefix)) {
         $this->addWhere("page_title LIKE '{$db->strencode(ApiQueryBase::titleToKey($prefix))}%'");
     }
     if (is_null($resultPageSet)) {
         $this->addFields(array('page_id', 'page_namespace', 'page_title'));
     } else {
         $this->addFields($resultPageSet->getPageTableFields());
     }
     $this->addOption('USE INDEX', 'name_title');
     $this->addOption('LIMIT', $limit + 1);
     $this->addOption('ORDER BY', 'page_namespace, page_title');
     wfProfileOut($this->getModuleProfileName() . '-parseParams');
     $res = $this->select(__METHOD__);
     wfProfileIn($this->getModuleProfileName() . '-saveResults');
     $data = array();
     $count = 0;
     while ($row = $db->fetchObject($res)) {
         if (++$count > $limit) {
             // We've reached the one extra which shows that there are additional pages to be had. Stop here...
             $this->setContinueEnumParameter('from', ApiQueryBase::keyToTitle($row->page_title));
             break;
         }
         if (is_null($resultPageSet)) {
             $vals = $this->addRowInfo('page', $row);
             if ($vals) {
                 $data[intval($row->page_id)] = $vals;
             }
         } else {
             $resultPageSet->processDbRow($row);
         }
     }
     $db->freeResult($res);
     if (is_null($resultPageSet)) {
         $result = $this->getResult();
         $result->setIndexedTagName($data, 'p');
         $result->addValue('query', $this->getModuleName(), $data);
     }
     wfProfileOut($this->getModuleProfileName() . '-saveResults');
 }
Ejemplo n.º 2
0
 private function run($resultPageSet = null)
 {
     $limit = $from = $namespace = $filterredir = null;
     extract($this->extractRequestParams());
     $db = $this->getDB();
     $where = array('page_namespace' => $namespace);
     if (isset($from)) {
         $where[] = 'page_title>=' . $db->addQuotes(ApiQueryBase::titleToKey($from));
     }
     if ($filterredir === 'redirects') {
         $where['page_is_redirect'] = 1;
     } elseif ($filterredir === 'nonredirects') {
         $where['page_is_redirect'] = 0;
     }
     if (is_null($resultPageSet)) {
         $fields = array('page_id', 'page_namespace', 'page_title');
     } else {
         $fields = $resultPageSet->getPageTableFields();
     }
     $this->profileDBIn();
     $res = $db->select('page', $fields, $where, __CLASS__ . '::' . __METHOD__, array('USE INDEX' => 'name_title', 'LIMIT' => $limit + 1, 'ORDER BY' => 'page_namespace, page_title'));
     $this->profileDBOut();
     $data = array();
     $count = 0;
     while ($row = $db->fetchObject($res)) {
         if (++$count > $limit) {
             // We've reached the one extra which shows that there are additional pages to be had. Stop here...
             $msg = array('continue' => $this->encodeParamName('from') . '=' . ApiQueryBase::keyToTitle($row->page_title));
             $this->getResult()->addValue('query-status', 'allpages', $msg);
             break;
         }
         $title = Title::makeTitle($row->page_namespace, $row->page_title);
         // skip any pages that user has no rights to read
         if ($title->userCanRead()) {
             if (is_null($resultPageSet)) {
                 $id = intval($row->page_id);
                 $data[] = $id;
                 // in generator mode, just assemble a list of page IDs.
             } else {
                 $resultPageSet->processDbRow($row);
             }
         }
     }
     $db->freeResult($res);
     if (is_null($resultPageSet)) {
         ApiResult::setIndexedTagName($data, 'p');
         $this->getResult()->addValue('query', 'allpages', $data);
     }
 }
 private function run($resultPageSet = null)
 {
     $db = $this->getDB();
     $params = $this->extractRequestParams();
     $this->addTables('page');
     if (!$this->addWhereIf('page_is_redirect = 1', $params['filterredir'] === 'redirects')) {
         $this->addWhereIf('page_is_redirect = 0', $params['filterredir'] === 'nonredirects');
     }
     $this->addWhereFld('page_namespace', $params['namespace']);
     if (!is_null($params['from'])) {
         $this->addWhere('page_title>=' . $db->addQuotes(ApiQueryBase::titleToKey($params['from'])));
     }
     if (isset($params['prefix'])) {
         $this->addWhere("page_title LIKE '" . $db->escapeLike(ApiQueryBase::titleToKey($params['prefix'])) . "%'");
     }
     if (is_null($resultPageSet)) {
         $this->addFields(array('page_id', 'page_namespace', 'page_title'));
     } else {
         $this->addFields($resultPageSet->getPageTableFields());
     }
     $this->addOption('USE INDEX', 'name_title');
     $limit = $params['limit'];
     $this->addOption('LIMIT', $limit + 1);
     $this->addOption('ORDER BY', 'page_namespace, page_title');
     $res = $this->select(__METHOD__);
     $data = array();
     $count = 0;
     while ($row = $db->fetchObject($res)) {
         if (++$count > $limit) {
             // We've reached the one extra which shows that there are additional pages to be had. Stop here...
             // TODO: Security issue - if the user has no right to view next title, it will still be shown
             $this->setContinueEnumParameter('from', ApiQueryBase::keyToTitle($row->page_title));
             break;
         }
         if (is_null($resultPageSet)) {
             $title = Title::makeTitle($row->page_namespace, $row->page_title);
             $data[] = array('pageid' => intval($row->page_id), 'ns' => intval($title->getNamespace()), 'title' => $title->getPrefixedText());
         } else {
             $resultPageSet->processDbRow($row);
         }
     }
     $db->freeResult($res);
     if (is_null($resultPageSet)) {
         $result = $this->getResult();
         $result->setIndexedTagName($data, 'p');
         $result->addValue('query', $this->getModuleName(), $data);
     }
 }
Ejemplo n.º 4
0
 private function run($resultPageSet = null)
 {
     $db = $this->getDB();
     $params = $this->extractRequestParams();
     $this->addTables('categorylinks');
     $this->addFields('cl_to');
     if (!is_null($params['from'])) {
         $this->addWhere('cl_to>=' . $db->addQuotes(ApiQueryBase::titleToKey($params['from'])));
     }
     if (isset($params['prefix'])) {
         $this->addWhere("cl_to LIKE '" . $db->escapeLike(ApiQueryBase::titleToKey($params['prefix'])) . "%'");
     }
     $this->addOption('LIMIT', $params['limit'] + 1);
     $this->addOption('ORDER BY', 'cl_to' . ($params['dir'] == 'descending' ? ' DESC' : ''));
     $this->addOption('DISTINCT');
     $res = $this->select(__METHOD__);
     $pages = array();
     $count = 0;
     while ($row = $db->fetchObject($res)) {
         if (++$count > $params['limit']) {
             // We've reached the one extra which shows that there are additional cats to be had. Stop here...
             // TODO: Security issue - if the user has no right to view next title, it will still be shown
             $this->setContinueEnumParameter('from', ApiQueryBase::keyToTitle($row->cl_to));
             break;
         }
         // Normalize titles
         $titleObj = Title::makeTitle(NS_CATEGORY, $row->cl_to);
         if (!is_null($resultPageSet)) {
             $pages[] = $titleObj->getPrefixedText();
         } else {
             // Don't show "Category:" everywhere in non-generator mode
             $pages[] = $titleObj->getText();
         }
     }
     $db->freeResult($res);
     if (is_null($resultPageSet)) {
         $result = $this->getResult();
         $result->setIndexedTagName($pages, 'c');
         $result->addValue('query', $this->getModuleName(), $pages);
     } else {
         $resultPageSet->populateFromTitles($pages);
     }
 }
Ejemplo n.º 5
0
 private function run($resultPageSet = null)
 {
     $db = $this->getDB();
     $params = $this->extractRequestParams();
     // Page filters
     if (!$this->addWhereIf('page_is_redirect = 1', $params['filterredir'] === 'redirects')) {
         $this->addWhereIf('page_is_redirect = 0', $params['filterredir'] === 'nonredirects');
     }
     $this->addWhereFld('page_namespace', $params['namespace']);
     if (!is_null($params['from'])) {
         $this->addWhere('page_title>=' . $db->addQuotes(ApiQueryBase::titleToKey($params['from'])));
     }
     if (isset($params['prefix'])) {
         $this->addWhere("page_title LIKE '" . $db->escapeLike(ApiQueryBase::titleToKey($params['prefix'])) . "%'");
     }
     $forceNameTitleIndex = true;
     if (isset($params['minsize'])) {
         $this->addWhere('page_len>=' . intval($params['minsize']));
         $forceNameTitleIndex = false;
     }
     if (isset($params['maxsize'])) {
         $this->addWhere('page_len<=' . intval($params['maxsize']));
         $forceNameTitleIndex = false;
     }
     // Page protection filtering
     if (isset($params['prtype'])) {
         $this->addTables('page_restrictions');
         $this->addWhere('page_id=pr_page');
         $this->addWhere('pr_expiry>' . $db->addQuotes($db->timestamp()));
         $this->addWhereFld('pr_type', $params['prtype']);
         $prlevel = $params['prlevel'];
         if (!is_null($prlevel) && $prlevel != '' && $prlevel != '*') {
             $this->addWhereFld('pr_level', $prlevel);
         }
         $this->addOption('DISTINCT');
         $forceNameTitleIndex = false;
     } else {
         if (isset($params['prlevel'])) {
             $this->dieUsage('prlevel may not be used without prtype', 'params');
         }
     }
     if ($params['filterlanglinks'] == 'withoutlanglinks') {
         $pageName = $this->getDB()->tableName('page');
         $llName = $this->getDB()->tableName('langlinks');
         $tables = "{$pageName} LEFT JOIN {$llName} ON page_id=ll_from";
         $this->addWhere('ll_from IS NULL');
         $this->addTables($tables);
         $forceNameTitleIndex = false;
     } else {
         if ($params['filterlanglinks'] == 'withlanglinks') {
             $this->addTables(array('page', 'langlinks'));
             $this->addWhere('page_id=ll_from');
             $forceNameTitleIndex = false;
         } else {
             $this->addTables('page');
         }
     }
     if ($forceNameTitleIndex) {
         $this->addOption('USE INDEX', 'name_title');
     }
     if (is_null($resultPageSet)) {
         $this->addFields(array('page_id', 'page_namespace', 'page_title'));
     } else {
         $this->addFields($resultPageSet->getPageTableFields());
     }
     $limit = $params['limit'];
     $this->addOption('LIMIT', $limit + 1);
     $this->addOption('ORDER BY', 'page_namespace, page_title' . ($params['dir'] == 'descending' ? ' DESC' : ''));
     $res = $this->select(__METHOD__);
     $data = array();
     $count = 0;
     while ($row = $db->fetchObject($res)) {
         if (++$count > $limit) {
             // We've reached the one extra which shows that there are additional pages to be had. Stop here...
             // TODO: Security issue - if the user has no right to view next title, it will still be shown
             $this->setContinueEnumParameter('from', ApiQueryBase::keyToTitle($row->page_title));
             break;
         }
         if (is_null($resultPageSet)) {
             $title = Title::makeTitle($row->page_namespace, $row->page_title);
             $data[] = array('pageid' => intval($row->page_id), 'ns' => intval($title->getNamespace()), 'title' => $title->getPrefixedText());
         } else {
             $resultPageSet->processDbRow($row);
         }
     }
     $db->freeResult($res);
     if (is_null($resultPageSet)) {
         $result = $this->getResult();
         $result->setIndexedTagName($data, 'p');
         $result->addValue('query', $this->getModuleName(), $data);
     }
 }
 private function run($resultPageSet = null)
 {
     $db = $this->getDB();
     $params = $this->extractRequestParams();
     $prop = array_flip($params['prop']);
     $fld_ids = isset($prop['ids']);
     $fld_title = isset($prop['title']);
     if ($params['unique']) {
         if (!is_null($resultPageSet)) {
             $this->dieUsage($this->getModuleName() . ' cannot be used as a generator in unique links mode', 'params');
         }
         if ($fld_ids) {
             $this->dieUsage($this->getModuleName() . ' cannot return corresponding page ids in unique links mode', 'params');
         }
         $this->addOption('DISTINCT');
     }
     $this->addTables('pagelinks');
     $this->addWhereFld('pl_namespace', $params['namespace']);
     if (!is_null($params['from'])) {
         $this->addWhere('pl_title>=' . $db->addQuotes(ApiQueryBase::titleToKey($params['from'])));
     }
     if (isset($params['prefix'])) {
         $this->addWhere("pl_title LIKE '" . $db->escapeLike(ApiQueryBase::titleToKey($params['prefix'])) . "%'");
     }
     if (is_null($resultPageSet)) {
         $this->addFields(array('pl_namespace', 'pl_title'));
         $this->addFieldsIf('pl_from', $fld_ids);
     } else {
         $this->addFields('pl_from');
         $pageids = array();
     }
     $this->addOption('USE INDEX', 'pl_namespace');
     $limit = $params['limit'];
     $this->addOption('LIMIT', $limit + 1);
     $this->addOption('ORDER BY', 'pl_namespace, pl_title');
     $res = $this->select(__METHOD__);
     $data = array();
     $count = 0;
     while ($row = $db->fetchObject($res)) {
         if (++$count > $limit) {
             // We've reached the one extra which shows that there are additional pages to be had. Stop here...
             // TODO: Security issue - if the user has no right to view next title, it will still be shown
             $this->setContinueEnumParameter('from', ApiQueryBase::keyToTitle($row->pl_title));
             break;
         }
         if (is_null($resultPageSet)) {
             $vals = array();
             if ($fld_ids) {
                 $vals['fromid'] = intval($row->pl_from);
             }
             if ($fld_title) {
                 $title = Title::makeTitle($row->pl_namespace, $row->pl_title);
                 $vals['ns'] = intval($title->getNamespace());
                 $vals['title'] = $title->getPrefixedText();
             }
             $data[] = $vals;
         } else {
             $pageids[] = $row->pl_from;
         }
     }
     $db->freeResult($res);
     if (is_null($resultPageSet)) {
         $result = $this->getResult();
         $result->setIndexedTagName($data, 'l');
         $result->addValue('query', $this->getModuleName(), $data);
     } else {
         $resultPageSet->populateFromPageIDs($pageids);
     }
 }
 public function execute()
 {
     $db = $this->getDB();
     $params = $this->extractRequestParams();
     $prop = $params['prop'];
     if (!is_null($prop)) {
         $prop = array_flip($prop);
         $fld_editcount = isset($prop['editcount']);
         $fld_groups = isset($prop['groups']);
     } else {
         $fld_editcount = $fld_groups = false;
     }
     $limit = $params['limit'];
     $tables = $db->tableName('user');
     if (!is_null($params['from'])) {
         $this->addWhere('user_name>=' . $db->addQuotes(ApiQueryBase::titleToKey($params['from'])));
     }
     if (isset($params['prefix'])) {
         $this->addWhere("user_name LIKE '" . $db->escapeLike(ApiQueryBase::titleToKey($params['prefix'])) . "%'");
     }
     if (!is_null($params['group'])) {
         // Filter only users that belong to a given group
         $tblName = $db->tableName('user_groups');
         $tables = "{$tables} INNER JOIN {$tblName} ug1 ON ug1.ug_user=user_id";
         $this->addWhereFld('ug1.ug_group', $params['group']);
     }
     if ($fld_groups) {
         // Show the groups the given users belong to
         // request more than needed to avoid not getting all rows that belong to one user
         $groupCount = count(User::getAllGroups());
         $sqlLimit = $limit + $groupCount + 1;
         $tblName = $db->tableName('user_groups');
         $tables = "{$tables} LEFT JOIN {$tblName} ug2 ON ug2.ug_user=user_id";
         $this->addFields('ug2.ug_group ug_group2');
     } else {
         $sqlLimit = $limit + 1;
     }
     $this->addOption('LIMIT', $sqlLimit);
     $this->addTables($tables);
     $this->addFields('user_name');
     $this->addFieldsIf('user_editcount', $fld_editcount);
     $this->addOption('ORDER BY', 'user_name');
     $res = $this->select(__METHOD__);
     $data = array();
     $count = 0;
     $lastUserData = false;
     $lastUser = false;
     $result = $this->getResult();
     //
     // This loop keeps track of the last entry.
     // For each new row, if the new row is for different user then the last, the last entry is added to results.
     // Otherwise, the group of the new row is appended to the last entry.
     // The setContinue... is more complex because of this, and takes into account the higher sql limit
     // to make sure all rows that belong to the same user are received.
     //
     while (true) {
         $row = $db->fetchObject($res);
         $count++;
         if (!$row || $lastUser != $row->user_name) {
             // Save the last pass's user data
             if (is_array($lastUserData)) {
                 $data[] = $lastUserData;
             }
             // No more rows left
             if (!$row) {
                 break;
             }
             if ($count > $limit) {
                 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
                 $this->setContinueEnumParameter('from', ApiQueryBase::keyToTitle($row->user_name));
                 break;
             }
             // Record new user's data
             $lastUser = $row->user_name;
             $lastUserData = array('name' => $lastUser);
             if ($fld_editcount) {
                 $lastUserData['editcount'] = intval($row->user_editcount);
             }
         }
         if ($sqlLimit == $count) {
             // BUG!  database contains group name that User::getAllGroups() does not return
             // TODO: should handle this more gracefully
             ApiBase::dieDebug(__METHOD__, 'MediaWiki configuration error: the database contains more user groups than known to User::getAllGroups() function');
         }
         // Add user's group info
         if ($fld_groups && !is_null($row->ug_group2)) {
             $lastUserData['groups'][] = $row->ug_group2;
             $result->setIndexedTagName($lastUserData['groups'], 'g');
         }
     }
     $db->freeResult($res);
     $result->setIndexedTagName($data, 'u');
     $result->addValue('query', $this->getModuleName(), $data);
 }