Fix Special:Import for new schema; make it create page records as needed and hook...
[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 to 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 /**
54 * isEmpty() returns false iff the gallery doesn't contain any images
55 */
56 function isEmpty() {
57 return empty( $this->mImages );
58 }
59
60 /**
61 * Enable/Disable showing of the file size of an image in the gallery.
62 * Enabled by default.
63 *
64 * @param boolean $f set to false to disable
65 */
66 function setShowBytes( $f ) {
67 $this->mShowBytes = ( $f == true);
68 }
69
70 /**
71 * Enable/Disable showing of the filename of an image in the gallery.
72 * Enabled by default.
73 *
74 * @param boolean $f set to false to disable
75 */
76 function setShowFilename( $f ) {
77 $this->mShowFilename = ( $f == true);
78 }
79
80 /**
81 * Return a HTML representation of the image gallery
82 *
83 * For each image in the gallery, display
84 * - a thumbnail
85 * - the image name
86 * - the additional text provided when adding the image
87 * - the size of the image
88 *
89 */
90 function toHTML() {
91 global $wgLang, $wgContLang, $wgUser;
92
93 $sk = $wgUser->getSkin();
94
95 $s = '<table class="gallery" cellspacing="0" cellpadding="0">';
96 $i = 0;
97 foreach ( $this->mImages as $pair ) {
98 $img =& $pair[0];
99 $text = $pair[1];
100
101 $name = $img->getName();
102 $nt = $img->getTitle();
103
104 // Not an image. Just print the name and skip.
105 if ( $nt->getNamespace() != NS_IMAGE ) {
106 $s .= '<td><div class="gallerybox" style="height: 152px;">' .
107 htmlspecialchars( $nt->getText() ) . '</div></td>' . (($i%4==3) ? "</tr>\n" : '');
108 $i++;
109
110 continue;
111 }
112
113 //TODO
114 //$ul = $sk->makeLink( $wgContLang->getNsText( Namespace::getUser() ) . ":{$ut}", $ut );
115
116 if( $this->mShowBytes ) {
117 if( $img->exists() ) {
118 $nb = wfMsg( 'nbytes', $wgLang->formatNum( $img->getSize() ) );
119 } else {
120 $nb = wfMsg( 'filemissing' );
121 }
122 $nb = htmlspecialchars( $nb ) . '<br />';
123 } else {
124 $nb = '';
125 }
126
127 '' ;
128 $textlink = $this->mShowFilename ?
129 $sk->makeKnownLinkObj( $nt, htmlspecialchars( $wgLang->truncate( $nt->getText(), 20, '...' ) ) ) . '<br />' :
130 '' ;
131
132 $s .= ($i%4==0) ? '<tr>' : '';
133 $thumb = $img->getThumbnail( 120, 120 );
134 $vpad = floor( ( 150 - $thumb->height ) /2 ) - 2;
135 $s .= '<td><div class="gallerybox">' .
136 '<div class="thumb" style="padding: ' . $vpad . 'px 0;">'.
137 $sk->makeKnownLinkObj( $nt, $thumb->toHtml() ) . '</div><div class="gallerytext">' .
138 $textlink . $text . $nb .
139 '</div>';
140 $s .= "</div></td>\n";
141 $s .= ($i%4==3) ? '</tr>' : '';
142 $i++;
143 }
144 if( $i %4 != 0 ) {
145 $s .= "</tr>\n";
146 }
147 $s .= '</table>';
148
149 return $s;
150 }
151
152 } //class
153
154
155
156
157 } // defined( 'MEDIAWIKI' )
158 ?>