http://www.mediawiki.org/wiki/Special:Code/MediaWiki/55014
Revision: 55014 Author: siebrand Date: 2009-08-14 12:46:04 +0000 (Fri, 14 Aug 2009) Log Message: ----------- * new style magic words support for Maps * raise a few settings out of the init method and use ParserFirstCallInit hook * reindent * bump version Modified Paths: -------------- trunk/extensions/Maps/Maps.php Added Paths: ----------- trunk/extensions/Maps/Maps.i18n.magic.php Added: trunk/extensions/Maps/Maps.i18n.magic.php =================================================================== --- trunk/extensions/Maps/Maps.i18n.magic.php (rev 0) +++ trunk/extensions/Maps/Maps.i18n.magic.php 2009-08-14 12:46:04 UTC (rev 55014) @@ -0,0 +1,13 @@ +<?php + +$magicWords = array(); + +$magicWords['en'] = array( + 'display_point' => array( 0, 'display_point' ), + 'display_points' => array( 0, 'display_points' ), + 'display_address' => array( 0, 'display_address' ), + 'display_addresses' => array( 0, 'display_addresses' ), + 'geocode' => array( 0, 'geocode' ), + 'geocodelat' => array( 0, 'geocodelat' ), + 'geocodelng' => array( 0, 'geocodelng' ), +); Property changes on: trunk/extensions/Maps/Maps.i18n.magic.php ___________________________________________________________________ Added: svn:keywords + Id Added: svn:eol-style + native Modified: trunk/extensions/Maps/Maps.php =================================================================== --- trunk/extensions/Maps/Maps.php 2009-08-14 12:25:26 UTC (rev 55013) +++ trunk/extensions/Maps/Maps.php 2009-08-14 12:46:04 UTC (rev 55014) @@ -13,9 +13,9 @@ /** * This documenation group collects source code files belonging to Maps. * - * Please do not use this group name for other code. If you have an extension to + * Please do not use this group name for other code. If you have an extension to * Maps, please use your own group defenition. - * + * * @defgroup Maps Maps */ @@ -23,7 +23,7 @@ die( 'Not an entry point.' ); } -define('Maps_VERSION', '0.3'); +define('Maps_VERSION', '0.4'); $egMapsScriptPath = $wgScriptPath . '/extensions/Maps'; $egMapsIP = $IP . '/extensions/Maps'; @@ -35,9 +35,10 @@ $wgExtensionFunctions[] = 'efMapsSetup'; $wgExtensionMessagesFiles['Maps'] = $egMapsIP . '/Maps.i18n.php'; +$wgExtensionMessagesFiles['MapsMagic'] = $egMapsIP . '/Maps.i18n.magic.php'; -$wgHooks['LanguageGetMagic'][] = 'efMapsFunctionMagic'; $wgHooks['AdminLinks'][] = 'efMapsAddToAdminLinks'; +$wgHooks['ParserFirstCallInit'][] = 'efMapsAddParserHooks'; // Autoload the general classes $wgAutoloadClasses['MapsMapFeature'] = $egMapsIP . '/Maps_MapFeature.php'; @@ -52,81 +53,79 @@ $egMapsServices = array(); $egMapsServices['googlemaps'] = array( - 'pf' => array('class' => 'MapsGoogleMaps', 'file' => 'GoogleMaps/Maps_GoogleMaps.php', 'local' => true), - 'classes' => array( - array('class' => 'MapsGoogleMapsUtils', 'file' => 'GoogleMaps/Maps_GoogleMapsUtils.php', 'local' => true) - ), - 'aliases' => array('google', 'googlemap', 'gmap', 'gmaps'), - 'parameters' => array( - 'type' => array('map-type', 'map type'), - 'types' => array('map-types', 'map types'), - 'earth' => array(), - 'autozoom' => array('auto zoom', 'mouse zoom', 'mousezoom'), - 'class' => array(), - 'style' => array() - ) - ); - + 'pf' => array('class' => 'MapsGoogleMaps', 'file' => 'GoogleMaps/Maps_GoogleMaps.php', 'local' => true), + 'classes' => array( + array('class' => 'MapsGoogleMapsUtils', 'file' => 'GoogleMaps/Maps_GoogleMapsUtils.php', 'local' => true) + ), + 'aliases' => array('google', 'googlemap', 'gmap', 'gmaps'), + 'parameters' => array( + 'type' => array('map-type', 'map type'), + 'types' => array('map-types', 'map types'), + 'earth' => array(), + 'autozoom' => array('auto zoom', 'mouse zoom', 'mousezoom'), + 'class' => array(), + 'style' => array() + ) +); + $egMapsServices['openlayers'] = array( - 'pf' => array('class' => 'MapsOpenLayers', 'file' => 'OpenLayers/Maps_OpenLayers.php', 'local' => true), - 'classes' => array( - array('class' => 'MapsOpenLayersUtils', 'file' => 'OpenLayers/Maps_OpenLayersUtils.php', 'local' => true) - ), - 'aliases' => array('layers', 'openlayer'), - 'parameters' => array( - 'layers' => array(), - 'baselayer' => array() - ) - ); - + 'pf' => array('class' => 'MapsOpenLayers', 'file' => 'OpenLayers/Maps_OpenLayers.php', 'local' => true), + 'classes' => array( + array('class' => 'MapsOpenLayersUtils', 'file' => 'OpenLayers/Maps_OpenLayersUtils.php', 'local' => true) + ), + 'aliases' => array('layers', 'openlayer'), + 'parameters' => array( + 'layers' => array(), + 'baselayer' => array() + ) +); + $egMapsServices['yahoomaps'] = array( - 'pf' => array('class' => 'MapsYahooMaps', 'file' => 'YahooMaps/Maps_YahooMaps.php', 'local' => true), - 'classes' => array( - array('class' => 'MapsYahooMapsUtils', 'file' => 'YahooMaps/Maps_YahooMapsUtils.php', 'local' => true) - ), - 'aliases' => array('yahoo', 'yahoomap', 'ymap', 'ymaps'), - 'parameters' => array( - 'type' => array('map-type'), - 'types' => array('map-types', 'map types'), - 'autozoom' => array('auto zoom', 'mouse zoom', 'mousezoom') - ) - ); - + 'pf' => array('class' => 'MapsYahooMaps', 'file' => 'YahooMaps/Maps_YahooMaps.php', 'local' => true), + 'classes' => array( + array('class' => 'MapsYahooMapsUtils', 'file' => 'YahooMaps/Maps_YahooMapsUtils.php', 'local' => true) + ), + 'aliases' => array('yahoo', 'yahoomap', 'ymap', 'ymaps'), + 'parameters' => array( + 'type' => array('map-type'), + 'types' => array('map-types', 'map types'), + 'autozoom' => array('auto zoom', 'mouse zoom', 'mousezoom') + ) +); + +$services_list = implode(', ', array_keys($egMapsServices)); + +$wgExtensionCredits['parserhook'][] = array( + 'path' => __FILE__, + 'name' => wfMsg('maps_name'), + 'version' => Maps_VERSION, + '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]"), + 'url' => 'http://www.mediawiki.org/wiki/Extension:Maps', + 'description' => wfMsg( 'maps_desc', $services_list ), + 'descriptionmsg' => wfMsg( 'maps_desc', $services_list ), +); + /** * Initialization function for the Maps extension */ function efMapsSetup() { - global $wgExtensionCredits, $wgOut, $wgAutoloadClasses; + global $wgOut, $wgAutoloadClasses; global $egMapsDefaultService, $egMapsAvailableServices, $egMapsServices, $egMapsScriptPath, $egMapsDefaultGeoService, $egMapsAvailableGeoServices, $egMapsIP; efMapsValidateGoogleMapsKey(); - + // Make sure the default service is one of the enabled ones $egMapsDefaultService = in_array($egMapsDefaultService, $egMapsAvailableServices) ? $egMapsDefaultService : $egMapsAvailableServices[0]; $egMapsDefaultGeoService = in_array($egMapsDefaultGeoService, $egMapsAvailableGeoServices) ? $egMapsDefaultGeoService : $egMapsAvailableGeoServices[0]; - - $services_list = implode(', ', array_keys($egMapsServices)); wfLoadExtensionMessages( 'Maps' ); - - $wgExtensionCredits['parserhook'][] = array( - 'path' => __FILE__, - 'name' => wfMsg('maps_name'), - 'version' => Maps_VERSION, - '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]"), - 'url' => 'http://www.mediawiki.org/wiki/Extension:Maps', - 'description' => wfMsg( 'maps_desc', $services_list ), - 'descriptionmsg' => wfMsg( 'maps_desc', $services_list ), - ); - efMapsAddParserHooks(); - $wgOut->addScriptFile($egMapsScriptPath . '/MapUtilityFunctions.js'); - + foreach ($egMapsServices as $serviceData) { $file = $serviceData['pf']['local'] ? $egMapsIP . '/' . $serviceData['pf']['file'] : $serviceData['pf']['file']; $wgAutoloadClasses[$serviceData['pf']['class']] = $file; - + foreach($serviceData['classes'] as $class) { $file = $class['local'] ? $egMapsIP . '/' . $class['file'] : $class['file']; $wgAutoloadClasses[$class['class']] = $file; @@ -135,48 +134,12 @@ } /** - * Adds the parser function hooks - */ -function efMapsAddParserHooks() { - global $wgParser; - - // A hooks to enable the '#display_point' and '#display_points' parser functions - $wgParser->setFunctionHook( 'display_point', array('MapsParserFunctions', 'displayPointRender') ); - $wgParser->setFunctionHook( 'display_points', array('MapsParserFunctions', 'displayPointsRender') ); - - // A hooks to enable the '#display_adress' and '#display_adresses' parser functions - $wgParser->setFunctionHook( 'display_address', array('MapsParserFunctions', 'displayAddressRender') ); - $wgParser->setFunctionHook( 'display_addresses', array('MapsParserFunctions', 'displayAddressesRender') ); - - // A hook to enable the geocoder parser functions - $wgParser->setFunctionHook( 'geocode', array('MapsGeocoder', 'renderGeocoder') ); - $wgParser->setFunctionHook( 'geocodelat' , array('MapsGeocoder', 'renderGeocoderLat') ); - $wgParser->setFunctionHook( 'geocodelng' , array('MapsGeocoder', 'renderGeocoderLng') ); -} - -/** - * Adds the magic words for the parser functions - */ -function efMapsFunctionMagic( &$magicWords, $langCode ) { - $magicWords['display_point'] = array( 0, 'display_point' ); - $magicWords['display_points'] = array( 0, 'display_points' ); - $magicWords['display_address'] = array( 0, 'display_address' ); - $magicWords['display_addresses'] = array( 0, 'display_addresses' ); - - $magicWords['geocode'] = array( 0, 'geocode' ); - $magicWords['geocodelat'] = array ( 0, 'geocodelat' ); - $magicWords['geocodelng'] = array ( 0, 'geocodelng' ); - - return true; // Unless we return true, other parser functions won't get loaded -} - -/** * This function ensures backward compatibility with Semantic Google Maps and other extensions * using $wgGoogleMapsKey instead of $egGoogleMapsKey. */ function efMapsValidateGoogleMapsKey() { global $egGoogleMapsKey, $wgGoogleMapsKey; - + if (strlen($egGoogleMapsKey) < 1 && isset($wgGoogleMapsKey)) $egGoogleMapsKey = $wgGoogleMapsKey; } @@ -185,15 +148,33 @@ */ function efMapsAddToAdminLinks(&$admin_links_tree) { // TODO: move the documentation link to another section - and make it non dependant on SMW? - $displaying_data_section = $admin_links_tree->getSection(wfMsg('smw_adminlinks_displayingdata')); - // Escape if SMW hasn't added links - if (is_null($displaying_data_section)) - return true; - $smw_docu_row = $displaying_data_section->getRow('smw'); - wfLoadExtensionMessages('Maps'); - $maps_docu_label = wfMsg('adminlinks_documentation', wfMsg('maps_name')); - $smw_docu_row->addItem(AlItem::newFromExternalLink("http://www.mediawiki.org/wiki/Extension:Maps", $maps_docu_label)); - return true; + $displaying_data_section = $admin_links_tree->getSection(wfMsg('smw_adminlinks_displayingdata')); + // Escape if SMW hasn't added links + if (is_null($displaying_data_section)) + return true; + $smw_docu_row = $displaying_data_section->getRow('smw'); + wfLoadExtensionMessages('Maps'); + $maps_docu_label = wfMsg('adminlinks_documentation', wfMsg('maps_name')); + $smw_docu_row->addItem(AlItem::newFromExternalLink("http://www.mediawiki.org/wiki/Extension:Maps", $maps_docu_label)); + return true; } +/** + * Add the parser function hooks + */ +function efMapsAddParserHooks( $parser ) { + // Hooks to enable the '#display_point' and '#display_points' parser functions + $parser->setFunctionHook( 'display_point', array('MapsParserFunctions', 'displayPointRender') ); + $parser->setFunctionHook( 'display_points', array('MapsParserFunctions', 'displayPointsRender') ); + // Hooks to enable the '#display_adress' and '#display_adresses' parser functions + $parser->setFunctionHook( 'display_address', array('MapsParserFunctions', 'displayAddressRender') ); + $parser->setFunctionHook( 'display_addresses', array('MapsParserFunctions', 'displayAddressesRender') ); + + // Hooks to enable the geocoder parser functions + $parser->setFunctionHook( 'geocode', array('MapsGeocoder', 'renderGeocoder') ); + $parser->setFunctionHook( 'geocodelat' , array('MapsGeocoder', 'renderGeocoderLat') ); + $parser->setFunctionHook( 'geocodelng' , array('MapsGeocoder', 'renderGeocoderLng') ); + + return true; +} _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs