/**
  * Check the language given as sup page argument.
  */
 private function checkSubPageLanguage()
 {
     if ($this->languageCode !== null && !$this->termsLanguages->hasLanguage($this->languageCode)) {
         $errorMessage = $this->msg('wikibase-wikibaserepopage-invalid-langcode', $this->languageCode)->parse();
         $this->showErrorHTML($errorMessage);
     }
 }
 /**
  * Prepare the arguments
  *
  * @param string $subPage
  */
 private function prepareArguments($subPage)
 {
     $request = $this->getRequest();
     $this->language = '';
     $this->type = null;
     if ($subPage !== null) {
         $parts = explode('/', $subPage);
         if (isset($parts[1])) {
             $this->type = $parts[1];
         }
         $this->language = $parts[0];
     }
     $this->language = $request->getText('language', $this->language);
     if ($this->language !== '' && !$this->termsLanguages->hasLanguage($this->language)) {
         $this->showErrorHTML($this->msg('wikibase-entitieswithoutlabel-invalid-language', $this->language)->parse());
         $this->language = '';
     }
     $this->type = $request->getText('type', $this->type);
     if ($this->type === '') {
         $this->type = null;
     }
     if ($this->type !== null && !$this->entityFactory->isEntityType($this->type)) {
         $this->showErrorHTML($this->msg('wikibase-entitieswithoutlabel-invalid-type', $this->type)->parse());
         $this->type = null;
     }
 }
 /**
  * @return ValueValidator[]
  */
 public function buildMonolingualTextValidators()
 {
     $validators = array();
     $validators[] = new DataFieldValidator('text', new CompositeValidator($this->getCommonStringValidators()));
     $validators[] = new DataFieldValidator('language', new MembershipValidator($this->contentLanguages->getLanguages()));
     $topValidator = new DataValueValidator(new CompositeValidator($validators));
     return array(new TypeValidator('DataValues\\DataValue'), $topValidator);
 }
 /**
  * @param OutputPage $out
  * @param string &$html
  *
  * @return bool
  */
 public function doOutputPageBeforeHTML(OutputPage $out, &$html)
 {
     $placeholders = $out->getProperty('wikibase-view-chunks');
     if (!empty($placeholders)) {
         $injector = new TextInjector($placeholders);
         $expander = $this->getEntityViewPlaceholderExpander($out);
         $html = $injector->inject($html, array($expander, 'getHtmlForPlaceholder'));
         $out->addJsConfigVars('wbUserSpecifiedLanguages', array_values(array_intersect($this->userLanguageLookup->getUserSpecifiedLanguages($out->getUser()), $this->termsLanguages->getLanguages())));
     }
 }
 /**
  * Returns a list of languages desired by the user in addition to the current interface language.
  *
  * @see UserLanguageLookup
  *
  * @return string[]
  */
 public function getExtraUserLanguages()
 {
     if ($this->extraLanguages === null) {
         if ($this->user->isAnon()) {
             // no extra languages for anon user
             $this->extraLanguages = array();
         } else {
             // ignore current interface language
             $skip = array($this->uiLanguage->getCode());
             $langs = array_diff($this->userLanguageLookup->getAllUserLanguages($this->user), $skip);
             // Make sure we only report actual term languages
             $this->extraLanguages = array_intersect($langs, $this->termsLanguages->getLanguages());
         }
     }
     return $this->extraLanguages;
 }
 /**
  * Check some of the supplied data for multilang arg
  *
  * @param array $arg The argument array to verify
  * @param string $langCode The language code used in the value part
  */
 private function validateMultilangArgs($arg, $langCode)
 {
     $this->assertArray($arg, 'An array was expected, but not found in the json for the ' . "langCode {$langCode}");
     if (!array_key_exists('language', $arg)) {
         $this->errorReporter->dieError("'language' was not found in the label or description json for {$langCode}", 'missing-language');
     }
     $this->assertString($arg['language'], 'A string was expected, but not found in the json ' . "for the langCode {$langCode} and argument 'language'");
     if (!is_numeric($langCode)) {
         if ($langCode !== $arg['language']) {
             $this->errorReporter->dieError("inconsistent language: {$langCode} is not equal to {$arg['language']}", 'inconsistent-language');
         }
     }
     if (!$this->termsLanguages->hasLanguage($arg['language'])) {
         $this->errorReporter->dieError('Unknown language: ' . $arg['language'], 'not-recognized-language');
     }
     if (!array_key_exists('remove', $arg)) {
         $this->assertString($arg['value'], 'A string was expected, but not found in the json ' . "for the langCode {$langCode} and argument 'value'");
     }
 }
 /**
  * @see SpecialWikibasePage::execute
  *
  * @since 0.1
  *
  * @param string|null $subPage
  */
 public function execute($subPage)
 {
     parent::execute($subPage);
     $request = $this->getRequest();
     $subPageParts = $subPage === '' ? array() : explode('/', $subPage, 2);
     $languageCode = $this->extractLanguageCode($request, $subPageParts);
     $label = $this->extractLabel($request, $subPageParts);
     $this->switchForm($languageCode, $label);
     // Display the result set
     if (isset($languageCode) && isset($label) && $label !== '') {
         // @todo We could have a LanguageCodeValidator or something and handle this
         // in the search interactor or some place else.
         if (!$this->contentLanguages->hasLanguage($languageCode)) {
             $this->showErrorHTML($this->msg('wikibase-itemdisambiguation-invalid-langcode')->escaped());
         } else {
             $searchResults = $this->getSearchResults($label, $languageCode);
             if (!empty($searchResults)) {
                 $this->displaySearchResults($searchResults, $label);
             } else {
                 $this->showNothingFound($languageCode, $label);
             }
         }
     }
 }
 /**
  * @see ApiBase::getAllowedParams
  */
 protected function getAllowedParams()
 {
     return array('search' => array(self::PARAM_TYPE => 'string', self::PARAM_REQUIRED => true), 'language' => array(self::PARAM_TYPE => $this->termsLanguages->getLanguages()), 'strictlanguage' => array(self::PARAM_TYPE => 'boolean', self::PARAM_DFLT => false), 'type' => array(self::PARAM_TYPE => $this->entityTypes, self::PARAM_DFLT => 'item'), 'limit' => array(self::PARAM_TYPE => 'limit', self::PARAM_DFLT => 7, self::PARAM_MAX => self::LIMIT_SML1, self::PARAM_MAX2 => self::LIMIT_SML2, self::PARAM_MIN => 0, self::PARAM_RANGE_ENFORCE => true));
 }
 private function newClientEntitySerializer()
 {
     return new ClientEntitySerializer($this->dataTypeLookup, array_unique(array_merge($this->termsLanguages->getLanguages(), $this->fallbackChain->getFetchLanguageCodes(), array($this->language->getCode()))), array($this->language->getCode() => $this->fallbackChain));
 }
 /**
  * @param string|null $languageCode
  *
  * @return bool
  */
 private function isValidLanguageCode($languageCode)
 {
     return $languageCode !== null && $this->termsLanguages->hasLanguage($languageCode);
 }