Tim Starling has uploaded a new change for review.

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

Change subject: Use MW's CDB compatibility wrapper
......................................................................

Use MW's CDB compatibility wrapper

Since it exists now, it's the obvious choice. Also, HHVM doesn't have the
DBA extension at present.

Change-Id: I19893a130d94e8d6b97de800656df1f0e2a92f58
---
M TrustedXFF.php
M generate.php
2 files changed, 8 insertions(+), 10 deletions(-)


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

diff --git a/TrustedXFF.php b/TrustedXFF.php
index be4ba44..ae52aa5 100644
--- a/TrustedXFF.php
+++ b/TrustedXFF.php
@@ -65,10 +65,7 @@
                        if ( !file_exists( $wgTrustedXffFile ) ) {
                                throw new MWException( 'TrustedXFF: hosts file 
missing. You need to download it.' );
                        }
-                       if ( !function_exists( 'dba_open' ) ) {
-                               throw new MWException( 'The TrustedXFF 
extension needs PHP\'s DBA module to work.' );
-                       }
-                       $this->cdb = dba_open( $wgTrustedXffFile, 'r-', 'cdb' );
+                       $this->cdb = CdbReader::open( $wgTrustedXffFile );
                }
                return $this->cdb;
        }
@@ -77,7 +74,7 @@
                $cdb = $this->getCdbHandle();
                // Try single host
                $hex = IP::toHex( $ip );
-               $data = dba_fetch( $hex, $cdb );
+               $data = $cdb->get( $hex );
                if ( $data ) {
                        return true;
                }
diff --git a/generate.php b/generate.php
index 455abda..a364f81 100644
--- a/generate.php
+++ b/generate.php
@@ -23,8 +23,9 @@
        echo "The TrustedXffFile extension is not enabled. Try specifing the 
target output file name on the command line!\n";
        exit( 1 );
 }
-$outFile = dba_open( $target, 'n', 'cdb' );
-if ( !$outFile ) {
+try {
+       $outFile = CdbWriter::open( $target );
+} catch ( CdbException $e ) {
        echo "Unable to open output file \"$target\"\n";
        exit( 1 );
 }
@@ -86,7 +87,7 @@
 
        if ( $start === $end ) {
                // Single host
-               dba_insert( $start, '1', $outFile );
+               $outFile->set( $start, '1' );
                $numHosts++;
                showProgress( $i, count( $ranges ) );
                continue;
@@ -119,14 +120,14 @@
        for ( $j = $startNum; $j <= $endNum; $j++ ) {
                $hex = strtoupper( base_convert( $j, 10, 16 ) );
                $hex = str_pad( $hex, $suffixLength, '0', STR_PAD_LEFT );
-               dba_insert( $prefix . $hex, '1', $outFile );
+               $outFile->set( $prefix . $hex, '1' );
                $numHosts++;
        }
        showProgress( $i, count( $ranges ) );
 }
 echo "\n";
 
-dba_close( $outFile );
+$outFile->close();
 echo "$numHosts hosts listed\n";
 
 

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

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

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

Reply via email to