/**
  * 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;
 }
Example #2
0
 /**
  * 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;
     }
 }
 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();
     }
 }
Example #4
0
 /**
  * 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;
 }
 /**
  * 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;
 }
Example #6
0
 /**
  * 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;
 }
 public function canBeUsedOn(Title $title)
 {
     return $title->inNamespace(NS_NOTEBOOK);
 }
 /**
  * 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]);
         }
     }
 }
 /**
  * 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;
 }