'ApiGetInfoboxes' ); function wfSetupInfoboxHook() { global $wgParser, $wgHooks; if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) { $wgHooks['ParserFirstCallInit'][] = 'registerInfoboxItems'; } else { if ( class_exists( 'StubObject' ) && !StubObject::isRealObject( $wgParser ) ) { $wgParser->_unstub(); } $wgParser->setHook( 'unbox', 'getExhibitTable' ); $defaults = InfoboxUtils::getPPparams(); $wgParser->setExhibitOptions( $defaults ); } } /* * Register the Hook only when the parser is used * Register exhibit ParserOptions for caching needs */ function registerInfoboxItems( &$parser ) { global $wgHooks; $parser->setHook( 'unbox', 'getExhibitTable' ); $defaults = InfoboxUtils::buildDefaultPPparams(); $parser->setExhibitOptions( $defaults ); $wgHooks['RunUnboxCache'][] = array( 'cacheInfoboxOnMatch' ); return true; } /* * Builds the final table as html for the * tag. */ function getExhibitTable( $data ) { $infobox = new InfoboxUtils(); $infobox->setupPP(); $args = $infobox->parseArgs( $data ); $exhibit = $infobox->getByType( $args['type'] ); $table = $infobox->buildTable( $exhibit, $args ); return $table; } function cacheInfoboxOnMatch( $parser, $element, $params, $ibox, $type ) { #remove spaces before caching $type = str_replace( ' ', '_', trim($type) ); if( $params['outofcycle'] ) { #Doing an out-of-cycle preprocess, return text plus label as infoboxOutput #cache first $icache = InfoboxCache::singleton(); $label = $parser->getTitle()->getText(); $infoboxOutput = new InfoboxOutput( $label ); $article = new Article( $parser->getTitle()); #getText()=label, element=data $infoboxOutput->addParts( $element ); $icache->save( $infoboxOutput, $article, $type ); #return object back to preprocessor $ibox = $infoboxOutput; } else { #Regular rendering, caching the infobox for later use global $wgArticle; if( $wgArticle ) { #It's a real article page $icache = InfoboxCache::singleton(); $label = $wgArticle->mTitle->getText(); $infoboxOutput = new InfoboxOutput( $label ); $infoboxOutput->addParts( $element ); $icache->save( $infoboxOutput, $wgArticle, $type ); print_r("savedDOM:$title"); } } return true; }