Merge "(bug 39957) Added threshold for showing number of page watchers."
[lhc/web/wiklou.git] / includes / media / DjVuImage.php
index 6aef562..cad9c1b 100644 (file)
  * @ingroup Media
  */
 class DjVuImage {
+       /**
+        * Constructor
+        *
+        * @param string $filename The DjVu file name.
+        */
        function __construct( $filename ) {
                $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
@@ -228,7 +238,7 @@ class DjVuImage {
        function retrieveMetaData() {
                global $wgDjvuToXML, $wgDjvuDump, $wgDjvuTxt;
                wfProfileIn( __METHOD__ );
-               
+
                if ( isset( $wgDjvuDump ) ) {
                        # djvudump is faster as of version 3.5
                        # http://sourceforge.net/tracker/index.php?func=detail&aid=1704049&group_id=32953&atid=406583
@@ -247,12 +257,12 @@ class DjVuImage {
                        $xml = null;
                }
                # Text layer
-               if ( isset( $wgDjvuTxt ) ) { 
+               if ( isset( $wgDjvuTxt ) ) {
                        wfProfileIn( 'djvutxt' );
                        $cmd = wfEscapeShellArg( $wgDjvuTxt ) . ' --detail=page ' . wfEscapeShellArg( $this->mFilename ) ;
                        wfDebug( __METHOD__.": $cmd\n" );
                        $retval = '';
-                       $txt = wfShellExec( $cmd, $retval );
+                       $txt = wfShellExec( $cmd, $retval, array(), array( 'memory' => self::DJVUTXT_MEMORY_LIMIT ) );
                        wfProfileOut( 'djvutxt' );
                        if( $retval == 0) {
                                # Strip some control characters
@@ -260,7 +270,7 @@ class DjVuImage {
                                $reg = <<<EOR
                                        /\(page\s[\d-]*\s[\d-]*\s[\d-]*\s[\d-]*\s*"
                                        ((?>    # Text to match is composed of atoms of either:
-                                         \\\\. # - any escaped character 
+                                         \\\\. # - any escaped character
                                          |     # - any character different from " and \
                                          [^"\\\\]+
                                        )*?)