Merge "Normalize newlines in DjVu text-layer metadata."
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Sat, 7 Dec 2013 00:20:43 +0000 (00:20 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Sat, 7 Dec 2013 00:20:43 +0000 (00:20 +0000)
1  2 
includes/media/DjVuImage.php

   * @ingroup Media
   */
  class DjVuImage {
 +      /**
 +       * @const DJVUTXT_MEMORY_LIMIT Memory limit for the DjVu description software
 +       */
 +      const DJVUTXT_MEMORY_LIMIT = 300000;
 +
        /**
         * Constructor
         *
                $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
@@@ -87,8 -87,6 +87,8 @@@
                // @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 );
                        // @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' ) {
                        // 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' ) {
                        // something that explicitly initializes local variables.
                        extract( unpack( 'a4chunk/Nlength', $header ) );
  
 +                      /** @var string $chunk
 +                       *  @var string $length */
                        return array( $chunk, $length );
                }
        }
  
                # 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,
@@@ -323,13 -306,14 +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 $dump
 +       * @return string
         */
        function convertDumpToXML( $dump ) {
                if ( strval( $dump ) == '' ) {