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;
23 * Is the gallery on a wiki page (i.e. not a special page)
28 * Create a new image gallery object.
30 function ImageGallery( ) {
31 $this->mImages
= array();
32 $this->mShowBytes
= true;
33 $this->mShowFilename
= true;
34 $this->mParsing
= false;
38 * Set the "parse" bit so we know to hide "bad" images
40 function setParsing( $val = true ) {
41 $this->mParsing
= $val;
47 * @param $caption Caption
49 function setCaption( $caption ) {
50 $this->mCaption
= $caption;
54 * Instruct the class to use a specific skin for rendering
56 * @param $skin Skin object
58 function useSkin( &$skin ) {
59 $this->mSkin
=& $skin;
63 * Return the skin that should be used
70 $skin =& $wgUser->getSkin();
72 $skin =& $this->mSkin
;
78 * Add an image to the gallery.
80 * @param $image Image object that is added to the gallery
81 * @param $html String: additional HTML text to be shown. The name and size of the image are always shown.
83 function add( $image, $html='' ) {
84 $this->mImages
[] = array( &$image, $html );
88 * Add an image at the beginning of the gallery.
90 * @param $image Image object that is added to the gallery
91 * @param $html String: Additional HTML text to be shown. The name and size of the image are always shown.
93 function insert( $image, $html='' ) {
94 array_unshift( $this->mImages
, array( &$image, $html ) );
99 * isEmpty() returns true if the gallery contains no images
102 return empty( $this->mImages
);
106 * Enable/Disable showing of the file size of an image in the gallery.
107 * Enabled by default.
109 * @param $f Boolean: set to false to disable.
111 function setShowBytes( $f ) {
112 $this->mShowBytes
= ( $f == true);
116 * Enable/Disable showing of the filename of an image in the gallery.
117 * Enabled by default.
119 * @param $f Boolean: set to false to disable.
121 function setShowFilename( $f ) {
122 $this->mShowFilename
= ( $f == true);
126 * Return a HTML representation of the image gallery
128 * For each image in the gallery, display
131 * - the additional text provided when adding the image
132 * - the size of the image
136 global $wgLang, $wgIgnoreImageErrors;
138 $sk =& $this->getSkin();
140 $s = '<table class="gallery" cellspacing="0" cellpadding="0">';
141 if( $this->mCaption
)
142 $s .= '<td class="galleryheader" colspan="4"><big>' . htmlspecialchars( $this->mCaption
) . '</big></td>';
145 foreach ( $this->mImages
as $pair ) {
149 $name = $img->getName();
150 $nt = $img->getTitle();
152 # If we're dealing with a non-image, or a blacklisted image,
153 # spit out the name and be done with it
154 if( $nt->getNamespace() != NS_IMAGE
155 ||
( $this->mParsing
&& wfIsBadImage( $nt->getDBkey() ) ) ) {
157 (($i%4
==0) ?
"<tr>\n" : '') .
158 '<td><div class="gallerybox" style="height: 152px;">' .
159 htmlspecialchars( $nt->getText() ) . '</div></td>' .
160 (($i%4
==3) ?
"</tr>\n" : '');
167 //$ul = $sk->makeLink( $wgContLang->getNsText( Namespace::getUser() ) . ":{$ut}", $ut );
169 if( $this->mShowBytes
) {
170 if( $img->exists() ) {
171 $nb = wfMsgExt( 'nbytes', array( 'parsemag', 'escape'),
172 $wgLang->formatNum( $img->getSize() ) );
174 $nb = wfMsgHtml( 'filemissing' );
181 $textlink = $this->mShowFilename ?
182 $sk->makeKnownLinkObj( $nt, htmlspecialchars( $wgLang->truncate( $nt->getText(), 20, '...' ) ) ) . "<br />\n" :
185 $s .= ($i%4
==0) ?
'<tr>' : '';
186 $thumb = $img->getThumbnail( 120, 120 );
188 $vpad = floor( ( 150 - $thumb->height
) /2 ) - 2;
189 $s .= '<td><div class="gallerybox">' . '<div class="thumb" style="padding: ' . $vpad . 'px 0;">';
191 # ATTENTION: The newline after <div class="gallerytext"> is needed to accommodate htmltidy which
192 # in version 4.8.6 generated crackpot html in its absence, see:
193 # http://bugzilla.wikimedia.org/show_bug.cgi?id=1765 -Ævar
194 $s .= $sk->makeKnownLinkObj( $nt, $thumb->toHtml() ) . '</div><div class="gallerytext">' . "\n" .
195 $textlink . $text . $nb .
197 $s .= "</div></td>\n";
199 # Error during thumbnail generation
200 $s .= '<td><div class="gallerybox" style="height: 152px;">' .
201 #htmlspecialchars( $nt->getText() ) . "<br />\n" .
202 htmlspecialchars( $img->getLastError() ) .
203 "</div><div class=\"gallerytext\">\n" .
204 $textlink . $text . $nb .
207 $s .= ($i%4
==3) ?
'</tr>' : '';