Extension:Coordinate

From MediaWiki.org

Jump to: navigation, search

         

Manual on MediaWiki Extensions
List of MediaWiki Extensions
Crystal Clear action run.png
Coordinate

Release status: beta

Implementation  Parser function
Description Convert geographical coordinates written in decimal degrees format to degrees format using a parser function.
Author(s)  user:buzink
Last Version  1.00
MediaWiki  1.82, 1.10
License No license specified
Download see below

check usage (experimental)

Contents

[edit] What can this extension do?

Convert geographical coordinates written in decimal degrees format to degrees format using a parser function. The function only works for N/E locations, but can be easily extended.

This can be especially useful in combination with the Geographic Coordinate attribute type of the semantic mediawiki extension.

[edit] Usage

({{#coordinate:lat|5.6907811760902405° E, 50.851378111532355° N}}, {{#coordinate:lon|5.6907811760902405° E, 50.851378111532355° N}})

becomes

(5.69078117609, 50.8513781115)

[edit] Installation

[edit] Upload file coordinate.php

<?php
 
# Define a setup function
$wgExtensionFunctions[] = 'wfExampleParserFunction_Setup';
# Add a hook to initialise the magic word
$wgHooks['LanguageGetMagic'][]       = 'wfExampleParserFunction_Magic';
 
function wfExampleParserFunction_Setup() {
        global $wgParser;
        # Set a function hook associating the "example" magic word with our function
        $wgParser->setFunctionHook( 'coordinate', 'wfExampleParserFunction_Render' );
}
 
function wfExampleParserFunction_Magic( &$magicWords, $langCode ) {
        # Add the magic word
        # The first array element is case sensitive, in this case it is not case sensitive
        # All remaining elements are synonyms for our parser function
        $magicWords['coordinate'] = array( 0, 'coordinate' );
        # unless we return true, other parser functions extensions won't get loaded.
        return true;
}
 
function wfExampleParserFunction_Render( &$parser, $param1 = '', $param2 = '' ) {
        # The parser function itself
        # The input parameters are wikitext with templates expanded
        # The output should be wikitext too
		
		$coordinates = preg_split("/,/", $param2);
 
		$lat = floatval($coordinates[0]);
		$lon = floatval($coordinates[1]);
 
		switch ($param1) {
			case 'lat':
				return $lat;
			case 'lon':
				return $lon;
		}		
}

[edit] Changes to LocalSettings.php

require_once("$IP/extensions/coordinate.php");