Index: branches/REL1_4/phase3/skins/common/images/fileicon-ogg.xcf |
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes on: branches/REL1_4/phase3/skins/common/images/fileicon-ogg.xcf |
___________________________________________________________________ |
Added: svn:mime-type |
1 | 1 | + application/octet-stream |
Index: branches/REL1_4/phase3/skins/common/images/fileicon.xcf |
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes on: branches/REL1_4/phase3/skins/common/images/fileicon.xcf |
___________________________________________________________________ |
Added: svn:mime-type |
2 | 2 | + application/octet-stream |
Index: branches/REL1_4/phase3/skins/common/images/fileicon-ogg.png |
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes on: branches/REL1_4/phase3/skins/common/images/fileicon-ogg.png |
___________________________________________________________________ |
Added: svn:mime-type |
3 | 3 | + application/octet-stream |
Index: branches/REL1_4/phase3/skins/common/images/fileicon.png |
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes on: branches/REL1_4/phase3/skins/common/images/fileicon.png |
___________________________________________________________________ |
Added: svn:mime-type |
4 | 4 | + application/octet-stream |
Index: branches/REL1_4/phase3/includes/Image.php |
— | — | @@ -344,6 +344,22 @@ |
345 | 345 | * @access public |
346 | 346 | */ |
347 | 347 | function createThumb( $width, $height=-1 ) { |
| 348 | + $thumb = $this->getThumbnail( $width, $height ); |
| 349 | + if( is_null( $thumb ) ) return ''; |
| 350 | + return $thumb->getUrl(); |
| 351 | + } |
| 352 | + |
| 353 | + /** |
| 354 | + * As createThumb, but returns a ThumbnailImage object. This can |
| 355 | + * provide access to the actual file, the real size of the thumb, |
| 356 | + * and can produce a convenient <img> tag for you. |
| 357 | + * |
| 358 | + * @param integer $width maximum width of the generated thumbnail |
| 359 | + * @param integer $height maximum height of the image (optional) |
| 360 | + * @return ThumbnailImage |
| 361 | + * @access public |
| 362 | + */ |
| 363 | + function &getThumbnail( $width, $height=-1 ) { |
348 | 364 | if ( $height == -1 ) { |
349 | 365 | return $this->renderThumb( $width ); |
350 | 366 | } |
— | — | @@ -358,17 +374,40 @@ |
359 | 375 | $thumbwidth = $thumbwidth * $height / $thumbheight; |
360 | 376 | $thumbheight = $height; |
361 | 377 | } |
362 | | - return $this->renderThumb( $thumbwidth ); |
| 378 | + $thumb = $this->renderThumb( $thumbwidth ); |
| 379 | + if( is_null( $thumb ) ) { |
| 380 | + $thumb = $this->iconThumb(); |
| 381 | + } |
| 382 | + return $thumb; |
363 | 383 | } |
| 384 | + |
| 385 | + /** |
| 386 | + * @return ThumbnailImage |
| 387 | + */ |
| 388 | + function iconThumb() { |
| 389 | + global $wgStylePath, $wgStyleDirectory; |
364 | 390 | |
| 391 | + $try = array( 'fileicon-' . $this->extension . '.png', 'fileicon.png' ); |
| 392 | + foreach( $try as $icon ) { |
| 393 | + $path = '/common/images/' . $icon; |
| 394 | + $filepath = $wgStyleDirectory . $path; |
| 395 | + if( file_exists( $filepath ) ) { |
| 396 | + return new ThumbnailImage( $filepath, $wgStylePath . $path ); |
| 397 | + } |
| 398 | + } |
| 399 | + return null; |
| 400 | + } |
| 401 | + |
365 | 402 | /** |
366 | 403 | * Create a thumbnail of the image having the specified width. |
367 | 404 | * The thumbnail will not be created if the width is larger than the |
368 | 405 | * image's width. Let the browser do the scaling in this case. |
369 | 406 | * The thumbnail is stored on disk and is only computed if the thumbnail |
370 | 407 | * file does not exist OR if it is older than the image. |
371 | | - * Returns the URL. |
| 408 | + * Returns an object which can return the pathname, URL, and physical |
| 409 | + * pixel size of the thumbnail -- or null on failure. |
372 | 410 | * |
| 411 | + * @return ThumbnailImage |
373 | 412 | * @access private |
374 | 413 | */ |
375 | 414 | function /* private */ renderThumb( $width ) { |
— | — | @@ -385,18 +424,18 @@ |
386 | 425 | if ( ! $this->exists() ) |
387 | 426 | { |
388 | 427 | # If there is no image, there will be no thumbnail |
389 | | - return ''; |
| 428 | + return null; |
390 | 429 | } |
391 | 430 | |
392 | 431 | # Sanity check $width |
393 | 432 | if( $width <= 0 ) { |
394 | 433 | # BZZZT |
395 | | - return ''; |
| 434 | + return null; |
396 | 435 | } |
397 | 436 | |
398 | 437 | if( $width > $this->width && !$this->mustRender() ) { |
399 | 438 | # Don't make an image bigger than the source |
400 | | - return $this->getViewURL(); |
| 439 | + return new ThumbnailImage( $this->getImagePath(), $this->getViewURL() ); |
401 | 440 | } |
402 | 441 | |
403 | 442 | if ( (! file_exists( $thumbPath ) ) || ( filemtime($thumbPath) < filemtime($this->imagePath) ) ) { |
— | — | @@ -483,8 +522,6 @@ |
484 | 523 | } |
485 | 524 | imagedestroy( $dst_image ); |
486 | 525 | imagedestroy( $src_image ); |
487 | | - |
488 | | - |
489 | 526 | } |
490 | 527 | # |
491 | 528 | # Check for zero-sized thumbnails. Those can be generated when |
— | — | @@ -506,7 +543,7 @@ |
507 | 544 | wfPurgeSquidServers($urlArr); |
508 | 545 | } |
509 | 546 | } |
510 | | - return $thumbUrl; |
| 547 | + return new ThumbnailImage( $thumbPath, $thumbUrl ); |
511 | 548 | } // END OF function createThumb |
512 | 549 | |
513 | 550 | /** |
— | — | @@ -836,4 +873,58 @@ |
837 | 874 | "width=\"$width\" height=\"$height\"" ); |
838 | 875 | } |
839 | 876 | |
| 877 | + |
| 878 | +/** |
| 879 | + * Wrapper class for thumbnail images |
| 880 | + */ |
| 881 | +class ThumbnailImage { |
| 882 | + /** |
| 883 | + * @param string $path Filesystem path to the thumb |
| 884 | + * @param string $url URL path to the thumb |
| 885 | + * @access private |
| 886 | + */ |
| 887 | + function ThumbnailImage( $path, $url ) { |
| 888 | + $this->url = $url; |
| 889 | + $this->path = $path; |
| 890 | + $size = @getimagesize( $this->path ); |
| 891 | + if( $size ) { |
| 892 | + $this->width = $size[0]; |
| 893 | + $this->height = $size[1]; |
| 894 | + } else { |
| 895 | + $this->width = 0; |
| 896 | + $this->height = 0; |
| 897 | + } |
| 898 | + } |
| 899 | + |
| 900 | + function getUrl() { |
| 901 | + return $this->url; |
| 902 | + } |
| 903 | + |
| 904 | + /** |
| 905 | + * Return HTML <img ... /> tag for the thumbnail, will include |
| 906 | + * width and height attributes and a blank alt text (as required). |
| 907 | + * |
| 908 | + * You can set or override additional attributes by passing an |
| 909 | + * associative array of name => data pairs. The data will be escaped |
| 910 | + * for HTML output, so should be in plaintext. |
| 911 | + * |
| 912 | + * @param array $attribs |
| 913 | + * @return string |
| 914 | + * @access public |
| 915 | + */ |
| 916 | + function toHtml( $attribs = array() ) { |
| 917 | + $attribs['src'] = $this->url; |
| 918 | + $attribs['width'] = $this->width; |
| 919 | + $attribs['height'] = $this->height; |
| 920 | + if( !isset( $attribs['alt'] ) ) $attribs['alt'] = ''; |
| 921 | + |
| 922 | + $html = '<img '; |
| 923 | + foreach( $attribs as $name => $data ) { |
| 924 | + $html .= $name . '="' . htmlspecialchars( $data ) . '" '; |
| 925 | + } |
| 926 | + $html .= '/>'; |
| 927 | + return $html; |
| 928 | + } |
| 929 | +} |
| 930 | + |
840 | 931 | ?> |
Index: branches/REL1_4/phase3/includes/ImageGallery.php |
— | — | @@ -119,10 +119,11 @@ |
120 | 120 | '' ; |
121 | 121 | |
122 | 122 | $s .= ($i%4==0) ? '<tr>' : ''; |
| 123 | + $thumb = $img->getThumbnail(120,120); |
123 | 124 | $s .= '<td valign="top" width="150px" style="background-color:#F0F0F0;">' . |
124 | 125 | '<table width="100%" height="150px">'. |
125 | 126 | '<tr><td align="center" valign="center" style="background-color:#F8F8F8;border:solid 1px #888888;">' . |
126 | | - $sk->makeKnownLinkObj( $nt, '<img src="'.$img->createThumb(120,120).'" alt="" />' ) . '</td></tr></table> ' . |
| 127 | + $sk->makeKnownLinkObj( $nt, $thumb->toHtml() ) . '</td></tr></table> ' . |
127 | 128 | $textlink . $text . $nb; |
128 | 129 | |
129 | 130 | $s .= "</td>\n" . (($i%4==3) ? "</tr>\n" : ''); |
Index: branches/REL1_4/phase3/RELEASE-NOTES |
— | — | @@ -131,6 +131,8 @@ |
132 | 132 | * (bug 922) bogus DOS line endings in LanguageEl.php |
133 | 133 | * Fix index usage in contribs |
134 | 134 | * Caching and load limiting options for Recentchanges RSS/Atom feed |
| 135 | +* (bug 1074) Add stock icons for non-image files in gallery/Newimages |
| 136 | +* Add width and height attributes on thumbs in gallery/Newimages |
135 | 137 | |
136 | 138 | === Caveats === |
137 | 139 | |