DAT-2875 infobox api change, action query prop for infobox introduced

This commit is contained in:
idradm 2015-06-11 18:08:51 +02:00
parent 29f713997c
commit c86e795f48
2 changed files with 33 additions and 18 deletions

View file

@ -8,19 +8,7 @@ class ApiQueryPortableInfobox extends ApiQueryGeneratorBase {
}
public function execute() {
$articles = array_map( function ( Title $item ) {
return Article::newFromTitle( $item, RequestContext::getMain() );
}, array_filter( $this->getPageSet()->getGoodTitles(), function ( Title $el ) {
return $el->inNamespace( NS_TEMPLATE );
} ) );
/**
* @var Article $article
*/
foreach ( $articles as $id => $article ) {
dd( $article->getParserOutput()->getProperty( PortableInfoboxParserTagController::INFOBOXES_PROPERTY_NAME ) );
}
dd( $articles );
$this->getResult()->addValue( null, $this->getModuleName(), $this->extractRequestParams() );
$this->runOnPageSet( $this->getPageSet() );
}
public function getVersion() {
@ -34,6 +22,33 @@ class ApiQueryPortableInfobox extends ApiQueryGeneratorBase {
* this object
*/
public function executeGenerator( $resultPageSet ) {
// TODO: Implement executeGenerator() method.
$this->runOnPageSet( $resultPageSet );
}
protected function runOnPageSet( ApiPageSet $pageSet ) {
$articles = array_map( function ( Title $item ) {
return Article::newFromTitle( $item, RequestContext::getMain() );
}, $pageSet->getGoodTitles() );
/**
* @var Article $article
*/
foreach ( $articles as $id => $article ) {
$d = $article->getParserOutput()->getProperty( PortableInfoboxParserTagController::INFOBOXES_PROPERTY_NAME );
if ( is_array( $d ) ) {
$inf = [ ];
foreach ( array_keys( $d ) as $k => $v ) {
$inf[ $k ] = [ ];
}
$pageSet->getResult()->setIndexedTagName( $inf, 'infobox' );
$pageSet->getResult()->addValue( [ 'query', 'pages', $id ], 'infoboxes', $inf );
foreach ( $d as $count => $infobox ) {
$s = isset( $infobox[ 'sources' ] ) ? $infobox[ 'sources' ] : [ ];
$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 );
}
}
}
}
}

View file

@ -72,7 +72,7 @@ class PortableInfoboxParserTagController extends WikiaController {
$data = $infoboxNode->getRenderData();
//save for later api usage
$this->saveToParserOutput( $parser->getOutput(), $data );
$this->saveToParserOutput( $parser->getOutput(), $infoboxNode );
$theme = $this->getThemeWithDefault( $params, $frame );
@ -117,10 +117,10 @@ class PortableInfoboxParserTagController extends WikiaController {
return strtr( $text, $this->markers );
}
protected function saveToParserOutput( \ParserOutput $parserOutput, $raw ) {
if ( !empty( $raw ) ) {
protected function saveToParserOutput( \ParserOutput $parserOutput, Nodes\NodeInfobox $raw ) {
if ( $raw ) {
$infoboxes = $parserOutput->getProperty( self::INFOBOXES_PROPERTY_NAME );
$infoboxes[ ] = $raw;
$infoboxes[ ] = [ 'data' => $raw->getRenderData(), 'sources' => $raw->getSource() ];
$parserOutput->setProperty( self::INFOBOXES_PROPERTY_NAME, $infoboxes );
}
}