MaxSem has uploaded a new change for review. https://gerrit.wikimedia.org/r/310631
Change subject: Always serve all the data on preview ...................................................................... Always serve all the data on preview Bug: T145615 Change-Id: I1a58a9e613a59a4259081fbb8dfb9a39aa813964 --- M includes/Tag/TagHandler.php M tests/phpunit/KartographerTest.php 2 files changed, 45 insertions(+), 15 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Kartographer refs/changes/31/310631/1 diff --git a/includes/Tag/TagHandler.php b/includes/Tag/TagHandler.php index 00264b6..26917c2 100644 --- a/includes/Tag/TagHandler.php +++ b/includes/Tag/TagHandler.php @@ -299,19 +299,25 @@ $output->addTrackingCategory( 'kartographer-tracking-category', $parser->getTitle() ); } - $interact = $state->getInteractiveGroups(); - $requested = $state->getRequestedGroups(); - if ( $interact || $requested ) { - $interact = array_flip( $interact ); - $liveData = array_intersect_key( (array)$data, $interact ); - $requested = array_unique( $requested ); - // Prevent pointless API requests for missing groups - foreach ( $requested as $group ) { - if ( !isset( $data->$group ) ) { - $liveData[$group] = []; + // https://phabricator.wikimedia.org/T145615 - include all data in previews + $options = $parser->getOptions(); + if ( ( $options->getIsPreview() || $options->getIsSectionPreview() ) && $data ) { + $output->addJsConfigVars( 'wgKartographerLiveData', $data ); + } else { + $interact = $state->getInteractiveGroups(); + $requested = $state->getRequestedGroups(); + if ( $interact || $requested ) { + $interact = array_flip( $interact ); + $liveData = array_intersect_key( (array)$data, $interact ); + $requested = array_unique( $requested ); + // Prevent pointless API requests for missing groups + foreach ( $requested as $group ) { + if ( !isset( $data->$group ) ) { + $liveData[$group] = []; + } } + $output->addJsConfigVars( 'wgKartographerLiveData', $liveData ); } - $output->addJsConfigVars( 'wgKartographerLiveData', $liveData ); } } diff --git a/tests/phpunit/KartographerTest.php b/tests/phpunit/KartographerTest.php index 7fe468f..d241c9b 100644 --- a/tests/phpunit/KartographerTest.php +++ b/tests/phpunit/KartographerTest.php @@ -171,7 +171,13 @@ ]; } - public function testLiveData() { + /** + * @dataProvider provideLiveData + * @param string[] $expected + * @param bool $preview + * @param bool $sectionPreview + */ + public function testLiveData( array $expected, $preview, $sectionPreview ) { $text = <<<WIKITEXT <maplink latitude=10 longitude=20 zoom=13> @@ -193,20 +199,38 @@ } </mapframe> WIKITEXT; - $output = $this->parse( $text ); + $output = $this->parse( $text, + function( ParserOptions $options ) use ( $preview, $sectionPreview ) { + $options->setIsPreview( $preview ); + $options->setIsSectionPreview( $sectionPreview ); + } + ); $vars = $output->getJsConfigVars(); $this->assertArrayHasKey( 'wgKartographerLiveData', $vars ); - $this->assertArrayEquals( [ '_5e4843908b3c3d3b11ac4321edadedde28882cc2' ], array_keys( $vars['wgKartographerLiveData'] ) ); + $this->assertArrayEquals( $expected, array_keys( (array)$vars['wgKartographerLiveData'] ) ); + } + + public function provideLiveData() { + return [ + [ [ '_5e4843908b3c3d3b11ac4321edadedde28882cc2' ], false, false ], + [ [ '_5e4843908b3c3d3b11ac4321edadedde28882cc2', '_2251fa240a210d2861cc9f44c48d7e3ba116ff2f' ], true, false ], + [ [ '_5e4843908b3c3d3b11ac4321edadedde28882cc2', '_2251fa240a210d2861cc9f44c48d7e3ba116ff2f' ], false, true ], + [ [ '_5e4843908b3c3d3b11ac4321edadedde28882cc2', '_2251fa240a210d2861cc9f44c48d7e3ba116ff2f' ], true, true ], + ]; } /** * Parses wikitext * @param string $text + * @param callable $optionsCallback * @return ParserOutput */ - private function parse( $text ) { + private function parse( $text, callable $optionsCallback = null ) { $parser = new Parser(); $options = new ParserOptions(); + if ( $optionsCallback ) { + $optionsCallback( $options ); + } $title = Title::newFromText( 'Test' ); return $parser->parse( $text, $title, $options ); -- To view, visit https://gerrit.wikimedia.org/r/310631 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1a58a9e613a59a4259081fbb8dfb9a39aa813964 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