*/
class ImageGallery
{
- var $mImages;
+ var $mImages, $mShowBytes, $mShowFilename;
/**
* Create a new image gallery object.
*/
function ImageGallery( ) {
- $this->mImages=array();
+ $this->mImages = array();
+ $this->mShowBytes = true;
+ $this->mShowFilename = true;
}
/**
return empty( $this->mImages );
}
+ /**
+ * Enable/Disable showing of the file size of an image in the gallery.
+ * Enabled by default.
+ *
+ * @param boolean $f set to false to disable
+ */
+ function setShowBytes( $f ) {
+ $this->mShowBytes = ( $f == true);
+ }
+
+ /**
+ * Enable/Disable showing of the filename of an image in the gallery.
+ * Enabled by default.
+ *
+ * @param boolean $f set to false to disable
+ */
+ function setShowFilename( $f ) {
+ $this->mShowFilename = ( $f == true);
+ }
+
/**
* Return a HTML representation of the image gallery
*
//TODO
//$ul = $sk->makeLink( $wgContLang->getNsText( Namespace::getUser() ) . ":{$ut}", $ut );
- $nb = wfMsg( "nbytes", $wgLang->formatNum( $img->getSize() ) );
+ $nb = $this->mShowBytes ?
+ wfMsg( "nbytes", $wgLang->formatNum( $img->getSize() ) ) . '<br />' :
+ '' ;
+ $textlink = $this->mShowFilename ?
+ $sk->makeKnownLinkObj( $nt, Language::truncate( $nt->getText(), 20, '...' ) ) . '<br />' :
+ '' ;
$s .= ($i%4==0) ? '<tr>' : '';
$s .= '<td valign="top" width="150px" style="background-color:#F0F0F0;">' .
'<table width="100%" height="150px">'.
'<tr><td align="center" valign="center" style="background-color:#F8F8F8;border:solid 1px #888888;">' .
$sk->makeKnownLinkObj( $nt, '<img src="'.$img->createThumb(120,120).'" alt="">' ) . '</td></tr></table> ' .
- $sk->makeKnownLinkObj( $nt, Language::truncate( $nt->getText(), 20, '...' ) ) .
- "<br />{$text}{$nb}<br />" ;
+ $textlink . $text . $nb;
$s .= '</td>' . (($i%4==3) ? '</tr>' : '');
return $s;
}
+ /**
+ * Transparently generates an image gallery from a text with one line per image.
+ * text labels may be given by using |-style alternative text. E.g.
+ * Image:one.jpg|The number "1"
+ * Image:tree.jpg|A tree
+ * given as text will return a gallery with two images, labeled 'The number "1"' and
+ * 'A tree'.
+ */
+ function newFromTextList( $text ) {
+ $ig = new ImageGallery();
+ $ig->setShowBytes( false );
+ $ig->setShowFilename( false );
+ $lines = explode( "\n", $text );
+ foreach ( $lines as $line ) {
+ preg_match( "/^([^|]+)(\\|(.*))?$/", $line, $matches );
+ # Skip empty lines
+ if ( count( $matches ) == 0 ) {
+ continue;
+ }
+ $nt = Title::newFromURL( $matches[1] );
+ if ( isset( $matches[3] ) ) {
+ $label = $matches[3];
+ } else {
+ $label = '';
+ }
+ $ig->add( Image::newFromTitle( $nt ), $label );
+ }
+ return $ig;
+ }
+
+
} //class
$pre_content = array();
$comment_content = array();
$ext_content = array();
+ $gallery_content = array();
# Replace any instances of the placeholders
$uniq_prefix = UNIQ_PREFIX;
}
}
+ # gallery
+ $text = Parser::extractTags('gallery', $text, $gallery_content, $uniq_prefix);
+ foreach( $gallery_content as $marker => $content ) {
+ require_once( 'ImageGallery.php' );
+ if ( $render ) {
+ $ig = ImageGallery::newFromTextList( $content );
+ $gallery_content[$marker] = $ig->toHTML();
+ } else {
+ $gallery_content[$marker] = '<gallery>'.$content.'</gallery>';
+ }
+ }
+
# Comments
if($stripcomments) {
$text = Parser::extractTags(STRIP_COMMENTS, $text, $comment_content, $uniq_prefix);
$state['math'] = $state['math'] + $math_content;
$state['pre'] = $state['pre'] + $pre_content;
$state['comment'] = $state['comment'] + $comment_content;
+ $state['gallery'] = $state['gallery'] + $gallery_content;
foreach( $ext_content as $tag => $array ) {
if ( array_key_exists( $tag, $state ) ) {
'math' => $math_content,
'pre' => $pre_content,
'comment' => $comment_content,
+ 'gallery' => $gallery_content,
) + $ext_content;
}
return $text;