当前位置: 首页>>代码示例>>PHP>>正文


PHP ApiQueryBase::addTitleInfo方法代码示例

本文整理汇总了PHP中ApiQueryBase::addTitleInfo方法的典型用法代码示例。如果您正苦于以下问题:PHP ApiQueryBase::addTitleInfo方法的具体用法?PHP ApiQueryBase::addTitleInfo怎么用?PHP ApiQueryBase::addTitleInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ApiQueryBase的用法示例。


在下文中一共展示了ApiQueryBase::addTitleInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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);
 }
开发者ID:amjadtbssm,项目名称:website,代码行数:38,代码来源:ApiPurge.php

示例2: 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);
 }
开发者ID:amjadtbssm,项目名称:website,代码行数:29,代码来源:ApiPatrol.php

示例3: 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);
 }
开发者ID:whysasse,项目名称:kmwiki,代码行数:30,代码来源:ApiPatrol.php

示例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);
     }
 }
开发者ID:Grprashanthkumar,项目名称:ColfusionWeb,代码行数:62,代码来源:ApiPurge.php

示例5: 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);
 }
开发者ID:tuxmania87,项目名称:GalaxyAdventures,代码行数:57,代码来源:ApiPurge.php

示例6: 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);
 }
开发者ID:seedbank,项目名称:old-repo,代码行数:18,代码来源:ApiPatrol.php

示例7: 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;
     }
 }
开发者ID:whysasse,项目名称:kmwiki,代码行数:24,代码来源:ApiPageSet.php

示例8: 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 );
		}
	}
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:18,代码来源:WikiSyncExporter.php

示例9: 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);
 }
开发者ID:BackupTheBerlios,项目名称:shoutwiki-svn,代码行数:40,代码来源:ApiQueryImages.php

示例10: 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);
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:39,代码来源:ApiPatrol.php

示例11: reportPage

 /**
  * @param Title $title
  * @param Title $origTitle
  * @param int $revisionCount
  * @param int $successCount
  * @param array $pageInfo
  * @return void
  */
 function reportPage($title, $origTitle, $revisionCount, $successCount, $pageInfo)
 {
     // Add a result entry
     $r = array();
     if ($title === null) {
         # Invalid or non-importable title
         $r['title'] = $pageInfo['title'];
         $r['invalid'] = true;
     } else {
         ApiQueryBase::addTitleInfo($r, $title);
         $r['revisions'] = intval($successCount);
     }
     $this->mResultArr[] = $r;
     // Piggyback on the parent to do the logging
     parent::reportPage($title, $origTitle, $revisionCount, $successCount, $pageInfo);
 }
开发者ID:mb720,项目名称:mediawiki,代码行数:24,代码来源:ApiImport.php

示例12: run


