r51399 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51398‎ | r51399 | r51400 >
Date:13:07, 3 June 2009
Author:thomasv
Status:ok
Tags:
Comment:
reverting r50050. djvu text should be stored in img_metadata (per Tim)
Modified paths:
  • /trunk/phase3/includes/media/DjVu.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/media/DjVu.php
@@ -52,8 +52,6 @@
5353 $m = false;
5454 if ( preg_match( '/^page(\d+)-(\d+)px$/', $str, $m ) ) {
5555 return array( 'width' => $m[2], 'page' => $m[1] );
56 - } else if ( preg_match( '/^page(\d+)-djvutxt$/', $str, $m ) ) {
57 - return array( 'djvutxt' => 1, 'page' => $m[1] );
5856 } else {
5957 return false;
6058 }
@@ -66,21 +64,8 @@
6765 );
6866 }
6967
70 - function normaliseParams( $image, &$params ) {
71 - global $wgDjvuTxt;
72 - if( $params['djvutxt'] && $wgDjvuTxt) {
73 - if ( !isset( $params['page'] ) ) {
74 - $params['page'] = 1;
75 - }
76 - $params['width'] = 0;
77 - $params['height'] = 0;
78 - return true;
79 - }
80 - else return parent::normaliseParams( $image, $params );
81 - }
82 -
8368 function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
84 - global $wgDjvuRenderer, $wgDjvuPostProcessor, $wgDjvuTxt;
 69+ global $wgDjvuRenderer, $wgDjvuPostProcessor;
8570
8671 // Fetch XML and check it, to give a more informative error message than the one which
8772 // normaliseParams will inevitably give.
@@ -109,36 +94,18 @@
11095 return new MediaTransformError( 'thumbnail_error', $width, $height, wfMsg( 'thumbnail_dest_directory' ) );
11196 }
11297
113 - if( $params['djvutxt'] && $wgDjvuTxt ) {
114 - # Extract djvu text
115 - $cmd = wfEscapeShellArg( $wgDjvuTxt ) . " --page={$page} " . wfEscapeShellArg( $srcPath ) ;
116 - wfProfileIn( 'djvutxt' );
117 - wfDebug( __METHOD__.": $cmd\n" );
118 - $err = wfShellExec( $cmd, $retval );
119 - wfProfileOut( 'djvutxt' );
120 - # Escape html characters
121 - $txt = htmlspecialchars( $err );
122 - # Write result to file
123 - if($retval == 0) {
124 - $f = fopen($dstPath, 'w');
125 - fwrite($f, $txt);
126 - fclose($f);
127 - }
 98+ # Use a subshell (brackets) to aggregate stderr from both pipeline commands
 99+ # before redirecting it to the overall stdout. This works in both Linux and Windows XP.
 100+ $cmd = '(' . wfEscapeShellArg( $wgDjvuRenderer ) . " -format=ppm -page={$page} -size={$width}x{$height} " .
 101+ wfEscapeShellArg( $srcPath );
 102+ if ( $wgDjvuPostProcessor ) {
 103+ $cmd .= " | {$wgDjvuPostProcessor}";
128104 }
129 - else {
130 - # Use a subshell (brackets) to aggregate stderr from both pipeline commands
131 - # before redirecting it to the overall stdout. This works in both Linux and Windows XP.
132 - $cmd = '(' . wfEscapeShellArg( $wgDjvuRenderer ) . " -format=ppm -page={$page} -size={$width}x{$height} " .
133 - wfEscapeShellArg( $srcPath );
134 - if ( $wgDjvuPostProcessor ) {
135 - $cmd .= " | {$wgDjvuPostProcessor}";
136 - }
137 - $cmd .= ' > ' . wfEscapeShellArg($dstPath) . ') 2>&1';
138 - wfProfileIn( 'ddjvu' );
139 - wfDebug( __METHOD__.": $cmd\n" );
140 - $err = wfShellExec( $cmd, $retval );
141 - wfProfileOut( 'ddjvu' );
142 - }
 105+ $cmd .= ' > ' . wfEscapeShellArg($dstPath) . ') 2>&1';
 106+ wfProfileIn( 'ddjvu' );
 107+ wfDebug( __METHOD__.": $cmd\n" );
 108+ $err = wfShellExec( $cmd, $retval );
 109+ wfProfileOut( 'ddjvu' );
143110
144111 $removed = $this->removeBadFile( $dstPath, $retval );
145112 if ( $retval != 0 || $removed ) {

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r50050extract djvu text (bug 18046); escape possible script with htmlspecialchars i...thomasv19:33, 29 April 2009

Status & tagging log