Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
73.91% |
17 / 23 |
|
25.00% |
1 / 4 |
CRAP | |
0.00% |
0 / 1 |
| DataModule | |
73.91% |
17 / 23 |
|
25.00% |
1 / 4 |
9.14 | |
0.00% |
0 / 1 |
| getScript | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
1 | |||
| enableModuleContentVersion | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| supportsURLLoading | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| numberOfNearbyPoints | |
42.86% |
3 / 7 |
|
0.00% |
0 / 1 |
9.66 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * ResourceLoader module providing extra data to the client-side. |
| 4 | * |
| 5 | * @file |
| 6 | * @ingroup Extensions |
| 7 | */ |
| 8 | |
| 9 | namespace Kartographer\Modules; |
| 10 | |
| 11 | use MediaWiki\Config\ConfigException; |
| 12 | use MediaWiki\Registration\ExtensionRegistry; |
| 13 | // phpcs:disable MediaWiki.Classes.FullQualifiedClassName -- T308814 |
| 14 | use MediaWiki\ResourceLoader as RL; |
| 15 | |
| 16 | /** |
| 17 | * @license MIT |
| 18 | */ |
| 19 | class DataModule extends RL\Module { |
| 20 | |
| 21 | /** @inheritDoc */ |
| 22 | public function getScript( RL\Context $context ) { |
| 23 | $config = $this->getConfig(); |
| 24 | return 'mw.config.set(' |
| 25 | . $context->encodeJson( [ |
| 26 | 'wgKartographerMapServer' => $config->get( 'KartographerMapServer' ), |
| 27 | 'wgKartographerStaticFullWidth' => $config->get( 'KartographerStaticFullWidth' ), |
| 28 | 'wgKartographerSrcsetScales' => $config->get( 'KartographerSrcsetScales' ), |
| 29 | 'wgKartographerStyles' => $config->get( 'KartographerStyles' ), |
| 30 | 'wgKartographerDfltStyle' => $config->get( 'KartographerDfltStyle' ), |
| 31 | 'wgKartographerUsePageLanguage' => $config->get( 'KartographerUsePageLanguage' ), |
| 32 | 'wgKartographerFallbackZoom' => $config->get( 'KartographerFallbackZoom' ), |
| 33 | 'wgKartographerSimpleStyleMarkers' => $config->get( 'KartographerSimpleStyleMarkers' ), |
| 34 | 'wgKartographerNearby' => $this->numberOfNearbyPoints(), |
| 35 | ] ) |
| 36 | . ');'; |
| 37 | } |
| 38 | |
| 39 | /** @inheritDoc */ |
| 40 | public function enableModuleContentVersion() { |
| 41 | return true; |
| 42 | } |
| 43 | |
| 44 | /** @inheritDoc */ |
| 45 | public function supportsURLLoading() { |
| 46 | // always use getScript() to acquire JavaScript (even in debug mode) |
| 47 | return false; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * @return int Number of points to load, 0 when the feature is disabled |
| 52 | */ |
| 53 | private function numberOfNearbyPoints(): int { |
| 54 | $limit = $this->getConfig()->get( 'KartographerNearby' ); |
| 55 | if ( !$limit ) { |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | if ( !ExtensionRegistry::getInstance()->isLoaded( 'GeoData' ) || |
| 60 | !ExtensionRegistry::getInstance()->isLoaded( 'CirrusSearch' ) |
| 61 | ) { |
| 62 | throw new ConfigException( '$wgKartographerNearby requires GeoData and CirrusSearch extensions' ); |
| 63 | } |
| 64 | |
| 65 | return $limit === true ? 300 : (int)$limit; |
| 66 | } |
| 67 | |
| 68 | } |