From: Jens Frank Date: Sat, 13 Nov 2004 12:04:31 +0000 (+0000) Subject: Moved code to Parser, registering images in a gallery as link X-Git-Tag: 1.5.0alpha1~1354 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/?a=commitdiff_plain;h=a8369d40dd0da4aba1552c7c2ee4af94d124ac91;p=lhc%2Fweb%2Fwiklou.git Moved code to Parser, registering images in a gallery as link --- diff --git a/includes/ImageGallery.php b/includes/ImageGallery.php index b652e49131..7ddacaed5f 100644 --- a/includes/ImageGallery.php +++ b/includes/ImageGallery.php @@ -117,37 +117,6 @@ class ImageGallery 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 diff --git a/includes/Parser.php b/includes/Parser.php index 645ad7cd8f..e7bbb39aa1 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -336,8 +336,7 @@ class Parser foreach( $gallery_content as $marker => $content ) { require_once( 'ImageGallery.php' ); if ( $render ) { - $ig = ImageGallery::newFromTextList( $content ); - $gallery_content[$marker] = $ig->toHTML(); + $gallery_content[$marker] = Parser::renderImageGallery( $content ); } else { $gallery_content[$marker] = ''.$content.''; } @@ -2991,6 +2990,38 @@ class Parser wfProfileOut( $fname ); return $colours; } + /** + * Renders 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 the HTML of a gallery with two images, + * labeled 'The number "1"' and + * 'A tree'. + */ + function renderImageGallery( $text ) { + global $wgLinkCache; + $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 ); + $wgLinkCache->addImageLinkObj( $nt ); + } + return $ig->toHTML(); + } } /**