JeroenDeDauw /
Maps
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Initialization file for the Maps extension. |
||
| 4 | * |
||
| 5 | * @links https://github.com/JeroenDeDauw/Maps/blob/master/README.md#maps Documentation |
||
| 6 | * @links https://github.com/JeroenDeDauw/Maps/issues Support |
||
| 7 | * @links https://github.com/JeroenDeDauw/Maps Source code |
||
| 8 | * |
||
| 9 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
||
| 10 | * @author Jeroen De Dauw < [email protected] > |
||
| 11 | */ |
||
| 12 | |||
| 13 | if ( version_compare( $GLOBALS['wgVersion'], '1.27c', '>' ) ) { |
||
| 14 | if ( function_exists( 'wfLoadExtension' ) ) { |
||
| 15 | wfLoadExtension( 'Maps' ); |
||
| 16 | // Keep i18n globals so mergeMessageFileList.php doesn't break |
||
| 17 | $wgMessagesDirs['Maps'] = __DIR__ . '/i18n'; |
||
| 18 | $wgExtensionMessagesFiles['MapsMagic'] = __DIR__ . '/Maps.i18n.magic.php'; |
||
| 19 | $wgExtensionMessagesFiles['MapsNamespaces'] = __DIR__ . '/Maps.i18n.namespaces.php'; |
||
| 20 | $wgExtensionMessagesFiles['MapsAlias'] = __DIR__ . '/Maps.i18n.alias.php'; |
||
| 21 | /* wfWarn( |
||
| 22 | 'Deprecated PHP entry point used for Maps extension. ' . |
||
| 23 | 'Please use wfLoadExtension instead, ' . |
||
| 24 | 'see https://www.mediawiki.org/wiki/Extension_registration for more details.' |
||
| 25 | ); */ |
||
| 26 | return; |
||
| 27 | } |
||
| 28 | } |
||
| 29 | |||
| 30 | if ( defined( 'Maps_VERSION' ) ) { |
||
| 31 | // Do not initialize more than once. |
||
| 32 | return 1; |
||
| 33 | } |
||
| 34 | |||
| 35 | define( 'Maps_VERSION' , '3.2 alpha' ); |
||
| 36 | |||
| 37 | // Include the composer autoloader if it is present. |
||
| 38 | if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) { |
||
| 39 | include_once( __DIR__ . '/vendor/autoload.php' ); |
||
| 40 | } |
||
| 41 | |||
| 42 | // Only initialize the extension when all dependencies are present. |
||
| 43 | if ( !defined( 'Validator_VERSION' ) ) { |
||
| 44 | throw new Exception( 'You need to have Validator installed in order to use Maps' ); |
||
| 45 | } |
||
| 46 | |||
| 47 | if ( version_compare( $GLOBALS['wgVersion'], '1.23c' , '<' ) ) { |
||
| 48 | throw new Exception( 'This version of Maps requires MediaWiki 1.23 or above.' ); |
||
| 49 | } |
||
| 50 | |||
| 51 | call_user_func( function() { |
||
| 52 | global $wgExtensionCredits; |
||
| 53 | global $wgResourceModules, $wgGroupPermissions, $egMapsNamespaceIndex, $wgStyleVersion; |
||
| 54 | global $egMapsStyleVersion, $wgHooks, $wgExtensionMessagesFiles, $wgMessagesDirs; |
||
| 55 | |||
| 56 | $wgExtensionCredits['parserhook'][] = array( |
||
| 57 | 'path' => __FILE__ , |
||
| 58 | 'name' => 'Maps' , |
||
| 59 | 'version' => Maps_VERSION , |
||
| 60 | 'author' => array( |
||
| 61 | '[https://www.mediawiki.org/wiki/User:Jeroen_De_Dauw Jeroen De Dauw]' |
||
| 62 | ) , |
||
| 63 | 'url' => 'https://github.com/JeroenDeDauw/Maps/blob/master/README.md#maps', |
||
| 64 | 'descriptionmsg' => 'maps-desc' |
||
| 65 | ); |
||
| 66 | |||
| 67 | // The different coordinate notations. |
||
| 68 | define( 'Maps_COORDS_FLOAT' , 'float' ); |
||
| 69 | define( 'Maps_COORDS_DMS' , 'dms' ); |
||
| 70 | define( 'Maps_COORDS_DM' , 'dm' ); |
||
| 71 | define( 'Maps_COORDS_DD' , 'dd' ); |
||
| 72 | |||
| 73 | $egMapsDir = __DIR__ . '/'; |
||
| 74 | |||
| 75 | $egMapsStyleVersion = $wgStyleVersion . '-' . Maps_VERSION; |
||
| 76 | |||
| 77 | $wgMessagesDirs['Maps'] = __DIR__ . '/i18n'; |
||
| 78 | $wgExtensionMessagesFiles['MapsMagic'] = __DIR__ . '/Maps.i18n.magic.php'; |
||
| 79 | $wgExtensionMessagesFiles['MapsNamespaces'] = __DIR__ . '/Maps.i18n.namespaces.php'; |
||
| 80 | $wgExtensionMessagesFiles['MapsAlias'] = __DIR__ . '/Maps.i18n.alias.php'; |
||
| 81 | |||
| 82 | $wgResourceModules = array_merge( $wgResourceModules, include 'Maps.resources.php' ); |
||
| 83 | |||
| 84 | $wgAPIModules['geocode'] = 'Maps\Api\Geocode'; |
||
|
0 ignored issues
–
show
|
|||
| 85 | |||
| 86 | // Register the initialization function of Maps. |
||
| 87 | $GLOBALS['wgExtensionFunctions'][] = function () { |
||
| 88 | wfRunHooks( 'MappingServiceLoad' ); |
||
| 89 | wfRunHooks( 'MappingFeatureLoad' ); |
||
| 90 | |||
| 91 | if ( in_array( 'googlemaps3', $GLOBALS['egMapsAvailableServices'] ) ) { |
||
| 92 | global $wgSpecialPages, $wgSpecialPageGroups; |
||
| 93 | |||
| 94 | $wgSpecialPages['MapEditor'] = 'SpecialMapEditor'; |
||
| 95 | $wgSpecialPageGroups['MapEditor'] = 'maps'; |
||
| 96 | } |
||
| 97 | |||
| 98 | return true; |
||
| 99 | }; |
||
| 100 | |||
| 101 | $wgHooks['AdminLinks'][] = 'MapsHooks::addToAdminLinks'; |
||
| 102 | $wgHooks['ArticleFromTitle'][] = 'MapsHooks::onArticleFromTitle'; |
||
| 103 | $wgHooks['MakeGlobalVariablesScript'][] = 'MapsHooks::onMakeGlobalVariablesScript'; |
||
| 104 | $wgHooks['CanonicalNamespaces'][] = 'MapsHooks::onCanonicalNamespaces'; $wgHooks['LoadExtensionSchemaUpdates'][] = 'MapsHooks::onLoadExtensionSchemaUpdates'; |
||
| 105 | $wgHooks['ArticlePurge'][] = 'MapsHooks::onArticlePurge'; |
||
| 106 | $wgHooks['LinksUpdateConstructed'][] = 'MapsHooks::onLinksUpdateConstructed'; |
||
| 107 | $wgHooks['ParserAfterTidy'][] = 'MapsHooks::onParserAfterTidy'; |
||
| 108 | $wgHooks['ParserClearState'][] = 'MapsHooks::onParserClearState'; |
||
| 109 | |||
| 110 | // Parser hooks |
||
| 111 | |||
| 112 | // Required for #coordinates. |
||
| 113 | $wgHooks['ParserFirstCallInit'][] = function( Parser &$parser ) { |
||
| 114 | $instance = new MapsCoordinates(); |
||
| 115 | return $instance->init( $parser ); |
||
| 116 | }; |
||
| 117 | |||
| 118 | $wgHooks['ParserFirstCallInit'][] = function( Parser &$parser ) { |
||
| 119 | $instance = new MapsDisplayMap(); |
||
| 120 | return $instance->init( $parser ); |
||
| 121 | }; |
||
| 122 | |||
| 123 | $wgHooks['ParserFirstCallInit'][] = function( Parser &$parser ) { |
||
| 124 | $instance = new MapsDistance(); |
||
| 125 | return $instance->init( $parser ); |
||
| 126 | }; |
||
| 127 | |||
| 128 | $wgHooks['ParserFirstCallInit'][] = function( Parser &$parser ) { |
||
| 129 | $instance = new MapsFinddestination(); |
||
| 130 | return $instance->init( $parser ); |
||
| 131 | }; |
||
| 132 | |||
| 133 | $wgHooks['ParserFirstCallInit'][] = function( Parser &$parser ) { |
||
| 134 | $instance = new MapsGeocode(); |
||
| 135 | return $instance->init( $parser ); |
||
| 136 | }; |
||
| 137 | |||
| 138 | $wgHooks['ParserFirstCallInit'][] = function( Parser &$parser ) { |
||
| 139 | $instance = new MapsGeodistance(); |
||
| 140 | return $instance->init( $parser ); |
||
| 141 | }; |
||
| 142 | |||
| 143 | $wgHooks['ParserFirstCallInit'][] = function( Parser &$parser ) { |
||
| 144 | $instance = new MapsMapsDoc(); |
||
| 145 | return $instance->init( $parser ); |
||
| 146 | }; |
||
| 147 | |||
| 148 | $wgHooks['ParserFirstCallInit'][] = function( Parser &$parser ) { |
||
| 149 | $instance = new MapsLayerDefinition(); |
||
| 150 | return $instance->init( $parser ); |
||
| 151 | }; |
||
| 152 | |||
| 153 | // Geocoders |
||
| 154 | |||
| 155 | // Registration of the GeoNames service geocoder. |
||
| 156 | $wgHooks['GeocoderFirstCallInit'][] = 'MapsGeonamesGeocoder::register'; |
||
| 157 | |||
| 158 | // Registration of the Google Geocoding (v2) service geocoder. |
||
| 159 | $wgHooks['GeocoderFirstCallInit'][] = 'MapsGoogleGeocoder::register'; |
||
| 160 | |||
| 161 | // Registration of the geocoder.us service geocoder. |
||
| 162 | $wgHooks['GeocoderFirstCallInit'][] = 'MapsGeocoderusGeocoder::register'; |
||
| 163 | |||
| 164 | // Layers |
||
| 165 | |||
| 166 | // Registration of the image layer type. |
||
| 167 | $wgHooks['MappingLayersInitialization'][] = 'MapsImageLayer::register'; |
||
| 168 | |||
| 169 | // Mapping services |
||
| 170 | |||
| 171 | // Include the mapping services that should be loaded into Maps. |
||
| 172 | // Commenting or removing a mapping service will make Maps completely ignore it, and so improve performance. |
||
| 173 | |||
| 174 | // Google Maps API v3 |
||
| 175 | // TODO: improve loading mechanism |
||
| 176 | include_once $egMapsDir . 'includes/services/GoogleMaps3/GoogleMaps3.php'; |
||
| 177 | |||
| 178 | // OpenLayers API |
||
| 179 | // TODO: improve loading mechanism |
||
| 180 | include_once $egMapsDir . 'includes/services/OpenLayers/OpenLayers.php'; |
||
| 181 | |||
| 182 | // Leaflet API |
||
| 183 | // TODO: improve loading mechanism |
||
| 184 | include_once $egMapsDir . 'includes/services/Leaflet/Leaflet.php'; |
||
| 185 | |||
| 186 | |||
| 187 | require_once __DIR__ . '/Maps_Settings.php'; |
||
| 188 | |||
| 189 | define( 'Maps_NS_LAYER' , $egMapsNamespaceIndex + 0 ); |
||
| 190 | define( 'Maps_NS_LAYER_TALK' , $egMapsNamespaceIndex + 1 ); |
||
| 191 | |||
| 192 | $wgAvailableRights[] = 'geocode'; |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$wgAvailableRights was never initialized. Although not strictly required by PHP, it is generally a good practice to add $wgAvailableRights = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. Loading history...
|
|||
| 193 | |||
| 194 | // Users that can geocode. By default the same as those that can edit. |
||
| 195 | foreach ( $wgGroupPermissions as $group => $rights ) { |
||
| 196 | if ( array_key_exists( 'edit' , $rights ) ) { |
||
| 197 | $wgGroupPermissions[$group]['geocode'] = $wgGroupPermissions[$group]['edit']; |
||
| 198 | } |
||
| 199 | } |
||
| 200 | |||
| 201 | global $wgParamDefinitions; |
||
| 202 | |||
| 203 | $wgParamDefinitions['mappingservice'] = array( |
||
| 204 | 'definition'=> 'Maps\ServiceParam', |
||
| 205 | ); |
||
| 206 | |||
| 207 | $wgParamDefinitions['mapslocation'] = array( |
||
| 208 | 'string-parser' => 'Maps\LocationParser', |
||
| 209 | ); |
||
| 210 | |||
| 211 | $wgParamDefinitions['mapsline'] = array( |
||
| 212 | 'string-parser' => 'Maps\LineParser', |
||
| 213 | ); |
||
| 214 | |||
| 215 | $wgParamDefinitions['mapscircle'] = array( |
||
| 216 | 'string-parser' => 'Maps\CircleParser', |
||
| 217 | ); |
||
| 218 | |||
| 219 | $wgParamDefinitions['mapsrectangle'] = array( |
||
| 220 | 'string-parser' => 'Maps\RectangleParser', |
||
| 221 | ); |
||
| 222 | |||
| 223 | $wgParamDefinitions['mapspolygon'] = array( |
||
| 224 | 'string-parser' => 'Maps\PolygonParser', |
||
| 225 | ); |
||
| 226 | |||
| 227 | $wgParamDefinitions['distance'] = array( |
||
| 228 | 'string-parser' => 'Maps\DistanceParser', |
||
| 229 | ); |
||
| 230 | |||
| 231 | $wgParamDefinitions['wmsoverlay'] = array( |
||
| 232 | 'string-parser' => 'Maps\WmsOverlayParser', |
||
| 233 | ); |
||
| 234 | |||
| 235 | $wgParamDefinitions['mapsimageoverlay'] = array( |
||
| 236 | 'string-parser' => 'Maps\ImageOverlayParser', |
||
| 237 | ); |
||
| 238 | } ); |
||
| 239 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.