jenkins-bot has submitted this change and it was merged. Change subject: Fall back to page title if wikibase-titletext is n/a ......................................................................
Fall back to page title if wikibase-titletext is n/a Change-Id: Ic20c54407447e517e3fd7926060c0bc85013892a --- M repo/Wikibase.hooks.php M repo/includes/EntityParserOutputGenerator.php M repo/includes/actions/EditEntityAction.php M repo/includes/actions/ViewEntityAction.php 4 files changed, 31 insertions(+), 27 deletions(-) Approvals: Aude: Looks good to me, approved jenkins-bot: Verified diff --git a/repo/Wikibase.hooks.php b/repo/Wikibase.hooks.php index fceee04..7681057 100644 --- a/repo/Wikibase.hooks.php +++ b/repo/Wikibase.hooks.php @@ -956,19 +956,18 @@ * @return bool */ public static function onOutputPageParserOutput( OutputPage $out, ParserOutput $parserOutput ) { + // Set in EntityParserOutputGenerator. $placeholders = $parserOutput->getExtensionData( 'wikibase-view-chunks' ); - - if ( $placeholders ) { + if ( $placeholders !== null ) { $out->setProperty( 'wikibase-view-chunks', $placeholders ); } - // used in ViewEntityAction and EditEntityAction to override the page html title + // 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 // on page view. $titleText = $parserOutput->getExtensionData( 'wikibase-titletext' ); - - if ( $titleText ) { + if ( $titleText !== null ) { $out->setProperty( 'wikibase-titletext', $titleText ); } @@ -988,7 +987,7 @@ public static function onOutputPageBeforeHTML( OutputPage $out, &$html ) { $placeholders = $out->getProperty( 'wikibase-view-chunks' ); - if ( $placeholders ) { + if ( !empty( $placeholders ) ) { $injector = new TextInjector( $placeholders ); $userLanguageLookup = new UserLanguageLookup(); $expander = new EntityViewPlaceholderExpander( diff --git a/repo/includes/EntityParserOutputGenerator.php b/repo/includes/EntityParserOutputGenerator.php index db5e412..958a529 100644 --- a/repo/includes/EntityParserOutputGenerator.php +++ b/repo/includes/EntityParserOutputGenerator.php @@ -3,13 +3,14 @@ namespace Wikibase; use ParserOutput; -use Wikibase\DataModel\Entity\Entity; +use Wikibase\DataModel\Entity\EntityDocument; use Wikibase\DataModel\Entity\EntityId; use Wikibase\DataModel\Entity\Item; use Wikibase\DataModel\SiteLink; use Wikibase\DataModel\SiteLinkList; use Wikibase\DataModel\Snak\Snak; use Wikibase\DataModel\StatementListProvider; +use Wikibase\DataModel\Term\FingerprintProvider; use Wikibase\Lib\Store\EntityInfo; use Wikibase\Lib\Store\EntityInfoBuilderFactory; use Wikibase\Lib\Store\EntityInfoTermLookup; @@ -256,21 +257,26 @@ /** * @param ParserOutput $parserOutput - * @param Entity $entity + * @param EntityDocument $entity */ - private function addTitleTextToParserOutput( ParserOutput $parserOutput, Entity $entity ) { - $preferred = $this->languageFallbackChain->extractPreferredValue( $entity->getLabels() ); + private function addTitleTextToParserOutput( ParserOutput $parserOutput, EntityDocument $entity ) { + $titleText = null; - if ( is_array( $preferred ) ) { - $titleText = $preferred['value']; - } else { + if ( $entity instanceof FingerprintProvider ) { + $labels = $entity->getFingerprint()->getLabels()->toTextArray(); + $preferred = $this->languageFallbackChain->extractPreferredValue( $labels ); + + if ( is_array( $preferred ) ) { + $titleText = $preferred['value']; + } + } + + if ( !is_string( $titleText ) ) { $entityId = $entity->getId(); - if ( !$entityId ) { - return; + if ( $entityId !== null ) { + $titleText = $entityId->getSerialization(); } - - $titleText = $entityId->getSerialization(); } $parserOutput->setExtensionData( 'wikibase-titletext', $titleText ); diff --git a/repo/includes/actions/EditEntityAction.php b/repo/includes/actions/EditEntityAction.php index e4970e5..901109d 100644 --- a/repo/includes/actions/EditEntityAction.php +++ b/repo/includes/actions/EditEntityAction.php @@ -276,7 +276,6 @@ /** * @var EntityContent $latestContent - * @var EntityContent $olderContent * @var EntityContent $newerContent */ $olderContent = $olderRevision->getContent(); @@ -343,7 +342,7 @@ } /** - * Used for overriding the page html title with the label, if available, or else the id. + * Used for overriding the page HTML title with the label, if available, or else the id. * This is passed via parser output and output page to save overhead on view / edit actions. * * @return string @@ -352,7 +351,7 @@ $titleText = $this->getOutput()->getProperty( 'wikibase-titletext' ); if ( $titleText === null ) { - $titleText = ''; + $titleText = $this->getTitle()->getPrefixedText(); } return $titleText; diff --git a/repo/includes/actions/ViewEntityAction.php b/repo/includes/actions/ViewEntityAction.php index 151f2f8..ab2b050 100644 --- a/repo/includes/actions/ViewEntityAction.php +++ b/repo/includes/actions/ViewEntityAction.php @@ -95,9 +95,9 @@ /** * @param OutputPage $outputPage - * @param string $labelText + * @param string $titleText */ - private function setPageTitle( OutputPage $outputPage, $labelText ) { + private function setPageTitle( OutputPage $outputPage, $titleText ) { // Escaping HTML characters in order to retain original label that may contain HTML // characters. This prevents having characters evaluated or stripped via // OutputPage::setPageTitle: @@ -105,21 +105,21 @@ $this->msg( 'difference-title' // This should be something like the following, - // $labelLang->getDirMark() . $labelText . $wgLang->getDirMark() + // $labelLang->getDirMark() . $titleText . $wgLang->getDirMark() // or should set the attribute of the h1 to correct direction. // Still note that the direction is "auto" so guessing should // give the right direction in most cases. - )->rawParams( htmlspecialchars( $labelText ) ) + )->rawParams( htmlspecialchars( $titleText ) ) ); } /** * @param OutputPage $outputPage - * @param string $labelText + * @param string $titleText */ - private function setHTMLTitle( OutputPage $outputPage, $labelText ) { + private function setHTMLTitle( OutputPage $outputPage, $titleText ) { // Prevent replacing {{...}} by using rawParams() instead of params(): - $outputPage->setHTMLTitle( $this->msg( 'pagetitle' )->rawParams( $labelText ) ); + $outputPage->setHTMLTitle( $this->msg( 'pagetitle' )->rawParams( $titleText ) ); } /** -- To view, visit https://gerrit.wikimedia.org/r/179135 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ic20c54407447e517e3fd7926060c0bc85013892a Gerrit-PatchSet: 5 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> Gerrit-Reviewer: Aude <aude.w...@gmail.com> Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits