From a773ee1a49d73774e6dcad216edc89be61649f94 Mon Sep 17 00:00:00 2001 From: Lukasz Konieczny Date: Thu, 31 Mar 2016 09:58:34 +0000 Subject: [PATCH 1/9] CE-3554: Extract labels from infobox markup and save them in page props --- controllers/ApiQueryPortableInfobox.class.php | 3 +++ ...rtableInfoboxParserTagController.class.php | 2 +- services/Parser/Nodes/Node.php | 22 +++++++++++++++++++ services/Parser/Nodes/NodeData.php | 4 ++++ services/Parser/Nodes/NodeGroup.php | 4 ++++ services/Parser/Nodes/NodeInfobox.php | 4 ++++ 6 files changed, 38 insertions(+), 1 deletion(-) diff --git a/controllers/ApiQueryPortableInfobox.class.php b/controllers/ApiQueryPortableInfobox.class.php index f5e512f..7281766 100644 --- a/controllers/ApiQueryPortableInfobox.class.php +++ b/controllers/ApiQueryPortableInfobox.class.php @@ -30,9 +30,12 @@ class ApiQueryPortableInfobox extends ApiQueryBase { $pageSet->getResult()->addValue( [ 'query', 'pages', $id ], 'infoboxes', $inf ); foreach ( $parsedInfoboxes as $count => $infobox ) { $s = isset( $infobox[ 'sources' ] ) ? $infobox[ 'sources' ] : [ ]; + $l = isset( $infobox[ 'labels' ] ) ? $infobox[ 'labels' ] : [ ]; $pageSet->getResult()->addValue( [ 'query', 'pages', $id, 'infoboxes', $count ], 'id', $count ); $pageSet->getResult()->setIndexedTagName( $s, "source" ); $pageSet->getResult()->addValue( [ 'query', 'pages', $id, 'infoboxes', $count ], 'sources', $s ); + $pageSet->getResult()->setIndexedTagName( $l, "labels" ); + $pageSet->getResult()->addValue( [ 'query', 'pages', $id, 'infoboxes', $count ], 'labels', $l ); } } } diff --git a/controllers/PortableInfoboxParserTagController.class.php b/controllers/PortableInfoboxParserTagController.class.php index 3d591cb..aa4de5c 100644 --- a/controllers/PortableInfoboxParserTagController.class.php +++ b/controllers/PortableInfoboxParserTagController.class.php @@ -134,7 +134,7 @@ class PortableInfoboxParserTagController extends WikiaController { // (see: PortableInfoboxDataService.class.php) if ( $raw ) { $infoboxes = json_decode( $parserOutput->getProperty( PortableInfoboxDataService::INFOBOXES_PROPERTY_NAME ), true ); - $infoboxes[] = [ 'data' => $raw->getRenderData(), 'sources' => $raw->getSource() ]; + $infoboxes[] = [ 'data' => $raw->getRenderData(), 'sources' => $raw->getSource(), 'labels' => $raw->getSourceLabel() ]; $parserOutput->setProperty( PortableInfoboxDataService::INFOBOXES_PROPERTY_NAME, json_encode( $infoboxes ) ); } } diff --git a/services/Parser/Nodes/Node.php b/services/Parser/Nodes/Node.php index 5ac67d9..270894d 100644 --- a/services/Parser/Nodes/Node.php +++ b/services/Parser/Nodes/Node.php @@ -30,6 +30,10 @@ class Node { return $this->extractSourceFromNode( $this->xmlNode ); } + public function getSourceLabel() { + return \Sanitizer::stripAllTags( $this->getInnerValue( $this->xmlNode->{self::LABEL_TAG_NAME} ) ); + } + /** * @return ExternalParser */ @@ -143,6 +147,24 @@ class Node { return array_values( $uniqueParams ); } + protected function getSourceLabelForChildren() { + /** @var Node $item */ + $result = [ ]; + foreach ( $this->getChildNodes() as $item ) { + $label = $item->getSourceLabel(); + if ( is_array( $label ) ) { + $result = array_merge( $result, $label ); + } else { + $source = $item->getSource()[0]; + if ( !empty( $source ) && !empty( $source ) ) { + $result[$source] = $label; + } + } + } + + return $result; + } + protected function getValueWithDefault( \SimpleXMLElement $xmlNode ) { $value = $this->extractDataFromSource( $xmlNode ); if ( !$value && $xmlNode->{self::DEFAULT_TAG_NAME} ) { diff --git a/services/Parser/Nodes/NodeData.php b/services/Parser/Nodes/NodeData.php index a4a655a..4d60177 100644 --- a/services/Parser/Nodes/NodeData.php +++ b/services/Parser/Nodes/NodeData.php @@ -13,4 +13,8 @@ class NodeData extends Node { return $this->data; } + + public function getSourceLabel() { + return \Sanitizer::stripAllTags( $this->getInnerValue( $this->xmlNode->{self::LABEL_TAG_NAME} ) ); + } } diff --git a/services/Parser/Nodes/NodeGroup.php b/services/Parser/Nodes/NodeGroup.php index bcdcd1c..f5c6945 100644 --- a/services/Parser/Nodes/NodeGroup.php +++ b/services/Parser/Nodes/NodeGroup.php @@ -74,6 +74,10 @@ class NodeGroup extends Node { return $this->getSourceForChildren(); } + public function getSourceLabel() { + return $this->getSourceLabelForChildren(); + } + protected function showIncomplete() { return strcasecmp( $this->getDisplay(), self::SHOW_INCOMPLETE_OPTION ) === 0; } diff --git a/services/Parser/Nodes/NodeInfobox.php b/services/Parser/Nodes/NodeInfobox.php index 464f9c4..a685d8b 100644 --- a/services/Parser/Nodes/NodeInfobox.php +++ b/services/Parser/Nodes/NodeInfobox.php @@ -43,4 +43,8 @@ class NodeInfobox extends Node { public function getSource() { return $this->getSourceForChildren(); } + + public function getSourceLabel() { + return $this->getSourceLabelForChildren(); + } } From 88030ff0d285dade1a36b5d358a951d3f1f14fb7 Mon Sep 17 00:00:00 2001 From: Lukasz Konieczny Date: Thu, 31 Mar 2016 10:00:03 +0000 Subject: [PATCH 2/9] CE-3554: Add unit tests for extracting labels --- tests/PortableInfoboxTemplatesHelperTest.php | 4 +-- tests/nodes/NodeDataTest.php | 26 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/tests/PortableInfoboxTemplatesHelperTest.php b/tests/PortableInfoboxTemplatesHelperTest.php index 8ee7a67..4c8ba37 100644 --- a/tests/PortableInfoboxTemplatesHelperTest.php +++ b/tests/PortableInfoboxTemplatesHelperTest.php @@ -24,9 +24,9 @@ class PortableInfoboxTemplatesHelperTest extends WikiaBaseTest { return [ [ 'test', false ], [ '', - [ [ 'data' => [ ], 'sources' => [ 'test' ] ] ] ], + [ [ 'data' => [ ], 'sources' => [ 'test' ], 'labels' => [ 'test' => 1 ] ] ] ], [ '', false ], - [ ' ', [ [ 'data' => [ ], 'sources' => [ ] ] ] ], + [ ' ', [ [ 'data' => [ ], 'sources' => [ ], 'labels' => [ ] ] ] ], [ '', false ], [ '', false ], ]; diff --git a/tests/nodes/NodeDataTest.php b/tests/nodes/NodeDataTest.php index 6fe9065..c21d353 100644 --- a/tests/nodes/NodeDataTest.php +++ b/tests/nodes/NodeDataTest.php @@ -38,6 +38,32 @@ class NodeDataTest extends WikiaBaseTest { ]; } + /** + * @covers \Wikia\PortableInfobox\Parser\Nodes\Node::getSourceLabel + * @dataProvider sourceLabelDataProvider + * + * @param $markup + * @param $params + * @param $expected + */ + public function testSourceLabel( $markup, $params, $expected ) { + $node = \Wikia\PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params ); + + $this->assertEquals( $expected, $node->getSourceLabel() ); + } + + public function sourceLabelDataProvider() { + return [ + [ '', [ ], '' ], + [ '{{{test}}}', + [ ], '' ], + [ '{{{test}}}', + [ ], '{{{test}}}' ], + [ '', [ ], 'testLabel' ], + [ '', [ ], '' ], + ]; + } + /** * @covers \Wikia\PortableInfobox\Parser\Nodes\Node::getExternalParser * @covers \Wikia\PortableInfobox\Parser\Nodes\Node::setExternalParser From 4f11b96e4887d6513c20b1c67b9b29242d942703 Mon Sep 17 00:00:00 2001 From: Lukasz Konieczny Date: Fri, 1 Apr 2016 11:07:30 +0000 Subject: [PATCH 3/9] CE-3554: Changes after CR --- controllers/ApiQueryPortableInfobox.class.php | 11 ++++---- ...rtableInfoboxParserTagController.class.php | 2 +- services/Parser/Nodes/Node.php | 19 +++++++------- services/Parser/Nodes/NodeData.php | 4 --- tests/PortableInfoboxTemplatesHelperTest.php | 4 +-- tests/nodes/NodeDataTest.php | 25 +++++++++++++++---- 6 files changed, 37 insertions(+), 28 deletions(-) diff --git a/controllers/ApiQueryPortableInfobox.class.php b/controllers/ApiQueryPortableInfobox.class.php index 7281766..6d329f9 100644 --- a/controllers/ApiQueryPortableInfobox.class.php +++ b/controllers/ApiQueryPortableInfobox.class.php @@ -29,13 +29,12 @@ class ApiQueryPortableInfobox extends ApiQueryBase { $pageSet->getResult()->setIndexedTagName( $inf, 'infobox' ); $pageSet->getResult()->addValue( [ 'query', 'pages', $id ], 'infoboxes', $inf ); foreach ( $parsedInfoboxes as $count => $infobox ) { - $s = isset( $infobox[ 'sources' ] ) ? $infobox[ 'sources' ] : [ ]; - $l = isset( $infobox[ 'labels' ] ) ? $infobox[ 'labels' ] : [ ]; + $sl = isset( $infobox[ 'sourcelabels' ] ) ? $infobox[ 'sourcelabels' ] : [ ]; $pageSet->getResult()->addValue( [ 'query', 'pages', $id, 'infoboxes', $count ], 'id', $count ); - $pageSet->getResult()->setIndexedTagName( $s, "source" ); - $pageSet->getResult()->addValue( [ 'query', 'pages', $id, 'infoboxes', $count ], 'sources', $s ); - $pageSet->getResult()->setIndexedTagName( $l, "labels" ); - $pageSet->getResult()->addValue( [ 'query', 'pages', $id, 'infoboxes', $count ], 'labels', $l ); + $pageSet->getResult()->setIndexedTagName( $l, "sourcelabels" ); + $pageSet->getResult()->addValue( + [ 'query', 'pages', $id, 'infoboxes', $count ], 'sourcelabels', $sl + ); } } } diff --git a/controllers/PortableInfoboxParserTagController.class.php b/controllers/PortableInfoboxParserTagController.class.php index aa4de5c..b994ff9 100644 --- a/controllers/PortableInfoboxParserTagController.class.php +++ b/controllers/PortableInfoboxParserTagController.class.php @@ -134,7 +134,7 @@ class PortableInfoboxParserTagController extends WikiaController { // (see: PortableInfoboxDataService.class.php) if ( $raw ) { $infoboxes = json_decode( $parserOutput->getProperty( PortableInfoboxDataService::INFOBOXES_PROPERTY_NAME ), true ); - $infoboxes[] = [ 'data' => $raw->getRenderData(), 'sources' => $raw->getSource(), 'labels' => $raw->getSourceLabel() ]; + $infoboxes[] = [ 'data' => $raw->getRenderData(), 'sourcelabels' => $raw->getSourceLabel() ]; $parserOutput->setProperty( PortableInfoboxDataService::INFOBOXES_PROPERTY_NAME, json_encode( $infoboxes ) ); } } diff --git a/services/Parser/Nodes/Node.php b/services/Parser/Nodes/Node.php index 270894d..7583e9c 100644 --- a/services/Parser/Nodes/Node.php +++ b/services/Parser/Nodes/Node.php @@ -31,7 +31,14 @@ class Node { } public function getSourceLabel() { - return \Sanitizer::stripAllTags( $this->getInnerValue( $this->xmlNode->{self::LABEL_TAG_NAME} ) ); + $source = $this->extractSourceFromNode( $this->xmlNode )[0]; + $label = \Sanitizer::stripAllTags( $this->getInnerValue( $this->xmlNode->{self::LABEL_TAG_NAME} ) ); + + if ( !empty( $source ) ) { + return [ $source => $label ]; + } + + return []; } /** @@ -151,15 +158,7 @@ class Node { /** @var Node $item */ $result = [ ]; foreach ( $this->getChildNodes() as $item ) { - $label = $item->getSourceLabel(); - if ( is_array( $label ) ) { - $result = array_merge( $result, $label ); - } else { - $source = $item->getSource()[0]; - if ( !empty( $source ) && !empty( $source ) ) { - $result[$source] = $label; - } - } + $result = array_merge( $result, $item->getSourceLabel() ); } return $result; diff --git a/services/Parser/Nodes/NodeData.php b/services/Parser/Nodes/NodeData.php index 4d60177..a4a655a 100644 --- a/services/Parser/Nodes/NodeData.php +++ b/services/Parser/Nodes/NodeData.php @@ -13,8 +13,4 @@ class NodeData extends Node { return $this->data; } - - public function getSourceLabel() { - return \Sanitizer::stripAllTags( $this->getInnerValue( $this->xmlNode->{self::LABEL_TAG_NAME} ) ); - } } diff --git a/tests/PortableInfoboxTemplatesHelperTest.php b/tests/PortableInfoboxTemplatesHelperTest.php index 4c8ba37..bc2c87b 100644 --- a/tests/PortableInfoboxTemplatesHelperTest.php +++ b/tests/PortableInfoboxTemplatesHelperTest.php @@ -24,9 +24,9 @@ class PortableInfoboxTemplatesHelperTest extends WikiaBaseTest { return [ [ 'test', false ], [ '', - [ [ 'data' => [ ], 'sources' => [ 'test' ], 'labels' => [ 'test' => 1 ] ] ] ], + [ [ 'data' => [ ], 'sourcelabels' => [ 'test' => 1 ] ] ] ], [ '', false ], - [ ' ', [ [ 'data' => [ ], 'sources' => [ ], 'labels' => [ ] ] ] ], + [ ' ', [ [ 'data' => [ ], 'sourcelabels' => [ ] ] ] ], [ '', false ], [ '', false ], ]; diff --git a/tests/nodes/NodeDataTest.php b/tests/nodes/NodeDataTest.php index c21d353..e773725 100644 --- a/tests/nodes/NodeDataTest.php +++ b/tests/nodes/NodeDataTest.php @@ -54,13 +54,28 @@ class NodeDataTest extends WikiaBaseTest { public function sourceLabelDataProvider() { return [ - [ '', [ ], '' ], + [ '', [ ], ['test' => ''] ], + [ '', [ ], ['test' => ''] ], + [ '', [ ], ['test' => ''] ], [ '<data source="test"><default>{{{test}}}</default></data>', - [ ], '' ], + [ ], ['test' => ''] ], [ '<data source="test"><label source="test">{{{test}}}</label><default>{{{test}}}</default></data>', - [ ], '{{{test}}}' ], - [ '<data source="test"><label>testLabel</label></data>', [ ], 'testLabel' ], - [ '<data></data>', [ ], '' ], + [ ], ['test' => '{{{test}}}'] ], + [ '<data source="test"><label>testLabel</label></data>', [ ], ['test' => 'testLabel'] ], + [ '<data></data>', [ ], [ ] ], + [ '<group><data source="test"><label>labelInsideGroup</label></data></group>', [], ['test' =>'labelInsideGroup'] ], + [ '<group>' . + '<data source="test"><label>labelInsideGroup</label></data>' . + '<data source="test2"><label>labelInsideGroup2</label></data>' . + '</group>', + [], ['test' =>'labelInsideGroup', 'test2' =>'labelInsideGroup2'] ], + [ '<group>' . + '<title source="title"/>' . + '<image source="image"/>' . + '<data source="test"><label>labelInsideGroup</label></data>' . + '<data source="test2"><label>labelInsideGroup2</label></data>' . + '</group>', + [], ['test' =>'labelInsideGroup', 'test2' =>'labelInsideGroup2', 'title' => '', 'image' => ''] ] ]; } From 06fad58042cc0074a650882c9cb4fe88ac228f21 Mon Sep 17 00:00:00 2001 From: Lukasz Konieczny <lukaszk@wikia-inc.com> Date: Fri, 1 Apr 2016 12:54:43 +0000 Subject: [PATCH 4/9] CE-3554: Support more sources --- services/Parser/Nodes/Node.php | 18 +++++++++--- tests/nodes/NodeDataTest.php | 54 +++++++++++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 5 deletions(-) diff --git a/services/Parser/Nodes/Node.php b/services/Parser/Nodes/Node.php index 7583e9c..0090823 100644 --- a/services/Parser/Nodes/Node.php +++ b/services/Parser/Nodes/Node.php @@ -31,14 +31,24 @@ class Node { } public function getSourceLabel() { - $source = $this->extractSourceFromNode( $this->xmlNode )[0]; + $sourceLabels = []; + $sources = $this->extractSourceFromNode( $this->xmlNode ); $label = \Sanitizer::stripAllTags( $this->getInnerValue( $this->xmlNode->{self::LABEL_TAG_NAME} ) ); - if ( !empty( $source ) ) { - return [ $source => $label ]; + if ( count( $sources ) > 1 ) { + foreach ( $sources as $source ) { + if ( !empty( $source ) ) { + $sourceLabel = !empty( $label ) ? "{$label} ({$source})" : $label; + $sourceLabels = array_merge( $sourceLabels, [ $source => $sourceLabel ] ); + } + } + } else { + if ( !empty( $sources[0] ) ) { + return [ $sources[0] => $label ]; + } } - return []; + return $sourceLabels; } /** diff --git a/tests/nodes/NodeDataTest.php b/tests/nodes/NodeDataTest.php index e773725..ce4e8cc 100644 --- a/tests/nodes/NodeDataTest.php +++ b/tests/nodes/NodeDataTest.php @@ -75,7 +75,59 @@ class NodeDataTest extends WikiaBaseTest { '<data source="test"><label>labelInsideGroup</label></data>' . '<data source="test2"><label>labelInsideGroup2</label></data>' . '</group>', - [], ['test' =>'labelInsideGroup', 'test2' =>'labelInsideGroup2', 'title' => '', 'image' => ''] ] + [], ['test' =>'labelInsideGroup', 'test2' =>'labelInsideGroup2', 'title' => '', 'image' => ''] ], + [ '<data source="test"><default>{{{test 2}}}</default></data>', [ ], [ 'test' => '', 'test 2' => '' ] ], + [ '<data source="test1"><default>{{#if: {{{test2|}}}| [[{{{test2}}} with some text]] }}</default></data>', + [ ], [ 'test1' => '', 'test2' => '' ] ], + [ '<data><default>{{#switch: {{{test2|}}}|{{{test3}}}|{{{test4|kdjk|sajdkfj|}}}]] }}</default></data>', + [ ], [ 'test2' => '', 'test3' => '', 'test4' => '' ] ], + [ '<data source="test1">' . + '<format>my {{{test2}}}$$$</format>' . + '<default>{{#switch: {{{test3|}}}|{{{test4}}}|{{{test5|kdjk|sajdkfj|}}}]] }}</default>' . + '</data>', + [ 'test1' => 'blabla' ], [ 'test1' => '', 'test2' => '', 'test3' => '', 'test4' => '', 'test5' => '' ] ], + [ '<data>' . + '<format>my {{{test2}}}$$$</format>' . + '<default>{{#switch: {{{test3|}}}|{{{test4}}}|{{{test5|kdjk|sajdkfj|}}}]] }}</default>' . + '</data>', + [ ], [ 'test2' => '', 'test3' => '', 'test4' => '', 'test5' => '' ] ], + [ '<data source="test1">' . + '<label>label</label>' . + '<default>{{#if: {{{test2|}}}| [[{{{test2}}} with some text]] }}</default>' . + '</data>', + [ ], [ 'test1' => 'label (test1)', 'test2' => 'label (test2)' ] ], + [ '<data>' . + '<label>other label</label>' . + '<default>{{#switch: {{{test2|}}}|{{{test3}}}|{{{test4|kdjk|sajdkfj|}}}]] }}</default>' . + '</data>', + [ ], [ 'test2' => 'other label (test2)', 'test3' => 'other label (test3)', 'test4' => 'other label (test4)' ] ], + [ '<data source="test1">' . + '<label>next label</label>' . + '<format>my {{{test2}}}$$$</format>' . + '<default>{{#switch: {{{test3|}}}|{{{test4}}}|{{{test5|kdjk|sajdkfj|}}}]] }}</default>' . + '</data>', + [ 'test1' => 'blabla' ], + [ + 'test1' => 'next label (test1)', + 'test2' => 'next label (test2)', + 'test3' => 'next label (test3)', + 'test4' => 'next label (test4)', + 'test5' => 'next label (test5)' + ] + ], + [ '<data>' . + '<label>last label</label>' . + '<format>my {{{test2}}}$$$</format>' . + '<default>{{#switch: {{{test3|}}}|{{{test4}}}|{{{test5|kdjk|sajdkfj|}}}]] }}</default>' . + '</data>', + [ ], + [ + 'test2' => 'last label (test2)', + 'test3' => 'last label (test3)', + 'test4' => 'last label (test4)', + 'test5' => 'last label (test5)' + ] + ] ]; } From d340841e171dd58b943116f6995a50f5012475b8 Mon Sep 17 00:00:00 2001 From: Lukasz Konieczny <lukaszk@wikia-inc.com> Date: Tue, 5 Apr 2016 07:27:18 +0000 Subject: [PATCH 5/9] CE-3554: Improve code after CR --- services/Parser/Nodes/Node.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/services/Parser/Nodes/Node.php b/services/Parser/Nodes/Node.php index 0090823..98d5f75 100644 --- a/services/Parser/Nodes/Node.php +++ b/services/Parser/Nodes/Node.php @@ -38,14 +38,12 @@ class Node { if ( count( $sources ) > 1 ) { foreach ( $sources as $source ) { if ( !empty( $source ) ) { - $sourceLabel = !empty( $label ) ? "{$label} ({$source})" : $label; - $sourceLabels = array_merge( $sourceLabels, [ $source => $sourceLabel ] ); + $sourceLabel = !empty( $label ) ? "{$label} ({$source})" : ''; + $sourceLabels[$source] = $sourceLabel; } } - } else { - if ( !empty( $sources[0] ) ) { - return [ $sources[0] => $label ]; - } + } elseif ( !empty( $sources[0] ) ) { + $sourceLabels[$sources[0]] = $label; } return $sourceLabels; From 9f7c54012b2828898bdd92fd6d06c7c80affafec Mon Sep 17 00:00:00 2001 From: Lukasz Konieczny <lukaszk@wikia-inc.com> Date: Tue, 5 Apr 2016 09:58:19 +0000 Subject: [PATCH 6/9] CE-3554: Combine two lines to one --- services/Parser/Nodes/Node.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/services/Parser/Nodes/Node.php b/services/Parser/Nodes/Node.php index 98d5f75..a1b4c2b 100644 --- a/services/Parser/Nodes/Node.php +++ b/services/Parser/Nodes/Node.php @@ -38,8 +38,7 @@ class Node { if ( count( $sources ) > 1 ) { foreach ( $sources as $source ) { if ( !empty( $source ) ) { - $sourceLabel = !empty( $label ) ? "{$label} ({$source})" : ''; - $sourceLabels[$source] = $sourceLabel; + $sourceLabels[$source] = !empty( $label ) ? "{$label} ({$source})" : ''; } } } elseif ( !empty( $sources[0] ) ) { From 1a92b184bb6d258704ad6ff3e52e2051529c4b14 Mon Sep 17 00:00:00 2001 From: Lukasz Konieczny <lukaszk@wikia-inc.com> Date: Thu, 7 Apr 2016 09:27:59 +0000 Subject: [PATCH 7/9] CE-3554: Add fallback for existing infobox page props data --- controllers/ApiQueryPortableInfobox.class.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/controllers/ApiQueryPortableInfobox.class.php b/controllers/ApiQueryPortableInfobox.class.php index 6d329f9..4e75028 100644 --- a/controllers/ApiQueryPortableInfobox.class.php +++ b/controllers/ApiQueryPortableInfobox.class.php @@ -29,7 +29,10 @@ class ApiQueryPortableInfobox extends ApiQueryBase { $pageSet->getResult()->setIndexedTagName( $inf, 'infobox' ); $pageSet->getResult()->addValue( [ 'query', 'pages', $id ], 'infoboxes', $inf ); foreach ( $parsedInfoboxes as $count => $infobox ) { - $sl = isset( $infobox[ 'sourcelabels' ] ) ? $infobox[ 'sourcelabels' ] : [ ]; + $sl = isset( $infobox[ 'sourcelabels' ] ) ? + $infobox[ 'sourcelabels' ] : + $this->sourceLabelsFallback( $infobox, $articleTitle ); + $pageSet->getResult()->addValue( [ 'query', 'pages', $id, 'infoboxes', $count ], 'id', $count ); $pageSet->getResult()->setIndexedTagName( $l, "sourcelabels" ); $pageSet->getResult()->addValue( @@ -39,4 +42,18 @@ class ApiQueryPortableInfobox extends ApiQueryBase { } } } + + private function sourceLabelsFallback( $infobox, $title ) { + global $wgCityId; + + Wikia\Logger\WikiaLogger::instance()->info( 'Portable Infobox ApiQuery sourcelabels fallback' ); + + $task = new Wikia\Tasks\Tasks\RefreshLinksForTitleTask(); + $task->title( $title ); + $task->call( 'refresh' ); + $task->wikiId( $wgCityId ); + $task->queue(); + + return $infobox[ 'sources' ] ? array_fill_keys( $infobox[ 'sources' ], '' ) : [ ]; + } } From 6cc68eaa19b64c582f0e5b26e9c7a3a7b9bb50e0 Mon Sep 17 00:00:00 2001 From: Lukasz Konieczny <lukaszk@wikia-inc.com> Date: Thu, 7 Apr 2016 09:29:26 +0000 Subject: [PATCH 8/9] CE-3554: Add doc and comment --- controllers/ApiQueryPortableInfobox.class.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/controllers/ApiQueryPortableInfobox.class.php b/controllers/ApiQueryPortableInfobox.class.php index 4e75028..045d7a3 100644 --- a/controllers/ApiQueryPortableInfobox.class.php +++ b/controllers/ApiQueryPortableInfobox.class.php @@ -43,6 +43,14 @@ class ApiQueryPortableInfobox extends ApiQueryBase { } } + /** + * We still have old infobox sources in page properties, so we need this fallback. + * Monitor kibana and remove it after logs stop appear + * + * @param $infobox + * @param $title + * @return array + */ private function sourceLabelsFallback( $infobox, $title ) { global $wgCityId; From 56e5697cfd643951292d27913560f18ef7fb7699 Mon Sep 17 00:00:00 2001 From: Lukasz Konieczny <lukaszk@wikia-inc.com> Date: Thu, 7 Apr 2016 10:24:18 +0000 Subject: [PATCH 9/9] CE-3554: Fix typo --- controllers/ApiQueryPortableInfobox.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/ApiQueryPortableInfobox.class.php b/controllers/ApiQueryPortableInfobox.class.php index 045d7a3..5c7d0a2 100644 --- a/controllers/ApiQueryPortableInfobox.class.php +++ b/controllers/ApiQueryPortableInfobox.class.php @@ -34,7 +34,7 @@ class ApiQueryPortableInfobox extends ApiQueryBase { $this->sourceLabelsFallback( $infobox, $articleTitle ); $pageSet->getResult()->addValue( [ 'query', 'pages', $id, 'infoboxes', $count ], 'id', $count ); - $pageSet->getResult()->setIndexedTagName( $l, "sourcelabels" ); + $pageSet->getResult()->setIndexedTagName( $sl, "sourcelabels" ); $pageSet->getResult()->addValue( [ 'query', 'pages', $id, 'infoboxes', $count ], 'sourcelabels', $sl );