Implemented param tracking for hook users, feels a bit hackish
[lhc/web/wiklou.git] / includes / MacBinary.php
index ad8fe4b..6643c07 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
- * @package MediaWiki
- * @subpackage SpecialPage
+ * @ingroup SpecialPage
  */
 
 class MacBinary {
-       function MacBinary( $filename ) {
+       function __construct( $filename ) {
                $this->open( $filename );
                $this->loadHeader();
        }
@@ -36,7 +35,7 @@ class MacBinary {
         * The file must be seekable, such as local filesystem.
         * Remote URLs probably won't work.
         *
-        * @param string $filename
+        * @param $filename String
         */
        function open( $filename ) {
                $this->valid = false;
@@ -49,7 +48,8 @@ class MacBinary {
 
        /**
         * Does this appear to be a valid MacBinary archive?
-        * @return bool
+        *
+        * @return Boolean
         */
        function isValid() {
                return $this->valid;
@@ -57,7 +57,8 @@ class MacBinary {
 
        /**
         * Get length of data fork
-        * @return int
+        *
+        * @return Integer
         */
        function dataForkLength() {
                return $this->dataLength;
@@ -65,8 +66,9 @@ class MacBinary {
 
        /**
         * Copy the data fork to an external file or resource.
-        * @param resource $destination
-        * @return bool
+        *
+        * @param $destination Ressource
+        * @return Boolean
         */
        function extractData( $destination ) {
                if( !$this->isValid() ) {
@@ -101,14 +103,14 @@ class MacBinary {
 
                fseek( $this->handle, 0 );
                $head = fread( $this->handle, 128 );
-               $this->hexdump( $head );
+               #$this->hexdump( $head );
 
                if( strlen( $head ) < 128 ) {
                        wfDebug( "$fname: couldn't read full MacBinary header\n" );
                        return false;
                }
 
-               if( $head{0} != "\x00" || $head{74} != "\x00" ) {
+               if( $head[0] != "\x00" || $head[74] != "\x00" ) {
                        wfDebug( "$fname: header bytes 0 and 74 not null\n" );
                        return false;
                }
@@ -125,7 +127,7 @@ class MacBinary {
                        }
                } else {
                        $crc = sprintf( "%x != %x", $storedCRC, $calculatedCRC );
-                       if( $storedCRC == 0 && $head{82} == "\x00" &&
+                       if( $storedCRC == 0 && $head[82] == "\x00" &&
                                substr( $head, 101, 24 ) == str_repeat( "\x00", 24 ) ) {
                                wfDebug( "$fname: no CRC, looks like MacBinary I\n" );
                                $this->version = 1;
@@ -140,7 +142,7 @@ class MacBinary {
                        }
                }
 
-               $nameLength = ord( $head{1} );
+               $nameLength = ord( $head[1] );
                if( $nameLength < 1 || $nameLength > 63 ) {
                        wfDebug( "$fname: invalid filename size $nameLength\n" );
                        return false;
@@ -174,9 +176,9 @@ class MacBinary {
         * with magic array thingy by Jim Van Verth.
         * http://search.cpan.org/~eryq/Convert-BinHex-1.119/lib/Convert/BinHex.pm
         *
-        * @param string $data
-        * @param int $seed
-        * @return int
+        * @param $data String
+        * @param $seed Integer
+        * @return Integer
         * @access private
         */
        function calcCRC( $data, $seed = 0 ) {
@@ -218,7 +220,7 @@ class MacBinary {
                $len = strlen( $data );
                $crc = $seed;
                for( $i = 0; $i < $len; $i++ ) {
-                       $crc ^= ord( $data{$i} ) << 8;
+                       $crc ^= ord( $data[$i] ) << 8;
                        $crc &= 0xFFFF;
                        $crc = ($crc << 8) ^ $MAGIC[$crc >> 8];
                        $crc &= 0xFFFF;
@@ -227,9 +229,9 @@ class MacBinary {
        }
 
        /**
-        * @param resource $destination
-        * @param int $bytesToCopy
-        * @return bool
+        * @param $destination Resource
+        * @param $bytesToCopy Integer
+        * @return Boolean
         * @access private
         */
        function copyBytesTo( $destination, $bytesToCopy ) {
@@ -254,16 +256,17 @@ class MacBinary {
                for( $remaining = strlen( $data ); $remaining > 0; $remaining -= $width ) {
                        $line = sprintf( "%04x:", $at );
                        $printable = '';
-                       for( $i = 0; $i < $width; $i++ ) {
-                               $byte = ord( $data{$at++} );
+                       for( $i = 0; $i < $width && $remaining - $i > 0; $i++ ) {
+                               $byte = ord( $data[$at++] );
                                $line .= sprintf( " %02x", $byte );
                                $printable .= ($byte >= 32 && $byte <= 126 )
                                        ? chr( $byte )
                                        : '.';
                        }
+                       if( $i < $width ) {
+                               $line .= str_repeat( '   ', $width - $i );
+                       }
                        wfDebug( "MacBinary: $line $printable\n" );
                }
        }
 }
-
-?>
\ No newline at end of file