Show titleblacklist error message in html when using js api module

Parse the message in html according to the errorformat= in the url,
fallback to wikitext to avoid a breaking change.

Bug: T369244
Change-Id: I58b995b3663b7dd286267e640d8d56164bd9be0b
This commit is contained in:
Umherirrender 2024-07-16 22:57:46 +02:00
parent ea252fcf43
commit 4290e114d4
2 changed files with 11 additions and 2 deletions

View file

@ -72,7 +72,12 @@ class ApiTitleBlacklist extends ApiBase {
$res->addValue( 'titleblacklist', 'result', 'blacklisted' );
// there aren't any messages for create(talk|page), using edit for those instead
$message = $blacklisted->getErrorMessage( $action !== 'create' ? $action : 'edit' );
$res->addValue( 'titleblacklist', 'reason', $this->msg( $message, $result )->page( $title )->text() );
$messageObj = $this->msg( $message, $result )->page( $title );
if ( $this->getErrorFormatter()->getFormat() === 'html' ) {
$res->addValue( 'titleblacklist', 'reason', $messageObj->parse() );
} else {
$res->addValue( 'titleblacklist', 'reason', $messageObj->text() );
}
$res->addValue( 'titleblacklist', 'message', $message );
$res->addValue( 'titleblacklist', 'line', htmlspecialchars( $blacklisted->getRaw() ) );
} else {

View file

@ -25,7 +25,11 @@
this.get( {
action: 'titleblacklist',
tbaction: 'create',
tbtitle: title.toString()
tbtitle: title.toString(),
errorformat: 'html',
errorlang: mw.config.get( 'wgUserLanguage' ),
errorsuselocal: '',
formatversion: 2
} )
.done( function ( data ) {
var result;