X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fhtmlform%2FOOUIHTMLForm.php;h=6fbf15b66d56be565846b68e5a5c8f0c10d6f5fe;hb=fa8253824f76e7f939a51720ed443c36ead37b9d;hp=0b227278a329885c33dbddc063546e4af51aac1e;hpb=ff13c3d92a3357d2cbb03c4d58dfc33999942b0a;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/htmlform/OOUIHTMLForm.php b/includes/htmlform/OOUIHTMLForm.php index 0b227278a3..6fbf15b66d 100644 --- a/includes/htmlform/OOUIHTMLForm.php +++ b/includes/htmlform/OOUIHTMLForm.php @@ -26,6 +26,7 @@ */ class OOUIHTMLForm extends HTMLForm { private $oouiErrors; + private $oouiWarnings; public function __construct( $descriptor, $context = null, $messagePrefix = '' ) { parent::__construct( $descriptor, $context, $messagePrefix ); @@ -185,28 +186,34 @@ class OOUIHTMLForm extends HTMLForm { } /** - * @param string|array|Status $err + * @param string|array|Status $elements + * @param string $elementsType * @return string */ - function getErrors( $err ) { - if ( !$err ) { + function getErrorsOrWarnings( $elements, $elementsType ) { + if ( !in_array( $elementsType, [ 'error', 'warning' ] ) ) { + throw new DomainException( $elementsType . ' is not a valid type.' ); + } + if ( !$elements ) { $errors = []; - } elseif ( $err instanceof Status ) { - if ( $err->isOK() ) { + } elseif ( $elements instanceof Status ) { + if ( $elements->isGood() ) { $errors = []; } else { - $errors = $err->getErrorsByType( 'error' ); + $errors = $elements->getErrorsByType( $elementsType ); foreach ( $errors as &$error ) { - // Input: array( 'message' => 'foo', 'errors' => array( 'a', 'b', 'c' ) ) - // Output: array( 'foo', 'a', 'b', 'c' ) + // Input: [ 'message' => 'foo', 'errors' => [ 'a', 'b', 'c' ] ] + // Output: [ 'foo', 'a', 'b', 'c' ] $error = array_merge( [ $error['message'] ], $error['params'] ); } } - } else { - $errors = $err; + } elseif ( $elementsType === 'errors' ) { + $errors = $elements; if ( !is_array( $errors ) ) { $errors = [ $errors ]; } + } else { + $errors = []; } foreach ( $errors as &$error ) { @@ -215,7 +222,11 @@ class OOUIHTMLForm extends HTMLForm { } // Used in getBody() - $this->oouiErrors = $errors; + if ( $elementsType === 'error' ) { + $this->oouiErrors = $errors; + } else { + $this->oouiWarnings = $errors; + } return ''; } @@ -236,7 +247,10 @@ class OOUIHTMLForm extends HTMLForm { if ( $this->oouiErrors ) { $classes[] = 'mw-htmlform-ooui-header-errors'; } - if ( $this->mHeader || $this->oouiErrors ) { + if ( $this->oouiWarnings ) { + $classes[] = 'mw-htmlform-ooui-header-warnings'; + } + if ( $this->mHeader || $this->oouiErrors || $this->oouiWarnings ) { // if there's no header, don't create an (empty) LabelWidget, simply use a placeholder if ( $this->mHeader ) { $element = new OOUI\LabelWidget( [ 'label' => new OOUI\HtmlSnippet( $this->mHeader ) ] ); @@ -249,6 +263,7 @@ class OOUIHTMLForm extends HTMLForm { [ 'align' => 'top', 'errors' => $this->oouiErrors, + 'notices' => $this->oouiWarnings, 'classes' => $classes, ] )