From ba76dfdd050b83eb124ef2f12a6f22c467133fca Mon Sep 17 00:00:00 2001 From: "C. Scott Ananian" Date: Thu, 17 Oct 2019 12:59:04 -0400 Subject: [PATCH] Deprecate setting Parser::mTitle to null This never happens in core code; however extensions have slipped into a state of sin. Bug: T235392 Change-Id: Ia254949cd8b3bc162b11dcc911dcce40d91bf1b7 (cherry picked from commit dd9e6124b4a47b98cccdaa2971d587ecc6f0ab6e) --- RELEASE-NOTES-1.34 | 3 +++ includes/parser/Parser.php | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES-1.34 b/RELEASE-NOTES-1.34 index ed2cf9c2e3..d34d14bb2b 100644 --- a/RELEASE-NOTES-1.34 +++ b/RELEASE-NOTES-1.34 @@ -619,6 +619,9 @@ because of Phabricator reports. fetchLanguageName, getFileName, getMessagesFileName, getJsonMessagesFileName. Use the new LanguageNameUtils class instead. (Note that fetchLanguageName(s) are called getLanguageName(s) in the new class.) +* Using the Parser without initializing its $mTitle property to non-null has + been deprecated. In a future release Parser::getTitle() will throw a + TypeError if $mTitle is uninitialized. === Other changes in 1.34 === * Added option to specify "Various authors" as author in extension credits using diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index ae77c4ef03..3aa2c69ffa 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -228,7 +228,11 @@ class Parser { public $mOptions; /** - * @var Title|null Beware - this is not always set + * Since 1.34, leaving `mTitle` uninitialized or setting `mTitle` to + * `null` is deprecated. + * + * @internal + * @var Title|null */ public $mTitle; # Title context, used for self-link rendering and similar things public $mOutputType; # Output type, one of the OT_xxx constants @@ -924,9 +928,14 @@ class Parser { /** * Accessor for the Title object * + * Since 1.34, leaving `mTitle` uninitialized as `null` is deprecated. + * * @return Title|null */ public function getTitle() : ?Title { + if ( $this->mTitle === null ) { + wfDeprecated( 'Parser title should never be null', '1.34' ); + } return $this->mTitle; } -- 2.20.1