runOnPageSet( $this->getPageSet() ); } public function getVersion() { return __CLASS__ . '$Id$'; } protected function runOnPageSet( ApiPageSet $pageSet ) { $articles = $pageSet->getGoodTitles(); foreach ( $articles as $id => $articleTitle ) { $parsedInfoboxes = PortableInfoboxDataService::newFromTitle( $articleTitle )->getData(); if ( is_array( $parsedInfoboxes ) && count( $parsedInfoboxes ) ) { $inf = [ ]; foreach ( array_keys( $parsedInfoboxes ) as $k => $v ) { $inf[ $k ] = [ ]; } $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' ] : [ ]; $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 ); } } } } }