r55014 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55013‎ | r55014 | r55015 >
Date:12:46, 14 August 2009
Author:siebrand
Status:reverted
Tags:
Comment:
* 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.i18n.magic.php (added) (history)
  • /trunk/extensions/Maps/Maps.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/Maps.i18n.magic.php
@@ -0,0 +1,13 @@
 2+<?php
 3+
 4+$magicWords = array();
 5+
 6+$magicWords['en'] = array(
 7+ 'display_point' => array( 0, 'display_point' ),
 8+ 'display_points' => array( 0, 'display_points' ),
 9+ 'display_address' => array( 0, 'display_address' ),
 10+ 'display_addresses' => array( 0, 'display_addresses' ),
 11+ 'geocode' => array( 0, 'geocode' ),
 12+ 'geocodelat' => array( 0, 'geocodelat' ),
 13+ 'geocodelng' => array( 0, 'geocodelng' ),
 14+);
Property changes on: trunk/extensions/Maps/Maps.i18n.magic.php
___________________________________________________________________
Name: svn:eol-style
115 + native
Name: svn:keywords
216 + Id
Index: trunk/extensions/Maps/Maps.php
@@ -13,9 +13,9 @@
1414 /**
1515 * This documenation group collects source code files belonging to Maps.
1616 *
17 - * Please do not use this group name for other code. If you have an extension to
 17+ * Please do not use this group name for other code. If you have an extension to
1818 * Maps, please use your own group defenition.
19 - *
 19+ *
2020 * @defgroup Maps Maps
2121 */
2222
@@ -23,7 +23,7 @@
2424 die( 'Not an entry point.' );
2525 }
2626
27 -define('Maps_VERSION', '0.3');
 27+define('Maps_VERSION', '0.4');
2828
2929 $egMapsScriptPath = $wgScriptPath . '/extensions/Maps';
3030 $egMapsIP = $IP . '/extensions/Maps';
@@ -35,9 +35,10 @@
3636 $wgExtensionFunctions[] = 'efMapsSetup';
3737
3838 $wgExtensionMessagesFiles['Maps'] = $egMapsIP . '/Maps.i18n.php';
 39+$wgExtensionMessagesFiles['MapsMagic'] = $egMapsIP . '/Maps.i18n.magic.php';
3940
40 -$wgHooks['LanguageGetMagic'][] = 'efMapsFunctionMagic';
4141 $wgHooks['AdminLinks'][] = 'efMapsAddToAdminLinks';
 42+$wgHooks['ParserFirstCallInit'][] = 'efMapsAddParserHooks';
4243
4344 // Autoload the general classes
4445 $wgAutoloadClasses['MapsMapFeature'] = $egMapsIP . '/Maps_MapFeature.php';
@@ -52,81 +53,79 @@
5354 $egMapsServices = array();
5455
5556 $egMapsServices['googlemaps'] = array(
56 - 'pf' => array('class' => 'MapsGoogleMaps', 'file' => 'GoogleMaps/Maps_GoogleMaps.php', 'local' => true),
57 - 'classes' => array(
58 - array('class' => 'MapsGoogleMapsUtils', 'file' => 'GoogleMaps/Maps_GoogleMapsUtils.php', 'local' => true)
59 - ),
60 - 'aliases' => array('google', 'googlemap', 'gmap', 'gmaps'),
61 - 'parameters' => array(
62 - 'type' => array('map-type', 'map type'),
63 - 'types' => array('map-types', 'map types'),
64 - 'earth' => array(),
65 - 'autozoom' => array('auto zoom', 'mouse zoom', 'mousezoom'),
66 - 'class' => array(),
67 - 'style' => array()
68 - )
69 - );
70 -
 57+ 'pf' => array('class' => 'MapsGoogleMaps', 'file' => 'GoogleMaps/Maps_GoogleMaps.php', 'local' => true),
 58+ 'classes' => array(
 59+ array('class' => 'MapsGoogleMapsUtils', 'file' => 'GoogleMaps/Maps_GoogleMapsUtils.php', 'local' => true)
 60+ ),
 61+ 'aliases' => array('google', 'googlemap', 'gmap', 'gmaps'),
 62+ 'parameters' => array(
 63+ 'type' => array('map-type', 'map type'),
 64+ 'types' => array('map-types', 'map types'),
 65+ 'earth' => array(),
 66+ 'autozoom' => array('auto zoom', 'mouse zoom', 'mousezoom'),
 67+ 'class' => array(),
 68+ 'style' => array()
 69+ )
 70+);
 71+
