getMain()->createPrinterByName('json'); } public function execute() { // Get parameters extract( $this->extractRequestParams() ); $retval = ''; #check for columns information if( !is_null($columns) ) { $columns = explode( "|", $columns ); } #get the exhibit if( preg_match( '/^Infobox/', $name ) == 1 ) { $name = substr( $name, 8 ); } $type = str_replace( ' ', '_', trim($name) ); $infobox = new InfoboxUtils(); $infobox->setupPP(); $exhibit = $infobox->getByType( $type ); #format the exhibit $result = $this->getResult(); $items = array(); foreach( $exhibit->ex as $label => $elements ) { $dom = new DOMDocument(); $dom->loadXML( "$elements" ); $nodelist = $dom->getElementsByTagName( 'part' ); $item = array(); for( $i=0; $i<$nodelist->length; $i++ ) { $elname = trim($nodelist->item($i)->firstChild->nodeValue); $elvalue = trim($nodelist->item($i)->lastChild->nodeValue); if( !is_null( $columns ) ) { if( in_array( $elname, $columns ) ) { $item[$elname] = $elvalue; } } else { #columns param does not exist, add all fields $item[$elname] = $elvalue; } } #add type & label if( !isset($item['type']) ) { $item['type'] = $type; } if( !isset($item['label']) ) { $item['label'] = $label; } $items[] = $item; } $result->setIndexedTagName($items, 'ex'); $result->addValue( null, 'items', $items ); } public function getAllowedParams() { return array ( 'name' => array( ApiBase :: PARAM_DFLT => 'Infobox_beer_style', ), 'columns' => null, 'generatexml' => false, ); } public function getParamDescription() { return array ( 'name' => 'Infobox type, aka template name', 'columns' => 'Columns of the infobox you want', 'generatexml' => 'Generate XML parse tree', ); } public function getDescription() { return 'This module gets all infoboxes belonging to a template'; } protected function getExamples() { return array ( 'api.php?action=getinfoboxes&name=Infobox_Aircraft' ); } public function getVersion() { return __CLASS__ . ': $Id: ApiGetInfoboxes.php 1 2008-11-02 cmoose $'; } }