Moved <gallery> code to Parser, registering images in a gallery as link
authorJens Frank <jeluf@users.mediawiki.org>
Sat, 13 Nov 2004 12:04:31 +0000 (12:04 +0000)
committerJens Frank <jeluf@users.mediawiki.org>
Sat, 13 Nov 2004 12:04:31 +0000 (12:04 +0000)
includes/ImageGallery.php
includes/Parser.php

index b652e49..7ddacae 100644 (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
 
 
index 645ad7c..e7bbb39 100644 (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();
+       }
 }
 
 /**