7ddacaed5f2012f6dc3192d1f770c5817945a919
[lhc/web/wiklou.git] / includes / ImageGallery.php
1
2 <?php
3 /**
4 * @package MediaWiki
5 */
6
7 /**
8 * This is not a valid entry point, perform no further processing unless MEDIAWIKI is defined
9 */
10 if( defined( 'MEDIAWIKI' ) ) {
11
12
13 /**
14 * Image gallery
15 *
16 * Add images to the gallery using add(), then render that list to HTML using toHTML().
17 *
18 * @package MediaWiki
19 */
20 class ImageGallery
21 {
22 var $mImages, $mShowBytes, $mShowFilename;
23
24 /**
25 * Create a new image gallery object.
26 */
27 function ImageGallery( ) {
28 $this->mImages = array();
29 $this->mShowBytes = true;
30 $this->mShowFilename = true;
31 }
32
33 /**
34 * Add an image to the gallery.
35 *
36 * @param Image $image Image object that is added to the gallery
37 * @param string $text Additional text to be shown. The name and size of the image are always shown.
38 */
39 function add( $image, $text='' ) {
40 $this->mImages[] = array( &$image, $text );
41 }
42
43 /**
44 * isEmpty() returns false iff the gallery doesn't contain any images
45 */
46 function isEmpty() {
47 return empty( $this->mImages );
48 }
49
50 /**
51 * Enable/Disable showing of the file size of an image in the gallery.
52 * Enabled by default.
53 *
54 * @param boolean $f set to false to disable
55 */
56 function setShowBytes( $f ) {
57 $this->mShowBytes = ( $f == true);
58 }
59
60 /**
61 * Enable/Disable showing of the filename of an image in the gallery.
62 * Enabled by default.
63 *
64 * @param boolean $f set to false to disable
65 */
66 function setShowFilename( $f ) {
67 $this->mShowFilename = ( $f == true);
68 }
69
70 /**
71 * Return a HTML representation of the image gallery
72 *
73 * For each image in the gallery, display
74 * - a thumbnail
75 * - the image name
76 * - the additional text provided when adding the image
77 * - the size of the image
78 *
79 */
80 function toHTML() {
81 global $wgLang, $wgContLang, $wgUser;
82
83 $sk = $wgUser->getSkin();
84
85 $s = '<table style="border:solid 1px #DDDDDD; cellspacing:0; cellpadding:0; margin:1em;">';
86 $i = 0;
87 foreach ( $this->mImages as $pair ) {
88 $img =& $pair[0];
89 $text = $pair[1];
90
91 $name = $img->getName();
92 $nt = $img->getTitle();
93
94 //TODO
95 //$ul = $sk->makeLink( $wgContLang->getNsText( Namespace::getUser() ) . ":{$ut}", $ut );
96
97 $nb = $this->mShowBytes ?
98 wfMsg( "nbytes", $wgLang->formatNum( $img->getSize() ) ) . '<br />' :
99 '' ;
100 $textlink = $this->mShowFilename ?
101 $sk->makeKnownLinkObj( $nt, Language::truncate( $nt->getText(), 20, '...' ) ) . '<br />' :
102 '' ;
103
104 $s .= ($i%4==0) ? '<tr>' : '';
105 $s .= '<td valign="top" width="150px" style="background-color:#F0F0F0;">' .
106 '<table width="100%" height="150px">'.
107 '<tr><td align="center" valign="center" style="background-color:#F8F8F8;border:solid 1px #888888;">' .
108 $sk->makeKnownLinkObj( $nt, '<img src="'.$img->createThumb(120,120).'" alt="">' ) . '</td></tr></table> ' .
109 $textlink . $text . $nb;
110
111 $s .= '</td>' . (($i%4==3) ? '</tr>' : '');
112
113 $i++;
114 }
115 $s .= '</table>';
116
117 return $s;
118 }
119
120 } //class
121
122
123
124
125 } // defined( 'MEDIAWIKI' )
126 ?>