diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2015-12-20 09:00:55 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2015-12-20 09:00:55 +0100 |
commit | a2190ac74dd4d7080b12bab90e552d7aa81209ef (patch) | |
tree | 8b31f38de9882d18df54cf8d9e0de74167a094eb /includes/api/ApiOptions.php | |
parent | 15e69f7b20b6596b9148030acce5b59993b95a45 (diff) | |
parent | 257401d8b2cf661adf36c84b0e3fd1cf85e33c22 (diff) |
Merge branch 'mw-1.26'
Diffstat (limited to 'includes/api/ApiOptions.php')
-rw-r--r-- | includes/api/ApiOptions.php | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/includes/api/ApiOptions.php b/includes/api/ApiOptions.php index 8ef06299..a62bcb6d 100644 --- a/includes/api/ApiOptions.php +++ b/includes/api/ApiOptions.php @@ -52,6 +52,14 @@ class ApiOptions extends ApiBase { $this->dieUsageMsg( array( '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_LATEST ) ) { + $this->dieUsage( 'Anonymous users cannot change preferences', 'notloggedin' ); + } + } + if ( $params['reset'] ) { $user->resetOptions( $params['resetkinds'], $this->getContext() ); $changed = true; @@ -75,11 +83,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': |