Aude has uploaded a new change for review. https://gerrit.wikimedia.org/r/168830
Change subject: Split ViewEntityAction labelText code into several methods ...................................................................... Split ViewEntityAction labelText code into several methods Change-Id: I165720eed483299c1472eb160154ca3b96231eaf --- M repo/includes/actions/ViewEntityAction.php 1 file changed, 59 insertions(+), 25 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/30/168830/1 diff --git a/repo/includes/actions/ViewEntityAction.php b/repo/includes/actions/ViewEntityAction.php index f5f304b..7160d7c 100644 --- a/repo/includes/actions/ViewEntityAction.php +++ b/repo/includes/actions/ViewEntityAction.php @@ -5,6 +5,7 @@ use Article; use ContentHandler; use LogEventsList; +use OutputPage; use SpecialPage; use ViewAction; use Wikibase\Repo\Content\EntityHandler; @@ -154,11 +155,11 @@ * @param EntityContent $content */ protected function displayEntityContent( EntityContent $content ) { - $out = $this->getOutput(); + $outputPage = $this->getOutput(); $editable = $this->isEditable(); // NOTE: page-wide property, independent of user permissions - $out->addJsConfigVars( 'wbIsEditView', $editable ); + $outputPage->addJsConfigVars( 'wbIsEditView', $editable ); if ( $editable && !$content->isRedirect() ) { $permissionChecker = $this->getPermissionChecker(); @@ -181,38 +182,71 @@ $this->getArticle()->setParserOptions( $parserOptions ); $this->getArticle()->view(); + $this->applyLabelToTitleText( $outputPage, $content ); + } + + /** + * @param OutputPage $outputPage + */ + private function applyLabelToTitleText( OutputPage $outputPage, EntityContent $content ) { + // Figure out which label to use for title. + $labelText = $this->getLabelText( $content ); + + if ( $this->isDiff() ) { + $this->setPageTitle( $outputPage, $labelText ); + } else { + $this->setHTMLTitle( $outputPage, $labelText ); + } + } + + /** + * @param OutputPage $outputPage + * @param string $labelText + */ + private function setPageTitle( OutputPage $outputPage, $labelText ) { + // Escaping HTML characters in order to retain original label that may contain HTML + // characters. This prevents having characters evaluated or stripped via + // OutputPage::setPageTitle: + $outputPage->setPageTitle( + $this->msg( + 'difference-title' + // This should be something like the following, + // $labelLang->getDirMark() . $labelText . $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 ) ) + ); + } + + /** + * @param OutputPage $outputPage + * @param string $labelText + */ + private function setHTMLTitle( OutputPage $outputPage, $labelText ) { + // Prevent replacing {{...}} by using rawParams() instead of params(): + $outputPage->setHTMLTitle( $this->msg( 'pagetitle' )->rawParams( $labelText ) ); + } + + /** + * @param EntityContent $content + * + * @return string + */ + private function getLabelText( EntityContent $content ) { // Figure out which label to use for title. $languageFallbackChain = $this->getLanguageFallbackChain(); $labelData = null; if ( !$content->isRedirect() ) { - $labelData = $languageFallbackChain->extractPreferredValueOrAny( $content->getEntity()->getLabels() ); + $labels = $content->getEntity()->getLabels(); + $labelData = $languageFallbackChain->extractPreferredValueOrAny( $labels ); } if ( $labelData ) { - $labelText = $labelData['value']; + return $labelData['value']; } else { - $labelText = $content->getEntityId()->getSerialization(); - } - - // Create and set the title. - if ( $this->isDiff() ) { - // Escaping HTML characters in order to retain original label that may contain HTML - // characters. This prevents having characters evaluated or stripped via - // OutputPage::setPageTitle: - $out->setPageTitle( - $this->msg( - 'difference-title' - // This should be something like the following, - // $labelLang->getDirMark() . $labelText . $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 ) ) - ); - } else { - // Prevent replacing {{...}} by using rawParams() instead of params(): - $this->getOutput()->setHTMLTitle( $this->msg( 'pagetitle' )->rawParams( $labelText ) ); + return $content->getEntityId()->getSerialization(); } } -- To view, visit https://gerrit.wikimedia.org/r/168830 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I165720eed483299c1472eb160154ca3b96231eaf Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Aude <aude.w...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits