diff --git a/PortableInfobox.setup.php b/PortableInfobox.setup.php index e8cebd0..3fab3cd 100644 --- a/PortableInfobox.setup.php +++ b/PortableInfobox.setup.php @@ -49,6 +49,7 @@ $wgAutoloadClasses[ 'PortableInfoboxHooks' ] = $dir . 'PortableInfoboxHooks.clas // hooks $wgHooks[ 'ParserFirstCallInit' ][] = 'PortableInfoboxParserTagController::parserTagInit'; $wgHooks['BeforePageDisplay'][] = 'PortableInfoboxHooks::onBeforePageDisplay'; +$wgHooks['ParserAfterTidy'][] = 'PortableInfoboxParserTagController::replaceInfoboxMarkers'; // i18n mapping $wgExtensionMessagesFiles[ 'PortableInfobox' ] = $dir . 'PortableInfobox.i18n.php'; diff --git a/controllers/PortableInfoboxParserTagController.class.php b/controllers/PortableInfoboxParserTagController.class.php index 9f33623..7001ee8 100644 --- a/controllers/PortableInfoboxParserTagController.class.php +++ b/controllers/PortableInfoboxParserTagController.class.php @@ -4,6 +4,21 @@ class PortableInfoboxParserTagController extends WikiaController { const PARSER_TAG_NAME = 'infobox'; const INFOBOXES_PROPERTY_NAME = 'infoboxes'; + private $count = 0; + private $markers = [ ]; + + protected static $instance; + + /** + * @return PortableInfoboxParserTagController + */ + public static function getInstance() { + if ( !isset( static::$instance ) ) { + static::$instance = new PortableInfoboxParserTagController(); + } + return static::$instance; + } + /** * @desc Parser hook: used to register parser tag in MW * @@ -11,7 +26,17 @@ class PortableInfoboxParserTagController extends WikiaController { * @return bool */ public static function parserTagInit( Parser $parser ) { - $parser->setHook( self::PARSER_TAG_NAME, [ new static(), 'renderInfobox' ] ); + $parser->setHook( self::PARSER_TAG_NAME, [ static::getInstance(), 'renderInfobox' ] ); + return true; + } + + /** + * Parser hook: used to replace infobox markes put on rendering + * @param $text + * @return string + */ + public static function replaceInfoboxMarkers( &$parser, &$text ) { + $text = static::getInstance()->replaceMarkers( $text ); return true; } @@ -25,6 +50,7 @@ class PortableInfoboxParserTagController extends WikiaController { * @returns String $html */ public function renderInfobox( $text, $params, $parser, $frame ) { + $this->count++; $markup = '<' . self::PARSER_TAG_NAME . '>' . $text . ''; $infoboxParser = new Wikia\PortableInfobox\Parser\XmlParser( $frame->getNamedArguments() ); @@ -43,7 +69,13 @@ class PortableInfoboxParserTagController extends WikiaController { $renderer = new PortableInfoboxRenderService(); $renderedValue = $renderer->renderInfobox( $data ); - return [ $renderedValue, 'markerType' => 'general' ]; + $marker = $parser->uniqPrefix() . "-" . self::PARSER_TAG_NAME . "-{$this->count}-QINU"; + $this->markers[ $marker ] = $renderedValue; + return [ $marker, 'markerType' => 'nowiki' ]; + } + + public function replaceMarkers( $text ) { + return strtr( $text, $this->markers ); } private function renderUnimplementedTagErrorMesssage( $tagName ) {