Adrian Heine has uploaded a new change for review. https://gerrit.wikimedia.org/r/291897
Change subject: Use Language{Name,Directionality}Lookup in SpecialNew* ...................................................................... Use Language{Name,Directionality}Lookup in SpecialNew* Change-Id: Iad9a230aae813324a303573fc7802d28061816ca --- M repo/includes/Specials/SpecialNewEntity.php M repo/includes/WikibaseRepo.php 2 files changed, 65 insertions(+), 58 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/97/291897/1 diff --git a/repo/includes/Specials/SpecialNewEntity.php b/repo/includes/Specials/SpecialNewEntity.php index 4307685..00b8775 100644 --- a/repo/includes/Specials/SpecialNewEntity.php +++ b/repo/includes/Specials/SpecialNewEntity.php @@ -5,7 +5,6 @@ use Html; use HTMLForm; use InvalidArgumentException; -use Language; use Status; use Wikibase\CopyrightMessageBuilder; use Wikibase\DataModel\Entity\EntityDocument; @@ -23,12 +22,13 @@ * @author Jens Ohlig * @author John Erling Blad < jeb...@gmail.com > * @author Bene* < benestar.wikime...@gmail.com > + * @author Adrian Heine <adrian.he...@wikimedia.de> */ abstract class SpecialNewEntity extends SpecialWikibaseRepoPage { /** * Contains pieces of the sub-page name of this special page if a subpage was called. - * E.g. array( 'a', 'b' ) in case of 'Special:NewEntity/a/b' + * E.g. [ 'a', 'b' ] in case of 'Special:NewEntity/a/b' * @var string[]|null */ protected $parts = null; @@ -44,9 +44,14 @@ private $description; /** - * @var Language|null + * @var string[] */ - private $contentLanguage; + private $aliases = []; + + /** + * @var string + */ + private $contentLanguageCode; /** * @var string[] @@ -54,19 +59,19 @@ private $languageCodes; /** - * @var string + * @var SpecialPageCopyrightView */ - private $rightsUrl; + private $copyrightView; /** - * @var string + * @var LanguageDirectionalityLookup */ - private $rightsText; + private $languageDirectionalityLookup; /** - * @var string[] + * @var LanguageNameLookup */ - private $aliases = array(); + private $languageNameLookup; /** * @param string $name Name of the special page, as seen in links and URLs. @@ -76,16 +81,17 @@ */ public function __construct( $name, $restriction = 'createpage' ) { parent::__construct( $name, $restriction ); - $wikibaseRepo = WikibaseRepo::getDefaultInstance(); - // TODO: find a way to inject these - $this->summaryFormatter = $wikibaseRepo->getSummaryFormatter(); - $this->languageCodes = $wikibaseRepo->getTermsLanguages()->getLanguages(); $settings = $wikibaseRepo->getSettings(); - - $this->rightsUrl = $settings->getSetting( 'dataRightsUrl' ); - $this->rightsText = $settings->getSetting( 'dataRightsText' ); + $this->copyrightView = new SpecialPageCopyrightView( + new CopyrightMessageBuilder(), + $settings->getSetting( 'dataRightsUrl' ), + $settings->getSetting( 'dataRightsText' ) + ); + $this->languageCodes = $wikibaseRepo->getTermsLanguages()->getLanguages(); + $this->languageDirectionalityLookup = $wikibaseRepo->getLanguageDirectionalityLookup(); + $this->languageNameLookup = $wikibaseRepo->getLanguageNameLookup(); } public function doesWrites() { @@ -106,7 +112,7 @@ $this->checkBlocked(); $this->checkReadOnly(); - $this->parts = ( $subPage === '' ? array() : explode( '/', $subPage ) ); + $this->parts = ( $subPage === '' ? [] : explode( '/', $subPage ) ); $this->prepareArguments(); $out = $this->getOutput(); @@ -152,10 +158,10 @@ } } - $this->getOutput()->addModuleStyles( array( 'wikibase.special' ) ); + $this->getOutput()->addModuleStyles( [ 'wikibase.special' ] ); foreach ( $this->getWarnings() as $warning ) { - $out->addHTML( Html::element( 'div', array( 'class' => 'warning' ), $warning ) ); + $out->addHTML( Html::element( 'div', [ 'class' => 'warning' ], $warning ) ); } $this->createForm( $this->getLegend(), $this->additionalFormElements() ); @@ -182,7 +188,7 @@ $this->description = $this->stringNormalizer->trimToNFC( $description ); $aliases = $this->getRequest()->getVal( 'aliases' ); - $explodedAliases = $aliases === null ? array() : explode( '|', $aliases ); + $explodedAliases = $aliases === null ? [] : explode( '|', $aliases ); foreach ( $explodedAliases as $alias ) { $alias = $this->stringNormalizer->trimToNFC( $alias ); @@ -191,10 +197,7 @@ } } - $this->contentLanguage = Language::factory( $this->getRequest()->getVal( - 'lang', - $this->getLanguage()->getCode() - ) ); + $this->contentLanguageCode = $this->getRequest()->getVal( 'lang', $this->getLanguage()->getCode() ); } /** @@ -207,7 +210,7 @@ protected function hasSufficientArguments() { return $this->label !== '' || $this->description !== '' - || $this->aliases !== array(); + || $this->aliases !== []; } /** @@ -233,7 +236,7 @@ } $fingerprint = $entity->getFingerprint(); - $languageCode = $this->contentLanguage->getCode(); + $languageCode = $this->contentLanguageCode; $fingerprint->setLabel( $languageCode, $this->label ); $fingerprint->setDescription( $languageCode, $this->description ); @@ -245,13 +248,12 @@ /** * Get options for language selector * - * @return array + * @return string[] */ private function getLanguageOptions() { - $names = Language::fetchLanguageNames( null, 'all' ); $languageOptions = []; foreach ( $this->languageCodes as $code ) { - $languageName = isset( $names[$code] ) ? $names[$code] : $code; + $languageName = $this->languageNameLookup->getName( $code ); $languageOptions["$languageName ($code)"] = $code; } return $languageOptions; @@ -263,18 +265,18 @@ protected function additionalFormElements() { $this->getOutput()->addModules( 'wikibase.special.languageLabelDescriptionAliases' ); - $langCode = $this->contentLanguage->getCode(); - $langDir = $this->contentLanguage->getDir(); - return array( - 'lang' => array( + $langCode = $this->contentLanguageCode; + $langDir = $this->languageDirectionalityLookup->getDirectionality( $this->contentLanguageCode ); + return [ + 'lang' => [ 'name' => 'lang', 'options' => $this->getLanguageOptions(), 'default' => $langCode, 'type' => 'combobox', 'id' => 'wb-newentity-language', 'label-message' => 'wikibase-newentity-language' - ), - 'label' => array( + ], + 'label' => [ 'name' => 'label', 'default' => $this->label ?: '', 'type' => 'text', @@ -285,8 +287,8 @@ 'wikibase-label-edit-placeholder' )->text(), 'label-message' => 'wikibase-newentity-label' - ), - 'description' => array( + ], + 'description' => [ 'name' => 'description', 'default' => $this->description ?: '', 'type' => 'text', @@ -297,8 +299,8 @@ 'wikibase-description-edit-placeholder' )->text(), 'label-message' => 'wikibase-newentity-description' - ), - 'aliases' => array( + ], + 'aliases' => [ 'name' => 'aliases', 'default' => $this->aliases ? implode( '|', $this->aliases ) : '', 'type' => 'text', @@ -309,8 +311,8 @@ 'wikibase-aliases-edit-placeholder' )->text(), 'label-message' => 'wikibase-newentity-aliases' - ) - ); + ] + ]; } /** @@ -319,7 +321,7 @@ * @param string|null $legend initial value for the label input box * @param array[] $additionalFormElements initial value for the description input box */ - private function createForm( $legend = null, array $additionalFormElements = array() ) { + private function createForm( $legend = null, array $additionalFormElements ) { $this->addCopyrightText(); HTMLForm::factory( 'ooui', $additionalFormElements, $this->getContext() ) @@ -336,13 +338,7 @@ * @todo could factor this out into a special page form builder and renderer */ private function addCopyrightText() { - $copyrightView = new SpecialPageCopyrightView( - new CopyrightMessageBuilder(), - $this->rightsUrl, - $this->rightsText - ); - - $html = $copyrightView->getHtml( $this->getLanguage(), 'wikibase-newentity-submit' ); + $html = $this->copyrightView->getHtml( $this->getLanguage(), 'wikibase-newentity-submit' ); $this->getOutput()->addHTML( $html ); } diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php index b57164f..f11f5f4 100644 --- a/repo/includes/WikibaseRepo.php +++ b/repo/includes/WikibaseRepo.php @@ -385,15 +385,21 @@ * @return WikibaseValueFormatterBuilders */ private function newWikibaseValueFormatterBuilders() { - global $wgLang; - return new WikibaseValueFormatterBuilders( $this->getDefaultLanguage(), new FormatterLabelDescriptionLookupFactory( $this->getTermLookup() ), - new LanguageNameLookup( $wgLang->getCode() ), + $this->getLanguageNameLookup(), $this->getLocalEntityUriParser(), $this->getEntityTitleLookup() ); + } + + /** + * @return LanguageNameLookup + */ + public function getLanguageNameLookup() { + global $wgLang; + return new LanguageNameLookup( $wgLang->getCode() ); } /** @@ -1555,11 +1561,9 @@ * @return EntityIdHtmlLinkFormatterFactory */ public function getEntityIdHtmlLinkFormatterFactory() { - global $wgLang; - return new EntityIdHtmlLinkFormatterFactory( $this->getEntityTitleLookup(), - new LanguageNameLookup( $wgLang->getCode() ) + $this->getLanguageNameLookup() ); } @@ -1613,8 +1617,8 @@ $this->getSiteStore(), $this->getDataTypeFactory(), TemplateFactory::getDefaultInstance(), - new LanguageNameLookup( $wgLang->getCode() ), - new MediaWikiLanguageDirectionalityLookup(), + $this->getLanguageNameLookup(), + $this->getLanguageDirectionalityLookup(), new MediaWikiNumberLocalizer( $wgLang ), $this->settings->getSetting( 'siteLinkGroups' ), $this->settings->getSetting( 'specialSiteLinkGroups' ), @@ -1624,6 +1628,13 @@ } /** + * @return LanguageDirectionalityLookup + */ + public function getLanguageDirectionalityLookup() { + return new MediaWikiLanguageDirectionalityLookup(); + } + + /** * @return DataTypeValidatorFactory */ public function getDataTypeValidatorFactory() { -- To view, visit https://gerrit.wikimedia.org/r/291897 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iad9a230aae813324a303573fc7802d28061816ca Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Adrian Heine <adrian.l...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits