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