r6656 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r6655‎ | r6656 | r6657 >
Date:09:53, 12 December 2004
Author:vibber
Status:old
Tags:
Comment:
* (bug 1074) Add stock icons for non-image files in gallery/Newimages
* Add width and height attributes on thumbs in gallery/Newimages
Modified paths:
  • /branches/REL1_4/phase3/RELEASE-NOTES (modified) (history)
  • /branches/REL1_4/phase3/includes/Image.php (modified) (history)
  • /branches/REL1_4/phase3/includes/ImageGallery.php (modified) (history)
  • /branches/REL1_4/phase3/skins/common/images/fileicon-ogg.png (added) (history)
  • /branches/REL1_4/phase3/skins/common/images/fileicon-ogg.xcf (added) (history)
  • /branches/REL1_4/phase3/skins/common/images/fileicon.png (added) (history)
  • /branches/REL1_4/phase3/skins/common/images/fileicon.xcf (added) (history)

Diff [purge]

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
11 + 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
22 + 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
33 + 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
44 + application/octet-stream
Index: branches/REL1_4/phase3/includes/Image.php
@@ -344,6 +344,22 @@
345345 * @access public
346346 */
347347 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 ) {
348364 if ( $height == -1 ) {
349365 return $this->renderThumb( $width );
350366 }
@@ -358,17 +374,40 @@
359375 $thumbwidth = $thumbwidth * $height / $thumbheight;
360376 $thumbheight = $height;
361377 }
362 - return $this->renderThumb( $thumbwidth );
 378+ $thumb = $this->renderThumb( $thumbwidth );
 379+ if( is_null( $thumb ) ) {
 380+ $thumb = $this->iconThumb();
 381+ }
 382+ return $thumb;
363383 }
 384+
 385+ /**
 386+ * @return ThumbnailImage
 387+ */
 388+ function iconThumb() {
 389+ global $wgStylePath, $wgStyleDirectory;
364390
 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+
365402 /**
366403 * Create a thumbnail of the image having the specified width.
367404 * The thumbnail will not be created if the width is larger than the
368405 * image's width. Let the browser do the scaling in this case.
369406 * The thumbnail is stored on disk and is only computed if the thumbnail
370407 * 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.
372410 *
 411+ * @return ThumbnailImage
373412 * @access private
374413 */
375414 function /* private */ renderThumb( $width ) {
@@ -385,18 +424,18 @@
386425 if ( ! $this->exists() )
387426 {
388427 # If there is no image, there will be no thumbnail
389 - return '';
 428+ return null;
390429 }
391430
392431 # Sanity check $width
393432 if( $width <= 0 ) {
394433 # BZZZT
395 - return '';
 434+ return null;
396435 }
397436
398437 if( $width > $this->width && !$this->mustRender() ) {
399438 # Don't make an image bigger than the source
400 - return $this->getViewURL();
 439+ return new ThumbnailImage( $this->getImagePath(), $this->getViewURL() );
401440 }
402441
403442 if ( (! file_exists( $thumbPath ) ) || ( filemtime($thumbPath) < filemtime($this->imagePath) ) ) {
@@ -483,8 +522,6 @@
484523 }
485524 imagedestroy( $dst_image );
486525 imagedestroy( $src_image );
487 -
488 -
489526 }
490527 #
491528 # Check for zero-sized thumbnails. Those can be generated when
@@ -506,7 +543,7 @@
507544 wfPurgeSquidServers($urlArr);
508545 }
509546 }
510 - return $thumbUrl;
 547+ return new ThumbnailImage( $thumbPath, $thumbUrl );
511548 } // END OF function createThumb
512549
513550 /**
@@ -836,4 +873,58 @@
837874 "width=\"$width\" height=\"$height\"" );
838875 }
839876
 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+
840931 ?>
Index: branches/REL1_4/phase3/includes/ImageGallery.php
@@ -119,10 +119,11 @@
120120 '' ;
121121
122122 $s .= ($i%4==0) ? '<tr>' : '';
 123+ $thumb = $img->getThumbnail(120,120);
123124 $s .= '<td valign="top" width="150px" style="background-color:#F0F0F0;">' .
124125 '<table width="100%" height="150px">'.
125126 '<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> ' .
127128 $textlink . $text . $nb;
128129
129130 $s .= "</td>\n" . (($i%4==3) ? "</tr>\n" : '');
Index: branches/REL1_4/phase3/RELEASE-NOTES
@@ -131,6 +131,8 @@
132132 * (bug 922) bogus DOS line endings in LanguageEl.php
133133 * Fix index usage in contribs
134134 * 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
135137
136138 === Caveats ===
137139

Follow-up revisions

RevisionCommit summaryAuthorDate
r6657* (bug 1074) Add stock icons for non-image files in gallery/Newimages...vibber09:56, 12 December 2004

Status & tagging log