From: jenkins-bot Date: Fri, 30 Jun 2017 02:21:13 +0000 (+0000) Subject: Merge "Fix \n handling for HTMLUsersMultiselectField" X-Git-Tag: 1.31.0-rc.0~2835 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=5049af1048c77b1ea6ab3193688d23a48ddf8df0;hp=c1f35920d1a8e84a1a81a217b20d9f69b0a12f6f Merge "Fix \n handling for HTMLUsersMultiselectField" --- diff --git a/includes/htmlform/fields/HTMLUsersMultiselectField.php b/includes/htmlform/fields/HTMLUsersMultiselectField.php index 53d1d06b23..286cb8d31d 100644 --- a/includes/htmlform/fields/HTMLUsersMultiselectField.php +++ b/includes/htmlform/fields/HTMLUsersMultiselectField.php @@ -15,18 +15,16 @@ use MediaWiki\Widget\UsersMultiselectWidget; * @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 @@ class HTMLUsersMultiselectField extends HTMLUserTextField { 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 @@ class HTMLUsersMultiselectField extends HTMLUserTextField { 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 @@ class HTMLUsersMultiselectField extends HTMLUserTextField { ->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