MaxSem has uploaded a new change for review. https://gerrit.wikimedia.org/r/278026
Change subject: Don't export uneeded geometries into page ...................................................................... Don't export uneeded geometries into page Bug: T128995 Change-Id: Ic261c4fa2dce192af972203109bb19557e61fbc8 --- M includes/Tag/MapFrame.php M includes/Tag/TagHandler.php M tests/phpunit/KartographerTest.php 3 files changed, 57 insertions(+), 10 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Kartographer refs/changes/26/278026/1 diff --git a/includes/Tag/MapFrame.php b/includes/Tag/MapFrame.php index 9e12a67..e413c9c 100644 --- a/includes/Tag/MapFrame.php +++ b/includes/Tag/MapFrame.php @@ -5,6 +5,7 @@ use FormatJson; use Html; +use ParserOutput; use UnexpectedValueException; /** @@ -37,6 +38,8 @@ 'center' => 'center', 'right' => 'floatright', ]; + + $output = $this->parser->getOutput(); switch ( $wgKartographerFrameMode ) { /* Not implemented in Kartotherian yet @@ -75,7 +78,7 @@ */ case 'interactive': - $this->parser->getOutput()->addModules( 'ext.kartographer.live' ); + $output->addModules( 'ext.kartographer.live' ); $attrs = $this->getDefaultAttributes(); $attrs['class'] .= ' mw-kartographer-interactive'; if ( isset( $alignClasses[$this->align] ) ) { @@ -90,7 +93,10 @@ $attrs['data-overlays'] = FormatJson::encode( $this->showGroups, false, FormatJson::ALL_OK ); } - $this->parser->getOutput()->setExtensionData( 'kartographer_interact', true ); + $groups = $output->getExtensionData( 'kartographer_interact' ); + $groups = $groups ?: []; + $groups = array_merge( $groups, $this->showGroups ); + $output->setExtensionData( 'kartographer_interact', $groups ); return Html::rawElement( 'div', $attrs ); break; default: diff --git a/includes/Tag/TagHandler.php b/includes/Tag/TagHandler.php index 819f7c2..fa54d5a 100644 --- a/includes/Tag/TagHandler.php +++ b/includes/Tag/TagHandler.php @@ -289,14 +289,18 @@ public static function finalParseStep( Parser $parser ) { $output = $parser->getOutput(); + $data = $output->getExtensionData( 'kartographer_data' ); if ( $output->getExtensionData( 'kartographer_broken' ) ) { $output->addTrackingCategory( 'kartographer-broken-category', $parser->getTitle() ); } if ( $output->getExtensionData( 'kartographer_valid' ) ) { $output->addTrackingCategory( 'kartographer-tracking-category', $parser->getTitle() ); } - if ( $output->getExtensionData( 'kartographer_interact' ) ) { - $output->addJsConfigVars( 'wgKartographerLiveData', $output->getExtensionData( 'kartographer_data' ) ); + $interact = $output->getExtensionData( 'kartographer_interact' ); + if ( $interact ) { + $interact = array_flip( array_unique( $interact ) ); + $liveData = array_intersect_key( (array)$data, $interact ); + $output->addJsConfigVars( 'wgKartographerLiveData', $liveData ); } } diff --git a/tests/phpunit/KartographerTest.php b/tests/phpunit/KartographerTest.php index d5f5e10..34f4a33 100644 --- a/tests/phpunit/KartographerTest.php +++ b/tests/phpunit/KartographerTest.php @@ -34,12 +34,8 @@ /** * @dataProvider provideTagData */ - public function testTagData( $expected, $input, $message ) { - $parser = new Parser(); - $options = new ParserOptions(); - $title = Title::newFromText( 'Test' ); - - $output = $parser->parse( $input, $title, $options ); + public function t1estTagData( $expected, $input, $message ) { + $output = $this->parse( $input ); if ( $expected === false ) { $this->assertTrue( $output->getExtensionData( 'kartographer_broken' ), 'Parse is expected to fail' ); @@ -87,6 +83,47 @@ ]; } + public function testLiveData() { + $text = +<<<WIKITEXT +<maplink latitude=10 longitude=20 zoom=13> +{ + "type": "Feature", + "geometry": { + "type": "Point", + "coordinates": [-122.3988, 37.8013] + } +} +</maplink> +<mapframe width=200 height=200 latitude=10 longitude=20 zoom=13> +{ + "type": "Feature", + "geometry": { + "type": "Point", + "coordinates": [10, 20] + } +} +</mapframe> +WIKITEXT; + $output = $this->parse( $text ); + $vars = $output->getJsConfigVars(); + $this->assertArrayHasKey( 'wgKartographerLiveData', $vars ); + $this->assertArrayEquals( [ '_5e4843908b3c3d3b11ac4321edadedde28882cc2' ], array_keys( $vars['wgKartographerLiveData'] ) ); + } + + /** + * Parses wikitext + * @param string $text + * @return ParserOutput + */ + private function parse( $text ) { + $parser = new Parser(); + $options = new ParserOptions(); + $title = Title::newFromText( 'Test' ); + + return $parser->parse( $text, $title, $options ); + } + private function hasTrackingCategory( ParserOutput $output, $key ) { $cat = wfMessage( $key )->inContentLanguage()->text(); $title = Title::makeTitleSafe( NS_CATEGORY, $cat ); -- To view, visit https://gerrit.wikimedia.org/r/278026 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic261c4fa2dce192af972203109bb19557e61fbc8 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Kartographer Gerrit-Branch: master Gerrit-Owner: MaxSem <maxsem.w...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits