2015-06-10 09:28:33 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
2015-06-16 09:00:39 +00:00
|
|
|
class ApiQueryPortableInfobox extends ApiQueryBase {
|
2015-06-10 09:28:33 +00:00
|
|
|
|
|
|
|
public function __construct( $query, $moduleName ) {
|
|
|
|
parent::__construct( $query, $moduleName, 'ib' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute() {
|
2015-06-11 16:08:51 +00:00
|
|
|
$this->runOnPageSet( $this->getPageSet() );
|
2015-06-10 09:28:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getVersion() {
|
|
|
|
return __CLASS__ . '$Id$';
|
|
|
|
}
|
|
|
|
|
2015-06-11 16:08:51 +00:00
|
|
|
protected function runOnPageSet( ApiPageSet $pageSet ) {
|
2015-08-19 20:00:27 +00:00
|
|
|
$articles = $pageSet->getGoodTitles();
|
2015-08-18 11:29:51 +00:00
|
|
|
|
2015-08-20 14:45:46 +00:00
|
|
|
foreach ( $articles as $id => $articleTitle ) {
|
2015-08-19 20:00:27 +00:00
|
|
|
$parsedInfoboxes = PortableInfoboxDataService::newFromTitle( $articleTitle )->getData();
|
2015-08-18 11:29:51 +00:00
|
|
|
|
2015-08-19 20:00:27 +00:00
|
|
|
if ( is_array( $parsedInfoboxes ) && count( $parsedInfoboxes ) ) {
|
2015-06-11 16:08:51 +00:00
|
|
|
$inf = [ ];
|
2016-12-09 13:01:49 +00:00
|
|
|
|
2015-08-18 18:38:06 +00:00
|
|
|
foreach ( array_keys( $parsedInfoboxes ) as $k => $v ) {
|
2015-06-11 16:08:51 +00:00
|
|
|
$inf[ $k ] = [ ];
|
|
|
|
}
|
2016-12-09 13:01:49 +00:00
|
|
|
|
2015-06-11 16:08:51 +00:00
|
|
|
$pageSet->getResult()->setIndexedTagName( $inf, 'infobox' );
|
|
|
|
$pageSet->getResult()->addValue( [ 'query', 'pages', $id ], 'infoboxes', $inf );
|
2016-04-07 09:27:59 +00:00
|
|
|
|
2016-12-09 13:01:49 +00:00
|
|
|
foreach ( $parsedInfoboxes as $count => $infobox ) {
|
2015-06-11 16:08:51 +00:00
|
|
|
$pageSet->getResult()->addValue( [ 'query', 'pages', $id, 'infoboxes', $count ], 'id', $count );
|
2016-12-09 09:59:03 +00:00
|
|
|
|
2016-12-09 15:55:42 +00:00
|
|
|
$pageSet->getResult()->addValue(
|
|
|
|
[ 'query', 'pages', $id, 'infoboxes', $count ],
|
|
|
|
'parser_tag_version',
|
|
|
|
$infobox['parser_tag_version']
|
|
|
|
);
|
2016-12-09 13:01:49 +00:00
|
|
|
|
2016-12-09 15:55:42 +00:00
|
|
|
// FIXME ?format=xml throws error
|
|
|
|
$pageSet->getResult()->setIndexedTagName( $infobox['metadata'], 'metadata' );
|
2016-04-01 11:07:30 +00:00
|
|
|
$pageSet->getResult()->addValue(
|
2016-12-09 15:55:42 +00:00
|
|
|
[ 'query', 'pages', $id, 'infoboxes', $count ], 'metadata', $infobox['metadata']
|
2016-04-01 11:07:30 +00:00
|
|
|
);
|
2015-06-11 16:08:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-10 09:28:33 +00:00
|
|
|
}
|
|
|
|
}
|