From d9022f63880ce039446fba8364f68e656b7bf4cb Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 3 May 2012 13:01:35 +0200 Subject: Update to MediaWiki 1.19.0 --- includes/ZipDirectoryReader.php | 124 +++++++++++++++++++++------------------- 1 file changed, 64 insertions(+), 60 deletions(-) (limited to 'includes/ZipDirectoryReader.php') diff --git a/includes/ZipDirectoryReader.php b/includes/ZipDirectoryReader.php index d21cf3b0..37934aea 100644 --- a/includes/ZipDirectoryReader.php +++ b/includes/ZipDirectoryReader.php @@ -1,8 +1,8 @@ getBlock( $startPos ); $sigPos = strrpos( $block, "PK\x05\x06" ); if ( $sigPos === false ) { - $this->error( 'zip-wrong-format', + $this->error( 'zip-wrong-format', "zip file lacks EOCDR signature. It probably isn't a zip file." ); } @@ -212,7 +213,7 @@ class ZipDirectoryReader { } /** - * Read the header called the "ZIP64 end of central directory locator". An + * Read the header called the "ZIP64 end of central directory locator". An * error will be raised if it does not exist. */ function readZip64EndOfCentralDirectoryLocator() { @@ -224,20 +225,20 @@ class ZipDirectoryReader { ); $structSize = $this->getStructSize( $info ); - $block = $this->getBlock( $this->getFileLength() - $this->eocdr['EOCDR size'] + $block = $this->getBlock( $this->getFileLength() - $this->eocdr['EOCDR size'] - $structSize, $structSize ); $this->eocdr64Locator = $data = $this->unpack( $block, $info ); if ( $data['signature'] !== "PK\x06\x07" ) { - // Note: Java will allow this and continue to read the - // EOCDR64, so we have to reject the upload, we can't + // Note: Java will allow this and continue to read the + // EOCDR64, so we have to reject the upload, we can't // just use the EOCDR header instead. $this->error( 'zip-bad', 'wrong signature on Zip64 end of central directory locator' ); } } /** - * Read the header called the "ZIP64 end of central directory record". It + * Read the header called the "ZIP64 end of central directory record". It * may replace the regular "end of central directory record" in ZIP64 files. */ function readZip64EndOfCentralDirectoryRecord() { @@ -266,14 +267,14 @@ class ZipDirectoryReader { $this->error( 'zip-bad', 'wrong signature on Zip64 end of central directory record' ); } if ( $data['disk'] !== 0 - || $data['CD start disk'] !== 0 ) + || $data['CD start disk'] !== 0 ) { $this->error( 'zip-unsupported', 'more than one disk (in EOCDR64)' ); } } /** - * Find the location of the central directory, as would be seen by a + * Find the location of the central directory, as would be seen by a * non-ZIP64 reader. * * @return List containing offset, size and end position. @@ -286,27 +287,27 @@ class ZipDirectoryReader { // Some readers use the EOCDR position instead of the offset field // to find the directory, so to be safe, we check if they both agree. if ( $offset + $size != $endPos ) { - $this->error( 'zip-bad', 'the central directory does not immediately precede the end ' . + $this->error( 'zip-bad', 'the central directory does not immediately precede the end ' . 'of central directory record' ); } return array( $offset, $size ); } /** - * Find the location of the central directory, as would be seen by a + * Find the location of the central directory, as would be seen by a * ZIP64-compliant reader. * * @return List containing offset, size and end position. */ function findZip64CentralDirectory() { - // The spec is ambiguous about the exact rules of precedence between the - // ZIP64 headers and the original headers. Here we follow zip_util.c + // The spec is ambiguous about the exact rules of precedence between the + // ZIP64 headers and the original headers. Here we follow zip_util.c // from OpenJDK 7. $size = $this->eocdr['CD size']; $offset = $this->eocdr['CD offset']; $numEntries = $this->eocdr['CD entries total']; $endPos = $this->eocdr['position']; - if ( $size == 0xffffffff + if ( $size == 0xffffffff || $offset == 0xffffffff || $numEntries == 0xffff ) { @@ -324,7 +325,7 @@ class ZipDirectoryReader { // Some readers use the EOCDR position instead of the offset field // to find the directory, so to be safe, we check if they both agree. if ( $offset + $size != $endPos ) { - $this->error( 'zip-bad', 'the central directory does not immediately precede the end ' . + $this->error( 'zip-bad', 'the central directory does not immediately precede the end ' . 'of central directory record' ); } return array( $offset, $size ); @@ -390,7 +391,7 @@ class ZipDirectoryReader { } // Convert the timestamp into MediaWiki format - // For the format, please see the MS-DOS 2.0 Programmer's Reference, + // For the format, please see the MS-DOS 2.0 Programmer's Reference, // pages 3-5 and 3-6. $time = $data['mod time']; $date = $data['mod date']; @@ -405,8 +406,8 @@ class ZipDirectoryReader { $year, $month, $day, $hour, $minute, $second ); // Convert the character set in the file name - if ( !function_exists( 'iconv' ) - || $this->testBit( $data['general bits'], self::GENERAL_UTF8 ) ) + if ( !function_exists( 'iconv' ) + || $this->testBit( $data['general bits'], self::GENERAL_UTF8 ) ) { $name = $data['name']; } else { @@ -444,7 +445,7 @@ class ZipDirectoryReader { while ( $extraPos < strlen( $extraField ) ) { $extra = $this->unpack( $extraField, $extraHeaderInfo, $extraPos ); $extraPos += $extraHeaderSize; - $extra += $this->unpack( $extraField, + $extra += $this->unpack( $extraField, array( 'data' => array( 'string', $extra['size'] ) ), $extraPos ); $extraPos += $extra['size']; @@ -473,7 +474,7 @@ class ZipDirectoryReader { * in the file to satisfy the request, an exception will be thrown. * * @param $start The byte offset of the start of the block. - * @param $length The number of bytes to return. If omitted, the remainder + * @param $length The number of bytes to return. If omitted, the remainder * of the file will be returned. * * @return string @@ -500,10 +501,10 @@ class ZipDirectoryReader { $block .= $this->getSegment( $segIndex ); } - $block = substr( $block, + $block = substr( $block, $start - $startSeg * self::SEGSIZE, $length ); - + if ( strlen( $block ) < $length ) { $this->error( 'zip-bad', 'getBlock() returned an unexpectedly small amount of data' ); } @@ -512,12 +513,12 @@ class ZipDirectoryReader { } /** - * Get a section of the file starting at position $segIndex * self::SEGSIZE, - * of length self::SEGSIZE. The result is cached. This is a helper function + * Get a section of the file starting at position $segIndex * self::SEGSIZE, + * of length self::SEGSIZE. The result is cached. This is a helper function * for getBlock(). * - * If there are not enough bytes in the file to satsify the request, the - * return value will be truncated. If a request is made for a segment beyond + * If there are not enough bytes in the file to satsify the request, the + * return value will be truncated. If a request is made for a segment beyond * the end of the file, an empty string will be returned. */ function getSegment( $segIndex ) { @@ -556,25 +557,25 @@ class ZipDirectoryReader { } /** - * Unpack a binary structure. This is like the built-in unpack() function + * Unpack a binary structure. This is like the built-in unpack() function * except nicer. * * @param $string The binary data input * - * @param $struct An associative array giving structure members and their - * types. In the key is the field name. The value may be either an - * integer, in which case the field is a little-endian unsigned integer - * encoded in the given number of bytes, or an array, in which case the - * first element of the array is the type name, and the subsequent + * @param $struct An associative array giving structure members and their + * types. In the key is the field name. The value may be either an + * integer, in which case the field is a little-endian unsigned integer + * encoded in the given number of bytes, or an array, in which case the + * first element of the array is the type name, and the subsequent * elements are type-dependent parameters. Only one such type is defined: - * - "string": The second array element gives the length of string. + * - "string": The second array element gives the length of string. * Not null terminated. * * @param $offset The offset into the string at which to start unpacking. * - * @return Unpacked associative array. Note that large integers in the input - * may be represented as floating point numbers in the return value, so - * the use of weak comparison is advised. + * @return Unpacked associative array. Note that large integers in the input + * may be represented as floating point numbers in the return value, so + * the use of weak comparison is advised. */ function unpack( $string, $struct, $offset = 0 ) { $size = $this->getStructSize( $struct ); @@ -600,8 +601,8 @@ class ZipDirectoryReader { $length = intval( $type ); $bytes = substr( $string, $pos, $length ); - // Calculate the value. Use an algorithm which automatically - // upgrades the value to floating point if necessary. + // Calculate the value. Use an algorithm which automatically + // upgrades the value to floating point if necessary. $value = 0; for ( $i = $length - 1; $i >= 0; $i-- ) { $value *= 256; @@ -623,7 +624,7 @@ class ZipDirectoryReader { } /** - * Returns a bit from a given position in an integer value, converted to + * Returns a bit from a given position in an integer value, converted to * boolean. * * @param $value integer @@ -678,6 +679,9 @@ class ZipDirectoryReaderError extends Exception { parent::__construct( "ZipDirectoryReader error: $code" ); } + /** + * @return mixed + */ function getErrorCode() { return $this->code; } -- cgit v1.2.3-54-g00ecf