Added read-only checks around User::saveSettings where they belong
authorAaron Schulz <aschulz@wikimedia.org>
Mon, 30 Mar 2015 19:00:07 +0000 (12:00 -0700)
committerOri.livneh <ori@wikimedia.org>
Thu, 2 Apr 2015 18:12:37 +0000 (18:12 +0000)
* Ideally saveSettings() would not just silently do nothing in
  read-only mode as not all callers expect that behavior. This
  change is just the first step.

Change-Id: Ieeaf531dac3027ddba89c60159b98f9c04de78d3

includes/User.php
includes/specials/SpecialSearch.php
includes/specials/SpecialUserlogin.php

index 2e88978..322f8af 100644 (file)
@@ -2706,7 +2706,9 @@ class User implements IDBAccessObject {
                $token = $this->getOption( $oname );
                if ( !$token ) {
                        $token = $this->resetTokenFromOption( $oname );
-                       $this->saveSettings();
+                       if ( !wfReadOnly() ) {
+                               $this->saveSettings();
+                       }
                }
                return $token;
        }
@@ -3500,7 +3502,9 @@ class User implements IDBAccessObject {
                        // Simply by setting every cell in the user_token column to NULL and letting them be
                        // regenerated as users log back into the wiki.
                        $this->setToken();
-                       $this->saveSettings();
+                       if ( !wfReadOnly() ) {
+                               $this->saveSettings();
+                       }
                }
                $session = array(
                        'wsUserID' => $this->mId,
@@ -3581,11 +3585,12 @@ class User implements IDBAccessObject {
        public function saveSettings() {
                global $wgAuth;
 
-               $this->load();
-               $this->loadPasswords();
                if ( wfReadOnly() ) {
                        return; // @TODO: caller should deal with this instead!
                }
+
+               $this->load();
+               $this->loadPasswords();
                if ( 0 == $this->mId ) {
                        return;
                }
@@ -3939,7 +3944,7 @@ class User implements IDBAccessObject {
                }
 
                $passwordFactory = self::getPasswordFactory();
-               if ( $passwordFactory->needsUpdate( $this->mPassword ) ) {
+               if ( $passwordFactory->needsUpdate( $this->mPassword ) && !wfReadOnly() ) {
                        $this->mPassword = $passwordFactory->newFromPlaintext( $password );
                        $this->saveSettings();
                }
index 55be2c2..608d62e 100644 (file)
@@ -533,7 +533,7 @@ class SpecialSearch extends SpecialPage {
                                $request->getVal( 'nsRemember' ),
                                'searchnamespace',
                                $request
-                       )
+                       ) && !wfReadOnly()
                ) {
                        // Reset namespace preferences: namespaces are not searched
                        // when they're not mentioned in the URL parameters.
index d6634a8..10edbcf 100644 (file)
@@ -762,7 +762,7 @@ class LoginForm extends SpecialPage {
                                // As a side-effect, we can authenticate the user's e-mail ad-
                                // dress if it's not already done, since the temporary password
                                // was sent via e-mail.
-                               if ( !$u->isEmailConfirmed() ) {
+                               if ( !$u->isEmailConfirmed() && !wfReadOnly() ) {
                                        $u->confirmEmail();
                                        $u->saveSettings();
                                }