Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
80.65% covered (warning)
80.65%
25 / 31
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
LegacyMapFrame
80.65% covered (warning)
80.65%
25 / 31
50.00% covered (danger)
50.00%
1 / 2
10.73
0.00% covered (danger)
0.00%
0 / 1
 updateState
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 render
79.31% covered (warning)
79.31%
23 / 29
0.00% covered (danger)
0.00%
0 / 1
9.72
1<?php
2
3namespace Kartographer\Tag;
4
5use Kartographer\PartialWikitextParser;
6use Kartographer\State;
7use MediaWiki\Html\Html;
8
9/**
10 * The <mapframe> tag inserts a map into wiki page
11 *
12 * @license MIT
13 */
14class 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 );
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        if ( $caption !== '' ) {
62            $html .= Html::rawElement( 'div', [ 'class' => 'thumbcaption' ],
63                $parser->halfParseWikitext( $caption ) );
64        }
65
66        return Html::rawElement( 'div', [ 'class' => $gen->getThumbClasses() ],
67            Html::rawElement( 'div', [
68                    'class' => 'thumbinner',
69                    'style' => "width: $gen->cssWidth;",
70                ], $html ) );
71    }
72
73}