Extension:YahooMaps/YahooMaps.php

 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.2.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" ); $wgParser->setHook( "yahoogeocoder", "renderYahooGeocoder" ); }

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 .= <<  This is the Yahoo Map area. If you are seeing this message and not a map, it means that an error has occurred because Yahoo can't be reached right now. Generally, this is either because your browser's proxy settings are incorrect or there is a network issue.  /*<![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 = ''; $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 .= <<<ENDMARKER // Add the marker Javascript var markerPoint = new YGeoPoint({$lat},{$lon}); var marker = new YMarker(markerPoint); marker.addLabel('${baseText}'); marker.addAutoExpand('${expandedText}'); map.addOverlay(marker); ENDMARKER;
 * 1) Create the map marker from a line of the format:
 * 2) latitude | longitude | Tag | Expanded (mouseover) text

return $output; }

function parseMarkerText(&$parser, $text) { $localParser = new Parser;
 * 1) Parse the wikitext markup for the marker text

# Parse the wikitext with a local parser $output = $localParser->parse($text, $parser->mTitle, $parser->mOptions, false)->getText; # Extract the body portion (which is the text) from the full document. However, this doesn't seem necessary any more (perhaps it's the local parser) #preg_match('/(?<=\)(.*)(?=\<\/body\>)/esm', $output, $matches); # Remove CR/LFs $output = preg_replace('/[\r\n]/esm', '', $output); $output = addcslashes($output, "\'\"");	return $output; }

function renderYahooGeocoder( $input, $argv, &$parser ) { global $wgScriptPath; $output = ''; $appId = getYahooAppId; //Create the Javascript for the geocoder $output .= <<   //<![CDATA[ var xmlhttp = false; var ymap; function callWS(target) { if(target !== ""){ var url = window.location.protocol + '//' + window.location.hostname + "${wgScriptPath}/extensions/YahooMaps/yproxy.php?" + encodeURI(target); xmlhttp.open('GET', url, true); xmlhttp.onreadystatechange = function { if(xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById('result').innerHTML = ''; parseResult(xmlhttp.responseText); } else { document.getElementById('result').innerHTML = "Loading..."; }	       };	        xmlhttp.send(null); }	   }	    function parseResult(parseMeString) { var parser = new DOMImplementation; var domDoc = parser.loadXML(parseMeString); if (domDoc == null) {	       alert("There was a problem parsing search results."); return; }	     var docRoot = domDoc.getDocumentElement; var items = docRoot.getElementsByTagName("Result"); for (var i =0; i < items.length; i++) { var lat = items.item(i).getElementsByTagName("Latitude").item(0).getFirstChild.getNodeValue; var lon = items.item(i).getElementsByTagName("Longitude").item(0).getFirstChild.getNodeValue; var marker = lat + " | " + lon + " | " + "TAG" + " | " + "POPUP DESCRIPTION"; var smart = " "; document.getElementById('result').innerHTML = smart; //And copy it to the clipboard in IE	         window.clipboardData.setData("Text", marker); }	   }	    function callGeocode { var query = document.getElementById("geoquery").value; var uri = "http://api.local.yahoo.com/MapsService/V1/geocode?appid={$appId}&location=" + query; callWS(uri); }		   if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest; xmlhttp.overrideMimeType('text/xml'); } else if (window.ActiveXObject) { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }   //]]>        Create marker 
 * 1) The callback function for converting the input text to HTML output

ENDGEOCODESCRIPT; return encode($output); }

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