From 32b3fa74f0f1c13a351647e0219745db08640319 Mon Sep 17 00:00:00 2001 From: Platonides Date: Sat, 11 Sep 2010 13:45:51 +0000 Subject: [PATCH] Remove $wgIP global, but add a hook instead. This allows extensions to "make mediawiki ignore ips completely", as requested earlier today in #mediawiki --- docs/hooks.txt | 3 +++ includes/ProxyTools.php | 12 +++++++----- includes/Setup.php | 1 - 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/hooks.txt b/docs/hooks.txt index bbc1bed88e..e9c972e2ba 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -826,6 +826,9 @@ $title: Title object of page $url: string value as output (out parameter, can modify) $query: query options passed to Title::getInternalURL() +'GetIP': modify the ip of the current user (called only once) +&$ip: string holding the ip as determined so far + 'GetLinkColours': modify the CSS class of an array of page links $linkcolour_ids: array of prefixed DB keys of the pages linked to, indexed by page_id. diff --git a/includes/ProxyTools.php b/includes/ProxyTools.php index 60ff360d9f..a0c48a2c9a 100644 --- a/includes/ProxyTools.php +++ b/includes/ProxyTools.php @@ -68,15 +68,15 @@ function wfGetAgent() { * @return string */ function wfGetIP() { - global $wgIP, $wgUsePrivateIPs, $wgCommandLineMode; + global $wgUsePrivateIPs, $wgCommandLineMode; + static $ip = false; # Return cached result - if ( !empty( $wgIP ) ) { - return $wgIP; + if ( !empty( $ip ) ) { + return $ip; } $ipchain = array(); - $ip = false; /* collect the originating ips */ # Client connecting to this webserver @@ -112,12 +112,14 @@ function wfGetIP() { } } + # Allow extensions to improve our guess + wfRunHooks( 'GetIP', array( &$ip ) ); + if( !$ip ) { throw new MWException( "Unable to determine IP" ); } wfDebug( "IP: $ip\n" ); - $wgIP = $ip; return $ip; } diff --git a/includes/Setup.php b/includes/Setup.php index 002c128034..b2f87e7f89 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -182,7 +182,6 @@ wfSuppressWarnings(); date_default_timezone_set( date_default_timezone_get() ); wfRestoreWarnings(); -$wgIP = false; # Load on demand # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor $wgRequest = new WebRequest; -- 2.20.1