本文整理汇总了PHP中SpecialPageFactory::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP SpecialPageFactory::exists方法的具体用法?PHP SpecialPageFactory::exists怎么用?PHP SpecialPageFactory::exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SpecialPageFactory
的用法示例。
在下文中一共展示了SpecialPageFactory::exists方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onSkinTemplatePageBeforeUserMsg
/**
* hook handler
* check conditions and display message
*
* @author Maciej Błaszkowski <marooned at wikia-inc.com>
*/
static function onSkinTemplatePageBeforeUserMsg(&$msgs)
{
global $wgUser, $wgMemc, $wgCookiePrefix;
if (self::$messageSeen) {
//user is just seeing the message - hide notification for this session
return true;
}
//get timestamp of message
$communityMessagesTimestamp = $wgMemc->get(wfMemcKey('CommunityMessagesTimestamp'));
if (!$communityMessagesTimestamp) {
$msgTitle = Title::newFromText('community-corner', NS_MEDIAWIKI);
if ($msgTitle) {
$msgRev = Revision::newFromTitle($msgTitle);
if ($msgRev) {
$communityMessagesTimestamp = wfTimestamp(TS_UNIX, $msgRev->getTimestamp());
$wgMemc->set(wfMemcKey('CommunityMessagesTimestamp'), $communityMessagesTimestamp, 86400);
}
}
}
if (!$communityMessagesTimestamp) {
//no message?
return true;
}
if ($communityMessagesTimestamp < time() - 86400) {
//message older than 24h - do not inform user about it
return true;
}
if ($wgUser->isLoggedIn()) {
$userTimestamp = self::getUserTimestamp($wgUser);
if ($userTimestamp !== false && $userTimestamp >= $communityMessagesTimestamp) {
//old, seen message
return true;
}
} else {
//anon
//compare timestamp from cookie
if (isset($_COOKIE[$wgCookiePrefix . 'CommunityMessages']) && $_COOKIE[$wgCookiePrefix . 'CommunityMessages'] >= $communityMessagesTimestamp) {
//old, seen message
return true;
}
}
if ($msgs != '') {
$msgs .= '<br/>';
}
// render message
$msg = '';
if (SpecialPageFactory::exists('WikiActivity')) {
$msg = wfMsgExt('communitymessages-notice-msg', array('parseinline', 'content'));
}
// macbre: add an easy way for Oasis to show it's own notification for community messages
wfRunHooks('CommunityMessages::showMessage', array(&$msg));
return true;
}
示例2: returnTitleToLua
/**
* Extract information from a Title object for return to Lua
*
* This also records a link to this title in the current ParserOutput
* and caches the title for repeated lookups. The caller should call
* incrementExpensiveFunctionCount() if necessary.
*
* @param $title Title Title to return
* @return array Lua data
*/
private function returnTitleToLua(Title $title)
{
// Cache it
$this->titleCache[$title->getPrefixedDBkey()] = $title;
if ($title->getArticleID() > 0) {
$this->idCache[$title->getArticleID()] = $title;
}
// Record a link
if ($this->getParser() && !$title->equals($this->getTitle())) {
$this->getParser()->getOutput()->addLink($title);
}
$ns = $title->getNamespace();
$ret = array('isLocal' => (bool) $title->isLocal(), 'isRedirect' => (bool) $title->isRedirect(), 'interwiki' => $title->getInterwiki(), 'namespace' => $ns, 'nsText' => $title->getNsText(), 'text' => $title->getText(), 'id' => $title->getArticleID(), 'fragment' => $title->getFragment(), 'thePartialUrl' => $title->getPartialURL());
if ($ns === NS_SPECIAL) {
$ret['exists'] = (bool) SpecialPageFactory::exists($title->getDBkey());
} else {
$ret['exists'] = $ret['id'] > 0;
}
if ($ns !== NS_FILE && $ns !== NS_MEDIA) {
$ret['fileExists'] = false;
}
return $ret;
}
示例3: isAlwaysKnown
/**
* Should links to this title be shown as potentially viewable (i.e. as
* "bluelinks"), even if there's no record by this title in the page
* table?
*
* This function is semi-deprecated for public use, as well as somewhat
* misleadingly named. You probably just want to call isKnown(), which
* calls this function internally.
*
* (ISSUE: Most of these checks are cheap, but the file existence check
* can potentially be quite expensive. Including it here fixes a lot of
* existing code, but we might want to add an optional parameter to skip
* it and any other expensive checks.)
*
* @return bool
*/
public function isAlwaysKnown()
{
$isKnown = null;
/**
* Allows overriding default behavior for determining if a page exists.
* If $isKnown is kept as null, regular checks happen. If it's
* a boolean, this value is returned by the isKnown method.
*
* @since 1.20
*
* @param Title $title
* @param bool|null $isKnown
*/
Hooks::run('TitleIsAlwaysKnown', array($this, &$isKnown));
if (!is_null($isKnown)) {
return $isKnown;
}
if ($this->isExternal()) {
return true;
// any interwiki link might be viewable, for all we know
}
switch ($this->mNamespace) {
case NS_MEDIA:
case NS_FILE:
// file exists, possibly in a foreign repo
return (bool) wfFindFile($this);
case NS_SPECIAL:
// valid special page
return SpecialPageFactory::exists($this->getDBkey());
case NS_MAIN:
// selflink, possibly with fragment
return $this->mDbkeyform == '';
case NS_MEDIAWIKI:
// known system message
return $this->hasSourceText() !== false;
default:
return false;
}
}
示例4: 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);
}
}
示例5: isAlwaysKnown
/**
* Should links to this title be shown as potentially viewable (i.e. as
* "bluelinks"), even if there's no record by this title in the page
* table?
*
* This function is semi-deprecated for public use, as well as somewhat
* misleadingly named. You probably just want to call isKnown(), which
* calls this function internally.
*
* (ISSUE: Most of these checks are cheap, but the file existence check
* can potentially be quite expensive. Including it here fixes a lot of
* existing code, but we might want to add an optional parameter to skip
* it and any other expensive checks.)
*
* @return Bool
*/
public function isAlwaysKnown()
{
if ($this->mInterwiki != '') {
return true;
// any interwiki link might be viewable, for all we know
}
switch ($this->mNamespace) {
case NS_MEDIA:
case NS_FILE:
// file exists, possibly in a foreign repo
return (bool) wfFindFile($this);
case NS_SPECIAL:
// valid special page
return SpecialPageFactory::exists($this->getDBkey());
case NS_MAIN:
// selflink, possibly with fragment
return $this->mDbkeyform == '';
case NS_MEDIAWIKI:
// known system message
return $this->hasSourceText() !== false;
default:
return false;
}
}
示例6: ifexistCommon
/**
* @param $parser Parser
* @param $frame PPFrame
* @param $titletext string
* @param $then string
* @param $else string
*
* @return string
*/
public static function ifexistCommon($parser, $frame, $titletext = '', $then = '', $else = '')
{
global $wgContLang;
$title = Title::newFromText($titletext);
$wgContLang->findVariantLink($titletext, $title, true);
if ($title) {
if ($title->getNamespace() == NS_MEDIA) {
/* If namespace is specified as NS_MEDIA, then we want to
* check the physical file, not the "description" page.
*/
if (!self::incrementIfexistCount($parser, $frame)) {
return $else;
}
$file = wfFindFile($title);
if (!$file) {
return $else;
}
$parser->mOutput->addImage($file->getName(), $file->getTimestamp(), $file->getSha1());
return $file->exists() ? $then : $else;
} elseif ($title->getNamespace() == NS_SPECIAL) {
/* Don't bother with the count for special pages,
* since their existence can be checked without
* accessing the database.
*/
return SpecialPageFactory::exists($title->getDBkey()) ? $then : $else;
} elseif ($title->isExternal()) {
/* Can't check the existence of pages on other sites,
* so just return $else. Makes a sort of sense, since
* they don't exist _locally_.
*/
return $else;
} else {
$pdbk = $title->getPrefixedDBkey();
if (!self::incrementIfexistCount($parser, $frame)) {
return $else;
}
$lc = LinkCache::singleton();
$id = $lc->getGoodLinkID($pdbk);
if ($id != 0) {
$parser->mOutput->addLink($title, $id);
return $then;
} elseif ($lc->isBadLink($pdbk)) {
$parser->mOutput->addLink($title, 0);
return $else;
}
$id = $title->getArticleID();
$parser->mOutput->addLink($title, $id);
if ($id) {
return $then;
}
}
}
return $else;
}
示例7: 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 can't really handle max-result-size failure here, but we need to
// check anyway in case someone set the limit stupidly low.
$fit = true;
$values = $pageSet->getNormalizedTitlesAsResult($result);
if ($values) {
$fit = $fit && $result->addValue('query', 'normalized', $values);
}
$values = $pageSet->getConvertedTitlesAsResult($result);
if ($values) {
$fit = $fit && $result->addValue('query', 'converted', $values);
}
$values = $pageSet->getInterwikiTitlesAsResult($result, $this->mParams['iwurl']);
if ($values) {
$fit = $fit && $result->addValue('query', 'interwiki', $values);
}
$values = $pageSet->getRedirectTitlesAsResult($result);
if ($values) {
$fit = $fit && $result->addValue('query', 'redirects', $values);
}
$values = $pageSet->getMissingRevisionIDsAsResult($result);
if ($values) {
$fit = $fit && $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');
$fit = $fit && $result->addValue('query', 'pageids', $pageIDs);
}
$result->setIndexedTagName($pages, 'page');
$fit = $fit && $result->addValue('query', 'pages', $pages);
}
if (!$fit) {
$this->dieUsage('The value of $wgAPIMaxResultSize on this wiki is ' . 'too small to hold basic result information', 'badconfig');
}
if ($this->mParams['export']) {
$this->doExport($pageSet, $result);
}
}
示例8: exists
/**
* Check if a given name exist as a special page or as a special page alias
*
* @param $name String: name of a special page
* @return Boolean: true if a special page exists with this name
* @deprecated since 1.18 call SpecialPageFactory method directly
*/
static function exists($name)
{
wfDeprecated(__METHOD__, '1.18');
return SpecialPageFactory::exists($name);
}
示例9: 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.
// Title normalizations
$normValues = array();
foreach ($pageSet->getNormalizedTitles() as $rawTitleStr => $titleStr) {
$normValues[] = array('from' => $rawTitleStr, 'to' => $titleStr);
}
if (count($normValues)) {
$result->setIndexedTagName($normValues, 'n');
$result->addValue('query', 'normalized', $normValues);
}
// Title conversions
$convValues = array();
foreach ($pageSet->getConvertedTitles() as $rawTitleStr => $titleStr) {
$convValues[] = array('from' => $rawTitleStr, 'to' => $titleStr);
}
if (count($convValues)) {
$result->setIndexedTagName($convValues, 'c');
$result->addValue('query', 'converted', $convValues);
}
// Interwiki titles
$intrwValues = array();
foreach ($pageSet->getInterwikiTitles() as $rawTitleStr => $interwikiStr) {
$item = array('title' => $rawTitleStr, 'iw' => $interwikiStr);
if ($this->iwUrl) {
$title = Title::newFromText($rawTitleStr);
$item['url'] = wfExpandUrl($title->getFullURL(), PROTO_CURRENT);
}
$intrwValues[] = $item;
}
if (count($intrwValues)) {
$result->setIndexedTagName($intrwValues, 'i');
$result->addValue('query', 'interwiki', $intrwValues);
}
// Show redirect information
$redirValues = array();
foreach ($pageSet->getRedirectTitles() as $titleStrFrom => $titleTo) {
$r = array('from' => strval($titleStrFrom), 'to' => $titleTo->getPrefixedText());
if ($titleTo->getFragment() !== '') {
$r['tofragment'] = $titleTo->getFragment();
}
$redirValues[] = $r;
}
if (count($redirValues)) {
$result->setIndexedTagName($redirValues, 'r');
$result->addValue('query', 'redirects', $redirValues);
}
// Missing revision elements
$missingRevIDs = $pageSet->getMissingRevisionIDs();
if (count($missingRevIDs)) {
$revids = array();
foreach ($missingRevIDs as $revid) {
$revids[$revid] = array('revid' => $revid);
}
$result->setIndexedTagName($revids, 'rev');
$result->addValue('query', 'badrevids', $revids);
}
// 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
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;
//.........这里部分代码省略.........
示例10: getExpensiveData
/**
* Extract expensive information from a Title object for return to Lua
*
* This records a link to this title in the current ParserOutput and caches the
* title for repeated lookups. It may call incrementExpensiveFunctionCount() if
* the title is not already cached.
*
* @param string $text Title text
* @return array Lua data
*/
public function getExpensiveData($text)
{
$this->checkType('getExpensiveData', 1, $text, 'string');
$title = Title::newFromText($text);
if (!$title) {
return array(null);
}
$dbKey = $title->getPrefixedDBkey();
if (isset($this->titleCache[$dbKey])) {
// It was already cached, so we already did the expensive work and added a link
$title = $this->titleCache[$dbKey];
} else {
if (!$title->equals($this->getTitle())) {
$this->incrementExpensiveFunctionCount();
// Record a link
if ($this->getParser()) {
$this->getParser()->getOutput()->addLink($title);
}
}
// Cache it
$this->titleCache[$dbKey] = $title;
if ($title->getArticleID() > 0) {
$this->idCache[$title->getArticleID()] = $title;
}
}
$ret = array('isRedirect' => (bool) $title->isRedirect(), 'id' => $title->getArticleID(), 'contentModel' => $title->getContentModel());
if ($title->getNamespace() === NS_SPECIAL) {
$ret['exists'] = (bool) SpecialPageFactory::exists($title->getDBkey());
} else {
// bug 70495: don't just check whether the ID != 0
$ret['exists'] = $title->exists();
}
return array($ret);
}
示例11: filterSpecialPages
private function filterSpecialPages($nodes, $filterInactiveSpecialPages)
{
if (!$filterInactiveSpecialPages) {
return $nodes;
}
wfProfileIn(__METHOD__);
// filters out every special page that is not defined
foreach ($nodes as $key => &$node) {
if (isset($node[self::ORIGINAL]) && stripos($node[self::ORIGINAL], 'special:') === 0) {
list(, $specialPageName) = explode(':', $node[self::ORIGINAL]);
if (!SpecialPageFactory::exists($specialPageName)) {
$inParentKey = array_search($key, $nodes[$node[self::PARENT_INDEX]][self::CHILDREN]);
// remove from parent's child list
unset($nodes[$node[self::PARENT_INDEX]][self::CHILDREN][$inParentKey]);
// remove node
unset($nodes[$key]);
} else {
// store special page canonical name for click tracking
$node[self::CANONICAL_NAME] = $specialPageName;
}
}
}
wfProfileOut(__METHOD__);
return $nodes;
}
示例12: exists
/**
* Check if a given name exist as a special page or as a special page alias
*
* @param $name String: name of a special page
* @return Boolean: true if a special page exists with this name
* @deprecated since 1.18 call SpecialPageFactory method directly
*/
static function exists($name)
{
return SpecialPageFactory::exists($name);
}