}
-function wfImageUrl( $img )
-{
- global $wgUploadPath;
-
- $nt = Title::newFromText( $img );
- if( !$nt ) return "";
-
- $name = $nt->getDBkey();
- $hash = md5( $name );
-
- $url = "{$wgUploadPath}/" . $hash{0} . "/" .
- substr( $hash, 0, 2 ) . "/{$name}";
- return wfUrlencode( $url );
-}
-
function wfImagePath( $img )
{
global $wgUploadDirectory;
var $name, # name of the image
$imagePath, # Path of the image
$url, # Image URL
- $title; # Title object for this image. Initialized when needed.
+ $title, # Title object for this image. Initialized when needed.
+ $fileExists, # does the image file exist on disk?
+ $width, # \
+ $height, # --- returned by getimagesize, see http://de3.php.net/manual/en/function.getimagesize.php
+ $type, # |
+ $attr; # /
function Image( $name )
{
$this->name = $name;
+ $this->title = Title::makeTitle( Namespace::getImage(), $this->name );
$this->imagePath = wfImagePath( $name );
- $this->url = wfImageUrl( $name );
- $this->title = NULL;
+ $this->url = $this->wfImageUrl( $name );
+
+ if ( $this->fileExists = file_exists( $this->imagePath ) ) // Sic!, "=" is intended
+ {
+ list($this->width, $this->height, $this->type, $this->attr) = getimagesize( $this->imagePath );
+ }
}
function newFromTitle( $nt )
return $this->imagePath;
}
+ function getWidth()
+ {
+ return $this->width;
+ }
+
+ function getHeight()
+ {
+ return $this->height;
+ }
+
+ function getType()
+ {
+ return $this->type;
+ }
+
function getEscapeLocalURL()
{
- if ( $this->title == NULL )
- {
- $this->title = Title::makeTitle( Namespace::getImage(), $this->name );
- }
return $this->title->escapeLocalURL();
}
+ function wfImageUrl( $name )
+ {
+ global $wgUploadPath;
+ $hash = md5( $name );
+
+ $url = "{$wgUploadPath}/" . $hash{0} . "/" .
+ substr( $hash, 0, 2 ) . "/{$name}";
+ return wfUrlencode( $url );
+ }
+
+
+ function exists()
+ {
+ return $this->fileExists;
+ }
+
+
function createThumb( $width ) {
global $wgUploadDirectory;
global $wgImageMagickConvertCommand;
$thumbPath = wfImageThumbDir( $thumbName )."/".$thumbName;
$thumbUrl = wfImageThumbUrl( $thumbName );
- if ( ! file_exists( $this->imagePath ) )
+ if ( ! $this->exists() )
{
# If there is no image, there will be no thumbnail
return "";
}
- if ( (! file_exists( $thumbPath ) )
- || ( filemtime($thumbPath) < filemtime($this->imagePath) ) ) {
+ if ( (! file_exists( $thumbPath ) )
+ || ( filemtime($thumbPath) < filemtime($this->imagePath) ) ) {
# Squid purging
if ( $wgUseSquid ) {
$urlArr = Array(
#
# First find out what kind of file this is, and select the correct
# input routine for this.
- list($src_width, $src_height, $src_type, $src_attr) = getimagesize( $this->imagePath );
- switch( $src_type ) {
+
+ switch( $this->type ) {
case 1: # GIF
$src_image = imagecreatefromgif( $this->imagePath );
break;
return "Image type not supported";
break;
}
- $height = floor( $src_height * ( $width/$src_width ) );
+ $height = floor( $this->height * ( $width/$this->width ) );
$dst_image = imagecreatetruecolor( $width, $height );
imagecopyresampled( $dst_image, $src_image,
0,0,0,0,
- $width, $height, $src_width, $src_height );
- switch( $src_type ) {
+ $width, $height, $this->width, $this->height );
+ switch( $this->type ) {
case 1: # GIF
case 3: # PNG
case 15: # WBMP
# no disk space is available or some other error occurs
#
$thumbstat = stat( $thumbPath );
- $imgstat = stat( $this->imagePath );
if( $thumbstat["size"] == 0 )
{
unlink( $thumbPath );
function openShowImage()
{
global $wgOut, $wgUser,$wgRequest;
- $name = $this->mTitle->getText();
- $path = wfImagePath( $name );
- $url = wfImageUrl( $name );
+ $img = Image::newFromTitle( $this->mTitle );
+ $url = $img->getUrl();
- if ( file_exists( $path ) ) {
- list($width, $height, $type, $attr) = getimagesize( $path );
+ if ( $img->exists() ) {
$sk = $wgUser->getSkin();
- if ( $type != "" ) {
+ if ( $img->getType() != "" ) {
# image
- $s = "<div class=\"fullImage\"><img src=\"{$url}\" width=\"{$width}\" height=\"{$height}\"".
- "alt=\"".$wgRequest->getVal( 'image' )."\" /></div>";
+ $s = "<div class=\"fullImage\">" .
+ "<img src=\"{$url}\" width=\"" . $img->getWidth() . "\" height=\"" . $img->getHeight() .
+ "\" alt=\"".$wgRequest->getVal( 'image' )."\" /></div>";
} else {
- $s = "<div class=\"fullMedia\">".$sk->makeMediaLink($name,"")."</div>";
+ $s = "<div class=\"fullMedia\">".$sk->makeMediaLink($img->getName(),"")."</div>";
}
$wgOut->addHTML( $s );
}
if ( $wgOut->isArticleRelated() ) {
if ( $wgTitle->getNamespace() == Namespace::getImage() ) {
$name = $wgTitle->getDBkey();
- $link = wfEscapeHTML( wfImageUrl( $name ) );
+ $link = wfEscapeHTML( Image::wfImageUrl( $name ) );
$style = $this->getInternalLinkAttributes( $link, $name );
$s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
}
global $wgUploadPath, $wgLang;
# $image = Title::makeTitle( Namespace::getImage(), $name );
$url = $img->getURL();
- $path = $img->getImagePath();
#$label = htmlspecialchars( $label );
$alt = preg_replace( "/<[^>]*>/", "", $label);
$alt = htmlspecialchars( $alt );
- if ( file_exists( $path ) )
+ if ( $img->exists() )
{
- list($width, $height, $type, $attr) = getimagesize( $path );
+ $width = $img->getWidth();
+ $height = $img->getHeight();
} else {
$width = $height = 200;
}
function makeMediaLinkObj( $nt, $alt = "" )
{
$name = $nt->getDBKey();
- $url = wfImageUrl( $name );
+ $url = Image::wfImageUrl( $name );
if ( empty( $alt ) ) {
$alt = preg_replace( '/\.(.+?)^/', '', $name );
}
$cur = wfMsg( "cur" );
if ( $iscur ) {
- $url = wfImageUrl( $img );
+ $url = Image::wfImageUrl( $img );
$rlink = $cur;
if ( $wgUser->isSysop() ) {
$link = $wgTitle->escapeLocalURL( "image=" . $wgTitle->getPartialURL() .
else { $ul = $sk->makeLink( $wgLang->getNsText(
Namespace::getUser() ) . ":{$ut}", $ut ); }
- $ilink = "<a href=\"" . wfImageUrl( $name ) .
+ $ilink = "<a href=\"" . Image::wfImageUrl( $name ) .
"\">{$name}</a>";
$nb = wfMsg( "nbytes", $wgLang->formatNum( $s->img_size ) );
while ( $obj = wfFetchObject( $res ) ) {
$name = $obj->img_name;
$dlink = $sk->makeKnownLink( "{$ins}:{$name}", wfMsg( "imgdesc" ) );
- $ilink = "<a href=\"" . wfImageUrl( $name ) . "\">{$name}</a>";
+ $ilink = "<a href=\"" . Image::wfImageUrl( $name ) . "\">{$name}</a>";
$d = $wgLang->timeanddate( $obj->img_timestamp, true );
$u = $obj->img_user;
$this->mUploadDescription, $this->mUploadCopyStatus, $this->mUploadSource );
$sk = $wgUser->getSkin();
- $ilink = $sk->makeMediaLink( $this->mUploadSaveName, wfImageUrl(
- $this->mUploadSaveName ) );
+ $ilink = $sk->makeMediaLink( $this->mUploadSaveName, Image::wfImageUrl( $this->mUploadSaveName ) );
$dname = $wgLang->getNsText( Namespace::getImage() ) . ":{$this->mUploadSaveName}";
$dlink = $sk->makeKnownLink( $dname, $dname );