Deprecate ParserOutput::addWarning() in favor of ::addWarningMsg()
Encourage localization and factor out common code by taking a message key as the first argument to ::addWarningMsg() instead of a wikitext string. This also plays nicer with Parsoid by separating out the localization code from the parse. Bug: T293515 Change-Id: I6a7c04c67ac586ab00d4edcbb3d09485a7794e23
This commit is contained in:
parent
06ab90f163
commit
4834340ec0
6 changed files with 55 additions and 25 deletions
|
|
@ -230,6 +230,7 @@ because of Phabricator reports.
|
||||||
- ::getFlag() - use ::getOutputFlag()
|
- ::getFlag() - use ::getOutputFlag()
|
||||||
- ::setFlag() - use ::setOutputFlag()
|
- ::setFlag() - use ::setOutputFlag()
|
||||||
- ::getAllFlags() - this method is now marked @internal
|
- ::getAllFlags() - this method is now marked @internal
|
||||||
|
- ::addWarning() - use ::addWarningMsg()
|
||||||
* The following methods were deprecated; use ::setPreventClickjacking(..)
|
* The following methods were deprecated; use ::setPreventClickjacking(..)
|
||||||
instead:
|
instead:
|
||||||
- OutputPage::preventClickjacking()
|
- OutputPage::preventClickjacking()
|
||||||
|
|
|
||||||
|
|
@ -501,11 +501,10 @@ class CoreParserFunctions {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$parser->getOutput()->addWarning(
|
$parser->getOutput()->addWarningMsg(
|
||||||
wfMessage( 'restricted-displaytitle',
|
'restricted-displaytitle',
|
||||||
// Message should be parsed, but this param should only be escaped.
|
// Message should be parsed, but this param should only be escaped.
|
||||||
wfEscapeWikiText( $text )
|
Message::plaintextParam( $text )
|
||||||
)->text()
|
|
||||||
);
|
);
|
||||||
$parser->addTrackingCategory( 'restricted-displaytitle-ignored' );
|
$parser->addTrackingCategory( 'restricted-displaytitle-ignored' );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -121,10 +121,12 @@ class PPFrame_Hash implements PPFrame {
|
||||||
// Numbered parameter
|
// Numbered parameter
|
||||||
$index = $bits['index'] - $indexOffset;
|
$index = $bits['index'] - $indexOffset;
|
||||||
if ( isset( $namedArgs[$index] ) || isset( $numberedArgs[$index] ) ) {
|
if ( isset( $namedArgs[$index] ) || isset( $numberedArgs[$index] ) ) {
|
||||||
$this->parser->getOutput()->addWarning( wfMessage( 'duplicate-args-warning',
|
$this->parser->getOutput()->addWarningMsg(
|
||||||
wfEscapeWikiText( $this->title ),
|
'duplicate-args-warning',
|
||||||
wfEscapeWikiText( $title ),
|
Message::plaintextParam( (string)$this->title ),
|
||||||
wfEscapeWikiText( $index ) )->text() );
|
Message::plaintextParam( (string)$title ),
|
||||||
|
Message::numParam( $index )
|
||||||
|
);
|
||||||
$this->parser->addTrackingCategory( 'duplicate-args-category' );
|
$this->parser->addTrackingCategory( 'duplicate-args-category' );
|
||||||
}
|
}
|
||||||
$numberedArgs[$index] = $bits['value'];
|
$numberedArgs[$index] = $bits['value'];
|
||||||
|
|
@ -133,11 +135,12 @@ class PPFrame_Hash implements PPFrame {
|
||||||
// Named parameter
|
// Named parameter
|
||||||
$name = trim( $this->expand( $bits['name'], PPFrame::STRIP_COMMENTS ) );
|
$name = trim( $this->expand( $bits['name'], PPFrame::STRIP_COMMENTS ) );
|
||||||
if ( isset( $namedArgs[$name] ) || isset( $numberedArgs[$name] ) ) {
|
if ( isset( $namedArgs[$name] ) || isset( $numberedArgs[$name] ) ) {
|
||||||
$this->parser->getOutput()->addWarning( wfMessage( 'duplicate-args-warning',
|
$this->parser->getOutput()->addWarningMsg(
|
||||||
wfEscapeWikiText( $this->title ),
|
'duplicate-args-warning',
|
||||||
wfEscapeWikiText( $title ),
|
Message::plaintextParam( (string)$this->title ),
|
||||||
// @phan-suppress-next-line SecurityCheck-DoubleEscaped taint track for named args
|
Message::plaintextParam( (string)$title ),
|
||||||
wfEscapeWikiText( $name ) )->text() );
|
Message::plaintextParam( (string)$name )
|
||||||
|
);
|
||||||
$this->parser->addTrackingCategory( 'duplicate-args-category' );
|
$this->parser->addTrackingCategory( 'duplicate-args-category' );
|
||||||
}
|
}
|
||||||
$namedArgs[$name] = $bits['value'];
|
$namedArgs[$name] = $bits['value'];
|
||||||
|
|
|
||||||
|
|
@ -2950,9 +2950,11 @@ class Parser {
|
||||||
# does no harm if $current and $max are present but are unnecessary for the message
|
# does no harm if $current and $max are present but are unnecessary for the message
|
||||||
# Not doing ->inLanguage( $this->mOptions->getUserLangObj() ), since this is shown
|
# Not doing ->inLanguage( $this->mOptions->getUserLangObj() ), since this is shown
|
||||||
# only during preview, and that would split the parser cache unnecessarily.
|
# only during preview, and that would split the parser cache unnecessarily.
|
||||||
$warning = wfMessage( "$limitationType-warning" )->numParams( $current, $max )
|
$this->mOutput->addWarningMsg(
|
||||||
->text();
|
"$limitationType-warning",
|
||||||
$this->mOutput->addWarning( $warning );
|
Message::numParam( $current ),
|
||||||
|
Message::numParam( $max )
|
||||||
|
);
|
||||||
$this->addTrackingCategory( "$limitationType-category" );
|
$this->addTrackingCategory( "$limitationType-category" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3237,8 +3239,10 @@ class Parser {
|
||||||
. wfMessage( 'parser-template-loop-warning', $titleText )->inContentLanguage()->text()
|
. wfMessage( 'parser-template-loop-warning', $titleText )->inContentLanguage()->text()
|
||||||
. '</span>';
|
. '</span>';
|
||||||
$this->addTrackingCategory( 'template-loop-category' );
|
$this->addTrackingCategory( 'template-loop-category' );
|
||||||
$this->mOutput->addWarning( wfMessage( 'template-loop-warning',
|
$this->mOutput->addWarningMsg(
|
||||||
wfEscapeWikiText( $titleText ) )->text() );
|
'template-loop-warning',
|
||||||
|
Message::plaintextParam( $titleText )
|
||||||
|
);
|
||||||
$this->logger->debug( __METHOD__ . ": template loop broken at '$titleText'" );
|
$this->logger->debug( __METHOD__ . ": template loop broken at '$titleText'" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3283,7 +3287,7 @@ class Parser {
|
||||||
// T91154: {{=}} is deprecated when it doesn't expand to `=`;
|
// T91154: {{=}} is deprecated when it doesn't expand to `=`;
|
||||||
// use {{Template:=}} if you must.
|
// use {{Template:=}} if you must.
|
||||||
$this->addTrackingCategory( 'template-equals-category' );
|
$this->addTrackingCategory( 'template-equals-category' );
|
||||||
$this->mOutput->addWarning( wfMessage( 'template-equals-warning' )->text() );
|
$this->mOutput->addWarningMsg( 'template-equals-warning' );
|
||||||
}
|
}
|
||||||
|
|
||||||
# Replace raw HTML by a placeholder
|
# Replace raw HTML by a placeholder
|
||||||
|
|
|
||||||
|
|
@ -838,10 +838,27 @@ class ParserOutput extends CacheTime {
|
||||||
$this->mLanguageLinks[] = $t;
|
$this->mLanguageLinks[] = $t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated since 1.38; use ::addWarningMsg() instead
|
||||||
|
*/
|
||||||
public function addWarning( $s ) {
|
public function addWarning( $s ) {
|
||||||
$this->mWarnings[$s] = 1;
|
$this->mWarnings[$s] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
* @since 1.38
|
||||||
|
*/
|
||||||
|
public function addWarningMsg( string $msg, ...$args ): void {
|
||||||
|
$s = wfMessage( $msg, ...$args )
|
||||||
|
// some callers set the title here?
|
||||||
|
->inContentLanguage() // because this ends up in cache
|
||||||
|
->text();
|
||||||
|
$this->mWarnings[$s] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
public function addOutputHook( $hook, $data = false ) {
|
public function addOutputHook( $hook, $data = false ) {
|
||||||
$this->mOutputHooks[] = [ $hook, $data ];
|
$this->mOutputHooks[] = [ $hook, $data ];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -816,8 +816,8 @@ EOF
|
||||||
// flags & co
|
// flags & co
|
||||||
$a = new ParserOutput();
|
$a = new ParserOutput();
|
||||||
|
|
||||||
$a->addWarning( 'Oops' );
|
$a->addWarningMsg( 'duplicate-args-warning', 'A', 'B', 'C' );
|
||||||
$a->addWarning( 'Whoops' );
|
$a->addWarningMsg( 'template-loop-warning', 'D' );
|
||||||
|
|
||||||
$a->setFlag( 'foo' );
|
$a->setFlag( 'foo' );
|
||||||
$a->setFlag( 'bar' );
|
$a->setFlag( 'bar' );
|
||||||
|
|
@ -827,8 +827,9 @@ EOF
|
||||||
|
|
||||||
$b = new ParserOutput();
|
$b = new ParserOutput();
|
||||||
|
|
||||||
$b->addWarning( 'Yikes' );
|
$b->addWarningMsg( 'template-equals-warning' );
|
||||||
$b->addWarning( 'Whoops' );
|
$b->addWarningMsg( 'template-loop-warning', 'D' );
|
||||||
|
$b->addWarning( 'Old School' ); // test the deprecated ::addWarning()
|
||||||
|
|
||||||
$b->setFlag( 'zoo' );
|
$b->setFlag( 'zoo' );
|
||||||
$b->setFlag( 'bar' );
|
$b->setFlag( 'bar' );
|
||||||
|
|
@ -837,7 +838,12 @@ EOF
|
||||||
$b->recordOption( 'Bar' );
|
$b->recordOption( 'Bar' );
|
||||||
|
|
||||||
yield 'flags' => [ $a, $b, [
|
yield 'flags' => [ $a, $b, [
|
||||||
'getWarnings' => [ 'Oops', 'Whoops', 'Yikes' ],
|
'getWarnings' => [
|
||||||
|
wfMessage( 'duplicate-args-warning', 'A', 'B', 'C' )->text(),
|
||||||
|
wfMessage( 'template-loop-warning', 'D' )->text(),
|
||||||
|
wfMessage( 'template-equals-warning' )->text(),
|
||||||
|
'Old School',
|
||||||
|
],
|
||||||
'$mFlags' => [ 'foo' => true, 'bar' => true, 'zoo' => true ],
|
'$mFlags' => [ 'foo' => true, 'bar' => true, 'zoo' => true ],
|
||||||
'getUsedOptions' => [ 'Foo', 'Bar', 'Zoo' ],
|
'getUsedOptions' => [ 'Foo', 'Bar', 'Zoo' ],
|
||||||
] ];
|
] ];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue