[MediaWiki-commits] [Gerrit] mediawiki...Kartographer[wmf/1.28.0-wmf.19]: Always serve all the data on preview
jenkins-bot has submitted this change and it was merged. Change subject: Always serve all the data on preview .. Always serve all the data on preview Bug: T145615 Change-Id: I1a58a9e613a59a4259081fbb8dfb9a39aa813964 (cherry picked from commit a41714fb29e51dc777aba504ef6f423cb987f08e) --- M includes/Tag/TagHandler.php M tests/phpunit/KartographerTest.php 2 files changed, 45 insertions(+), 15 deletions(-) Approvals: Dereckson: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/Tag/TagHandler.php b/includes/Tag/TagHandler.php index 00264b6..7412e71 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 ( $data && ( $options->getIsPreview() || $options->getIsSectionPreview() ) ) { + $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 = << @@ -193,20 +199,38 @@ } 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 +
[MediaWiki-commits] [Gerrit] mediawiki...Kartographer[wmf/1.28.0-wmf.19]: Always serve all the data on preview
Yurik has uploaded a new change for review. https://gerrit.wikimedia.org/r/310681 Change subject: Always serve all the data on preview .. Always serve all the data on preview Bug: T145615 Change-Id: I1a58a9e613a59a4259081fbb8dfb9a39aa813964 (cherry picked from commit a41714fb29e51dc777aba504ef6f423cb987f08e) --- 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/81/310681/1 diff --git a/includes/Tag/TagHandler.php b/includes/Tag/TagHandler.php index 00264b6..7412e71 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 ( $data && ( $options->getIsPreview() || $options->getIsSectionPreview() ) ) { + $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 = << @@ -193,20 +199,38 @@ } 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 ], + ]; } /** *