X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiOptions.php;h=01a376073f38b7e3d94b8832d00c439f38bbeae9;hb=9b9daadc46b3456dd9b9120e4aeb98e2ae38f26a;hp=265c2ccb674cd4473c42c0157fa09bf87c17b63c;hpb=7869ebbc249d478288caa1c0a858abdd5f699b76;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiOptions.php b/includes/api/ApiOptions.php index 265c2ccb67..01a376073f 100644 --- a/includes/api/ApiOptions.php +++ b/includes/api/ApiOptions.php @@ -74,13 +74,36 @@ class ApiOptions extends ApiBase { } $prefs = Preferences::getPreferences( $user, $this->getContext() ); + + // Multiselect options are stored in the database with one key per + // option, each having a boolean value. Extract those keys. + $multiselectOptions = array(); + foreach ( $prefs as $name => $info ) { + if ( ( isset( $info['type'] ) && $info['type'] == 'multiselect' ) || + ( isset( $info['class'] ) && $info['class'] == 'HTMLMultiSelectField' ) ) { + $options = HTMLFormField::flattenOptions( $info['options'] ); + $prefix = isset( $info['prefix'] ) ? $info['prefix'] : $name; + + foreach ( $options as $value ) { + $multiselectOptions["$prefix$value"] = true; + } + + unset( $prefs[$name] ); + } + } + foreach ( $changes as $key => $value ) { - if ( !isset( $prefs[$key] ) ) { + if ( isset( $prefs[$key] ) ) { + $field = HTMLForm::loadInputFromParameters( $key, $prefs[$key] ); + $validation = $field->validate( $value, $user->getOptions() ); + } elseif( isset( $multiselectOptions[$key] ) ) { + // A key for a multiselect option. + $validation = true; + $value = (bool)$value; + } else { $this->setWarning( "Not a valid preference: $key" ); continue; } - $field = HTMLForm::loadInputFromParameters( $key, $prefs[$key] ); - $validation = $field->validate( $value, $user->getOptions() ); if ( $validation === true ) { $user->setOption( $key, $value ); $changed = true;