From: Brion Vibber Date: Sun, 12 Dec 2004 09:56:02 +0000 (+0000) Subject: * (bug 1074) Add stock icons for non-image files in gallery/Newimages X-Git-Tag: 1.5.0alpha1~1098 X-Git-Url: https://git.cyclocoop.org/%7B%7B%20url_for%28%27votes%27%2C%20votes=%27waiting%27%29%20%7D%7D?a=commitdiff_plain;h=fada5faa4bbc09f6affa7b82fbcce91bb359d140;p=lhc%2Fweb%2Fwiklou.git * (bug 1074) Add stock icons for non-image files in gallery/Newimages * Add width and height attributes on thumbs in gallery/Newimages --- diff --git a/includes/Image.php b/includes/Image.php index 654048e5d5..90c4a9f745 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -323,6 +323,22 @@ class Image * @access public */ function createThumb( $width, $height=-1 ) { + $thumb = $this->getThumbnail( $width, $height ); + if( is_null( $thumb ) ) return ''; + return $thumb->getUrl(); + } + + /** + * As createThumb, but returns a ThumbnailImage object. This can + * provide access to the actual file, the real size of the thumb, + * and can produce a convenient tag for you. + * + * @param integer $width maximum width of the generated thumbnail + * @param integer $height maximum height of the image (optional) + * @return ThumbnailImage + * @access public + */ + function &getThumbnail( $width, $height=-1 ) { if ( $height == -1 ) { return $this->renderThumb( $width ); } @@ -337,7 +353,28 @@ class Image $thumbwidth = $thumbwidth * $height / $thumbheight; $thumbheight = $height; } - return $this->renderThumb( $thumbwidth ); + $thumb = $this->renderThumb( $thumbwidth ); + if( is_null( $thumb ) ) { + $thumb = $this->iconThumb(); + } + return $thumb; + } + + /** + * @return ThumbnailImage + */ + function iconThumb() { + global $wgStylePath, $wgStyleDirectory; + + $try = array( 'fileicon-' . $this->extension . '.png', 'fileicon.png' ); + foreach( $try as $icon ) { + $path = '/common/images/' . $icon; + $filepath = $wgStyleDirectory . $path; + if( file_exists( $filepath ) ) { + return new ThumbnailImage( $filepath, $wgStylePath . $path ); + } + } + return null; } /** @@ -346,8 +383,10 @@ class Image * image's width. Let the browser do the scaling in this case. * The thumbnail is stored on disk and is only computed if the thumbnail * file does not exist OR if it is older than the image. - * Returns the URL. + * Returns an object which can return the pathname, URL, and physical + * pixel size of the thumbnail -- or null on failure. * + * @return ThumbnailImage * @access private */ function /* private */ renderThumb( $width ) { @@ -364,18 +403,18 @@ class Image if ( ! $this->exists() ) { # If there is no image, there will be no thumbnail - return ''; + return null; } # Sanity check $width if( $width <= 0 ) { # BZZZT - return ''; + return null; } if( $width > $this->width && !$this->mustRender() ) { # Don't make an image bigger than the source - return $this->getViewURL(); + return new ThumbnailImage( $this->getImagePath(), $this->getViewURL() ); } if ( (! file_exists( $thumbPath ) ) || ( filemtime($thumbPath) < filemtime($this->imagePath) ) ) { @@ -462,8 +501,6 @@ class Image } imagedestroy( $dst_image ); imagedestroy( $src_image ); - - } # # Check for zero-sized thumbnails. Those can be generated when @@ -485,7 +522,7 @@ class Image wfPurgeSquidServers($urlArr); } } - return $thumbUrl; + return new ThumbnailImage( $thumbPath, $thumbUrl ); } // END OF function createThumb /** @@ -867,4 +904,58 @@ function getSVGsize( $filename ) { "width=\"$width\" height=\"$height\"" ); } + +/** + * Wrapper class for thumbnail images + */ +class ThumbnailImage { + /** + * @param string $path Filesystem path to the thumb + * @param string $url URL path to the thumb + * @access private + */ + function ThumbnailImage( $path, $url ) { + $this->url = $url; + $this->path = $path; + $size = @getimagesize( $this->path ); + if( $size ) { + $this->width = $size[0]; + $this->height = $size[1]; + } else { + $this->width = 0; + $this->height = 0; + } + } + + function getUrl() { + return $this->url; + } + + /** + * Return HTML tag for the thumbnail, will include + * width and height attributes and a blank alt text (as required). + * + * You can set or override additional attributes by passing an + * associative array of name => data pairs. The data will be escaped + * for HTML output, so should be in plaintext. + * + * @param array $attribs + * @return string + * @access public + */ + function toHtml( $attribs = array() ) { + $attribs['src'] = $this->url; + $attribs['width'] = $this->width; + $attribs['height'] = $this->height; + if( !isset( $attribs['alt'] ) ) $attribs['alt'] = ''; + + $html = ' $data ) { + $html .= $name . '="' . htmlspecialchars( $data ) . '" '; + } + $html .= '/>'; + return $html; + } +} + ?> diff --git a/includes/ImageGallery.php b/includes/ImageGallery.php index 44177d62a8..81af0cbae8 100644 --- a/includes/ImageGallery.php +++ b/includes/ImageGallery.php @@ -119,10 +119,11 @@ class ImageGallery '' ; $s .= ($i%4==0) ? '' : ''; + $thumb = $img->getThumbnail(120,120); $s .= '' . ''. '
' . - $sk->makeKnownLinkObj( $nt, '' ) . '
' . + $sk->makeKnownLinkObj( $nt, $thumb->toHtml() ) . ' ' . $textlink . $text . $nb; $s .= "\n" . (($i%4==3) ? "\n" : ''); diff --git a/skins/common/images/fileicon-ogg.png b/skins/common/images/fileicon-ogg.png new file mode 100644 index 0000000000..aa82607029 Binary files /dev/null and b/skins/common/images/fileicon-ogg.png differ diff --git a/skins/common/images/fileicon-ogg.xcf b/skins/common/images/fileicon-ogg.xcf new file mode 100644 index 0000000000..a91024bf21 Binary files /dev/null and b/skins/common/images/fileicon-ogg.xcf differ diff --git a/skins/common/images/fileicon.png b/skins/common/images/fileicon.png new file mode 100644 index 0000000000..2271faeb7d Binary files /dev/null and b/skins/common/images/fileicon.png differ diff --git a/skins/common/images/fileicon.xcf b/skins/common/images/fileicon.xcf new file mode 100644 index 0000000000..45135def94 Binary files /dev/null and b/skins/common/images/fileicon.xcf differ