本文整理汇总了PHP中ApiPageSet::populateFromTitles方法的典型用法代码示例。如果您正苦于以下问题:PHP ApiPageSet::populateFromTitles方法的具体用法?PHP ApiPageSet::populateFromTitles怎么用?PHP ApiPageSet::populateFromTitles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApiPageSet
的用法示例。
在下文中一共展示了ApiPageSet::populateFromTitles方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* @param ApiPageSet $resultPageSet
*/
private function run($resultPageSet = null)
{
$params = $this->extractRequestParams();
$search = $params['search'];
$limit = $params['limit'];
$namespaces = $params['namespace'];
$searcher = new TitlePrefixSearch();
$titles = $searcher->searchWithVariants($search, $limit, $namespaces);
if ($resultPageSet) {
$resultPageSet->populateFromTitles($titles);
} else {
$result = $this->getResult();
foreach ($titles as $title) {
if (!$limit--) {
break;
}
$vals = array('ns' => intval($title->getNamespace()), 'title' => $title->getPrefixedText());
if ($title->isSpecialPage()) {
$vals['special'] = '';
} else {
$vals['pageid'] = intval($title->getArticleId());
}
$fit = $result->addValue(array('query', $this->getModuleName()), null, $vals);
if (!$fit) {
break;
}
}
$result->setIndexedTagName_internal(array('query', $this->getModuleName()), $this->getModulePrefix());
}
}
示例2: run
/**
* @param ApiPageSet $resultPageSet
*/
private function run($resultPageSet = null)
{
$params = $this->extractRequestParams();
$search = $params['search'];
$limit = $params['limit'];
$namespaces = $params['namespace'];
$offset = $params['offset'];
$searchEngine = MediaWikiServices::getInstance()->newSearchEngine();
$searchEngine->setLimitOffset($limit + 1, $offset);
$searchEngine->setNamespaces($namespaces);
$titles = $searchEngine->extractTitles($searchEngine->completionSearchWithVariants($search));
if ($resultPageSet) {
$resultPageSet->setRedirectMergePolicy(function (array $current, array $new) {
if (!isset($current['index']) || $new['index'] < $current['index']) {
$current['index'] = $new['index'];
}
return $current;
});
if (count($titles) > $limit) {
$this->setContinueEnumParameter('offset', $offset + $params['limit']);
array_pop($titles);
}
$resultPageSet->populateFromTitles($titles);
foreach ($titles as $index => $title) {
$resultPageSet->setGeneratorData($title, ['index' => $index + $offset + 1]);
}
} else {
$result = $this->getResult();
$count = 0;
foreach ($titles as $title) {
if (++$count > $limit) {
$this->setContinueEnumParameter('offset', $offset + $params['limit']);
break;
}
$vals = ['ns' => intval($title->getNamespace()), 'title' => $title->getPrefixedText()];
if ($title->isSpecialPage()) {
$vals['special'] = true;
} else {
$vals['pageid'] = intval($title->getArticleID());
}
$fit = $result->addValue(['query', $this->getModuleName()], null, $vals);
if (!$fit) {
$this->setContinueEnumParameter('offset', $offset + $count - 1);
break;
}
}
$result->addIndexedTagName(['query', $this->getModuleName()], $this->getModulePrefix());
}
}
示例3: createPageSetWithRedirect
protected function createPageSetWithRedirect()
{
$target = Title::makeTitle(NS_MAIN, 'UTRedirectTarget');
$sourceA = Title::makeTitle(NS_MAIN, 'UTRedirectSourceA');
$sourceB = Title::makeTitle(NS_MAIN, 'UTRedirectSourceB');
self::editPage('UTRedirectTarget', 'api page set test');
self::editPage('UTRedirectSourceA', '#REDIRECT [[UTRedirectTarget]]');
self::editPage('UTRedirectSourceB', '#REDIRECT [[UTRedirectTarget]]');
$request = new FauxRequest(['redirects' => 1]);
$context = new RequestContext();
$context->setRequest($request);
$main = new ApiMain($context);
$pageSet = new ApiPageSet($main);
$pageSet->setGeneratorData($sourceA, ['index' => 1]);
$pageSet->setGeneratorData($sourceB, ['index' => 3]);
$pageSet->populateFromTitles([$sourceA, $sourceB]);
return [$target, $pageSet];
}
示例4: run
/**
* @param ApiPageSet $resultPageSet
*/
private function run($resultPageSet = null)
{
$params = $this->extractRequestParams();
$search = $params['search'];
$limit = $params['limit'];
$namespaces = $params['namespace'];
$offset = $params['offset'];
$searcher = new TitlePrefixSearch();
$titles = $searcher->searchWithVariants($search, $limit + 1, $namespaces, $offset);
if ($resultPageSet) {
if (count($titles) > $limit) {
$this->setContinueEnumParameter('offset', $offset + $params['limit']);
array_pop($titles);
}
$resultPageSet->populateFromTitles($titles);
foreach ($titles as $index => $title) {
$resultPageSet->setGeneratorData($title, array('index' => $index + $offset + 1));
}
} else {
$result = $this->getResult();
$count = 0;
foreach ($titles as $title) {
if (++$count > $limit) {
$this->setContinueEnumParameter('offset', $offset + $params['limit']);
break;
}
$vals = array('ns' => intval($title->getNamespace()), 'title' => $title->getPrefixedText());
if ($title->isSpecialPage()) {
$vals['special'] = true;
} else {
$vals['pageid'] = intval($title->getArticleId());
}
$fit = $result->addValue(array('query', $this->getModuleName()), null, $vals);
if (!$fit) {
$this->setContinueEnumParameter('offset', $offset + $count - 1);
break;
}
}
$result->addIndexedTagName(array('query', $this->getModuleName()), $this->getModulePrefix());
}
}
示例5: run
//.........这里部分代码省略.........
$result = $matches->next();
continue;
}
$title = $result->getTitle();
if ($resultPageSet === null) {
$vals = array();
ApiQueryBase::addTitleInfo($vals, $title);
if (isset($prop['snippet'])) {
$vals['snippet'] = $result->getTextSnippet($terms);
}
if (isset($prop['size'])) {
$vals['size'] = $result->getByteSize();
}
if (isset($prop['wordcount'])) {
$vals['wordcount'] = $result->getWordCount();
}
if (isset($prop['timestamp'])) {
$vals['timestamp'] = wfTimestamp(TS_ISO_8601, $result->getTimestamp());
}
if (isset($prop['titlesnippet'])) {
$vals['titlesnippet'] = $result->getTitleSnippet();
}
if (isset($prop['categorysnippet'])) {
$vals['categorysnippet'] = $result->getCategorySnippet();
}
if (!is_null($result->getRedirectTitle())) {
if (isset($prop['redirecttitle'])) {
$vals['redirecttitle'] = $result->getRedirectTitle()->getPrefixedText();
}
if (isset($prop['redirectsnippet'])) {
$vals['redirectsnippet'] = $result->getRedirectSnippet();
}
}
if (!is_null($result->getSectionTitle())) {
if (isset($prop['sectiontitle'])) {
$vals['sectiontitle'] = $result->getSectionTitle()->getFragment();
}
if (isset($prop['sectionsnippet'])) {
$vals['sectionsnippet'] = $result->getSectionSnippet();
}
}
if (isset($prop['isfilematch'])) {
$vals['isfilematch'] = $result->isFileMatch();
}
// Add item to results and see whether it fits
$fit = $apiResult->addValue(array('query', $this->getModuleName()), null, $vals);
if (!$fit) {
$this->setContinueEnumParameter('offset', $params['offset'] + $count - 1);
break;
}
} else {
$titles[] = $title;
}
$result = $matches->next();
}
$hasInterwikiResults = false;
$totalhits = null;
if ($interwiki && $resultPageSet === null && $matches->hasInterwikiResults()) {
foreach ($matches->getInterwikiResults() as $matches) {
$matches = $matches->getInterwikiResults();
$hasInterwikiResults = true;
// Include number of results if requested
if ($resultPageSet === null && isset($searchInfo['totalhits'])) {
$totalhits += $matches->getTotalHits();
}
$result = $matches->next();
while ($result) {
$title = $result->getTitle();
if ($resultPageSet === null) {
$vals = array('namespace' => $result->getInterwikiNamespaceText(), 'title' => $title->getText(), 'url' => $title->getFullUrl());
// Add item to results and see whether it fits
$fit = $apiResult->addValue(array('query', 'interwiki' . $this->getModuleName(), $result->getInterwikiPrefix()), null, $vals);
if (!$fit) {
// We hit the limit. We can't really provide any meaningful
// pagination info so just bail out
break;
}
} else {
$titles[] = $title;
}
$result = $matches->next();
}
}
if ($totalhits !== null) {
$apiResult->addValue(array('query', 'interwikisearchinfo'), 'totalhits', $totalhits);
}
}
if ($resultPageSet === null) {
$apiResult->addIndexedTagName(array('query', $this->getModuleName()), 'p');
if ($hasInterwikiResults) {
$apiResult->addIndexedTagName(array('query', 'interwiki' . $this->getModuleName()), 'p');
}
} else {
$resultPageSet->populateFromTitles($titles);
$offset = $params['offset'] + 1;
foreach ($titles as $index => $title) {
$resultPageSet->setGeneratorData($title, array('index' => $index + $offset));
}
}
}
示例6: run
//.........这里部分代码省略.........
$this->dieContinueUsageIf(strval($ar_id) !== $cont[3]);
$this->addWhere("ar_namespace {$op} {$ns} OR " . "(ar_namespace = {$ns} AND " . "(ar_title {$op} {$title} OR " . "(ar_title = {$title} AND " . "(ar_timestamp {$op} {$ts} OR " . "(ar_timestamp = {$ts} AND " . "ar_id {$op}= {$ar_id})))))");
} else {
$this->dieContinueUsageIf(count($cont) != 2);
$ts = $db->addQuotes($db->timestamp($cont[0]));
$ar_id = (int) $cont[1];
$this->dieContinueUsageIf(strval($ar_id) !== $cont[1]);
$this->addWhere("ar_timestamp {$op} {$ts} OR " . "(ar_timestamp = {$ts} AND " . "ar_id {$op}= {$ar_id})");
}
}
$this->addOption('LIMIT', $this->limit + 1);
$sort = $dir == 'newer' ? '' : ' DESC';
$orderby = [];
if ($optimizeGenerateTitles) {
// Targeting index name_title_timestamp
if ($params['namespace'] === null || count(array_unique($params['namespace'])) > 1) {
$orderby[] = "ar_namespace {$sort}";
}
$orderby[] = "ar_title {$sort}";
} elseif ($mode == 'all') {
// Targeting index name_title_timestamp
if ($params['namespace'] === null || count(array_unique($params['namespace'])) > 1) {
$orderby[] = "ar_namespace {$sort}";
}
$orderby[] = "ar_title {$sort}";
$orderby[] = "ar_timestamp {$sort}";
$orderby[] = "ar_id {$sort}";
} else {
// Targeting index usertext_timestamp
// 'user' is always constant.
$orderby[] = "ar_timestamp {$sort}";
$orderby[] = "ar_id {$sort}";
}
$this->addOption('ORDER BY', $orderby);
$res = $this->select(__METHOD__);
$pageMap = [];
// Maps ns&title to array index
$count = 0;
$nextIndex = 0;
$generated = [];
foreach ($res as $row) {
if (++$count > $this->limit) {
// We've had enough
if ($optimizeGenerateTitles) {
$this->setContinueEnumParameter('continue', "{$row->ar_namespace}|{$row->ar_title}");
} elseif ($mode == 'all') {
$this->setContinueEnumParameter('continue', "{$row->ar_namespace}|{$row->ar_title}|{$row->ar_timestamp}|{$row->ar_id}");
} else {
$this->setContinueEnumParameter('continue', "{$row->ar_timestamp}|{$row->ar_id}");
}
break;
}
// Miser mode namespace check
if ($miser_ns !== null && !in_array($row->ar_namespace, $miser_ns)) {
continue;
}
if ($resultPageSet !== null) {
if ($params['generatetitles']) {
$key = "{$row->ar_namespace}:{$row->ar_title}";
if (!isset($generated[$key])) {
$generated[$key] = Title::makeTitle($row->ar_namespace, $row->ar_title);
}
} else {
$generated[] = $row->ar_rev_id;
}
} else {
$revision = Revision::newFromArchiveRow($row);
$rev = $this->extractRevisionInfo($revision, $row);
if (!isset($pageMap[$row->ar_namespace][$row->ar_title])) {
$index = $nextIndex++;
$pageMap[$row->ar_namespace][$row->ar_title] = $index;
$title = $revision->getTitle();
$a = ['pageid' => $title->getArticleID(), 'revisions' => [$rev]];
ApiResult::setIndexedTagName($a['revisions'], 'rev');
ApiQueryBase::addTitleInfo($a, $title);
$fit = $result->addValue(['query', $this->getModuleName()], $index, $a);
} else {
$index = $pageMap[$row->ar_namespace][$row->ar_title];
$fit = $result->addValue(['query', $this->getModuleName(), $index, 'revisions'], null, $rev);
}
if (!$fit) {
if ($mode == 'all') {
$this->setContinueEnumParameter('continue', "{$row->ar_namespace}|{$row->ar_title}|{$row->ar_timestamp}|{$row->ar_id}");
} else {
$this->setContinueEnumParameter('continue', "{$row->ar_timestamp}|{$row->ar_id}");
}
break;
}
}
}
if ($resultPageSet !== null) {
if ($params['generatetitles']) {
$resultPageSet->populateFromTitles($generated);
} else {
$resultPageSet->populateFromRevisionIDs($generated);
}
} else {
$result->addIndexedTagName(['query', $this->getModuleName()], 'page');
}
}