Liangent has uploaded a new change for review.

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


Change subject: Include preferred label for used entities on EntityView
......................................................................

Include preferred label for used entities on EntityView

* A new pseudo language code, qqc, is added, for data based on current context
* EntityView now initializes a fallback chain for current context, and send it
  for serialization, to have wbUsedEntities include some labels for view by
  final users.
* A helper JS variable, wbContextLanguageCode, is added, to identify labels for
  page views on client side.

Change-Id: Ic8ad24f49ba7fafe11e3dceb5d36e18d5b9ef19f
---
M lib/includes/LanguageFallbackChain.php
M repo/includes/EntityView.php
2 files changed, 19 insertions(+), 3 deletions(-)


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

diff --git a/lib/includes/LanguageFallbackChain.php 
b/lib/includes/LanguageFallbackChain.php
index ee91987..03da481 100644
--- a/lib/includes/LanguageFallbackChain.php
+++ b/lib/includes/LanguageFallbackChain.php
@@ -30,6 +30,11 @@
 class LanguageFallbackChain {
 
        /**
+        * Pseudo language code used to identify a fallback chain initialized 
from current context.
+        */
+       const CONTEXT_LANGUAGE_CODE = 'qqc';
+
+       /**
         * @var LanguageWithConversion[]
         */
        private $chain = array();
diff --git a/repo/includes/EntityView.php b/repo/includes/EntityView.php
index 628e562..a20278d 100644
--- a/repo/includes/EntityView.php
+++ b/repo/includes/EntityView.php
@@ -810,6 +810,9 @@
                $out->addJsConfigVars( 'wbEntityType', $entity->getType() );
                $out->addJsConfigVars( 'wbDataLangName', 
Utils::fetchLanguageName( $langCode ) );
 
+               // Some constant, but to avoid hard coding it everywhere
+               $out->addJsConfigVars( 'wbContextLanguageCode', 
LanguageFallbackChain::CONTEXT_LANGUAGE_CODE );
+
                // entity specific data
                $out->addJsConfigVars( 'wbEntityId', 
$this->getFormattedIdForEntity( $entity ) );
 
@@ -832,7 +835,7 @@
                $refFinder = new ReferencedEntitiesFinder( $entityLoader );
 
                $usedEntityIds = $refFinder->findClaimLinks( 
$entity->getClaims() );
-               $basicEntityInfo = static::getBasicEntityInfo( $entityLoader, 
$usedEntityIds, $langCode );
+               $basicEntityInfo = static::getBasicEntityInfo( $entityLoader, 
$usedEntityIds, $langCode, $this->getContext() );
 
                $out->addJsConfigVars(
                        'wbUsedEntities',
@@ -850,9 +853,12 @@
         * @param EntityLookup $entityLoader
         * @param EntityId[] $entityIds
         * @param string $langCode For the entity labels which will be included 
in one language only.
+        * @param IContextSource $context Set it to include labels to display 
for the given context too.
         * @return array
         */
-       protected static function getBasicEntityInfo( EntityLookup 
$entityLoader, array $entityIds, $langCode ) {
+       protected static function getBasicEntityInfo(
+               EntityLookup $entityLoader, array $entityIds, $langCode, 
IContextSource $context = null
+       ) {
                wfProfileIn( __METHOD__ );
 
                $entityContentFactory = EntityContentFactory::singleton();
@@ -864,7 +870,12 @@
                $serializationOptions = new EntitySerializationOptions( 
WikibaseRepo::getDefaultInstance()->getIdFormatter() );
                $serializationOptions->setProps( array( 'labels', 
'descriptions', 'datatype' ) );
 
-               $serializationOptions->setLanguages( array( $langCode ) );
+               $languages = array( $langCode );
+               if ( $context ) {
+                       $factory = 
WikibaseRepo::getDefaultInstance()->getLanguageFallbackChainFactory();
+                       
$languages[LanguageFallbackChain::CONTEXT_LANGUAGE_CODE] = 
$factory->newFromContext( $context );
+               }
+               $serializationOptions->setLanguages( $languages );
 
                foreach( $entities as $prefixedId => $entity ) {
                        if( $entity === null ) {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic8ad24f49ba7fafe11e3dceb5d36e18d5b9ef19f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Liangent <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to