Remove $wgIP global, but add a hook instead.
authorPlatonides <platonides@users.mediawiki.org>
Sat, 11 Sep 2010 13:45:51 +0000 (13:45 +0000)
committerPlatonides <platonides@users.mediawiki.org>
Sat, 11 Sep 2010 13:45:51 +0000 (13:45 +0000)
This allows extensions to "make mediawiki ignore ips completely", as requested earlier today in #mediawiki

docs/hooks.txt
includes/ProxyTools.php
includes/Setup.php

index bbc1bed..e9c972e 100644 (file)
@@ -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.
index 60ff360..a0c48a2 100644 (file)
@@ -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;
 }
 
index 002c128..b2f87e7 100644 (file)
@@ -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;