public function getDetails()
 {
     $pageid = $this->getRequiredParam('pageid');
     $title = Title::newFromID($pageid);
     $data = PortableInfoboxDataService::newFromTitle($title)->getData();
     $output = isset($data) && is_array($data) ? array_map(function ($infobox) {
         return isset($infobox['data']) ? $infobox['data'] : $infobox;
     }, $data) : [];
     $this->setResponseData(['items' => $output]);
 }
 public static function onImageServingCollectImages(&$imageNamesArray, $articleTitle)
 {
     if ($articleTitle) {
         $infoboxImages = PortableInfoboxDataService::newFromTitle($articleTitle)->getImages();
         if (!empty($infoboxImages)) {
             $imageNamesArray = array_merge($infoboxImages, (array) $imageNamesArray);
         }
     }
     return true;
 }
 protected function loadImagesFromInfoboxes($articleIds)
 {
     wfProfileIn(__METHOD__);
     $images = [];
     foreach ($articleIds as $id) {
         $images = array_merge($images, PortableInfoboxDataService::newFromPageID($id)->getImages());
     }
     if ($images) {
         $details = $this->loadImagesMetadata($images);
         foreach ($details as $name => $row) {
             //set popularity to one, to trick image serving
             $this->addImageDetails($row->img_name, '1', $row->img_width, $row->img_height, $row->img_minor_mime);
         }
     }
     wfProfileOut(__METHOD__);
 }
 public function testConstructor()
 {
     $service = PortableInfoboxDataService::newFromPageID(null);
     $result = $service->getData();
     $this->assertEquals([], $result);
 }
 public static function titleHasPortableInfobox(Title $title)
 {
     $portableData = PortableInfoboxDataService::newFromTitle($title)->getData();
     return !empty($portableData);
 }