Lewis Cawte has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/233109

Change subject: Make Special:ConfirmEmail load the user from the master
......................................................................

Make Special:ConfirmEmail load the user from the master

* This can help guard against stale reads if the user was
  created or changed a second ago.

Bug: T105896
Change-Id: Ib2a59762cd8f4a4b7ad86d0700f186bee1d5b2d1
(cherry picked from commit 3f24d1e348f23f331ad0a85d2e83876830e83df6)
---
M includes/User.php
M includes/specials/SpecialConfirmemail.php
2 files changed, 18 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/09/233109/1

diff --git a/includes/User.php b/includes/User.php
index 8ea491c..663a80b 100644
--- a/includes/User.php
+++ b/includes/User.php
@@ -526,19 +526,24 @@
         * If the code is invalid or has expired, returns NULL.
         *
         * @param string $code Confirmation code
+        * @param int $flags User::READ_* bitfield
         * @return User|null
         */
-       public static function newFromConfirmationCode( $code ) {
-               $dbr = wfGetDB( DB_SLAVE );
-               $id = $dbr->selectField( 'user', 'user_id', array(
-                       'user_email_token' => md5( $code ),
-                       'user_email_token_expires > ' . $dbr->addQuotes( 
$dbr->timestamp() ),
-                       ) );
-               if ( $id !== false ) {
-                       return User::newFromId( $id );
-               } else {
-                       return null;
-               }
+       public static function newFromConfirmationCode( $code, $flags = 0 ) {
+               $db = ( $flags & self::READ_LATEST ) == self::READ_LATEST
+                       ? wfGetDB( DB_MASTER )
+                       : wfGetDB( DB_SLAVE );
+
+               $id = $db->selectField(
+                       'user',
+                       'user_id',
+                       array(
+                               'user_email_token' => md5( $code ),
+                               'user_email_token_expires > ' . $db->addQuotes( 
$db->timestamp() ),
+                       )
+               );
+
+               return $id ? User::newFromId( $id ) : null;
        }
 
        /**
diff --git a/includes/specials/SpecialConfirmemail.php 
b/includes/specials/SpecialConfirmemail.php
index b6ab112..6356155 100644
--- a/includes/specials/SpecialConfirmemail.php
+++ b/includes/specials/SpecialConfirmemail.php
@@ -120,7 +120,7 @@
         * @param string $code Confirmation code
         */
        function attemptConfirm( $code ) {
-               $user = User::newFromConfirmationCode( $code );
+               $user = User::newFromConfirmationCode( $code, User::READ_LATEST 
);
                if ( !is_object( $user ) ) {
                        $this->getOutput()->addWikiMsg( 'confirmemail_invalid' 
);
 
@@ -164,7 +164,7 @@
         * @param string $code Confirmation code
         */
        function attemptInvalidate( $code ) {
-               $user = User::newFromConfirmationCode( $code );
+               $user = User::newFromConfirmationCode( $code, User::READ_LATEST 
);
                if ( !is_object( $user ) ) {
                        $this->getOutput()->addWikiMsg( 'confirmemail_invalid' 
);
 

-- 
To view, visit https://gerrit.wikimedia.org/r/233109
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib2a59762cd8f4a4b7ad86d0700f186bee1d5b2d1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: REL1_25
Gerrit-Owner: Lewis Cawte <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to