Fix cross site scripting bug
[mediawiki.git] / includes / ImageGallery.php
blob7c6c153354948c5118bc0682f52fa01a4fd4ea26
2 <?php
3 /**
4 * @package MediaWiki
5 */
7 /**
8 * This is not a valid entry point, perform no further processing unless MEDIAWIKI is defined
9 */
10 if( defined( 'MEDIAWIKI' ) ) {
13 /**
14 * Image gallery
16 * Add images to the gallery using add(), then render that list to HTML using toHTML().
18 * @package MediaWiki
20 class ImageGallery
22 var $mImages;
24 /**
25 * Create a new image gallery object.
27 function ImageGallery( ) {
28 $this->mImages=array();
31 /**
32 * Add an image to the gallery.
34 * @param Image $image Image object that is added to the gallery
35 * @param string $text Additional text to be shown. The name and size of the image are always shown.
37 function add( $image, $text='' ) {
38 $this->mImages[] = array( &$image, $text );
41 /**
42 * isEmpty() returns false iff the gallery doesn't contain any images
44 function isEmpty() {
45 return empty( $this->mImages );
48 /**
49 * Return a HTML representation of the image gallery
51 * For each image in the gallery, display
52 * - a thumbnail
53 * - the image name
54 * - the additional text provided when adding the image
55 * - the size of the image
58 function toHTML() {
59 global $wgLang, $wgContLang, $wgUser;
61 $sk = $wgUser->getSkin();
63 $s = '<table style="border:solid 1px #DDDDDD; cellspacing:0; cellpadding:0; margin:1em;">';
64 $i = 0;
65 foreach ( $this->mImages as $pair ) {
66 $img =& $pair[0];
67 $text = $pair[1];
69 $name = $img->getName();
70 $nt = $img->getTitle();
72 //TODO
73 //$ul = $sk->makeLink( $wgContLang->getNsText( Namespace::getUser() ) . ":{$ut}", $ut );
75 $nb = wfMsg( "nbytes", $wgLang->formatNum( $img->getSize() ) );
77 $s .= ($i%4==0) ? '<tr>' : '';
78 $s .= '<td valign="top" width="150px" style="background-color:#F0F0F0;">' .
79 '<table width="100%" height="150px">'.
80 '<tr><td align="center" valign="center" style="background-color:#F8F8F8;border:solid 1px #888888;">' .
81 $sk->makeKnownLinkObj( $nt, '<img src="'.$img->createThumb(120,120).'" alt="">' ) . '</td></tr></table> ' .
82 $sk->makeKnownLinkObj( $nt, Language::truncate( $nt->getText(), 20, '...' ) ) .
83 "<br />{$text}{$nb}<br />" ;
85 $s .= '</td>' . (($i%4==3) ? '</tr>' : '');
87 $i++;
89 $s .= '</table>';
91 return $s;
94 } //class
99 } // defined( 'MEDIAWIKI' )