コード例 #1
0
 /**
  * Check if infobox (div element or table which contains 'infobox' string in class attribute)
  * exists in first article section, and extract it from this section
  *
  * @param Parser $parser Parser instance
  * @param integer $section number of section in article text
  * @param string $content reference to section content
  * @param boolean $showEditLinks  should add edit link
  * @return bool
  */
 public static function onParserSectionCreate($parser, $section, &$content, $showEditLinks)
 {
     // skip if we're not parsing for venus
     if (!F::app()->checkSkin('venus')) {
         return true;
     }
     try {
         if (self::isInfoboxInFirstSection($parser, $section, $content)) {
             $infoboxExtractor = new InfoboxExtractor($content);
             $dom = $infoboxExtractor->getDOMDocument();
             $nodes = $infoboxExtractor->getInfoboxNodes();
             $node = $nodes->item(0);
             if ($node instanceof DOMElement) {
                 $body = $dom->documentElement->firstChild;
                 // replace extracted infobox with a dummy element to prevent newlines from creating empty paragraphs (CON-2166)
                 // <table infobox-placeholder="1"></table>
                 $placeholder = $dom->createElement('table');
                 $placeholder->setAttribute('infobox-placeholder', 'true');
                 $node->parentNode->insertBefore($placeholder, $node);
                 // perform a magic around infobox wrapper
                 $node = $infoboxExtractor->clearInfoboxStyles($node);
                 $infoboxWrapper = $infoboxExtractor->wrapInfobox($node, 'infoboxWrapper', 'infobox-wrapper');
                 $infoboxContainer = $infoboxExtractor->wrapInfobox($infoboxWrapper, 'infoboxContainer', 'infobox-container');
                 // move infobox to the beginning of article content
                 $infoboxExtractor->insertNode($body, $infoboxContainer, true);
                 $content = $dom->saveHTML();
                 $parser->getOutput()->addModules('ext.wikia.venus.article.infobox');
             }
         }
     } catch (DOMException $e) {
         // log exceptions
         WikiaLogger::instance()->error(__METHOD__, ['exception' => $e]);
     }
     return true;
 }
コード例 #2
0
 /**
  * @dataProvider testGetStylesArrayDataProvider
  */
 public function testGetStylesArray($styles, $expected)
 {
     $infoboxExtractor = new InfoboxExtractor('');
     $stylesArray = $infoboxExtractor->getStylesArray($styles);
     $this->assertEquals($expected, $stylesArray);
 }
コード例 #3
0
 /**
  * Create default query to extract infobox nodes
  */
 public function setDefaultQuery()
 {
     self::$defaultQuery = "((//div|//table)[contains(translate(@class, '" . strtoupper(self::INFOBOX_CLASS_NAME) . "', '" . self::INFOBOX_CLASS_NAME . "'), '" . self::INFOBOX_CLASS_NAME . "')])[1]";
 }