mirror of
https://github.com/Universal-Omega/PortableInfobox.git
synced 2024-11-15 20:09:44 +00:00
Merge pull request #10117 from Wikia/CE-3554
CE-3554: Improve infobox input fields labels in VE dialog
This commit is contained in:
commit
e8c9a1611a
|
@ -29,12 +29,39 @@ 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' ] : [ ];
|
||||
$sl = isset( $infobox[ 'sourcelabels' ] ) ?
|
||||
$infobox[ 'sourcelabels' ] :
|
||||
$this->sourceLabelsFallback( $infobox, $articleTitle );
|
||||
|
||||
$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( $sl, "sourcelabels" );
|
||||
$pageSet->getResult()->addValue(
|
||||
[ 'query', 'pages', $id, 'infoboxes', $count ], 'sourcelabels', $sl
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
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' ], '' ) : [ ];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(), 'sourcelabels' => $raw->getSourceLabel() ];
|
||||
$parserOutput->setProperty( PortableInfoboxDataService::INFOBOXES_PROPERTY_NAME, json_encode( $infoboxes ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,24 @@ class Node {
|
|||
return $this->extractSourceFromNode( $this->xmlNode );
|
||||
}
|
||||
|
||||
public function getSourceLabel() {
|
||||
$sourceLabels = [];
|
||||
$sources = $this->extractSourceFromNode( $this->xmlNode );
|
||||
$label = \Sanitizer::stripAllTags( $this->getInnerValue( $this->xmlNode->{self::LABEL_TAG_NAME} ) );
|
||||
|
||||
if ( count( $sources ) > 1 ) {
|
||||
foreach ( $sources as $source ) {
|
||||
if ( !empty( $source ) ) {
|
||||
$sourceLabels[$source] = !empty( $label ) ? "{$label} ({$source})" : '';
|
||||
}
|
||||
}
|
||||
} elseif ( !empty( $sources[0] ) ) {
|
||||
$sourceLabels[$sources[0]] = $label;
|
||||
}
|
||||
|
||||
return $sourceLabels;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ExternalParser
|
||||
*/
|
||||
|
@ -143,6 +161,16 @@ class Node {
|
|||
return array_values( $uniqueParams );
|
||||
}
|
||||
|
||||
protected function getSourceLabelForChildren() {
|
||||
/** @var Node $item */
|
||||
$result = [ ];
|
||||
foreach ( $this->getChildNodes() as $item ) {
|
||||
$result = array_merge( $result, $item->getSourceLabel() );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function getValueWithDefault( \SimpleXMLElement $xmlNode ) {
|
||||
$value = $this->extractDataFromSource( $xmlNode );
|
||||
if ( !$value && $xmlNode->{self::DEFAULT_TAG_NAME} ) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -43,4 +43,8 @@ class NodeInfobox extends Node {
|
|||
public function getSource() {
|
||||
return $this->getSourceForChildren();
|
||||
}
|
||||
|
||||
public function getSourceLabel() {
|
||||
return $this->getSourceLabelForChildren();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,9 +24,9 @@ class PortableInfoboxTemplatesHelperTest extends WikiaBaseTest {
|
|||
return [
|
||||
[ 'test', false ],
|
||||
[ '<includeonly><infobox><data source="test"><label>1</label></data></infobox></includeonly>',
|
||||
[ [ 'data' => [ ], 'sources' => [ 'test' ] ] ] ],
|
||||
[ [ 'data' => [ ], 'sourcelabels' => [ 'test' => 1 ] ] ] ],
|
||||
[ '<includeonly></includeonly><infobox></infobox>', false ],
|
||||
[ '<includeonly><infobox></infobox></includeonly> ', [ [ 'data' => [ ], 'sources' => [ ] ] ] ],
|
||||
[ '<includeonly><infobox></infobox></includeonly> ', [ [ 'data' => [ ], 'sourcelabels' => [ ] ] ] ],
|
||||
[ '<nowiki><includeonly><infobox></infobox></includeonly></nowiki>', false ],
|
||||
[ '<includeonly><nowiki><infobox></infobox></nowiki></includeonly>', false ],
|
||||
];
|
||||
|
|
|
@ -38,6 +38,99 @@ 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 [
|
||||
[ '<data source="test"></data>', [ ], ['test' => ''] ],
|
||||
[ '<image source="test"/>', [ ], ['test' => ''] ],
|
||||
[ '<title source="test"/>', [ ], ['test' => ''] ],
|
||||
[ '<data source="test"><default>{{{test}}}</default></data>',
|
||||
[ ], ['test' => ''] ],
|
||||
[ '<data source="test"><label source="test">{{{test}}}</label><default>{{{test}}}</default></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' => ''] ],
|
||||
[ '<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)'
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Wikia\PortableInfobox\Parser\Nodes\Node::getExternalParser
|
||||
* @covers \Wikia\PortableInfobox\Parser\Nodes\Node::setExternalParser
|
||||
|
|
Loading…
Reference in a new issue