r40684 - Code Review

From MediaWiki.org

Jump to: navigation, search
Repository:MediaWiki
Revision:r40683 | r40684 (on ViewVC) | r40685 >
Date:22:12, 9 September 2008
Author:mrzman
Status:new
Tags:
Comment:Actually parse the options so links and templates will work in captions, code adapted from Cite extension.
Modified paths:

Diff [purge]

Index: trunk/extensions/ImageMap/ImageMap_body.php
===================================================================
--- trunk/extensions/ImageMap/ImageMap_body.php	(revision 40683)
+++ trunk/extensions/ImageMap/ImageMap_body.php	(revision 40684)
@@ -70,7 +70,33 @@
 				if ( wfIsBadImage( $imageTitle->getDBkey() , $parser->mTitle ) ) {
 					return self::error( 'imagemap_bad_image' );
 				}
-				$imageHTML = $parser->makeImage( $imageTitle, Sanitizer::escapeHtmlAllowEntities($options) );
+				// Parse the options so we can use links and the like in the caption, code adapted from Cite extension
+				if ( method_exists( $parser, 'recursiveTagParse' ) ) {
+					// New fast method
+					$parsedoptions = $parser->recursiveTagParse( Sanitizer::escapeHtmlAllowEntities($options) );
+				} else {
+					// Old method
+					$ret = $parser->parse(
+						Sanitizer::escapeHtmlAllowEntities($options),
+						$parser->mTitle,
+						$parser->mOptions,
+						// Avoid whitespace buildup
+						false,
+						false
+					);
+					$text = $ret->getText();
+					global $wgUseTidy;
+					if ( ! $wgUseTidy )
+						$parsedoptions = $text;
+					else {
+						$text = preg_replace( '~^<p>\s*~', '', $text );
+						$text = preg_replace( '~\s*</p>\s*~', '', $text );
+						$text = preg_replace( '~\n$~', '', $text );
+						
+						$parsedoptions =  $text;
+					}
+				}
+				$imageHTML = $parser->makeImage( $imageTitle, $parsedoptions );
 				$parser->mOutput->addImage( $imageTitle->getDBkey() );
 
 				$domDoc = new DOMDocument();
Views
Toolbox