These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
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 https://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
||
10 | * @author Jeroen De Dauw < [email protected] > |
||
11 | */ |
||
12 | |||
13 | use DataValues\Geo\Parsers\GeoCoordinateParser; |
||
14 | use FileFetcher\SimpleFileFetcher; |
||
15 | use Maps\CircleParser; |
||
16 | use Maps\DistanceParser; |
||
17 | use Maps\ImageOverlayParser; |
||
18 | use Maps\LineParser; |
||
19 | use Maps\LocationParser; |
||
20 | use Maps\PolygonParser; |
||
21 | use Maps\RectangleParser; |
||
22 | use Maps\ServiceParam; |
||
23 | use Maps\WmsOverlayParser; |
||
24 | |||
25 | if ( !defined( 'MEDIAWIKI' ) ) { |
||
26 | die( 'Not an entry point.' ); |
||
27 | } |
||
28 | |||
29 | if ( defined( 'Maps_VERSION' ) ) { |
||
30 | // Do not initialize more than once. |
||
31 | return 1; |
||
32 | } |
||
33 | |||
34 | define( 'Maps_VERSION' , '3.8.1' ); |
||
35 | |||
36 | // Include the composer autoloader if it is present. |
||
37 | if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) { |
||
38 | include_once( __DIR__ . '/vendor/autoload.php' ); |
||
39 | } |
||
40 | |||
41 | // Only initialize the extension when all dependencies are present. |
||
42 | if ( !defined( 'Validator_VERSION' ) ) { |
||
43 | throw new Exception( 'You need to have Validator installed in order to use Maps' ); |
||
44 | } |
||
45 | |||
46 | if ( version_compare( $GLOBALS['wgVersion'], '1.23c' , '<' ) ) { |
||
47 | throw new Exception( |
||
48 | 'This version of Maps requires MediaWiki 1.23 or above; use Maps 3.5.x for older versions.' |
||
49 | . ' More information at https://github.com/JeroenDeDauw/Maps/blob/master/INSTALL.md' |
||
50 | ); |
||
51 | } |
||
52 | |||
53 | call_user_func( function() { |
||
54 | $GLOBALS['wgExtensionCredits']['parserhook'][] = [ |
||
55 | 'path' => __FILE__ , |
||
56 | 'name' => 'Maps' , |
||
57 | 'version' => Maps_VERSION , |
||
58 | 'author' => [ |
||
59 | '[https://www.mediawiki.org/wiki/User:Jeroen_De_Dauw Jeroen De Dauw]', |
||
60 | '...' |
||
61 | ] , |
||
62 | 'url' => 'https://github.com/JeroenDeDauw/Maps/blob/master/README.md#maps' , |
||
63 | 'descriptionmsg' => 'maps-desc', |
||
64 | 'license-name' => 'GPL-2.0+' |
||
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 | $GLOBALS['egMapsStyleVersion'] = $GLOBALS['wgStyleVersion'] . '-' . Maps_VERSION; |
||
74 | |||
75 | // Internationalization |
||
76 | $GLOBALS['wgMessagesDirs']['Maps'] = __DIR__ . '/i18n'; |
||
77 | $GLOBALS['wgExtensionMessagesFiles']['MapsMagic'] = __DIR__ . '/Maps.i18n.magic.php'; |
||
78 | $GLOBALS['wgExtensionMessagesFiles']['MapsAlias'] = __DIR__ . '/Maps.i18n.alias.php'; |
||
79 | |||
80 | $GLOBALS['wgResourceModules'] = array_merge( $GLOBALS['wgResourceModules'], include 'Maps.resources.php' ); |
||
81 | |||
82 | $GLOBALS['wgAPIModules']['geocode'] = 'Maps\Api\Geocode'; |
||
83 | |||
84 | // Register the initialization function of Maps. |
||
85 | $GLOBALS['wgExtensionFunctions'][] = function () { |
||
86 | |||
87 | if ( $GLOBALS['egMapsGMaps3Language'] === '' ) { |
||
88 | $GLOBALS['egMapsGMaps3Language'] = $GLOBALS['wgLang']; |
||
89 | } |
||
90 | |||
91 | Hooks::run( 'MappingServiceLoad' ); |
||
92 | Hooks::run( 'MappingFeatureLoad' ); |
||
93 | |||
94 | if ( in_array( 'googlemaps3', $GLOBALS['egMapsAvailableServices'] ) ) { |
||
95 | $GLOBALS['wgSpecialPages']['MapEditor'] = 'SpecialMapEditor'; |
||
96 | $GLOBALS['wgSpecialPageGroups']['MapEditor'] = 'maps'; |
||
97 | } |
||
98 | |||
99 | return true; |
||
100 | }; |
||
101 | |||
102 | $GLOBALS['wgHooks']['AdminLinks'][] = 'MapsHooks::addToAdminLinks'; |
||
103 | $GLOBALS['wgHooks']['MakeGlobalVariablesScript'][] = 'MapsHooks::onMakeGlobalVariablesScript'; |
||
104 | |||
105 | // Parser hooks |
||
106 | |||
107 | // Required for #coordinates. |
||
108 | $GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) { |
||
109 | $instance = new MapsCoordinates(); |
||
110 | return $instance->init( $parser ); |
||
111 | }; |
||
112 | |||
113 | $GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) { |
||
114 | $instance = new MapsDisplayMap(); |
||
115 | return $instance->init( $parser ); |
||
116 | }; |
||
117 | |||
118 | $GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) { |
||
119 | $instance = new MapsDistance(); |
||
120 | return $instance->init( $parser ); |
||
121 | }; |
||
122 | |||
123 | $GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) { |
||
124 | $instance = new MapsFinddestination(); |
||
125 | return $instance->init( $parser ); |
||
126 | }; |
||
127 | |||
128 | $GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) { |
||
129 | $instance = new MapsGeocode(); |
||
130 | return $instance->init( $parser ); |
||
131 | }; |
||
132 | |||
133 | $GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) { |
||
134 | $instance = new MapsGeodistance(); |
||
135 | return $instance->init( $parser ); |
||
136 | }; |
||
137 | |||
138 | $GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) { |
||
139 | $instance = new MapsMapsDoc(); |
||
140 | return $instance->init( $parser ); |
||
141 | }; |
||
142 | |||
143 | // Geocoders |
||
144 | |||
145 | // Registration of the GeoNames service geocoder. |
||
146 | $GLOBALS['wgHooks']['GeocoderFirstCallInit'][] = 'MapsGeonamesGeocoder::register'; |
||
147 | |||
148 | // Registration of the Google Geocoding (v2) service geocoder. |
||
149 | $GLOBALS['wgHooks']['GeocoderFirstCallInit'][] = 'MapsGoogleGeocoder::register'; |
||
150 | |||
151 | // Registration of the geocoder.us service geocoder. |
||
152 | $GLOBALS['wgHooks']['GeocoderFirstCallInit'][] = 'MapsGeocoderusGeocoder::register'; |
||
153 | |||
154 | // Registration of the OSM Nominatim service geocoder. |
||
155 | $GLOBALS['wgHooks']['GeocoderFirstCallInit'][] = function() { |
||
156 | \Maps\Geocoders::registerGeocoder( |
||
157 | 'nominatim', |
||
158 | new \Maps\Geocoders\NominatimGeocoder( new SimpleFileFetcher() ) |
||
159 | ); |
||
160 | return true; |
||
161 | }; |
||
162 | |||
163 | // Mapping services |
||
164 | |||
165 | // Include the mapping services that should be loaded into Maps. |
||
166 | // Commenting or removing a mapping service will make Maps completely ignore it, and so improve performance. |
||
167 | |||
168 | // Google Maps API v3 |
||
169 | // TODO: improve loading mechanism |
||
170 | include_once __DIR__ . '/includes/services/GoogleMaps3/GoogleMaps3.php'; |
||
171 | |||
172 | // OpenLayers API |
||
173 | // TODO: improve loading mechanism |
||
174 | include_once __DIR__ . '/includes/services/OpenLayers/OpenLayers.php'; |
||
175 | |||
176 | // Leaflet API |
||
177 | // TODO: improve loading mechanism |
||
178 | include_once __DIR__ . '/includes/services/Leaflet/Leaflet.php'; |
||
179 | |||
180 | |||
181 | require_once __DIR__ . '/Maps_Settings.php'; |
||
182 | |||
183 | $GLOBALS['wgAvailableRights'][] = 'geocode'; |
||
184 | |||
185 | // Users that can geocode. By default the same as those that can edit. |
||
186 | foreach ( $GLOBALS['wgGroupPermissions'] as $group => $rights ) { |
||
187 | if ( array_key_exists( 'edit' , $rights ) ) { |
||
188 | $GLOBALS['wgGroupPermissions'][$group]['geocode'] = $GLOBALS['wgGroupPermissions'][$group]['edit']; |
||
189 | } |
||
190 | } |
||
191 | |||
192 | $GLOBALS['wgParamDefinitions']['coordinate'] = [ |
||
193 | 'string-parser' => GeoCoordinateParser::class, |
||
194 | ]; |
||
195 | |||
196 | $GLOBALS['wgParamDefinitions']['mappingservice'] = [ |
||
197 | 'definition'=> ServiceParam::class, |
||
198 | ]; |
||
199 | |||
200 | $GLOBALS['wgParamDefinitions']['mapslocation'] = [ |
||
201 | 'string-parser' => LocationParser::class, |
||
202 | ]; |
||
203 | |||
204 | $GLOBALS['wgParamDefinitions']['mapsline'] = [ |
||
205 | 'string-parser' => LineParser::class, |
||
206 | ]; |
||
207 | |||
208 | $GLOBALS['wgParamDefinitions']['mapscircle'] = [ |
||
209 | 'string-parser' => CircleParser::class, |
||
210 | ]; |
||
211 | |||
212 | $GLOBALS['wgParamDefinitions']['mapsrectangle'] = [ |
||
213 | 'string-parser' => RectangleParser::class, |
||
214 | ]; |
||
215 | |||
216 | $GLOBALS['wgParamDefinitions']['mapspolygon'] = [ |
||
217 | 'string-parser' => PolygonParser::class, |
||
218 | ]; |
||
219 | |||
220 | $GLOBALS['wgParamDefinitions']['distance'] = [ |
||
221 | 'string-parser' => DistanceParser::class, |
||
222 | ]; |
||
223 | |||
224 | $GLOBALS['wgParamDefinitions']['wmsoverlay'] = [ |
||
225 | 'string-parser' => WmsOverlayParser::class, |
||
226 | ]; |
||
227 | |||
228 | $GLOBALS['wgParamDefinitions']['mapsimageoverlay'] = [ |
||
229 | 'string-parser' => ImageOverlayParser::class, |
||
230 | ]; |
||
231 | } ); |
||
232 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.