Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
86.21% |
25 / 29 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| LegacyMapFrame | |
86.21% |
25 / 29 |
|
50.00% |
1 / 2 |
10.26 | |
0.00% |
0 / 1 |
| updateState | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| render | |
85.19% |
23 / 27 |
|
0.00% |
0 / 1 |
9.26 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Kartographer\Tag; |
| 4 | |
| 5 | use Kartographer\PartialWikitextParser; |
| 6 | use Kartographer\State; |
| 7 | use MediaWiki\Html\Html; |
| 8 | |
| 9 | /** |
| 10 | * The <mapframe> tag inserts a map into wiki page |
| 11 | * |
| 12 | * @license MIT |
| 13 | */ |
| 14 | class LegacyMapFrame extends LegacyTagHandler { |
| 15 | |
| 16 | public const TAG = 'mapframe'; |
| 17 | |
| 18 | protected function updateState( State $state, array $geometries ): void { |
| 19 | parent::updateState( $state, $geometries ); |
| 20 | // Must be after the parent call because that possibly added a private group hash |
| 21 | $state->addInteractiveGroups( $this->args->showGroups ); |
| 22 | } |
| 23 | |
| 24 | /** @inheritDoc */ |
| 25 | protected function render( PartialWikitextParser $parser, bool $serverMayRenderOverlays ): string { |
| 26 | // TODO if fullwidth, we really should use interactive mode.. |
| 27 | // BUT not possible to use both modes at the same time right now. T248023 |
| 28 | // Should be fixed, especially considering VE in page editing etc... |
| 29 | $staticMode = $this->config->get( 'KartographerStaticMapframe' ); |
| 30 | if ( $staticMode && !$serverMayRenderOverlays ) { |
| 31 | $this->getOutput()->setJsConfigVar( 'wgKartographerStaticMapframePreview', 1 ); |
| 32 | } |
| 33 | $this->getOutput()->addModules( [ $staticMode && $serverMayRenderOverlays |
| 34 | ? 'ext.kartographer.staticframe' |
| 35 | : 'ext.kartographer.frame' ] ); |
| 36 | |
| 37 | $gen = new MapFrameAttributeGenerator( $this->args, $this->config ); |
| 38 | $attrs = $gen->prepareAttrs(); |
| 39 | |
| 40 | $pageTitle = $this->parserContext->getPrefixedDBkey(); |
| 41 | $revisionId = $this->parserContext->getRevisionId(); |
| 42 | $imgAttrs = $gen->prepareImgAttrs( $serverMayRenderOverlays, $pageTitle, $revisionId, 'legacy' ); |
| 43 | $imgAttrs['alt'] ??= wfMessage( 'kartographer-static-mapframe-alt' )->text(); |
| 44 | |
| 45 | $thumbnail = Html::element( 'img', $imgAttrs ); |
| 46 | if ( !$serverMayRenderOverlays ) { |
| 47 | $thumbnail = Html::rawElement( 'noscript', [], $thumbnail ); |
| 48 | if ( $this->args->usesAutoPosition() ) { |
| 49 | // Impossible to render .png thumbnails that depend on unsaved ExternalData. Preview |
| 50 | // will replace this with a dynamic map anyway when JavaScript is available. |
| 51 | $thumbnail = ''; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | $html = Html::rawElement( 'a', $attrs, $thumbnail ); |
| 56 | if ( $this->args->frameless ) { |
| 57 | return $html; |
| 58 | } |
| 59 | |
| 60 | $caption = (string)$this->args->text; |
| 61 | $html .= Html::rawElement( 'figcaption', [], |
| 62 | $caption !== '' ? $parser->halfParseWikitext( $caption ) : '' ); |
| 63 | |
| 64 | return Html::rawElement( 'figure', [ |
| 65 | 'class' => $gen->getThumbClasses(), |
| 66 | 'typeof' => 'mw:File/Thumb', |
| 67 | ], $html ); |
| 68 | } |
| 69 | |
| 70 | } |