Merge category paging from REL1_4
[lhc/web/wiklou.git] / includes / ImageGallery.php
1 <?php
2 /**
3 * @package MediaWiki
4 */
5
6 /**
7 * This is not a valid entry point, perform no further processing unless MEDIAWIKI is defined
8 */
9 if( defined( 'MEDIAWIKI' ) ) {
10
11
12 /**
13 * Image gallery
14 *
15 * Add images to the gallery using add(), then render that list to HTML using toHTML().
16 *
17 * @package MediaWiki
18 */
19 class ImageGallery
20 {
21 var $mImages, $mShowBytes, $mShowFilename;
22
23 /**
24 * Create a new image gallery object.
25 */
26 function ImageGallery( ) {
27 $this->mImages = array();
28 $this->mShowBytes = true;
29 $this->mShowFilename = true;
30 }
31
32 /**
33 * Add an image at the end of the gallery.
34 *
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.
37 */
38 function add( $image, $html='' ) {
39 $this->mImages[] = array( &$image, $html );
40 }
41
42 /**
43 * Add an image at the beginning of the gallery.
44 *
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.
47 */
48 function insert( $image, $html='' ) {
49 array_unshift( $this->mImages, array( &$image, $html ) );
50 }
51
52 /**
53 * isEmpty() returns false iff the gallery doesn't contain any images
54 */
55 function isEmpty() {
56 return empty( $this->mImages );
57 }
58
59 /**
60 * Enable/Disable showing of the file size of an image in the gallery.
61 * Enabled by default.
62 *
63 * @param boolean $f set to false to disable
64 */
65 function setShowBytes( $f ) {
66 $this->mShowBytes = ( $f == true);
67 }
68
69 /**
70 * Enable/Disable showing of the filename of an image in the gallery.
71 * Enabled by default.
72 *
73 * @param boolean $f set to false to disable
74 */
75 function setShowFilename( $f ) {
76 $this->mShowFilename = ( $f == true);
77 }
78
79 /**
80 * Return a HTML representation of the image gallery
81 *
82 * For each image in the gallery, display
83 * - a thumbnail
84 * - the image name
85 * - the additional text provided when adding the image
86 * - the size of the image
87 *
88 */
89 function toHTML() {
90 global $wgLang, $wgContLang, $wgUser;
91
92 $sk = $wgUser->getSkin();
93
94 $s = '<table style="border:solid 1px #DDDDDD; cellspacing:0; cellpadding:0; margin:1em;">';
95 $i = 0;
96 foreach ( $this->mImages as $pair ) {
97 $img =& $pair[0];
98 $text = $pair[1];
99
100 $name = $img->getName();
101 $nt = $img->getTitle();
102
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" : '');
107 $i++;
108
109 continue;
110 }
111
112 //TODO
113 //$ul = $sk->makeLink( $wgContLang->getNsText( Namespace::getUser() ) . ":{$ut}", $ut );
114
115 if( $this->mShowBytes ) {
116 if( $img->exists() ) {
117 $nb = wfMsg( 'nbytes', $wgLang->formatNum( $img->getSize() ) );
118 } else {
119 $nb = wfMsg( 'filemissing' );
120 }
121 $nb = htmlspecialchars( $nb ) . '<br />';
122 } else {
123 $nb = '';
124 }
125
126 '' ;
127 $textlink = $this->mShowFilename ?
128 $sk->makeKnownLinkObj( $nt, htmlspecialchars( $wgLang->truncate( $nt->getText(), 20, '...' ) ) ) . '<br />' :
129 '' ;
130
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;
138
139 $s .= "</td>\n" . (($i%4==3) ? "</tr>\n" : '');
140
141 $i++;
142 }
143 if( $i %4 != 0 ) {
144 $s .= "</tr>\n";
145 }
146 $s .= '</table>';
147
148 return $s;
149 }
150
151 } //class
152
153
154
155
156 } // defined( 'MEDIAWIKI' )
157 ?>