Work through the NFC substeps with the actual data to make the substep times more...
[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;
23
24 /**
25 * Create a new image gallery object.
26 */
27 function ImageGallery( ) {
28 $this->mImages=array();
29 }
30
31 /**
32 * Add an image to the gallery.
33 *
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.
36 */
37 function add( $image, $text='' ) {
38 $this->mImages[] = array( &$image, $text );
39 }
40
41 /**
42 * isEmpty() returns false iff the gallery doesn't contain any images
43 */
44 function isEmpty() {
45 return empty( $this->mImages );
46 }
47
48 /**
49 * Return a HTML representation of the image gallery
50 *
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
56 *
57 */
58 function toHTML() {
59 global $wgLang, $wgContLang, $wgUser;
60
61 $sk = $wgUser->getSkin();
62
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];
68
69 $name = $img->getName();
70 $nt = $img->getTitle();
71
72 //TODO
73 //$ul = $sk->makeLink( $wgContLang->getNsText( Namespace::getUser() ) . ":{$ut}", $ut );
74
75 $nb = wfMsg( "nbytes", $wgLang->formatNum( $img->getSize() ) );
76
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 />" ;
84
85 $s .= '</td>' . (($i%4==3) ? '</tr>' : '');
86
87 $i++;
88 }
89 $s .= '</table>';
90
91 return $s;
92 }
93
94 } //class
95
96
97
98
99 } // defined( 'MEDIAWIKI' )
100 ?>