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;
21 * Create a new image gallery object.
23 function ImageGallery( ) {
24 $this->mImages
= array();
25 $this->mShowBytes
= true;
26 $this->mShowFilename
= true;
30 * Add an image to the gallery.
32 * @param $image Image object that is added to the gallery
33 * @param $html String: additional HTML text to be shown. The name and size of the image are always shown.
35 function add( $image, $html='' ) {
36 $this->mImages
[] = array( &$image, $html );
40 * Add an image at the beginning of the gallery.
42 * @param $image Image object that is added to the gallery
43 * @param $html String: Additional HTML text to be shown. The name and size of the image are always shown.
45 function insert( $image, $html='' ) {
46 array_unshift( $this->mImages
, array( &$image, $html ) );
51 * isEmpty() returns true if the gallery contains no images
54 return empty( $this->mImages
);
58 * Enable/Disable showing of the file size of an image in the gallery.
61 * @param $f Boolean: set to false to disable.
63 function setShowBytes( $f ) {
64 $this->mShowBytes
= ( $f == true);
68 * Enable/Disable showing of the filename of an image in the gallery.
71 * @param $f Boolean: set to false to disable.
73 function setShowFilename( $f ) {
74 $this->mShowFilename
= ( $f == true);
78 * Return a HTML representation of the image gallery
80 * For each image in the gallery, display
83 * - the additional text provided when adding the image
84 * - the size of the image
88 global $wgLang, $wgUser;
90 $sk = $wgUser->getSkin();
92 $s = '<table class="gallery" cellspacing="0" cellpadding="0">';
94 foreach ( $this->mImages
as $pair ) {
98 $name = $img->getName();
99 $nt = $img->getTitle();
101 // Not an image. Just print the name and skip.
102 if ( $nt->getNamespace() != NS_IMAGE
) {
104 (($i%4
==0) ?
"<tr>\n" : '') .
105 '<td><div class="gallerybox" style="height: 152px;">' .
106 htmlspecialchars( $nt->getText() ) . '</div></td>' .
107 (($i%4
==3) ?
"</tr>\n" : '');
114 //$ul = $sk->makeLink( $wgContLang->getNsText( Namespace::getUser() ) . ":{$ut}", $ut );
116 if( $this->mShowBytes
) {
117 if( $img->exists() ) {
118 $nb = wfMsgHtml( 'nbytes', $wgLang->formatNum( $img->getSize() ) );
120 $nb = wfMsgHtml( 'filemissing' );
127 $textlink = $this->mShowFilename ?
128 $sk->makeKnownLinkObj( $nt, htmlspecialchars( $wgLang->truncate( $nt->getText(), 20, '...' ) ) ) . "<br />\n" :
131 $s .= ($i%4
==0) ?
'<tr>' : '';
132 $thumb = $img->getThumbnail( 120, 120 );
133 $vpad = floor( ( 150 - $thumb->height
) /2 ) - 2;
134 $s .= '<td><div class="gallerybox">' . '<div class="thumb" style="padding: ' . $vpad . 'px 0;">';
136 # ATTENTION: The newline after <div class="gallerytext"> is needed to accommodate htmltidy which
137 # in version 4.8.6 generated crackpot html in its absence, see:
138 # http://bugzilla.wikimedia.org/show_bug.cgi?id=1765 -Ævar
139 $s .= $sk->makeKnownLinkObj( $nt, $thumb->toHtml() ) . '</div><div class="gallerytext">' . "\n" .
140 $textlink . $text . $nb .
142 $s .= "</div></td>\n";
143 $s .= ($i%4
==3) ?
'</tr>' : '';