7172 $egMapsServices['openlayers'] = array(
72 - 'pf' => array('class' => 'MapsOpenLayers', 'file' => 'OpenLayers/Maps_OpenLayers.php', 'local' => true),
73 - 'classes' => array(
74 - array('class' => 'MapsOpenLayersUtils', 'file' => 'OpenLayers/Maps_OpenLayersUtils.php', 'local' => true)
75 - ),
76 - 'aliases' => array('layers', 'openlayer'),
77 - 'parameters' => array(
78 - 'layers' => array(),
79 - 'baselayer' => array()
80 - )
81 - );
82 -
 73+ 'pf' => array('class' => 'MapsOpenLayers', 'file' => 'OpenLayers/Maps_OpenLayers.php', 'local' => true),
 74+ 'classes' => array(
 75+ array('class' => 'MapsOpenLayersUtils', 'file' => 'OpenLayers/Maps_OpenLayersUtils.php', 'local' => true)
 76+ ),
 77+ 'aliases' => array('layers', 'openlayer'),
 78+ 'parameters' => array(
 79+ 'layers' => array(),
 80+ 'baselayer' => array()
 81+ )
 82+);
 83+
8384 $egMapsServices['yahoomaps'] = array(
84 - 'pf' => array('class' => 'MapsYahooMaps', 'file' => 'YahooMaps/Maps_YahooMaps.php', 'local' => true),
85 - 'classes' => array(
86 - array('class' => 'MapsYahooMapsUtils', 'file' => 'YahooMaps/Maps_YahooMapsUtils.php', 'local' => true)
87 - ),
88 - 'aliases' => array('yahoo', 'yahoomap', 'ymap', 'ymaps'),
89 - 'parameters' => array(
90 - 'type' => array('map-type'),
91 - 'types' => array('map-types', 'map types'),
92 - 'autozoom' => array('auto zoom', 'mouse zoom', 'mousezoom')
93 - )
94 - );
95 -
 85+ 'pf' => array('class' => 'MapsYahooMaps', 'file' => 'YahooMaps/Maps_YahooMaps.php', 'local' => true),
 86+ 'classes' => array(
 87+ array('class' => 'MapsYahooMapsUtils', 'file' => 'YahooMaps/Maps_YahooMapsUtils.php', 'local' => true)
 88+ ),
 89+ 'aliases' => array('yahoo', 'yahoomap', 'ymap', 'ymaps'),
 90+ 'parameters' => array(
 91+ 'type' => array('map-type'),
 92+ 'types' => array('map-types', 'map types'),
 93+ 'autozoom' => array('auto zoom', 'mouse zoom', 'mousezoom')
 94+ )
 95+);
 96+
 97+$services_list = implode(', ', array_keys($egMapsServices));
 98+
 99+$wgExtensionCredits['parserhook'][] = array(
 100+ 'path' => __FILE__,
 101+ 'name' => wfMsg('maps_name'),
 102+ 'version' => Maps_VERSION,
 103+ '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]"),
 104+ 'url' => 'http://www.mediawiki.org/wiki/Extension:Maps',
 105+ 'description' => wfMsg( 'maps_desc', $services_list ),
 106+ 'descriptionmsg' => wfMsg( 'maps_desc', $services_list ),
 107+);
 108+
