Merge "Add way of including all stderr output when executing command"
[lhc/web/wiklou.git] / includes / User.php
index 25b35b3..12912e1 100644 (file)
@@ -1489,12 +1489,13 @@ class User {
         * last-hit counters will be shared across wikis.
         *
         * @param string $action Action to enforce; 'edit' if unspecified
+        * @param integer $incrBy Positive amount to increment counter by [defaults to 1]
         * @return bool True if a rate limiter was tripped
         */
-       public function pingLimiter( $action = 'edit' ) {
+       public function pingLimiter( $action = 'edit', $incrBy = 1 ) {
                // Call the 'PingLimiter' hook
                $result = false;
-               if ( !wfRunHooks( 'PingLimiter', array( &$this, $action, &$result ) ) ) {
+               if ( !wfRunHooks( 'PingLimiter', array( &$this, $action, &$result, $incrBy ) ) ) {
                        return $result;
                }
 
@@ -1583,9 +1584,13 @@ class User {
                                }
                        } else {
                                wfDebug( __METHOD__ . ": adding record for $key $summary\n" );
-                               $wgMemc->add( $key, 0, intval( $period ) ); // first ping
+                               if ( $incrBy > 0 ) {
+                                       $wgMemc->add( $key, 0, intval( $period ) ); // first ping
+                               }
+                       }
+                       if ( $incrBy > 0 ) {
+                               $wgMemc->incr( $key, $incrBy );
                        }
-                       $wgMemc->incr( $key );
                }
 
                wfProfileOut( __METHOD__ );
@@ -1700,6 +1705,7 @@ class User {
                        return $this->mLocked;
                }
                global $wgAuth;
+               StubObject::unstub( $wgAuth );
                $authUser = $wgAuth->getUserInstance( $this );
                $this->mLocked = (bool)$authUser->isLocked();
                return $this->mLocked;
@@ -1717,6 +1723,7 @@ class User {
                $this->getBlockedStatus();
                if ( !$this->mHideName ) {
                        global $wgAuth;
+                       StubObject::unstub( $wgAuth );
                        $authUser = $wgAuth->getUserInstance( $this );
                        $this->mHideName = (bool)$authUser->isHidden();
                }
@@ -2763,7 +2770,7 @@ class User {
                        $this->mEditCount = $count;
                        wfProfileOut( __METHOD__ );
                }
-               return (int) $this->mEditCount;
+               return (int)$this->mEditCount;
        }
 
        /**
@@ -3134,19 +3141,24 @@ class User {
         *  true: Force setting the secure attribute when setting the cookie
         *  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()
         */
-       protected function setCookie( $name, $value, $exp = 0, $secure = null ) {
-               $this->getRequest()->response()->setcookie( $name, $value, $exp, array(
-                       'secure' => $secure,
-               ) );
+       protected function setCookie( $name, $value, $exp = 0, $secure = null, $params = array() ) {
+               $params['secure'] = $secure;
+               $this->getRequest()->response()->setcookie( $name, $value, $exp, $params );
        }
 
        /**
         * Clear a cookie on the user's client
         * @param string $name Name of the cookie to clear
+        * @param bool $secure
+        *  true: Force setting the secure attribute when setting the cookie
+        *  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()
         */
-       protected function clearCookie( $name ) {
-               $this->setCookie( $name, '', time() - 86400 );
+       protected function clearCookie( $name, $secure = null, $params = array() ) {
+               $this->setCookie( $name, '', time() - 86400, $secure, $params );
        }
 
        /**
@@ -3204,10 +3216,22 @@ class User {
                /**
                 * If wpStickHTTPS was selected, also set an insecure cookie that
                 * will cause the site to redirect the user to HTTPS, if they access
-                * it over HTTP. Bug 29898.
+                * it over HTTP. Bug 29898. Use an un-prefixed cookie, so it's the same
+                * as the one set by centralauth (bug 53538). Also set it to session, or
+                * standard time setting, based on if rememberme was set.
                 */
                if ( $request->getCheck( 'wpStickHTTPS' ) || $this->requiresHTTPS() ) {
-                       $this->setCookie( 'forceHTTPS', 'true', time() + 2592000, false ); //30 days
+                       $time = null;
+                       if ( ( 1 == $this->getOption( 'rememberpassword' ) ) ) {
+                               $time = 0; // set to $wgCookieExpiration
+                       }
+                       $this->setCookie(
+                               'forceHTTPS',
+                               'true',
+                               $time,
+                               false,
+                               array( 'prefix' => '' ) // no prefix
+                       );
                }
        }
 
@@ -3231,7 +3255,7 @@ class User {
 
                $this->clearCookie( 'UserID' );
                $this->clearCookie( 'Token' );
-               $this->clearCookie( 'forceHTTPS' );
+               $this->clearCookie( 'forceHTTPS', false, array( 'prefix' => '' ) );
 
                // Remember when user logged out, to prevent seeing cached pages
                $this->setCookie( 'LoggedOut', time(), time() + 86400 );
@@ -3759,8 +3783,7 @@ class User {
                } elseif ( $type === true ) {
                        $message = 'confirmemail_body_changed';
                } else {
-                       // Give grep a chance to find the usages:
-                       // confirmemail_body_changed, confirmemail_body_set
+                       // Messages: confirmemail_body_changed, confirmemail_body_set
                        $message = 'confirmemail_body_' . $type;
                }
 
@@ -4383,7 +4406,7 @@ class User {
                // Pull from a slave to be less cruel to servers
                // Accuracy isn't the point anyway here
                $dbr = wfGetDB( DB_SLAVE );
-               $count = (int) $dbr->selectField(
+               $count = (int)$dbr->selectField(
                        'revision',
                        'COUNT(rev_user)',
                        array( 'rev_user' => $this->getId() ),