Use the request object provided in User::setCookies
authorErik Bernhardson <ebernhardson@wikimedia.org>
Wed, 3 Dec 2014 22:45:26 +0000 (14:45 -0800)
committerErik Bernhardson <ebernhardson@wikimedia.org>
Wed, 3 Dec 2014 22:47:44 +0000 (14:47 -0800)
When calling User::setCookies with a $request object that was not
passed on to the User::setCookie method, which went ahead and
updated the request from RequestContext::getMain rather than
the provided request.

This patch adds another parameter to User::setCookie to accept
a request object, and User::setCookies to pass the request along.

Change-Id: Ie46fd8c90753e8bf54ce58842c08e0519a269582

includes/User.php

index c4a6127..084befe 100644 (file)
@@ -3362,10 +3362,15 @@ class User implements IDBAccessObject {
         *  false: Force NOT setting the secure attribute when setting the cookie
         *  null (default): Use the default ($wgCookieSecure) to set the secure attribute
         * @param array $params Array of options sent passed to WebResponse::setcookie()
+        * @param WebRequest|null $request WebRequest object to use; $wgRequest will be used if null
+        *        is passed.
         */
-       protected function setCookie( $name, $value, $exp = 0, $secure = null, $params = array() ) {
+       protected function setCookie( $name, $value, $exp = 0, $secure = null, $params = array(), $request = null ) {
+               if ( $request === null ) {
+                       $request = $this->getRequest();
+               }
                $params['secure'] = $secure;
-               $this->getRequest()->response()->setcookie( $name, $value, $exp, $params );
+               $request->response()->setcookie( $name, $value, $exp, $params );
        }
 
        /**
@@ -3430,7 +3435,7 @@ class User implements IDBAccessObject {
                        if ( $value === false ) {
                                $this->clearCookie( $name );
                        } else {
-                               $this->setCookie( $name, $value, 0, $secure );
+                               $this->setCookie( $name, $value, 0, $secure, array(), $request );
                        }
                }