7 * This is not a valid entry point, perform no further processing unless MEDIAWIKI is defined
9 if( defined( 'MEDIAWIKI' ) ) {
15 * Add images to the gallery using add(), then render that list to HTML using toHTML().
21 var $mImages, $mShowBytes, $mShowFilename;
24 * Create a new image gallery object.
26 function ImageGallery( ) {
27 $this->mImages
= array();
28 $this->mShowBytes
= true;
29 $this->mShowFilename
= true;
33 * Add an image to the gallery.
35 * @param Image $image Image object that is added to the gallery
36 * @param string $html Additional HTML text to be shown. The name and size of the image are always shown.
38 function add( $image, $html='' ) {
39 $this->mImages
[] = array( &$image, $html );
43 * Add an image at the beginning of the gallery.
45 * @param Image $image Image object that is added to the gallery
46 * @param string $html Additional HTML text to be shown. The name and size of the image are always shown.
48 function insert( $image, $html='' ) {
49 array_unshift( $this->mImages
, array( &$image, $html ) );
54 * isEmpty() returns false iff the gallery doesn't contain any images
57 return empty( $this->mImages
);
61 * Enable/Disable showing of the file size of an image in the gallery.
64 * @param boolean $f set to false to disable
66 function setShowBytes( $f ) {
67 $this->mShowBytes
= ( $f == true);
71 * Enable/Disable showing of the filename of an image in the gallery.
74 * @param boolean $f set to false to disable
76 function setShowFilename( $f ) {
77 $this->mShowFilename
= ( $f == true);
81 * Return a HTML representation of the image gallery
83 * For each image in the gallery, display
86 * - the additional text provided when adding the image
87 * - the size of the image
91 global $wgLang, $wgContLang, $wgUser;
93 $sk = $wgUser->getSkin();
95 $s = '<table class="gallery" cellspacing="0" cellpadding="0">';
97 foreach ( $this->mImages
as $pair ) {
101 $name = $img->getName();
102 $nt = $img->getTitle();
104 // Not an image. Just print the name and skip.
105 if ( $nt->getNamespace() != NS_IMAGE
) {
106 $s .= '<td><div class="gallerybox" style="height: 152px;">' .
107 htmlspecialchars( $nt->getText() ) . '</div></td>' . (($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 = wfMsg( 'nbytes', $wgLang->formatNum( $img->getSize() ) );
120 $nb = wfMsg( 'filemissing' );
122 $nb = htmlspecialchars( $nb ) . '<br />';
128 $textlink = $this->mShowFilename ?
129 $sk->makeKnownLinkObj( $nt, htmlspecialchars( $wgLang->truncate( $nt->getText(), 20, '...' ) ) ) . '<br />' :
132 $s .= ($i%4
==0) ?
'<tr>' : '';
133 $thumb = $img->getThumbnail( 120, 120 );
134 $vpad = floor( ( 150 - $thumb->height
) /2 ) - 2;
135 $s .= '<td><div class="gallerybox">' .
136 '<div class="thumb" style="padding: ' . $vpad . 'px 0;">'.
137 $sk->makeKnownLinkObj( $nt, $thumb->toHtml() ) . '</div>';
139 $s .= '<div class="gallerytext">' .
140 $textlink . $text . $nb .
143 $s .= "</div></td>\n";
144 $s .= ($i%4
==3) ?
'</tr>' : '';
160 } // defined( 'MEDIAWIKI' )