Legoktm has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/176709

Change subject: Move TrustedXFF class into its own file
......................................................................

Move TrustedXFF class into its own file

Change-Id: I0eed5816841797d29b87d3c1964621b62ed7ac46
---
A TrustedXFF.body.php
M TrustedXFF.php
2 files changed, 67 insertions(+), 66 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TrustedXFF 
refs/changes/09/176709/1

diff --git a/TrustedXFF.body.php b/TrustedXFF.body.php
new file mode 100644
index 0000000..0b7612f
--- /dev/null
+++ b/TrustedXFF.body.php
@@ -0,0 +1,66 @@
+<?php
+
+class TrustedXFF {
+       static $instance;
+
+       public $cdb;
+
+       // FIXME: IPv6 ranges need to be put here for now, there is no
+       // trusted-hosts.txt support. The ranges are too large to be expanded 
with
+       // the current CDB system.
+       static $ipv6Ranges = array(
+               // Opera Mini
+               // Source: Email 22-May-2013
+               '2001:4c28:1::/48',
+               '2001:4c28:2000::/36',
+               '2001:4c28:3000::/36'
+       );
+
+       static function onIsTrustedProxy( &$ip, &$trusted ) {
+               // Don't want to override hosts that are already trusted
+               if ( !$trusted ) {
+                       $trusted = self::getInstance()->isTrusted( $ip );
+               }
+               return true;
+       }
+
+       static function getInstance() {
+               if ( !self::$instance ) {
+                       self::$instance = new TrustedXFF;
+               }
+               return self::$instance;
+       }
+
+       function getCdbHandle() {
+               if ( !$this->cdb ) {
+                       global $wgTrustedXffFile;
+                       if ( !file_exists( $wgTrustedXffFile ) ) {
+                               throw new MWException( 'TrustedXFF: hosts file 
missing. You need to download it.' );
+                       }
+                       $this->cdb = CdbReader::open( $wgTrustedXffFile );
+               }
+               return $this->cdb;
+       }
+
+       function isTrusted( $ip ) {
+               $cdb = $this->getCdbHandle();
+               // Try single host
+               $hex = IP::toHex( $ip );
+               $data = $cdb->get( $hex );
+               if ( $data ) {
+                       return true;
+               }
+
+               // Try IPv6 ranges
+               if ( substr( $hex, 0, 2 ) === 'v6' ) {
+                       foreach ( self::$ipv6Ranges as $range ) {
+                               list( $start, $end ) = IP::parseRange( $range );
+                               if ( $hex >= $start && $hex <= $end ) {
+                                       return true;
+                               }
+                       }
+               }
+
+               return false;
+       }
+}
diff --git a/TrustedXFF.php b/TrustedXFF.php
index ef95c26..4431b10 100644
--- a/TrustedXFF.php
+++ b/TrustedXFF.php
@@ -26,72 +26,7 @@
        'url'            => 
'https://www.mediawiki.org/wiki/Extension:TrustedXFF',
 );
 
+$wgAutoloadClasses['TrustedXFF'] = __DIR__ . '/TrustedXFF.body.php';
 $wgMessagesDirs['TrustedXFF'] = __DIR__ . '/i18n';
 $wgExtensionMessagesFiles['TrustedXFF'] = __DIR__ . '/TrustedXFF.i18n.php';
 $wgHooks['IsTrustedProxy'][] = 'TrustedXFF::onIsTrustedProxy';
-
-class TrustedXFF {
-       static $instance;
-
-       public $cdb;
-
-       // FIXME: IPv6 ranges need to be put here for now, there is no
-       // trusted-hosts.txt support. The ranges are too large to be expanded 
with
-       // the current CDB system.
-       static $ipv6Ranges = array(
-               // Opera Mini
-               // Source: Email 22-May-2013
-               '2001:4c28:1::/48',
-               '2001:4c28:2000::/36',
-               '2001:4c28:3000::/36'
-       );
-
-       static function onIsTrustedProxy( &$ip, &$trusted ) {
-               // Don't want to override hosts that are already trusted
-               if ( !$trusted ) {
-                       $trusted = self::getInstance()->isTrusted( $ip );
-               }
-               return true;
-       }
-
-       static function getInstance() {
-               if ( !self::$instance ) {
-                       self::$instance = new TrustedXFF;
-               }
-               return self::$instance;
-       }
-
-       function getCdbHandle() {
-               if ( !$this->cdb ) {
-                       global $wgTrustedXffFile;
-                       if ( !file_exists( $wgTrustedXffFile ) ) {
-                               throw new MWException( 'TrustedXFF: hosts file 
missing. You need to download it.' );
-                       }
-                       $this->cdb = CdbReader::open( $wgTrustedXffFile );
-               }
-               return $this->cdb;
-       }
-
-       function isTrusted( $ip ) {
-               $cdb = $this->getCdbHandle();
-               // Try single host
-               $hex = IP::toHex( $ip );
-               $data = $cdb->get( $hex );
-               if ( $data ) {
-                       return true;
-               }
-
-               // Try IPv6 ranges
-               if ( substr( $hex, 0, 2 ) === 'v6' ) {
-                       foreach ( self::$ipv6Ranges as $range ) {
-                               list( $start, $end ) = IP::parseRange( $range );
-                               if ( $hex >= $start && $hex <= $end ) {
-                                       return true;
-                               }
-                       }
-               }
-
-               return false;
-       }
-}
-

-- 
To view, visit https://gerrit.wikimedia.org/r/176709
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0eed5816841797d29b87d3c1964621b62ed7ac46
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TrustedXFF
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to