From 2712cb8330d8e9b4755d89b6909c5589ee6da8d3 Mon Sep 17 00:00:00 2001 From: "C. Scott Ananian" Date: Wed, 6 May 2020 12:38:07 -0400 Subject: Fix impedance mismatch with Parser::getRevisionRecordObject() Parser::getRevisionRecordObject() returns `null` if the revision is missing, but it invokes ParserOptions::getCurrentRevisionRecordCallback() (ie, Parser::statelessFetchRevisionRecord() by default) which returns `false` as its error condition. This reverts commit ae74a29af3116eb73a4cb775736b3acee0a65c59, and instead fixes the bug at its root. Bug: T251952 Change-Id: If36b35391f7833a1aded8b5a0de706d44187d423 --- includes/parser/CoreParserFunctions.php | 4 +--- includes/parser/Parser.php | 8 ++++++++ 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'includes/parser') diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index 427c8ca7857c..a96d873a3b62 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -1394,9 +1394,7 @@ class CoreParserFunctions { } // fetch revision from cache/database and return the value $rev = self::getCachedRevisionObject( $parser, $t, 'vary-user' ); - - // TODO what can getCachedRevisionObject return other than RevisionRecord and null - if ( !( $rev instanceof RevisionRecord ) ) { + if ( $rev === null ) { return ''; } $user = $rev->getUser(); diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index e9698527167e..92c0c2df4659 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -5778,6 +5778,14 @@ class Parser { $this ); + if ( $rev === false ) { + // The revision record callback returns `false` (not null) to + // indicate that the revision is missing. (See for example + // Parser::statelessFetchRevisionRecord(), the default callback.) + // This API expects `null` instead. (T251952) + $rev = null; + } + if ( $this->mRevisionId === null && $rev && $rev->getId() ) { // We are in preview mode (mRevisionId is null), and the current revision callback // returned an existing revision. Ignore it and return null, it's probably the page's -- cgit v1.2.3