//.........这里部分代码省略.........
     }
     if ($params['user'] !== null) {
         $id = User::idFromName($params['user']);
         if ($id) {
             $this->addWhereFld('rev_user', $id);
         } else {
             $this->addWhereFld('rev_user_text', $params['user']);
         }
     } elseif ($params['excludeuser'] !== null) {
         $id = User::idFromName($params['excludeuser']);
         if ($id) {
             $this->addWhere('rev_user != ' . $id);
         } else {
             $this->addWhere('rev_user_text != ' . $db->addQuotes($params['excludeuser']));
         }
     }
     if ($params['user'] !== null || $params['excludeuser'] !== null) {
         // Paranoia: avoid brute force searches (bug 17342)
         if (!$this->getUser()->isAllowed('deletedhistory')) {
             $bitmask = Revision::DELETED_USER;
         } elseif (!$this->getUser()->isAllowedAny('suppressrevision', 'viewsuppressed')) {
             $bitmask = Revision::DELETED_USER | Revision::DELETED_RESTRICTED;
         } else {
             $bitmask = 0;
         }
         if ($bitmask) {
             $this->addWhere($db->bitAnd('rev_deleted', $bitmask) . " != {$bitmask}");
         }
     }
     $dir = $params['dir'];
     if ($params['continue'] !== null) {
         $op = $dir == 'newer' ? '>' : '<';
         $cont = explode('|', $params['continue']);
         $this->dieContinueUsageIf(count($cont) != 2);
         $ts = $db->addQuotes($db->timestamp($cont[0]));
         $rev_id = (int) $cont[1];
         $this->dieContinueUsageIf(strval($rev_id) !== $cont[1]);
         $this->addWhere("rev_timestamp {$op} {$ts} OR " . "(rev_timestamp = {$ts} AND " . "rev_id {$op}= {$rev_id})");
     }
     $this->addOption('LIMIT', $this->limit + 1);
     $sort = $dir == 'newer' ? '' : ' DESC';
     $orderby = array();
     // Targeting index rev_timestamp, user_timestamp, or usertext_timestamp
     // But 'user' is always constant for the latter two, so it doesn't matter here.
     $orderby[] = "rev_timestamp {$sort}";
     $orderby[] = "rev_id {$sort}";
     $this->addOption('ORDER BY', $orderby);
     $res = $this->select(__METHOD__);
     $pageMap = array();
     // Maps rev_page to array index
     $count = 0;
     $nextIndex = 0;
     $generated = array();
     foreach ($res as $row) {
         if (++$count > $this->limit) {
             // We've had enough
             $this->setContinueEnumParameter('continue', "{$row->rev_timestamp}|{$row->rev_id}");
             break;
         }
         // Miser mode namespace check
         if ($miser_ns !== null && !in_array($row->page_namespace, $miser_ns)) {
             continue;
         }
         if ($resultPageSet !== null) {
             if ($params['generatetitles']) {
                 $generated[$row->rev_page] = $row->rev_page;
             } else {
                 $generated[] = $row->rev_id;
             }
         } else {
             $revision = Revision::newFromRow($row);
             $rev = $this->extractRevisionInfo($revision, $row);
             if (!isset($pageMap[$row->rev_page])) {
                 $index = $nextIndex++;
                 $pageMap[$row->rev_page] = $index;
                 $title = $revision->getTitle();
                 $a = array('pageid' => $title->getArticleID(), 'revisions' => array($rev));
                 ApiResult::setIndexedTagName($a['revisions'], 'rev');
                 ApiQueryBase::addTitleInfo($a, $title);
                 $fit = $result->addValue(array('query', $this->getModuleName()), $index, $a);
             } else {
                 $index = $pageMap[$row->rev_page];
                 $fit = $result->addValue(array('query', $this->getModuleName(), $index, 'revisions'), null, $rev);
             }
             if (!$fit) {
                 $this->setContinueEnumParameter('continue', "{$row->rev_timestamp}|{$row->rev_id}");
                 break;
             }
         }
     }
     if ($resultPageSet !== null) {
         if ($params['generatetitles']) {
             $resultPageSet->populateFromPageIDs($generated);
         } else {
             $resultPageSet->populateFromRevisionIDs($generated);
         }
     } else {
         $result->addIndexedTagName(array('query', $this->getModuleName()), 'page');
     }
 }
开发者ID:rrameshs,项目名称:mediawiki,代码行数:101,代码来源:ApiQueryAllRevisions.php

示例13: run

 /**
  * @param $resultPageSet ApiPageSet
  * @return void
  */
 private function run($resultPageSet = null)
 {
     $this->selectNamedDB('watchlist', DB_SLAVE, 'watchlist');
     $params = $this->extractRequestParams();
     $user = $this->getWatchlistUser($params);
     $prop = array_flip((array) $params['prop']);
     $show = array_flip((array) $params['show']);
     if (isset($show['changed']) && isset($show['!changed'])) {
         $this->dieUsageMsg('show');
     }
     $this->addTables('watchlist');
     $this->addFields(array('wl_namespace', 'wl_title'));
     $this->addFieldsIf('wl_notificationtimestamp', isset($prop['changed']));
     $this->addWhereFld('wl_user', $user->getId());
     $this->addWhereFld('wl_namespace', $params['namespace']);
     $this->addWhereIf('wl_notificationtimestamp IS NOT NULL', isset($show['changed']));
     $this->addWhereIf('wl_notificationtimestamp IS NULL', isset($show['!changed']));
     if (isset($params['continue'])) {
         $cont = explode('|', $params['continue']);
         $this->dieContinueUsageIf(count($cont) != 2);
         $ns = intval($cont[0]);
         $this->dieContinueUsageIf(strval($ns) !== $cont[0]);
         $title = $this->getDB()->addQuotes($cont[1]);
         $op = $params['dir'] == 'ascending' ? '>' : '<';
         $this->addWhere("wl_namespace {$op} {$ns} OR " . "(wl_namespace = {$ns} AND " . "wl_title {$op}= {$title})");
     }
     $sort = $params['dir'] == 'descending' ? ' DESC' : '';
     // Don't ORDER BY wl_namespace if it's constant in the WHERE clause
     if (count($params['namespace']) == 1) {
         $this->addOption('ORDER BY', 'wl_title' . $sort);
     } else {
         $this->addOption('ORDER BY', array('wl_namespace' . $sort, 'wl_title' . $sort));
     }
     $this->addOption('LIMIT', $params['limit'] + 1);
     $res = $this->select(__METHOD__);
     $titles = array();
     $count = 0;
     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('continue', $row->wl_namespace . '|' . $row->wl_title);
             break;
         }
         $t = Title::makeTitle($row->wl_namespace, $row->wl_title);
         if (is_null($resultPageSet)) {
             $vals = array();
             ApiQueryBase::addTitleInfo($vals, $t);
             if (isset($prop['changed']) && !is_null($row->wl_notificationtimestamp)) {
                 $vals['changed'] = wfTimestamp(TS_ISO_8601, $row->wl_notificationtimestamp);
             }
             $fit = $this->getResult()->addValue($this->getModuleName(), null, $vals);
             if (!$fit) {
                 $this->setContinueEnumParameter('continue', $row->wl_namespace . '|' . $row->wl_title);
                 break;
             }
         } else {
             $titles[] = $t;
         }
     }
     if (is_null($resultPageSet)) {
         $this->getResult()->setIndexedTagName_internal($this->getModuleName(), 'wr');
     } else {
         $resultPageSet->populateFromTitles($titles);
     }
 }
开发者ID:mangowi,项目名称:mediawiki,代码行数:69,代码来源:ApiQueryWatchlistRaw.php

示例14: outputGeneralPageInfo

 /**
  * Appends an element for each page in the current pageSet with the
  * most general information (id, title), plus any title normalizations
  * and missing or invalid title/pageids/revids.
  */
 private function outputGeneralPageInfo()
 {
     $pageSet = $this->getPageSet();
     $result = $this->getResult();
     // We don't check for a full result set here because we can't be adding
     // more than 380K. The maximum revision size is in the megabyte range,
     // and the maximum result size must be even higher than that.
     $values = $pageSet->getNormalizedTitlesAsResult($result);
     if ($values) {
         $result->addValue('query', 'normalized', $values);
     }
     $values = $pageSet->getConvertedTitlesAsResult($result);
     if ($values) {
         $result->addValue('query', 'converted', $values);
     }
     $values = $pageSet->getInterwikiTitlesAsResult($result, $this->mParams['iwurl']);
     if ($values) {
         $result->addValue('query', 'interwiki', $values);
     }
     $values = $pageSet->getRedirectTitlesAsResult($result);
     if ($values) {
         $result->addValue('query', 'redirects', $values);
     }
     $values = $pageSet->getMissingRevisionIDsAsResult($result);
     if ($values) {
         $result->addValue('query', 'badrevids', $values);
     }
     // Page elements
     $pages = array();
     // Report any missing titles
     foreach ($pageSet->getMissingTitles() as $fakeId => $title) {
         $vals = array();
         ApiQueryBase::addTitleInfo($vals, $title);
         $vals['missing'] = '';
         $pages[$fakeId] = $vals;
     }
     // Report any invalid titles
     foreach ($pageSet->getInvalidTitles() as $fakeId => $title) {
         $pages[$fakeId] = array('title' => $title, 'invalid' => '');
     }
     // Report any missing page ids
     foreach ($pageSet->getMissingPageIDs() as $pageid) {
         $pages[$pageid] = array('pageid' => $pageid, 'missing' => '');
     }
     // Report special pages
     /** @var $title Title */
     foreach ($pageSet->getSpecialTitles() as $fakeId => $title) {
         $vals = array();
         ApiQueryBase::addTitleInfo($vals, $title);
         $vals['special'] = '';
         if ($title->isSpecialPage() && !SpecialPageFactory::exists($title->getDBkey())) {
             $vals['missing'] = '';
         } elseif ($title->getNamespace() == NS_MEDIA && !wfFindFile($title)) {
             $vals['missing'] = '';
         }
         $pages[$fakeId] = $vals;
     }
     // Output general page information for found titles
     foreach ($pageSet->getGoodTitles() as $pageid => $title) {
         $vals = array();
         $vals['pageid'] = $pageid;
         ApiQueryBase::addTitleInfo($vals, $title);
         $pages[$pageid] = $vals;
     }
     if (count($pages)) {
         if ($this->mParams['indexpageids']) {
             $pageIDs = array_keys($pages);
             // json treats all map keys as strings - converting to match
             $pageIDs = array_map('strval', $pageIDs);
             $result->setIndexedTagName($pageIDs, 'id');
             $result->addValue('query', 'pageids', $pageIDs);
         }
         $result->setIndexedTagName($pages, 'page');
         $result->addValue('query', 'pages', $pages);
     }
     if ($this->mParams['export']) {
         $this->doExport($pageSet, $result);
     }
 }
