Liangent has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/71852


Change subject: Remove Utils::lookupUserMultilangText(): replace by language 
fallback chain
......................................................................

Remove Utils::lookupUserMultilangText(): replace by language fallback chain

Utils::reorderArray() and Utils::filterMultilangText() can be removed later,
after both this and I40ad9647ba489a7950773f21a2ec04273ef1fe9e are merged.

Change-Id: Icf35995c962a3d65d329994d0312f085f83d3088
---
M lib/includes/Utils.php
M repo/includes/actions/EditEntityAction.php
M repo/includes/actions/ViewEntityAction.php
3 files changed, 14 insertions(+), 89 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/52/71852/1

diff --git a/lib/includes/Utils.php b/lib/includes/Utils.php
index c6ce523..98cf1f6 100644
--- a/lib/includes/Utils.php
+++ b/lib/includes/Utils.php
@@ -338,74 +338,6 @@
        }
 
        /**
-        * Find the first multilingual string that can be used for constructing 
a language object
-        * for the current user. If a preferred language can't be identified 
the global chain is
-        * used.
-        *
-        * Note that a user specific multilingual string is not globally 
cachable.
-        *
-        * FIXME: duplication with @see lookupMultilangText, needs refactor
-        *
-        * @since 0.1
-        *
-        * @param array $texts the key-value pairs to check for existence
-        * @param array $sequence the list of keys that should exist
-        * @param array $fallback an array of values that are used as a 
replacement if nothing is found
-        *              The fallback is in the form array( code, text, language 
)
-        * @return array|null triplet with the initial language code, the text, 
and the language object
-        */
-       static public function lookupUserMultilangText( array $texts = null, 
array $sequence = null, array $fallback = null ) {
-               // FIXME: deprecated globals!
-               global $wgUser, $wgLang;
-
-               // Prerequisites for further processing
-               if ( is_null( $texts ) || is_null( $sequence ) ) {
-                       return $fallback; // makes the simplest use case
-               }
-
-               // Filter down the result
-               $texts = \Wikibase\Utils::filterMultilangText( $texts, 
$sequence );
-               if ( is_null( $texts ) || empty( $texts ) ) {
-                       return $fallback;
-               }
-
-               // Check if we can use the ordinary language
-               // This should always be used if possible because this will 
match
-               // with the user set language
-               reset($texts);
-               list( $code, $text ) = each( $texts );
-               if ( $wgLang->getCode() === $code ) {
-                       $lang = Language::factory( $code );
-                       if ( !is_null( $lang ) ) {
-                               return array( $code, $text, $lang );
-                       }
-               }
-
-               // Find the first preferred language code we can turn into a 
language object
-               // Note that the factory call do a pretty dumb cleaning up that 
can make this vejjy slow
-               foreach ( $texts as $code => $text ) {
-                       if ( $wgUser->getOption( "sttl-languages-$code" ) ) {
-                               $lang = Language::factory( $code );
-                               if ( !is_null( $lang ) ) {
-                                       return array( $code, $text, $lang );
-                               }
-                       }
-               }
-
-               // Find the first ordinary language code we can turn into a 
language object
-               // Note that the factory call do a pretty dumb cleaning up that 
can make this vejjy slow
-               foreach ( $texts as $code => $text ) {
-                       $lang = Language::factory( $code );
-                       if ( !is_null( $lang ) ) {
-                               return array( $code, $text, $lang );
-                       }
-               }
-
-               // Use the fallback if the previous fails
-               return $fallback;
-       }
-
-       /**
         * Get the fallback languages prepended with the source language itself.
         *
         * A language chain in this respect is the language itself and all 
fallback
diff --git a/repo/includes/actions/EditEntityAction.php 
b/repo/includes/actions/EditEntityAction.php
index 1312945..7908750 100644
--- a/repo/includes/actions/EditEntityAction.php
+++ b/repo/includes/actions/EditEntityAction.php
@@ -288,15 +288,15 @@
         */
        public function getLabelText( EntityContent $content ) {
 
-               $langCode = $this->getContext()->getLanguage()->getCode();
-               list( , $labelText, ) =
-                       Utils::lookupUserMultilangText(
-                               $content->getEntity()->getLabels(),
-                               Utils::languageChain( $langCode ),
-                               array( $langCode, $this->getPageTitle(), 
$this->getContext()->getLanguage() )
-                       );
+               $languageFallbackChainFactory = 
WikibaseRepo::getDefaultInstance()->getLanguageFallbackChainFactory();
+               $languageFallbackChain = 
$languageFallbackChainFactory->newFromContext( $this->getContext() );
+               $labelData = $languageFallbackChain->extractPreferredValue( 
$content->getEntity()->getLabels() );
 
-               return $labelText;
+               if ( $labelData ) {
+                       return $labelData['value'];
+               } else {
+                       return $this->getPageTitle();
+               }
        }
 
        /**
diff --git a/repo/includes/actions/ViewEntityAction.php 
b/repo/includes/actions/ViewEntityAction.php
index 7482534..88d7174 100644
--- a/repo/includes/actions/ViewEntityAction.php
+++ b/repo/includes/actions/ViewEntityAction.php
@@ -194,20 +194,13 @@
                $this->getArticle()->view();
 
                // Figure out which label to use for title.
-               $langCode = $this->getContext()->getLanguage()->getCode();
-               // FIXME: Removed as a quickfix
-               /*
-               list( $labelCode, $labelText, $labelLang) =
-                       Utils::lookupUserMultilangText(
-                               $content->getEntity()->getLabels(),
-                               Utils::languageChain( $langCode ),
-                               array( $langCode, $this->getPageTitle(), 
$this->getContext()->getLanguage() )
-                       );
-*/
-               // FIXME: this replaces the stuff above
-               $labelText = $content->getEntity()->getLabel( $langCode );
+               $languageFallbackChainFactory = 
WikibaseRepo::getDefaultInstance()->getLanguageFallbackChainFactory();
+               $languageFallbackChain = 
$languageFallbackChainFactory->newFromContext( $this->getContext() );
+               $labelData = $languageFallbackChain->extractPreferredValue( 
$content->getEntity()->getLabels() );
 
-               if ( $labelText === false ) {
+               if ( $labelData ) {
+                       $labelText = $labelData['value'];
+               } else {
                        $idPrefixer = 
WikibaseRepo::getDefaultInstance()->getIdFormatter();
                        $labelText = strtoupper( $idPrefixer->format( 
$content->getEntity()->getId() ) );
                }

-- 
To view, visit https://gerrit.wikimedia.org/r/71852
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icf35995c962a3d65d329994d0312f085f83d3088
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Liangent <liang...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to