1 | <?php |
||
33 | class MapsSetup { |
||
34 | |||
35 | private $mwGlobals; |
||
36 | |||
37 | public function __construct( array &$mwGlobals ) { |
||
40 | |||
41 | public function setup() { |
||
49 | |||
50 | private function defaultSettings() { |
||
51 | if ( $this->mwGlobals['egMapsGMaps3Language'] === '' ) { |
||
52 | $this->mwGlobals['egMapsGMaps3Language'] = $this->mwGlobals['wgLang']; |
||
53 | } |
||
54 | |||
55 | if ( in_array( 'googlemaps3', $this->mwGlobals['egMapsAvailableServices'] ) ) { |
||
56 | $this->mwGlobals['wgSpecialPages']['MapEditor'] = 'Maps\MediaWiki\Specials\SpecialMapEditor'; |
||
57 | $this->mwGlobals['wgSpecialPageGroups']['MapEditor'] = 'maps'; |
||
58 | } |
||
59 | |||
60 | if ( $this->mwGlobals['egMapsGMaps3ApiKey'] === '' && array_key_exists( |
||
61 | 'egGoogleJsApiKey', |
||
62 | $this->mwGlobals |
||
63 | ) ) { |
||
64 | $this->mwGlobals['egMapsGMaps3ApiKey'] = $this->mwGlobals['egGoogleJsApiKey']; |
||
65 | } |
||
66 | } |
||
67 | |||
68 | private function registerAllTheThings() { |
||
69 | $this->registerParserHooks(); |
||
70 | $this->registerPermissions(); |
||
71 | $this->registerParameterTypes(); |
||
72 | $this->registerHooks(); |
||
73 | $this->registerGeoJsonContentModel(); |
||
74 | $this->registerEditApiModuleFallback(); |
||
75 | } |
||
76 | |||
77 | 50 | private function registerParserHooks() { |
|
78 | if ( $this->mwGlobals['egMapsEnableCoordinateFunction'] ) { |
||
79 | 50 | $this->mwGlobals['wgHooks']['ParserFirstCallInit'][] = function ( Parser &$parser ) { |
|
80 | 50 | return ( new CoordinatesFunction() )->init( $parser ); |
|
81 | }; |
||
82 | } |
||
83 | |||
84 | 50 | $this->mwGlobals['wgHooks']['ParserFirstCallInit'][] = function ( Parser &$parser ) { |
|
85 | 50 | foreach ( [ 'display_map', 'display_point', 'display_points', 'display_line' ] as $hookName ) { |
|
86 | 50 | $parser->setFunctionHook( |
|
87 | 50 | $hookName, |
|
88 | 50 | function ( Parser $parser, PPFrame $frame, array $arguments ) { |
|
89 | 19 | $mapHtml = MapsFactory::newDefault()->getDisplayMapFunction()->getMapHtmlForKeyValueStrings( |
|
90 | 19 | $parser, |
|
91 | 19 | array_map( |
|
92 | 19 | function ( $argument ) use ( $frame ) { |
|
93 | 19 | return $frame->expand( $argument ); |
|
94 | 19 | }, |
|
95 | $arguments |
||
96 | ) |
||
97 | ); |
||
98 | |||
99 | return [ |
||
100 | 19 | $mapHtml, |
|
101 | 'noparse' => true, |
||
102 | 'isHTML' => true, |
||
103 | ]; |
||
104 | 50 | }, |
|
105 | 50 | Parser::SFH_OBJECT_ARGS |
|
106 | ); |
||
107 | |||
108 | 50 | $parser->setHook( |
|
109 | 50 | $hookName, |
|
110 | 50 | function ( $text, array $arguments, Parser $parser ) { |
|
111 | 2 | if ( $text !== null ) { |
|
112 | 2 | $defaultParameters = DisplayMapFunction::getHookDefinition( "\n" )->getDefaultParameters(); |
|
113 | 2 | $defaultParam = array_shift( $defaultParameters ); |
|
114 | |||
115 | // If there is a first default parameter, set the tag contents as its value. |
||
116 | 2 | if ( $defaultParam !== null ) { |
|
117 | 2 | $arguments[$defaultParam] = $text; |
|
118 | } |
||
119 | } |
||
120 | |||
121 | 2 | return MapsFactory::newDefault()->getDisplayMapFunction()->getMapHtmlForParameterList( $parser, $arguments ); |
|
122 | 50 | } |
|
123 | ); |
||
124 | } |
||
125 | 50 | }; |
|
126 | |||
127 | 50 | $this->mwGlobals['wgHooks']['ParserFirstCallInit'][] = function ( Parser &$parser ) { |
|
128 | 50 | return ( new DistanceFunction() )->init( $parser ); |
|
129 | }; |
||
130 | |||
131 | 50 | $this->mwGlobals['wgHooks']['ParserFirstCallInit'][] = function ( Parser &$parser ) { |
|
132 | 50 | return ( new FindDestinationFunction() )->init( $parser ); |
|
133 | }; |
||
134 | |||
135 | 50 | $this->mwGlobals['wgHooks']['ParserFirstCallInit'][] = function ( Parser &$parser ) { |
|
136 | 50 | return ( new GeocodeFunction() )->init( $parser ); |
|
137 | }; |
||
138 | |||
139 | 50 | $this->mwGlobals['wgHooks']['ParserFirstCallInit'][] = function ( Parser &$parser ) { |
|
140 | 50 | return ( new GeoDistanceFunction() )->init( $parser ); |
|
141 | }; |
||
142 | |||
143 | 50 | $this->mwGlobals['wgHooks']['ParserFirstCallInit'][] = function ( Parser &$parser ) { |
|
144 | 50 | return ( new MapsDocFunction() )->init( $parser ); |
|
145 | }; |
||
146 | } |
||
147 | |||
148 | private function registerPermissions() { |
||
158 | |||
159 | private function registerParameterTypes() { |
||
200 | |||
201 | private function registerHooks() { |
||
202 | $this->mwGlobals['wgHooks']['AdminLinks'][] = 'Maps\MediaWiki\MapsHooks::addToAdminLinks'; |
||
203 | $this->mwGlobals['wgHooks']['MakeGlobalVariablesScript'][] = 'Maps\MediaWiki\MapsHooks::onMakeGlobalVariablesScript'; |
||
211 | |||
212 | private function registerGeoJsonContentModel() { |
||
215 | |||
216 | /** |
||
217 | * mediawiki.api.edit is present in 1.31 but not 1.33 |
||
218 | * Once Maps requires MW 1.33+, this can be removed after replacing usage of mediawiki.api.edit |
||
219 | */ |
||
220 | private function registerEditApiModuleFallback() { |
||
232 | |||
233 | } |
||
234 |