adding DataService class

This commit is contained in:
jacek 2015-06-09 12:14:00 +02:00
parent 40c2fc00b8
commit 08bcb2aa36

View file

@ -0,0 +1,30 @@
<?php
class PortableInfoboxDataService {
const IMAGE_FIELD_TYPE = 'image';
public function getInfoboxDataByTitle( $title ) {
$data = [];
if ( $title && $title->exists() ) {
$data = Article::newFromTitle( $title, RequestContext::getMain() )
//on empty parser cache this should be regenerated, see WikiPage.php:2996
->getParserOutput()
->getProperty( PortableInfoboxParserTagController::INFOBOXES_PROPERTY_NAME );
}
return $data;
}
public function getImageListFromInfoboxData( $data ) {
$images = [];
foreach ( $data as $infobox ) {
foreach ( $infobox as $field ) {
if ( $field['type'] == self::IMAGE_FIELD_TYPE && isset( $field['data'] ) && !empty( $field['data']['key'] ) ) {
$images[ $field['data']['key'] ] = true;
}
}
}
return array_keys( $images );
}
}