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 Image object that is added to the gallery
33 * @param string $html 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 Image object that is added to the gallery
43 * @param string $html 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 boolean $f 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 boolean $f 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
) {
103 $s .= '<td><div class="gallerybox" style="height: 152px;">' .
104 htmlspecialchars( $nt->getText() ) . '</div></td>' . (($i%4
==3) ?
"</tr>\n" : '');
111 //$ul = $sk->makeLink( $wgContLang->getNsText( Namespace::getUser() ) . ":{$ut}", $ut );
113 if( $this->mShowBytes
) {
114 if( $img->exists() ) {
115 $nb = wfMsgHtml( 'nbytes', $wgLang->formatNum( $img->getSize() ) );
117 $nb = wfMsgHtml( 'filemissing' );
124 $textlink = $this->mShowFilename ?
125 $sk->makeKnownLinkObj( $nt, htmlspecialchars( $wgLang->truncate( $nt->getText(), 20, '...' ) ) ) . "<br />\n" :
128 $s .= ($i%4
==0) ?
'<tr>' : '';
129 $thumb = $img->getThumbnail( 120, 120 );
130 $vpad = floor( ( 150 - $thumb->height
) /2 ) - 2;
131 $s .= '<td><div class="gallerybox">' . '<div class="thumb" style="padding: ' . $vpad . 'px 0;">';
133 # ATTENTION: The newline after <div class="gallerytext"> is needed to accommodate htmltidy which
134 # in version 4.8.6 generated crackpot html in its absence, see:
135 # http://bugzilla.wikimedia.org/show_bug.cgi?id=1765 -Ævar
136 $s .= $sk->makeKnownLinkObj( $nt, $thumb->toHtml() ) . '</div><div class="gallerytext">' . "\n" .
137 $textlink . $text . $nb .
139 $s .= "</div></td>\n";
140 $s .= ($i%4
==3) ?
'</tr>' : '';