6 # NOTE FOR WINDOWS USERS:
7 # To enable EXIF functions, add the folloing lines to the
8 # "Windows extensions" section of php.ini:
10 # extension=extensions/php_mbstring.dll
11 # extension=extensions/php_exif.dll
14 require_once('Exif.php');
18 * Class to represent an image
20 * Provides methods to retrieve paths (physical, logical, URL),
21 * to generate thumbnails or for uploading.
29 var $name, # name of the image (constructor)
30 $imagePath, # Path of the image (loadFromXxx)
31 $url, # Image URL (accessor)
32 $title, # Title object for this image (constructor)
33 $fileExists, # does the image file exist on disk? (loadFromXxx)
34 $fromSharedDirectory, # load this image from $wgSharedUploadDirectory (loadFromXxx)
35 $historyLine, # Number of line to return by nextHistoryLine() (constructor)
36 $historyRes, # result of the query for the image's history (nextHistoryLine)
39 $bits, # --- returned by getimagesize (loadFromXxx)
41 $type, # MEDIATYPE_xxx (bitmap, drawing, audio...)
42 $mime, # MIME type, determined by MimeMagic::guessMimeType
43 $size, # Size in bytes (loadFromXxx)
45 $exif, # The Exif class
46 $dataLoaded; # Whether or not all this has been loaded from the database (loadFromXxx)
52 * Create an Image object from an image name
54 * @param string $name name of the image, used to create a title object using Title::makeTitleSafe
57 function newFromName( $name ) {
58 $title = Title
::makeTitleSafe( NS_IMAGE
, $name );
59 return new Image( $title );
63 * Obsolete factory function, use constructor
65 function newFromTitle( $title ) {
66 return new Image( $title );
69 function Image( $title ) {
72 $this->title
=& $title;
73 $this->name
= $title->getDBkey();
74 $this->metadata
= serialize ( array() ) ;
76 $n = strrpos( $this->name
, '.' );
77 $this->extension
= strtolower( $n ?
substr( $this->name
, $n +
1 ) : '' );
78 $this->historyLine
= 0;
80 $this->dataLoaded
= false;
83 $this->exif
= new Exif
;
87 * Get the memcached keys
88 * Returns an array, first element is the local cache key, second is the shared cache key, if there is one
90 function getCacheKeys( $shared = false ) {
91 global $wgDBname, $wgUseSharedUploads, $wgSharedUploadDBname, $wgCacheSharedUploads;
94 $hashedName = md5($this->name
);
95 $keys = array( "$wgDBname:Image:$hashedName" );
96 if ( $wgUseSharedUploads && $wgSharedUploadDBname && $wgCacheSharedUploads ) {
97 $keys[] = "$wgSharedUploadDBname:Image:$hashedName";
103 * Try to load image metadata from memcached. Returns true on success.
105 function loadFromCache() {
106 global $wgUseSharedUploads, $wgMemc;
107 $fname = 'Image::loadFromMemcached';
108 wfProfileIn( $fname );
109 $this->dataLoaded
= false;
110 $keys = $this->getCacheKeys();
111 $cachedValues = $wgMemc->get( $keys[0] );
113 // Check if the key existed and belongs to this version of MediaWiki
114 if (!empty($cachedValues) && is_array($cachedValues) && isset($cachedValues['width'])
115 && $cachedValues['fileExists'] && isset( $cachedValues['mime'] ) && isset( $cachedValues['metadata'] ) )
117 if ( $wgUseSharedUploads && $cachedValues['fromShared']) {
118 # if this is shared file, we need to check if image
119 # in shared repository has not changed
120 if ( isset( $keys[1] ) ) {
121 $commonsCachedValues = $wgMemc->get( $keys[1] );
122 if (!empty($commonsCachedValues) && is_array($commonsCachedValues) && isset($commonsCachedValues['width'])) {
123 $this->name
= $commonsCachedValues['name'];
124 $this->imagePath
= $commonsCachedValues['imagePath'];
125 $this->fileExists
= $commonsCachedValues['fileExists'];
126 $this->width
= $commonsCachedValues['width'];
127 $this->height
= $commonsCachedValues['height'];
128 $this->bits
= $commonsCachedValues['bits'];
129 $this->type
= $commonsCachedValues['type'];
130 $this->mime
= $commonsCachedValues['mime'];
131 $this->metadata
= $commonsCachedValues['metadata'];
132 $this->size
= $commonsCachedValues['size'];
133 $this->fromSharedDirectory
= true;
134 $this->dataLoaded
= true;
135 $this->imagePath
= $this->getFullPath(true);
140 $this->name
= $cachedValues['name'];
141 $this->imagePath
= $cachedValues['imagePath'];
142 $this->fileExists
= $cachedValues['fileExists'];
143 $this->width
= $cachedValues['width'];
144 $this->height
= $cachedValues['height'];
145 $this->bits
= $cachedValues['bits'];
146 $this->type
= $cachedValues['type'];
147 $this->mime
= $cachedValues['mime'];
148 $this->metadata
= $cachedValues['metadata'];
149 $this->size
= $cachedValues['size'];
150 $this->fromSharedDirectory
= false;
151 $this->dataLoaded
= true;
152 $this->imagePath
= $this->getFullPath();
156 wfProfileOut( $fname );
157 return $this->dataLoaded
;
161 * Save the image metadata to memcached
163 function saveToCache() {
166 // We can't cache metadata for non-existent files, because if the file later appears
167 // in commons, the local keys won't be purged.
168 if ( $this->fileExists
) {
169 $keys = $this->getCacheKeys();
171 $cachedValues = array('name' => $this->name
,
172 'imagePath' => $this->imagePath
,
173 'fileExists' => $this->fileExists
,
174 'fromShared' => $this->fromSharedDirectory
,
175 'width' => $this->width
,
176 'height' => $this->height
,
177 'bits' => $this->bits
,
178 'type' => $this->type
,
179 'mime' => $this->mime
,
180 'metadata' => $this->metadata
,
181 'size' => $this->size
);
183 $wgMemc->set( $keys[0], $cachedValues );
188 * Load metadata from the file itself
190 function loadFromFile() {
191 global $wgUseSharedUploads, $wgSharedUploadDirectory, $wgLang,
193 $fname = 'Image::loadFromFile';
194 wfProfileIn( $fname );
195 $this->imagePath
= $this->getFullPath();
196 $this->fileExists
= file_exists( $this->imagePath
);
197 $this->fromSharedDirectory
= false;
200 if (!$this->fileExists
) wfDebug("$fname: ".$this->imagePath
." not found locally!\n");
202 # If the file is not found, and a shared upload directory is used, look for it there.
203 if (!$this->fileExists
&& $wgUseSharedUploads && $wgSharedUploadDirectory) {
204 # In case we're on a wgCapitalLinks=false wiki, we
205 # capitalize the first letter of the filename before
206 # looking it up in the shared repository.
207 $sharedImage = Image
::newFromName( $wgLang->ucfirst($this->name
) );
208 $this->fileExists
= file_exists( $sharedImage->getFullPath(true) );
209 if ( $this->fileExists
) {
210 $this->name
= $sharedImage->name
;
211 $this->imagePath
= $this->getFullPath(true);
212 $this->fromSharedDirectory
= true;
217 if ( $this->fileExists
) {
218 $magic=& wfGetMimeMagic();
220 $this->mime
= $magic->guessMimeType($this->imagePath
,true);
221 $this->type
= $magic->getMediaType($this->imagePath
,$this->mime
);
224 $this->size
= filesize( $this->imagePath
);
226 $magic=& wfGetMimeMagic();
229 if( $this->mime
== 'image/svg' ) {
230 wfSuppressWarnings();
231 $gis = wfGetSVGsize( $this->imagePath
);
234 elseif ( !$magic->isPHPImageType( $this->mime
) ) {
235 # Don't try to get the width and height of sound and video files, that's bad for performance
238 $gis[2]= 0; //unknown
239 $gis[3]= ""; //width height string
242 wfSuppressWarnings();
243 $gis = getimagesize( $this->imagePath
);
247 wfDebug("$fname: ".$this->imagePath
." loaded, ".$this->size
." bytes, ".$this->mime
.".\n");
252 $gis[2]= 0; //unknown
253 $gis[3]= ""; //width height string
256 $this->type
= MEDIATYPE_UNKNOWN
;
257 wfDebug("$fname: ".$this->imagePath
." NOT FOUND!\n");
260 $this->width
= $gis[0];
261 $this->height
= $gis[1];
263 #NOTE: $gis[2] contains a code for the image type. This is no longer used.
265 #NOTE: we have to set this flag early to avoid load() to be called
266 # be some of the functions below. This may lead to recursion or other bad things!
267 # as ther's only one thread of execution, this should be safe anyway.
268 $this->dataLoaded
= true;
271 if ($this->fileExists
&& $wgShowEXIF) $this->metadata
= serialize ( $this->retrieveExifData() ) ;
272 else $this->metadata
= serialize ( array() ) ;
274 if ( isset( $gis['bits'] ) ) $this->bits
= $gis['bits'];
275 else $this->bits
= 0;
277 wfProfileOut( $fname );
281 * Load image metadata from the DB
283 function loadFromDB() {
284 global $wgUseSharedUploads, $wgSharedUploadDBname, $wgLang;
285 $fname = 'Image::loadFromDB';
286 wfProfileIn( $fname );
288 $dbr =& wfGetDB( DB_SLAVE
);
290 $this->checkDBSchema($dbr);
292 $row = $dbr->selectRow( 'image',
293 array( 'img_size', 'img_width', 'img_height', 'img_bits',
294 'img_media_type', 'img_major_mime', 'img_minor_mime', 'img_metadata' ),
295 array( 'img_name' => $this->name
), $fname );
297 $this->fromSharedDirectory
= false;
298 $this->fileExists
= true;
299 $this->loadFromRow( $row );
300 $this->imagePath
= $this->getFullPath();
301 // Check for rows from a previous schema, quietly upgrade them
302 if ( is_null($this->type
) ) {
305 } elseif ( $wgUseSharedUploads && $wgSharedUploadDBname ) {
306 # In case we're on a wgCapitalLinks=false wiki, we
307 # capitalize the first letter of the filename before
308 # looking it up in the shared repository.
309 $name = $wgLang->ucfirst($this->name
);
311 $row = $dbr->selectRow( "`$wgSharedUploadDBname`.image",
312 array( 'img_size', 'img_width', 'img_height', 'img_bits', 'img_media_type', 'img_major_mime', 'img_minor_mime' ),
313 array( 'img_name' => $name ), $fname );
315 $this->fromSharedDirectory
= true;
316 $this->fileExists
= true;
317 $this->imagePath
= $this->getFullPath(true);
319 $this->loadFromRow( $row );
321 // Check for rows from a previous schema, quietly upgrade them
322 if ( is_null($this->type
) ) {
334 $this->fileExists
= false;
335 $this->fromSharedDirectory
= false;
336 $this->metadata
= serialize ( array() ) ;
339 # Unconditionally set loaded=true, we don't want the accessors constantly rechecking
340 $this->dataLoaded
= true;
344 * Load image metadata from a DB result row
346 function loadFromRow( &$row ) {
347 $this->size
= $row->img_size
;
348 $this->width
= $row->img_width
;
349 $this->height
= $row->img_height
;
350 $this->bits
= $row->img_bits
;
351 $this->type
= $row->img_media_type
;
353 $major= $row->img_major_mime
;
354 $minor= $row->img_minor_mime
;
356 if (!$major) $this->mime
= "unknown/unknown";
358 if (!$minor) $minor= "unknown";
359 $this->mime
= $major.'/'.$minor;
362 $this->metadata
= $row->img_metadata
;
363 if ( $this->metadata
== "" ) $this->metadata
= serialize ( array() ) ;
365 $this->dataLoaded
= true;
369 * Load image metadata from cache or DB, unless already loaded
372 global $wgSharedUploadDBname, $wgUseSharedUploads;
373 if ( !$this->dataLoaded
) {
374 if ( !$this->loadFromCache() ) {
376 if ( !$wgSharedUploadDBname && $wgUseSharedUploads ) {
377 $this->loadFromFile();
378 } elseif ( $this->fileExists
) {
379 $this->saveToCache();
382 $this->dataLoaded
= true;
387 * Metadata was loaded from the database, but the row had a marker indicating it needs to be
388 * upgraded from the 1.4 schema, which had no width, height, bits or type. Upgrade the row.
390 function upgradeRow() {
391 global $wgDBname, $wgSharedUploadDBname;
392 $fname = 'Image::upgradeRow';
393 $this->loadFromFile();
394 $dbw =& wfGetDB( DB_MASTER
);
396 if ( $this->fromSharedDirectory
) {
397 if ( !$wgSharedUploadDBname ) {
401 // Write to the other DB using selectDB, not database selectors
402 // This avoids breaking replication in MySQL
403 $dbw->selectDB( $wgSharedUploadDBname );
406 $this->checkDBSchema($dbw);
408 if (strpos($this->mime
,'/')!==false) {
409 list($major,$minor)= explode('/',$this->mime
,2);
416 wfDebug("$fname: upgrading ".$this->name
." to 1.5 schema\n");
418 $dbw->update( 'image',
420 'img_width' => $this->width
,
421 'img_height' => $this->height
,
422 'img_bits' => $this->bits
,
423 'img_media_type' => $this->type
,
424 'img_major_mime' => $major,
425 'img_minor_mime' => $minor,
426 'img_metadata' => $this->metadata
,
427 ), array( 'img_name' => $this->name
), $fname
429 if ( $this->fromSharedDirectory
) {
430 $dbw->selectDB( $wgDBname );
435 * Return the name of this image
443 * Return the associated title object
446 function getTitle() {
451 * Return the URL of the image file
457 if($this->fileExists
) {
458 $this->url
= Image
::imageUrl( $this->name
, $this->fromSharedDirectory
);
466 function getViewURL() {
467 if( $this->mustRender()) {
468 if( $this->canRender() ) {
469 return $this->createThumb( $this->getWidth() );
472 wfDebug('Image::getViewURL(): supposed to render '.$this->name
.' ('.$this->mime
."), but can't!\n");
473 return $this->getURL(); #hm... return NULL?
476 return $this->getURL();
481 * Return the image path of the image in the
482 * local file system as an absolute path
485 function getImagePath() {
487 return $this->imagePath
;
491 * Return the width of the image
493 * Returns -1 if the file specified is not a known image type
496 function getWidth() {
502 * Return the height of the image
504 * Returns -1 if the file specified is not a known image type
507 function getHeight() {
509 return $this->height
;
513 * Return the size of the image file, in bytes
522 * Returns the mime type of the file.
524 function getMimeType() {
530 * Return the type of the media in the file.
531 * Use the value returned by this function with the MEDIATYPE_xxx constants.
533 function getMediaType() {
539 * Checks if the file can be presented to the browser as a bitmap.
541 * Currently, this checks if the file is an image format
542 * that can be converted to a format
543 * supported by all browsers (namely GIF, PNG and JPEG),
544 * or if it is an SVG image and SVG conversion is enabled.
546 * @todo remember the result of this check.
548 function canRender() {
549 global $wgUseImageMagick;
551 if( $this->getWidth()<=0 ||
$this->getHeight()<=0 ) return false;
553 $mime= $this->getMimeType();
555 if (!$mime ||
$mime==='unknown' ||
$mime==='unknown/unknown') return false;
557 #if it's SVG, check if ther's a converter enabled
558 if ($mime === 'image/svg') {
559 global $wgSVGConverters, $wgSVGConverter;
561 if ($wgSVGConverter && isset( $wgSVGConverters[$wgSVGConverter])) {
566 #image formats available on ALL browsers
567 if ( $mime === 'image/gif'
568 ||
$mime === 'image/png'
569 ||
$mime === 'image/jpeg' ) return true;
571 #image formats that can be converted to the above formats
572 if ($wgUseImageMagick) {
573 #convertable by ImageMagick (there are more...)
574 if ( $mime === 'image/vnd.wap.wbmp'
575 ||
$mime === 'image/x-xbitmap'
576 ||
$mime === 'image/x-xpixmap'
577 #|| $mime === 'image/x-icon' #file may be split into multiple parts
578 ||
$mime === 'image/x-portable-anymap'
579 ||
$mime === 'image/x-portable-bitmap'
580 ||
$mime === 'image/x-portable-graymap'
581 ||
$mime === 'image/x-portable-pixmap'
582 #|| $mime === 'image/x-photoshop' #this takes a lot of CPU and RAM!
583 ||
$mime === 'image/x-rgb'
584 ||
$mime === 'image/x-bmp'
585 ||
$mime === 'image/tiff' ) return true;
588 #convertable by the PHP GD image lib
589 if ( $mime === 'image/vnd.wap.wbmp'
590 ||
$mime === 'image/x-xbitmap' ) return true;
598 * Return true if the file is of a type that can't be directly
599 * rendered by typical browsers and needs to be re-rasterized.
601 * This returns true for everything but the bitmap types
602 * supported by all browsers, i.e. JPEG; GIF and PNG. It will
603 * also return true for any non-image formats.
607 function mustRender() {
608 $mime= $this->getMimeType();
610 if ( $mime === "image/gif"
611 ||
$mime === "image/png"
612 ||
$mime === "image/jpeg" ) return false;
618 * Determines if this media file may be shown inline on a page.
620 * This is currently synonymous to canRender(), but this could be
621 * extended to also allow inline display of other media,
622 * like flash animations or videos. If you do so, please keep in mind that
623 * that could be a scurity risc.
625 function allowInlineDisplay() {
626 return $this->canRender();
630 * Determines if this media file is in a format that is unlikely to contain viruses
631 * or malicious content. It uses the global $wgTrustedMediaFormats list to determine
632 * if the file is safe.
634 * This is used to show a warning on the description page of non-safe files.
635 * It may also be used to disallow direct [[media:...]] links to such files.
637 * Note that this function will always return ture if allowInlineDisplay()
638 * or isTrustedFile() is true for this file.
640 function isSafeFile() {
641 if ($this->allowInlineDisplay()) return true;
642 if ($this->isTrustedFile()) return true;
644 global $wgTrustedMediaFormats;
646 $type= $this->getMediaType();
647 $mime= $this->getMimeType();
648 #wfDebug("Image::isSafeFile: type= $type, mime= $mime\n");
650 if (!$type ||
$type===MEDIATYPE_UNKNOWN
) return false; #unknown type, not trusted
651 if ( in_array( $type, $wgTrustedMediaFormats) ) return true;
653 if ($mime==="unknown/unknown") return false; #unknown type, not trusted
654 if ( in_array( $mime, $wgTrustedMediaFormats) ) return true;
659 /** Returns true if the file is flagegd as trusted. Files flagged that way can be
660 * linked to directly, even if that is not allowed for this type of file normally.
662 * This is a dummy function right now and always returns false. It could be implemented
663 * to extract a flag from the database. The trusted flag could be set on upload, if the
664 * user has sufficient privileges, to bypass script- and html-filters. It may even be
665 * coupeled with cryptographics signatures or such.
667 function isTrustedFile() {
668 #this could be implemented to check a flag in the databas,
669 #look for signatures, etc
674 * Return the escapeLocalURL of this image
677 function getEscapeLocalURL() {
679 return $this->title
->escapeLocalURL();
683 * Return the escapeFullURL of this image
686 function getEscapeFullURL() {
688 return $this->title
->escapeFullURL();
692 * Return the URL of an image, provided its name.
694 * @param string $name Name of the image, without the leading "Image:"
695 * @param boolean $fromSharedDirectory Should this be in $wgSharedUploadPath?
699 function imageUrl( $name, $fromSharedDirectory = false ) {
700 global $wgUploadPath,$wgUploadBaseUrl,$wgSharedUploadPath;
701 if($fromSharedDirectory) {
703 $path = $wgSharedUploadPath;
705 $base = $wgUploadBaseUrl;
706 $path = $wgUploadPath;
708 $url = "{$base}{$path}" . wfGetHashPath($name, $fromSharedDirectory) . "{$name}";
709 return wfUrlencode( $url );
713 * Returns true if the image file exists on disk.
719 return $this->fileExists
;
726 function thumbUrl( $width, $subdir='thumb') {
727 global $wgUploadPath, $wgUploadBaseUrl,
728 $wgSharedUploadPath,$wgSharedUploadDirectory,
729 $wgSharedThumbnailScriptPath, $wgThumbnailScriptPath;
731 // Generate thumb.php URL if possible
735 if ( $this->fromSharedDirectory
) {
736 if ( $wgSharedThumbnailScriptPath ) {
737 $script = $wgSharedThumbnailScriptPath;
740 if ( $wgThumbnailScriptPath ) {
741 $script = $wgThumbnailScriptPath;
745 $url = $script . '?f=' . urlencode( $this->name
) . '&w=' . urlencode( $width );
746 if( $this->mustRender() ) {
750 $name = $this->thumbName( $width );
751 if($this->fromSharedDirectory
) {
753 $path = $wgSharedUploadPath;
755 $base = $wgUploadBaseUrl;
756 $path = $wgUploadPath;
758 if ( Image
::isHashed( $this->fromSharedDirectory
) ) {
759 $url = "{$base}{$path}/{$subdir}" .
760 wfGetHashPath($this->name
, $this->fromSharedDirectory
)
761 . $this->name
.'/'.$name;
762 $url = wfUrlencode( $url );
764 $url = "{$base}{$path}/{$subdir}/{$name}";
767 return array( $script !== false, $url );
771 * Return the file name of a thumbnail of the specified width
773 * @param integer $width Width of the thumbnail image
774 * @param boolean $shared Does the thumbnail come from the shared repository?
777 function thumbName( $width ) {
778 $thumb = $width."px-".$this->name
;
780 if( $this->mustRender() ) {
781 if( $this->canRender() ) {
782 # Rasterize to PNG (for SVG vector images, etc)
786 #should we use iconThumb here to get a symbolic thumbnail?
787 #or should we fail with an internal error?
788 return NULL; //can't make bitmap
795 * Create a thumbnail of the image having the specified width/height.
796 * The thumbnail will not be created if the width is larger than the
797 * image's width. Let the browser do the scaling in this case.
798 * The thumbnail is stored on disk and is only computed if the thumbnail
799 * file does not exist OR if it is older than the image.
802 * Keeps aspect ratio of original image. If both width and height are
803 * specified, the generated image will be no bigger than width x height,
804 * and will also have correct aspect ratio.
806 * @param integer $width maximum width of the generated thumbnail
807 * @param integer $height maximum height of the image (optional)
810 function createThumb( $width, $height=-1 ) {
811 $thumb = $this->getThumbnail( $width, $height );
812 if( is_null( $thumb ) ) return '';
813 return $thumb->getUrl();
817 * As createThumb, but returns a ThumbnailImage object. This can
818 * provide access to the actual file, the real size of the thumb,
819 * and can produce a convenient <img> tag for you.
821 * @param integer $width maximum width of the generated thumbnail
822 * @param integer $height maximum height of the image (optional)
823 * @return ThumbnailImage
826 function &getThumbnail( $width, $height=-1 ) {
827 if ( $height == -1 ) {
828 return $this->renderThumb( $width );
832 if ($this->canRender()) {
833 if ( $width < $this->width
) {
834 $thumbheight = $this->height
* $width / $this->width
;
835 $thumbwidth = $width;
837 $thumbheight = $this->height
;
838 $thumbwidth = $this->width
;
840 if ( $thumbheight > $height ) {
841 $thumbwidth = $thumbwidth * $height / $thumbheight;
842 $thumbheight = $height;
845 $thumb = $this->renderThumb( $thumbwidth );
847 else $thumb= NULL; #not a bitmap or renderable image, don't try.
849 if( is_null( $thumb ) ) {
850 $thumb = $this->iconThumb();
856 * @return ThumbnailImage
858 function iconThumb() {
859 global $wgStylePath, $wgStyleDirectory;
861 $try = array( 'fileicon-' . $this->extension
. '.png', 'fileicon.png' );
862 foreach( $try as $icon ) {
863 $path = '/common/images/icons/' . $icon;
864 $filepath = $wgStyleDirectory . $path;
865 if( file_exists( $filepath ) ) {
866 return new ThumbnailImage( $wgStylePath . $path, 120, 120 );
873 * Create a thumbnail of the image having the specified width.
874 * The thumbnail will not be created if the width is larger than the
875 * image's width. Let the browser do the scaling in this case.
876 * The thumbnail is stored on disk and is only computed if the thumbnail
877 * file does not exist OR if it is older than the image.
878 * Returns an object which can return the pathname, URL, and physical
879 * pixel size of the thumbnail -- or null on failure.
881 * @return ThumbnailImage
884 function renderThumb( $width, $useScript = true ) {
885 global $wgUseSquid, $wgInternalServer;
886 global $wgThumbnailScriptPath, $wgSharedThumbnailScriptPath;
888 $width = IntVal( $width );
891 if ( ! $this->exists() )
893 # If there is no image, there will be no thumbnail
897 # Sanity check $width
898 if( $width <= 0 ||
$this->width
<= 0) {
903 if( $width > $this->width
&& !$this->mustRender() ) {
904 # Don't make an image bigger than the source
905 return new ThumbnailImage( $this->getViewURL(), $this->getWidth(), $this->getHeight() );
908 $height = floor( $this->height
* ( $width/$this->width
) );
910 list( $isScriptUrl, $url ) = $this->thumbUrl( $width );
911 if ( $isScriptUrl && $useScript ) {
912 // Use thumb.php to render the image
913 return new ThumbnailImage( $url, $width, $height );
916 $thumbName = $this->thumbName( $width, $this->fromSharedDirectory
);
917 $thumbPath = wfImageThumbDir( $this->name
, $this->fromSharedDirectory
).'/'.$thumbName;
919 if ( !file_exists( $thumbPath ) ) {
920 $oldThumbPath = wfDeprecatedThumbDir( $thumbName, 'thumb', $this->fromSharedDirectory
).
923 if ( file_exists( $oldThumbPath ) ) {
924 if ( filemtime($oldThumbPath) >= filemtime($this->imagePath
) ) {
925 rename( $oldThumbPath, $thumbPath );
928 unlink( $oldThumbPath );
932 $this->reallyRenderThumb( $thumbPath, $width, $height );
935 # This has to be done after the image is updated and present for all machines on NFS,
936 # or else the old version might be stored into the squid again
938 if ( substr( $url, 0, 4 ) == 'http' ) {
939 $urlArr = array( $url );
941 $urlArr = array( $wgInternalServer.$url );
943 wfPurgeSquidServers($urlArr);
948 return new ThumbnailImage( $url, $width, $height, $thumbPath );
949 } // END OF function renderThumb
952 * Really render a thumbnail
953 * Call this only for images for which canRender() returns true.
957 function reallyRenderThumb( $thumbPath, $width, $height ) {
958 global $wgSVGConverters, $wgSVGConverter,
959 $wgUseImageMagick, $wgImageMagickConvertCommand;
963 if( $this->mime
=== "image/svg" ) {
964 #Right now we have only SVG
966 global $wgSVGConverters, $wgSVGConverter;
967 if( isset( $wgSVGConverters[$wgSVGConverter] ) ) {
968 global $wgSVGConverterPath;
970 array( '$path/', '$width', '$input', '$output' ),
971 array( $wgSVGConverterPath,
973 wfEscapeShellArg( $this->imagePath
),
974 wfEscapeShellArg( $thumbPath ) ),
975 $wgSVGConverters[$wgSVGConverter] );
976 $conv = shell_exec( $cmd );
980 } elseif ( $wgUseImageMagick ) {
982 # Specify white background color, will be used for transparent images
983 # in Internet Explorer/Windows instead of default black.
984 $cmd = $wgImageMagickConvertCommand .
985 " -quality 85 -background white -geometry {$width} ".
986 wfEscapeShellArg($this->imagePath
) . " " .
987 wfEscapeShellArg($thumbPath);
988 wfDebug("reallyRenderThumb: running ImageMagick: $cmd");
989 $conv = shell_exec( $cmd );
991 # Use PHP's builtin GD library functions.
993 # First find out what kind of file this is, and select the correct
994 # input routine for this.
998 switch( $this->type
) {
1000 $src_image = imagecreatefromgif( $this->imagePath
);
1003 $src_image = imagecreatefromjpeg( $this->imagePath
);
1007 $src_image = imagecreatefrompng( $this->imagePath
);
1008 $truecolor = ( $this->bits
> 8 );
1010 case 15: # WBMP for WML
1011 $src_image = imagecreatefromwbmp( $this->imagePath
);
1014 $src_image = imagecreatefromxbm( $this->imagePath
);
1017 return 'Image type not supported';
1021 $dst_image = imagecreatetruecolor( $width, $height );
1023 $dst_image = imagecreate( $width, $height );
1025 imagecopyresampled( $dst_image, $src_image,
1027 $width, $height, $this->width
, $this->height
);
1028 switch( $this->type
) {
1033 imagepng( $dst_image, $thumbPath );
1036 imageinterlace( $dst_image );
1037 imagejpeg( $dst_image, $thumbPath, 95 );
1042 imagedestroy( $dst_image );
1043 imagedestroy( $src_image );
1047 # Check for zero-sized thumbnails. Those can be generated when
1048 # no disk space is available or some other error occurs
1050 if( file_exists( $thumbPath ) ) {
1051 $thumbstat = stat( $thumbPath );
1052 if( $thumbstat['size'] == 0 ) {
1053 unlink( $thumbPath );
1059 * Get all thumbnail names previously generated for this image
1061 function getThumbnails( $shared = false ) {
1062 if ( Image
::isHashed( $shared ) ) {
1065 $dir = wfImageThumbDir( $this->name
, $shared );
1067 // This generates an error on failure, hence the @
1068 $handle = @opendir
( $dir );
1071 while ( false !== ( $file = readdir($handle) ) ) {
1072 if ( $file{0} != '.' ) {
1076 closedir( $handle );
1086 * Delete all previously generated thumbnails, refresh metadata in memcached and purge the squid
1088 function purgeCache( $archiveFiles = array(), $shared = false ) {
1089 global $wgInternalServer, $wgUseSquid;
1091 // Refresh metadata cache
1093 $this->loadFromFile();
1094 $this->saveToCache();
1096 // Delete thumbnails
1097 $files = $this->getThumbnails( $shared );
1098 $dir = wfImageThumbDir( $this->name
, $shared );
1100 foreach ( $files as $file ) {
1101 if ( preg_match( '/^(\d+)px/', $file, $m ) ) {
1102 $urls[] = $wgInternalServer . $this->thumbUrl( $m[1], $this->fromSharedDirectory
);
1103 @unlink
( "$dir/$file" );
1108 if ( $wgUseSquid ) {
1109 $urls[] = $wgInternalServer . $this->getViewURL();
1110 foreach ( $archiveFiles as $file ) {
1111 $urls[] = $wgInternalServer . wfImageArchiveUrl( $file );
1113 wfPurgeSquidServers( $urls );
1117 function checkDBSchema(&$db) {
1118 # img_name must be unique
1119 if ( !$db->indexUnique( 'image', 'img_name' ) && !$db->indexExists('image','PRIMARY') ) {
1120 wfDebugDieBacktrace( 'Database schema not up to date, please run maintenance/archives/patch-image_name_unique.sql' );
1123 #new fields must exist
1124 if ( !$db->fieldExists( 'image', 'img_media_type' )
1125 ||
!$db->fieldExists( 'image', 'img_metadata' )
1126 ||
!$db->fieldExists( 'image', 'img_width' ) ) {
1128 wfDebugDieBacktrace( 'Database schema not up to date, please run maintenance/updater.php' );
1133 * Return the image history of this image, line by line.
1134 * starts with current version, then old versions.
1135 * uses $this->historyLine to check which line to return:
1136 * 0 return line for current version
1137 * 1 query for old versions, return first one
1138 * 2, ... return next old version from above query
1142 function nextHistoryLine() {
1143 $fname = 'Image::nextHistoryLine()';
1144 $dbr =& wfGetDB( DB_SLAVE
);
1146 $this->checkDBSchema($dbr);
1148 if ( $this->historyLine
== 0 ) {// called for the first time, return line from cur
1149 $this->historyRes
= $dbr->select( 'image',
1150 array( 'img_size','img_description','img_user','img_user_text','img_timestamp', "'' AS oi_archive_name" ),
1151 array( 'img_name' => $this->title
->getDBkey() ),
1154 if ( 0 == wfNumRows( $this->historyRes
) ) {
1157 } else if ( $this->historyLine
== 1 ) {
1158 $this->historyRes
= $dbr->select( 'oldimage',
1159 array( 'oi_size AS img_size', 'oi_description AS img_description', 'oi_user AS img_user',
1160 'oi_user_text AS img_user_text', 'oi_timestamp AS img_timestamp', 'oi_archive_name'
1161 ), array( 'oi_name' => $this->title
->getDBkey() ), $fname, array( 'ORDER BY' => 'oi_timestamp DESC' )
1164 $this->historyLine ++
;
1166 return $dbr->fetchObject( $this->historyRes
);
1170 * Reset the history pointer to the first element of the history
1173 function resetHistory() {
1174 $this->historyLine
= 0;
1178 * Return the full filesystem path to the file. Note that this does
1179 * not mean that a file actually exists under that location.
1181 * This path depends on whether directory hashing is active or not,
1182 * i.e. whether the images are all found in the same directory,
1183 * or in hashed paths like /images/3/3c.
1186 * @param boolean $fromSharedDirectory Return the path to the file
1187 * in a shared repository (see $wgUseSharedRepository and related
1188 * options in DefaultSettings.php) instead of a local one.
1191 function getFullPath( $fromSharedRepository = false ) {
1192 global $wgUploadDirectory, $wgSharedUploadDirectory;
1193 global $wgHashedUploadDirectory, $wgHashedSharedUploadDirectory;
1195 $dir = $fromSharedRepository ?
$wgSharedUploadDirectory :
1198 // $wgSharedUploadDirectory may be false, if thumb.php is used
1200 $fullpath = $dir . wfGetHashPath($this->name
, $fromSharedRepository) . $this->name
;
1212 function isHashed( $shared ) {
1213 global $wgHashedUploadDirectory, $wgHashedSharedUploadDirectory;
1214 return $shared ?
$wgHashedSharedUploadDirectory : $wgHashedUploadDirectory;
1218 * Record an image upload in the upload log and the image table
1220 function recordUpload( $oldver, $desc, $copyStatus = '', $source = '' ) {
1221 global $wgUser, $wgLang, $wgTitle, $wgOut, $wgDeferredUpdateList;
1222 global $wgUseCopyrightUpload, $wgUseSquid, $wgPostCommitUpdateList;
1224 $fname = 'Image::recordUpload';
1225 $dbw =& wfGetDB( DB_MASTER
);
1227 $this->checkDBSchema($dbw);
1229 // Delete thumbnails and refresh the metadata cache
1230 $this->purgeCache();
1232 // Fail now if the image isn't there
1233 if ( !$this->fileExists ||
$this->fromSharedDirectory
) {
1234 wfDebug( "Image::recordUpload: File ".$this->imagePath
." went missing!\n" );
1238 if ( $wgUseCopyrightUpload ) {
1239 $textdesc = '== ' . wfMsg ( 'filedesc' ) . " ==\n" . $desc . "\n" .
1240 '== ' . wfMsg ( 'filestatus' ) . " ==\n" . $copyStatus . "\n" .
1241 '== ' . wfMsg ( 'filesource' ) . " ==\n" . $source ;
1246 $now = $dbw->timestamp();
1249 if (strpos($this->mime
,'/')!==false) {
1250 list($major,$minor)= explode('/',$this->mime
,2);
1253 $major= $this->mime
;
1257 # Test to see if the row exists using INSERT IGNORE
1258 # This avoids race conditions by locking the row until the commit, and also
1259 # doesn't deadlock. SELECT FOR UPDATE causes a deadlock for every race condition.
1260 $dbw->insert( 'image',
1262 'img_name' => $this->name
,
1263 'img_size'=> $this->size
,
1264 'img_width' => $this->width
,
1265 'img_height' => $this->height
,
1266 'img_bits' => $this->bits
,
1267 'img_media_type' => $this->type
,
1268 'img_major_mime' => $major,
1269 'img_minor_mime' => $minor,
1270 'img_timestamp' => $now,
1271 'img_description' => $desc,
1272 'img_user' => $wgUser->getID(),
1273 'img_user_text' => $wgUser->getName(),
1274 'img_metadata' => $this->metadata
,
1277 $descTitle = $this->getTitle();
1278 $purgeURLs = array();
1280 if ( $dbw->affectedRows() ) {
1281 # Successfully inserted, this is a new image
1282 $id = $descTitle->getArticleID();
1285 $article = new Article( $descTitle );
1286 $article->insertNewArticle( $textdesc, $desc, false, false, true );
1289 # Collision, this is an update of an image
1290 # Insert previous contents into oldimage
1291 $dbw->insertSelect( 'oldimage', 'image',
1293 'oi_name' => 'img_name',
1294 'oi_archive_name' => $dbw->addQuotes( $oldver ),
1295 'oi_size' => 'img_size',
1296 'oi_width' => 'img_width',
1297 'oi_height' => 'img_height',
1298 'oi_bits' => 'img_bits',
1299 'oi_timestamp' => 'img_timestamp',
1300 'oi_description' => 'img_description',
1301 'oi_user' => 'img_user',
1302 'oi_user_text' => 'img_user_text',
1303 ), array( 'img_name' => $this->name
), $fname
1306 # Update the current image row
1307 $dbw->update( 'image',
1309 'img_size' => $this->size
,
1310 'img_width' => $this->width
,
1311 'img_height' => $this->height
,
1312 'img_bits' => $this->bits
,
1313 'img_media_type' => $this->type
,
1314 'img_major_mime' => $major,
1315 'img_minor_mime' => $minor,
1316 'img_timestamp' => $now,
1317 'img_description' => $desc,
1318 'img_user' => $wgUser->getID(),
1319 'img_user_text' => $wgUser->getName(),
1320 'img_metadata' => $this->metadata
,
1321 ), array( /* WHERE */
1322 'img_name' => $this->name
1326 # Invalidate the cache for the description page
1327 $descTitle->invalidateCache();
1328 $purgeURLs[] = $descTitle->getInternalURL();
1331 # Invalidate cache for all pages using this image
1332 $linksTo = $this->getLinksTo();
1334 if ( $wgUseSquid ) {
1335 $u = SquidUpdate
::newFromTitles( $linksTo, $purgeURLs );
1336 array_push( $wgPostCommitUpdateList, $u );
1338 Title
::touchArray( $linksTo );
1340 $log = new LogPage( 'upload' );
1341 $log->addEntry( 'upload', $descTitle, $desc );
1347 * Get an array of Title objects which are articles which use this image
1348 * Also adds their IDs to the link cache
1350 * This is mostly copied from Title::getLinksTo()
1352 function getLinksTo( $options = '' ) {
1353 global $wgLinkCache;
1354 $fname = 'Image::getLinksTo';
1355 wfProfileIn( $fname );
1358 $db =& wfGetDB( DB_MASTER
);
1360 $db =& wfGetDB( DB_SLAVE
);
1363 extract( $db->tableNames( 'page', 'imagelinks' ) );
1364 $encName = $db->addQuotes( $this->name
);
1365 $sql = "SELECT page_namespace,page_title,page_id FROM $page,$imagelinks WHERE page_id=il_from AND il_to=$encName $options";
1366 $res = $db->query( $sql, $fname );
1369 if ( $db->numRows( $res ) ) {
1370 while ( $row = $db->fetchObject( $res ) ) {
1371 if ( $titleObj = Title
::makeTitle( $row->page_namespace
, $row->page_title
) ) {
1372 $wgLinkCache->addGoodLink( $row->page_id
, $titleObj->getPrefixedDBkey() );
1373 $retVal[] = $titleObj;
1377 $db->freeResult( $res );
1381 * Retrive Exif data from the database
1383 * Retrive Exif data from the database and prune unrecognized tags
1384 * and/or tags with invalid contents
1388 function retrieveExifData () {
1389 if ( $this->getMimeType() !== "image/jpeg" ) return array ();
1391 $exif = exif_read_data( $this->imagePath
);
1392 foreach($exif as $k => $v) {
1393 if ( !in_array($k, array_keys($this->exif
->mFlatExif
)) ) {
1394 wfDebug( "Image::retrieveExifData: '$k' is not a valid Exif tag (type: '" . gettype($v) . "'; data: '$v')\n");
1399 foreach($exif as $k => $v) {
1400 if ( !$this->exif
->validate($k, $v) ) {
1401 wfDebug( "Image::retrieveExifData: '$k' contained invalid data (type: '" . gettype($v) . "'; data: '$v')\n");
1408 function getExifData () {
1410 if ( $this->metadata
=== '0' )
1413 $purge = $wgRequest->getVal( 'action' ) == 'purge';
1414 $ret = unserialize ( $this->metadata
);
1416 $oldver = isset( $ret['MEDIAWIKI_EXIF_VERSION'] ) ?
$ret['MEDIAWIKI_EXIF_VERSION'] : 0;
1417 $newver = $this->exif
->version();
1419 if ( !count( $ret ) ||
$purge ||
$oldver != $newver ) {
1420 $this->updateExifData( $newver );
1422 if ( isset( $ret['MEDIAWIKI_EXIF_VERSION'] ) )
1423 unset( $ret['MEDIAWIKI_EXIF_VERSION'] );
1425 foreach($ret as $k => $v) {
1426 $ret[$k] = $this->exif
->format($k, $v);
1432 function updateExifData( $version ) {
1433 $fname = 'Image:updateExifData';
1435 if ( $this->getImagePath() === false ) # Not a local image
1438 # Get EXIF data from image
1439 $exif = $this->retrieveExifData();
1440 if ( count( $exif ) ) {
1441 $exif['MEDIAWIKI_EXIF_VERSION'] = $version;
1442 $this->metadata
= serialize( $exif );
1444 $this->metadata
= '0';
1447 # Update EXIF data in database
1448 $dbw =& wfGetDB( DB_MASTER
);
1450 $this->checkDBSchema($dbw);
1452 $dbw->update( 'image',
1453 array( 'img_metadata' => $this->metadata
),
1454 array( 'img_name' => $this->name
),
1463 * Returns the image directory of an image
1464 * If the directory does not exist, it is created.
1465 * The result is an absolute path.
1467 * This function is called from thumb.php before Setup.php is included
1469 * @param string $fname file name of the image file
1472 function wfImageDir( $fname ) {
1473 global $wgUploadDirectory, $wgHashedUploadDirectory;
1475 if (!$wgHashedUploadDirectory) { return $wgUploadDirectory; }
1477 $hash = md5( $fname );
1478 $oldumask = umask(0);
1479 $dest = $wgUploadDirectory . '/' . $hash{0};
1480 if ( ! is_dir( $dest ) ) { mkdir( $dest, 0777 ); }
1481 $dest .= '/' . substr( $hash, 0, 2 );
1482 if ( ! is_dir( $dest ) ) { mkdir( $dest, 0777 ); }
1489 * Returns the image directory of an image's thubnail
1490 * If the directory does not exist, it is created.
1491 * The result is an absolute path.
1493 * This function is called from thumb.php before Setup.php is included
1495 * @param string $fname file name of the original image file
1496 * @param string $subdir (optional) subdirectory of the image upload directory that should be used for storing the thumbnail. Default is 'thumb'
1497 * @param boolean $shared (optional) use the shared upload directory
1500 function wfImageThumbDir( $fname, $shared = false ) {
1501 $base = wfImageArchiveDir( $fname, 'thumb', $shared );
1502 if ( Image
::isHashed( $shared ) ) {
1503 $dir = "$base/$fname";
1505 if ( !is_dir( $base ) ) {
1506 $oldumask = umask(0);
1507 @mkdir
( $base, 0777 );
1511 if ( ! is_dir( $dir ) ) {
1512 $oldumask = umask(0);
1513 @mkdir
( $dir, 0777 );
1524 * Old thumbnail directory, kept for conversion
1526 function wfDeprecatedThumbDir( $thumbName , $subdir='thumb', $shared=false) {
1527 return wfImageArchiveDir( $thumbName, $subdir, $shared );
1531 * Returns the image directory of an image's old version
1532 * If the directory does not exist, it is created.
1533 * The result is an absolute path.
1535 * This function is called from thumb.php before Setup.php is included
1537 * @param string $fname file name of the thumbnail file, including file size prefix
1538 * @param string $subdir (optional) subdirectory of the image upload directory that should be used for storing the old version. Default is 'archive'
1539 * @param boolean $shared (optional) use the shared upload directory (only relevant for other functions which call this one)
1542 function wfImageArchiveDir( $fname , $subdir='archive', $shared=false ) {
1543 global $wgUploadDirectory, $wgHashedUploadDirectory,
1544 $wgSharedUploadDirectory, $wgHashedSharedUploadDirectory;
1545 $dir = $shared ?
$wgSharedUploadDirectory : $wgUploadDirectory;
1546 $hashdir = $shared ?
$wgHashedSharedUploadDirectory : $wgHashedUploadDirectory;
1547 if (!$hashdir) { return $dir.'/'.$subdir; }
1548 $hash = md5( $fname );
1549 $oldumask = umask(0);
1551 # Suppress warning messages here; if the file itself can't
1552 # be written we'll worry about it then.
1553 wfSuppressWarnings();
1555 $archive = $dir.'/'.$subdir;
1556 if ( ! is_dir( $archive ) ) { mkdir( $archive, 0777 ); }
1557 $archive .= '/' . $hash{0};
1558 if ( ! is_dir( $archive ) ) { mkdir( $archive, 0777 ); }
1559 $archive .= '/' . substr( $hash, 0, 2 );
1560 if ( ! is_dir( $archive ) ) { mkdir( $archive, 0777 ); }
1562 wfRestoreWarnings();
1569 * Return the hash path component of an image path (URL or filesystem),
1570 * e.g. "/3/3c/", or just "/" if hashing is not used.
1572 * @param $dbkey The filesystem / database name of the file
1573 * @param $fromSharedDirectory Use the shared file repository? It may
1574 * use different hash settings from the local one.
1576 function wfGetHashPath ( $dbkey, $fromSharedDirectory = false ) {
1577 global $wgHashedSharedUploadDirectory, $wgSharedUploadDirectory;
1578 global $wgHashedUploadDirectory;
1580 if( Image
::isHashed( $fromSharedDirectory ) ) {
1581 $hash = md5($dbkey);
1582 return '/' . $hash{0} . '/' . substr( $hash, 0, 2 ) . '/';
1589 * Returns the image URL of an image's old version
1591 * @param string $fname file name of the image file
1592 * @param string $subdir (optional) subdirectory of the image upload directory that is used by the old version. Default is 'archive'
1595 function wfImageArchiveUrl( $name, $subdir='archive' ) {
1596 global $wgUploadPath, $wgHashedUploadDirectory;
1598 if ($wgHashedUploadDirectory) {
1599 $hash = md5( substr( $name, 15) );
1600 $url = $wgUploadPath.'/'.$subdir.'/' . $hash{0} . '/' .
1601 substr( $hash, 0, 2 ) . '/'.$name;
1603 $url = $wgUploadPath.'/'.$subdir.'/'.$name;
1605 return wfUrlencode($url);
1609 * Return a rounded pixel equivalent for a labeled CSS/SVG length.
1610 * http://www.w3.org/TR/SVG11/coords.html#UnitIdentifiers
1612 * @param string $length
1613 * @return int Length in pixels
1615 function wfScaleSVGUnit( $length ) {
1616 static $unitLength = array(
1623 '' => 1.0, // "User units" pixels by default
1624 '%' => 2.0, // Fake it!
1626 if( preg_match( '/^(\d+)(em|ex|px|pt|pc|cm|mm|in|%|)$/', $length, $matches ) ) {
1627 $length = FloatVal( $matches[1] );
1628 $unit = $matches[2];
1629 return round( $length * $unitLength[$unit] );
1632 return round( FloatVal( $length ) );
1637 * Compatible with PHP getimagesize()
1638 * @todo support gzipped SVGZ
1639 * @todo check XML more carefully
1640 * @todo sensible defaults
1642 * @param string $filename
1645 function wfGetSVGsize( $filename ) {
1649 // Read a chunk of the file
1650 $f = fopen( $filename, "rt" );
1651 if( !$f ) return false;
1652 $chunk = fread( $f, 4096 );
1655 // Uber-crappy hack! Run through a real XML parser.
1656 if( !preg_match( '/<svg\s*([^>]*)\s*>/s', $chunk, $matches ) ) {
1660 if( preg_match( '/\bwidth\s*=\s*("[^"]+"|\'[^\']+\')/s', $tag, $matches ) ) {
1661 $width = wfScaleSVGUnit( trim( substr( $matches[1], 1, -1 ) ) );
1663 if( preg_match( '/\bheight\s*=\s*("[^"]+"|\'[^\']+\')/s', $tag, $matches ) ) {
1664 $height = wfScaleSVGUnit( trim( substr( $matches[1], 1, -1 ) ) );
1667 return array( $width, $height, 'SVG',
1668 "width=\"$width\" height=\"$height\"" );
1672 * Determine if an image exists on the 'bad image list'
1674 * @param string $name The image to check
1677 function wfIsBadImage( $name ) {
1679 static $titleList = false;
1680 if ( $titleList === false ) {
1681 $titleList = array();
1683 $lines = explode("\n", wfMsgForContent( 'bad_image_list' ));
1684 foreach ( $lines as $line ) {
1685 if ( preg_match( '/^\*\s*\[{2}:(' . $wgContLang->getNsText( NS_IMAGE
) . ':.*?)\]{2}/', $line, $m ) ) {
1686 $t = Title
::newFromText( $m[1] );
1687 $titleList[$t->getDBkey()] = 1;
1692 return array_key_exists( $name, $titleList );
1698 * Wrapper class for thumbnail images
1699 * @package MediaWiki
1701 class ThumbnailImage
{
1703 * @param string $path Filesystem path to the thumb
1704 * @param string $url URL path to the thumb
1707 function ThumbnailImage( $url, $width, $height, $path = false ) {
1709 $this->width
= $width;
1710 $this->height
= $height;
1711 $this->path
= $path;
1715 * @return string The thumbnail URL
1722 * Return HTML <img ... /> tag for the thumbnail, will include
1723 * width and height attributes and a blank alt text (as required).
1725 * You can set or override additional attributes by passing an
1726 * associative array of name => data pairs. The data will be escaped
1727 * for HTML output, so should be in plaintext.
1729 * @param array $attribs
1733 function toHtml( $attribs = array() ) {
1734 $attribs['src'] = $this->url
;
1735 $attribs['width'] = $this->width
;
1736 $attribs['height'] = $this->height
;
1737 if( !isset( $attribs['alt'] ) ) $attribs['alt'] = '';
1740 foreach( $attribs as $name => $data ) {
1741 $html .= $name . '="' . htmlspecialchars( $data ) . '" ';