r16036 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r16035‎ | r16036 | r16037 >
Date:17:34, 13 August 2006
Author:jeluf
Status:old
Tags:
Comment:
(bug 6420) Render thumbnails for djvu images, show multipage preview on image page
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/DjVuImage.php (modified) (history)
  • /trunk/phase3/includes/Image.php (modified) (history)
  • /trunk/phase3/includes/ImageGallery.php (modified) (history)
  • /trunk/phase3/includes/ImagePage.php (modified) (history)
  • /trunk/phase3/includes/Linker.php (modified) (history)
  • /trunk/phase3/includes/MimeMagic.php (modified) (history)
  • /trunk/phase3/includes/Parser.php (modified) (history)
  • /trunk/phase3/languages/MessagesDe.php (modified) (history)
  • /trunk/phase3/skins/common/common.css (modified) (history)
  • /trunk/phase3/skins/monobook/main.css (modified) (history)
  • /trunk/phase3/thumb.php (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/monobook/main.css
@@ -1444,3 +1444,24 @@
14451445 content: "\00BB \0020";
14461446 }
14471447
 1448+div.multipageimagenavbox {
 1449+ border: solid 1px silver;
 1450+ padding: 4px;
 1451+ margin: 1em;
 1452+ -moz-border-radius: 6px;
 1453+ background: #f0f0f0;
 1454+}
 1455+
 1456+div.multipageimagenavbox div.thumb {
 1457+ border: none;
 1458+ margin-left: 2em;
 1459+ margin-right: 2em;
 1460+}
 1461+
 1462+div.multipageimagenavbox hr {
 1463+ margin: 6px;
 1464+}
 1465+
 1466+table.multipageimage td {
 1467+ text-align: center;
 1468+}
Index: trunk/phase3/skins/common/common.css
@@ -383,4 +383,26 @@
384384 table.gallery td.galleryheader {
385385 text-align: center;
386386 font-weight: bold;
387 -}
\ No newline at end of file
 387+}
 388+
 389+div.multipageimagenavbox {
 390+ border: solid 1px silver;
 391+ padding: 4px;
 392+ margin: 1em;
 393+ -moz-border-radius: 6px;
 394+ background: #f0f0f0;
 395+}
 396+
 397+div.multipageimagenavbox div.thumb {
 398+ border: none;
 399+ margin-left: 2em;
 400+ margin-right: 2em;
 401+}
 402+
 403+div.multipageimagenavbox hr {
 404+ margin: 6px;
 405+}
 406+
 407+table.multipageimage td {
 408+ text-align: center;
 409+}
Index: trunk/phase3/thumb.php
@@ -17,13 +17,20 @@
1818 require_once( 'StreamFile.php' );
1919
2020 // Get input parameters
 21+$p=null;
2122
2223 if ( get_magic_quotes_gpc() ) {
2324 $fileName = stripslashes( $_REQUEST['f'] );
2425 $width = stripslashes( $_REQUEST['w'] );
 26+ if ( isset( $_REQUEST['p'] ) ) { // optional page number
 27+ $page = stripslashes( $_REQUEST['p'] );
 28+ }
2529 } else {
2630 $fileName = $_REQUEST['f'];
2731 $width = $_REQUEST['w'];
 32+ if ( isset( $_REQUEST['p'] ) ) { // optional page number
 33+ $page = $_REQUEST['p'] ;
 34+ }
2835 }
2936
3037 $pre_render= isset($_REQUEST['r']) && $_REQUEST['r']!="0";
@@ -31,12 +38,18 @@
3239 // Some basic input validation
3340
3441 $width = intval( $width );
 42+if ( ! is_null( $page ) ) {
 43+ $page = intval( $page );
 44+}
3545 $fileName = strtr( $fileName, '\\/', '__' );
3646
3747 // Work out paths, carefully avoiding constructing an Image object because that won't work yet
3848
3949 $imagePath = wfImageDir( $fileName ) . '/' . $fileName;
4050 $thumbName = "{$width}px-$fileName";
 51+if ( ! is_null( $page ) ) {
 52+ $thumbName = 'page' . $page . '-' . $thumbName;
 53+}
