/** Fetch the math */ function fetchMath($sum) { $math = new MathRenderer($sum); $math->setOutputMode(MW_MATH_PNG); $html = $math->render(); return preg_replace('/alt=".*"/', '', $html); }
/** Fetch the math */ function fetchMath($sum) { if (MWInit::classExists('MathRenderer')) { $math = new MathRenderer($sum); } else { throw new MWException('MathCaptcha requires the Math extension for MediaWiki versions 1.18 and above.'); } $math->setOutputMode(MW_MATH_PNG); $html = $math->render(); return preg_replace('/alt=".*?"/', '', $html); }
/** Fetch the math */ function fetchMath($sum) { // class_exists() unfortunately doesn't work with HipHop, and // its replacement, MWInit::classExists(), wasn't added until // MW 1.18, and is thus unusable here - so instead, we'll // just duplicate the code of MWInit::classExists(). try { $r = new ReflectionClass('MathRenderer'); } catch (ReflectionException $r) { throw new MWException('MathCaptcha requires the Math extension for MediaWiki versions 1.18 and above.'); } $math = new MathRenderer($sum); $math->setOutputMode(MW_MATH_PNG); $html = $math->render(); return preg_replace('/alt=".*?"/', '', $html); }
/** Fetch the math */ function fetchMath($sum) { if (class_exists('MathRenderer')) { $math = MathRenderer::getRenderer($sum, array(), MW_MATH_PNG); } else { throw new Exception('MathCaptcha requires the Math extension for MediaWiki versions 1.18 and above.'); } $html = $math->render(); return preg_replace('/alt=".*?"/', '', $html); }
function wfSajaxGetMathUrl($term) { $originalLink = MathRenderer::renderMath($term); if (false == strpos($originalLink, 'src="')) { return ''; } $srcPart = substr($originalLink, strpos($originalLink, "src=") + 5); $url = strtok($srcPart, '"'); return $url; }
/** * Callback function for the <math> parser hook. * * @param $content * @param $attributes * @param $parser Parser * @return */ static function mathTagHook($content, $attributes, $parser) { global $wgContLang, $wgUseMathJax; $renderedMath = MathRenderer::renderMath($content, $attributes, $parser->getOptions()); if ($wgUseMathJax) { self::addMathJax($parser); } $output = $renderedMath; return $wgContLang->armourMath($output); }
/** * Check of a formula exists, rendering if not * This will return either an image tag with link to image (complicated formulas) * or html (simple) * * @param string $tex LaTeX formula * @param array $params Parameters (not used?) * @return string */ public static function renderMath($tex, $params = array()) { $math = new MathRenderer($tex, $params); return $math->render(); }
public static function renderMath($tex, $params = array(), ParserOptions $parserOptions = null) { $math = new MathRenderer($tex, $params); if ($parserOptions) { $math->setOutputMode($parserOptions->getMath()); } return $math->render(); }
function renderMath($tex) { global $wgUser; $math = new MathRenderer($tex); $math->setOutputMode($wgUser->getOption('math')); return $math->render(); }
/** * 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; }
public static function renderMath($tex, $params = array()) { global $wgUser; # SEAN: We need this since XML code like & < cannot # be processed as is. $tex = html_entity_decode($tex); $math = new MathRenderer($tex, $params); $math->setOutputMode($wgUser->getOption('math')); return $math->render(); }
/** * 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; }
static function math($content, $attributes, $parser) { global $wgContLang; return $wgContLang->armourMath(MathRenderer::renderMath($content, $attributes)); }
/** * 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() * If the $state is already a valid strip state, it adds to the 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()) { wfProfileIn(__METHOD__); $render = $this->mOutputType == OT_HTML; $uniq_prefix = $this->mUniqPrefix; $commentState = 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 = Parser::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 = wfEscapeHTMLTagsOnly($content); break; case 'math': $output = MathRenderer::renderMath($content); 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, because unstrip() is no longer recursive so // it won't do it itself $output = $this->unstrip($output, $state); if (!$stripcomments && $element == '!--') { $commentState[$marker] = $output; } elseif ($element == 'html' || $element == 'nowiki') { $state['nowiki'][$marker] = $output; } else { $state['general'][$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 = strtr($text, $commentState); } wfProfileOut(__METHOD__); return $text; }
/** * Return the text to be used for a given extension tag. * This is the ghost of strip(). * * @param array $params Associative array of parameters: * name PPNode for the tag name * attr PPNode for unparsed text where tag attributes are thought to be * attributes Optional associative array of parsed attributes * inner Contents of extension element * noClose Original text did not have a close tag * @param PPFrame $frame */ function extensionSubstitution($params, $frame) { global $wgRawHtml, $wgContLang; $name = $frame->expand($params['name']); $attrText = !isset($params['attr']) ? null : $frame->expand($params['attr']); $content = !isset($params['inner']) ? null : $frame->expand($params['inner']); $marker = "{$this->mUniqPrefix}-{$name}-" . sprintf('%08X', $this->mMarkerIndex++) . self::MARKER_SUFFIX; if ($this->ot['html']) { $name = strtolower($name); $attributes = Sanitizer::decodeTagAttributes($attrText); if (isset($params['attributes'])) { $attributes = $attributes + $params['attributes']; } switch ($name) { case 'html': if ($wgRawHtml) { $output = $content; break; } else { throw new MWException('<html> extension tag encountered unexpectedly'); } case 'nowiki': $content = strtr($content, array('-{' => '-{', '}-' => '}-')); $output = Xml::escapeTagsOnly($content); break; case 'math': $output = $wgContLang->armourMath(MathRenderer::renderMath($content, $attributes)); break; case 'gallery': $output = $this->renderImageGallery($content, $attributes); break; default: if (isset($this->mTagHooks[$name])) { # Workaround for PHP bug 35229 and similar if (!is_callable($this->mTagHooks[$name])) { throw new MWException("Tag hook for {$name} is not callable\n"); } $output = call_user_func_array($this->mTagHooks[$name], array($content, $attributes, $this)); } else { $output = '<span class="error">Invalid tag extension name: ' . htmlspecialchars($name) . '</span>'; } } } else { if (is_null($attrText)) { $attrText = ''; } if (isset($params['attributes'])) { foreach ($params['attributes'] as $attrName => $attrValue) { $attrText .= ' ' . htmlspecialchars($attrName) . '="' . htmlspecialchars($attrValue) . '"'; } } if ($content === null) { $output = "<{$name}{$attrText}/>"; } else { $close = is_null($params['close']) ? '' : $frame->expand($params['close']); $output = "<{$name}{$attrText}>{$content}{$close}"; } } if ($name === 'html' || $name === 'nowiki') { $this->mStripState->nowiki->setPair($marker, $output); } else { $this->mStripState->general->setPair($marker, $output); } return $marker; }
/** * Render a math forumla * Output depends on complexity of formula. HTML is tried first with image used for complex formulas * * @param array $mtch_arr Wiki markup matching a <math>formula</math> * @return string */ private function _getMath($matches) { $m = MathRenderer::renderMath(trim($matches[1]), array('option' => $this->get('option'))); return $this->_dataPush(array($matches[0], 'math', $this->_randomString(), $m)); }
public static function renderMath($tex, $params = array()) { global $wgUser; $math = new MathRenderer($tex, $params); $math->setOutputMode($wgUser->getOption('math')); return $math->render(); }