PageRenderTime 55ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/extensions/Maps/Maps.php

https://github.com/ChuguluGames/mediawiki-svn
PHP | 314 lines | 182 code | 62 blank | 70 comment | 6 complexity | 595c96d516c6506fe6c51460f292fa49 MD5 | raw file
  1. <?php
  2. /**
  3. * Initialization file for the Maps extension.
  4. *
  5. * On MediaWiki.org: http://www.mediawiki.org/wiki/Extension:Maps
  6. * Official documentation: http://mapping.referata.com/wiki/Maps
  7. * Examples/demo's: http://mapping.referata.com/wiki/Maps_examples
  8. *
  9. * @file Maps.php
  10. * @ingroup Maps
  11. *
  12. * @licence GNU GPL v3
  13. * @author Jeroen De Dauw < jeroendedauw@gmail.com >
  14. */
  15. /**
  16. * This documenation group collects source code files belonging to Maps.
  17. *
  18. * Please do not use this group name for other code. If you have an extension to
  19. * Maps, please use your own group definition.
  20. *
  21. * @defgroup Maps Maps
  22. */
  23. if ( !defined( 'MEDIAWIKI' ) ) {
  24. die( 'Not an entry point.' );
  25. }
  26. if ( version_compare( $wgVersion, '1.17', '<' ) ) {
  27. die( '<b>Error:</b> This version of Maps requires MediaWiki 1.17 or above; use Maps 0.7.x for older versions.' );
  28. }
  29. // Include the Validator extension if that hasn't been done yet, since it's required for Maps to work.
  30. if ( !defined( 'Validator_VERSION' ) ) {
  31. @include_once( dirname( __FILE__ ) . '/../Validator/Validator.php' );
  32. }
  33. // Only initialize the extension when all dependencies are present.
  34. if ( ! defined( 'Validator_VERSION' ) ) {
  35. die( '<b>Error:</b> You need to have <a href="http://www.mediawiki.org/wiki/Extension:Validator">Validator</a> installed in order to use <a href="http://www.mediawiki.org/wiki/Extension:Maps">Maps</a>.<br />' );
  36. }
  37. define( 'Maps_VERSION', '1.0.3 alpha' );
  38. $wgExtensionCredits['parserhook'][] = array(
  39. 'path' => __FILE__,
  40. 'name' => 'Maps',
  41. 'version' => Maps_VERSION,
  42. 'author' => array(
  43. '[http://www.mediawiki.org/wiki/User:Jeroen_De_Dauw Jeroen De Dauw]'
  44. ),
  45. 'url' => 'http://www.mediawiki.org/wiki/Extension:Maps',
  46. 'descriptionmsg' => 'maps-desc'
  47. );
  48. // The different coordinate notations.
  49. define( 'Maps_COORDS_FLOAT', 'float' );
  50. define( 'Maps_COORDS_DMS', 'dms' );
  51. define( 'Maps_COORDS_DM', 'dm' );
  52. define( 'Maps_COORDS_DD', 'dd' );
  53. $egMapsScriptPath = ( $wgExtensionAssetsPath === false ? $wgScriptPath . '/extensions' : $wgExtensionAssetsPath ) . '/Maps';
  54. $egMapsDir = dirname( __FILE__ ) . '/';
  55. $egMapsStyleVersion = $wgStyleVersion . '-' . Maps_VERSION;
  56. $wgAutoloadClasses['MapsHooks'] = dirname( __FILE__ ) . '/Maps.hooks.php';
  57. // Autoload the "includes/" classes and interfaces.
  58. $incDir = dirname( __FILE__ ) . '/includes/';
  59. $wgAutoloadClasses['MapsMapper'] = $incDir . 'Maps_Mapper.php';
  60. $wgAutoloadClasses['MapsCoordinateParser'] = $incDir . 'Maps_CoordinateParser.php';
  61. $wgAutoloadClasses['MapsDistanceParser'] = $incDir . 'Maps_DistanceParser.php';
  62. $wgAutoloadClasses['MapsGeoFunctions'] = $incDir . 'Maps_GeoFunctions.php';
  63. $wgAutoloadClasses['MapsGeocoders'] = $incDir . 'Maps_Geocoders.php';
  64. $wgAutoloadClasses['MapsGeocoder'] = $incDir . 'Maps_Geocoder.php';
  65. $wgAutoloadClasses['MapsKMLFormatter'] = $incDir . 'Maps_KMLFormatter.php';
  66. $wgAutoloadClasses['MapsLayer'] = $incDir . 'Maps_Layer.php';
  67. $wgAutoloadClasses['MapsLayerPage'] = $incDir . 'Maps_LayerPage.php';
  68. $wgAutoloadClasses['MapsLayers'] = $incDir . 'Maps_Layers.php';
  69. $wgAutoloadClasses['MapsLocation'] = $incDir . 'Maps_Location.php';
  70. $wgAutoloadClasses['iMappingService'] = $incDir . 'iMappingService.php';
  71. $wgAutoloadClasses['MapsMappingServices'] = $incDir . 'Maps_MappingServices.php';
  72. $wgAutoloadClasses['MapsMappingService'] = $incDir . 'Maps_MappingService.php';
  73. $wgAutoloadClasses['ApiGeocode'] = $incDir . 'api/ApiGeocode.php';
  74. // Autoload the "includes/criteria/" classes.
  75. $criDir = $incDir . 'criteria/';
  76. $wgAutoloadClasses['CriterionIsDistance'] = $criDir . 'CriterionIsDistance.php';
  77. $wgAutoloadClasses['CriterionIsImage'] = $criDir . 'CriterionIsImage.php';
  78. $wgAutoloadClasses['CriterionIsLocation'] = $criDir . 'CriterionIsLocation.php';
  79. $wgAutoloadClasses['CriterionMapDimension'] = $criDir . 'CriterionMapDimension.php';
  80. $wgAutoloadClasses['CriterionMapLayer'] = $criDir . 'CriterionMapLayer.php';
  81. unset( $criDir );
  82. // Autoload the "includes/features/" classes.
  83. $ftDir = $incDir . '/features/';
  84. $wgAutoloadClasses['MapsBaseMap'] = $ftDir . 'Maps_BaseMap.php';
  85. $wgAutoloadClasses['MapsBasePointMap'] = $ftDir . 'Maps_BasePointMap.php';
  86. unset( $ftDir );
  87. // Autoload the "includes/geocoders/" classes.
  88. $geoDir = $incDir . 'geocoders/';
  89. $wgAutoloadClasses['MapsGeonamesGeocoder'] = $geoDir . 'Maps_GeonamesGeocoder.php';
  90. $wgAutoloadClasses['MapsGeonamesOldGeocoder'] = $geoDir . 'Maps_GeonamesOldGeocoder.php';
  91. $wgAutoloadClasses['MapsGoogleGeocoder'] = $geoDir . 'Maps_GoogleGeocoder.php';
  92. $wgAutoloadClasses['MapsYahooGeocoder'] = $geoDir . 'Maps_YahooGeocoder.php';
  93. unset( $geoDir );
  94. // Autoload the "includes/layers/" classes.
  95. $lyrDir = $incDir . 'layers/';
  96. $wgAutoloadClasses['MapsImageLayer'] = $lyrDir . 'Maps_ImageLayer.php';
  97. $wgAutoloadClasses['MapsKMLLayer'] = $lyrDir . 'Maps_KMLLayer.php';
  98. unset( $lyrDir );
  99. // Autoload the "includes/manipulations/" classes.
  100. $manDir = $incDir . 'manipulations/';
  101. $wgAutoloadClasses['MapsParamDimension'] = $manDir . 'Maps_ParamDimension.php';
  102. $wgAutoloadClasses['MapsParamFile'] = $manDir . 'Maps_ParamFile.php';
  103. $wgAutoloadClasses['MapsParamGeoService'] = $manDir . 'Maps_ParamGeoService.php';
  104. $wgAutoloadClasses['MapsParamLocation'] = $manDir . 'Maps_ParamLocation.php';
  105. $wgAutoloadClasses['MapsParamService'] = $manDir . 'Maps_ParamService.php';
  106. $wgAutoloadClasses['MapsParamZoom'] = $manDir . 'Maps_ParamZoom.php';
  107. unset( $manDir );
  108. // Autoload the "includes/parserHooks/" classes.
  109. $phDir = $incDir . '/parserHooks/';
  110. $wgAutoloadClasses['MapsCoordinates'] = $phDir . 'Maps_Coordinates.php';
  111. $wgAutoloadClasses['MapsDisplayMap'] = $phDir . 'Maps_DisplayMap.php';
  112. $wgAutoloadClasses['MapsDisplayPoint'] = $phDir . 'Maps_DisplayPoint.php';
  113. $wgAutoloadClasses['MapsDistance'] = $phDir . 'Maps_Distance.php';
  114. $wgAutoloadClasses['MapsFinddestination'] = $phDir . 'Maps_Finddestination.php';
  115. $wgAutoloadClasses['MapsGeocode'] = $phDir . 'Maps_Geocode.php';
  116. $wgAutoloadClasses['MapsGeodistance'] = $phDir . 'Maps_Geodistance.php';
  117. $wgAutoloadClasses['MapsMapsDoc'] = $phDir . 'Maps_MapsDoc.php';
  118. unset( $phDir );
  119. unset( $incDir );
  120. $wgAPIModules['geocode'] = 'ApiGeocode';
  121. $wgExtensionMessagesFiles['MapsMagic'] = $egMapsDir . 'Maps.i18n.magic.php';
  122. $wgExtensionMessagesFiles['Maps'] = $egMapsDir . 'Maps.i18n.php';
  123. // Register the initialization function of Maps.
  124. $wgExtensionFunctions[] = 'efMapsSetup';
  125. // Since 0.2
  126. $wgHooks['AdminLinks'][] = 'MapsHooks::addToAdminLinks';
  127. // Since 0.6.5
  128. $wgHooks['UnitTestsList'][] = 'MapsHooks::registerUnitTests';
  129. // Since 0.7.1
  130. $wgHooks['ArticleFromTitle'][] = 'MapsHooks::onArticleFromTitle';
  131. // Since 1.0
  132. $wgHooks['MakeGlobalVariablesScript'][] = 'MapsHooks::onMakeGlobalVariablesScript';
  133. $egMapsFeatures = array();
  134. $egMapsFeatures['pf'][] = 'MapsDisplayMap::initialize';
  135. $egMapsFeatures['pf'][] = 'MapsDisplayPoint::initialize';
  136. # Parser hooks
  137. # Required for #coordinates.
  138. $wgHooks['ParserFirstCallInit'][] = 'MapsCoordinates::staticInit';
  139. $wgHooks['LanguageGetMagic'][] = 'MapsCoordinates::staticMagic';
  140. # Required for #display_map.
  141. $wgHooks['ParserFirstCallInit'][] = 'MapsDisplayMap::staticInit';
  142. $wgHooks['LanguageGetMagic'][] = 'MapsDisplayMap::staticMagic';
  143. # Required for #display_point.
  144. $wgHooks['ParserFirstCallInit'][] = 'MapsDisplayPoint::staticInit';
  145. $wgHooks['LanguageGetMagic'][] = 'MapsDisplayPoint::staticMagic';
  146. # Required for #distance.
  147. $wgHooks['ParserFirstCallInit'][] = 'MapsDistance::staticInit';
  148. $wgHooks['LanguageGetMagic'][] = 'MapsDistance::staticMagic';
  149. # Required for #finddestination.
  150. $wgHooks['ParserFirstCallInit'][] = 'MapsFinddestination::staticInit';
  151. $wgHooks['LanguageGetMagic'][] = 'MapsFinddestination::staticMagic';
  152. # Required for #geocode.
  153. $wgHooks['ParserFirstCallInit'][] = 'MapsGeocode::staticInit';
  154. $wgHooks['LanguageGetMagic'][] = 'MapsGeocode::staticMagic';
  155. # Required for #geodistance.
  156. $wgHooks['ParserFirstCallInit'][] = 'MapsGeodistance::staticInit';
  157. $wgHooks['LanguageGetMagic'][] = 'MapsGeodistance::staticMagic';
  158. # Required for #mapsdoc.
  159. $wgHooks['ParserFirstCallInit'][] = 'MapsMapsDoc::staticInit';
  160. $wgHooks['LanguageGetMagic'][] = 'MapsMapsDoc::staticMagic';
  161. # Geocoders
  162. # Registration of the GeoNames service geocoder.
  163. $wgHooks['GeocoderFirstCallInit'][] = 'MapsGeonamesGeocoder::register';
  164. # Registration of the legacy GeoNames service geocoder.
  165. $wgHooks['GeocoderFirstCallInit'][] = 'MapsGeonamesOldGeocoder::register';
  166. # Registration of the Google Geocoding (v2) service geocoder.
  167. $wgHooks['GeocoderFirstCallInit'][] = 'MapsGoogleGeocoder::register';
  168. # Registration of the Yahoo! Geocoding service geocoder.
  169. $wgHooks['GeocoderFirstCallInit'][] = 'MapsYahooGeocoder::register';
  170. # Layers
  171. # Registration of the image layer type.
  172. $wgHooks['MappingLayersInitialization'][] = 'MapsImageLayer::register';
  173. # Registration of the KML layer type.
  174. $wgHooks['MappingLayersInitialization'][] = 'MapsKMLLayer::register';
  175. # Mapping services
  176. # Include the mapping services that should be loaded into Maps.
  177. # Commenting or removing a mapping service will make Maps completely ignore it, and so improve performance.
  178. # Google Maps API v2
  179. include_once $egMapsDir . 'includes/services/GoogleMaps/GoogleMaps.php';
  180. # Google Maps API v3
  181. include_once $egMapsDir . 'includes/services/GoogleMaps3/GoogleMaps3.php';
  182. # OpenLayers API
  183. include_once $egMapsDir . 'includes/services/OpenLayers/OpenLayers.php';
  184. # Yahoo! Maps API
  185. include_once $egMapsDir . 'includes/services/YahooMaps/YahooMaps.php';
  186. # WMF OSM
  187. include_once $egMapsDir . 'includes/services/OSM/OSM.php';
  188. $egMapsSettings = array();
  189. // Include the settings file.
  190. require_once $egMapsDir . 'Maps_Settings.php';
  191. define( 'Maps_NS_LAYER', $egMapsNamespaceIndex + 0 );
  192. define( 'Maps_NS_LAYER_TALK', $egMapsNamespaceIndex + 1 );
  193. $wgResourceModules['ext.maps.common'] = array(
  194. 'localBasePath' => dirname( __FILE__ ) . '/includes',
  195. 'remoteBasePath' => $egMapsScriptPath . '/includes',
  196. 'group' => 'ext.maps',
  197. 'messages' => array(
  198. 'maps-load-failed',
  199. ),
  200. 'scripts' => array(
  201. 'ext.maps.common.js'
  202. )
  203. );
  204. $wgResourceModules['ext.maps.coord'] = array(
  205. 'localBasePath' => dirname( __FILE__ ) . '/includes',
  206. 'remoteBasePath' => $egMapsScriptPath . '/includes',
  207. 'group' => 'ext.maps',
  208. 'messages' => array(
  209. 'maps-abb-north',
  210. 'maps-abb-east',
  211. 'maps-abb-south',
  212. 'maps-abb-west',
  213. ),
  214. 'scripts' => array(
  215. 'ext.maps.coord.js'
  216. )
  217. );
  218. $wgResourceModules['ext.maps.resizable'] = array(
  219. 'dependencies' => 'jquery.ui.resizable'
  220. );
  221. $wgAvailableRights[] = 'geocode';
  222. # Users that can geocode. By default the same as those that can edit.
  223. foreach ( $wgGroupPermissions as $group => $rights ) {
  224. if ( array_key_exists( 'edit', $rights ) ) {
  225. $wgGroupPermissions[$group]['geocode'] = $wgGroupPermissions[$group]['edit'];
  226. }
  227. }
  228. $egMapsGlobalJSVars = array();
  229. /**
  230. * Initialization function for the Maps extension.
  231. *
  232. * @since 0.1
  233. *
  234. * @return true
  235. */
  236. function efMapsSetup() {
  237. global $wgExtraNamespaces, $wgNamespaceAliases;
  238. if ( is_null( $wgExtraNamespaces ) ) {
  239. $wgExtraNamespaces = array();
  240. }
  241. $wgExtraNamespaces += array(
  242. Maps_NS_LAYER => 'Layer',
  243. Maps_NS_LAYER_TALK => 'Layer talk'
  244. );
  245. $wgNamespaceAliases += array(
  246. wfMsg( 'maps-ns-layer' ) => Maps_NS_LAYER,
  247. wfMsg( 'maps-ns-layer-talk' ) => Maps_NS_LAYER_TALK
  248. );
  249. wfRunHooks( 'MappingServiceLoad' );
  250. wfRunHooks( 'MappingFeatureLoad' );
  251. return true;
  252. }