mirror of
https://github.com/Universal-Omega/PortableInfobox.git
synced 2024-11-15 20:09:44 +00:00
adding DataService class
This commit is contained in:
parent
40c2fc00b8
commit
08bcb2aa36
30
services/PortableInfoboxDataService.class.php
Normal file
30
services/PortableInfoboxDataService.class.php
Normal 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 );
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue