Update OOjs UI to v0.1.0-pre (0fbf6bd14e)
[lhc/web/wiklou.git] / includes / media / DjVuImage.php
index 9bfc378..099375b 100644 (file)
@@ -3,7 +3,7 @@
  * DjVu image handler.
  *
  * Copyright © 2006 Brion Vibber <brion@pobox.com>
- * http://www.mediawiki.org/
+ * https://www.mediawiki.org/
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * @ingroup Media
  */
 class DjVuImage {
+       /**
+        * @const DJVUTXT_MEMORY_LIMIT Memory limit for the DjVu description software
+        */
+       const DJVUTXT_MEMORY_LIMIT = 300000;
+
        /**
         * Constructor
         *
@@ -43,11 +48,6 @@ class DjVuImage {
                $this->mFilename = $filename;
        }
 
-       /**
-        * @const DJVUTXT_MEMORY_LIMIT Memory limit for the DjVu description software
-        */
-       const DJVUTXT_MEMORY_LIMIT = 300000;
-
        /**
         * Check if the given file is indeed a valid DjVu image file
         * @return bool
@@ -60,7 +60,7 @@ class DjVuImage {
 
        /**
         * Return data in the style of getimagesize()
-        * @return array or false on failure
+        * @return array|bool Array or false on failure
         */
        public function getImageSize() {
                $data = $this->getInfo();
@@ -87,6 +87,8 @@ class DjVuImage {
                // @todo FIXME: Would be good to replace this extract() call with
                // something that explicitly initializes local variables.
                extract( unpack( 'a4magic/a4chunk/NchunkLength', $header ) );
+               /** @var string $chunk
+                *  @var string $chunkLength */
                echo "$chunk $chunkLength\n";
                $this->dumpForm( $file, $chunkLength, 1 );
                fclose( $file );
@@ -104,6 +106,8 @@ class DjVuImage {
                        // @todo FIXME: Would be good to replace this extract() call with
                        // something that explicitly initializes local variables.
                        extract( unpack( 'a4chunk/NchunkLength', $chunkHeader ) );
+                       /** @var string $chunk
+                        *  @var string $chunkLength */
                        echo str_repeat( ' ', $indent * 4 ) . "$chunk $chunkLength\n";
 
                        if ( $chunk == 'FORM' ) {
@@ -138,6 +142,10 @@ class DjVuImage {
                        // something that explicitly initializes local variables.
                        extract( unpack( 'a4magic/a4form/NformLength/a4subtype', $header ) );
 
+                       /** @var string $magic
+                        *  @var string $subtype
+                        *  @var string $formLength
+                        *  @var string $formType */
                        if ( $magic != 'AT&T' ) {
                                wfDebug( __METHOD__ . ": not a DjVu file\n" );
                        } elseif ( $subtype == 'DJVU' ) {
@@ -164,6 +172,8 @@ class DjVuImage {
                        // something that explicitly initializes local variables.
                        extract( unpack( 'a4chunk/Nlength', $header ) );
 
+                       /** @var string $chunk
+                        *  @var string $length */
                        return array( $chunk, $length );
                }
        }
@@ -238,6 +248,13 @@ class DjVuImage {
 
                # Newer files have rotation info in byte 10, but we don't use it yet.
 
+               /** @var string $width
+                *  @var string $height
+                *  @var string $major
+                *  @var string $minor
+                *  @var string $resolution
+                *  @var string $length
+                *  @var string $gamma */
                return array(
                        'width' => $width,
                        'height' => $height,
@@ -306,12 +323,15 @@ EOR;
 
        function pageTextCallback( $matches ) {
                # Get rid of invalid UTF-8, strip control characters
-               return '<PAGE value="' . htmlspecialchars( UtfNormal::cleanUp( $matches[1] ) ) . '" />';
+               $val = htmlspecialchars( UtfNormal::cleanUp( stripcslashes( $matches[1] ) ) );
+               $val = str_replace( array( "\n", '�' ), array( '&#10;', '' ), $val );
+               return '<PAGE value="' . $val . '" />';
        }
 
        /**
         * Hack to temporarily work around djvutoxml bug
-        * @return bool|string
+        * @param string $dump
+        * @return string
         */
        function convertDumpToXML( $dump ) {
                if ( strval( $dump ) == '' ) {