Index: trunk/phase3/skins/common/images/fileicon-ogg.xcf |
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes on: trunk/phase3/skins/common/images/fileicon-ogg.xcf |
___________________________________________________________________ |
Added: svn:mime-type |
1 | 1 | + application/octet-stream |
Index: trunk/phase3/skins/common/images/fileicon.xcf |
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes on: trunk/phase3/skins/common/images/fileicon.xcf |
___________________________________________________________________ |
Added: svn:mime-type |
2 | 2 | + application/octet-stream |
Index: trunk/phase3/skins/common/images/fileicon-ogg.png |
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes on: trunk/phase3/skins/common/images/fileicon-ogg.png |
___________________________________________________________________ |
Added: svn:mime-type |
3 | 3 | + application/octet-stream |
Index: trunk/phase3/skins/common/images/fileicon.png |
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes on: trunk/phase3/skins/common/images/fileicon.png |
___________________________________________________________________ |
Added: svn:mime-type |
4 | 4 | + application/octet-stream |
Index: trunk/phase3/includes/Image.php |
— | — | @@ -323,6 +323,22 @@ |
324 | 324 | * @access public |
325 | 325 | */ |
326 | 326 | function createThumb( $width, $height=-1 ) { |
| 327 | + $thumb = $this->getThumbnail( $width, $height ); |
| 328 | + if( is_null( $thumb ) ) return ''; |
| 329 | + return $thumb->getUrl(); |
| 330 | + } |
| 331 | + |
| 332 | + /** |
| 333 | + * As createThumb, but returns a ThumbnailImage object. This can |
| 334 | + * provide access to the actual file, the real size of the thumb, |
| 335 | + * and can produce a convenient <img> tag for you. |
| 336 | + * |
| 337 | + * @param integer $width maximum width of the generated thumbnail |
| 338 | + * @param integer $height maximum height of the image (optional) |
| 339 | + * @return ThumbnailImage |
| 340 | + * @access public |
| 341 | + */ |
| 342 | + function &getThumbnail( $width, $height=-1 ) { |
327 | 343 | if ( $height == -1 ) { |
328 | 344 | return $this->renderThumb( $width ); |
329 | 345 | } |
— | — | @@ -337,17 +353,40 @@ |
338 | 354 | $thumbwidth = $thumbwidth * $height / $thumbheight; |
339 | 355 | $thumbheight = $height; |
340 | 356 | } |
341 | | - return $this->renderThumb( $thumbwidth ); |
| 357 | + $thumb = $this->renderThumb( $thumbwidth ); |
| 358 | + if( is_null( $thumb ) ) { |
| 359 | + $thumb = $this->iconThumb(); |
| 360 | + } |
| 361 | + return $thumb; |
342 | 362 | } |
| 363 | + |
| 364 | + /** |
| 365 | + * @return ThumbnailImage |
| 366 | + */ |
| 367 | + function iconThumb() { |
| 368 | + global $wgStylePath, $wgStyleDirectory; |
343 | 369 | |
| 370 | + $try = array( 'fileicon-' . $this->extension . '.png', 'fileicon.png' ); |
| 371 | + foreach( $try as $icon ) { |
| 372 | + $path = '/common/images/' . $icon; |
| 373 | + $filepath = $wgStyleDirectory . $path; |
| 374 | + if( file_exists( $filepath ) ) { |
| 375 | + return new ThumbnailImage( $filepath, $wgStylePath . $path ); |
| 376 | + } |
| 377 | + } |
| 378 | + return null; |
| 379 | + } |
| 380 | + |
344 | 381 | /** |
345 | 382 | * Create a thumbnail of the image having the specified width. |
346 | 383 | * The thumbnail will not be created if the width is larger than the |
347 | 384 | * image's width. Let the browser do the scaling in this case. |
348 | 385 | * The thumbnail is stored on disk and is only computed if the thumbnail |
349 | 386 | * file does not exist OR if it is older than the image. |
350 | | - * Returns the URL. |
| 387 | + * Returns an object which can return the pathname, URL, and physical |
| 388 | + * pixel size of the thumbnail -- or null on failure. |
351 | 389 | * |
| 390 | + * @return ThumbnailImage |
352 | 391 | * @access private |
353 | 392 | */ |
354 | 393 | function /* private */ renderThumb( $width ) { |
— | — | @@ -364,18 +403,18 @@ |
365 | 404 | if ( ! $this->exists() ) |
366 | 405 | { |
367 | 406 | # If there is no image, there will be no thumbnail |
368 | | - return ''; |
| 407 | + return null; |
369 | 408 | } |
370 | 409 | |
371 | 410 | # Sanity check $width |
372 | 411 | if( $width <= 0 ) { |
373 | 412 | # BZZZT |
374 | | - return ''; |
| 413 | + return null; |
375 | 414 | } |
376 | 415 | |
377 | 416 | if( $width > $this->width && !$this->mustRender() ) { |
378 | 417 | # Don't make an image bigger than the source |
379 | | - return $this->getViewURL(); |
| 418 | + return new ThumbnailImage( $this->getImagePath(), $this->getViewURL() ); |
380 | 419 | } |
381 | 420 | |
382 | 421 | if ( (! file_exists( $thumbPath ) ) || ( filemtime($thumbPath) < filemtime($this->imagePath) ) ) { |
— | — | @@ -462,8 +501,6 @@ |
463 | 502 | } |
464 | 503 | imagedestroy( $dst_image ); |
465 | 504 | imagedestroy( $src_image ); |
466 | | - |
467 | | - |
468 | 505 | } |
469 | 506 | # |
470 | 507 | # Check for zero-sized thumbnails. Those can be generated when |
— | — | @@ -485,7 +522,7 @@ |
486 | 523 | wfPurgeSquidServers($urlArr); |
487 | 524 | } |
488 | 525 | } |
489 | | - return $thumbUrl; |
| 526 | + return new ThumbnailImage( $thumbPath, $thumbUrl ); |
490 | 527 | } // END OF function createThumb |
491 | 528 | |
492 | 529 | /** |
— | — | @@ -867,4 +904,58 @@ |
868 | 905 | "width=\"$width\" height=\"$height\"" ); |
869 | 906 | } |
870 | 907 | |
| 908 | + |
| 909 | +/** |
| 910 | + * Wrapper class for thumbnail images |
| 911 | + */ |
| 912 | +class ThumbnailImage { |
| 913 | + /** |
| 914 | + * @param string $path Filesystem path to the thumb |
| 915 | + * @param string $url URL path to the thumb |
| 916 | + * @access private |
| 917 | + */ |
| 918 | + function ThumbnailImage( $path, $url ) { |
| 919 | + $this->url = $url; |
| 920 | + $this->path = $path; |
| 921 | + $size = @getimagesize( $this->path ); |
| 922 | + if( $size ) { |
| 923 | + $this->width = $size[0]; |
| 924 | + $this->height = $size[1]; |
| 925 | + } else { |
| 926 | + $this->width = 0; |
| 927 | + $this->height = 0; |
| 928 | + } |
| 929 | + } |
| 930 | + |
| 931 | + function getUrl() { |
| 932 | + return $this->url; |
| 933 | + } |
| 934 | + |
| 935 | + /** |
| 936 | + * Return HTML <img ... /> tag for the thumbnail, will include |
| 937 | + * width and height attributes and a blank alt text (as required). |
| 938 | + * |
| 939 | + * You can set or override additional attributes by passing an |
| 940 | + * associative array of name => data pairs. The data will be escaped |
| 941 | + * for HTML output, so should be in plaintext. |
| 942 | + * |
| 943 | + * @param array $attribs |
| 944 | + * @return string |
| 945 | + * @access public |
| 946 | + */ |
| 947 | + function toHtml( $attribs = array() ) { |
| 948 | + $attribs['src'] = $this->url; |
| 949 | + $attribs['width'] = $this->width; |
| 950 | + $attribs['height'] = $this->height; |
| 951 | + if( !isset( $attribs['alt'] ) ) $attribs['alt'] = ''; |
| 952 | + |
| 953 | + $html = '<img '; |
| 954 | + foreach( $attribs as $name => $data ) { |
| 955 | + $html .= $name . '="' . htmlspecialchars( $data ) . '" '; |
| 956 | + } |
| 957 | + $html .= '/>'; |
| 958 | + return $html; |
| 959 | + } |
| 960 | +} |
| 961 | + |
871 | 962 | ?> |
Index: trunk/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" : ''); |