2006-11-01 06:34:42 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2013-11-26 19:35:51 +00:00
|
|
|
* Main file for extension ImageMap.
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
2006-11-01 06:34:42 +00:00
|
|
|
*
|
|
|
|
* Syntax:
|
|
|
|
* <imagemap>
|
|
|
|
* Image:Foo.jpg | 100px | picture of a foo
|
|
|
|
*
|
|
|
|
* rect 0 0 50 50 [[Foo type A]]
|
|
|
|
* circle 50 50 20 [[Foo type B]]
|
2011-06-17 16:26:31 +00:00
|
|
|
*
|
2006-12-13 05:55:37 +00:00
|
|
|
* desc bottom-left
|
2006-11-01 06:34:42 +00:00
|
|
|
* </imagemap>
|
|
|
|
*
|
2016-03-03 16:36:38 +00:00
|
|
|
* Coordinates are relative to the source image, not the thumbnail.
|
2006-11-01 06:34:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
class ImageMap {
|
2016-03-03 16:36:38 +00:00
|
|
|
public static $id = 0;
|
2006-11-01 06:34:42 +00:00
|
|
|
|
2006-12-13 05:55:37 +00:00
|
|
|
const TOP_RIGHT = 0;
|
|
|
|
const BOTTOM_RIGHT = 1;
|
|
|
|
const BOTTOM_LEFT = 2;
|
|
|
|
const TOP_LEFT = 3;
|
|
|
|
const NONE = 4;
|
|
|
|
|
2015-05-03 06:29:25 +00:00
|
|
|
/**
|
2017-10-06 22:39:06 +00:00
|
|
|
* @param Parser &$parser
|
2015-05-03 06:29:25 +00:00
|
|
|
*/
|
|
|
|
public static function onParserFirstCallInit( Parser &$parser ) {
|
2017-05-17 18:17:52 +00:00
|
|
|
$parser->setHook( 'imagemap', [ 'ImageMap', 'render' ] );
|
2015-05-03 06:29:25 +00:00
|
|
|
}
|
|
|
|
|
2012-01-28 17:05:20 +00:00
|
|
|
/**
|
2017-10-06 22:39:06 +00:00
|
|
|
* @param string $input
|
|
|
|
* @param array $params
|
|
|
|
* @param Parser $parser
|
2016-03-03 16:36:38 +00:00
|
|
|
* @return string HTML (Image map, or error message)
|
2012-01-28 17:05:20 +00:00
|
|
|
*/
|
|
|
|
public static function render( $input, $params, $parser ) {
|
2016-03-03 16:49:52 +00:00
|
|
|
global $wgUrlProtocols, $wgNoFollowLinks;
|
|
|
|
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'main' );
|
2006-12-13 05:55:37 +00:00
|
|
|
|
2006-11-01 06:34:42 +00:00
|
|
|
$lines = explode( "\n", $input );
|
|
|
|
|
|
|
|
$first = true;
|
|
|
|
$lineNum = 0;
|
2008-10-06 06:58:13 +00:00
|
|
|
$mapHTML = '';
|
2017-05-17 18:17:52 +00:00
|
|
|
$links = [];
|
2007-04-17 11:59:53 +00:00
|
|
|
|
2016-03-03 16:36:38 +00:00
|
|
|
// Define canonical desc types to allow i18n of 'imagemap_desc_types'
|
2007-04-17 11:59:53 +00:00
|
|
|
$descTypesCanonical = 'top-right, bottom-right, bottom-left, top-left, none';
|
2006-12-13 05:55:37 +00:00
|
|
|
$descType = self::BOTTOM_RIGHT;
|
2007-01-05 16:44:59 +00:00
|
|
|
$defaultLinkAttribs = false;
|
2007-04-17 09:18:42 +00:00
|
|
|
$realmap = true;
|
2017-05-17 18:17:52 +00:00
|
|
|
$extLinks = [];
|
2006-11-01 06:34:42 +00:00
|
|
|
foreach ( $lines as $line ) {
|
|
|
|
++$lineNum;
|
2007-04-18 09:14:41 +00:00
|
|
|
$externLink = false;
|
2006-11-01 06:34:42 +00:00
|
|
|
|
|
|
|
$line = trim( $line );
|
2006-12-13 05:55:37 +00:00
|
|
|
if ( $line == '' || $line[0] == '#' ) {
|
2006-11-01 06:34:42 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $first ) {
|
|
|
|
$first = false;
|
|
|
|
|
2016-03-03 16:36:38 +00:00
|
|
|
// The first line should have an image specification on it
|
|
|
|
// Extract it and render the HTML
|
2006-11-01 06:34:42 +00:00
|
|
|
$bits = explode( '|', $line, 2 );
|
|
|
|
if ( count( $bits ) == 1 ) {
|
|
|
|
$image = $bits[0];
|
|
|
|
$options = '';
|
|
|
|
} else {
|
|
|
|
list( $image, $options ) = $bits;
|
|
|
|
}
|
|
|
|
$imageTitle = Title::newFromText( $image );
|
2016-09-28 03:31:48 +00:00
|
|
|
if ( !$imageTitle || !$imageTitle->inNamespace( NS_FILE ) ) {
|
2006-11-01 06:34:42 +00:00
|
|
|
return self::error( 'imagemap_no_image' );
|
|
|
|
}
|
2012-08-30 16:12:52 +00:00
|
|
|
if ( wfIsBadImage( $imageTitle->getDBkey(), $parser->mTitle ) ) {
|
2008-08-02 03:23:05 +00:00
|
|
|
return self::error( 'imagemap_bad_image' );
|
|
|
|
}
|
2008-09-09 22:31:06 +00:00
|
|
|
// Parse the options so we can use links and the like in the caption
|
2008-09-16 02:17:55 +00:00
|
|
|
$parsedOptions = $parser->recursiveTagParse( $options );
|
|
|
|
$imageHTML = $parser->makeImage( $imageTitle, $parsedOptions );
|
|
|
|
$parser->replaceLinkHolders( $imageHTML );
|
|
|
|
$imageHTML = $parser->mStripState->unstripBoth( $imageHTML );
|
|
|
|
$imageHTML = Sanitizer::normalizeCharReferences( $imageHTML );
|
2006-11-01 06:34:42 +00:00
|
|
|
|
2008-05-14 23:12:52 +00:00
|
|
|
$domDoc = new DOMDocument();
|
2008-10-06 06:05:48 +00:00
|
|
|
wfSuppressWarnings();
|
|
|
|
$ok = $domDoc->loadXML( $imageHTML );
|
|
|
|
wfRestoreWarnings();
|
|
|
|
if ( !$ok ) {
|
|
|
|
return self::error( 'imagemap_invalid_image' );
|
|
|
|
}
|
2006-12-13 05:55:37 +00:00
|
|
|
$xpath = new DOMXPath( $domDoc );
|
|
|
|
$imgs = $xpath->query( '//img' );
|
|
|
|
if ( !$imgs->length ) {
|
2006-11-01 06:34:42 +00:00
|
|
|
return self::error( 'imagemap_invalid_image' );
|
|
|
|
}
|
2012-08-30 16:12:52 +00:00
|
|
|
$imageNode = $imgs->item( 0 );
|
|
|
|
$thumbWidth = $imageNode->getAttribute( 'width' );
|
|
|
|
$thumbHeight = $imageNode->getAttribute( 'height' );
|
2006-11-01 06:34:42 +00:00
|
|
|
|
2011-06-17 04:47:28 +00:00
|
|
|
$imageObj = wfFindFile( $imageTitle );
|
2008-04-26 18:24:23 +00:00
|
|
|
if ( !$imageObj || !$imageObj->exists() ) {
|
2007-05-28 01:44:57 +00:00
|
|
|
return self::error( 'imagemap_invalid_image' );
|
|
|
|
}
|
2016-03-03 16:36:38 +00:00
|
|
|
// Add the linear dimensions to avoid inaccuracy in the scale
|
|
|
|
// factor when one is much larger than the other
|
|
|
|
// (sx+sy)/(x+y) = s
|
2006-11-01 06:34:42 +00:00
|
|
|
$denominator = $imageObj->getWidth() + $imageObj->getHeight();
|
|
|
|
$numerator = $thumbWidth + $thumbHeight;
|
|
|
|
if ( $denominator <= 0 || $numerator <= 0 ) {
|
|
|
|
return self::error( 'imagemap_invalid_image' );
|
|
|
|
}
|
|
|
|
$scale = $numerator / $denominator;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-03-03 16:36:38 +00:00
|
|
|
// Handle desc spec
|
2006-12-13 05:55:37 +00:00
|
|
|
$cmd = strtok( $line, " \t" );
|
|
|
|
if ( $cmd == 'desc' ) {
|
2012-08-30 16:12:52 +00:00
|
|
|
$typesText = wfMessage( 'imagemap_desc_types' )->inContentLanguage()->text();
|
2007-04-17 11:59:53 +00:00
|
|
|
if ( $descTypesCanonical != $typesText ) {
|
|
|
|
// i18n desc types exists
|
|
|
|
$typesText = $descTypesCanonical . ', ' . $typesText;
|
|
|
|
}
|
2006-12-13 05:55:37 +00:00
|
|
|
$types = array_map( 'trim', explode( ',', $typesText ) );
|
|
|
|
$type = trim( strtok( '' ) );
|
|
|
|
$descType = array_search( $type, $types );
|
2007-04-17 11:59:53 +00:00
|
|
|
if ( $descType > 4 ) {
|
|
|
|
// A localized descType is used. Subtract 5 to reach the canonical desc type.
|
|
|
|
$descType = $descType - 5;
|
|
|
|
}
|
2016-03-03 16:36:38 +00:00
|
|
|
// <0? In theory never, but paranoia...
|
|
|
|
if ( $descType === false || $descType < 0 ) {
|
2006-12-13 05:55:37 +00:00
|
|
|
return self::error( 'imagemap_invalid_desc', $typesText );
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-12-10 22:51:18 +00:00
|
|
|
$title = false;
|
2016-03-03 16:36:38 +00:00
|
|
|
// Find the link
|
2007-04-18 09:14:41 +00:00
|
|
|
$link = trim( strstr( $line, '[' ) );
|
2017-05-17 18:17:52 +00:00
|
|
|
$m = [];
|
2006-11-01 06:34:42 +00:00
|
|
|
if ( preg_match( '/^ \[\[ ([^|]*+) \| ([^\]]*+) \]\] \w* $ /x', $link, $m ) ) {
|
|
|
|
$title = Title::newFromText( $m[1] );
|
|
|
|
$alt = trim( $m[2] );
|
|
|
|
} elseif ( preg_match( '/^ \[\[ ([^\]]*+) \]\] \w* $ /x', $link, $m ) ) {
|
|
|
|
$title = Title::newFromText( $m[1] );
|
2012-08-30 16:12:52 +00:00
|
|
|
if ( is_null( $title ) ) {
|
|
|
|
return self::error( 'imagemap_invalid_title', $lineNum );
|
|
|
|
}
|
2006-12-13 05:55:37 +00:00
|
|
|
$alt = $title->getFullText();
|
2017-05-17 18:17:52 +00:00
|
|
|
} elseif ( in_array( substr( $link, 1, strpos( $link, '//' ) + 1 ), $wgUrlProtocols )
|
|
|
|
|| in_array( substr( $link, 1, strpos( $link, ':' ) ), $wgUrlProtocols )
|
|
|
|
) {
|
2007-04-18 09:14:41 +00:00
|
|
|
if ( preg_match( '/^ \[ ([^\s]*+) \s ([^\]]*+) \] \w* $ /x', $link, $m ) ) {
|
2008-01-27 01:58:39 +00:00
|
|
|
$title = $m[1];
|
|
|
|
$alt = trim( $m[2] );
|
2007-04-18 09:14:41 +00:00
|
|
|
$externLink = true;
|
|
|
|
} elseif ( preg_match( '/^ \[ ([^\]]*+) \] \w* $ /x', $link, $m ) ) {
|
2008-01-27 01:58:39 +00:00
|
|
|
$title = $alt = trim( $m[1] );
|
2007-04-18 09:14:41 +00:00
|
|
|
$externLink = true;
|
|
|
|
}
|
2006-11-01 06:34:42 +00:00
|
|
|
} else {
|
|
|
|
return self::error( 'imagemap_no_link', $lineNum );
|
|
|
|
}
|
|
|
|
if ( !$title ) {
|
|
|
|
return self::error( 'imagemap_invalid_title', $lineNum );
|
|
|
|
}
|
|
|
|
|
|
|
|
$shapeSpec = substr( $line, 0, -strlen( $link ) );
|
|
|
|
|
2016-03-03 16:36:38 +00:00
|
|
|
// Tokenize shape spec
|
2006-11-01 06:34:42 +00:00
|
|
|
$shape = strtok( $shapeSpec, " \t" );
|
|
|
|
switch ( $shape ) {
|
|
|
|
case 'default':
|
2017-05-17 18:17:52 +00:00
|
|
|
$coords = [];
|
2006-11-01 06:34:42 +00:00
|
|
|
break;
|
|
|
|
case 'rect':
|
|
|
|
$coords = self::tokenizeCoords( 4, $lineNum );
|
|
|
|
if ( !is_array( $coords ) ) {
|
|
|
|
return $coords;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'circle':
|
|
|
|
$coords = self::tokenizeCoords( 3, $lineNum );
|
|
|
|
if ( !is_array( $coords ) ) {
|
|
|
|
return $coords;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'poly':
|
2017-05-17 18:17:52 +00:00
|
|
|
$coords = [];
|
2006-11-01 06:34:42 +00:00
|
|
|
$coord = strtok( " \t" );
|
|
|
|
while ( $coord !== false ) {
|
|
|
|
$coords[] = $coord;
|
2006-11-27 03:13:46 +00:00
|
|
|
$coord = strtok( " \t" );
|
2006-11-01 06:34:42 +00:00
|
|
|
}
|
|
|
|
if ( !count( $coords ) ) {
|
|
|
|
return self::error( 'imagemap_missing_coord', $lineNum );
|
|
|
|
}
|
2008-10-06 07:03:23 +00:00
|
|
|
if ( count( $coords ) % 2 !== 0 ) {
|
|
|
|
return self::error( 'imagemap_poly_odd', $lineNum );
|
|
|
|
}
|
2006-11-01 06:34:42 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return self::error( 'imagemap_unrecognised_shape', $lineNum );
|
|
|
|
}
|
|
|
|
|
2016-03-03 16:36:38 +00:00
|
|
|
// Scale the coords using the size of the source image
|
2006-11-01 06:34:42 +00:00
|
|
|
foreach ( $coords as $i => $c ) {
|
2007-01-15 19:44:30 +00:00
|
|
|
$coords[$i] = intval( round( $c * $scale ) );
|
2006-11-01 06:34:42 +00:00
|
|
|
}
|
|
|
|
|
2016-03-03 16:36:38 +00:00
|
|
|
// Construct the area tag
|
2017-05-17 18:17:52 +00:00
|
|
|
$attribs = [];
|
2007-04-18 09:14:41 +00:00
|
|
|
if ( $externLink ) {
|
|
|
|
$attribs['href'] = $title;
|
|
|
|
$attribs['class'] = 'plainlinks';
|
|
|
|
if ( $wgNoFollowLinks ) {
|
|
|
|
$attribs['rel'] = 'nofollow';
|
|
|
|
}
|
2011-06-17 16:26:31 +00:00
|
|
|
} elseif ( $title->getFragment() != '' && $title->getPrefixedDBkey() == '' ) {
|
2016-03-03 16:36:38 +00:00
|
|
|
// XXX: kluge to handle [[#Fragment]] links, should really fix getLocalURL()
|
|
|
|
// in Title.php to return an empty string in this case
|
2007-08-07 17:01:38 +00:00
|
|
|
$attribs['href'] = $title->getFragmentForURL();
|
2007-04-18 09:14:41 +00:00
|
|
|
} else {
|
2012-09-01 12:25:01 +00:00
|
|
|
$attribs['href'] = $title->getLocalURL() . $title->getFragmentForURL();
|
2007-04-18 09:14:41 +00:00
|
|
|
}
|
2007-01-05 16:44:59 +00:00
|
|
|
if ( $shape != 'default' ) {
|
|
|
|
$attribs['shape'] = $shape;
|
|
|
|
}
|
2006-11-01 06:34:42 +00:00
|
|
|
if ( $coords ) {
|
|
|
|
$attribs['coords'] = implode( ',', $coords );
|
|
|
|
}
|
|
|
|
if ( $alt != '' ) {
|
2007-01-05 16:44:59 +00:00
|
|
|
if ( $shape != 'default' ) {
|
|
|
|
$attribs['alt'] = $alt;
|
|
|
|
}
|
2006-12-13 05:55:37 +00:00
|
|
|
$attribs['title'] = $alt;
|
2011-06-17 16:26:31 +00:00
|
|
|
}
|
2007-01-05 16:44:59 +00:00
|
|
|
if ( $shape == 'default' ) {
|
|
|
|
$defaultLinkAttribs = $attribs;
|
|
|
|
} else {
|
2008-10-06 06:58:13 +00:00
|
|
|
$mapHTML .= Xml::element( 'area', $attribs ) . "\n";
|
2007-01-05 16:44:59 +00:00
|
|
|
}
|
2007-04-18 09:14:41 +00:00
|
|
|
if ( $externLink ) {
|
|
|
|
$extLinks[] = $title;
|
|
|
|
} else {
|
|
|
|
$links[] = $title;
|
|
|
|
}
|
2006-11-01 06:34:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( $first ) {
|
|
|
|
return self::error( 'imagemap_no_image' );
|
|
|
|
}
|
|
|
|
|
2012-01-15 21:25:24 +00:00
|
|
|
if ( $mapHTML == '' ) {
|
2007-04-17 09:18:42 +00:00
|
|
|
// no areas defined, default only. It's not a real imagemap, so we do not need some tags
|
|
|
|
$realmap = false;
|
2006-11-01 06:34:42 +00:00
|
|
|
}
|
|
|
|
|
2007-04-17 09:18:42 +00:00
|
|
|
if ( $realmap ) {
|
2016-03-03 16:36:38 +00:00
|
|
|
// Construct the map
|
|
|
|
// Add random number to avoid breaking cached HTML fragments that are
|
|
|
|
// later joined together on the one page (bug 16471)
|
2008-12-19 07:03:27 +00:00
|
|
|
$mapName = "ImageMap_" . ++self::$id . '_' . mt_rand( 0, 0x7fffffff );
|
2008-10-06 06:58:13 +00:00
|
|
|
$mapHTML = "<map name=\"$mapName\">\n$mapHTML</map>\n";
|
2007-04-17 09:18:42 +00:00
|
|
|
|
2016-03-03 16:36:38 +00:00
|
|
|
// Alter the image tag
|
2007-04-17 09:18:42 +00:00
|
|
|
$imageNode->setAttribute( 'usemap', "#$mapName" );
|
|
|
|
}
|
2008-10-06 06:58:13 +00:00
|
|
|
|
2016-03-03 16:36:38 +00:00
|
|
|
// Add a surrounding div, remove the default link to the description page
|
2006-12-13 05:55:37 +00:00
|
|
|
$anchor = $imageNode->parentNode;
|
|
|
|
$parent = $anchor->parentNode;
|
|
|
|
$div = $parent->insertBefore( new DOMElement( 'div' ), $anchor );
|
2012-05-17 12:06:02 +00:00
|
|
|
$div->setAttribute( 'class', 'noresize' );
|
2007-01-05 16:44:59 +00:00
|
|
|
if ( $defaultLinkAttribs ) {
|
|
|
|
$defaultAnchor = $div->appendChild( new DOMElement( 'a' ) );
|
|
|
|
foreach ( $defaultLinkAttribs as $name => $value ) {
|
|
|
|
$defaultAnchor->setAttribute( $name, $value );
|
|
|
|
}
|
|
|
|
$imageParent = $defaultAnchor;
|
|
|
|
} else {
|
|
|
|
$imageParent = $div;
|
|
|
|
}
|
|
|
|
|
2016-03-03 16:36:38 +00:00
|
|
|
// Add the map HTML to the div
|
|
|
|
// We used to add it before the div, but that made tidy unhappy
|
2008-10-06 06:58:13 +00:00
|
|
|
if ( $mapHTML != '' ) {
|
2008-12-02 18:02:13 +00:00
|
|
|
$mapDoc = new DOMDocument();
|
|
|
|
$mapDoc->loadXML( $mapHTML );
|
2008-10-06 06:58:13 +00:00
|
|
|
$mapNode = $domDoc->importNode( $mapDoc->documentElement, true );
|
|
|
|
$div->appendChild( $mapNode );
|
|
|
|
}
|
|
|
|
|
2007-01-05 16:44:59 +00:00
|
|
|
$imageParent->appendChild( $imageNode->cloneNode( true ) );
|
2006-12-13 05:55:37 +00:00
|
|
|
$parent->removeChild( $anchor );
|
|
|
|
|
2016-03-03 16:36:38 +00:00
|
|
|
// Determine whether a "magnify" link is present
|
2006-12-13 05:55:37 +00:00
|
|
|
$xpath = new DOMXPath( $domDoc );
|
|
|
|
$magnify = $xpath->query( '//div[@class="magnify"]' );
|
|
|
|
if ( !$magnify->length && $descType != self::NONE ) {
|
2016-03-03 16:36:38 +00:00
|
|
|
// Add image description link
|
2006-12-13 05:55:37 +00:00
|
|
|
if ( $descType == self::TOP_LEFT || $descType == self::BOTTOM_LEFT ) {
|
2008-10-06 03:10:34 +00:00
|
|
|
$marginLeft = 0;
|
2006-12-13 05:55:37 +00:00
|
|
|
} else {
|
2008-10-06 03:10:34 +00:00
|
|
|
$marginLeft = $thumbWidth - 20;
|
2006-12-13 05:55:37 +00:00
|
|
|
}
|
|
|
|
if ( $descType == self::TOP_LEFT || $descType == self::TOP_RIGHT ) {
|
2008-10-06 03:10:34 +00:00
|
|
|
$marginTop = -$thumbHeight;
|
2008-10-06 03:37:30 +00:00
|
|
|
// 1px hack for IE, to stop it poking out the top
|
|
|
|
$marginTop += 1;
|
2006-12-13 05:55:37 +00:00
|
|
|
} else {
|
2008-10-06 03:10:34 +00:00
|
|
|
$marginTop = -20;
|
2006-12-13 05:55:37 +00:00
|
|
|
}
|
2008-10-06 04:24:20 +00:00
|
|
|
$div->setAttribute( 'style', "height: {$thumbHeight}px; width: {$thumbWidth}px; " );
|
2008-10-06 03:10:34 +00:00
|
|
|
$descWrapper = $div->appendChild( new DOMElement( 'div' ) );
|
2011-06-17 16:26:31 +00:00
|
|
|
$descWrapper->setAttribute( 'style',
|
|
|
|
"margin-left: {$marginLeft}px; " .
|
2012-08-30 16:12:52 +00:00
|
|
|
"margin-top: {$marginTop}px; " .
|
|
|
|
"text-align: left;"
|
2008-10-06 03:10:34 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$descAnchor = $descWrapper->appendChild( new DOMElement( 'a' ) );
|
2012-09-01 12:25:01 +00:00
|
|
|
$descAnchor->setAttribute( 'href', $imageTitle->getLocalURL() );
|
2012-08-30 16:12:52 +00:00
|
|
|
$descAnchor->setAttribute(
|
|
|
|
'title',
|
|
|
|
wfMessage( 'imagemap_description' )->inContentLanguage()->text()
|
|
|
|
);
|
2006-12-13 05:55:37 +00:00
|
|
|
$descImg = $descAnchor->appendChild( new DOMElement( 'img' ) );
|
2012-08-30 16:12:52 +00:00
|
|
|
$descImg->setAttribute(
|
|
|
|
'alt',
|
|
|
|
wfMessage( 'imagemap_description' )->inContentLanguage()->text()
|
|
|
|
);
|
2016-03-03 16:49:52 +00:00
|
|
|
$url = $config->get( 'ExtensionAssetsPath' ) . '/ImageMap/desc-20.png';
|
|
|
|
$descImg->setAttribute(
|
|
|
|
'src',
|
|
|
|
OutputPage::transformResourcePath( $config, $url )
|
|
|
|
);
|
2006-12-13 05:55:37 +00:00
|
|
|
$descImg->setAttribute( 'style', 'border: none;' );
|
|
|
|
}
|
|
|
|
|
2016-03-03 16:36:38 +00:00
|
|
|
// Output the result
|
|
|
|
// We use saveXML() not saveHTML() because then we get XHTML-compliant output.
|
|
|
|
// The disadvantage is that we have to strip out the DTD
|
2017-10-11 12:05:46 +00:00
|
|
|
$output = preg_replace( '/<\?xml[^?]*\?>/', '', $domDoc->saveXML( null, LIBXML_NOEMPTYTAG ) );
|
2006-11-01 06:34:42 +00:00
|
|
|
|
2016-03-03 16:36:38 +00:00
|
|
|
// Register links
|
2006-11-01 06:34:42 +00:00
|
|
|
foreach ( $links as $title ) {
|
2012-08-30 16:12:52 +00:00
|
|
|
if ( $title->isExternal() || $title->getNamespace() == NS_SPECIAL ) {
|
2008-01-16 06:08:01 +00:00
|
|
|
// Don't register special or interwiki links...
|
2012-08-30 16:12:52 +00:00
|
|
|
} elseif ( $title->getNamespace() == NS_MEDIA ) {
|
2008-01-16 06:08:01 +00:00
|
|
|
// Regular Media: links are recorded as image usages
|
|
|
|
$parser->mOutput->addImage( $title->getDBkey() );
|
|
|
|
} else {
|
|
|
|
// Plain ol' link
|
|
|
|
$parser->mOutput->addLink( $title );
|
|
|
|
}
|
2006-11-01 06:34:42 +00:00
|
|
|
}
|
2016-03-03 16:36:38 +00:00
|
|
|
foreach ( $extLinks as $title ) {
|
|
|
|
$parser->mOutput->addExternalLink( $title );
|
2007-04-18 09:14:41 +00:00
|
|
|
}
|
2016-03-03 16:36:38 +00:00
|
|
|
// Armour output against broken parser
|
2006-12-13 05:55:37 +00:00
|
|
|
$output = str_replace( "\n", '', $output );
|
2006-11-01 06:34:42 +00:00
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2012-01-28 17:05:20 +00:00
|
|
|
/**
|
2017-10-06 22:39:06 +00:00
|
|
|
* @param int $count
|
|
|
|
* @param int|string $lineNum
|
2016-03-03 16:36:38 +00:00
|
|
|
* @return array|string String with error (HTML), or array of coordinates
|
2012-01-28 17:05:20 +00:00
|
|
|
*/
|
2006-11-01 06:34:42 +00:00
|
|
|
static function tokenizeCoords( $count, $lineNum ) {
|
2017-05-17 18:17:52 +00:00
|
|
|
$coords = [];
|
2006-11-01 06:34:42 +00:00
|
|
|
for ( $i = 0; $i < $count; $i++ ) {
|
|
|
|
$coord = strtok( " \t" );
|
|
|
|
if ( $coord === false ) {
|
|
|
|
return self::error( 'imagemap_missing_coord', $lineNum );
|
|
|
|
}
|
|
|
|
if ( !is_numeric( $coord ) || $coord > 1e9 || $coord < 0 ) {
|
|
|
|
return self::error( 'imagemap_invalid_coord', $lineNum );
|
|
|
|
}
|
|
|
|
$coords[$i] = $coord;
|
|
|
|
}
|
|
|
|
return $coords;
|
|
|
|
}
|
|
|
|
|
2012-01-28 17:05:20 +00:00
|
|
|
/**
|
2017-10-06 22:39:06 +00:00
|
|
|
* @param string $name
|
|
|
|
* @param string|int|bool $line
|
2016-03-03 16:36:38 +00:00
|
|
|
* @return string HTML
|
2012-01-28 17:05:20 +00:00
|
|
|
*/
|
2006-11-01 06:34:42 +00:00
|
|
|
static function error( $name, $line = false ) {
|
2012-08-30 16:12:52 +00:00
|
|
|
return '<p class="error">' . wfMessage( $name, $line )->text() . '</p>';
|
2006-11-01 06:34:42 +00:00
|
|
|
}
|
|
|
|
}
|