Load User via READ_LATEST in ApiOptions to avoid CAS errors
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 26 Aug 2015 00:27:46 +0000 (17:27 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 26 Aug 2015 20:48:49 +0000 (13:48 -0700)
Bug: T95839
Change-Id: I3c4cf4347af24f3313e709a996618b755da22dd2

includes/api/ApiOptions.php

index 436f22a..a62bcb6 100644 (file)
@@ -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;