jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/354982 )
Change subject: Fix \n handling for HTMLUsersMultiselectField
......................................................................
Fix \n handling for HTMLUsersMultiselectField
Bug: T166836
Change-Id: I51b772946f1e50a21fb86cab969defb4647b820b
---
M includes/htmlform/fields/HTMLUsersMultiselectField.php
1 file changed, 13 insertions(+), 12 deletions(-)
Approvals:
Krinkle: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/htmlform/fields/HTMLUsersMultiselectField.php
b/includes/htmlform/fields/HTMLUsersMultiselectField.php
index 8829f66..eb88909 100644
--- a/includes/htmlform/fields/HTMLUsersMultiselectField.php
+++ b/includes/htmlform/fields/HTMLUsersMultiselectField.php
@@ -15,18 +15,16 @@
* @note This widget is not likely to remain functional in non-OOUI forms.
*/
class HTMLUsersMultiselectField extends HTMLUserTextField {
-
public function loadDataFromRequest( $request ) {
- if ( !$request->getCheck( $this->mName ) ) {
- return $this->getDefault();
- }
+ $value = $request->getText( $this->mName, $this->getDefault() );
- $usersArray = explode( "\n", $request->getText( $this->mName )
);
+ $usersArray = explode( "\n", $value );
// Remove empty lines
$usersArray = array_values( array_filter( $usersArray,
function( $username ) {
return trim( $username ) !== '';
} ) );
- return $usersArray;
+ // This function is expected to return a string
+ return implode( "\n", $usersArray );
}
public function validate( $value, $alldata ) {
@@ -38,7 +36,9 @@
return false;
}
- foreach ( $value as $username ) {
+ // $value is a string, because HTMLForm fields store their
values as strings
+ $usersArray = explode( "\n", $value );
+ foreach ( $usersArray as $username ) {
$result = parent::validate( $username, $alldata );
if ( $result !== true ) {
return $result;
@@ -48,12 +48,12 @@
return true;
}
- public function getInputHTML( $values ) {
+ public function getInputHTML( $value ) {
$this->mParent->getOutput()->enableOOUI();
- return $this->getInputOOUI( $values );
+ return $this->getInputOOUI( $value );
}
- public function getInputOOUI( $values ) {
+ public function getInputOOUI( $value ) {
$params = [ 'name' => $this->mName ];
if ( isset( $this->mParams['default'] ) ) {
@@ -68,8 +68,9 @@
->plain();
}
- if ( !is_null( $values ) ) {
- $params['default'] = $values;
+ if ( !is_null( $value ) ) {
+ // $value is a string, but the widget expects an array
+ $params['default'] = explode( "\n", $value );
}
// Make the field auto-infusable when it's used inside a legacy
HTMLForm rather than OOUIHTMLForm
--
To view, visit https://gerrit.wikimedia.org/r/354982
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I51b772946f1e50a21fb86cab969defb4647b820b
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Mattflaschen <[email protected]>
Gerrit-Reviewer: Bartosz DziewoĆski <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: MtDu <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits