Index: trunk/phase3/tests/phpunit/includes/WebRequestTest.php |
— | — | @@ -85,4 +85,102 @@ |
86 | 86 | ), |
87 | 87 | ); |
88 | 88 | } |
| 89 | + |
| 90 | + /** |
| 91 | + * @dataProvider provideGetIP |
| 92 | + */ |
| 93 | + function testGetIP( $expected, $input, $squid, $private, $description ) { |
| 94 | + global $wgSquidServersNoPurge, $wgUsePrivateIPs; |
| 95 | + $oldServer = $_SERVER; |
| 96 | + $_SERVER = $input; |
| 97 | + $wgSquidServersNoPurge = $squid; |
| 98 | + $wgUsePrivateIPs = $private; |
| 99 | + $request = new WebRequest(); |
| 100 | + $result = $request->getIP(); |
| 101 | + $_SERVER = $oldServer; |
| 102 | + $this->assertEquals( $expected, $result, $description ); |
| 103 | + } |
| 104 | + |
| 105 | + function provideGetIP() { |
| 106 | + return array( |
| 107 | + array( |
| 108 | + '127.0.0.1', |
| 109 | + array( |
| 110 | + 'REMOTE_ADDR' => '127.0.0.1' |
| 111 | + ), |
| 112 | + array(), |
| 113 | + false, |
| 114 | + 'Simple IPv4' |
| 115 | + ), |
| 116 | + array( |
| 117 | + '::1', |
| 118 | + array( |
| 119 | + 'REMOTE_ADDR' => '::1' |
| 120 | + ), |
| 121 | + array(), |
| 122 | + false, |
| 123 | + 'Simple IPv6' |
| 124 | + ), |
| 125 | + array( |
| 126 | + '12.0.0.3', |
| 127 | + array( |
| 128 | + 'REMOTE_ADDR' => '12.0.0.1', |
| 129 | + 'HTTP_X_FORWARDED_FOR' => '12.0.0.3, 12.0.0.2' |
| 130 | + ), |
| 131 | + array( '12.0.0.1', '12.0.0.2' ), |
| 132 | + false, |
| 133 | + 'With X-Forwaded-For' |
| 134 | + ), |
| 135 | + array( |
| 136 | + '12.0.0.1', |
| 137 | + array( |
| 138 | + 'REMOTE_ADDR' => '12.0.0.1', |
| 139 | + 'HTTP_X_FORWARDED_FOR' => '12.0.0.3, 12.0.0.2' |
| 140 | + ), |
| 141 | + array(), |
| 142 | + false, |
| 143 | + 'With X-Forwaded-For and disallowed server' |
| 144 | + ), |
| 145 | + array( |
| 146 | + '12.0.0.2', |
| 147 | + array( |
| 148 | + 'REMOTE_ADDR' => '12.0.0.1', |
| 149 | + 'HTTP_X_FORWARDED_FOR' => '12.0.0.3, 12.0.0.2' |
| 150 | + ), |
| 151 | + array( '12.0.0.1' ), |
| 152 | + false, |
| 153 | + 'With multiple X-Forwaded-For and only one allowed server' |
| 154 | + ), |
| 155 | + array( |
| 156 | + '12.0.0.2', |
| 157 | + array( |
| 158 | + 'REMOTE_ADDR' => '12.0.0.2', |
| 159 | + 'HTTP_X_FORWARDED_FOR' => '10.0.0.3, 12.0.0.2' |
| 160 | + ), |
| 161 | + array( '12.0.0.1', '12.0.0.2' ), |
| 162 | + false, |
| 163 | + 'With X-Forwaded-For and private IP' |
| 164 | + ), |
| 165 | + array( |
| 166 | + '10.0.0.3', |
| 167 | + array( |
| 168 | + 'REMOTE_ADDR' => '12.0.0.2', |
| 169 | + 'HTTP_X_FORWARDED_FOR' => '10.0.0.3, 12.0.0.2' |
| 170 | + ), |
| 171 | + array( '12.0.0.1', '12.0.0.2' ), |
| 172 | + true, |
| 173 | + 'With X-Forwaded-For and private IP (allowed)' |
| 174 | + ), |
| 175 | + ); |
| 176 | + } |
| 177 | + |
| 178 | + /** |
| 179 | + * @expectedException MWException |
| 180 | + */ |
| 181 | + function testGetIpLackOfRemoteAddrThrowAnException() { |
| 182 | + var_dump( $_SERVER ); |
| 183 | + $request = new WebRequest(); |
| 184 | + # Next call throw an exception about lacking an IP |
| 185 | + $request->getIP(); |
| 186 | + } |
89 | 187 | } |
Index: trunk/phase3/includes/ProxyTools.php |
— | — | @@ -8,29 +8,13 @@ |
9 | 9 | /** |
10 | 10 | * Extracts the XFF string from the request header |
11 | 11 | * Note: headers are spoofable |
| 12 | + * |
| 13 | + * @deprecated in 1.19; use $wgRequest->getHeader( 'X-Forwarded-For' ) instead. |
12 | 14 | * @return string |
13 | 15 | */ |
14 | 16 | function wfGetForwardedFor() { |
15 | | - $apacheHeaders = function_exists( 'apache_request_headers' ) ? apache_request_headers() : null; |
16 | | - if( is_array( $apacheHeaders ) ) { |
17 | | - // More reliable than $_SERVER due to case and -/_ folding |
18 | | - $set = array(); |
19 | | - foreach ( $apacheHeaders as $tempName => $tempValue ) { |
20 | | - $set[ strtoupper( $tempName ) ] = $tempValue; |
21 | | - } |
22 | | - $index = strtoupper ( 'X-Forwarded-For' ); |
23 | | - } else { |
24 | | - // Subject to spoofing with headers like X_Forwarded_For |
25 | | - $set = $_SERVER; |
26 | | - $index = 'HTTP_X_FORWARDED_FOR'; |
27 | | - } |
28 | | - |
29 | | - #Try to see if XFF is set |
30 | | - if( isset( $set[$index] ) ) { |
31 | | - return $set[$index]; |
32 | | - } else { |
33 | | - return null; |
34 | | - } |
| 17 | + global $wgRequest; |
| 18 | + return $wgRequest->getHeader( 'X-Forwarded-For' ); |
35 | 19 | } |
36 | 20 | |
37 | 21 | /** |
— | — | @@ -42,88 +26,20 @@ |
43 | 27 | */ |
44 | 28 | function wfGetAgent() { |
45 | 29 | wfDeprecated( __FUNCTION__ ); |
46 | | - if( function_exists( 'apache_request_headers' ) ) { |
47 | | - // More reliable than $_SERVER due to case and -/_ folding |
48 | | - $set = array(); |
49 | | - foreach ( apache_request_headers() as $tempName => $tempValue ) { |
50 | | - $set[ strtoupper( $tempName ) ] = $tempValue; |
51 | | - } |
52 | | - $index = strtoupper ( 'User-Agent' ); |
53 | | - } else { |
54 | | - // Subject to spoofing with headers like X_Forwarded_For |
55 | | - $set = $_SERVER; |
56 | | - $index = 'HTTP_USER_AGENT'; |
57 | | - } |
58 | | - if( isset( $set[$index] ) ) { |
59 | | - return $set[$index]; |
60 | | - } else { |
61 | | - return ''; |
62 | | - } |
| 30 | + global $wgRequest; |
| 31 | + return $wgRequest->getHeader( 'User-Agent' ); |
63 | 32 | } |
64 | 33 | |
65 | 34 | /** |
66 | 35 | * Work out the IP address based on various globals |
67 | 36 | * For trusted proxies, use the XFF client IP (first of the chain) |
68 | | - * @param $reset boolean Used to reset the internal static variable |
69 | | - * tracking the IP address. Set to anything non empty to reset it, for |
70 | | - * example: wfGetIP( 'reset' ); (default: false). |
| 37 | + * |
| 38 | + * @deprecated in 1.19; call $wgRequest->getIP() directly. |
71 | 39 | * @return string |
72 | 40 | */ |
73 | | -function wfGetIP( $reset = false ) { |
74 | | - global $wgUsePrivateIPs, $wgCommandLineMode; |
75 | | - static $ip = false; |
76 | | - |
77 | | - if( $reset ) { |
78 | | - $ip = false; |
79 | | - } |
80 | | - |
81 | | - # Return cached result |
82 | | - if ( !empty( $ip ) ) { |
83 | | - return $ip; |
84 | | - } |
85 | | - |
86 | | - /* collect the originating ips */ |
87 | | - # Client connecting to this webserver |
88 | | - if ( isset( $_SERVER['REMOTE_ADDR'] ) ) { |
89 | | - $ip = IP::canonicalize( $_SERVER['REMOTE_ADDR'] ); |
90 | | - } elseif( $wgCommandLineMode ) { |
91 | | - $ip = '127.0.0.1'; |
92 | | - } |
93 | | - |
94 | | - # Append XFF |
95 | | - $forwardedFor = wfGetForwardedFor(); |
96 | | - if ( $forwardedFor !== null ) { |
97 | | - $ipchain = array_map( 'trim', explode( ',', $forwardedFor ) ); |
98 | | - $ipchain = array_reverse( $ipchain ); |
99 | | - if ( $ip ) { |
100 | | - array_unshift( $ipchain, $ip ); |
101 | | - } |
102 | | - |
103 | | - # Step through XFF list and find the last address in the list which is a trusted server |
104 | | - # Set $ip to the IP address given by that trusted server, unless the address is not sensible (e.g. private) |
105 | | - foreach ( $ipchain as $i => $curIP ) { |
106 | | - $curIP = IP::canonicalize( $curIP ); |
107 | | - if ( wfIsTrustedProxy( $curIP ) ) { |
108 | | - if ( isset( $ipchain[$i + 1] ) ) { |
109 | | - if( $wgUsePrivateIPs || IP::isPublic( $ipchain[$i + 1 ] ) ) { |
110 | | - $ip = $ipchain[$i + 1]; |
111 | | - } |
112 | | - } |
113 | | - } else { |
114 | | - break; |
115 | | - } |
116 | | - } |
117 | | - } |
118 | | - |
119 | | - # Allow extensions to improve our guess |
120 | | - wfRunHooks( 'GetIP', array( &$ip ) ); |
121 | | - |
122 | | - if( !$ip ) { |
123 | | - throw new MWException( "Unable to determine IP" ); |
124 | | - } |
125 | | - |
126 | | - wfDebug( "IP: $ip\n" ); |
127 | | - return $ip; |
| 41 | +function wfGetIP() { |
| 42 | + global $wgRequest; |
| 43 | + return $wgRequest->getIP(); |
128 | 44 | } |
129 | 45 | |
130 | 46 | /** |
— | — | @@ -148,14 +64,14 @@ |
149 | 65 | */ |
150 | 66 | function wfProxyCheck() { |
151 | 67 | global $wgBlockOpenProxies, $wgProxyPorts, $wgProxyScriptPath; |
152 | | - global $wgMemc, $wgProxyMemcExpiry; |
| 68 | + global $wgMemc, $wgProxyMemcExpiry, $wgRequest; |
153 | 69 | global $wgProxyKey; |
154 | 70 | |
155 | 71 | if ( !$wgBlockOpenProxies ) { |
156 | 72 | return; |
157 | 73 | } |
158 | 74 | |
159 | | - $ip = wfGetIP(); |
| 75 | + $ip = $wgRequest->getIP(); |
160 | 76 | |
161 | 77 | # Get MemCached key |
162 | 78 | $mcKey = wfMemcKey( 'proxy', 'ip', $ip ); |
Index: trunk/phase3/includes/User.php |
— | — | @@ -1259,7 +1259,7 @@ |
1260 | 1260 | # user is not immune to autoblocks/hardblocks, and they are the current user so we |
1261 | 1261 | # know which IP address they're actually coming from |
1262 | 1262 | if ( !$this->isAllowed( 'ipblock-exempt' ) && $this->getID() == $wgUser->getID() ) { |
1263 | | - $ip = wfGetIP(); |
| 1263 | + $ip = $this->getRequest()->getIP(); |
1264 | 1264 | } else { |
1265 | 1265 | $ip = null; |
1266 | 1266 | } |
— | — | @@ -1409,7 +1409,7 @@ |
1410 | 1410 | */ |
1411 | 1411 | public function isPingLimitable() { |
1412 | 1412 | global $wgRateLimitsExcludedIPs; |
1413 | | - if( in_array( wfGetIP(), $wgRateLimitsExcludedIPs ) ) { |
| 1413 | + if( in_array( $this->getRequest()->getIP(), $wgRateLimitsExcludedIPs ) ) { |
1414 | 1414 | // No other good way currently to disable rate limits |
1415 | 1415 | // for specific IPs. :P |
1416 | 1416 | // But this is a crappy hack and should die. |
— | — | @@ -1450,7 +1450,7 @@ |
1451 | 1451 | $limits = $wgRateLimits[$action]; |
1452 | 1452 | $keys = array(); |
1453 | 1453 | $id = $this->getId(); |
1454 | | - $ip = wfGetIP(); |
| 1454 | + $ip = $this->getRequet()->getIP(); |
1455 | 1455 | $userLimit = false; |
1456 | 1456 | |
1457 | 1457 | if( isset( $limits['anon'] ) && $id == 0 ) { |
— | — | @@ -1607,7 +1607,7 @@ |
1608 | 1608 | if( IP::isIPAddress( $this->getName() ) ) { |
1609 | 1609 | $ip = $this->getName(); |
1610 | 1610 | } elseif( !$ip ) { |
1611 | | - $ip = wfGetIP(); |
| 1611 | + $ip = $this->getRequest()->getIP(); |
1612 | 1612 | } |
1613 | 1613 | $blocked = false; |
1614 | 1614 | wfRunHooks( 'UserIsBlockedGlobally', array( &$this, $ip, &$blocked ) ); |
— | — | @@ -1685,7 +1685,7 @@ |
1686 | 1686 | $this->load(); |
1687 | 1687 | if ( $this->mName === false ) { |
1688 | 1688 | # Clean up IPs |
1689 | | - $this->mName = IP::sanitizeIP( wfGetIP() ); |
| 1689 | + $this->mName = IP::sanitizeIP( $this->getRequest()->getIP() ); |
1690 | 1690 | } |
1691 | 1691 | return $this->mName; |
1692 | 1692 | } |
— | — | @@ -2943,7 +2943,7 @@ |
2944 | 2944 | return; |
2945 | 2945 | } |
2946 | 2946 | |
2947 | | - $userblock->doAutoblock( wfGetIP() ); |
| 2947 | + $userblock->doAutoblock( $this->getRequest()->getIP() ); |
2948 | 2948 | } |
2949 | 2949 | |
2950 | 2950 | /** |
— | — | @@ -3012,7 +3012,7 @@ |
3013 | 3013 | # blocked with createaccount disabled, prevent new account creation there even |
3014 | 3014 | # when the user is logged in |
3015 | 3015 | if( $this->mBlockedFromCreateAccount === false ){ |
3016 | | - $this->mBlockedFromCreateAccount = Block::newFromTarget( null, wfGetIP() ); |
| 3016 | + $this->mBlockedFromCreateAccount = Block::newFromTarget( null, $this->getRequest()->getIP() ); |
3017 | 3017 | } |
3018 | 3018 | return $this->mBlockedFromCreateAccount instanceof Block && $this->mBlockedFromCreateAccount->prevents( 'createaccount' ) |
3019 | 3019 | ? $this->mBlockedFromCreateAccount |
— | — | @@ -3228,7 +3228,7 @@ |
3229 | 3229 | |
3230 | 3230 | return $this->sendMail( wfMsg( 'confirmemail_subject' ), |
3231 | 3231 | wfMsg( $message, |
3232 | | - wfGetIP(), |
| 3232 | + $this->getRequest()->getIP(), |
3233 | 3233 | $this->getName(), |
3234 | 3234 | $url, |
3235 | 3235 | $wgLang->timeanddate( $expiration, false ), |
Index: trunk/phase3/includes/RecentChange.php |
— | — | @@ -361,8 +361,9 @@ |
362 | 362 | */ |
363 | 363 | public static function notifyEdit( $timestamp, &$title, $minor, &$user, $comment, $oldId, |
364 | 364 | $lastTimestamp, $bot, $ip='', $oldSize=0, $newSize=0, $newId=0, $patrol=0 ) { |
| 365 | + global $wgRequest; |
365 | 366 | if( !$ip ) { |
366 | | - $ip = wfGetIP(); |
| 367 | + $ip = $wgRequest->getIP(); |
367 | 368 | if( !$ip ) $ip = ''; |
368 | 369 | } |
369 | 370 | |
— | — | @@ -424,8 +425,9 @@ |
425 | 426 | */ |
426 | 427 | public static function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot, |
427 | 428 | $ip='', $size=0, $newId=0, $patrol=0 ) { |
| 429 | + global $wgRequest; |
428 | 430 | if( !$ip ) { |
429 | | - $ip = wfGetIP(); |
| 431 | + $ip = $wgRequest->getIP(); |
430 | 432 | if( !$ip ) $ip = ''; |
431 | 433 | } |
432 | 434 | |
— | — | @@ -484,7 +486,7 @@ |
485 | 487 | $overRedir = false ) { |
486 | 488 | global $wgRequest; |
487 | 489 | if( !$ip ) { |
488 | | - $ip = wfGetIP(); |
| 490 | + $ip = $wgRequest->getIP(); |
489 | 491 | if( !$ip ) $ip = ''; |
490 | 492 | } |
491 | 493 | |
— | — | @@ -565,7 +567,7 @@ |
566 | 568 | $type, $action, $target, $logComment, $params, $newId=0 ) { |
567 | 569 | global $wgRequest; |
568 | 570 | if( !$ip ) { |
569 | | - $ip = wfGetIP(); |
| 571 | + $ip = $wgRequest->getIP(); |
570 | 572 | if( !$ip ) { |
571 | 573 | $ip = ''; |
572 | 574 | } |
Index: trunk/phase3/includes/EditPage.php |
— | — | @@ -856,7 +856,7 @@ |
857 | 857 | * @return int one of the constants describing the result |
858 | 858 | */ |
859 | 859 | function internalAttemptSave( &$result, $bot = false ) { |
860 | | - global $wgFilterCallback, $wgUser, $wgParser; |
| 860 | + global $wgFilterCallback, $wgUser, $wgRequest, $wgParser; |
861 | 861 | global $wgMaxArticleSize; |
862 | 862 | |
863 | 863 | wfProfileIn( __METHOD__ ); |
— | — | @@ -888,7 +888,7 @@ |
889 | 889 | } |
890 | 890 | if ( $match !== false ) { |
891 | 891 | $result['spam'] = $match; |
892 | | - $ip = wfGetIP(); |
| 892 | + $ip = $wgRequest->getIP(); |
893 | 893 | $pdbk = $this->mTitle->getPrefixedDBkey(); |
894 | 894 | $match = str_replace( "\n", '', $match ); |
895 | 895 | wfDebugLog( 'SpamRegex', "$ip spam regex hit [[$pdbk]]: \"$match\"" ); |
Index: trunk/phase3/includes/WebRequest.php |
— | — | @@ -44,6 +44,12 @@ |
45 | 45 | */ |
46 | 46 | private $response; |
47 | 47 | |
| 48 | + /** |
| 49 | + * Cached client IP address |
| 50 | + * @var String |
| 51 | + */ |
| 52 | + private $ip; |
| 53 | + |
48 | 54 | public function __construct() { |
49 | 55 | /// @todo FIXME: This preemptive de-quoting can interfere with other web libraries |
50 | 56 | /// and increases our memory footprint. It would be cleaner to do on |
— | — | @@ -962,6 +968,72 @@ |
963 | 969 | arsort( $langs, SORT_NUMERIC ); |
964 | 970 | return $langs; |
965 | 971 | } |
| 972 | + |
| 973 | + /** |
| 974 | + * Fetch the raw IP from the request |
| 975 | + * |
| 976 | + * @return String |
| 977 | + */ |
| 978 | + protected function getRawIP() { |
| 979 | + if ( isset( $_SERVER['REMOTE_ADDR'] ) ) { |
| 980 | + return IP::canonicalize( $_SERVER['REMOTE_ADDR'] ); |
| 981 | + } else { |
| 982 | + return null; |
| 983 | + } |
| 984 | + } |
| 985 | + |
| 986 | + /** |
| 987 | + * Work out the IP address based on various globals |
| 988 | + * For trusted proxies, use the XFF client IP (first of the chain) |
| 989 | + * @return string |
| 990 | + */ |
| 991 | + public function getIP() { |
| 992 | + global $wgUsePrivateIPs; |
| 993 | + |
| 994 | + # Return cached result |
| 995 | + if ( $this->ip !== null ) { |
| 996 | + return $this->ip; |
| 997 | + } |
| 998 | + |
| 999 | + # collect the originating ips |
| 1000 | + $ip = $this->getRawIP(); |
| 1001 | + |
| 1002 | + # Append XFF |
| 1003 | + $forwardedFor = $this->getHeader( 'X-Forwarded-For' ); |
| 1004 | + if ( $forwardedFor !== false ) { |
| 1005 | + $ipchain = array_map( 'trim', explode( ',', $forwardedFor ) ); |
| 1006 | + $ipchain = array_reverse( $ipchain ); |
| 1007 | + if ( $ip ) { |
| 1008 | + array_unshift( $ipchain, $ip ); |
| 1009 | + } |
| 1010 | + |
| 1011 | + # Step through XFF list and find the last address in the list which is a trusted server |
| 1012 | + # Set $ip to the IP address given by that trusted server, unless the address is not sensible (e.g. private) |
| 1013 | + foreach ( $ipchain as $i => $curIP ) { |
| 1014 | + $curIP = IP::canonicalize( $curIP ); |
| 1015 | + if ( wfIsTrustedProxy( $curIP ) ) { |
| 1016 | + if ( isset( $ipchain[$i + 1] ) ) { |
| 1017 | + if ( $wgUsePrivateIPs || IP::isPublic( $ipchain[$i + 1 ] ) ) { |
| 1018 | + $ip = $ipchain[$i + 1]; |
| 1019 | + } |
| 1020 | + } |
| 1021 | + } else { |
| 1022 | + break; |
| 1023 | + } |
| 1024 | + } |
| 1025 | + } |
| 1026 | + |
| 1027 | + # Allow extensions to improve our guess |
| 1028 | + wfRunHooks( 'GetIP', array( &$ip ) ); |
| 1029 | + |
| 1030 | + if ( !$ip ) { |
| 1031 | + throw new MWException( "Unable to determine IP" ); |
| 1032 | + } |
| 1033 | + |
| 1034 | + wfDebug( "IP: $ip\n" ); |
| 1035 | + $this->ip = $ip; |
| 1036 | + return $ip; |
| 1037 | + } |
966 | 1038 | } |
967 | 1039 | |
968 | 1040 | /** |
— | — | @@ -1165,4 +1237,8 @@ |
1166 | 1238 | public function checkUrlExtension( $extWhitelist = array() ) { |
1167 | 1239 | return true; |
1168 | 1240 | } |
| 1241 | + |
| 1242 | + protected function getRawIP() { |
| 1243 | + return '127.0.0.1'; |
| 1244 | + } |
1169 | 1245 | } |
Index: trunk/phase3/includes/Title.php |
— | — | @@ -1562,7 +1562,7 @@ |
1563 | 1563 | if ( $reason == '' ) { |
1564 | 1564 | $reason = wfMsg( 'blockednoreason' ); |
1565 | 1565 | } |
1566 | | - $ip = wfGetIP(); |
| 1566 | + $ip = $user->getRequest()->getIP(); |
1567 | 1567 | |
1568 | 1568 | if ( is_numeric( $id ) ) { |
1569 | 1569 | $name = User::whoIs( $id ); |
Index: trunk/phase3/includes/SkinLegacy.php |
— | — | @@ -889,7 +889,7 @@ |
890 | 890 | } |
891 | 891 | |
892 | 892 | function nameAndLogin() { |
893 | | - global $wgUser, $wgLang, $wgContLang; |
| 893 | + global $wgUser, $wgLang, $wgRequest, $wgContLang; |
894 | 894 | |
895 | 895 | $logoutPage = $wgContLang->specialPage( 'Userlogout' ); |
896 | 896 | |
— | — | @@ -897,7 +897,7 @@ |
898 | 898 | |
899 | 899 | if ( $wgUser->isAnon() ) { |
900 | 900 | if ( $this->getSkin()->showIPinHeader() ) { |
901 | | - $name = wfGetIP(); |
| 901 | + $name = $wgRequest->getIP(); |
902 | 902 | |
903 | 903 | $talkLink = Linker::link( $wgUser->getTalkPage(), |
904 | 904 | $wgLang->getNsText( NS_TALK ) ); |
Index: trunk/phase3/includes/specials/SpecialPasswordReset.php |
— | — | @@ -162,7 +162,7 @@ |
163 | 163 | |
164 | 164 | // We need to have a valid IP address for the hook, but per bug 18347, we should |
165 | 165 | // send the user's name if they're logged in. |
166 | | - $ip = wfGetIP(); |
| 166 | + $ip = $this->getRequest()->getIP(); |
167 | 167 | if ( !$ip ) { |
168 | 168 | return array( 'badipaddress' ); |
169 | 169 | } |
Index: trunk/phase3/includes/specials/SpecialUserlogin.php |
— | — | @@ -251,7 +251,7 @@ |
252 | 252 | * @private |
253 | 253 | */ |
254 | 254 | function addNewAccountInternal() { |
255 | | - global $wgUser, $wgOut; |
| 255 | + global $wgUser, $wgOut, $wgRequest; |
256 | 256 | global $wgMemc, $wgAccountCreationThrottle; |
257 | 257 | global $wgAuth, $wgMinimalPasswordLength; |
258 | 258 | global $wgEmailConfirmToEdit; |
— | — | @@ -308,7 +308,7 @@ |
309 | 309 | return false; |
310 | 310 | } |
311 | 311 | |
312 | | - $ip = wfGetIP(); |
| 312 | + $ip = $wgRequest->getIP(); |
313 | 313 | if ( $wgUser->isDnsBlacklisted( $ip, true /* check $wgProxyWhitelist */ ) ) { |
314 | 314 | $this->mainLoginForm( wfMsg( 'sorbs_create_account_reason' ) . ' (' . htmlspecialchars( $ip ) . ')' ); |
315 | 315 | return false; |
— | — | @@ -588,12 +588,12 @@ |
589 | 589 | * @return Bool|Integer The integer hit count or True if it is already at the limit |
590 | 590 | */ |
591 | 591 | public static function incLoginThrottle( $username ) { |
592 | | - global $wgPasswordAttemptThrottle, $wgMemc; |
| 592 | + global $wgPasswordAttemptThrottle, $wgMemc, $wgRequest; |
593 | 593 | $username = trim( $username ); // sanity |
594 | 594 | |
595 | 595 | $throttleCount = 0; |
596 | 596 | if ( is_array( $wgPasswordAttemptThrottle ) ) { |
597 | | - $throttleKey = wfMemcKey( 'password-throttle', wfGetIP(), md5( $username ) ); |
| 597 | + $throttleKey = wfMemcKey( 'password-throttle', $wgRequest->getIP(), md5( $username ) ); |
598 | 598 | $count = $wgPasswordAttemptThrottle['count']; |
599 | 599 | $period = $wgPasswordAttemptThrottle['seconds']; |
600 | 600 | |
— | — | @@ -616,10 +616,10 @@ |
617 | 617 | * @return void |
618 | 618 | */ |
619 | 619 | public static function clearLoginThrottle( $username ) { |
620 | | - global $wgMemc; |
| 620 | + global $wgMemc, $wgRequest; |
621 | 621 | $username = trim( $username ); // sanity |
622 | 622 | |
623 | | - $throttleKey = wfMemcKey( 'password-throttle', wfGetIP(), md5( $username ) ); |
| 623 | + $throttleKey = wfMemcKey( 'password-throttle', $wgRequest->getIP(), md5( $username ) ); |
624 | 624 | $wgMemc->delete( $throttleKey ); |
625 | 625 | } |
626 | 626 | |
— | — | @@ -682,7 +682,7 @@ |
683 | 683 | } |
684 | 684 | |
685 | 685 | function processLogin() { |
686 | | - global $wgUser; |
| 686 | + global $wgUser, $wgRequest, $wgLang; |
687 | 687 | |
688 | 688 | switch ( $this->authenticateUserData() ) { |
689 | 689 | case self::SUCCESS: |
— | — | @@ -697,7 +697,7 @@ |
698 | 698 | self::clearLoginToken(); |
699 | 699 | |
700 | 700 | // Reset the throttle |
701 | | - $key = wfMemcKey( 'password-throttle', wfGetIP(), md5( $this->mUsername ) ); |
| 701 | + $key = wfMemcKey( 'password-throttle', $wgRequest->getIP(), md5( $this->mUsername ) ); |
702 | 702 | global $wgMemc; |
703 | 703 | $wgMemc->delete( $key ); |
704 | 704 | |
— | — | @@ -705,7 +705,6 @@ |
706 | 706 | /* Replace the language object to provide user interface in |
707 | 707 | * correct language immediately on this first page load. |
708 | 708 | */ |
709 | | - global $wgLang, $wgRequest; |
710 | 709 | $code = $wgRequest->getVal( 'uselang', $wgUser->getOption( 'language' ) ); |
711 | 710 | $wgLang = Language::factory( $code ); |
712 | 711 | return $this->successfulLogin(); |
— | — | @@ -779,12 +778,12 @@ |
780 | 779 | * @private |
781 | 780 | */ |
782 | 781 | function mailPasswordInternal( $u, $throttle = true, $emailTitle = 'passwordremindertitle', $emailText = 'passwordremindertext' ) { |
783 | | - global $wgServer, $wgScript, $wgUser, $wgNewPasswordExpiry; |
| 782 | + global $wgServer, $wgScript, $wgUser, $wgNewPasswordExpiry, $wgRequest; |
784 | 783 | |
785 | 784 | if ( $u->getEmail() == '' ) { |
786 | 785 | return Status::newFatal( 'noemail', $u->getName() ); |
787 | 786 | } |
788 | | - $ip = wfGetIP(); |
| 787 | + $ip = $wgRequest->getIP(); |
789 | 788 | if( !$ip ) { |
790 | 789 | return Status::newFatal( 'badipaddress' ); |
791 | 790 | } |
Index: trunk/phase3/includes/specials/SpecialBlockme.php |
— | — | @@ -38,7 +38,7 @@ |
39 | 39 | $this->setHeaders(); |
40 | 40 | $this->outputHeader(); |
41 | 41 | |
42 | | - $ip = wfGetIP(); |
| 42 | + $ip = $wgRequest->getIP(); |
43 | 43 | if( !$wgBlockOpenProxies || $wgRequest->getText( 'ip' ) != md5( $ip . $wgProxyKey ) ) { |
44 | 44 | $wgOut->addWikiMsg( 'proxyblocker-disabled' ); |
45 | 45 | return; |
Index: trunk/phase3/includes/specials/SpecialVersion.php |
— | — | @@ -502,7 +502,7 @@ |
503 | 503 | * @return String: HTML fragment |
504 | 504 | */ |
505 | 505 | private function IPInfo() { |
506 | | - $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) ); |
| 506 | + $ip = str_replace( '--', ' - ', htmlspecialchars( $this->getRequest()->getIP() ) ); |
507 | 507 | return "<!-- visited from $ip -->\n" . |
508 | 508 | "<span style='display:none'>visited from $ip</span>"; |
509 | 509 | } |
Index: trunk/phase3/includes/Autopromote.php |
— | — | @@ -166,9 +166,9 @@ |
167 | 167 | $groups = array_slice( $cond, 1 ); |
168 | 168 | return count( array_intersect( $groups, $user->getGroups() ) ) == count( $groups ); |
169 | 169 | case APCOND_ISIP: |
170 | | - return $cond[1] == wfGetIP(); |
| 170 | + return $cond[1] == $user->getRequest()->getIP(); |
171 | 171 | case APCOND_IPINRANGE: |
172 | | - return IP::isInRange( wfGetIP(), $cond[1] ); |
| 172 | + return IP::isInRange( $user->getRequest()->getIP(), $cond[1] ); |
173 | 173 | case APCOND_BLOCKED: |
174 | 174 | return $user->isBlocked(); |
175 | 175 | case APCOND_ISBOT: |
Index: trunk/phase3/includes/Exception.php |
— | — | @@ -352,7 +352,7 @@ |
353 | 353 | */ |
354 | 354 | class UserBlockedError extends ErrorPageError { |
355 | 355 | public function __construct( Block $block ){ |
356 | | - global $wgLang; |
| 356 | + global $wgLang, $wgRequest; |
357 | 357 | |
358 | 358 | $blockerUserpage = $block->getBlocker()->getUserPage(); |
359 | 359 | $link = "[[{$blockerUserpage->getPrefixedText()}|{$blockerUserpage->getText()}]]"; |
— | — | @@ -372,7 +372,7 @@ |
373 | 373 | array( |
374 | 374 | $link, |
375 | 375 | $reason, |
376 | | - wfGetIP(), |
| 376 | + $wgRequest->getIP(), |
377 | 377 | $block->getBlocker()->getName(), |
378 | 378 | $block->getId(), |
379 | 379 | $wgLang->formatExpiry( $block->mExpiry ), |
Index: trunk/phase3/api.php |
— | — | @@ -127,7 +127,7 @@ |
128 | 128 | $items = array( |
129 | 129 | wfTimestamp( TS_MW ), |
130 | 130 | $endtime - $starttime, |
131 | | - wfGetIP(), |
| 131 | + $wgRequest->getIP(), |
132 | 132 | $_SERVER['HTTP_USER_AGENT'] |
133 | 133 | ); |
134 | 134 | $items[] = $wgRequest->wasPosted() ? 'POST' : 'GET'; |