* Changes preferences of the current user.
*/
public function execute() {
- $user = $this->getUser();
-
- if ( $user->isAnon() ) {
+ if ( $this->getUser()->isAnon() ) {
$this->dieUsage( 'Anonymous users cannot change preferences', 'notloggedin' );
- }
-
- if ( !$user->isAllowed( 'editmyoptions' ) ) {
- $this->dieUsage( 'You don\'t have permission to edit your options', 'permissiondenied' );
+ } elseif ( !$this->getUser()->isAllowed( 'editmyoptions' ) ) {
+ $this->dieUsage( "You don't have permission to edit your options", 'permissiondenied' );
}
$params = $this->extractRequestParams();
$changed = false;
if ( isset( $params['optionvalue'] ) && !isset( $params['optionname'] ) ) {
- $this->dieUsageMsg( array( 'missingparam', 'optionname' ) );
+ $this->dieUsageMsg( [ 'missingparam', 'optionname' ] );
}
// Load the user from the master to reduce CAS errors on double post (T95839)
- if ( wfGetLB()->getServerCount() > 1 ) {
- $user = User::newFromId( $user->getId() );
- if ( !$user->loadFromId( User::READ_EXCLUSIVE ) ) {
- $this->dieUsage( 'Anonymous users cannot change preferences', 'notloggedin' );
- }
+ $user = $this->getUser()->getInstanceForUpdate();
+ if ( !$user ) {
+ $this->dieUsage( 'Anonymous users cannot change preferences', 'notloggedin' );
}
if ( $params['reset'] ) {
$changed = true;
}
- $changes = array();
+ $changes = [];
if ( count( $params['change'] ) ) {
foreach ( $params['change'] as $entry ) {
$array = explode( '=', $entry, 2 );
// Regular option.
if ( $htmlForm === null ) {
// We need a dummy HTMLForm for the validate callback...
- $htmlForm = new HTMLForm( array(), $this );
+ $htmlForm = new HTMLForm( [], $this );
}
$field = HTMLForm::loadInputFromParameters( $key, $prefs[$key] );
$field->mParent = $htmlForm;
$optionKinds = User::listOptionKinds();
$optionKinds[] = 'all';
- return array(
+ return [
'reset' => false,
- 'resetkinds' => array(
+ 'resetkinds' => [
ApiBase::PARAM_TYPE => $optionKinds,
ApiBase::PARAM_DFLT => 'all',
ApiBase::PARAM_ISMULTI => true
- ),
- 'change' => array(
+ ],
+ 'change' => [
ApiBase::PARAM_ISMULTI => true,
- ),
- 'optionname' => array(
+ ],
+ 'optionname' => [
ApiBase::PARAM_TYPE => 'string',
- ),
- 'optionvalue' => array(
+ ],
+ 'optionvalue' => [
ApiBase::PARAM_TYPE => 'string',
- ),
- );
+ ],
+ ];
}
public function needsToken() {
}
protected function getExamplesMessages() {
- return array(
+ return [
'action=options&reset=&token=123ABC'
=> 'apihelp-options-example-reset',
'action=options&change=skin=vector|hideminor=1&token=123ABC'
'action=options&reset=&change=skin=monobook&optionname=nickname&' .
'optionvalue=[[User:Beau|Beau]]%20([[User_talk:Beau|talk]])&token=123ABC'
=> 'apihelp-options-example-complex',
- );
+ ];
}
}