Index: trunk/extensions/Maps/Maps.php |
— | — | @@ -13,9 +13,9 @@ |
14 | 14 | /** |
15 | 15 | * This documenation group collects source code files belonging to Maps. |
16 | 16 | * |
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 |
18 | 18 | * Maps, please use your own group defenition. |
19 | | - * |
| 19 | + * |
20 | 20 | * @defgroup Maps Maps |
21 | 21 | */ |
22 | 22 | |
— | — | @@ -23,7 +23,7 @@ |
24 | 24 | die( 'Not an entry point.' ); |
25 | 25 | } |
26 | 26 | |
27 | | -define('Maps_VERSION', '0.4'); |
| 27 | +define('Maps_VERSION', '0.3'); |
28 | 28 | |
29 | 29 | $egMapsScriptPath = $wgScriptPath . '/extensions/Maps'; |
30 | 30 | $egMapsIP = $IP . '/extensions/Maps'; |
— | — | @@ -35,10 +35,9 @@ |
36 | 36 | $wgExtensionFunctions[] = 'efMapsSetup'; |
37 | 37 | |
38 | 38 | $wgExtensionMessagesFiles['Maps'] = $egMapsIP . '/Maps.i18n.php'; |
39 | | -$wgExtensionMessagesFiles['MapsMagic'] = $egMapsIP . '/Maps.i18n.magic.php'; |
40 | 39 | |
| 40 | +$wgHooks['LanguageGetMagic'][] = 'efMapsFunctionMagic'; |
41 | 41 | $wgHooks['AdminLinks'][] = 'efMapsAddToAdminLinks'; |
42 | | -$wgHooks['ParserFirstCallInit'][] = 'efMapsAddParserHooks'; |
43 | 42 | |
44 | 43 | // Autoload the general classes |
45 | 44 | $wgAutoloadClasses['MapsMapFeature'] = $egMapsIP . '/Maps_MapFeature.php'; |
— | — | @@ -53,79 +52,81 @@ |
54 | 53 | $egMapsServices = array(); |
55 | 54 | |
56 | 55 | $egMapsServices['googlemaps'] = array( |
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 | | - |
| 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 | + |
72 | 71 | $egMapsServices['openlayers'] = array( |
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 | | - |
| 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 | + |
84 | 83 | $egMapsServices['yahoomaps'] = array( |
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 | | - |
| 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 | + |
109 | 96 | /** |
110 | 97 | * Initialization function for the Maps extension |
111 | 98 | */ |
112 | 99 | function efMapsSetup() { |
113 | | - global $wgOut, $wgAutoloadClasses; |
| 100 | + global $wgExtensionCredits, $wgOut, $wgAutoloadClasses; |
114 | 101 | global $egMapsDefaultService, $egMapsAvailableServices, $egMapsServices, $egMapsScriptPath, $egMapsDefaultGeoService, $egMapsAvailableGeoServices, $egMapsIP; |
115 | 102 | |
116 | 103 | efMapsValidateGoogleMapsKey(); |
117 | | - |
| 104 | + |
118 | 105 | // Make sure the default service is one of the enabled ones |
119 | 106 | $egMapsDefaultService = in_array($egMapsDefaultService, $egMapsAvailableServices) ? $egMapsDefaultService : $egMapsAvailableServices[0]; |
120 | 107 | $egMapsDefaultGeoService = in_array($egMapsDefaultGeoService, $egMapsAvailableGeoServices) ? $egMapsDefaultGeoService : $egMapsAvailableGeoServices[0]; |
| 108 | + |
| 109 | + $services_list = implode(', ', array_keys($egMapsServices)); |
121 | 110 | |
122 | 111 | 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 | + ); |
123 | 122 | |
| 123 | + efMapsAddParserHooks(); |
| 124 | + |
124 | 125 | $wgOut->addScriptFile($egMapsScriptPath . '/MapUtilityFunctions.js'); |
125 | | - |
| 126 | + |
126 | 127 | foreach ($egMapsServices as $serviceData) { |
127 | 128 | $file = $serviceData['pf']['local'] ? $egMapsIP . '/' . $serviceData['pf']['file'] : $serviceData['pf']['file']; |
128 | 129 | $wgAutoloadClasses[$serviceData['pf']['class']] = $file; |
129 | | - |
| 130 | + |
130 | 131 | foreach($serviceData['classes'] as $class) { |
131 | 132 | $file = $class['local'] ? $egMapsIP . '/' . $class['file'] : $class['file']; |
132 | 133 | $wgAutoloadClasses[$class['class']] = $file; |
— | — | @@ -134,12 +135,48 @@ |
135 | 136 | } |
136 | 137 | |
137 | 138 | /** |
| 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 | +/** |
138 | 175 | * This function ensures backward compatibility with Semantic Google Maps and other extensions |
139 | 176 | * using $wgGoogleMapsKey instead of $egGoogleMapsKey. |
140 | 177 | */ |
141 | 178 | function efMapsValidateGoogleMapsKey() { |
142 | 179 | global $egGoogleMapsKey, $wgGoogleMapsKey; |
143 | | - |
| 180 | + |
144 | 181 | if (strlen($egGoogleMapsKey) < 1 && isset($wgGoogleMapsKey)) $egGoogleMapsKey = $wgGoogleMapsKey; |
145 | 182 | } |
146 | 183 | |
— | — | @@ -148,33 +185,15 @@ |
149 | 186 | */ |
150 | 187 | function efMapsAddToAdminLinks(&$admin_links_tree) { |
151 | 188 | // TODO: move the documentation link to another section - and make it non dependant on SMW? |
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; |
| 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; |
161 | 198 | } |
162 | 199 | |
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') ); |
170 | 200 | |
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 | | -} |