Exemple #1
0
 /**
  * @param string $text
  * @return string
  */
 public function postprocess($text)
 {
     // Revert <html-{link,meta}> back to <{link,meta}>
     $text = preg_replace('!<html-(link|meta)([^>]*?)(/{0,1}>)!', '<$1$2$3', $text);
     // Restore the contents of placeholder tokens
     $text = $this->mTokens->replace($text);
     return $text;
 }
	/**
	 * libxml in its usual pointlessness converts many chars to entities - this function
	 * perfoms a reverse conversion
	 * @param string $html
	 * @return string
	 */
	private function fixLibXML( $html ) {
		wfProfileIn( __METHOD__ );
		static $replacements;
		if ( ! $replacements ) {
			// We don't include rules like '&#34;' => '&amp;quot;' because entities had already been
			// normalized by libxml. Using this function with input not sanitized by libxml is UNSAFE!
			$replacements = new ReplacementArray( array(
				'&quot;' => '&amp;quot;',
				'&amp;' => '&amp;amp;',
				'&lt;' => '&amp;lt;',
				'&gt;' => '&amp;gt;',
			) );
		}
		$html = $replacements->replace( $html );
		$html = mb_convert_encoding( $html, 'UTF-8', 'HTML-ENTITIES' );
		wfProfileOut( __METHOD__ );
		return $html;
	}
Exemple #3
0
 /**
  * @param $text string
  * @return string
  */
 public function postprocess($text)
 {
     return $this->mTokens->replace($text);
 }
 static function onAddHTML(&$out, &$text)
 {
     if (!isset($out->mLqtReplacements) || !count($out->mLqtReplacements)) {
         return true;
     }
     $replacements = $out->mLqtReplacements;
     $replacer = new ReplacementArray($replacements);
     $text = $replacer->replace($text);
     return true;
 }
 protected function ccnorm($s)
 {
     static $equivset = null;
     static $replacementArray = null;
     if (is_null($equivset) || is_null($replacementArray)) {
         global $IP;
         require_once "{$IP}/extensions/AntiSpoof/equivset.php";
         $replacementArray = new ReplacementArray($equivset);
     }
     return $replacementArray->replace($s);
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
Exemple #8
0
 /**
  * libxml in its usual pointlessness converts many chars to entities - this function
  * perfoms a reverse conversion
  * @param string $html
  * @return string
  */
 private function fixLibXML($html)
 {
     static $replacements;
     if (!$replacements) {
         // We don't include rules like '&#34;' => '&amp;quot;' because entities had already been
         // normalized by libxml. Using this function with input not sanitized by libxml is UNSAFE!
         $replacements = new ReplacementArray(array('&quot;' => '&amp;quot;', '&amp;' => '&amp;amp;', '&lt;' => '&amp;lt;', '&gt;' => '&amp;gt;'));
     }
     $html = $replacements->replace($html);
     if (function_exists('mb_convert_encoding')) {
         // Just in case the conversion in getDoc() above used named
         // entities that aren't known to html_entity_decode().
         $html = mb_convert_encoding($html, 'UTF-8', 'HTML-ENTITIES');
     } else {
         $html = html_entity_decode($html, ENT_COMPAT, 'utf-8');
     }
     return $html;
 }
 /**
  * @param $s
  * @return mixed
  */
 protected function ccnorm($s)
 {
     static $replacementArray = null;
     if (is_null($replacementArray)) {
         global $IP;
         if (is_readable("{$IP}/extensions/AntiSpoof/equivset.php")) {
             // Satisfy analyzer.
             $equivset = null;
             // Contains a map of characters in $equivset.
             require "{$IP}/extensions/AntiSpoof/equivset.php";
             $replacementArray = new ReplacementArray($equivset);
         } else {
             // AntiSpoof isn't available, so just create a dummy
             wfDebugLog('AbuseFilter', "Can't compute normalized string (ccnorm) as the AntiSpoof Extension isn't isntalled.");
             $replacementArray = new ReplacementArray(array());
         }
     }
     return $replacementArray->replace($s);
 }