summaryrefslogtreecommitdiff
path: root/extensions/ImageMap/ImageMap_body.php
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2014-01-28 09:50:25 -0500
committerLuke Shumaker <LukeShu@sbcglobal.net>2014-01-28 09:50:25 -0500
commit5744df39e15f85c6cc8a9faf8924d77e76d2b216 (patch)
treea8c8dd40a94d1fa0d5377566aa5548ae55a163da /extensions/ImageMap/ImageMap_body.php
parent4bb2aeca1d198391ca856aa16c40b8559c68daec (diff)
parent224b22a051051f6c2e494c3a2fb4adb42898e2d1 (diff)
Merge branch 'archwiki'
Conflicts: extensions/FluxBBAuthPlugin.php extensions/SyntaxHighlight_GeSHi/README extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.class.php extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.i18n.php extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.php extensions/SyntaxHighlight_GeSHi/geshi/docs/CHANGES extensions/SyntaxHighlight_GeSHi/geshi/docs/THANKS extensions/SyntaxHighlight_GeSHi/geshi/docs/TODO extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/AbstractClass.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/AbstractClass_logo.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/AbstractMethod.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/AbstractPrivateClass.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/AbstractPrivateClass_logo.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/AbstractPrivateMethod.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/Class.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/Class_logo.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/Constant.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/Constructor.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/Destructor.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/Function.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/Global.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/I.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/Index.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/Interface.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/Interface_logo.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/L.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/Lminus.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/Lplus.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/Method.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/Page.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/Page_logo.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/PrivateClass.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/PrivateClass_logo.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/PrivateMethod.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/PrivateVariable.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/StaticMethod.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/StaticVariable.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/T.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/Tminus.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/Tplus.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/Variable.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/blank.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/class_folder.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/file.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/folder.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/function_folder.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/next_button.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/next_button_disabled.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/package.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/package_folder.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/previous_button.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/previous_button_disabled.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/private_class_logo.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/tutorial.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/tutorial_folder.png extensions/SyntaxHighlight_GeSHi/geshi/docs/api/media/images/up_button.png extensions/SyntaxHighlight_GeSHi/geshi/docs/geshi-doc.html extensions/SyntaxHighlight_GeSHi/geshi/docs/geshi-doc.txt extensions/SyntaxHighlight_GeSHi/geshi/geshi.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/4cs.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/6502acme.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/6502kickass.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/6502tasm.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/68000devpac.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/abap.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/actionscript.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/actionscript3.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/ada.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/algol68.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/apache.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/applescript.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/apt_sources.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/asm.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/asp.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/autoconf.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/autohotkey.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/autoit.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/avisynth.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/awk.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/bascomavr.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/bash.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/basic4gl.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/bf.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/bibtex.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/blitzbasic.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/bnf.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/boo.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/c.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/c_loadrunner.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/c_mac.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/caddcl.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/cadlisp.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/cfdg.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/cfm.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/chaiscript.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/cil.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/clojure.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/cmake.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/cobol.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/coffeescript.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/cpp-qt.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/cpp.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/csharp.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/css.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/cuesheet.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/d.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/dcs.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/delphi.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/diff.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/div.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/dos.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/dot.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/e.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/ecmascript.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/eiffel.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/email.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/epc.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/erlang.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/euphoria.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/f1.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/falcon.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/fo.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/fortran.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/freebasic.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/fsharp.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/gambas.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/gdb.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/genero.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/genie.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/gettext.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/glsl.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/gml.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/gnuplot.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/go.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/groovy.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/gwbasic.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/haskell.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/hicest.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/hq9plus.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/html4strict.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/html5.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/icon.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/idl.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/ini.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/inno.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/intercal.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/io.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/j.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/java.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/java5.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/javascript.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/jquery.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/kixtart.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/klonec.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/klonecpp.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/latex.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/lb.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/lisp.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/llvm.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/locobasic.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/logtalk.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/lolcode.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/lotusformulas.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/lotusscript.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/lscript.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/lsl2.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/lua.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/m68k.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/magiksf.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/make.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/mapbasic.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/matlab.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/mirc.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/mmix.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/modula2.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/modula3.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/mpasm.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/mxml.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/mysql.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/newlisp.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/nsis.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/oberon2.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/objc.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/objeck.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/ocaml-brief.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/ocaml.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/oobas.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/oracle11.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/oracle8.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/oxygene.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/oz.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/pascal.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/pcre.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/per.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/perl.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/perl6.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/pf.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/php-brief.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/php.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/pic16.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/pike.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/pixelbender.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/pli.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/plsql.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/postgresql.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/povray.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/powerbuilder.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/powershell.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/proftpd.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/progress.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/prolog.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/properties.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/providex.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/purebasic.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/pycon.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/python.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/q.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/qbasic.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/rails.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/rebol.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/reg.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/robots.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/rpmspec.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/rsplus.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/ruby.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/sas.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/scala.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/scheme.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/scilab.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/sdlbasic.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/smalltalk.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/smarty.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/sql.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/systemverilog.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/tcl.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/teraterm.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/text.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/thinbasic.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/tsql.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/typoscript.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/unicon.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/uscript.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/vala.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/vb.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/vbnet.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/verilog.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/vhdl.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/vim.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/visualfoxpro.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/visualprolog.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/whitespace.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/whois.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/winbatch.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/xbasic.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/xml.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/xorg_conf.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/xpp.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/yaml.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/z80.php extensions/SyntaxHighlight_GeSHi/geshi/geshi/zxbasic.php
Diffstat (limited to 'extensions/ImageMap/ImageMap_body.php')
-rw-r--r--extensions/ImageMap/ImageMap_body.php391
1 files changed, 391 insertions, 0 deletions
diff --git a/extensions/ImageMap/ImageMap_body.php b/extensions/ImageMap/ImageMap_body.php
new file mode 100644
index 00000000..e67b4426
--- /dev/null
+++ b/extensions/ImageMap/ImageMap_body.php
@@ -0,0 +1,391 @@
+<?php
+
+/**
+ * Image map extension.
+ *
+ * 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]]
+ *
+ * desc bottom-left
+ * </imagemap>
+ *
+ * Coordinates are relative to the source image, not the thumbnail
+ *
+ */
+
+class ImageMap {
+ static public $id = 0;
+
+ const TOP_RIGHT = 0;
+ const BOTTOM_RIGHT = 1;
+ const BOTTOM_LEFT = 2;
+ const TOP_LEFT = 3;
+ const NONE = 4;
+
+ /**
+ * @param $input
+ * @param $params
+ * @param $parser Parser
+ * @return array|mixed|string
+ */
+ public static function render( $input, $params, $parser ) {
+ global $wgExtensionAssetsPath, $wgUrlProtocols, $wgNoFollowLinks;
+
+ $lines = explode( "\n", $input );
+
+ $first = true;
+ $lineNum = 0;
+ $mapHTML = '';
+ $links = array();
+
+ # Define canonical desc types to allow i18n of 'imagemap_desc_types'
+ $descTypesCanonical = 'top-right, bottom-right, bottom-left, top-left, none';
+ $descType = self::BOTTOM_RIGHT;
+ $defaultLinkAttribs = false;
+ $realmap = true;
+ $extLinks = array();
+ foreach ( $lines as $line ) {
+ ++$lineNum;
+ $externLink = false;
+
+ $line = trim( $line );
+ if ( $line == '' || $line[0] == '#' ) {
+ continue;
+ }
+
+ if ( $first ) {
+ $first = false;
+
+ # The first line should have an image specification on it
+ # Extract it and render the HTML
+ $bits = explode( '|', $line, 2 );
+ if ( count( $bits ) == 1 ) {
+ $image = $bits[0];
+ $options = '';
+ } else {
+ list( $image, $options ) = $bits;
+ }
+ $imageTitle = Title::newFromText( $image );
+ if ( !$imageTitle || $imageTitle->getNamespace() != NS_IMAGE ) {
+ return self::error( 'imagemap_no_image' );
+ }
+ if ( wfIsBadImage( $imageTitle->getDBkey(), $parser->mTitle ) ) {
+ return self::error( 'imagemap_bad_image' );
+ }
+ // Parse the options so we can use links and the like in the caption
+ $parsedOptions = $parser->recursiveTagParse( $options );
+ $imageHTML = $parser->makeImage( $imageTitle, $parsedOptions );
+ $parser->replaceLinkHolders( $imageHTML );
+ $imageHTML = $parser->mStripState->unstripBoth( $imageHTML );
+ $imageHTML = Sanitizer::normalizeCharReferences( $imageHTML );
+
+ $domDoc = new DOMDocument();
+ wfSuppressWarnings();
+ $ok = $domDoc->loadXML( $imageHTML );
+ wfRestoreWarnings();
+ if ( !$ok ) {
+ return self::error( 'imagemap_invalid_image' );
+ }
+ $xpath = new DOMXPath( $domDoc );
+ $imgs = $xpath->query( '//img' );
+ if ( !$imgs->length ) {
+ return self::error( 'imagemap_invalid_image' );
+ }
+ $imageNode = $imgs->item( 0 );
+ $thumbWidth = $imageNode->getAttribute( 'width' );
+ $thumbHeight = $imageNode->getAttribute( 'height' );
+
+ $imageObj = wfFindFile( $imageTitle );
+ if ( !$imageObj || !$imageObj->exists() ) {
+ return self::error( 'imagemap_invalid_image' );
+ }
+ # Add the linear dimensions to avoid inaccuracy in the scale
+ # factor when one is much larger than the other
+ # (sx+sy)/(x+y) = s
+ $denominator = $imageObj->getWidth() + $imageObj->getHeight();
+ $numerator = $thumbWidth + $thumbHeight;
+ if ( $denominator <= 0 || $numerator <= 0 ) {
+ return self::error( 'imagemap_invalid_image' );
+ }
+ $scale = $numerator / $denominator;
+ continue;
+ }
+
+ # Handle desc spec
+ $cmd = strtok( $line, " \t" );
+ if ( $cmd == 'desc' ) {
+ $typesText = wfMessage( 'imagemap_desc_types' )->inContentLanguage()->text();
+ if ( $descTypesCanonical != $typesText ) {
+ // i18n desc types exists
+ $typesText = $descTypesCanonical . ', ' . $typesText;
+ }
+ $types = array_map( 'trim', explode( ',', $typesText ) );
+ $type = trim( strtok( '' ) );
+ $descType = array_search( $type, $types );
+ if ( $descType > 4 ) {
+ // A localized descType is used. Subtract 5 to reach the canonical desc type.
+ $descType = $descType - 5;
+ }
+ if ( $descType === false || $descType < 0 ) { // <0? In theory never, but paranoia...
+ return self::error( 'imagemap_invalid_desc', $typesText );
+ }
+ continue;
+ }
+
+ # Find the link
+ $link = trim( strstr( $line, '[' ) );
+ $m = array();
+ 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] );
+ if ( is_null( $title ) ) {
+ return self::error( 'imagemap_invalid_title', $lineNum );
+ }
+ $alt = $title->getFullText();
+ } elseif ( in_array( substr( $link, 1, strpos( $link, '//' ) + 1 ), $wgUrlProtocols ) || in_array( substr( $link, 1, strpos( $link, ':' ) ), $wgUrlProtocols ) ) {
+ if ( preg_match( '/^ \[ ([^\s]*+) \s ([^\]]*+) \] \w* $ /x', $link, $m ) ) {
+ $title = $m[1];
+ $alt = trim( $m[2] );
+ $externLink = true;
+ } elseif ( preg_match( '/^ \[ ([^\]]*+) \] \w* $ /x', $link, $m ) ) {
+ $title = $alt = trim( $m[1] );
+ $externLink = true;
+ }
+ } else {
+ return self::error( 'imagemap_no_link', $lineNum );
+ }
+ if ( !$title ) {
+ return self::error( 'imagemap_invalid_title', $lineNum );
+ }
+
+ $shapeSpec = substr( $line, 0, -strlen( $link ) );
+
+ # Tokenize shape spec
+ $shape = strtok( $shapeSpec, " \t" );
+ switch ( $shape ) {
+ case 'default':
+ $coords = array();
+ 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':
+ $coords = array();
+ $coord = strtok( " \t" );
+ while ( $coord !== false ) {
+ $coords[] = $coord;
+ $coord = strtok( " \t" );
+ }
+ if ( !count( $coords ) ) {
+ return self::error( 'imagemap_missing_coord', $lineNum );
+ }
+ if ( count( $coords ) % 2 !== 0 ) {
+ return self::error( 'imagemap_poly_odd', $lineNum );
+ }
+ break;
+ default:
+ return self::error( 'imagemap_unrecognised_shape', $lineNum );
+ }
+
+ # Scale the coords using the size of the source image
+ foreach ( $coords as $i => $c ) {
+ $coords[$i] = intval( round( $c * $scale ) );
+ }
+
+ # Construct the area tag
+ $attribs = array();
+ if ( $externLink ) {
+ $attribs['href'] = $title;
+ $attribs['class'] = 'plainlinks';
+ if ( $wgNoFollowLinks ) {
+ $attribs['rel'] = 'nofollow';
+ }
+ } elseif ( $title->getFragment() != '' && $title->getPrefixedDBkey() == '' ) {
+ # XXX: kluge to handle [[#Fragment]] links, should really fix getLocalURL()
+ # in Title.php to return an empty string in this case
+ $attribs['href'] = $title->getFragmentForURL();
+ } else {
+ $attribs['href'] = $title->getLocalURL() . $title->getFragmentForURL();
+ }
+ if ( $shape != 'default' ) {
+ $attribs['shape'] = $shape;
+ }
+ if ( $coords ) {
+ $attribs['coords'] = implode( ',', $coords );
+ }
+ if ( $alt != '' ) {
+ if ( $shape != 'default' ) {
+ $attribs['alt'] = $alt;
+ }
+ $attribs['title'] = $alt;
+ }
+ if ( $shape == 'default' ) {
+ $defaultLinkAttribs = $attribs;
+ } else {
+ $mapHTML .= Xml::element( 'area', $attribs ) . "\n";
+ }
+ if ( $externLink ) {
+ $extLinks[] = $title;
+ } else {
+ $links[] = $title;
+ }
+ }
+
+ if ( $first ) {
+ return self::error( 'imagemap_no_image' );
+ }
+
+ if ( $mapHTML == '' ) {
+ // no areas defined, default only. It's not a real imagemap, so we do not need some tags
+ $realmap = false;
+ }
+
+ if ( $realmap ) {
+ # Construct the map
+ # Add random number to avoid breaking cached HTML fragments that are
+ # later joined together on the one page (bug 16471)
+ $mapName = "ImageMap_" . ++self::$id . '_' . mt_rand( 0, 0x7fffffff );
+ $mapHTML = "<map name=\"$mapName\">\n$mapHTML</map>\n";
+
+ # Alter the image tag
+ $imageNode->setAttribute( 'usemap', "#$mapName" );
+ }
+
+ # Add a surrounding div, remove the default link to the description page
+ $anchor = $imageNode->parentNode;
+ $parent = $anchor->parentNode;
+ $div = $parent->insertBefore( new DOMElement( 'div' ), $anchor );
+ $div->setAttribute( 'class', 'noresize' );
+ if ( $defaultLinkAttribs ) {
+ $defaultAnchor = $div->appendChild( new DOMElement( 'a' ) );
+ foreach ( $defaultLinkAttribs as $name => $value ) {
+ $defaultAnchor->setAttribute( $name, $value );
+ }
+ $imageParent = $defaultAnchor;
+ } else {
+ $imageParent = $div;
+ }
+
+ # Add the map HTML to the div
+ # We used to add it before the div, but that made tidy unhappy
+ if ( $mapHTML != '' ) {
+ $mapDoc = new DOMDocument();
+ $mapDoc->loadXML( $mapHTML );
+ $mapNode = $domDoc->importNode( $mapDoc->documentElement, true );
+ $div->appendChild( $mapNode );
+ }
+
+ $imageParent->appendChild( $imageNode->cloneNode( true ) );
+ $parent->removeChild( $anchor );
+
+ # Determine whether a "magnify" link is present
+ $xpath = new DOMXPath( $domDoc );
+ $magnify = $xpath->query( '//div[@class="magnify"]' );
+ if ( !$magnify->length && $descType != self::NONE ) {
+ # Add image description link
+ if ( $descType == self::TOP_LEFT || $descType == self::BOTTOM_LEFT ) {
+ $marginLeft = 0;
+ } else {
+ $marginLeft = $thumbWidth - 20;
+ }
+ if ( $descType == self::TOP_LEFT || $descType == self::TOP_RIGHT ) {
+ $marginTop = -$thumbHeight;
+ // 1px hack for IE, to stop it poking out the top
+ $marginTop += 1;
+ } else {
+ $marginTop = -20;
+ }
+ $div->setAttribute( 'style', "height: {$thumbHeight}px; width: {$thumbWidth}px; " );
+ $descWrapper = $div->appendChild( new DOMElement( 'div' ) );
+ $descWrapper->setAttribute( 'style',
+ "margin-left: {$marginLeft}px; " .
+ "margin-top: {$marginTop}px; " .
+ "text-align: left;"
+ );
+
+ $descAnchor = $descWrapper->appendChild( new DOMElement( 'a' ) );
+ $descAnchor->setAttribute( 'href', $imageTitle->getLocalURL() );
+ $descAnchor->setAttribute(
+ 'title',
+ wfMessage( 'imagemap_description' )->inContentLanguage()->text()
+ );
+ $descImg = $descAnchor->appendChild( new DOMElement( 'img' ) );
+ $descImg->setAttribute(
+ 'alt',
+ wfMessage( 'imagemap_description' )->inContentLanguage()->text()
+ );
+ $descImg->setAttribute( 'src', "$wgExtensionAssetsPath/ImageMap/desc-20.png" );
+ $descImg->setAttribute( 'style', 'border: none;' );
+ }
+
+ # 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
+ $output = preg_replace( '/<\?xml[^?]*\?>/', '', $domDoc->saveXML() );
+
+ # Register links
+ foreach ( $links as $title ) {
+ if ( $title->isExternal() || $title->getNamespace() == NS_SPECIAL ) {
+ // Don't register special or interwiki links...
+ } elseif ( $title->getNamespace() == NS_MEDIA ) {
+ // Regular Media: links are recorded as image usages
+ $parser->mOutput->addImage( $title->getDBkey() );
+ } else {
+ // Plain ol' link
+ $parser->mOutput->addLink( $title );
+ }
+ }
+ if ( isset( $extLinks ) ) {
+ foreach ( $extLinks as $title ) {
+ $parser->mOutput->addExternalLink( $title );
+ }
+ }
+ # Armour output against broken parser
+ $output = str_replace( "\n", '', $output );
+ return $output;
+ }
+
+ /**
+ * @param $count int
+ * @param $lineNum int|string
+ * @return array|string
+ */
+ static function tokenizeCoords( $count, $lineNum ) {
+ $coords = array();
+ 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;
+ }
+
+ /**
+ * @param $name string
+ * @param $line string|int|bool
+ * @return string
+ */
+ static function error( $name, $line = false ) {
+ return '<p class="error">' . wfMessage( $name, $line )->text() . '</p>';
+ }
+}