X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiOptions.php;h=436f22aee5d285d2ffaa5e31103c6f12189615d1;hb=4e90d55fdc9d31d93e24cf05687eb7d180806f44;hp=b01dc3e2397e60a17f6fbf35a39454b1cdda5554;hpb=793d0cec58cbd738d4c4682db3a856f24de11c47;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiOptions.php b/includes/api/ApiOptions.php index b01dc3e239..436f22aee5 100644 --- a/includes/api/ApiOptions.php +++ b/includes/api/ApiOptions.php @@ -75,11 +75,17 @@ class ApiOptions extends ApiBase { $prefs = Preferences::getPreferences( $user, $this->getContext() ); $prefsKinds = $user->getOptionKinds( $this->getContext(), $changes ); + $htmlForm = null; foreach ( $changes as $key => $value ) { switch ( $prefsKinds[$key] ) { case 'registered': // Regular option. + if ( $htmlForm === null ) { + // We need a dummy HTMLForm for the validate callback... + $htmlForm = new HTMLForm( array(), $this ); + } $field = HTMLForm::loadInputFromParameters( $key, $prefs[$key] ); + $field->mParent = $htmlForm; $validation = $field->validate( $value, $user->getOptions() ); break; case 'registered-multiselect': @@ -153,30 +159,6 @@ class ApiOptions extends ApiBase { ); } - public function getParamDescription() { - return array( - 'reset' => 'Resets preferences to the site defaults', - 'resetkinds' => 'List of types of options to reset when the "reset" option is set', - 'change' => array( 'List of changes, formatted name=value (e.g. skin=vector), ' . - 'value cannot contain pipe characters. If no value is given (not ', - 'even an equals sign), e.g., optionname|otheroption|..., the ' . - 'option will be reset to its default value' - ), - 'optionname' => 'A name of a option which should have an optionvalue set', - 'optionvalue' => 'A value of the option specified by the optionname, ' . - 'can contain pipe characters', - ); - } - - public function getDescription() { - return array( - 'Change preferences of the current user.', - 'Only options which are registered in core or in one of installed extensions,', - 'or as options with keys prefixed with \'userjs-\' (intended to be used by user', - 'scripts), can be set.' - ); - } - public function needsToken() { return 'csrf'; } @@ -185,12 +167,15 @@ class ApiOptions extends ApiBase { return 'https://www.mediawiki.org/wiki/API:Options'; } - public function getExamples() { + protected function getExamplesMessages() { return array( - 'api.php?action=options&reset=&token=123ABC', - 'api.php?action=options&change=skin=vector|hideminor=1&token=123ABC', - 'api.php?action=options&reset=&change=skin=monobook&optionname=nickname&' . - 'optionvalue=[[User:Beau|Beau]]%20([[User_talk:Beau|talk]])&token=123ABC', + 'action=options&reset=&token=123ABC' + => 'apihelp-options-example-reset', + 'action=options&change=skin=vector|hideminor=1&token=123ABC' + => 'apihelp-options-example-change', + 'action=options&reset=&change=skin=monobook&optionname=nickname&' . + 'optionvalue=[[User:Beau|Beau]]%20([[User_talk:Beau|talk]])&token=123ABC' + => 'apihelp-options-example-complex', ); } }