Index: trunk/phase3/includes/User.php |
— | — | @@ -202,9 +202,9 @@ |
203 | 203 | $mLocked, $mHideName, $mOptions; |
204 | 204 | |
205 | 205 | /** |
206 | | - * @var Skin |
| 206 | + * @var WebRequest |
207 | 207 | */ |
208 | | - var $mSkin; |
| 208 | + private $mRequest; |
209 | 209 | |
210 | 210 | /** |
211 | 211 | * @var Block |
— | — | @@ -407,11 +407,14 @@ |
408 | 408 | * Create a new user object using data from session or cookies. If the |
409 | 409 | * login credentials are invalid, the result is an anonymous user. |
410 | 410 | * |
| 411 | + * @param $request WebRequest object to use; $wgRequest will be used if |
| 412 | + * ommited. |
411 | 413 | * @return User |
412 | 414 | */ |
413 | | - static function newFromSession() { |
| 415 | + static function newFromSession( WebRequest $request = null ) { |
414 | 416 | $user = new User; |
415 | 417 | $user->mFrom = 'session'; |
| 418 | + $user->mRequest = $request; |
416 | 419 | return $user; |
417 | 420 | } |
418 | 421 | |
— | — | @@ -851,8 +854,6 @@ |
852 | 855 | function loadDefaults( $name = false ) { |
853 | 856 | wfProfileIn( __METHOD__ ); |
854 | 857 | |
855 | | - global $wgRequest; |
856 | | - |
857 | 858 | $this->mId = 0; |
858 | 859 | $this->mName = $name; |
859 | 860 | $this->mRealName = ''; |
— | — | @@ -862,8 +863,9 @@ |
863 | 864 | $this->mOptionOverrides = null; |
864 | 865 | $this->mOptionsLoaded = false; |
865 | 866 | |
866 | | - if( $wgRequest->getCookie( 'LoggedOut' ) !== null ) { |
867 | | - $this->mTouched = wfTimestamp( TS_MW, $wgRequest->getCookie( 'LoggedOut' ) ); |
| 867 | + $loggedOut = $this->getRequest()->getCookie( 'LoggedOut' ); |
| 868 | + if( $loggedOut !== null ) { |
| 869 | + $this->mTouched = wfTimestamp( TS_MW, $loggedOut ); |
868 | 870 | } else { |
869 | 871 | $this->mTouched = '0'; # Allow any pages to be cached |
870 | 872 | } |
— | — | @@ -914,7 +916,7 @@ |
915 | 917 | * @return Bool True if the user is logged in, false otherwise. |
916 | 918 | */ |
917 | 919 | private function loadFromSession() { |
918 | | - global $wgRequest, $wgExternalAuthType, $wgAutocreatePolicy; |
| 920 | + global $wgExternalAuthType, $wgAutocreatePolicy; |
919 | 921 | |
920 | 922 | $result = null; |
921 | 923 | wfRunHooks( 'UserLoadFromSession', array( $this, &$result ) ); |
— | — | @@ -930,9 +932,11 @@ |
931 | 933 | } |
932 | 934 | } |
933 | 935 | |
934 | | - $cookieId = $wgRequest->getCookie( 'UserID' ); |
935 | | - $sessId = $wgRequest->getSessionData( 'wsUserID' ); |
| 936 | + $request = $this->getRequest(); |
936 | 937 | |
| 938 | + $cookieId = $request->getCookie( 'UserID' ); |
| 939 | + $sessId = $request->getSessionData( 'wsUserID' ); |
| 940 | + |
937 | 941 | if ( $cookieId !== null ) { |
938 | 942 | $sId = intval( $cookieId ); |
939 | 943 | if( $sessId !== null && $cookieId != $sessId ) { |
— | — | @@ -941,7 +945,7 @@ |
942 | 946 | cookie user ID ($sId) don't match!" ); |
943 | 947 | return false; |
944 | 948 | } |
945 | | - $wgRequest->setSessionData( 'wsUserID', $sId ); |
| 949 | + $request->setSessionData( 'wsUserID', $sId ); |
946 | 950 | } elseif ( $sessId !== null && $sessId != 0 ) { |
947 | 951 | $sId = $sessId; |
948 | 952 | } else { |
— | — | @@ -949,11 +953,11 @@ |
950 | 954 | return false; |
951 | 955 | } |
952 | 956 | |
953 | | - if ( $wgRequest->getSessionData( 'wsUserName' ) !== null ) { |
954 | | - $sName = $wgRequest->getSessionData( 'wsUserName' ); |
955 | | - } elseif ( $wgRequest->getCookie( 'UserName' ) !== null ) { |
956 | | - $sName = $wgRequest->getCookie( 'UserName' ); |
957 | | - $wgRequest->setSessionData( 'wsUserName', $sName ); |
| 957 | + if ( $request->getSessionData( 'wsUserName' ) !== null ) { |
| 958 | + $sName = $request->getSessionData( 'wsUserName' ); |
| 959 | + } elseif ( $request->getCookie( 'UserName' ) !== null ) { |
| 960 | + $sName = $request->getCookie( 'UserName' ); |
| 961 | + $request->setSessionData( 'wsUserName', $sName ); |
958 | 962 | } else { |
959 | 963 | $this->loadDefaults(); |
960 | 964 | return false; |
— | — | @@ -973,11 +977,11 @@ |
974 | 978 | return false; |
975 | 979 | } |
976 | 980 | |
977 | | - if ( $wgRequest->getSessionData( 'wsToken' ) !== null ) { |
978 | | - $passwordCorrect = $proposedUser->getToken() === $wgRequest->getSessionData( 'wsToken' ); |
| 981 | + if ( $request->getSessionData( 'wsToken' ) !== null ) { |
| 982 | + $passwordCorrect = $proposedUser->getToken() === $request->getSessionData( 'wsToken' ); |
979 | 983 | $from = 'session'; |
980 | | - } elseif ( $wgRequest->getCookie( 'Token' ) !== null ) { |
981 | | - $passwordCorrect = $proposedUser->getToken() === $wgRequest->getCookie( 'Token' ); |
| 984 | + } elseif ( $request->getCookie( 'Token' ) !== null ) { |
| 985 | + $passwordCorrect = $proposedUser->getToken() === $request->getCookie( 'Token' ); |
982 | 986 | $from = 'cookie'; |
983 | 987 | } else { |
984 | 988 | # No session or persistent login cookie |
— | — | @@ -987,7 +991,7 @@ |
988 | 992 | |
989 | 993 | if ( ( $sName === $proposedUser->getName() ) && $passwordCorrect ) { |
990 | 994 | $this->loadFromUserObject( $proposedUser ); |
991 | | - $wgRequest->setSessionData( 'wsToken', $this->mToken ); |
| 995 | + $request->setSessionData( 'wsToken', $this->mToken ); |
992 | 996 | wfDebug( "User: logged in from $from\n" ); |
993 | 997 | return true; |
994 | 998 | } else { |
— | — | @@ -1166,7 +1170,6 @@ |
1167 | 1171 | $this->mDatePreference = null; |
1168 | 1172 | $this->mBlockedby = -1; # Unset |
1169 | 1173 | $this->mHash = false; |
1170 | | - $this->mSkin = null; |
1171 | 1174 | $this->mRights = null; |
1172 | 1175 | $this->mEffectiveGroups = null; |
1173 | 1176 | $this->mOptions = null; |
— | — | @@ -2183,11 +2186,6 @@ |
2184 | 2187 | $this->load(); |
2185 | 2188 | $this->loadOptions(); |
2186 | 2189 | |
2187 | | - if ( $oname == 'skin' ) { |
2188 | | - # Clear cached skin, so the new one displays immediately in Special:Preferences |
2189 | | - $this->mSkin = null; |
2190 | | - } |
2191 | | - |
2192 | 2190 | // Explicitly NULL values should refer to defaults |
2193 | 2191 | global $wgDefaultUserOptions; |
2194 | 2192 | if( is_null( $val ) && isset( $wgDefaultUserOptions[$oname] ) ) { |
— | — | @@ -2468,6 +2466,20 @@ |
2469 | 2467 | } |
2470 | 2468 | |
2471 | 2469 | /** |
| 2470 | + * Get the WebRequest object to use with this object |
| 2471 | + * |
| 2472 | + * @return WebRequest |
| 2473 | + */ |
| 2474 | + public function getRequest() { |
| 2475 | + if ( $this->mRequest ) { |
| 2476 | + return $this->mRequest; |
| 2477 | + } else { |
| 2478 | + global $wgRequest; |
| 2479 | + return $wgRequest; |
| 2480 | + } |
| 2481 | + } |
| 2482 | + |
| 2483 | + /** |
2472 | 2484 | * Get the current skin, loading it if required |
2473 | 2485 | * @return Skin The current skin |
2474 | 2486 | * @todo FIXME: Need to check the old failback system [AV] |
— | — | @@ -2625,8 +2637,7 @@ |
2626 | 2638 | * if 0 or not specified, use the default $wgCookieExpiration |
2627 | 2639 | */ |
2628 | 2640 | protected function setCookie( $name, $value, $exp = 0 ) { |
2629 | | - global $wgRequest; |
2630 | | - $wgRequest->response()->setcookie( $name, $value, $exp ); |
| 2641 | + $this->getRequest()->response()->setcookie( $name, $value, $exp ); |
2631 | 2642 | } |
2632 | 2643 | |
2633 | 2644 | /** |
— | — | @@ -2645,8 +2656,7 @@ |
2646 | 2657 | */ |
2647 | 2658 | function setCookies( $request = null ) { |
2648 | 2659 | if ( $request === null ) { |
2649 | | - global $wgRequest; |
2650 | | - $request = $wgRequest; |
| 2660 | + $request = $this->getRequest(); |
2651 | 2661 | } |
2652 | 2662 | |
2653 | 2663 | $this->load(); |
— | — | @@ -2695,11 +2705,9 @@ |
2696 | 2706 | * @see logout() |
2697 | 2707 | */ |
2698 | 2708 | function doLogout() { |
2699 | | - global $wgRequest; |
2700 | | - |
2701 | 2709 | $this->clearInstanceCache( 'defaults' ); |
2702 | 2710 | |
2703 | | - $wgRequest->setSessionData( 'wsUserID', 0 ); |
| 2711 | + $this->getRequest()->setSessionData( 'wsUserID', 0 ); |
2704 | 2712 | |
2705 | 2713 | $this->clearCookie( 'UserID' ); |
2706 | 2714 | $this->clearCookie( 'Token' ); |
— | — | @@ -3056,8 +3064,7 @@ |
3057 | 3065 | */ |
3058 | 3066 | function editToken( $salt = '', $request = null ) { |
3059 | 3067 | if ( $request == null ) { |
3060 | | - global $wgRequest; |
3061 | | - $request = $wgRequest; |
| 3068 | + $request = $this->getRequest(); |
3062 | 3069 | } |
3063 | 3070 | |
3064 | 3071 | if ( $this->isAnon() ) { |
Index: trunk/phase3/includes/RequestContext.php |
— | — | @@ -120,10 +120,7 @@ |
121 | 121 | */ |
122 | 122 | public function getUser() { |
123 | 123 | if ( !isset($this->user) ) { |
124 | | - global $wgCommandLineMode; |
125 | | - $this->user = $wgCommandLineMode |
126 | | - ? new User |
127 | | - : User::newFromSession( $this->getRequest() ); |
| 124 | + $this->user = User::newFromSession( $this->getRequest() ); |
128 | 125 | } |
129 | 126 | return $this->user; |
130 | 127 | } |
— | — | @@ -347,4 +344,4 @@ |
348 | 345 | public function getSkin() { |
349 | 346 | return $this->context->getSkin(); |
350 | 347 | } |
351 | | -} |
\ No newline at end of file |
| 348 | +} |