diff --git a/RELEASE-NOTES-1.41 b/RELEASE-NOTES-1.41 index 23296d1a7a5..20cef01b773 100644 --- a/RELEASE-NOTES-1.41 +++ b/RELEASE-NOTES-1.41 @@ -454,6 +454,8 @@ because of Phabricator reports. are now deprecated. * The XmlJsCode wrapper class has been renamed to MediaWiki\Html\HtmlJsCode, and the old name is now deprecated. +* The use of non-serializable arguments to ParserOutput::addWarningMsg() has + been deprecated and will emit deprecation warnings. * MediaWiki\ResourceLoader\Module::getDeprecationInformation() is deprecated. Use ::getDeprecationWarning() instead. * … diff --git a/includes/parser/ParserOutput.php b/includes/parser/ParserOutput.php index 02d335cdd89..1445c51e78e 100644 --- a/includes/parser/ParserOutput.php +++ b/includes/parser/ParserOutput.php @@ -1037,12 +1037,24 @@ class ParserOutput extends CacheTime implements ContentMetadataCollector { /** * Add a warning to the output for this page. * @param string $msg The localization message key for the warning - * @param mixed ...$args Optional arguments for the message + * @param mixed|JsonUnserializable ...$args Optional arguments for the + * message. These arguments must be serializable/unserializable with + * JsonCodec; see the @note on ParserOutput::setExtensionData() * @since 1.38 */ public function addWarningMsg( string $msg, ...$args ): void { // preserve original arguments in $mWarningMsgs to allow merge - // @todo: these aren't serialized/unserialized + // @todo: these aren't serialized/unserialized yet -- before we + // turn on serialization of $this->mWarningMsgs we need to ensure + // callers aren't passing nonserializable arguments: T343048. + $jsonCodec = MediaWikiServices::getInstance()->getJsonCodec(); + $path = $jsonCodec->detectNonSerializableData( $args, true ); + if ( $path !== null ) { + wfDeprecatedMsg( + "ParserOutput::addWarningMsg() called with nonserializable arguments: $path", + '1.41' + ); + } $this->mWarningMsgs[$msg] = $args; $s = wfMessage( $msg, ...$args ) // some callers set the title here?