jenkins-bot has submitted this change and it was merged.
Change subject: Improve HTMLSubmitField return value
......................................................................
Improve HTMLSubmitField return value
- do not return anything when the button was not clicked
- return boolean true (instead of the button text) when it was clicked
Unbreaks submit fields which currently don't return anything so there is
no easy way to tell whether they have been clicked.
Change-Id: If4e0dfb6ee6674f0dace80a01850e2d0cbbdb47a
---
M includes/htmlform/HTMLForm.php
M includes/htmlform/HTMLFormField.php
M includes/htmlform/HTMLFormFieldCloner.php
M includes/htmlform/HTMLSubmitField.php
4 files changed, 24 insertions(+), 5 deletions(-)
Approvals:
Anomie: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/htmlform/HTMLForm.php b/includes/htmlform/HTMLForm.php
index d50fac0..6878399 100644
--- a/includes/htmlform/HTMLForm.php
+++ b/includes/htmlform/HTMLForm.php
@@ -1495,7 +1495,7 @@
foreach ( $fields as $key => $value ) {
if ( $value instanceof HTMLFormField ) {
- $v = empty( $value->mParams['nodata'] )
+ $v = isset( $this->mFieldData[$key] )
? $this->mFieldData[$key]
: $value->getDefault();
@@ -1604,12 +1604,13 @@
$fieldData = [];
foreach ( $this->mFlatFields as $fieldname => $field ) {
- if ( !empty( $field->mParams['nodata'] ) ) {
+ $request = $this->getRequest();
+ if ( $field->skipLoadData( $request ) ) {
continue;
} elseif ( !empty( $field->mParams['disabled'] ) ) {
$fieldData[$fieldname] = $field->getDefault();
} else {
- $fieldData[$fieldname] =
$field->loadDataFromRequest( $this->getRequest() );
+ $fieldData[$fieldname] =
$field->loadDataFromRequest( $request );
}
}
diff --git a/includes/htmlform/HTMLFormField.php
b/includes/htmlform/HTMLFormField.php
index e86d4c4..d5f4cc06 100644
--- a/includes/htmlform/HTMLFormField.php
+++ b/includes/htmlform/HTMLFormField.php
@@ -1106,4 +1106,14 @@
return $this->msg( $value, [] );
}
}
+
+ /**
+ * Skip this field when collecting data.
+ * @param WebRequest $request
+ * @return bool
+ * @since 1.27
+ */
+ public function skipLoadData( $request ) {
+ return !empty( $this->mParams['nodata'] );
+ }
}
diff --git a/includes/htmlform/HTMLFormFieldCloner.php
b/includes/htmlform/HTMLFormFieldCloner.php
index 4f2460f..7359092 100644
--- a/includes/htmlform/HTMLFormFieldCloner.php
+++ b/includes/htmlform/HTMLFormFieldCloner.php
@@ -150,7 +150,7 @@
$subrequest = new DerivativeRequest( $request, $data,
$request->wasPosted() );
$row = [];
foreach ( $fields as $fieldname => $field ) {
- if ( !empty( $field->mParams['nodata'] ) ) {
+ if ( $field->skipLoadData( $subrequest ) ) {
continue;
} elseif ( !empty( $field->mParams['disabled']
) ) {
$row[$fieldname] = $field->getDefault();
@@ -271,7 +271,7 @@
$fields = $this->createFieldsForKey( $key );
foreach ( $fields as $fieldname => $field ) {
- $v = ( empty( $field->mParams['nodata'] ) && $values
!== null )
+ $v = isset( $values[$fieldname] )
? $values[$fieldname]
: $field->getDefault();
diff --git a/includes/htmlform/HTMLSubmitField.php
b/includes/htmlform/HTMLSubmitField.php
index 7f90100..cb98549 100644
--- a/includes/htmlform/HTMLSubmitField.php
+++ b/includes/htmlform/HTMLSubmitField.php
@@ -8,4 +8,12 @@
protected $buttonType = 'submit';
protected $mFlags = [ 'primary', 'constructive' ];
+
+ public function skipLoadData( $request ) {
+ return !$request->getCheck( $this->mName );
+ }
+
+ public function loadDataFromRequest( $request ) {
+ return $request->getCheck( $this->mName );
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/280884
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: If4e0dfb6ee6674f0dace80a01850e2d0cbbdb47a
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Gergő Tisza <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Gergő Tisza <[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