Merge "Fix form submission on Special:RandomInCategory"
[lhc/web/wiklou.git] / includes / User.php
index 72f66f0..25b35b3 100644 (file)
@@ -2599,6 +2599,26 @@ class User {
                return $this->mDatePreference;
        }
 
+       /**
+        * Determine based on the wiki configuration and the user's options,
+        * whether this user must be over HTTPS no matter what.
+        *
+        * @return bool
+        */
+       public function requiresHTTPS() {
+               global $wgSecureLogin;
+               if ( !$wgSecureLogin ) {
+                       return false;
+               } else {
+                       $https = $this->getBoolOption( 'prefershttps' );
+                       wfRunHooks( 'UserRequiresHTTPS', array( $this, &$https ) );
+                       if ( $https ) {
+                               $https = wfCanIPUseHTTPS( $this->getRequest()->getIP() );
+                       }
+                       return $https;
+               }
+       }
+
        /**
         * Get the user preferred stub threshold
         *
@@ -3186,7 +3206,7 @@ class User {
                 * will cause the site to redirect the user to HTTPS, if they access
                 * it over HTTP. Bug 29898.
                 */
-               if ( $request->getCheck( 'wpStickHTTPS' ) ) {
+               if ( $request->getCheck( 'wpStickHTTPS' ) || $this->requiresHTTPS() ) {
                        $this->setCookie( 'forceHTTPS', 'true', time() + 2592000, false ); //30 days
                }
        }