In ImageGallery:
authorTim Starling <tstarling@users.mediawiki.org>
Wed, 22 Aug 2007 13:40:22 +0000 (13:40 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Wed, 22 Aug 2007 13:40:22 +0000 (13:40 +0000)
* Split "is parsing" and "respect bad images" concepts.
* Call media handler parser hook
* Use the $linkAttribs parameter instead of putting an <a> tag around the whole media output.

includes/CategoryPage.php
includes/ImageGallery.php
includes/Parser.php

index 435a3f4..76a388a 100644 (file)
@@ -106,7 +106,7 @@ class CategoryViewer {
                $this->children_start_char = array();
                if( $this->showGallery ) {
                        $this->gallery = new ImageGallery();
-                       $this->gallery->setParsing();
+                       $this->gallery->setHideBadImages();
                }
        }
 
index 8d7c36d..0fe58bd 100644 (file)
@@ -20,9 +20,14 @@ class ImageGallery
        var $mRevisionId = 0;
 
        /**
-        * Is the gallery on a wiki page (i.e. not a special page)
+        * Hide blacklisted images?
         */
-       var $mParsing;
+       var $mHideBadImages;
+
+       /**
+        * Registered parser object for output callbacks
+        */
+       var $mParser;
 
        /**
         * Contextual title, used when images are being screened
@@ -42,14 +47,22 @@ class ImageGallery
                $this->mImages = array();
                $this->mShowBytes = true;
                $this->mShowFilename = true;
-               $this->mParsing = false;
+               $this->mParser = false;
+               $this->mHideBadImages = false;
        }
 
        /**
-        * Set the "parse" bit so we know to hide "bad" images
+        * Register a parser object
         */
-       function setParsing( $val = true ) {
-               $this->mParsing = $val;
+       function setParser( $parser ) {
+               $this->mParser = $parser;
+       }
+
+       /**
+        * Set bad image flag
+        */
+       function setHideBadImages( $flag = true ) {
+               $this->mHideBadImages = $flag;
        }
 
        /**
@@ -238,7 +251,7 @@ class ImageGallery
                                # We're dealing with a non-image, spit out the name and be done with it.
                                $thumbhtml = "\n\t\t\t".'<div style="height: '.($this->mHeights*1.25+2).'px;">'
                                        . htmlspecialchars( $nt->getText() ) . '</div>';
-                       } elseif( $this->mParsing && wfIsBadImage( $nt->getDBkey(), $this->getContextTitle() ) ) {
+                       } elseif( $this->mHideBadImages && wfIsBadImage( $nt->getDBkey(), $this->getContextTitle() ) ) {
                                # The image is blacklisted, just show it as a text link.
                                $thumbhtml = "\n\t\t\t".'<div style="height: '.($this->mHeights*1.25+2).'px;">'
                                        . $sk->makeKnownLinkObj( $nt, htmlspecialchars( $nt->getText() ) ) . '</div>';
@@ -248,8 +261,18 @@ class ImageGallery
                                        . htmlspecialchars( $img->getLastError() ) . '</div>';
                        } else {
                                $vpad = floor( ( 1.25*$this->mHeights - $thumb->height ) /2 ) - 2;
+                               $linkAttribs = array(
+                                       'title' => $nt->getPrefixedText(),
+                                       'href' => $nt->getLocalURL(),
+                               );
+                                       
                                $thumbhtml = "\n\t\t\t".'<div class="thumb" style="padding: ' . $vpad . 'px 0; width: '.($this->mWidths+30).'px;">'
-                                       . $sk->makeKnownLinkObj( $nt, $thumb->toHtml() ) . '</div>';
+                                       . $thumb->toHtml( array(), $linkAttribs ) . '</div>';
+
+                               // Call parser transform hook
+                               if ( $this->mParser && $img->getHandler() ) {
+                                       $img->getHandler()->parserTransformHook( $this->mParser, $img );
+                               }
                        }
 
                        //TODO
index 9f79d67..da8d512 100644 (file)
@@ -4411,7 +4411,8 @@ class Parser
                $ig->setContextTitle( $this->mTitle );
                $ig->setShowBytes( false );
                $ig->setShowFilename( false );
-               $ig->setParsing();
+               $ig->setParser( $this );
+               $ig->setHideBadImages();
                $ig->setAttributes( Sanitizer::validateTagAttributes( $params, 'table' ) );
                $ig->useSkin( $this->mOptions->getSkin() );
                $ig->mRevisionId = $this->mRevisionId;