Lucas_Werkmeister_WMDE added a subscriber: guergana.tzatchkova.
Lucas_Werkmeister_WMDE added a comment.


  In T329655#8922650 <https://phabricator.wikimedia.org/T329655#8922650>, 
@Michael wrote:
  
  > The code that generates those lines in PHP is in 
`\Wikibase\View\TermsListView::getTermView`. However, depending on whether 
there is at least one Term or no Term at all for a language, that method is 
reached in two very different ways.
  > [snip]
  > In my tests, the second path does not seem to know anything about the terms 
available...
  
  @guergana.tzatchkova and I looked some more into this. The first code path 
happens for each language that has terms, when Wikibase renders the entity to 
be put into the parser output. The second code path happens on each page view, 
for any languages that aren’t in the parser output yet. And because that second 
code path happens even on cached page views, it tries to avoid loading the real 
entity if possible, and instead just creates an empty one.
  
  If we add the `mul` label of an entity as another property to the parser 
output (just like the rendered termbox rows for the languages with terms get 
added), then we can later load this information in the hook handler and add it 
to the otherwise empty “fake” entity. Here’s a sketch of how that could work:
  
    diff --git 
a/repo/includes/ParserOutput/PlaceholderEmittingEntityTermsView.php 
b/repo/includes/ParserOutput/PlaceholderEmittingEntityTermsView.php
    index 34da4ed8c2..1d9bd9d21a 100644
    --- a/repo/includes/ParserOutput/PlaceholderEmittingEntityTermsView.php
    +++ b/repo/includes/ParserOutput/PlaceholderEmittingEntityTermsView.php
    @@ -155,6 +155,10 @@ public function getPlaceholders(
                                        $entity->getDescriptions(),
                                        $entity->getAliasGroups()
                                ),
    +                   'wikibase-mul-label' =>
    +                           $entity->getLabels()->hasTermForLanguage( 'mul' 
)
    +                                   ? $entity->getLabels()->getByLanguage( 
'mul' )->getText()
    +                                   : null,
                ];
        }
     
    diff --git a/repo/includes/RepoHooks.php b/repo/includes/RepoHooks.php
    index ac1855efbc..a1d0c9a92e 100644
    --- a/repo/includes/RepoHooks.php
    +++ b/repo/includes/RepoHooks.php
    @@ -770,6 +770,12 @@ public static function onOutputPageParserOutput( 
OutputPage $outputPage, ParserO
                        $outputPage->setProperty( 'wikibase-terms-list-items', 
$termsListItems );
                }
     
    +           // Set in EntityParserOutputGenerator.
    +           $mulLabel = $parserOutput->getExtensionData( 
'wikibase-mul-label' );
    +           if ( $mulLabel !== null ) {
    +                   $outputPage->setProperty( 'wikibase-mul-label', 
$mulLabel );
    +           }
    +
                // Used in ViewEntityAction and EditEntityAction to override 
the page HTML title
                // with the label, if available, or else the id. Passed via 
parser output
                // and output page to save overhead of fetching content and 
accessing an entity
    diff --git a/repo/includes/Hooks/OutputPageBeforeHTMLHookHandler.php 
