/**
  * @param \Message|string|string[] $message
  * @param bool                     $forContent
  *
  * @throws \MWException
  *
  * @return Menu
  */
 public function getMenuFromMessage($message, $forContent = false)
 {
     if (is_string($message) || is_array($message)) {
         $message = \Message::newFromKey($message);
     }
     $this->assert(is_a($message, '\\Message'), 'String, array of strings or Message object expected.', $message);
     if ($forContent) {
         $message = $message->inContentLanguage();
     }
     if (!$message->exists()) {
         return $this->getMenuFromMessageText('', $forContent);
     }
     return $this->getMenuFromMessageText($message->text(), $forContent);
 }
 public function testUserForCreation($user, $autocreate, array $options = [])
 {
     $block = $user->isBlockedFromCreateAccount();
     if ($block) {
         $errorParams = [$block->getTarget(), $block->mReason ?: \Message::newFromKey('blockednoreason')->text(), $block->getByName()];
         if ($block->getType() === \Block::TYPE_RANGE) {
             $errorMessage = 'cantcreateaccount-range-text';
             $errorParams[] = $this->manager->getRequest()->getIP();
         } else {
             $errorMessage = 'cantcreateaccount-text';
         }
         return StatusValue::newFatal(new \Message($errorMessage, $errorParams));
     } else {
         return StatusValue::newGood();
     }
 }
 /**
  * @param \Message|string|string[] $message
  * @param bool                     $forContent
  *
  * @throws \MWException
  *
  * @return Menu
  */
 public function getMenuFromMessage($message, $forContent = false)
 {
     if (is_string($message) || is_array($message)) {
         $message = \Message::newFromKey($message);
     }
     if (!is_a($message, '\\Message')) {
         throw new \MWException('String, array of strings or Message object expected. Got ' . is_object($message) ? get_class($message) : gettype($message) . '.');
     }
     if ($forContent) {
         $message = $message->inContentLanguage();
     }
     if (!$message->exists()) {
         return $this->getMenuFromMessageText('', $forContent);
     }
     return $this->getMenuFromMessageText($message->text(), $forContent);
 }
 /**
  * Builds the HTML code for this component
  *
  * @return String the HTML code
  */
 public function getHtml()
 {
     $ret = '';
     $sidebar = $this->getSkinTemplate()->getSidebar(array('search' => false, 'toolbox' => false, 'languages' => false));
     $msg = \Message::newFromKey('skin-chameleon-navmenu-flatten');
     if ($msg->exists()) {
         $flatten = array_map('trim', explode(';', $msg->plain()));
     } elseif ($this->getDomElement() !== null) {
         $flatten = array_map('trim', explode(';', $this->getDomElement()->getAttribute('flatten')));
     } else {
         $flatten = array();
     }
     // create a dropdown for each sidebar box
     foreach ($sidebar as $boxName => $box) {
         $ret .= $this->getDropdownForNavMenu($boxName, $box, array_search($boxName, $flatten) !== false);
     }
     return $ret;
 }
 /**
  * Returns the label of the selector for this view.
  * @return String the selector label
  */
 public function getSelectorLabel()
 {
     return Message::newFromKey('srf-filtered-selectorlabel-calendar')->inContentLanguage()->text();
 }
Exemplo n.º 6
0
    if (!defined('MW_NO_SESSION_HANDLER')) {
        MediaWiki\Session\PHPSessionHandler::install(MediaWiki\Session\SessionManager::singleton());
    }
    // Initialize the session
    try {
        $session = MediaWiki\Session\SessionManager::getGlobalSession();
    } catch (OverflowException $ex) {
        if (isset($ex->sessionInfos) && count($ex->sessionInfos) >= 2) {
            // The exception is because the request had multiple possible
            // sessions tied for top priority. Report this to the user.
            $list = [];
            foreach ($ex->sessionInfos as $info) {
                $list[] = $info->getProvider()->describe($wgContLang);
            }
            $list = $wgContLang->listToText($list);
            throw new HttpError(400, Message::newFromKey('sessionmanager-tie', $list)->inLanguage($wgContLang)->plain());
        }
        // Not the one we want, rethrow
        throw $ex;
    }
    if ($session->isPersistent()) {
        $wgInitialSessionId = $session->getSessionId();
    }
    $session->renew();
    if (MediaWiki\Session\PHPSessionHandler::isEnabled() && ($session->isPersistent() || $session->shouldRememberUser())) {
        // Start the PHP-session for backwards compatibility
        session_id($session->getId());
        MediaWiki\quietCall('session_start');
    }
    unset($session);
} else {
 public static function provideTestForAccountCreation()
 {
     return ['No hook errors' => [null, null, \StatusValue::newGood()], 'AbortNewAccount, old style' => ['foobar', null, \StatusValue::newFatal(\Message::newFromKey('createaccount-hook-aborted')->rawParams('foobar'))], 'AbortNewAccount, new style' => ['foobar', \Status::newFatal('aborted!', 'param'), \StatusValue::newFatal('aborted!', 'param')]];
 }
Exemplo n.º 8
0
 /**
  * @covers Message::newFromKey
  */
 public function testNewFromKey()
 {
     $this->assertInstanceOf('Message', Message::newFromKey('mainpage'));
     $this->assertInstanceOf('Message', Message::newFromKey('i-dont-exist-evar'));
 }
 /**
  * Prevents that the wiki gets accidentally inaccessible for all users.
  * Some of the rights which are pre-set in the $bsgPermissionConfig have
  * a the flag "preventLockout" set to true. This makes it impossible to
  * save the permission settings if not at least one group has these rights enabled.
  *
  * @param array $aGroupPermissions
  * @return bool|String
  */
 protected static function preventPermissionLockout(&$aGroupPermissions)
 {
     global $bsgPermissionConfig;
     $aRights = User::getAllRights();
     if (!is_array($aRights)) {
         return false;
     }
     foreach ($aRights as $sRight) {
         if (isset($bsgPermissionConfig[$sRight]['preventLockout'])) {
             $bIsSet = false;
             if (is_array($aGroupPermissions)) {
                 foreach ($aGroupPermissions as $aDataset) {
                     if (isset($aDataset[$sRight]) && $aDataset[$sRight]) {
                         $bIsSet = true;
                         continue 2;
                     }
                 }
                 if (!$bIsSet) {
                     return Message::newFromKey('bs-permissionmanager-error-lockout')->params($sRight)->plain();
                 }
             }
         }
     }
     return true;
 }