From: Bartosz DziewoƄski Date: Wed, 18 Jul 2018 18:09:39 +0000 (+0200) Subject: HTMLMultiSelectField: Improve compat with GET forms with no wpFormIdentifier X-Git-Tag: 1.34.0-rc.0~4677^2~1 X-Git-Url: http://git.cyclocoop.org/data/%24oldEdit?a=commitdiff_plain;h=098fd0dcb34cca4a3d11059e0d6a7d4861124d98;p=lhc%2Fweb%2Fwiklou.git HTMLMultiSelectField: Improve compat with GET forms with no wpFormIdentifier Now it behaves more like HTMLCheckField: if there is clearly a value submitted, it will load it. Setting wpFormIdentifier is still needed for forms with default-on checkboxes (without form identifier, it is impossible to distinguish a page view without form submission, and form submission with default-on checkbox unchecked). In particular, this fixes the 'Show additional logs' checkboxes on Special:Log: they no longer get unchecked after form submission. Change-Id: Ief74a7e424b37ccd44759133b3cb8665275314a6 --- diff --git a/includes/htmlform/fields/HTMLCheckField.php b/includes/htmlform/fields/HTMLCheckField.php index 7523b5fe84..aad9f6e9d2 100644 --- a/includes/htmlform/fields/HTMLCheckField.php +++ b/includes/htmlform/fields/HTMLCheckField.php @@ -116,10 +116,9 @@ class HTMLCheckField extends HTMLFormField { public function loadDataFromRequest( $request ) { $invert = isset( $this->mParams['invert'] ) && $this->mParams['invert']; - // GetCheck won't work like we want for checks. // Fetch the value in either one of the two following case: - // - we have a valid submit attempt (form was just submitted, or a GET URL forged by the user) - // - checkbox name has a value (false or true), ie is not null + // - we have a valid submit attempt (form was just submitted) + // - we have a value (an URL manually built by the user, or GET form with no wpFormIdentifier) if ( $this->isSubmitAttempt( $request ) || $request->getVal( $this->mName ) !== null ) { return $invert ? !$request->getBool( $this->mName ) diff --git a/includes/htmlform/fields/HTMLMultiSelectField.php b/includes/htmlform/fields/HTMLMultiSelectField.php index 4b1bc552bb..2038606597 100644 --- a/includes/htmlform/fields/HTMLMultiSelectField.php +++ b/includes/htmlform/fields/HTMLMultiSelectField.php @@ -214,10 +214,14 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable * @return string|array */ public function loadDataFromRequest( $request ) { - if ( $this->isSubmitAttempt( $request ) ) { + $fromRequest = $request->getArray( $this->mName, [] ); + // Fetch the value in either one of the two following case: + // - we have a valid submit attempt (form was just submitted) + // - we have a value (an URL manually built by the user, or GET form with no wpFormIdentifier) + if ( $this->isSubmitAttempt( $request ) || $fromRequest ) { // Checkboxes are just not added to the request arrays if they're not checked, // so it's perfectly possible for there not to be an entry at all - return $request->getArray( $this->mName, [] ); + return $fromRequest; } else { // That's ok, the user has not yet submitted the form, so show the defaults return $this->getDefault();