jenkins-bot has submitted this change and it was merged.
Change subject: OOUIHTMLForm: Display errors in a nicer way, part 1
......................................................................
OOUIHTMLForm: Display errors in a nicer way, part 1
Depends on Ie14a35fac70d62ff7d102caaa56654ebde11d7dd in OOUI.
Part 2 follows after some cleanup in intermediary commits
in Ifbf38878d41906184f97169b22002f788711a311.
As a bonus, HTMLFormField::getOOUI() now always produces a
OOUI\FieldLayout in OOUI mode. This will let us clean up some code
where we had to take errors HTML from HTMLForm
(I91af6efa8762e9676efea532381292e221255862).
Bug: T98894
Change-Id: I860a96858c4fcac62d63b46e35a9153f22c0a9c9
---
M includes/htmlform/HTMLFormField.php
M includes/htmlform/OOUIHTMLForm.php
2 files changed, 54 insertions(+), 12 deletions(-)
Approvals:
Jforrester: Looks good to me, approved
Florianschmidtwelzow: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/includes/htmlform/HTMLFormField.php
b/includes/htmlform/HTMLFormField.php
index 1d8137e..0fab033 100644
--- a/includes/htmlform/HTMLFormField.php
+++ b/includes/htmlform/HTMLFormField.php
@@ -558,23 +558,25 @@
*
* @param string $value The value to set the input to.
*
- * @return string
+ * @return OOUI\\FieldLayout|OOUI\\ActionFieldLayout
*/
public function getOOUI( $value ) {
- list( $errors, $errorClass ) = $this->getErrorsAndErrorClass(
$value );
-
$inputField = $this->getInputOOUI( $value );
if ( !$inputField ) {
- // This field doesn't have an OOUI implementation yet
at all.
- // OK, use this trick:
- return $this->getDiv( $value );
+ // This field doesn't have an OOUI implementation yet
at all. Fall back to getDiv() to
+ // generate the whole field, label and errors and all,
then wrap it in a Widget.
+ // It might look weird, but it'll work OK.
+ return $this->getFieldLayoutOOUI(
+ new OOUI\Widget( array( 'content' => new
OOUI\HtmlSnippet( $this->getDiv( $value ) ) ) ),
+ array( 'infusable' => false )
+ );
}
$infusable = true;
if ( is_string( $inputField ) ) {
- // Mmm… We have an OOUI implementation, but it's not
complete, and we got a load of HTML.
- // Cheat a little and wrap it in a widget! It won't be
infusable, though, since client-side
+ // We have an OOUI implementation, but it's not proper,
and we got a load of HTML.
+ // Cheat a little and wrap it in a widget. It won't be
infusable, though, since client-side
// JavaScript doesn't know how to rebuilt the contents.
$inputField = new OOUI\Widget( array( 'content' => new
OOUI\HtmlSnippet( $inputField ) ) );
$infusable = false;
@@ -582,16 +584,21 @@
$fieldType = get_class( $this );
$helpText = $this->getHelpText();
+ $errors = $this->getErrorsRaw( $value );
+ foreach ( $errors as &$error ) {
+ $error = new OOUI\HtmlSnippet( $error );
+ }
+
$config = array(
- 'classes' => array( "mw-htmlform-field-$fieldType",
$this->mClass, $errorClass ),
+ 'classes' => array( "mw-htmlform-field-$fieldType",
$this->mClass ),
'align' => $this->getLabelAlignOOUI(),
'label' => $this->getLabel(),
'help' => $helpText !== null ? new OOUI\HtmlSnippet(
$helpText ) : null,
+ 'errors' => $errors,
'infusable' => $infusable,
);
- $field = $this->getFieldLayoutOOUI( $inputField, $config );
- return $field . $errors;
+ return $this->getFieldLayoutOOUI( $inputField, $config );
}
/**
@@ -778,7 +785,7 @@
* @since 1.20
*
* @param string $value The value of the input
- * @return array
+ * @return array array( $errors, $errorClass )
*/
public function getErrorsAndErrorClass( $value ) {
$errors = $this->validate( $value, $this->mParent->mFieldData );
@@ -795,6 +802,32 @@
}
/**
+ * Determine form errors to display, returning them in an array.
+ *
+ * @since 1.26
+ * @param string $value The value of the input
+ * @return string[] Array of error HTML strings
+ */
+ public function getErrorsRaw( $value ) {
+ $errors = $this->validate( $value, $this->mParent->mFieldData );
+
+ if ( is_bool( $errors ) || !$this->mParent->wasSubmitted() ) {
+ $errors = array();
+ }
+
+ if ( !is_array( $errors ) ) {
+ $errors = array( $errors );
+ }
+ foreach ( $errors as &$error ) {
+ if ( $error instanceof Message ) {
+ $error = $error->parse();
+ }
+ }
+
+ return $errors;
+ }
+
+ /**
* @return string
*/
function getLabel() {
diff --git a/includes/htmlform/OOUIHTMLForm.php
b/includes/htmlform/OOUIHTMLForm.php
index eec13ee..b5547f6 100644
--- a/includes/htmlform/OOUIHTMLForm.php
+++ b/includes/htmlform/OOUIHTMLForm.php
@@ -104,6 +104,15 @@
return $html;
}
+ /**
+ * @param string|array|Status $errors
+ * @return string
+ */
+ function getErrors( $errors ) {
+ // TODO Write me!
+ return '';
+ }
+
function getBody() {
$fieldset = parent::getBody();
// FIXME This only works for forms with no subsections
--
To view, visit https://gerrit.wikimedia.org/r/227603
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I860a96858c4fcac62d63b46e35a9153f22c0a9c9
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits