Moved <gallery> code to Parser, registering images in a gallery as link

This commit is contained in:
Jens Frank 2004-11-13 12:04:31 +00:00
parent e34d357e9d
commit a8369d40dd
2 changed files with 33 additions and 33 deletions

View file

@ -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

View file

@ -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] = '<gallery>'.$content.'</gallery>';
}
@ -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();
}
}
/**