本文整理汇总了PHP中ApiQueryBase类的典型用法代码示例。如果您正苦于以下问题:PHP ApiQueryBase类的具体用法?PHP ApiQueryBase怎么用?PHP ApiQueryBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ApiQueryBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Patrols the article or provides the reason the patrol failed.
*/
public function execute()
{
$params = $this->extractRequestParams();
$this->requireOnlyOneParameter($params, 'rcid', 'revid');
if (isset($params['rcid'])) {
$rc = RecentChange::newFromID($params['rcid']);
if (!$rc) {
$this->dieUsageMsg(array('nosuchrcid', $params['rcid']));
}
} else {
$rev = Revision::newFromId($params['revid']);
if (!$rev) {
$this->dieUsageMsg(array('nosuchrevid', $params['revid']));
}
$rc = $rev->getRecentChange();
if (!$rc) {
$this->dieUsage('The revision ' . $params['revid'] . " can't be patrolled as it's too old", 'notpatrollable');
}
}
$retval = $rc->doMarkPatrolled($this->getUser());
if ($retval) {
$this->dieUsageMsg(reset($retval));
}
$result = array('rcid' => intval($rc->getAttribute('rc_id')));
ApiQueryBase::addTitleInfo($result, $rc->getTitle());
$this->getResult()->addValue(null, $this->getModuleName(), $result);
}
示例2: execute
/**
* Purges the cache of a page
*/
public function execute()
{
global $wgUser;
$params = $this->extractRequestParams();
if (!$wgUser->isAllowed('purge')) {
$this->dieUsageMsg(array('cantpurge'));
}
if (!isset($params['titles'])) {
$this->dieUsageMsg(array('missingparam', 'titles'));
}
$result = array();
foreach ($params['titles'] as $t) {
$r = array();
$title = Title::newFromText($t);
if (!$title instanceof Title) {
$r['title'] = $t;
$r['invalid'] = '';
$result[] = $r;
continue;
}
ApiQueryBase::addTitleInfo($r, $title);
if (!$title->exists()) {
$r['missing'] = '';
$result[] = $r;
continue;
}
$article = new Article($title);
$article->doPurge();
// Directly purge and skip the UI part of purge().
$r['purged'] = '';
$result[] = $r;
}
$this->getResult()->setIndexedTagName($result, 'page');
$this->getResult()->addValue(null, $this->getModuleName(), $result);
}
示例3: execute
/**
* Patrols the article or provides the reason the patrol failed.
*/
public function execute()
{
global $wgUser, $wgUseRCPatrol, $wgUseNPPatrol;
$this->getMain()->requestWriteMode();
$params = $this->extractRequestParams();
if (!isset($params['token'])) {
$this->dieUsageMsg(array('missingparam', 'token'));
}
if (!isset($params['rcid'])) {
$this->dieUsageMsg(array('missingparam', 'rcid'));
}
if (!$wgUser->matchEditToken($params['token'])) {
$this->dieUsageMsg(array('sessionfailure'));
}
$rc = RecentChange::newFromID($params['rcid']);
if (!$rc instanceof RecentChange) {
$this->dieUsageMsg(array('nosuchrcid', $params['rcid']));
}
$retval = RecentChange::markPatrolled($params['rcid']);
if ($retval) {
$this->dieUsageMsg(current($retval));
}
$result = array('rcid' => $rc->getAttribute('rc_id'));
ApiQueryBase::addTitleInfo($result, $rc->getTitle());
$this->getResult()->addValue(null, $this->getModuleName(), $result);
}
示例4: execute
/**
* Purges the cache of a page
*/
public function execute()
{
$params = $this->extractRequestParams();
$forceLinkUpdate = $params['forcelinkupdate'];
$pageSet = $this->getPageSet();
$pageSet->execute();
$result = array();
self::addValues($result, $pageSet->getInvalidTitles(), 'invalid', 'title');
self::addValues($result, $pageSet->getSpecialTitles(), 'special', 'title');
self::addValues($result, $pageSet->getMissingPageIDs(), 'missing', 'pageid');
self::addValues($result, $pageSet->getMissingRevisionIDs(), 'missing', 'revid');
self::addValues($result, $pageSet->getMissingTitles(), 'missing');
self::addValues($result, $pageSet->getInterwikiTitlesAsResult());
foreach ($pageSet->getGoodTitles() as $title) {
$r = array();
ApiQueryBase::addTitleInfo($r, $title);
$page = WikiPage::factory($title);
$page->doPurge();
// Directly purge and skip the UI part of purge().
$r['purged'] = '';
if ($forceLinkUpdate) {
if (!$this->getUser()->pingLimiter()) {
global $wgEnableParserCache;
$popts = $page->makeParserOptions('canonical');
# Parse content; note that HTML generation is only needed if we want to cache the result.
$content = $page->getContent(Revision::RAW);
$p_result = $content->getParserOutput($title, $page->getLatest(), $popts, $wgEnableParserCache);
# Update the links tables
$updates = $content->getSecondaryDataUpdates($title, null, true, $p_result);
DataUpdate::runUpdates($updates);
$r['linkupdate'] = '';
if ($wgEnableParserCache) {
$pcache = ParserCache::singleton();
$pcache->save($p_result, $page, $popts);
}
} else {
$error = $this->parseMsg(array('actionthrottledtext'));
$this->setWarning($error['info']);
$forceLinkUpdate = false;
}
}
$result[] = $r;
}
$apiResult = $this->getResult();
$apiResult->setIndexedTagName($result, 'page');
$apiResult->addValue(null, $this->getModuleName(), $result);
$values = $pageSet->getNormalizedTitlesAsResult($apiResult);
if ($values) {
$apiResult->addValue(null, 'normalized', $values);
}
$values = $pageSet->getConvertedTitlesAsResult($apiResult);
if ($values) {
$apiResult->addValue(null, 'converted', $values);
}
$values = $pageSet->getRedirectTitlesAsResult($apiResult);
if ($values) {
$apiResult->addValue(null, 'redirects', $values);
}
}
示例5: run
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');
}
示例6: execute
/**
* Purges the cache of a page
*/
public function execute()
{
global $wgUser;
$params = $this->extractRequestParams();
if (!$wgUser->isAllowed('purge') && !$this->getMain()->isInternalMode() && !$this->getMain()->getRequest()->wasPosted()) {
$this->dieUsageMsg(array('mustbeposted', $this->getModuleName()));
}
$forceLinkUpdate = $params['forcelinkupdate'];
$result = array();
foreach ($params['titles'] as $t) {
$r = array();
$title = Title::newFromText($t);
if (!$title instanceof Title) {
$r['title'] = $t;
$r['invalid'] = '';
$result[] = $r;
continue;
}
ApiQueryBase::addTitleInfo($r, $title);
if (!$title->exists()) {
$r['missing'] = '';
$result[] = $r;
continue;
}
$context = $this->createContext();
$context->setTitle($title);
$article = Article::newFromTitle($title, $context);
$article->doPurge();
// Directly purge and skip the UI part of purge().
$r['purged'] = '';
if ($forceLinkUpdate) {
if (!$wgUser->pingLimiter()) {
global $wgParser, $wgEnableParserCache;
$popts = new ParserOptions();
$p_result = $wgParser->parse($article->getContent(), $title, $popts);
# Update the links tables
$u = new LinksUpdate($title, $p_result);
$u->doUpdate();
$r['linkupdate'] = '';
if ($wgEnableParserCache) {
$pcache = ParserCache::singleton();
$pcache->save($p_result, $article, $popts);
}
} else {
$this->setWarning($this->parseMsg(array('actionthrottledtext')));
$forceLinkUpdate = false;
}
}
$result[] = $r;
}
$apiResult = $this->getResult();
$apiResult->setIndexedTagName($result, 'page');
$apiResult->addValue(null, $this->getModuleName(), $result);
}
示例7: run
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);
}
}
示例8: execute
/**
* Patrols the article or provides the reason the patrol failed.
*/
public function execute()
{
$params = $this->extractRequestParams();
$rc = RecentChange::newFromID($params['rcid']);
if (!$rc instanceof RecentChange) {
$this->dieUsageMsg(array('nosuchrcid', $params['rcid']));
}
$retval = $rc->doMarkPatrolled($this->getUser());
if ($retval) {
$this->dieUsageMsg(reset($retval));
}
$result = array('rcid' => intval($rc->getAttribute('rc_id')));
ApiQueryBase::addTitleInfo($result, $rc->getTitle());
$this->getResult()->addValue(null, $this->getModuleName(), $result);
}
示例9: run
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);
}
}
示例10: addValues
/**
* Add all items from $values into the result
* @param array $result Output
* @param array $values Values to add
* @param string $flag The name of the boolean flag to mark this element
* @param string $name If given, name of the value
*/
private static function addValues(array &$result, $values, $flag = null, $name = null)
{
foreach ($values as $val) {
if ($val instanceof Title) {
$v = array();
ApiQueryBase::addTitleInfo($v, $val);
} elseif ($name !== null) {
$v = array($name => $val);
} else {
$v = $val;
}
if ($flag !== null) {
$v[$flag] = '';
}
$result[] = $v;
}
}
示例11: reportPage
function reportPage( $title, $origTitle, $revisionCount, $successCount, $pageInfo = '' ) {
// Add a result entry
$r = array();
ApiQueryBase::addTitleInfo($r, $title);
$r['revisions'] = intval($successCount);
$this->mResultArr[] = $r;
# call the parent to do the logging
# avoid bug in 1.15.4 Special:Import (new file page text without the file uploaded)
# PHP Fatal error: Call to a member function insertOn() on a non-object in E:\www\psychologos\includes\specials\SpecialImport.php on line 334
// do not create informational null revisions
// because they are placed on top of real user made revisions,
// making the binary search algorithm used to compare local and remote revs to fail
// TODO: change the binary search algorithm to two/three level hashes
if ( WikiSyncSetup::$report_null_revisions && $title->getArticleId() !== 0 ) {
parent::reportPage( $title, $origTitle, $revisionCount, $successCount, $pageInfo );
}
}
示例12: run
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);
}
}
示例13: run
private function run($resultPageSet = null)
{
if ($this->getPageSet()->getGoodTitleCount() == 0) {
return;
}
// nothing to do
$this->addFields(array('il_from', 'il_to'));
$this->addTables('imagelinks');
$this->addWhereFld('il_from', array_keys($this->getPageSet()->getGoodTitles()));
$this->addOption('ORDER BY', "il_from, il_to");
$db = $this->getDB();
$res = $this->select(__METHOD__);
if (is_null($resultPageSet)) {
$data = array();
$lastId = 0;
// database has no ID 0
while ($row = $db->fetchObject($res)) {
if ($lastId != $row->il_from) {
if ($lastId != 0) {
$this->addPageSubItems($lastId, $data);
$data = array();
}
$lastId = $row->il_from;
}
$vals = array();
ApiQueryBase::addTitleInfo($vals, Title::makeTitle(NS_IMAGE, $row->il_to));
$data[] = $vals;
}
if ($lastId != 0) {
$this->addPageSubItems($lastId, $data);
}
} else {
$titles = array();
while ($row = $db->fetchObject($res)) {
$titles[] = Title::makeTitle(NS_IMAGE, $row->il_to);
}
$resultPageSet->populateFromTitles($titles);
}
$db->freeResult($res);
}
示例14: execute
/**
* Patrols the article or provides the reason the patrol failed.
*/
public function execute()
{
$params = $this->extractRequestParams();
$this->requireOnlyOneParameter($params, 'rcid', 'revid');
if (isset($params['rcid'])) {
$rc = RecentChange::newFromId($params['rcid']);
if (!$rc) {
$this->dieUsageMsg(['nosuchrcid', $params['rcid']]);
}
} else {
$rev = Revision::newFromId($params['revid']);
if (!$rev) {
$this->dieUsageMsg(['nosuchrevid', $params['revid']]);
}
$rc = $rev->getRecentChange();
if (!$rc) {
$this->dieUsage('The revision ' . $params['revid'] . " can't be patrolled as it's too old", 'notpatrollable');
}
}
$user = $this->getUser();
$tags = $params['tags'];
// Check if user can add tags
if (!is_null($tags)) {
$ableToTag = ChangeTags::canAddTagsAccompanyingChange($tags, $user);
if (!$ableToTag->isOK()) {
$this->dieStatus($ableToTag);
}
}
$retval = $rc->doMarkPatrolled($user, false, $tags);
if ($retval) {
$this->dieUsageMsg(reset($retval));
}
$result = ['rcid' => intval($rc->getAttribute('rc_id'))];
ApiQueryBase::addTitleInfo($result, $rc->getTitle());
$this->getResult()->addValue(null, $this->getModuleName(), $result);
}
示例15: run
/**
* @param $resultPageSet ApiPageSet
* @return void
*/
private function run($resultPageSet = null)
{
$params = $this->extractRequestParams();
$this->addTables('protected_titles');
$this->addFields(array('pt_namespace', 'pt_title', 'pt_timestamp'));
$prop = array_flip($params['prop']);
$this->addFieldsIf('pt_user', isset($prop['user']) || isset($prop['userid']));
$this->addFieldsIf('pt_reason', isset($prop['comment']) || isset($prop['parsedcomment']));
$this->addFieldsIf('pt_expiry', isset($prop['expiry']));
$this->addFieldsIf('pt_create_perm', isset($prop['level']));
$this->addTimestampWhereRange('pt_timestamp', $params['dir'], $params['start'], $params['end']);
$this->addWhereFld('pt_namespace', $params['namespace']);
$this->addWhereFld('pt_create_perm', $params['level']);
if (isset($prop['user'])) {
$this->addTables('user');
$this->addFields('user_name');
$this->addJoinConds(array('user' => array('LEFT JOIN', 'user_id=pt_user')));
}
$this->addOption('LIMIT', $params['limit'] + 1);
$res = $this->select(__METHOD__);
$count = 0;
$result = $this->getResult();
$titles = array();
foreach ($res as $row) {
if (++$count > $params['limit']) {
// We've reached the one extra which shows that there are additional pages to be had. Stop here...
$this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->pt_timestamp));
break;
}
$title = Title::makeTitle($row->pt_namespace, $row->pt_title);
if (is_null($resultPageSet)) {
$vals = array();
ApiQueryBase::addTitleInfo($vals, $title);
if (isset($prop['timestamp'])) {
$vals['timestamp'] = wfTimestamp(TS_ISO_8601, $row->pt_timestamp);
}
if (isset($prop['user']) && !is_null($row->user_name)) {
$vals['user'] = $row->user_name;
}
if (isset($prop['user'])) {
$vals['userid'] = $row->pt_user;
}
if (isset($prop['comment'])) {
$vals['comment'] = $row->pt_reason;
}
if (isset($prop['parsedcomment'])) {
global $wgUser;
$vals['parsedcomment'] = $wgUser->getSkin()->formatComment($row->pt_reason, $title);
}
if (isset($prop['expiry'])) {
global $wgContLang;
$vals['expiry'] = $wgContLang->formatExpiry($row->pt_expiry, TS_ISO_8601);
}
if (isset($prop['level'])) {
$vals['level'] = $row->pt_create_perm;
}
$fit = $result->addValue(array('query', $this->getModuleName()), null, $vals);
if (!$fit) {
$this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->pt_timestamp));
break;
}
} else {
$titles[] = $title;
}
}
if (is_null($resultPageSet)) {
$result->setIndexedTagName_internal(array('query', $this->getModuleName()), $this->getModulePrefix());
} else {
$resultPageSet->populateFromTitles($titles);
}
}