r55248 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55247‎ | r55248 | r55249 >
Date:17:58, 18 August 2009
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Fixed error in version number.
Modified paths:
  • /tags/extensions/Maps/REL_0_3_2/Maps.php (added) (history)

Diff [purge]

Index: tags/extensions/Maps/REL_0_3_2/Maps.php
@@ -0,0 +1,208 @@
 2+<?php
 3+
 4+/**
 5+ * Initialization file for the Maps extension.
 6+ * Extension documentation: http://www.mediawiki.org/wiki/Extension:Maps
 7+ *
 8+ * @file Maps.php
 9+ * @ingroup Maps
 10+ *
 11+ * @author Jeroen De Dauw
 12+ */
 13+
 14+/**
 15+ * This documenation group collects source code files belonging to Maps.
 16+ *
 17+ * Please do not use this group name for other code. If you have an extension to
 18+ * Maps, please use your own group defenition.
 19+ *
 20+ * @defgroup Maps Maps
 21+ */
 22+
 23+if( !defined( 'MEDIAWIKI' ) ) {
 24+ die( 'Not an entry point.' );
 25+}
 26+
 27+define('Maps_VERSION', '0.3.2');
 28+
 29+$egMapsScriptPath = $wgScriptPath . '/extensions/Maps';
 30+$egMapsIP = $IP . '/extensions/Maps';
 31+$egMapsIncludePath = $wgServer . $egMapsScriptPath;
 32+
 33+// Include the settings file
 34+require_once($egMapsIP . '/Maps_Settings.php');
 35+
 36+$wgExtensionFunctions[] = 'efMapsSetup';
 37+
 38+$wgExtensionMessagesFiles['Maps'] = $egMapsIP . '/Maps.i18n.php';
 39+
 40+$wgHooks['LanguageGetMagic'][] = 'efMapsFunctionMagic';
 41+$wgHooks['AdminLinks'][] = 'efMapsAddToAdminLinks';
 42+
 43+// Autoload the general classes
 44+$wgAutoloadClasses['MapsMapFeature'] = $egMapsIP . '/Maps_MapFeature.php';
 45+$wgAutoloadClasses['MapsBaseMap'] = $egMapsIP . '/Maps_BaseMap.php';
 46+$wgAutoloadClasses['MapsMapper'] = $egMapsIP . '/Maps_Mapper.php';
 47+$wgAutoloadClasses['MapsParserFunctions'] = $egMapsIP . '/Maps_ParserFunctions.php';
 48+$wgAutoloadClasses['MapsUtils'] = $egMapsIP . '/Maps_Utils.php';
 49+$wgAutoloadClasses['MapsGeocoder'] = $egMapsIP . '/Maps_Geocoder.php';
 50+$wgAutoloadClasses['MapsBaseGeocoder'] = $egMapsIP . '/Maps_BaseGeocoder.php';
 51+
 52+// TODO: document
 53+// TODO: create checks to see what components are avalable for every
 54+// service to be used in available lists and setting of default service of each component
 55+// TODO: create feature hook system?
 56+if (empty($egMapsServices)) $egMapsServices = array();
 57+
 58+$egMapsServices['googlemaps'] = array(
 59+ 'pf' => array('class' => 'MapsGoogleMaps', 'file' => 'GoogleMaps/Maps_GoogleMaps.php', 'local' => true),
 60+ 'classes' => array(
 61+ array('class' => 'MapsGoogleMapsUtils', 'file' => 'GoogleMaps/Maps_GoogleMapsUtils.php', 'local' => true)
 62+ ),
 63+ 'aliases' => array('google', 'googlemap', 'gmap', 'gmaps'),
 64+ 'parameters' => array(
 65+ 'type' => array('map-type', 'map type'),
 66+ 'types' => array('map-types', 'map types'),
 67+ 'earth' => array(),
 68+ 'autozoom' => array('auto zoom', 'mouse zoom', 'mousezoom'),
 69+ 'class' => array(),
 70+ 'style' => array()
 71+ )
 72+ );
 73+
 74+$egMapsServices['openlayers'] = array(
 75+ 'pf' => array('class' => 'MapsOpenLayers', 'file' => 'OpenLayers/Maps_OpenLayers.php', 'local' => true),
 76+ 'classes' => array(
 77+ array('class' => 'MapsOpenLayersUtils', 'file' => 'OpenLayers/Maps_OpenLayersUtils.php', 'local' => true)
 78+ ),
 79+ 'aliases' => array('layers', 'openlayer'),
 80+ 'parameters' => array(
 81+ 'layers' => array(),
 82+ 'baselayer' => array()
 83+ )
 84+ );
 85+
 86+$egMapsServices['yahoomaps'] = array(
 87+ 'pf' => array('class' => 'MapsYahooMaps', 'file' => 'YahooMaps/Maps_YahooMaps.php', 'local' => true),
 88+ 'classes' => array(
 89+ array('class' => 'MapsYahooMapsUtils', 'file' => 'YahooMaps/Maps_YahooMapsUtils.php', 'local' => true)
 90+ ),
 91+ 'aliases' => array('yahoo', 'yahoomap', 'ymap', 'ymaps'),
 92+ 'parameters' => array(
 93+ 'type' => array('map-type'),
 94+ 'types' => array('map-types', 'map types'),
 95+ 'autozoom' => array('auto zoom', 'mouse zoom', 'mousezoom')
 96+ )
 97+ );
 98+
 99+/**
 100+ * Initialization function for the Maps extension
 101+ */
 102+function efMapsSetup() {
 103+ global $wgExtensionCredits, $wgOut, $wgAutoloadClasses, $IP;
 104+ global $egMapsDefaultService, $egMapsAvailableServices, $egMapsServices, $egMapsScriptPath, $egMapsDefaultGeoService, $egMapsAvailableGeoServices, $egMapsIP;
 105+
 106+ efMapsValidateGoogleMapsKey();
 107+
 108+ // Make sure the default service is one of the enabled ones
 109+ $egMapsDefaultService = in_array($egMapsDefaultService, $egMapsAvailableServices) ? $egMapsDefaultService : $egMapsAvailableServices[0];
 110+ $egMapsDefaultGeoService = in_array($egMapsDefaultGeoService, $egMapsAvailableGeoServices) ? $egMapsDefaultGeoService : $egMapsAvailableGeoServices[0];
 111+
 112+ $services_list = implode(', ', array_keys($egMapsServices));
 113+ $services_count = count( $egMapsServices );
 114+
 115+ wfLoadExtensionMessages( 'Maps' );
 116+
 117+ $wgExtensionCredits['parserhook'][] = array(
 118+ 'path' => __FILE__,
 119+ 'name' => wfMsg('maps_name'),
 120+ 'version' => Maps_VERSION,
 121+ 'author' => array("[http://bn2vs.com Jeroen De Dauw]", "[http://www.mediawiki.org/wiki/User:Yaron_Koren Yaron Koren]", "Robert Buzink", "Matt Williamson", "[http://www.sergeychernyshev.com Sergey Chernyshev]"),
 122+ 'url' => 'http://www.mediawiki.org/wiki/Extension:Maps',
 123+ 'description' => wfMsgExt( 'maps_desc', 'parsemag', $services_list, $services_count ),
 124+ 'descriptionmsg' => wfMsgExt( 'maps_desc', 'parsemag', $services_list, $services_count ),
 125+ );
 126+
 127+ efMapsAddParserHooks();
 128+
 129+ $wgOut->addScriptFile($egMapsScriptPath . '/MapUtilityFunctions.js');
 130+
 131+ foreach ($egMapsServices as $serviceData) {
 132+ if (array_key_exists('pf', $serviceData)) {
 133+ $file = $serviceData['pf']['local'] ? $egMapsIP . '/' . $serviceData['pf']['file'] : $IP . '/extensions/' . $serviceData['pf']['file'];
 134+ $wgAutoloadClasses[$serviceData['pf']['class']] = $file;
 135+ }
 136+
 137+ if (array_key_exists('classes', $serviceData)) {
 138+ foreach($serviceData['classes'] as $class) {
 139+ $file = $class['local'] ? $egMapsIP . '/' . $class['file'] : $IP . '/extensions/' . $class['file'];
 140+ $wgAutoloadClasses[$class['class']] = $file;
 141+ }
 142+ }
 143+
 144+ }
 145+}
 146+
 147+/**
 148+ * Adds the parser function hooks
 149+ */
 150+function efMapsAddParserHooks() {
 151+ global $wgParser;
 152+
 153+ // A hooks to enable the '#display_point' and '#display_points' parser functions
 154+ $wgParser->setFunctionHook( 'display_point', array('MapsParserFunctions', 'displayPointRender') );
 155+ $wgParser->setFunctionHook( 'display_points', array('MapsParserFunctions', 'displayPointsRender') );
 156+
 157+ // A hooks to enable the '#display_adress' and '#display_adresses' parser functions
 158+ $wgParser->setFunctionHook( 'display_address', array('MapsParserFunctions', 'displayAddressRender') );
 159+ $wgParser->setFunctionHook( 'display_addresses', array('MapsParserFunctions', 'displayAddressesRender') );
 160+
 161+ // A hook to enable the geocoder parser functions
 162+ $wgParser->setFunctionHook( 'geocode', array('MapsGeocoder', 'renderGeocoder') );
 163+ $wgParser->setFunctionHook( 'geocodelat' , array('MapsGeocoder', 'renderGeocoderLat') );
 164+ $wgParser->setFunctionHook( 'geocodelng' , array('MapsGeocoder', 'renderGeocoderLng') );
 165+}
 166+
 167+/**
 168+ * Adds the magic words for the parser functions
 169+ */
 170+function efMapsFunctionMagic( &$magicWords, $langCode ) {
 171+ $magicWords['display_point'] = array( 0, 'display_point' );
 172+ $magicWords['display_points'] = array( 0, 'display_points' );
 173+ $magicWords['display_address'] = array( 0, 'display_address' );
 174+ $magicWords['display_addresses'] = array( 0, 'display_addresses' );
 175+
 176+ $magicWords['geocode'] = array( 0, 'geocode' );
 177+ $magicWords['geocodelat'] = array ( 0, 'geocodelat' );
 178+ $magicWords['geocodelng'] = array ( 0, 'geocodelng' );
 179+
 180+ return true; // Unless we return true, other parser functions won't get loaded
 181+}
 182+
 183+/**
 184+ * This function ensures backward compatibility with Semantic Google Maps and other extensions
 185+ * using $wgGoogleMapsKey instead of $egGoogleMapsKey.
 186+ */
 187+function efMapsValidateGoogleMapsKey() {
 188+ global $egGoogleMapsKey, $wgGoogleMapsKey;
 189+
 190+ if (strlen($egGoogleMapsKey) < 1 && isset($wgGoogleMapsKey)) $egGoogleMapsKey = $wgGoogleMapsKey;
 191+}
 192+
 193+/**
 194+ * Adds a link to Admin Links page
 195+ */
 196+function efMapsAddToAdminLinks(&$admin_links_tree) {
 197+ // TODO: move the documentation link to another section - and make it non dependant on SMW?
 198+ $displaying_data_section = $admin_links_tree->getSection(wfMsg('smw_adminlinks_displayingdata'));
 199+ // Escape if SMW hasn't added links
 200+ if (is_null($displaying_data_section))
 201+ return true;
 202+ $smw_docu_row = $displaying_data_section->getRow('smw');
 203+ wfLoadExtensionMessages('Maps');
 204+ $maps_docu_label = wfMsg('adminlinks_documentation', wfMsg('maps_name'));
 205+ $smw_docu_row->addItem(AlItem::newFromExternalLink("http://www.mediawiki.org/wiki/Extension:Maps", $maps_docu_label));
 206+ return true;
 207+}
 208+
 209+

Status & tagging log