本文整理汇总了PHP中Title::inNamespace方法的典型用法代码示例。如果您正苦于以下问题:PHP Title::inNamespace方法的具体用法?PHP Title::inNamespace怎么用?PHP Title::inNamespace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Title
的用法示例。
在下文中一共展示了Title::inNamespace方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUserPermissionsErrors
/**
* getUserPermissionsErrors hook
*
* @param Title $title
* @param User $user
* @param string $action
* @param $result
* @return bool
*/
public static function getUserPermissionsErrors(Title $title, User $user, $action, &$result)
{
if (!$title->inNamespace(NS_HIERA)) {
return true;
}
if ($action === 'create' || $action === 'edit') {
if (!$user->isLoggedIn()) {
$result = array('openstackmanager-notloggedin');
return false;
}
$userLDAP = new OpenStackNovaUser();
if (!$userLDAP->exists()) {
$result = array('openstackmanager-nonovacred-admincreate');
}
$project = $title->getText();
if (!$userLDAP->inRole('projectadmin', $project) && !$user->isAllowed('editallhiera')) {
$result = array('openstackmanager-hiera-noadmin', $project);
return false;
}
}
return true;
}
示例2: isValidMoveTarget
/**
* Checks if $this can be moved to a given Title
* - Selects for update, so don't call it unless you mean business
*
* @since 1.25
* @return bool
*/
protected function isValidMoveTarget()
{
# Is it an existing file?
if ($this->newTitle->inNamespace(NS_FILE)) {
$file = wfLocalFile($this->newTitle);
$file->load(File::READ_LATEST);
if ($file->exists()) {
wfDebug(__METHOD__ . ": file exists\n");
return false;
}
}
# Is it a redirect with no history?
if (!$this->newTitle->isSingleRevRedirect()) {
wfDebug(__METHOD__ . ": not a one-rev redirect\n");
return false;
}
# Get the article text
$rev = Revision::newFromTitle($this->newTitle, false, Revision::READ_LATEST);
if (!is_object($rev)) {
return false;
}
$content = $rev->getContent();
# Does the redirect point to the source?
# Or is it a broken self-redirect, usually caused by namespace collisions?
$redirTitle = $content ? $content->getRedirectTarget() : null;
if ($redirTitle) {
if ($redirTitle->getPrefixedDBkey() !== $this->oldTitle->getPrefixedDBkey() && $redirTitle->getPrefixedDBkey() !== $this->newTitle->getPrefixedDBkey()) {
wfDebug(__METHOD__ . ": redirect points to other page\n");
return false;
} else {
return true;
}
} else {
# Fail safe (not a redirect after all. strange.)
wfDebug(__METHOD__ . ": failsafe: database says " . $this->newTitle->getPrefixedDBkey() . " is a redirect, but it doesn't contain a valid redirect.\n");
return false;
}
}
示例3: execute
function execute($par)
{
$this->useTransactionalTimeLimit();
$user = $this->getUser();
$this->setHeaders();
$this->outputHeader();
$this->loadRequest($par);
$this->checkPermissions();
// Needs to be after mTargetObj is set
$out = $this->getOutput();
if (is_null($this->mTargetObj)) {
$out->addWikiMsg('undelete-header');
# Not all users can just browse every deleted page from the list
if ($user->isAllowed('browsearchive')) {
$this->showSearchForm();
}
return;
}
$this->addHelpLink('Help:Undelete');
if ($this->mAllowed) {
$out->setPageTitle($this->msg('undeletepage'));
} else {
$out->setPageTitle($this->msg('viewdeletedpage'));
}
$this->getSkin()->setRelevantTitle($this->mTargetObj);
if ($this->mTimestamp !== '') {
$this->showRevision($this->mTimestamp);
} elseif ($this->mFilename !== null && $this->mTargetObj->inNamespace(NS_FILE)) {
$file = new ArchivedFile($this->mTargetObj, '', $this->mFilename);
// Check if user is allowed to see this file
if (!$file->exists()) {
$out->addWikiMsg('filedelete-nofile', $this->mFilename);
} elseif (!$file->userCan(File::DELETED_FILE, $user)) {
if ($file->isDeleted(File::DELETED_RESTRICTED)) {
throw new PermissionsError('suppressrevision');
} else {
throw new PermissionsError('deletedtext');
}
} elseif (!$user->matchEditToken($this->mToken, $this->mFilename)) {
$this->showFileConfirmationForm($this->mFilename);
} else {
$this->showFile($this->mFilename);
}
} elseif ($this->mRestore && $this->mAction == 'submit') {
$this->undelete();
} else {
$this->showHistory();
}
}
示例4: onCodeEditorGetPageLanguage
/**
* Declares JSON as the code editor language for Campaign: pages.
* This hook only runs if the CodeEditor extension is enabled.
* @param Title $title
* @param string &$lang Page language.
* @return bool
*/
static function onCodeEditorGetPageLanguage($title, &$lang)
{
if ($title->inNamespace(NS_CAMPAIGN)) {
$lang = 'json';
}
return true;
}
示例5: onSkinEditSectionLinks
/**
* Changes the section edit links to add a VE edit link.
*
* This is attached to the MediaWiki 'SkinEditSectionLinks' hook.
*
* @param $skin Skin
* @param $title Title
* @param $section string
* @param $tooltip string
* @param $result array
* @param $lang Language
* @return bool true
*/
public static function onSkinEditSectionLinks(Skin $skin, Title $title, $section, $tooltip, &$result, $lang)
{
// Only do this if the user has VE enabled
// (and we're not in parserTests)
// (and we're not on a foreign file description page)
if (isset($GLOBALS['wgVisualEditorInParserTests']) || !$skin->getUser()->getOption('visualeditor-enable') || $skin->getUser()->getOption('visualeditor-betatempdisable') || $title->inNamespace(NS_FILE) && WikiPage::factory($title) instanceof WikiFilePage && !WikiPage::factory($title)->isLocal()) {
return true;
}
$config = ConfigFactory::getDefaultInstance()->makeConfig('visualeditor');
$tabMessages = $config->get('VisualEditorTabMessages');
$veEditSection = $tabMessages['editsection'] !== null ? $tabMessages['editsection'] : 'editsection';
$sourceEditSection = $tabMessages['editsectionsource'] !== null ? $tabMessages['editsectionsource'] : 'editsection';
$result['editsection']['text'] = $skin->msg($sourceEditSection)->inLanguage($lang)->text();
$veLink = array('text' => $skin->msg($veEditSection)->inLanguage($lang)->text(), 'targetTitle' => $title, 'attribs' => $result['editsection']['attribs'] + array('class' => 'mw-editsection-visualeditor'), 'query' => array('veaction' => 'edit', 'vesection' => $section), 'options' => array('noclasses', 'known'));
$result['veeditsection'] = $veLink;
if ($config->get('VisualEditorTabPosition') === 'before') {
krsort($result);
// TODO: This will probably cause weird ordering if any other extensions added something already.
// ... wfArrayInsertBefore?
}
return true;
}
示例6: onDoEditSectionLink
/**
* Changes the section edit links to add a VE edit link.
*
* This is attached to the MediaWiki 'DoEditSectionLink' hook.
*
* @param $skin Skin
* @param $title Title
* @param $section string
* @param $tooltip string
* @param $result string HTML
* @param $lang Language
* @return bool true
*/
public static function onDoEditSectionLink(Skin $skin, Title $title, $section, $tooltip, &$result, $lang)
{
// Only do this if the user has VE enabled
// (and we're not in parserTests)
// (and we're not on a foreign file description page)
if (!self::isVisible($skin) || isset($GLOBALS['wgVisualEditorInParserTests']) || !$skin->getUser()->getGlobalPreference('visualeditor-enable') || $skin->getUser()->getGlobalPreference('visualeditor-betatempdisable') || $title->inNamespace(NS_FILE) && WikiPage::factory($title) instanceof WikiFilePage && !WikiPage::factory($title)->isLocal()) {
return true;
}
$config = ConfigFactory::getDefaultInstance()->makeConfig('visualeditor');
$tabMessages = $config->get('VisualEditorTabMessages');
$veEditSection = $tabMessages['editsection'] !== null ? $tabMessages['editsection'] : 'editsection';
$sourceEditSection = $tabMessages['editsectionsource'] !== null ? $tabMessages['editsectionsource'] : 'editsection';
// Code mostly duplicated from Skin::doEditSectionLink() :(
$attribs = array();
if (!is_null($tooltip)) {
# Bug 25462: undo double-escaping.
$tooltip = Sanitizer::decodeCharReferences($tooltip);
$attribs['title'] = $skin->msg('editsectionhint')->rawParams($tooltip)->inLanguage($lang)->text();
}
$veLink = Linker::link($title, $skin->msg($veEditSection)->inLanguage($lang)->text(), $attribs + array('class' => 'mw-editsection-visualeditor'), array('veaction' => 'edit', 'vesection' => $section), array('noclasses', 'known'));
$sourceLink = Linker::link($title, $skin->msg($sourceEditSection)->inLanguage($lang)->text(), $attribs, array('action' => 'edit', 'section' => $section), array('noclasses', 'known'));
$veFirst = $config->get('VisualEditorTabPosition') === 'before';
$result = '<span class="mw-editsection">' . '<span class="mw-editsection-bracket">[</span>' . ($veFirst ? $veLink : $sourceLink) . '<span class="mw-editsection-divider">' . $skin->msg('pipe-separator')->inLanguage($lang)->text() . '</span>' . ($veFirst ? $sourceLink : $veLink) . '<span class="mw-editsection-bracket">]</span>' . '</span>';
return true;
}
示例7: canBeUsedOn
public function canBeUsedOn(Title $title)
{
return $title->inNamespace(NS_NOTEBOOK);
}
示例8: linkfix
/**
* Make Special:MyLanguage links red if the target page doesn't exists.
* A bit hacky because the core code is not so flexible.
*
* Hook: LinkBegin
*
* @param $dummy
* @param Title $target
* @param string $html
* @param array $customAttribs
* @param array $query
* @param array $options
* @param string|null $ret
*/
public static function linkfix($dummy, $target, &$html, &$customAttribs, &$query, &$options, &$ret)
{
if (!$target->inNamespace(NS_SPECIAL)) {
return;
}
list($name, $subpage) = SpecialPageFactory::resolveAlias($target->getDBkey());
if ($name !== 'MyLanguage') {
return;
}
if ((string) $subpage === '') {
return;
}
$realTarget = Title::newFromText($subpage);
if (!$realTarget || !$realTarget->exists()) {
$options[] = 'broken';
$index = array_search('known', $options, true);
if ($index !== false) {
unset($options[$index]);
}
$index = array_search('noclasses', $options, true);
if ($index !== false) {
unset($options[$index]);
}
}
}
示例9: onSkinEditSectionLinks
/**
* Changes the section edit links to add a VE edit link.
*
* This is attached to the MediaWiki 'SkinEditSectionLinks' hook.
*
* @param $skin Skin
* @param $title Title
* @param $section string
* @param $tooltip string
* @param $result array
* @param $lang Language
* @return bool true
*/
public static function onSkinEditSectionLinks(Skin $skin, Title $title, $section, $tooltip, &$result, $lang)
{
$config = ConfigFactory::getDefaultInstance()->makeConfig('visualeditor');
// Exit if we're using the single edit tab.
if ($config->get('VisualEditorUseSingleEditTab') && $skin->getUser()->getOption('visualeditor-tabs') !== 'multi-tab') {
return true;
}
// Exit if we're in parserTests
if (isset($GLOBALS['wgVisualEditorInParserTests'])) {
return true;
}
// Exit if the user doesn't have VE enabled
if (!$skin->getUser()->getOption('visualeditor-enable') || $skin->getUser()->getOption('visualeditor-betatempdisable') || $skin->getUser()->getOption('visualeditor-autodisable') || $config->get('VisualEditorDisableForAnons') && $skin->getUser()->isAnon()) {
return true;
}
// Exit if we're on a foreign file description page
if ($title->inNamespace(NS_FILE) && WikiPage::factory($title) instanceof WikiFilePage && !WikiPage::factory($title)->isLocal()) {
return true;
}
$tabMessages = $config->get('VisualEditorTabMessages');
$sourceEditSection = $tabMessages['editsectionsource'] !== null ? $tabMessages['editsectionsource'] : 'editsection';
$result['editsection']['text'] = $skin->msg($sourceEditSection)->inLanguage($lang)->text();
$availableNamespaces = $config->get('VisualEditorAvailableNamespaces');
// add VE edit section in VE available namespaces
if ($title->inNamespaces(array_keys(array_filter($availableNamespaces)))) {
$veEditSection = $tabMessages['editsection'] !== null ? $tabMessages['editsection'] : 'editsection';
$veLink = array('text' => $skin->msg($veEditSection)->inLanguage($lang)->text(), 'targetTitle' => $title, 'attribs' => $result['editsection']['attribs'] + array('class' => 'mw-editsection-visualeditor'), 'query' => array('veaction' => 'edit', 'vesection' => $section), 'options' => array('noclasses', 'known'));
$result['veeditsection'] = $veLink;
if ($config->get('VisualEditorTabPosition') === 'before') {
krsort($result);
// TODO: This will probably cause weird ordering if any other extensions added something
// already.
// ... wfArrayInsertBefore?
}
}
return true;
}