X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiOptions.php;h=c4de31f581e1ccddf83534604069cb73780096ca;hb=8c30c3704fa144f6d09cd27b127cef507d59d753;hp=fe7d10dde267576bdb2496266ce7c0f9a6c697de;hpb=8c96aec32cffaab96b2bd9dca206a99a13640545;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiOptions.php b/includes/api/ApiOptions.php index fe7d10dde2..c4de31f581 100644 --- a/includes/api/ApiOptions.php +++ b/includes/api/ApiOptions.php @@ -52,9 +52,9 @@ class ApiOptions extends ApiBase { $this->dieWithError( [ 'apierror-missingparam', 'optionname' ] ); } - if ( $params['reset'] ) { - $this->resetPreferences( $params['resetkinds'] ); - $changed = true; + $resetKinds = $params['resetkinds']; + if ( !$params['reset'] ) { + $resetKinds = []; } $changes = []; @@ -68,6 +68,14 @@ class ApiOptions extends ApiBase { $newValue = $params['optionvalue'] ?? null; $changes[$params['optionname']] = $newValue; } + + Hooks::run( 'ApiOptions', [ $this, $user, $changes, $resetKinds ] ); + + if ( $resetKinds ) { + $this->resetPreferences( $resetKinds ); + $changed = true; + } + if ( !$changed && !count( $changes ) ) { $this->dieWithError( 'apierror-nochanges' ); } @@ -80,12 +88,18 @@ class ApiOptions extends ApiBase { switch ( $prefsKinds[$key] ) { case 'registered': // Regular option. - if ( $htmlForm === null ) { - // We need a dummy HTMLForm for the validate callback... - $htmlForm = new HTMLForm( [], $this ); + if ( $value === null ) { + // Reset it + $validation = true; + } else { + // Validate + if ( $htmlForm === null ) { + // We need a dummy HTMLForm for the validate callback... + $htmlForm = new HTMLForm( [], $this ); + } + $field = HTMLForm::loadInputFromParameters( $key, $prefs[$key], $htmlForm ); + $validation = $field->validate( $value, $user->getOptions() ); } - $field = HTMLForm::loadInputFromParameters( $key, $prefs[$key], $htmlForm ); - $validation = $field->validate( $value, $user->getOptions() ); break; case 'registered-multiselect': case 'registered-checkmatrix':