/** * 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; } }
/** * 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); } }
/** * 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); } } } }
/** * @param string|null $languageCode * * @return bool */ private function isValidLanguageCode($languageCode) { return $languageCode !== null && $this->termsLanguages->hasLanguage($languageCode); }