本文整理汇总了PHP中ApiPageSet::getRedirectTitles方法的典型用法代码示例。如果您正苦于以下问题:PHP ApiPageSet::getRedirectTitles方法的具体用法?PHP ApiPageSet::getRedirectTitles怎么用?PHP ApiPageSet::getRedirectTitles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApiPageSet
的用法示例。
在下文中一共展示了ApiPageSet::getRedirectTitles方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute()
{
// The data is hot but user-dependent, like page views, so we set vary cookies
$this->getMain()->setCacheMode('anon-public-user-private');
// Get parameters
$params = $this->extractRequestParams();
$text = $params['text'];
$title = $params['title'];
if ($title === null) {
$titleProvided = false;
// A title is needed for parsing, so arbitrarily choose one
$title = 'API';
} else {
$titleProvided = true;
}
$page = $params['page'];
$pageid = $params['pageid'];
$oldid = $params['oldid'];
$model = $params['contentmodel'];
$format = $params['contentformat'];
if (!is_null($page) && (!is_null($text) || $titleProvided)) {
$this->dieUsage('The page parameter cannot be used together with the text and title parameters', 'params');
}
$prop = array_flip($params['prop']);
if (isset($params['section'])) {
$this->section = $params['section'];
if (!preg_match('/^((T-)?\\d+|new)$/', $this->section)) {
$this->dieUsage("The section parameter must be a valid section id or 'new'", "invalidsection");
}
} else {
$this->section = false;
}
// The parser needs $wgTitle to be set, apparently the
// $title parameter in Parser::parse isn't enough *sigh*
// TODO: Does this still need $wgTitle?
global $wgParser, $wgTitle;
$redirValues = null;
// Return result
$result = $this->getResult();
if (!is_null($oldid) || !is_null($pageid) || !is_null($page)) {
if ($this->section === 'new') {
$this->dieUsage('section=new cannot be combined with oldid, pageid or page parameters. ' . 'Please use text', 'params');
}
if (!is_null($oldid)) {
// Don't use the parser cache
$rev = Revision::newFromId($oldid);
if (!$rev) {
$this->dieUsage("There is no revision ID {$oldid}", 'missingrev');
}
if (!$rev->userCan(Revision::DELETED_TEXT, $this->getUser())) {
$this->dieUsage("You don't have permission to view deleted revisions", 'permissiondenied');
}
$titleObj = $rev->getTitle();
$wgTitle = $titleObj;
$pageObj = WikiPage::factory($titleObj);
$popts = $this->makeParserOptions($pageObj, $params);
// If for some reason the "oldid" is actually the current revision, it may be cached
// Deliberately comparing $pageObj->getLatest() with $rev->getId(), rather than
// checking $rev->isCurrent(), because $pageObj is what actually ends up being used,
// and if its ->getLatest() is outdated, $rev->isCurrent() won't tell us that.
if ($rev->getId() == $pageObj->getLatest()) {
// May get from/save to parser cache
$p_result = $this->getParsedContent($pageObj, $popts, $pageid, isset($prop['wikitext']));
} else {
// This is an old revision, so get the text differently
$this->content = $rev->getContent(Revision::FOR_THIS_USER, $this->getUser());
if ($this->section !== false) {
$this->content = $this->getSectionContent($this->content, 'r' . $rev->getId());
}
// Should we save old revision parses to the parser cache?
$p_result = $this->content->getParserOutput($titleObj, $rev->getId(), $popts);
}
} else {
// Not $oldid, but $pageid or $page
if ($params['redirects']) {
$reqParams = array('redirects' => '');
if (!is_null($pageid)) {
$reqParams['pageids'] = $pageid;
} else {
// $page
$reqParams['titles'] = $page;
}
$req = new FauxRequest($reqParams);
$main = new ApiMain($req);
$pageSet = new ApiPageSet($main);
$pageSet->execute();
$redirValues = $pageSet->getRedirectTitlesAsResult($this->getResult());
$to = $page;
foreach ($pageSet->getRedirectTitles() as $title) {
$to = $title->getFullText();
}
$pageParams = array('title' => $to);
} elseif (!is_null($pageid)) {
$pageParams = array('pageid' => $pageid);
} else {
// $page
$pageParams = array('title' => $page);
}
$pageObj = $this->getTitleOrPageId($pageParams, 'fromdb');
$titleObj = $pageObj->getTitle();
//.........这里部分代码省略.........