r72803 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72802‎ | r72803 | r72804 >
Date:13:45, 11 September 2010
Author:platonides
Status:ok (Comments)
Tags:
Comment:
Remove $wgIP global, but add a hook instead.
This allows extensions to "make mediawiki ignore ips completely", as requested earlier today in #mediawiki
Modified paths:
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/ProxyTools.php (modified) (history)
  • /trunk/phase3/includes/Setup.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -826,6 +826,9 @@
827827 $url: string value as output (out parameter, can modify)
828828 $query: query options passed to Title::getInternalURL()
829829
 830+'GetIP': modify the ip of the current user (called only once)
 831+&$ip: string holding the ip as determined so far
 832+
830833 'GetLinkColours': modify the CSS class of an array of page links
831834 $linkcolour_ids: array of prefixed DB keys of the pages linked to,
832835 indexed by page_id.
Index: trunk/phase3/includes/ProxyTools.php
@@ -68,15 +68,15 @@
6969 * @return string
7070 */
7171 function wfGetIP() {
72 - global $wgIP, $wgUsePrivateIPs, $wgCommandLineMode;
 72+ global $wgUsePrivateIPs, $wgCommandLineMode;
 73+ static $ip = false;
7374
7475 # Return cached result
75 - if ( !empty( $wgIP ) ) {
76 - return $wgIP;
 76+ if ( !empty( $ip ) ) {
 77+ return $ip;
7778 }
7879
7980 $ipchain = array();
80 - $ip = false;
8181
8282 /* collect the originating ips */
8383 # Client connecting to this webserver
@@ -112,12 +112,14 @@
113113 }
114114 }
115115
 116+ # Allow extensions to improve our guess
 117+ wfRunHooks( 'GetIP', array( &$ip ) );
 118+
116119 if( !$ip ) {
117120 throw new MWException( "Unable to determine IP" );
118121 }
119122
120123 wfDebug( "IP: $ip\n" );
121 - $wgIP = $ip;
122124 return $ip;
123125 }
124126
Index: trunk/phase3/includes/Setup.php
@@ -182,7 +182,6 @@
183183 date_default_timezone_set( date_default_timezone_get() );
184184 wfRestoreWarnings();
185185
186 -$wgIP = false; # Load on demand
187186 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
188187 $wgRequest = new WebRequest;
189188

Follow-up revisions

RevisionCommit summaryAuthorDate
r72876Release notes for r72803platonides17:26, 12 September 2010

Comments

#Comment by Bryan (talk | contribs)   14:37, 11 September 2010

RELEASE-NOTES, breaks backwards compatibility.

#Comment by Nikerabbit (talk | contribs)   19:45, 11 September 2010

With what? It looks to me that $wgIP was never documented as something that could be used.

#Comment by Platonides (talk | contribs)   19:48, 11 September 2010

It was a global for internal usage.

For reading (nothing used it), the documented way is wfGetIP()

And for writing, it is initialised after LocalSettings

#Comment by Bryan (talk | contribs)   19:51, 11 September 2010

Ok.

#Comment by 😂 (talk | contribs)   15:08, 12 September 2010

New hook still needs RELEASE-NOTES mention.

#Comment by Platonides (talk | contribs)   17:39, 12 September 2010

Added in r72876

#Comment by Tim Starling (talk | contribs)   02:21, 15 September 2010

$wgIP was originally the only way to access the IP address. However, it was expensive to initialise it on every request, so in r10905 I changed it to be lazy-initialised, and I migrated all existing uses from $wgIP to wfGetIP(). It was never intended to be modified by extensions, and using a hook instead is fine by me.

Status & tagging log