7e6307eff469c1d915a0f1157ac9d10e88d8ecde
2 if ( ! defined( 'MEDIAWIKI' ) )
12 * Add images to the gallery using add(), then render that list to HTML using toHTML().
18 var $mImages, $mShowBytes, $mShowFilename;
19 var $mCaption = false;
22 * Is the gallery on a wiki page (i.e. not a special page)
27 * Create a new image gallery object.
29 function ImageGallery( ) {
30 $this->mImages
= array();
31 $this->mShowBytes
= true;
32 $this->mShowFilename
= true;
33 $this->mParsing
= false;
37 * Set the "parse" bit so we know to hide "bad" images
39 function setParsing( $val = true ) {
40 $this->mParsing
= $val;
46 * @param $caption Caption
48 function setCaption( $caption ) {
49 $this->mCaption
= $caption;
53 * Add an image to the gallery.
55 * @param $image Image object that is added to the gallery
56 * @param $html String: additional HTML text to be shown. The name and size of the image are always shown.
58 function add( $image, $html='' ) {
59 $this->mImages
[] = array( &$image, $html );
60 wfDebug( "ImageGallery::add " . $image->getName() . "\n" );
64 * Add an image at the beginning of the gallery.
66 * @param $image Image object that is added to the gallery
67 * @param $html String: Additional HTML text to be shown. The name and size of the image are always shown.
69 function insert( $image, $html='' ) {
70 array_unshift( $this->mImages
, array( &$image, $html ) );
75 * isEmpty() returns true if the gallery contains no images
78 return empty( $this->mImages
);
82 * Enable/Disable showing of the file size of an image in the gallery.
85 * @param $f Boolean: set to false to disable.
87 function setShowBytes( $f ) {
88 $this->mShowBytes
= ( $f == true);
92 * Enable/Disable showing of the filename of an image in the gallery.
95 * @param $f Boolean: set to false to disable.
97 function setShowFilename( $f ) {
98 $this->mShowFilename
= ( $f == true);
102 * Return a HTML representation of the image gallery
104 * For each image in the gallery, display
107 * - the additional text provided when adding the image
108 * - the size of the image
112 global $wgLang, $wgIgnoreImageErrors, $wgGenerateThumbnailOnParse;
114 $s = '<table class="gallery" cellspacing="0" cellpadding="0">';
115 if( $this->mCaption
)
116 $s .= '<td class="galleryheader" colspan="4"><big>' . htmlspecialchars( $this->mCaption
) . '</big></td>';
119 foreach ( $this->mImages
as $pair ) {
123 $name = $img->getName();
124 $nt = $img->getTitle();
126 if( $nt->getNamespace() != NS_IMAGE
) {
127 # We're dealing with a non-image, spit out the name and be done with it.
128 $thumbhtml = '<div style="height: 152px;">' . htmlspecialchars( $nt->getText() ) . '</div>';
130 else if( $this->mParsing
&& wfIsBadImage( $nt->getDBkey() ) ) {
131 # The image is blacklisted, just show it as a text link.
132 $thumbhtml = '<div style="height: 152px;">'
133 . Linker
::makeKnownLinkObj( $nt, htmlspecialchars( $nt->getText() ) ) . '</div>';
134 } else if( !( $thumb = $img->getThumbnail( 120, 120, $wgGenerateThumbnailOnParse ) ) ) {
135 # Error generating thumbnail.
136 $thumbhtml = '<div style="height: 152px;">'
137 . htmlspecialchars( $img->getLastError() ) . '</div>';
140 $vpad = floor( ( 150 - $thumb->height
) /2 ) - 2;
141 $thumbhtml = '<div class="thumb" style="padding: ' . $vpad . 'px 0;">'
142 . Linker
::makeKnownLinkObj( $nt, $thumb->toHtml() ) . '</div>';
146 //$ul = Linker::makeLink( $wgContLang->getNsText( Namespace::getUser() ) . ":{$ut}", $ut );
148 if( $this->mShowBytes
) {
149 if( $img->exists() ) {
150 $nb = wfMsgExt( 'nbytes', array( 'parsemag', 'escape'),
151 $wgLang->formatNum( $img->getSize() ) );
153 $nb = wfMsgHtml( 'filemissing' );
160 $textlink = $this->mShowFilename ?
161 Linker
::makeKnownLinkObj( $nt, htmlspecialchars( $wgLang->truncate( $nt->getText(), 20, '...' ) ) ) . "<br />\n" :
164 # ATTENTION: The newline after <div class="gallerytext"> is needed to accommodate htmltidy which
165 # in version 4.8.6 generated crackpot html in its absence, see:
166 # http://bugzilla.wikimedia.org/show_bug.cgi?id=1765 -Ævar
168 $s .= ($i%4
==0) ?
'<tr>' : '';
169 $s .= '<td><div class="gallerybox">' . $thumbhtml
170 . '<div class="gallerytext">' . "\n" . $textlink . $text . $nb
171 . "</div></div></td>\n";
172 $s .= ($i%4
==3) ?
'</tr>' : '';