开发者ID:Tarendai,项目名称:spring-website,代码行数:84,代码来源:ApiQuery.php

示例15: run

 /**
  * @param $resultPageSet ApiPageSet
  * @return void
  */
 private function run($resultPageSet = null)
 {
     global $wgContLang;
     $params = $this->extractRequestParams();
     // Extract parameters
     $limit = $params['limit'];
     $query = $params['search'];
     $what = $params['what'];
     $searchInfo = array_flip($params['info']);
     $prop = array_flip($params['prop']);
     // Create search engine instance and set options
     $search = isset($params['backend']) && $params['backend'] != self::BACKEND_NULL_PARAM ? SearchEngine::create($params['backend']) : SearchEngine::create();
     $search->setLimitOffset($limit + 1, $params['offset']);
     $search->setNamespaces($params['namespace']);
     $search->showRedirects = $params['redirects'];
     $query = $search->transformSearchTerm($query);
     $query = $search->replacePrefixes($query);
     // Perform the actual search
     if ($what == 'text') {
         $matches = $search->searchText($query);
     } elseif ($what == 'title') {
         $matches = $search->searchTitle($query);
     } elseif ($what == 'nearmatch') {
         $matches = SearchEngine::getNearMatchResultSet($query);
     } else {
         // We default to title searches; this is a terrible legacy
         // of the way we initially set up the MySQL fulltext-based
         // search engine with separate title and text fields.
         // In the future, the default should be for a combined index.
         $what = 'title';
         $matches = $search->searchTitle($query);
         // Not all search engines support a separate title search,
         // for instance the Lucene-based engine we use on Wikipedia.
         // In this case, fall back to full-text search (which will
         // include titles in it!)
         if (is_null($matches)) {
             $what = 'text';
             $matches = $search->searchText($query);
         }
     }
     if (is_null($matches)) {
         $this->dieUsage("{$what} search is disabled", "search-{$what}-disabled");
     } elseif ($matches instanceof Status && !$matches->isGood()) {
         $this->dieUsage($matches->getWikiText(), 'search-error');
     }
     $apiResult = $this->getResult();
     // Add search meta data to result
     if (isset($searchInfo['totalhits'])) {
         $totalhits = $matches->getTotalHits();
         if ($totalhits !== null) {
             $apiResult->addValue(array('query', 'searchinfo'), 'totalhits', $totalhits);
         }
     }
     if (isset($searchInfo['suggestion']) && $matches->hasSuggestion()) {
         $apiResult->addValue(array('query', 'searchinfo'), 'suggestion', $matches->getSuggestionQuery());
     }
     // Add the search results to the result
     $terms = $wgContLang->convertForSearchResult($matches->termMatches());
     $titles = array();
     $count = 0;
     $result = $matches->next();
     while ($result) {
         if (++$count > $limit) {
             // We've reached the one extra which shows that there are
             // additional items to be had. Stop here...
             $this->setContinueEnumParameter('offset', $params['offset'] + $params['limit']);
             break;
         }
         // Silently skip broken and missing titles
         if ($result->isBrokenTitle() || $result->isMissingRevision()) {
             $result = $matches->next();
             continue;
         }
         $title = $result->getTitle();
         if (is_null($resultPageSet)) {
             $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 (!is_null($result->getScore()) && isset($prop['score'])) {
                 $vals['score'] = $result->getScore();
             }
             if (isset($prop['titlesnippet'])) {
                 $vals['titlesnippet'] = $result->getTitleSnippet($terms);
             }
             if (!is_null($result->getRedirectTitle())) {
//.........这里部分代码省略.........
开发者ID:biribogos,项目名称:wikihow-src,代码行数:101,代码来源:ApiQuerySearch.php


注:本文中的ApiQueryBase::addTitleInfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。