Merge "Add PreferencesFormPreSave hook"
[lhc/web/wiklou.git] / includes / utils / CdbPHP.php
index e7bb4bc..c178ffe 100644 (file)
@@ -69,7 +69,7 @@ class CdbFunctions {
         *
         * @param $s string
         *
-        * @return
+        * @return int
         */
        public static function hash( $s ) {
                $h = 5381;
@@ -103,9 +103,6 @@ class CdbReaderPHP extends CdbReader {
        /** The filename */
        var $fileName;
 
-       /** The file handle */
-       var $handle;
-
        /* number of hash slots searched under this key */
        var $loop;
 
@@ -129,18 +126,18 @@ class CdbReaderPHP extends CdbReader {
 
        /**
         * @param $fileName string
-        * @throws MWException
+        * @throws CdbException
         */
-       function __construct( $fileName ) {
+       public function __construct( $fileName ) {
                $this->fileName = $fileName;
                $this->handle = fopen( $fileName, 'rb' );
                if ( !$this->handle ) {
-                       throw new MWException( 'Unable to open CDB file "' . $this->fileName . '".' );
+                       throw new CdbException( 'Unable to open CDB file "' . $this->fileName . '".' );
                }
                $this->findStart();
        }
 
-       function close() {
+       public function close() {
                if ( isset( $this->handle ) ) {
                        fclose( $this->handle );
                }
@@ -176,7 +173,7 @@ class CdbReaderPHP extends CdbReader {
        }
 
        /**
-        * @throws MWException
+        * @throws CdbException
         * @param $length
         * @param $pos
         * @return string
@@ -184,7 +181,7 @@ class CdbReaderPHP extends CdbReader {
        protected function read( $length, $pos ) {
                if ( fseek( $this->handle, $pos ) == -1 ) {
                        // This can easily happen if the internal pointers are incorrect
-                       throw new MWException(
+                       throw new CdbException(
                                'Seek failed, file "' . $this->fileName . '" may be corrupted.' );
                }
 
@@ -194,7 +191,7 @@ class CdbReaderPHP extends CdbReader {
 
                $buf = fread( $this->handle, $length );
                if ( $buf === false || strlen( $buf ) !== $length ) {
-                       throw new MWException(
+                       throw new CdbException(
                                'Read from CDB file failed, file "' . $this->fileName . '" may be corrupted.' );
                }
 
@@ -204,13 +201,13 @@ class CdbReaderPHP extends CdbReader {
        /**
         * Unpack an unsigned integer and throw an exception if it needs more than 31 bits
         * @param $s
-        * @throws MWException
+        * @throws CdbException
         * @return mixed
         */
        protected function unpack31( $s ) {
                $data = unpack( 'V', $s );
                if ( $data[1] > 0x7fffffff ) {
-                       throw new MWException(
+                       throw new CdbException(
                                'Error in CDB file "' . $this->fileName . '", integer too big.' );
                }
 
@@ -291,15 +288,13 @@ class CdbReaderPHP extends CdbReader {
  * CDB writer class
  */
 class CdbWriterPHP extends CdbWriter {
-       var $handle, $realFileName, $tmpFileName;
-
        var $hplist;
        var $numentries, $pos;
 
        /**
         * @param $fileName string
         */
-       function __construct( $fileName ) {
+       public function __construct( $fileName ) {
                $this->realFileName = $fileName;
                $this->tmpFileName = $fileName . '.tmp.' . mt_rand( 0, 0x7fffffff );
                $this->handle = fopen( $this->tmpFileName, 'wb' );
@@ -315,16 +310,9 @@ class CdbWriterPHP extends CdbWriter {
                }
        }
 
-       function __destruct() {
-               if ( isset( $this->handle ) ) {
-                       $this->close();
-               }
-       }
-
        /**
-        * @param $key
-        * @param $value
-        * @return
+        * @param string $key
+        * @param string $value
         */
        public function set( $key, $value ) {
                if ( strval( $key ) === '' ) {
@@ -338,14 +326,14 @@ class CdbWriterPHP extends CdbWriter {
        }
 
        /**
-        * @throws MWException
+        * @throws CdbException
         */
        public function close() {
                $this->finish();
                if ( isset( $this->handle ) ) {
                        fclose( $this->handle );
                }
-               if ( wfIsWindows() && file_exists( $this->realFileName ) ) {
+               if ( $this->isWindows() && file_exists( $this->realFileName ) ) {
                        unlink( $this->realFileName );
                }
                if ( !rename( $this->tmpFileName, $this->realFileName ) ) {
@@ -355,7 +343,7 @@ class CdbWriterPHP extends CdbWriter {
        }
 
        /**
-        * @throws MWException
+        * @throws CdbException
         * @param $buf
         */
        protected function write( $buf ) {
@@ -366,7 +354,7 @@ class CdbWriterPHP extends CdbWriter {
        }
 
        /**
-        * @throws MWException
+        * @throws CdbException
         * @param $len
         */
        protected function posplus( $len ) {
@@ -396,7 +384,7 @@ class CdbWriterPHP extends CdbWriter {
        }
 
        /**
-        * @throws MWException
+        * @throws CdbException
         * @param $keylen
         * @param $datalen
         */
@@ -412,7 +400,7 @@ class CdbWriterPHP extends CdbWriter {
        }
 
        /**
-        * @throws MWException
+        * @throws CdbException
         */
        protected function finish() {
                // Hack for DBA cross-check
@@ -491,13 +479,13 @@ class CdbWriterPHP extends CdbWriter {
         * Clean up the temp file and throw an exception
         *
         * @param $msg string
-        * @throws MWException
+        * @throws CdbException
         */
        protected function throwException( $msg ) {
                if ( $this->handle ) {
                        fclose( $this->handle );
                        unlink( $this->tmpFileName );
                }
-               throw new MWException( $msg );
+               throw new CdbException( $msg );
        }
 }