Do not assume string is message key in OOUIHtmlForm::getErrorsOrWarnings

single string is raw html,
not a message key as documented on HTMLForm::trySubmit

Also remove is_string, any truthy value would be implicit string casted
in HtmlForm::getErrorsOrWarnings

Reorder the if in HtmlForm to look similar to OOUI

Change-Id: I5b78b0df2cca695f8f5c6b08aa4d6c015d1fa1fe
This commit is contained in:
Umherirrender 2020-08-22 17:56:44 +02:00 committed by Thiemo Kreuz (WMDE)
parent aa18c32c3d
commit cf8c94b163
2 changed files with 13 additions and 9 deletions

View file

@ -1342,10 +1342,12 @@ class HTMLForm extends ContextSource {
->setInterfaceMessageFlag( true )
->parse();
}
} elseif ( is_array( $elements ) && $elementsType === 'error' ) {
$elementstr = $this->formatErrors( $elements );
} elseif ( $elementsType === 'error' ) {
$elementstr = $elements;
if ( is_array( $elements ) ) {
$elementstr = $this->formatErrors( $elements );
} elseif ( $elements && $elements !== true ) {
$elementstr = (string)$elements;
}
}
return $elementstr

View file

@ -220,21 +220,23 @@ class OOUIHTMLForm extends HTMLForm {
if ( !$elements->isGood() ) {
$errors = $elements->getErrorsByType( $elementsType );
foreach ( $errors as &$error ) {
// Input: [ 'message' => 'foo', 'errors' => [ 'a', 'b', 'c' ] ]
// Input: [ 'message' => 'foo', 'params' => [ 'a', 'b', 'c' ] ]
// Output: [ 'foo', 'a', 'b', 'c' ]
$error = array_merge( [ $error['message'] ], $error['params'] );
$error = $this->getMessage(
array_merge( [ $error['message'] ], $error['params'] ) )->parse();
}
}
} elseif ( $elementsType === 'error' ) {
if ( is_array( $elements ) ) {
$errors = $elements;
} elseif ( is_string( $elements ) ) {
$errors = [ $elements ];
foreach ( $elements as $error ) {
$errors[] = $this->getMessage( $error )->parse();
}
} elseif ( $elements && $elements !== true ) {
$errors[] = (string)$elements;
}
}
foreach ( $errors as &$error ) {
$error = $this->getMessage( $error )->parse();
$error = new OOUI\HtmlSnippet( $error );
}