In ImageGallery:

* 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.
This commit is contained in:
Tim Starling 2007-08-22 13:40:22 +00:00
parent c3d7a096ef
commit daf77bd5f1
3 changed files with 34 additions and 10 deletions

View 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();
}
}

View 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

View 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;