r94932 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94931‎ | r94932 | r94933 >
Date:20:03, 18 August 2011
Author:ialex
Status:ok (Comments)
Tags:
Comment:
Moved wfGetIP() to WebRequest::getIP():
* Changed all calls in core to the latter
* Also marked wfGetForwardedFor() as deprecated
* Moved wfGetIP() tests to WebRequestTest
Modified paths:
  • /trunk/phase3/api.php (modified) (history)
  • /trunk/phase3/includes/Autopromote.php (modified) (history)
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/includes/Exception.php (modified) (history)
  • /trunk/phase3/includes/ProxyTools.php (modified) (history)
  • /trunk/phase3/includes/RecentChange.php (modified) (history)
  • /trunk/phase3/includes/SkinLegacy.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/User.php (modified) (history)
  • /trunk/phase3/includes/WebRequest.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialBlockme.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialPasswordReset.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUserlogin.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialVersion.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/ProxyTools (deleted) (history)
  • /trunk/phase3/tests/phpunit/includes/WebRequestTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/WebRequestTest.php
@@ -85,4 +85,102 @@
8686 ),
8787 );
8888 }
 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+ }
89187 }
Index: trunk/phase3/includes/ProxyTools.php
@@ -8,29 +8,13 @@
99 /**
1010 * Extracts the XFF string from the request header
1111 * Note: headers are spoofable
 12+ *
 13+ * @deprecated in 1.19; use $wgRequest->getHeader( 'X-Forwarded-For' ) instead.
1214 * @return string
1315 */
1416 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' );
3519 }
3620
3721 /**
@@ -42,88 +26,20 @@
4327 */
4428 function wfGetAgent() {
4529 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' );
6332 }
6433
6534 /**
6635 * Work out the IP address based on various globals
6736 * 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.
7139 * @return string
7240 */
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();
12844 }
12945
13046 /**
@@ -148,14 +64,14 @@
14965 */
15066 function wfProxyCheck() {
15167 global $wgBlockOpenProxies, $wgProxyPorts, $wgProxyScriptPath;
152 - global $wgMemc, $wgProxyMemcExpiry;
 68+ global $wgMemc, $wgProxyMemcExpiry, $wgRequest;
15369 global $wgProxyKey;
15470
15571 if ( !$wgBlockOpenProxies ) {
15672 return;
15773 }
15874
159 - $ip = wfGetIP();
 75+ $ip = $wgRequest->getIP();
16076
16177 # Get MemCached key
16278 $mcKey = wfMemcKey( 'proxy', 'ip', $ip );
Index: trunk/phase3/includes/User.php
@@ -1259,7 +1259,7 @@
12601260 # user is not immune to autoblocks/hardblocks, and they are the current user so we
12611261 # know which IP address they're actually coming from
12621262 if ( !$this->isAllowed( 'ipblock-exempt' ) && $this->getID() == $wgUser->getID() ) {
1263 - $ip = wfGetIP();
 1263+ $ip = $this->getRequest()->getIP();
12641264 } else {
12651265 $ip = null;
12661266 }
@@ -1409,7 +1409,7 @@
14101410 */
14111411 public function isPingLimitable() {
14121412 global $wgRateLimitsExcludedIPs;
1413 - if( in_array( wfGetIP(), $wgRateLimitsExcludedIPs ) ) {
 1413+ if( in_array( $this->getRequest()->getIP(), $wgRateLimitsExcludedIPs ) ) {
14141414 // No other good way currently to disable rate limits
14151415 // for specific IPs. :P
14161416 // But this is a crappy hack and should die.
@@ -1450,7 +1450,7 @@
14511451 $limits = $wgRateLimits[$action];
14521452 $keys = array();
14531453 $id = $this->getId();
1454 - $ip = wfGetIP();
 1454+ $ip = $this->getRequet()->getIP();
14551455 $userLimit = false;
14561456
14571457 if( isset( $limits['anon'] ) && $id == 0 ) {
@@ -1607,7 +1607,7 @@
16081608 if( IP::isIPAddress( $this->getName() ) ) {
16091609 $ip = $this->getName();
16101610 } elseif( !$ip ) {
1611 - $ip = wfGetIP();
 1611+ $ip = $this->getRequest()->getIP();
16121612 }
16131613 $blocked = false;
16141614 wfRunHooks( 'UserIsBlockedGlobally', array( &$this, $ip, &$blocked ) );
@@ -1685,7 +1685,7 @@
16861686 $this->load();
16871687 if ( $this->mName === false ) {
16881688 # Clean up IPs
1689 - $this->mName = IP::sanitizeIP( wfGetIP() );
 1689+ $this->mName = IP::sanitizeIP( $this->getRequest()->getIP() );
16901690 }
16911691 return $this->mName;
16921692 }
@@ -2943,7 +2943,7 @@
29442944 return;
29452945 }
29462946
2947 - $userblock->doAutoblock( wfGetIP() );
 2947+ $userblock->doAutoblock( $this->getRequest()->getIP() );
29482948 }
29492949
29502950 /**
@@ -3012,7 +3012,7 @@
30133013 # blocked with createaccount disabled, prevent new account creation there even
30143014 # when the user is logged in
30153015 if( $this->mBlockedFromCreateAccount === false ){
3016 - $this->mBlockedFromCreateAccount = Block::newFromTarget( null, wfGetIP() );
 3016+ $this->mBlockedFromCreateAccount = Block::newFromTarget( null, $this->getRequest()->getIP() );
30173017 }
30183018 return $this->mBlockedFromCreateAccount instanceof Block && $this->mBlockedFromCreateAccount->prevents( 'createaccount' )
30193019 ? $this->mBlockedFromCreateAccount
@@ -3228,7 +3228,7 @@
32293229
32303230 return $this->sendMail( wfMsg( 'confirmemail_subject' ),
32313231 wfMsg( $message,
3232 - wfGetIP(),
 3232+ $this->getRequest()->getIP(),
32333233 $this->getName(),
32343234 $url,
32353235 $wgLang->timeanddate( $expiration, false ),
Index: trunk/phase3/includes/RecentChange.php
@@ -361,8 +361,9 @@
362362 */
363363 public static function notifyEdit( $timestamp, &$title, $minor, &$user, $comment, $oldId,
364364 $lastTimestamp, $bot, $ip='', $oldSize=0, $newSize=0, $newId=0, $patrol=0 ) {
 365+ global $wgRequest;
365366 if( !$ip ) {
366 - $ip = wfGetIP();
 367+ $ip = $wgRequest->getIP();
367368 if( !$ip ) $ip = '';
368369 }
369370
@@ -424,8 +425,9 @@
425426 */
426427 public static function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot,
427428 $ip='', $size=0, $newId=0, $patrol=0 ) {
 429+ global $wgRequest;
428430 if( !$ip ) {
429 - $ip = wfGetIP();
 431+ $ip = $wgRequest->getIP();
430432 if( !$ip ) $ip = '';
431433 }
432434
@@ -484,7 +486,7 @@
485487 $overRedir = false ) {
486488 global $wgRequest;
487489 if( !$ip ) {
488 - $ip = wfGetIP();
 490+ $ip = $wgRequest->getIP();
489491 if( !$ip ) $ip = '';
490492 }
491493
@@ -565,7 +567,7 @@
566568 $type, $action, $target, $logComment, $params, $newId=0 ) {
567569 global $wgRequest;
568570 if( !$ip ) {
569 - $ip = wfGetIP();
 571+ $ip = $wgRequest->getIP();
570572 if( !$ip ) {
571573 $ip = '';
572574 }
Index: trunk/phase3/includes/EditPage.php
@@ -856,7 +856,7 @@
857857 * @return int one of the constants describing the result
858858 */
859859 function internalAttemptSave( &$result, $bot = false ) {
860 - global $wgFilterCallback, $wgUser, $wgParser;
 860+ global $wgFilterCallback, $wgUser, $wgRequest, $wgParser;
861861 global $wgMaxArticleSize;
862862
863863 wfProfileIn( __METHOD__ );
@@ -888,7 +888,7 @@
889889 }
890890 if ( $match !== false ) {
891891 $result['spam'] = $match;
892 - $ip = wfGetIP();
 892+ $ip = $wgRequest->getIP();
893893 $pdbk = $this->mTitle->getPrefixedDBkey();
894894 $match = str_replace( "\n", '', $match );
895895 wfDebugLog( 'SpamRegex', "$ip spam regex hit [[$pdbk]]: \"$match\"" );
Index: trunk/phase3/includes/WebRequest.php
@@ -44,6 +44,12 @@
4545 */
4646 private $response;
4747
 48+ /**
 49+ * Cached client IP address
 50+ * @var String
 51+ */
 52+ private $ip;
 53+
4854 public function __construct() {
4955 /// @todo FIXME: This preemptive de-quoting can interfere with other web libraries
5056 /// and increases our memory footprint. It would be cleaner to do on
@@ -962,6 +968,72 @@
963969 arsort( $langs, SORT_NUMERIC );
964970 return $langs;
965971 }
 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+ }
9661038 }
9671039
9681040 /**
@@ -1165,4 +1237,8 @@
11661238 public function checkUrlExtension( $extWhitelist = array() ) {
11671239 return true;
11681240 }
 1241+
 1242+ protected function getRawIP() {
 1243+ return '127.0.0.1';
 1244+ }
11691245 }
Index: trunk/phase3/includes/Title.php
@@ -1562,7 +1562,7 @@
15631563 if ( $reason == '' ) {
15641564 $reason = wfMsg( 'blockednoreason' );
15651565 }
1566 - $ip = wfGetIP();
 1566+ $ip = $user->getRequest()->getIP();
15671567
15681568 if ( is_numeric( $id ) ) {
15691569 $name = User::whoIs( $id );
Index: trunk/phase3/includes/SkinLegacy.php
@@ -889,7 +889,7 @@
890890 }
891891
892892 function nameAndLogin() {
893 - global $wgUser, $wgLang, $wgContLang;
 893+ global $wgUser, $wgLang, $wgRequest, $wgContLang;
894894
895895 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
896896
@@ -897,7 +897,7 @@
898898
899899 if ( $wgUser->isAnon() ) {
900900 if ( $this->getSkin()->showIPinHeader() ) {
901 - $name = wfGetIP();
 901+ $name = $wgRequest->getIP();
902902
903903 $talkLink = Linker::link( $wgUser->getTalkPage(),
904904 $wgLang->getNsText( NS_TALK ) );
Index: trunk/phase3/includes/specials/SpecialPasswordReset.php
@@ -162,7 +162,7 @@
163163
164164 // We need to have a valid IP address for the hook, but per bug 18347, we should
165165 // send the user's name if they're logged in.
166 - $ip = wfGetIP();
 166+ $ip = $this->getRequest()->getIP();
167167 if ( !$ip ) {
168168 return array( 'badipaddress' );
169169 }
Index: trunk/phase3/includes/specials/SpecialUserlogin.php
@@ -251,7 +251,7 @@
252252 * @private
253253 */
254254 function addNewAccountInternal() {
255 - global $wgUser, $wgOut;
 255+ global $wgUser, $wgOut, $wgRequest;
256256 global $wgMemc, $wgAccountCreationThrottle;
257257 global $wgAuth, $wgMinimalPasswordLength;
258258 global $wgEmailConfirmToEdit;
@@ -308,7 +308,7 @@
309309 return false;
310310 }
311311
312 - $ip = wfGetIP();
 312+ $ip = $wgRequest->getIP();
313313 if ( $wgUser->isDnsBlacklisted( $ip, true /* check $wgProxyWhitelist */ ) ) {
314314 $this->mainLoginForm( wfMsg( 'sorbs_create_account_reason' ) . ' (' . htmlspecialchars( $ip ) . ')' );
315315 return false;
@@ -588,12 +588,12 @@
589589 * @return Bool|Integer The integer hit count or True if it is already at the limit
590590 */
591591 public static function incLoginThrottle( $username ) {
592 - global $wgPasswordAttemptThrottle, $wgMemc;
 592+ global $wgPasswordAttemptThrottle, $wgMemc, $wgRequest;
593593 $username = trim( $username ); // sanity
594594
595595 $throttleCount = 0;
596596 if ( is_array( $wgPasswordAttemptThrottle ) ) {
597 - $throttleKey = wfMemcKey( 'password-throttle', wfGetIP(), md5( $username ) );
 597+ $throttleKey = wfMemcKey( 'password-throttle', $wgRequest->getIP(), md5( $username ) );
598598 $count = $wgPasswordAttemptThrottle['count'];
599599 $period = $wgPasswordAttemptThrottle['seconds'];
600600
@@ -616,10 +616,10 @@
617617 * @return void
618618 */
619619 public static function clearLoginThrottle( $username ) {
620 - global $wgMemc;
 620+ global $wgMemc, $wgRequest;
621621 $username = trim( $username ); // sanity
622622
623 - $throttleKey = wfMemcKey( 'password-throttle', wfGetIP(), md5( $username ) );
 623+ $throttleKey = wfMemcKey( 'password-throttle', $wgRequest->getIP(), md5( $username ) );
624624 $wgMemc->delete( $throttleKey );
625625 }
626626
@@ -682,7 +682,7 @@
683683 }
684684
685685 function processLogin() {
686 - global $wgUser;
 686+ global $wgUser, $wgRequest, $wgLang;
687687
688688 switch ( $this->authenticateUserData() ) {
689689 case self::SUCCESS:
@@ -697,7 +697,7 @@
698698 self::clearLoginToken();
699699
700700 // Reset the throttle
701 - $key = wfMemcKey( 'password-throttle', wfGetIP(), md5( $this->mUsername ) );
 701+ $key = wfMemcKey( 'password-throttle', $wgRequest->getIP(), md5( $this->mUsername ) );
702702 global $wgMemc;
703703 $wgMemc->delete( $key );
704704
@@ -705,7 +705,6 @@
706706 /* Replace the language object to provide user interface in
707707 * correct language immediately on this first page load.
708708 */
709 - global $wgLang, $wgRequest;
710709 $code = $wgRequest->getVal( 'uselang', $wgUser->getOption( 'language' ) );
711710 $wgLang = Language::factory( $code );
712711 return $this->successfulLogin();
@@ -779,12 +778,12 @@
780779 * @private
781780 */
782781 function mailPasswordInternal( $u, $throttle = true, $emailTitle = 'passwordremindertitle', $emailText = 'passwordremindertext' ) {
783 - global $wgServer, $wgScript, $wgUser, $wgNewPasswordExpiry;
 782+ global $wgServer, $wgScript, $wgUser, $wgNewPasswordExpiry, $wgRequest;
784783
785784 if ( $u->getEmail() == '' ) {
786785 return Status::newFatal( 'noemail', $u->getName() );
787786 }
788 - $ip = wfGetIP();
 787+ $ip = $wgRequest->getIP();
789788 if( !$ip ) {
790789 return Status::newFatal( 'badipaddress' );
791790 }
Index: trunk/phase3/includes/specials/SpecialBlockme.php
@@ -38,7 +38,7 @@
3939 $this->setHeaders();
4040 $this->outputHeader();
4141
42 - $ip = wfGetIP();
 42+ $ip = $wgRequest->getIP();
4343 if( !$wgBlockOpenProxies || $wgRequest->getText( 'ip' ) != md5( $ip . $wgProxyKey ) ) {
4444 $wgOut->addWikiMsg( 'proxyblocker-disabled' );
4545 return;
Index: trunk/phase3/includes/specials/SpecialVersion.php
@@ -502,7 +502,7 @@
503503 * @return String: HTML fragment
504504 */
505505 private function IPInfo() {
506 - $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
 506+ $ip = str_replace( '--', ' - ', htmlspecialchars( $this->getRequest()->getIP() ) );
507507 return "<!-- visited from $ip -->\n" .
508508 "<span style='display:none'>visited from $ip</span>";
509509 }
Index: trunk/phase3/includes/Autopromote.php
@@ -166,9 +166,9 @@
167167 $groups = array_slice( $cond, 1 );
168168 return count( array_intersect( $groups, $user->getGroups() ) ) == count( $groups );
169169 case APCOND_ISIP:
170 - return $cond[1] == wfGetIP();
 170+ return $cond[1] == $user->getRequest()->getIP();
171171 case APCOND_IPINRANGE:
172 - return IP::isInRange( wfGetIP(), $cond[1] );
 172+ return IP::isInRange( $user->getRequest()->getIP(), $cond[1] );
173173 case APCOND_BLOCKED:
174174 return $user->isBlocked();
175175 case APCOND_ISBOT:
Index: trunk/phase3/includes/Exception.php
@@ -352,7 +352,7 @@
353353 */
354354 class UserBlockedError extends ErrorPageError {
355355 public function __construct( Block $block ){
356 - global $wgLang;
 356+ global $wgLang, $wgRequest;
357357
358358 $blockerUserpage = $block->getBlocker()->getUserPage();
359359 $link = "[[{$blockerUserpage->getPrefixedText()}|{$blockerUserpage->getText()}]]";
@@ -372,7 +372,7 @@
373373 array(
374374 $link,
375375 $reason,
376 - wfGetIP(),
 376+ $wgRequest->getIP(),
377377 $block->getBlocker()->getName(),
378378 $block->getId(),
379379 $wgLang->formatExpiry( $block->mExpiry ),
Index: trunk/phase3/api.php
@@ -127,7 +127,7 @@
128128 $items = array(
129129 wfTimestamp( TS_MW ),
130130 $endtime - $starttime,
131 - wfGetIP(),
 131+ $wgRequest->getIP(),
132132 $_SERVER['HTTP_USER_AGENT']
133133 );
134134 $items[] = $wgRequest->wasPosted() ? 'POST' : 'GET';

Follow-up revisions

RevisionCommit summaryAuthorDate
r94934Removed debugging code from r94932ialex20:05, 18 August 2011
r94940Fix getRequet to getRequestreedy20:56, 18 August 2011
r110776Add @since to getIP/getRawIP...reedy20:20, 6 February 2012

Comments

#Comment by Reedy (talk | contribs)   20:58, 18 August 2011

Call to getRequet in User fixed in r94940

#Comment by Nikerabbit (talk | contribs)   10:39, 21 September 2011

Commit message does not mention wfGetAgent change, but that looks fine too.

#Comment by Hashar (talk | contribs)   22:10, 23 February 2012

On wikitech-l, Arthur Richards is wondering if WebRequest::getRawIP() could be made public:

http://permalink.gmane.org/gmane.science.linguistics.wikipedia.technical/58963

Status & tagging log