Aude has uploaded a new change for review. https://gerrit.wikimedia.org/r/285557
Change subject: Fix fatal error in OutputPageBeforeHTMLHookHandler ...................................................................... Fix fatal error in OutputPageBeforeHTMLHookHandler Check that we have valid EntityId and EntityRevision objects before trying to load an Entity from EntityRevision. There are cases (e.g. an admin viewing a revision of a deleted item) where the EntityId is not available or an EntityRevision is not found. (my patch on master was not a clean cherry pick so I have made this patch against the branch) Bug: T132645 Change-Id: I513c64648f46600e6f0b1a2e565f47775853b9bb --- M repo/includes/Hooks/OutputPageBeforeHTMLHookHandler.php 1 file changed, 27 insertions(+), 6 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/57/285557/1 diff --git a/repo/includes/Hooks/OutputPageBeforeHTMLHookHandler.php b/repo/includes/Hooks/OutputPageBeforeHTMLHookHandler.php index 1e282c1..85ee46e 100644 --- a/repo/includes/Hooks/OutputPageBeforeHTMLHookHandler.php +++ b/repo/includes/Hooks/OutputPageBeforeHTMLHookHandler.php @@ -3,7 +3,9 @@ namespace Wikibase\Repo\Hooks; use OutputPage; +use Wikibase\DataModel\Entity\EntityId; use Wikibase\DataModel\Term\AliasesProvider; +use Wikibase\EntityRevision; use Wikibase\Lib\ContentLanguages; use Wikibase\Lib\LanguageNameLookup; use Wikibase\Lib\Store\EntityRevisionLookup; @@ -126,9 +128,26 @@ if ( !empty( $placeholders ) ) { $injector = new TextInjector( $placeholders ); - $expander = $this->getEntityViewPlaceholderExpander( $out ); + $callback = function() { + return ''; + }; - $html = $injector->inject( $html, array( $expander, 'getHtmlForPlaceholder' ) ); + $entityId = $this->outputPageEntityIdReader->getEntityIdFromOutputPage( $out ); + + if ( $entityId instanceof EntityId ) { + $revisionId = $out->getRevisionId(); + $entityRevision = $this->entityRevisionLookup->getEntityRevision( + $entityId, + $revisionId + ); + + if ( $entityRevision instanceof EntityRevision ) { + $expander = $this->getEntityViewPlaceholderExpander( $out, $entityRevision ); + $callback = [ $expander, 'getHtmlForPlaceholder' ]; + } + } + + $html = $injector->inject( $html, $callback ); $out->addJsConfigVars( 'wbUserSpecifiedLanguages', @@ -145,14 +164,16 @@ /** * @param OutputPage $out + * @param EntityRevision $entityRev * * @return EntityViewPlaceholderExpander */ - private function getEntityViewPlaceholderExpander( OutputPage $out ) { + private function getEntityViewPlaceholderExpander( + OutputPage $out, + EntityRevision $entityRevision + ) { + $entity = $entityRevision->getEntity(); - $entityId = $this->outputPageEntityIdReader->getEntityIdFromOutputPage( $out ); - $revisionId = $out->getRevisionId(); - $entity = $this->entityRevisionLookup->getEntityRevision( $entityId, $revisionId )->getEntity(); $labelsProvider = $entity; $descriptionsProvider = $entity; $aliasesProvider = $entity instanceof AliasesProvider ? $entity : null; -- To view, visit https://gerrit.wikimedia.org/r/285557 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I513c64648f46600e6f0b1a2e565f47775853b9bb Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: wmf/1.27.0-wmf.21 Gerrit-Owner: Aude <aude.w...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits