r25049 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25048‎ | r25049 | r25050 >
Date:13:40, 22 August 2007
Author:tstarling
Status:old
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/includes/CategoryPage.php (modified) (history)
  • /trunk/phase3/includes/ImageGallery.php (modified) (history)
  • /trunk/phase3/includes/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/CategoryPage.php
@@ -106,7 +106,7 @@
107107 $this->children_start_char = array();
108108 if( $this->showGallery ) {
109109 $this->gallery = new ImageGallery();
110 - $this->gallery->setParsing();
 110+ $this->gallery->setHideBadImages();
111111 }
112112 }
113113
Index: trunk/phase3/includes/Parser.php
@@ -4411,7 +4411,8 @@
44124412 $ig->setContextTitle( $this->mTitle );
44134413 $ig->setShowBytes( false );
44144414 $ig->setShowFilename( false );
4415 - $ig->setParsing();
 4415+ $ig->setParser( $this );
 4416+ $ig->setHideBadImages();
44164417 $ig->setAttributes( Sanitizer::validateTagAttributes( $params, 'table' ) );
44174418 $ig->useSkin( $this->mOptions->getSkin() );
44184419 $ig->mRevisionId = $this->mRevisionId;
Index: trunk/phase3/includes/ImageGallery.php
@@ -20,11 +20,16 @@
2121 var $mRevisionId = 0;
2222
2323 /**
24 - * Is the gallery on a wiki page (i.e. not a special page)
 24+ * Hide blacklisted images?
2525 */
26 - var $mParsing;
 26+ var $mHideBadImages;
2727
2828 /**
 29+ * Registered parser object for output callbacks
 30+ */
 31+ var $mParser;
 32+
 33+ /**
2934 * Contextual title, used when images are being screened
3035 * against the bad image list
3136 */
@@ -42,17 +47,25 @@
4348 $this->mImages = array();
4449 $this->mShowBytes = true;
4550 $this->mShowFilename = true;
46 - $this->mParsing = false;
 51+ $this->mParser = false;
 52+ $this->mHideBadImages = false;
4753 }
4854
4955 /**
50 - * Set the "parse" bit so we know to hide "bad" images
 56+ * Register a parser object
5157 */
52 - function setParsing( $val = true ) {
53 - $this->mParsing = $val;
 58+ function setParser( $parser ) {
 59+ $this->mParser = $parser;
5460 }
5561
5662 /**
 63+ * Set bad image flag
 64+ */
 65+ function setHideBadImages( $flag = true ) {
 66+ $this->mHideBadImages = $flag;
 67+ }
 68+
 69+ /**
5770 * Set the caption (as plain text)
5871 *
5972 * @param $caption Caption
@@ -238,7 +251,7 @@
239252 # We're dealing with a non-image, spit out the name and be done with it.
240253 $thumbhtml = "\n\t\t\t".'<div style="height: '.($this->mHeights*1.25+2).'px;">'
241254 . htmlspecialchars( $nt->getText() ) . '</div>';
242 - } elseif( $this->mParsing && wfIsBadImage( $nt->getDBkey(), $this->getContextTitle() ) ) {
 255+ } elseif( $this->mHideBadImages && wfIsBadImage( $nt->getDBkey(), $this->getContextTitle() ) ) {
243256 # The image is blacklisted, just show it as a text link.
244257 $thumbhtml = "\n\t\t\t".'<div style="height: '.($this->mHeights*1.25+2).'px;">'
245258 . $sk->makeKnownLinkObj( $nt, htmlspecialchars( $nt->getText() ) ) . '</div>';
@@ -248,8 +261,18 @@
249262 . htmlspecialchars( $img->getLastError() ) . '</div>';
250263 } else {
251264 $vpad = floor( ( 1.25*$this->mHeights - $thumb->height ) /2 ) - 2;
 265+ $linkAttribs = array(
 266+ 'title' => $nt->getPrefixedText(),
 267+ 'href' => $nt->getLocalURL(),
 268+ );
 269+
252270 $thumbhtml = "\n\t\t\t".'<div class="thumb" style="padding: ' . $vpad . 'px 0; width: '.($this->mWidths+30).'px;">'
253 - . $sk->makeKnownLinkObj( $nt, $thumb->toHtml() ) . '</div>';
 271+ . $thumb->toHtml( array(), $linkAttribs ) . '</div>';
 272+
 273+ // Call parser transform hook
 274+ if ( $this->mParser && $img->getHandler() ) {
 275+ $img->getHandler()->parserTransformHook( $this->mParser, $img );
 276+ }
254277 }
255278
256279 //TODO

Follow-up revisions

RevisionCommit summaryAuthorDate
r25068Order of link parameters changed in r25049; putting them back so the parser t...brion20:07, 22 August 2007
r25109Merged revisions 25016-25108 via svnmerge from...david07:30, 24 August 2007

Status & tagging log