PortableInfobox/controllers/ApiQueryPortableInfobox.class.php

41 lines
1.3 KiB
PHP
Raw Normal View History

<?php
class ApiQueryPortableInfobox extends ApiQueryBase {
public function __construct( $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'ib' );
}
public function execute() {
$this->runOnPageSet( $this->getPageSet() );
}
public function getVersion() {
return __CLASS__ . '$Id$';
}
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-19 20:00:27 +00:00
foreach ( $articles as $articleTitle ) {
$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 ) ) {
$inf = [ ];
2015-08-18 18:38:06 +00:00
foreach ( array_keys( $parsedInfoboxes ) as $k => $v ) {
$inf[ $k ] = [ ];
}
$pageSet->getResult()->setIndexedTagName( $inf, 'infobox' );
$pageSet->getResult()->addValue( [ 'query', 'pages', $id ], 'infoboxes', $inf );
2015-08-18 11:29:51 +00:00
foreach ( $parsedInfoboxes 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 );
}
}
}
}
}