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 * isEmpty() returns false iff the gallery doesn't contain any images
46 return empty( $this->mImages
);
50 * Enable/Disable showing of the file size of an image in the gallery.
53 * @param boolean $f set to false to disable
55 function setShowBytes( $f ) {
56 $this->mShowBytes
= ( $f == true);
60 * Enable/Disable showing of the filename of an image in the gallery.
63 * @param boolean $f set to false to disable
65 function setShowFilename( $f ) {
66 $this->mShowFilename
= ( $f == true);
70 * Return a HTML representation of the image gallery
72 * For each image in the gallery, display
75 * - the additional text provided when adding the image
76 * - the size of the image
80 global $wgLang, $wgContLang, $wgUser;
82 $sk = $wgUser->getSkin();
84 $s = '<table style="border:solid 1px #DDDDDD; cellspacing:0; cellpadding:0; margin:1em;">';
86 foreach ( $this->mImages
as $pair ) {
90 $name = $img->getName();
91 $nt = $img->getTitle();
93 // Not an image. Just print the name and skip.
94 if ( $nt->getNamespace() != NS_IMAGE
) {
95 $s .= '<td valign="top" width="150px" style="background-color:#F0F0F0;">' .
96 htmlspecialchars( $nt->getText() ) . '</td>' . (($i%4
==3) ?
"</tr>\n" : '');
103 //$ul = $sk->makeLink( $wgContLang->getNsText( Namespace::getUser() ) . ":{$ut}", $ut );
105 if( $this->mShowBytes
) {
106 if( $img->exists() ) {
107 $nb = wfMsg( 'nbytes', $wgLang->formatNum( $img->getSize() ) );
109 $nb = wfMsg( 'filemissing' );
111 $nb = htmlspecialchars( $nb ) . '<br />';
117 $textlink = $this->mShowFilename ?
118 $sk->makeKnownLinkObj( $nt, htmlspecialchars( $wgLang->truncate( $nt->getText(), 20, '...' ) ) ) . '<br />' :
121 $s .= ($i%4
==0) ?
'<tr>' : '';
122 $thumb = $img->getThumbnail(120,120);
123 $s .= '<td valign="top" width="150px" style="background-color:#F0F0F0;">' .
124 '<table width="100%" height="150px">'.
125 '<tr><td align="center" valign="center" style="background-color:#F8F8F8;border:solid 1px #888888;">' .
126 $sk->makeKnownLinkObj( $nt, $thumb->toHtml() ) . '</td></tr></table> ' .
127 $textlink . $text . $nb;
129 $s .= "</td>\n" . (($i%4
==3) ?
"</tr>\n" : '');
146 } // defined( 'MEDIAWIKI' )