4154 if ( $pre_render ) {
4255 $thumbName .= '.png';
4356 }
@@ -55,6 +68,9 @@
5669
5770 $img = Image::newFromName( $fileName );
5871 if ( $img ) {
 72+ if ( ! is_null( $page ) ) {
 73+ $img->selectPage( $page );
 74+ }
5975 $thumb = $img->renderThumb( $width, false );
6076 } else {
6177 $thumb = false;
Index: trunk/phase3/includes/MimeMagic.php
@@ -504,6 +504,15 @@
505505 # see http://www.php.net/manual/en/ref.mime-magic.php for details.
506506
507507 $m= mime_content_type($file);
 508+
 509+ if ( $m == 'text/plain' ) {
 510+ // mime_content_type sometimes considers DJVU files to be text/plain.
 511+ $deja = new DjVuImage( $file );
 512+ if( $deja->isValid() ) {
 513+ wfDebug("$fname: (re)detected $file as image/vnd.djvu\n");
 514+ $m = 'image/vnd.djvu';
 515+ }
 516+ }
508517 }
509518 else wfDebug("$fname: no magic mime detector found!\n");
510519
Index: trunk/phase3/includes/ImagePage.php
@@ -187,6 +187,12 @@
188188
189189 if ( $this->img->exists() ) {
190190 # image
 191+ $page = $wgRequest->getIntOrNull( 'page' );
 192+ if ( ! is_null( $page ) ) {
 193+ $this->img->selectPage( $page );
 194+ } else {
 195+ $page = 1;
 196+ }
191197 $width = $this->img->getWidth();
192198 $height = $this->img->getHeight();
193199 $showLink = false;
@@ -236,9 +242,53 @@
237243 $url = $this->img->getViewURL();
238244 $showLink = true;
239245 }
 246+
 247+ if ( $this->img->isMultipage() ) {
 248+ $wgOut->addHTML( '<table class="multipageimage"><tr><td>' );
 249+ }
 250+
240251 $wgOut->addHTML( '<div class="fullImageLink" id="file">' . $anchoropen .
241252 "<img border=\"0\" src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" alt=\"" .
242253 htmlspecialchars( $wgRequest->getVal( 'image' ) ).'" />' . $anchorclose . '</div>' );
 254+
 255+ if ( $this->img->isMultipage() ) {
 256+ $count = $this->img->pageCount();
 257+
 258+ if ( $page > 1 ) {
 259+ $label = $wgOut->parse( wfMsg( 'imgmultipageprev' ), false );
 260+ $link = $sk->makeLinkObj( $this->mTitle, $label, 'page='. ($page-1) );
 261+ $this->img->selectPage( $page - 1 );
 262+ $thumb1 = $sk->makeThumbLinkObj( $this->img, $link, $label, 'none' );
 263+ } else {
 264+ $thumb1 = '';
 265+ }
 266+
 267+ if ( $page < $count ) {
 268+ $label = wfMsg( 'imgmultipagenext' );
 269+ $this->img->selectPage( $page + 1 );
 270+ $link = $sk->makeLinkObj( $this->mTitle, $label, 'page='. ($page+1) );
 271+ $thumb2 = $sk->makeThumbLinkObj( $this->img, $link, $label, 'none' );
 272+ } else {
 273+ $thumb2 = '';
 274+ }
 275+
 276+ $select = '<form name="pageselector" action="' . $this->img->getEscapeLocalUrl( '' ) . '" method="GET" onchange="document.pageselector.submit();">' ;
 277+ $select .= $wgOut->parse( wfMsg( 'imgmultigotopre' ), false ) .
 278+ ' <select id="pageselector" name="page">';
 279+ for ( $i=1; $i <= $count; $i++ ) {
 280+ if ( $i == $page ) {
 281+ $select .= "<option value=\"$i\" selected=\"selected\">$i</option>";
 282+ } else {
 283+ $select .= "<option value=\"$i\" >$i</option>\n";
 284+ }
 285+ }
 286+ $select .= '</select>' . $wgOut->parse( wfMsg( 'imgmultigotopost' ), false ) .
 287+ '<input type="submit" value="' .
 288+ htmlspecialchars( wfMsg( 'imgmultigo' ) ) . '"></form>';
 289+
 290+ $wgOut->addHTML( '</td><td><div class="multipageimagenavbox">' .
 291+ "$select<hr />$thumb1\n$thumb2<br clear=\"all\" /></div></td></tr></table>" );
 292+ }
