/** * Strips and renders nowiki, pre, math, hiero * If $render is set, performs necessary rendering operations on plugins * Returns the text, and fills an array with data needed in unstrip() * * @param StripState $state * * @param bool $stripcomments when set, HTML comments <!-- like this --> * will be stripped in addition to other tags. This is important * for section editing, where these comments cause confusion when * counting the sections in the wikisource * * @param array dontstrip contains tags which should not be stripped; * used to prevent stipping of <gallery> when saving (fixes bug 2700) * * @private */ function strip($text, $state, $stripcomments = false, $dontstrip = array()) { global $wgContLang, $wgUseTeX, $wgScriptPath, $wgVersion, $wgHooks, $wgExtensionFunctions; wfProfileIn(__METHOD__); $render = $this->mOutputType == OT_HTML; $uniq_prefix = $this->mUniqPrefix; $commentState = new ReplacementArray(); $nowikiItems = array(); $generalItems = array(); $elements = array_merge(array('nowiki', 'gallery', 'math'), array_keys($this->mTagHooks)); if (isset($wgHooks['ParserFirstCallInit']) && in_array('efSyntaxHighlight_GeSHiSetup', $wgHooks['ParserFirstCallInit']) || isset($wgExtensionFunctions) && in_array('efSyntaxHighlight_GeSHiSetup', $wgExtensionFunctions)) { $elements = array_merge($elements, array('source')); } if (isset($wgHooks['ParserFirstCallInit']) && in_array('wfCite', $wgHooks['ParserFirstCallInit']) || isset($wgExtensionFunctions) && in_array('wfCite', $wgExtensionFunctions)) { $elements = array_merge($elements, array('ref', 'references')); } global $wgRawHtml; if ($wgRawHtml) { $elements[] = 'html'; } # Removing $dontstrip tags from $elements list (currently only 'gallery', fixing bug 2700) foreach ($elements as $k => $v) { if (!in_array($v, $dontstrip)) { continue; } unset($elements[$k]); } $elements = array_unique($elements); $matches = array(); if (version_compare("1.12", $wgVersion, ">")) { $text = Parser::extractTagsAndParams($elements, $text, $matches, $uniq_prefix); } else { $text = self::extractTagsAndParams($elements, $text, $matches, $uniq_prefix); } foreach ($matches as $marker => $data) { list($element, $content, $params, $tag) = $data; if ($render) { $tagName = strtolower($element); wfProfileIn(__METHOD__ . "-render-{$tagName}"); switch ($tagName) { case '!--': // Comment if (substr($tag, -3) == '-->') { $output = $tag; } else { // Unclosed comment in input. // Close it so later stripping can remove it $output = "{$tag}-->"; } break; case 'references': $output = $this->fck_wikiTag('references', $content, $params); break; case 'ref': $output = $this->fck_wikiTag('ref', $content, $params); break; case 'source': $output = $this->fck_wikiTag('source', $content, $params); break; case 'html': if ($wgRawHtml) { $output = $this->fck_wikiTag('html', $content, $params); } break; case 'nowiki': $output = $this->fck_wikiTag('nowiki', $content, $params); // required by FCKeditor break; case 'math': if ($wgUseTeX) { //normal render $output = $wgContLang->armourMath(MathRenderer::renderMath($content)); } else { // show fakeimage $output = '<img _fckfakelement="true" class="FCK__MWMath" _fck_mw_math="' . $content . '" src="' . $wgScriptPath . '/skins/common/images/button_math.png" />'; } break; case 'gallery': $output = $this->fck_wikiTag('gallery', $content, $params); // required by FCKeditor //$output = $this->renderImageGallery( $content, $params ); break; default: if (isset($this->mTagHooks[$tagName])) { $this->fck_mw_taghook = $tagName; // required by FCKeditor $output = call_user_func_array($this->mTagHooks[$tagName], array($content, $params, $this)); } else { throw new MWException("Invalid call hook {$element}"); } } wfProfileOut(__METHOD__ . "-render-{$tagName}"); } else { // Just stripping tags; keep the source $output = $tag; } // Unstrip the output, to support recursive strip() calls $output = $state->unstripBoth($output); if (!$stripcomments && $element == '!--') { $commentState->setPair($marker, $output); } elseif ($element == 'html' || $element == 'nowiki') { # $nowikiItems[$marker] = $output; $state->addNoWiki($marker, $output); } else { # $generalItems[$marker] = $output; $state->addGeneral($marker, $output); } } # Unstrip comments unless explicitly told otherwise. # (The comments are always stripped prior to this point, so as to # not invoke any extension tags / parser hooks contained within # a comment.) if (!$stripcomments) { // Put them all back and forget them $text = $commentState->replace($text); } $this->fck_matches = $matches; wfProfileOut(__METHOD__); return $text; }
/** * strip/replaceVariables/unstrip for preprocessor regression testing * * @param $text string * @param $title Title * @param $options ParserOptions * @param $outputType int * * @return string */ function testSrvus($text, Title $title, ParserOptions $options, $outputType = self::OT_HTML) { $this->startParse($title, $options, $outputType, true); $text = $this->replaceVariables($text); $text = $this->mStripState->unstripBoth($text); $text = Sanitizer::removeHTMLtags($text); return $text; }
/** * Strips and renders nowiki, pre, math, hiero * If $render is set, performs necessary rendering operations on plugins * Returns the text, and fills an array with data needed in unstrip() * * @param StripState $state * * @param bool $stripcomments when set, HTML comments <!-- like this --> * will be stripped in addition to other tags. This is important * for section editing, where these comments cause confusion when * counting the sections in the wikisource * * @param array dontstrip contains tags which should not be stripped; * used to prevent stipping of <gallery> when saving (fixes bug 2700) * * @private */ function strip($text, $state, $stripcomments = false, $dontstrip = array()) { global $wgContLang; wfProfileIn(__METHOD__); $render = $this->mOutputType == self::OT_HTML; $uniq_prefix = $this->mUniqPrefix; $commentState = new ReplacementArray(); $nowikiItems = array(); $generalItems = array(); $elements = array_merge(array('nowiki', 'gallery'), array_keys($this->mTagHooks)); global $wgRawHtml; if ($wgRawHtml) { $elements[] = 'html'; } if ($this->mOptions->getUseTeX()) { $elements[] = 'math'; } # Removing $dontstrip tags from $elements list (currently only 'gallery', fixing bug 2700) foreach ($elements as $k => $v) { if (!in_array($v, $dontstrip)) { continue; } unset($elements[$k]); } $matches = array(); $text = self::extractTagsAndParams($elements, $text, $matches, $uniq_prefix); foreach ($matches as $marker => $data) { list($element, $content, $params, $tag) = $data; if ($render) { $tagName = strtolower($element); wfProfileIn(__METHOD__ . "-render-{$tagName}"); switch ($tagName) { case '!--': // Comment if (substr($tag, -3) == '-->') { $output = $tag; } else { // Unclosed comment in input. // Close it so later stripping can remove it $output = "{$tag}-->"; } break; case 'html': if ($wgRawHtml) { $output = $content; break; } // Shouldn't happen otherwise. :) // Shouldn't happen otherwise. :) case 'nowiki': $output = Xml::escapeTagsOnly($content); break; case 'math': $output = $wgContLang->armourMath(MathRenderer::renderMath($content, $params)); break; case 'gallery': $output = $this->renderImageGallery($content, $params); break; default: if (isset($this->mTagHooks[$tagName])) { $output = call_user_func_array($this->mTagHooks[$tagName], array($content, $params, $this)); } else { throw new MWException("Invalid call hook {$element}"); } } wfProfileOut(__METHOD__ . "-render-{$tagName}"); } else { // Just stripping tags; keep the source $output = $tag; } // Unstrip the output, to support recursive strip() calls $output = $state->unstripBoth($output); if (!$stripcomments && $element == '!--') { $commentState->setPair($marker, $output); } elseif ($element == 'html' || $element == 'nowiki') { $nowikiItems[$marker] = $output; } else { $generalItems[$marker] = $output; } } # Add the new items to the state # We do this after the loop instead of during it to avoid slowing # down the recursive unstrip $state->nowiki->mergeArray($nowikiItems); $state->general->mergeArray($generalItems); # Unstrip comments unless explicitly told otherwise. # (The comments are always stripped prior to this point, so as to # not invoke any extension tags / parser hooks contained within # a comment.) if (!$stripcomments) { // Put them all back and forget them $text = $commentState->replace($text); } wfProfileOut(__METHOD__); return $text; }