X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiOptions.php;h=5b0d86a7f647ad986cec4dfdbb11a0746a299164;hb=036b9c41674a8eb1bdcd71a15fffb5a091223d9e;hp=8bfe447df59c4e5a3abf6eb4bbc235596a025642;hpb=1dd2e07276e1deaf431ddb01c92111038f9e2cd6;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiOptions.php b/includes/api/ApiOptions.php index 8bfe447df5..5b0d86a7f6 100644 --- a/includes/api/ApiOptions.php +++ b/includes/api/ApiOptions.php @@ -36,22 +36,26 @@ class ApiOptions extends ApiBase { */ public function execute() { if ( $this->getUser()->isAnon() ) { - $this->dieUsage( 'Anonymous users cannot change preferences', 'notloggedin' ); - } elseif ( !$this->getUser()->isAllowed( 'editmyoptions' ) ) { - $this->dieUsage( "You don't have permission to edit your options", 'permissiondenied' ); + $this->dieWithError( + [ 'apierror-mustbeloggedin', $this->msg( 'action-editmyoptions' ) ], 'notloggedin' + ); } + $this->checkUserRightsAny( 'editmyoptions' ); + $params = $this->extractRequestParams(); $changed = false; if ( isset( $params['optionvalue'] ) && !isset( $params['optionname'] ) ) { - $this->dieUsageMsg( [ 'missingparam', 'optionname' ] ); + $this->dieWithError( [ 'apierror-missingparam', 'optionname' ] ); } // Load the user from the master to reduce CAS errors on double post (T95839) $user = $this->getUser()->getInstanceForUpdate(); if ( !$user ) { - $this->dieUsage( 'Anonymous users cannot change preferences', 'notloggedin' ); + $this->dieWithError( + [ 'apierror-mustbeloggedin', $this->msg( 'action-editmyoptions' ) ], 'notloggedin' + ); } if ( $params['reset'] ) { @@ -71,7 +75,7 @@ class ApiOptions extends ApiBase { $changes[$params['optionname']] = $newValue; } if ( !$changed && !count( $changes ) ) { - $this->dieUsage( 'No changes were requested', 'nochanges' ); + $this->dieWithError( 'apierror-nochanges' ); } $prefs = Preferences::getPreferences( $user, $this->getContext() ); @@ -98,26 +102,26 @@ class ApiOptions extends ApiBase { case 'userjs': // Allow non-default preferences prefixed with 'userjs-', to be set by user scripts if ( strlen( $key ) > 255 ) { - $validation = 'key too long (no more than 255 bytes allowed)'; + $validation = $this->msg( 'apiwarn-validationfailed-keytoolong', Message::numParam( 255 ) ); } elseif ( preg_match( '/[^a-zA-Z0-9_-]/', $key ) !== 0 ) { - $validation = 'invalid key (only a-z, A-Z, 0-9, _, - allowed)'; + $validation = $this->msg( 'apiwarn-validationfailed-badchars' ); } else { $validation = true; } break; case 'special': - $validation = 'cannot be set by this module'; + $validation = $this->msg( 'apiwarn-validationfailed-cannotset' ); break; case 'unused': default: - $validation = 'not a valid preference'; + $validation = $this->msg( 'apiwarn-validationfailed-badpref' ); break; } if ( $validation === true ) { $user->setOption( $key, $value ); $changed = true; } else { - $this->setWarning( "Validation error for '$key': $validation" ); + $this->addWarning( [ 'apiwarn-validationfailed', wfEscapeWikitext( $key ), $validation ] ); } } @@ -165,7 +169,7 @@ class ApiOptions extends ApiBase { } public function getHelpUrls() { - return 'https://www.mediawiki.org/wiki/API:Options'; + return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Options'; } protected function getExamplesMessages() {