243293 } else {
244294 #if direct link is allowed but it's not a renderable image, show an icon.
245295 if ($this->img->isSafeFile()) {
Index: trunk/phase3/includes/Linker.php
@@ -456,11 +456,16 @@
457457
458458 /** @todo document */
459459 function makeImageLinkObj( $nt, $label, $alt, $align = '', $width = false, $height = false, $framed = false,
460 - $thumb = false, $manual_thumb = '' )
 460+ $thumb = false, $manual_thumb = '', $page = null )
461461 {
462462 global $wgContLang, $wgUser, $wgThumbLimits, $wgGenerateThumbnailOnParse;
463463
464464 $img = new Image( $nt );
 465+
 466+ if ( ! is_null( $page ) ) {
 467+ $img->selectPage( $page );
 468+ }
 469+
465470 if ( !$img->allowInlineDisplay() && $img->exists() ) {
466471 return $this->makeKnownLinkObj( $nt );
467472 }
@@ -468,7 +473,7 @@
469474 $url = $img->getViewURL();
470475 $error = $prefix = $postfix = '';
471476
472 - wfDebug( "makeImageLinkObj: '$width'x'$height'\n" );
 477+ wfDebug( "makeImageLinkObj: '$width'x'$height', \"$label\"\n" );
473478
474479 if ( 'center' == $align )
475480 {
@@ -564,7 +569,6 @@
565570 */
566571 function makeThumbLinkObj( $img, $label = '', $alt, $align = 'right', $boxwidth = 180, $boxheight=false, $framed=false , $manual_thumb = "" ) {
567572 global $wgStylePath, $wgContLang, $wgGenerateThumbnailOnParse;
568 - $url = $img->getViewURL();
569573 $thumbUrl = '';
570574 $error = '';
571575
@@ -583,7 +587,7 @@
584588 // Use image dimensions, don't scale
585589 $boxwidth = $width;
586590 $boxheight = $height;
587 - $thumbUrl = $url;
 591+ $thumbUrl = $img->getViewURL();
588592 } else {
589593 if ( $boxheight === false )
590594 $boxheight = -1;
@@ -626,7 +630,7 @@
627631 $s = "<div class=\"thumb t{$align}\"><div style=\"width:{$oboxwidth}px;\">";
628632 if( $thumbUrl == '' ) {
629633 // Couldn't generate thumbnail? Scale the image client-side.
630 - $thumbUrl = $url;
 634+ $thumbUrl = $img->getViewURL();
631635 }
632636 if ( $error ) {
633637 $s .= htmlspecialchars( $error );
Index: trunk/phase3/includes/Parser.php
@@ -4086,9 +4086,11 @@
40874087 $mwWidth =& MagicWord::get( 'img_width' );
40884088 $mwCenter =& MagicWord::get( 'img_center' );
40894089 $mwFramed =& MagicWord::get( 'img_framed' );
 4090+ $mwPage =& MagicWord::get( 'img_page' );
40904091 $caption = '';
40914092
40924093 $width = $height = $framed = $thumb = false;
 4094+ $page = null;
40934095 $manual_thumb = '' ;
40944096
40954097 foreach( $part as $key => $val ) {
@@ -4098,6 +4100,9 @@
40994101 # use manually specified thumbnail
41004102 $thumb=true;
41014103 $manual_thumb = $match;
 4104+ } elseif ( ! is_null( $match = $mwPage->matchVariableStartToEnd($val) ) ) {
 4105+ # Select a page in a multipage document
 4106+ $page = $match;
41024107 } elseif ( ! is_null( $mwRight->matchVariableStartToEnd($val) ) ) {
41034108 # remember to set an alignment, don't render immediately
41044109 $align = 'right';
@@ -4136,7 +4141,8 @@
41374142
41384143 # Linker does the rest
41394144 $sk =& $this->mOptions->getSkin();
4140 - return $sk->makeImageLinkObj( $nt, $caption, $alt, $align, $width, $height, $framed, $thumb, $manual_thumb );
 4145+ return $sk->makeImageLinkObj( $nt, $caption, $alt, $align, $width, $height,
 4146+ $framed, $thumb, $manual_thumb, $page );
41414147 }
41424148
41434149 /**
Index: trunk/phase3/includes/Image.php
@@ -46,6 +46,7 @@
4747 $size, # Size in bytes (loadFromXxx)
4848 $metadata, # Metadata
4949 $dataLoaded, # Whether or not all this has been loaded from the database (loadFromXxx)
 50+ $page, # Page to render when creating thumbnails
5051 $lastError; # Error string associated with a thumbnail display error
5152
5253
@@ -86,6 +87,7 @@
8788 $this->extension = Image::normalizeExtension( $n ?
8889 substr( $this->name, $n + 1 ) : '' );
8990 $this->historyLine = 0;
 91+ $this->page = 1;
9092
9193 $this->dataLoaded = false;
9294 }
@@ -307,7 +309,11 @@
308310 $this->dataLoaded = true;
309311
310312
311 - $this->metadata = serialize( $this->retrieveExifData( $this->imagePath ) );
 313+ if ( $this->mime == 'image/vnd.djvu' ) {
 314+ $this->metadata = $deja->retrieveMetaData();
 315+ } else {
 316+ $this->metadata = serialize( $this->retrieveExifData( $this->imagePath ) );
 317+ }
312318
313319 if ( isset( $gis['bits'] ) ) $this->bits = $gis['bits'];
314320 else $this->bits = 0;
@@ -323,7 +329,6 @@
324330 wfProfileIn( __METHOD__ );
325331
326332 $dbr =& wfGetDB( DB_SLAVE );
327 -
328333 $this->checkDBSchema($dbr);
329334
330335 $row = $dbr->selectRow( 'image',
@@ -605,7 +610,7 @@
606611 * @todo remember the result of this check.
607612 */
608613 function canRender() {
609 - global $wgUseImageMagick;
 614+ global $wgUseImageMagick, $wgDjvuRenderer;
610615
611616 if( $this->getWidth()<=0 || $this->getHeight()<=0 ) return false;
612617
@@ -651,6 +656,7 @@
652657 if ( $mime === 'image/vnd.wap.wbmp'
653658 || $mime === 'image/x-xbitmap' ) return true;
654659 }
 660+ if ( $mime === 'image/vnd.djvu' && isset( $wgDjvuRenderer ) && $wgDjvuRenderer ) return true;
655661
656662 return false;
657663 }
@@ -738,9 +744,16 @@
739745 * Return the escapeLocalURL of this image
740746 * @public
741747 */
742 - function getEscapeLocalURL() {
 748+ function getEscapeLocalURL( $query=false) {
743749 $this->getTitle();
744 - return $this->title->escapeLocalURL();
 750+ if ( $query === false ) {
 751+ if ( $this->page != 1 ) {
 752+ $query = 'page=' . $this->page;
 753+ } else {
 754+ $query = '';
 755+ }
 756+ }
 757+ return $this->title->escapeLocalURL( $query );
745758 }
746759
747760 /**
@@ -840,6 +853,9 @@
841854 */
842855 function thumbName( $width ) {
843856 $thumb = $width."px-".$this->name;
 857+ if ( $this->page != 1 ) {
 858+ $thumb = "page{$this->page}-$thumb";
 859+ }
844860
845861 if( $this->mustRender() ) {
846862 if( $this->canRender() ) {
@@ -1127,6 +1143,7 @@
11281144 global $wgSVGConverters, $wgSVGConverter;
11291145 global $wgUseImageMagick, $wgImageMagickConvertCommand;
11301146 global $wgCustomConvertCommand;
 1147+ global $wgDjvuRenderer, $wgDjvuPostProcessor;
11311148
11321149 $this->load();
11331150
@@ -1153,96 +1170,112 @@
11541171 $err = wfShellExec( $cmd, $retval );
11551172 wfProfileOut( 'rsvg' );
11561173 }
1157 - } elseif ( $wgUseImageMagick ) {
1158 - # use ImageMagick
1159 -
1160 - if ( $this->mime == 'image/jpeg' ) {
1161 - $quality = "-quality 80"; // 80%
1162 - } elseif ( $this->mime == 'image/png' ) {
1163 - $quality = "-quality 95"; // zlib 9, adaptive filtering
1164 - } else {
1165 - $quality = ''; // default
1166 - }
 1174+ } else {
 1175+ if ( $this->mime === "image/vnd.djvu" && $wgDjvuRenderer ) {
 1176+ // DJVU image
 1177+ // The file contains several images. First, extract the
 1178+ // page in hi-res, if it doesn't yet exist. Then, thumbnail
 1179+ // it.
11671180
1168 - # Specify white background color, will be used for transparent images
1169 - # in Internet Explorer/Windows instead of default black.
 1181+ $cmd = "{$wgDjvuRenderer} -page={$this->page} -size=${width}x${height} " .
 1182+ wfEscapeShellArg( $this->imagePath ) .
 1183+ " | {$wgDjvuPostProcessor} > " . wfEscapeShellArg($thumbPath);
 1184+ wfProfileIn( 'ddjvu' );
 1185+ wfDebug( "reallyRenderThumb DJVU: $cmd\n" );
 1186+ $err = wfShellExec( $cmd, $retval );
 1187+ wfProfileOut( 'ddjvu' );
11701188
1171 - # Note, we specify "-size {$width}" and NOT "-size {$width}x{$height}".
1172 - # It seems that ImageMagick has a bug wherein it produces thumbnails of
1173 - # the wrong size in the second case.
 1189+ } elseif ( $wgUseImageMagick ) {
 1190+ # use ImageMagick
11741191
1175 - $cmd = wfEscapeShellArg($wgImageMagickConvertCommand) .
1176 - " {$quality} -background white -size {$width} ".
1177 - wfEscapeShellArg($this->imagePath) .
1178 - // Coalesce is needed to scale animated GIFs properly (bug 1017).
1179 - ' -coalesce ' .
1180 - // For the -resize option a "!" is needed to force exact size,
1181 - // or ImageMagick may decide your ratio is wrong and slice off
1182 - // a pixel.
1183 - " -resize " . wfEscapeShellArg( "{$width}x{$height}!" ) .
1184 - " -depth 8 " .
1185 - wfEscapeShellArg($thumbPath) . " 2>&1";
1186 - wfDebug("reallyRenderThumb: running ImageMagick: $cmd\n");
1187 - wfProfileIn( 'convert' );
1188 - $err = wfShellExec( $cmd, $retval );
1189 - wfProfileOut( 'convert' );
1190 - } elseif( $wgCustomConvertCommand ) {
1191 - # Use a custom convert command
1192 - # Variables: %s %d %w %h
1193 - $src = wfEscapeShellArg( $this->imagePath );
1194 - $dst = wfEscapeShellArg( $thumbPath );
1195 - $cmd = $wgCustomConvertCommand;
1196 - $cmd = str_replace( '%s', $src, str_replace( '%d', $dst, $cmd ) ); # Filenames
1197 - $cmd = str_replace( '%h', $height, str_replace( '%w', $width, $cmd ) ); # Size
1198 - wfDebug( "reallyRenderThumb: Running custom convert command $cmd\n" );
1199 - wfProfileIn( 'convert' );
1200 - $err = wfShellExec( $cmd, $retval );
1201 - wfProfileOut( 'convert' );
1202 - } else {
1203 - # Use PHP's builtin GD library functions.
1204 - #
1205 - # First find out what kind of file this is, and select the correct
1206 - # input routine for this.
 1192+ if ( $this->mime == 'image/jpeg' ) {
 1193+ $quality = "-quality 80"; // 80%
 1194+ } elseif ( $this->mime == 'image/png' ) {
 1195+ $quality = "-quality 95"; // zlib 9, adaptive filtering
 1196+ } else {
 1197+ $quality = ''; // default
 1198+ }
12071199
1208 - $typemap = array(
1209 - 'image/gif' => array( 'imagecreatefromgif', 'palette', 'imagegif' ),
1210 - 'image/jpeg' => array( 'imagecreatefromjpeg', 'truecolor', array( &$this, 'imageJpegWrapper' ) ),
1211 - 'image/png' => array( 'imagecreatefrompng', 'bits', 'imagepng' ),
1212 - 'image/vnd.wap.wmbp' => array( 'imagecreatefromwbmp', 'palette', 'imagewbmp' ),
1213 - 'image/xbm' => array( 'imagecreatefromxbm', 'palette', 'imagexbm' ),
1214 - );
1215 - if( !isset( $typemap[$this->mime] ) ) {
1216 - $err = 'Image type not supported';
1217 - wfDebug( "$err\n" );
1218 - return $err;
1219 - }
1220 - list( $loader, $colorStyle, $saveType ) = $typemap[$this->mime];
 1200+ # Specify white background color, will be used for transparent images
 1201+ # in Internet Explorer/Windows instead of default black.
 1202+
 1203+ # Note, we specify "-size {$width}" and NOT "-size {$width}x{$height}".
 1204+ # It seems that ImageMagick has a bug wherein it produces thumbnails of
 1205+ # the wrong size in the second case.
 1206+
 1207+ $cmd = wfEscapeShellArg($wgImageMagickConvertCommand) .
 1208+ " {$quality} -background white -size {$width} ".
 1209+ wfEscapeShellArg($this->imagePath) .
 1210+ // Coalesce is needed to scale animated GIFs properly (bug 1017).
 1211+ ' -coalesce ' .
 1212+ // For the -resize option a "!" is needed to force exact size,
 1213+ // or ImageMagick may decide your ratio is wrong and slice off
 1214+ // a pixel.
 1215+ " -resize " . wfEscapeShellArg( "{$width}x{$height}!" ) .
 1216+ " -depth 8 " .
 1217+ wfEscapeShellArg($thumbPath) . " 2>&1";
 1218+ wfDebug("reallyRenderThumb: running ImageMagick: $cmd\n");
 1219+ wfProfileIn( 'convert' );
 1220+ $err = wfShellExec( $cmd, $retval );
 1221+ wfProfileOut( 'convert' );
 1222+ } elseif( $wgCustomConvertCommand ) {
 1223+ # Use a custom convert command
 1224+ # Variables: %s %d %w %h
 1225+ $src = wfEscapeShellArg( $this->imagePath );
 1226+ $dst = wfEscapeShellArg( $thumbPath );
 1227+ $cmd = $wgCustomConvertCommand;
 1228+ $cmd = str_replace( '%s', $src, str_replace( '%d', $dst, $cmd ) ); # Filenames
 1229+ $cmd = str_replace( '%h', $height, str_replace( '%w', $width, $cmd ) ); # Size
 1230+ wfDebug( "reallyRenderThumb: Running custom convert command $cmd\n" );
 1231+ wfProfileIn( 'convert' );
 1232+ $err = wfShellExec( $cmd, $retval );
 1233+ wfProfileOut( 'convert' );
 1234+ } else {
 1235+ # Use PHP's builtin GD library functions.
 1236+ #
 1237+ # First find out what kind of file this is, and select the correct
 1238+ # input routine for this.
 1239+
 1240+ $typemap = array(
 1241+ 'image/gif' => array( 'imagecreatefromgif', 'palette', 'imagegif' ),
 1242+ 'image/jpeg' => array( 'imagecreatefromjpeg', 'truecolor', array( &$this, 'imageJpegWrapper' ) ),
 1243+ 'image/png' => array( 'imagecreatefrompng', 'bits', 'imagepng' ),
 1244+ 'image/vnd.wap.wmbp' => array( 'imagecreatefromwbmp', 'palette', 'imagewbmp' ),
 1245+ 'image/xbm' => array( 'imagecreatefromxbm', 'palette', 'imagexbm' ),
 1246+ );
 1247+ if( !isset( $typemap[$this->mime] ) ) {
 1248+ $err = 'Image type not supported';
 1249+ wfDebug( "$err\n" );
 1250+ return $err;
 1251+ }
 1252+ list( $loader, $colorStyle, $saveType ) = $typemap[$this->mime];
12211253
1222 - if( !function_exists( $loader ) ) {
1223 - $err = "Incomplete GD library configuration: missing function $loader";
1224 - wfDebug( "$err\n" );
1225 - return $err;
1226 - }
1227 - if( $colorStyle == 'palette' ) {
1228 - $truecolor = false;
1229 - } elseif( $colorStyle == 'truecolor' ) {
1230 - $truecolor = true;
1231 - } elseif( $colorStyle == 'bits' ) {
1232 - $truecolor = ( $this->bits > 8 );
1233 - }
 1254+ if( !function_exists( $loader ) ) {
 1255+ $err = "Incomplete GD library configuration: missing function $loader";
 1256+ wfDebug( "$err\n" );
 1257+ return $err;
 1258+ }
 1259+ if( $colorStyle == 'palette' ) {
 1260+ $truecolor = false;
 1261+ } elseif( $colorStyle == 'truecolor' ) {
 1262+ $truecolor = true;
 1263+ } elseif( $colorStyle == 'bits' ) {
 1264+ $truecolor = ( $this->bits > 8 );
 1265+ }
12341266
1235 - $src_image = call_user_func( $loader, $this->imagePath );
1236 - if ( $truecolor ) {
1237 - $dst_image = imagecreatetruecolor( $width, $height );
1238 - } else {
1239 - $dst_image = imagecreate( $width, $height );
 1267+ $src_image = call_user_func( $loader, $this->imagePath );
 1268+ if ( $truecolor ) {
 1269+ $dst_image = imagecreatetruecolor( $width, $height );
 1270+ } else {
 1271+ $dst_image = imagecreate( $width, $height );
 1272+ }
 1273+ imagecopyresampled( $dst_image, $src_image,
 1274+ 0,0,0,0,
 1275+ $width, $height, $this->width, $this->height );
 1276+ call_user_func( $saveType, $dst_image, $thumbPath );
 1277+ imagedestroy( $dst_image );
 1278+ imagedestroy( $src_image );
12401279 }
1241 - imagecopyresampled( $dst_image, $src_image,
1242 - 0,0,0,0,
1243 - $width, $height, $this->width, $this->height );
1244 - call_user_func( $saveType, $dst_image, $thumbPath );
1245 - imagedestroy( $dst_image );
1246 - imagedestroy( $src_image );
12471280 }
12481281
12491282 #
@@ -1712,7 +1745,7 @@
17131746
17141747 function getExifData() {
17151748 global $wgRequest;
1716 - if ( $this->metadata === '0' )
 1749+ if ( $this->metadata === '0' || $this->mime == 'image/vnd.djvu' )
17171750 return array();
17181751
17191752 $purge = $wgRequest->getVal( 'action' ) == 'purge';
@@ -2210,6 +2243,52 @@
22112244
22122245 return $revisions;
22132246 }
 2247+
 2248+ /**
 2249+ * Select a page from a multipage document. Determines the page used for
 2250+ * rendering thumbnails.
 2251+ *
 2252+ * @param $page Integer: page number, starting with 1
 2253+ */
 2254+ function selectPage( $page ) {
 2255+ wfDebug( __METHOD__." selecting page $page \n" );
 2256+ $this->page = $page;
 2257+ if ( ! $this->dataLoaded ) {
 2258+ $this->load();
 2259+ }
 2260+ if ( ! isset( $this->multiPageXML ) ) {
 2261+ $this->multiPageXML = new SimpleXMLElement( $this->metadata );
 2262+ }
 2263+ $o = $this->multiPageXML->BODY[0]->OBJECT[$page-1];
 2264+ $this->height = intval( $o['height'] );
 2265+ $this->width = intval( $o['width'] );
 2266+ wfDebug( __METHOD__." >>>>METADATA>>>>\n".$o->asXML() . "\n<<<<<<<\n\n" );
 2267+ wfDebug( __METHOD__." >>>>XML OBJECT>>>>\n". print_r($o,true) . "\n<<<<<<<\n\n" );
 2268+ }
 2269+
 2270+ /**
 2271+ * Returns 'true' if this image is a multipage document, e.g. a DJVU
 2272+ * document.
 2273+ *
 2274+ * @return Bool
 2275+ */
 2276+ function isMultipage() {
 2277+ return ( $this->mime == 'image/vnd.djvu' );
 2278+ }
 2279+
 2280+ /**
 2281+ * Returns the number of pages of a multipage document, or NULL for
 2282+ * documents which aren't multipage documents
 2283+ */
 2284+ function pageCount() {
 2285+ if ( ! $this->isMultipage() ) {
 2286+ return null;
 2287+ }
 2288+ if ( ! isset( $this->multiPageXML ) ) {
 2289+ $this->multiPageXML = new SimpleXMLElement( $this->metadata );
 2290+ }
 2291+ return count( $this->multiPageXML->xpath( '//OBJECT' ) );
 2292+ }
22142293
22152294 } //class
22162295
Index: trunk/phase3/includes/DefaultSettings.php
@@ -2186,4 +2186,24 @@
21872187 */
21882188 $wgMaxShellMemory = 102400;
21892189
 2190+/**
 2191+ * DJVU settings
 2192+ * Path of the djvutoxml executable
 2193+ * Enable this and $wgDjvuRenderer to enable djvu rendering
 2194+ */
 2195+# $wgDjvuToXML = 'djvutoxml';
 2196+
 2197+/**
 2198+ * Path of the ddjvu DJVU renderer
 2199+ * Enable this and $wgDjvuToXML to enable djvu rendering
 2200+ */
 2201+# $wgDjvuRenderer = 'ddjvu';
 2202+
 2203+/**
 2204+ * Path of the DJVU post processor
 2205+ * May include command line options
 2206+ * Default: ppmtojpeg, since ddjvu generates ppm output
 2207+ */
 2208+$wgDjvuPostProcessor = 'ppmtojpeg';
 2209+
21902210 ?>
Index: trunk/phase3/includes/ImageGallery.php
@@ -82,6 +82,7 @@
8383 */
8484 function add( $image, $html='' ) {
8585 $this->mImages[] = array( &$image, $html );
 86+ wfDebug( "ImageGallery::add " . $image->getName() . "\n" );
8687 }
8788
8889 /**
@@ -157,8 +158,7 @@
158159 # The image is blacklisted, just show it as a text link.
159160 $thumbhtml = '<div style="height: 152px;">'
160161 . $sk->makeKnownLinkObj( $nt, htmlspecialchars( $nt->getText() ) ) . '</div>';
161 - }
162 - else if( !( $thumb = $img->getThumbnail( 120, 120, $wgGenerateThumbnailOnParse ) ) ) {
 162+ } else if( !( $thumb = $img->getThumbnail( 120, 120, $wgGenerateThumbnailOnParse ) ) ) {
163163 # Error generating thumbnail.
164164 $thumbhtml = '<div style="height: 152px;">'
165165 . htmlspecialchars( $img->getLastError() ) . '</div>';
Index: trunk/phase3/includes/DjVuImage.php
@@ -208,7 +208,23 @@
209209 'resolution' => $resolution,
210210 'gamma' => $gamma / 10.0 );
211211 }
 212+
 213+ /**
 214+ * Return an XML string describing the DjVu image
 215+ * @return string
 216+ */
 217+ function retrieveMetaData() {
 218+ global $wgDjvuToXML;
 219+ if ( isset( $wgDjvuToXML ) ) {
 220+ $cmd = $wgDjvuToXML . ' --without-anno --without-text ' . $this->mFilename;
 221+ $xml = wfShellExec( $cmd, $retval );
 222+ } else {
 223+ $xml = null;
 224+ }
 225+ return $xml;
 226+ }
 227+
212228 }
213229
214230
215 -?>
\ No newline at end of file
 231+?>
Index: trunk/phase3/RELEASE-NOTES
@@ -26,6 +26,9 @@
2727 == Major new features ==
2828
2929 * (bug 550) Allow blocks on anonymous users only.
 30+* (bug 6420) Render thumbnails for DJVU images, support multipage DJVU display
 31+ on image pages. Added new 'page=' thumbnail option to select a page from a
 32+ multipage djvu for thumbnail generation.
3033
3134 == Changes since 1.7 ==
3235
Index: trunk/phase3/languages/MessagesDe.php
@@ -1889,6 +1889,14 @@
18901890
18911891 'loginlanguagelabel' => 'Sprache: $1',
18921892
 1893+
 1894+# Multipage image navigation
 1895+'imgmultipageprev' => '&larr; vorige Seite',
 1896+'imgmultipagenext' => 'n&auml;chste Seite &rarr;',
 1897+'imgmultigo' => 'OK',
 1898+'imgmultigotopre' => 'Gehe zu Seite',
 1899+'imgmultigotopost' => '',
 1900+
18931901 );
18941902
18951903