b/repo/includes/Hooks/OutputPageBeforeHTMLHookHandler.php
    index c318278299..443eb31451 100644
    --- a/repo/includes/Hooks/OutputPageBeforeHTMLHookHandler.php
    +++ b/repo/includes/Hooks/OutputPageBeforeHTMLHookHandler.php
    @@ -13,6 +13,7 @@
     use Wikibase\DataModel\Entity\EntityDocument;
     use Wikibase\DataModel\Entity\EntityId;
     use Wikibase\DataModel\Entity\EntityIdParser;
    +use Wikibase\DataModel\Term\LabelsProvider;
     use Wikibase\Lib\ContentLanguages;
     use Wikibase\Lib\EntityFactory;
     use Wikibase\Lib\LanguageFallbackChainFactory;
    @@ -272,7 +273,11 @@ private function getEntity( OutputPage $out ) {
                        return $entityRev->getEntity();
                }
     
    -           return $this->entityFactory->newEmpty( 
$entityId->getEntityType() );
    +           $entity = $this->entityFactory->newEmpty( 
$entityId->getEntityType() );
    +           if ( $entity instanceof LabelsProvider && $out->getProperty( 
'wikibase-mul-label' ) ) {
    +                   $entity->getLabels()->setTextForLanguage( 'mul', 
$out->getProperty( 'wikibase-mul-label' ) );
    +           }
    +           return $entity;
        }
     
        private function needsRealEntity( OutputPage $out ) {
    diff --git a/view/src/TermsListView.php b/view/src/TermsListView.php
    index 3fd483f714..6e9921ac4a 100644
    --- a/view/src/TermsListView.php
    +++ b/view/src/TermsListView.php
    @@ -112,15 +112,24 @@ public function getListItemHtml(
        }
     
        private function getLabelView( TermList $listOfLabelTerms, string 
$languageCode ): string {
    -           $hasLabelInLanguage = $listOfLabelTerms->hasTermForLanguage( 
$languageCode );
    -           $effectiveLanguage = $hasLabelInLanguage ? $languageCode : 
$this->textProvider->getLanguageOf( 'wikibase-label-empty' );
    +           if ( $listOfLabelTerms->hasTermForLanguage( $languageCode ) ) {
    +                   $labelEntry = $listOfLabelTerms->getByLanguage( 
$languageCode )->getText();
    +                   $effectiveLanguage = $languageCode;
    +                   $isEmpty = false;
    +           } elseif ( $listOfLabelTerms->hasTermForLanguage( 'mul' ) ) {
    +                   $labelEntry = $listOfLabelTerms->getByLanguage( 'mul' 
)->getText();
    +                   $effectiveLanguage = 'mul';
    +                   $isEmpty = true;
    +           } else {
    +                   $this->textProvider->get( 'wikibase-label-empty' );
    +                   $effectiveLanguage = 
$this->textProvider->getLanguageOf( 'wikibase-label-empty' );
    +                   $isEmpty = true;
    +           }
    +
                return $this->templateFactory->render(
                        'wikibase-labelview',
    -                   $hasLabelInLanguage ? '' : 'wb-empty',
    -                   htmlspecialchars( $hasLabelInLanguage
    -                           ? $listOfLabelTerms->getByLanguage( 
$languageCode )->getText()
    -                           : $this->textProvider->get( 
'wikibase-label-empty' )
    -                   ),
    +                   $isEmpty ? 'wb-empty' : '',
    +                   htmlspecialchars( $labelEntry ),
                        '',
                        $this->languageDirectionalityLookup->getDirectionality( 
$effectiveLanguage ) ?: 'auto',
                        $effectiveLanguage
  
  In my local testing, that mostly seems to work, though the JS in 
`view/resources/jquery/wikibase/jquery.wikibase.labelview.js` also needs to be 
adjusted for the “all entered languages” to behave the same.

TASK DETAIL
  https://phabricator.wikimedia.org/T329655

EMAIL PREFERENCES
  https://phabricator.wikimedia.org/settings/panel/emailpreferences/

To: Lucas_Werkmeister_WMDE
Cc: guergana.tzatchkova, Lucas_Werkmeister_WMDE, Sarai-WMDE, noarave, 
ItamarWMDE, Michael, Manuel, Aklapper, Astuthiodit_1, karapayneWMDE, Invadibot, 
maantietaja, Akuckartz, darthmon_wmde, Nandana, Lahi, Gq86, GoranSMilovanovic, 
QZanden, LawExplorer, _jensen, rosalieper, Scott_WUaS, Wikidata-bugs, aude, 
Lydia_Pintscher, Mbch331
_______________________________________________
Wikidata-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to