96109 /**
97110 * Initialization function for the Maps extension
98111 */
99112 function efMapsSetup() {
100 - global $wgExtensionCredits, $wgOut, $wgAutoloadClasses;
 113+ global $wgOut, $wgAutoloadClasses;
101114 global $egMapsDefaultService, $egMapsAvailableServices, $egMapsServices, $egMapsScriptPath, $egMapsDefaultGeoService, $egMapsAvailableGeoServices, $egMapsIP;
102115
103116 efMapsValidateGoogleMapsKey();
104 -
 117+
105118 // Make sure the default service is one of the enabled ones
106119 $egMapsDefaultService = in_array($egMapsDefaultService, $egMapsAvailableServices) ? $egMapsDefaultService : $egMapsAvailableServices[0];
107120 $egMapsDefaultGeoService = in_array($egMapsDefaultGeoService, $egMapsAvailableGeoServices) ? $egMapsDefaultGeoService : $egMapsAvailableGeoServices[0];
108 -
109 - $services_list = implode(', ', array_keys($egMapsServices));
110121
111122 wfLoadExtensionMessages( 'Maps' );
112 -
113 - $wgExtensionCredits['parserhook'][] = array(
114 - 'path' => __FILE__,
115 - 'name' => wfMsg('maps_name'),
116 - 'version' => Maps_VERSION,
117 - '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]"),
118 - 'url' => 'http://www.mediawiki.org/wiki/Extension:Maps',
119 - 'description' => wfMsg( 'maps_desc', $services_list ),
120 - 'descriptionmsg' => wfMsg( 'maps_desc', $services_list ),
121 - );
122123
123 - efMapsAddParserHooks();
124 -
125124 $wgOut->addScriptFile($egMapsScriptPath . '/MapUtilityFunctions.js');
126 -
 125+
127126 foreach ($egMapsServices as $serviceData) {
128127 $file = $serviceData['pf']['local'] ? $egMapsIP . '/' . $serviceData['pf']['file'] : $serviceData['pf']['file'];
129128 $wgAutoloadClasses[$serviceData['pf']['class']] = $file;
130 -
 129+
131130 foreach($serviceData['classes'] as $class) {
132131 $file = $class['local'] ? $egMapsIP . '/' . $class['file'] : $class['file'];
133132 $wgAutoloadClasses[$class['class']] = $file;
@@ -135,48 +134,12 @@
136135 }
137136
138137 /**
139 - * Adds the parser function hooks
140 - */
141 -function efMapsAddParserHooks() {
142 - global $wgParser;
143 -
144 - // A hooks to enable the '#display_point' and '#display_points' parser functions
145 - $wgParser->setFunctionHook( 'display_point', array('MapsParserFunctions', 'displayPointRender') );
146 - $wgParser->setFunctionHook( 'display_points', array('MapsParserFunctions', 'displayPointsRender') );
147 -
148 - // A hooks to enable the '#display_adress' and '#display_adresses' parser functions
149 - $wgParser->setFunctionHook( 'display_address', array('MapsParserFunctions', 'displayAddressRender') );
150 - $wgParser->setFunctionHook( 'display_addresses', array('MapsParserFunctions', 'displayAddressesRender') );
151 -
152 - // A hook to enable the geocoder parser functions
153 - $wgParser->setFunctionHook( 'geocode', array('MapsGeocoder', 'renderGeocoder') );
154 - $wgParser->setFunctionHook( 'geocodelat' , array('MapsGeocoder', 'renderGeocoderLat') );
155 - $wgParser->setFunctionHook( 'geocodelng' , array('MapsGeocoder', 'renderGeocoderLng') );
156 -}
157 -
158 -/**
159 - * Adds the magic words for the parser functions
160 - */
161 -function efMapsFunctionMagic( &$magicWords, $langCode ) {
162 - $magicWords['display_point'] = array( 0, 'display_point' );
163 - $magicWords['display_points'] = array( 0, 'display_points' );
164 - $magicWords['display_address'] = array( 0, 'display_address' );
165 - $magicWords['display_addresses'] = array( 0, 'display_addresses' );
166 -
167 - $magicWords['geocode'] = array( 0, 'geocode' );
168 - $magicWords['geocodelat'] = array ( 0, 'geocodelat' );
169 - $magicWords['geocodelng'] = array ( 0, 'geocodelng' );
170 -
171 - return true; // Unless we return true, other parser functions won't get loaded
172 -}
173 -
174 -/**
175138 * This function ensures backward compatibility with Semantic Google Maps and other extensions
176139 * using $wgGoogleMapsKey instead of $egGoogleMapsKey.
177140 */
178141 function efMapsValidateGoogleMapsKey() {
179142 global $egGoogleMapsKey, $wgGoogleMapsKey;
180 -
 143+
181144 if (strlen($egGoogleMapsKey) < 1 && isset($wgGoogleMapsKey)) $egGoogleMapsKey = $wgGoogleMapsKey;
182145 }
183146
@@ -185,15 +148,33 @@
186149 */
187150 function efMapsAddToAdminLinks(&$admin_links_tree) {
188151 // TODO: move the documentation link to another section - and make it non dependant on SMW?
189 - $displaying_data_section = $admin_links_tree->getSection(wfMsg('smw_adminlinks_displayingdata'));
190 - // Escape if SMW hasn't added links
191 - if (is_null($displaying_data_section))
192 - return true;
193 - $smw_docu_row = $displaying_data_section->getRow('smw');
194 - wfLoadExtensionMessages('Maps');
195 - $maps_docu_label = wfMsg('adminlinks_documentation', wfMsg('maps_name'));
196 - $smw_docu_row->addItem(AlItem::newFromExternalLink("http://www.mediawiki.org/wiki/Extension:Maps", $maps_docu_label));
197 - return true;
 152+ $displaying_data_section = $admin_links_tree->getSection(wfMsg('smw_adminlinks_displayingdata'));
 153+ // Escape if SMW hasn't added links
 154+ if (is_null($displaying_data_section))
 155+ return true;
 156+ $smw_docu_row = $displaying_data_section->getRow('smw');
 157+ wfLoadExtensionMessages('Maps');
 158+ $maps_docu_label = wfMsg('adminlinks_documentation', wfMsg('maps_name'));
 159+ $smw_docu_row->addItem(AlItem::newFromExternalLink("http://www.mediawiki.org/wiki/Extension:Maps", $maps_docu_label));
 160+ return true;
198161 }
199162
 163+/**
 164+ * Add the parser function hooks
 165+ */
 166+function efMapsAddParserHooks( $parser ) {
 167+ // Hooks to enable the '#display_point' and '#display_points' parser functions
 168+ $parser->setFunctionHook( 'display_point', array('MapsParserFunctions', 'displayPointRender') );
 169+ $parser->setFunctionHook( 'display_points', array('MapsParserFunctions', 'displayPointsRender') );
200170
 171+ // Hooks to enable the '#display_adress' and '#display_adresses' parser functions
 172+ $parser->setFunctionHook( 'display_address', array('MapsParserFunctions', 'displayAddressRender') );
 173+ $parser->setFunctionHook( 'display_addresses', array('MapsParserFunctions', 'displayAddressesRender') );
 174+
 175+ // Hooks to enable the geocoder parser functions
 176+ $parser->setFunctionHook( 'geocode', array('MapsGeocoder', 'renderGeocoder') );
 177+ $parser->setFunctionHook( 'geocodelat' , array('MapsGeocoder', 'renderGeocoderLat') );
 178+ $parser->setFunctionHook( 'geocodelng' , array('MapsGeocoder', 'renderGeocoderLng') );
 179+
 180+ return true;
 181+}

Follow-up revisions

RevisionCommit summaryAuthorDate
r55017Revert changes from r55014 in Maps.php at request of Jeroen. He was planning ...siebrand14:11, 14 August 2009

Status & tagging log