Extension:YahooMaps

What can this extension do?
This extension allows you to easily create Yahoo maps and markers. The extended descriptions of the markers are all wikitext, enabling links, images, etc. Yahoo maps (unlike Google maps) are allowed to be used for both private (i.e. intranet) and public sites.

Usage
Example:  39.945337 | -105.16412 | KEF | Superior, CO ''Home of Key Equipment Finance (a division of Key Bank)''

All tag attributes are optional, and default to: (basically, centered on the US)
 * style = ''
 * zoom = 15
 * lat = 37.4041960114344
 * lon = -100.008194923401

Installation
Create YahooMaps.php in your extensions directory as follows:  some text 
 * 5) the function registered by the extension gets the text between the
 * 6) tags as input and can transform it into arbitrary HTML code.
 * 7) Note: The output is not interpreted as WikiText but directly
 * 8)       included in the HTML output. So Wiki markup is not supported.
 * 9) To activate the extension, include it from your LocalSettings.php
 * 10) with: include("extensions/YourExtensionName.php");

if( !defined( 'MEDIAWIKI' ) ) { die; }

$wgExtensionFunctions[] = "wfYahooMapsExtension";

$wgExtensionCredits['other'][] = array(       'name' => 'Yahoo Maps Extension',        'author' => 'Chris Reigrut',        'version' => '0.1.0',        'url' => 'http://www.mediawiki.org/wiki/Extension:YahooMaps',        'description' => 'Create Yahoo maps with wikitext markers' );

function wfYahooMapsExtension { global $wgParser; # register the extension with the WikiText parser $wgParser->setHook( "yahoomap", "renderYahooMap" ); }

function renderYahooMap( $input, $argv, &$parser ) { $output = ''; $id = rand; $style = $argv['style']; $zoom = $argv['zoom']; if ($zoom == NULL) { $zoom = 15; } 	$lat = $argv['lat']; if ($lat == NULL) { $lat = 37.4041960114344; } 	$lon = $argv['lon']; if ($lon == NULL) { $lon = -100.008194923401; }
 * 1) The callback function for converting the input text to HTML output

$appId = getYahooAppId; //Create the Javascript for the map from the tag attributes $output .= <<   /*<![CDATA[*/ // Create the standard map var map = new YMap(document.getElementById("map{$id}"),YAHOO_MAP_REG); // Center the map at the specified lat/lon and zoom var center = new YGeoPoint({$lat},{$lon}); // Add the map type control (to select Map/Satellite/Hybrid) map.addTypeControl; // Add the map zoom control map.addZoomLong; ENDPREFIX; # The contents of the tag are the markers. Each line is one marker. $lines = preg_split("/[\r\n]+/", $input); foreach($lines as $line) { if ($line!= NULL && trim($line) != '') { $output .= addMarker($parser, trim($line)); }	}   # Finish the Javascript $output .= <<*/ ENDSUFFIX; return encode($output); }

function addMarker(&$parser, $markerLine) { $output = '';
 * 1) Create the map marker from a line of the format:
 * 2) latitude | longitude | Tag | Expanded (mouseover) text

$tokens = preg_split("/\s*\|\s*/", $markerLine); $lat = array_shift($tokens); $lon = array_shift($tokens); $baseText = parseMarkerText($parser, array_shift($tokens)); // Combine the remaining tokens (that were split around |) into the expanded text // This allows us use pipes in the expanded text (such as image alignment, alternate text for links, etc) $expandedText = parseMarkerText($parser, implode('|', $tokens)); $output .= <<parse($text, $parser->mTitle, $parser->mOptions, false)->getText; # Extract the body portion (which is the text) from the full document preg_match('/(?<=\)(.*)(?=\<\/body\>)/esm', $output, $matches); # Remove CR/LFs $output = preg_replace('/[\r\n]/esm', '', $matches[0]); return $output; }
 * 1) Parse the wikitext markup for the marker text

function encode($text) { return ''; }
 * 1) Encode the given string so that it will no longer be processed by the wikitext engine

function decode($text) { return preg_replace(           '//esm',            'base64_decode("$1")',            $text        ); }
 * 1) Decode all of the encoded portions of the page

function getYahooAppId { global $wgYahooMapsAppId; if ($wgYahooMapsAppId==null || $wgYahooMapsAppId=='') { return "YahooDemo"; }	return $wgYahooMapsAppId; }

if (!function_exists('processEncodedOutput')) { $wgHooks['ParserAfterTidy'][] = 'processEncodedOutput'; function processEncodedOutput( &$out, &$text ) { # Find all hidden content and restore to normal $text = decode($text); return true; } } ?>
 * 1) Process the page after tidy runs, decoding all encoded portions

Parameters
You should add your [Yahoo Maps application ID] as a parameter within LocalSettings.php just prior to the. Unfortunately, the solution is a bit overzealous, and will cause your map to display incorrectly--it will start out ok, but after about a second all markers will be offset downward by some amount proportional to n-1 (where n is the marker number). To fix this, change the following: function setrelative (nodes) { var i = 0; while (i < nodes.length) { if(((nodes[i].style.float && nodes[i].style.float != ('none') ||       (nodes[i].align && nodes[i].align != ('none'))) && (!nodes[i].style.position || nodes[i].style.position != 'relative'))) {           nodes[i].style.position = 'relative'; }       i++; } } to: function setrelative (nodes) { var i = 0; while (i < nodes.length) { if(((nodes[i].style.float && nodes[i].style.float != ('none') ||       (nodes[i].align && nodes[i].align != ('none'))) && (!nodes[i].style.position || nodes[i].style.position != 'relative'))) {	   if (nodes[i].id.substring(7,0) != 'ymarker') { nodes[i].style.position = 'relative'; }       }        i++; } }