/** * @param ResourceLoaderContext $context * @return array */ public function getStyles(ResourceLoaderContext $context) { $geshi = SyntaxHighlight_GeSHi::prepare('', $this->lang); if (!$geshi->error) { $css = SyntaxHighlight_GeSHi::getCSS($geshi); } else { $css = ResourceLoader::makeComment($geshi->error()); } return array('all' => $css); }
/** * Initialise messages and ensure the GeSHi class is loaded */ private static function initialise() { if (!self::$initialised) { wfLoadExtensionMessages('SyntaxHighlight_GeSHi'); if (!class_exists('GeSHi')) { require 'geshi/geshi.php'; } self::$initialised = true; } return true; }
/** * Parse the Content object and generate a ParserOutput from the result. * * @param $title Title The page title to use as a context for rendering * @param $revId null|int The revision being rendered (optional) * @param $options null|ParserOptions Any parser options * @param $generateHtml boolean Whether to generate HTML (default: true). * @param &$output ParserOutput representing the HTML form of the text. * @return ParserOutput */ protected function fillParserOutput(Title $title, $revId = null, ParserOptions $options = null, $generateHtml = true, ParserOutput &$output) { global $wgParser, $wgScribuntoUseGeSHi, $wgUseSiteCss; $text = $this->getNativeData(); $output = null; // Get documentation, if any $output = new ParserOutput(); $doc = Scribunto::getDocPage($title); if ($doc) { $msg = wfMessage($doc->exists() ? 'scribunto-doc-page-show' : 'scribunto-doc-page-does-not-exist', $doc->getPrefixedText())->inContentLanguage(); if (!$msg->isDisabled()) { // We need the ParserOutput for categories and such, so we // can't use $msg->parse(). $docViewLang = $doc->getPageViewLanguage(); $dir = $docViewLang->getDir(); // Code is forced to be ltr, but the documentation can be rtl. // Correct direction class is needed for correct formatting. // The possible classes are // mw-content-ltr or mw-content-rtl $dirClass = "mw-content-{$dir}"; $docWikitext = Html::rawElement('div', array('lang' => $docViewLang->getHtmlCode(), 'dir' => $dir, 'class' => $dirClass), "\n" . $msg->plain() . "\n"); if (!$options) { // NOTE: use canonical options per default to produce cacheable output $options = ContentHandler::getForTitle($doc)->makeParserOptions('canonical'); } else { if ($options->getTargetLanguage() === null) { $options->setTargetLanguage($doc->getPageLanguage()); } } $output = $wgParser->parse($docWikitext, $title, $options, true, true, $revId); } // Mark the doc page as a transclusion, so we get purged when it // changes. $output->addTemplate($doc, $doc->getArticleID(), $doc->getLatestRevID()); } // Validate the script, and include an error message and tracking // category if it's invalid $engine = Scribunto::newDefaultEngine(); $engine->setTitle($title); $status = $engine->validate($text, $title->getPrefixedDBkey()); if (!$status->isOK()) { $output->setText($output->getText() . Html::rawElement('div', array('class' => 'errorbox'), $status->getHTML('scribunto-error-short', 'scribunto-error-long'))); $catmsg = wfMessage('scribunto-module-with-errors-category')->title($title)->inContentLanguage(); if (!$catmsg->isDisabled()) { $cat = Title::makeTitleSafe(NS_CATEGORY, $catmsg->text()); if ($cat) { $sort = (string) $output->getProperty('defaultsort'); $output->addCategory($cat->getDBkey(), $sort); } else { wfDebug(__METHOD__ . ": [[MediaWiki:scribunto-module-with-errors-category]] " . "is not a valid title!\n"); } } } if (!$generateHtml) { // We don't need the actual HTML $output->setText(''); return $output; } // Add HTML for the actual script $language = $engine->getGeSHiLanguage(); if ($wgScribuntoUseGeSHi && $language) { $geshi = SyntaxHighlight_GeSHi::prepare($text, $language); $geshi->set_language($language); if ($geshi instanceof GeSHi && !$geshi->error()) { $code = $geshi->parse_code(); if ($code) { // @todo Once we drop support for old versions of // Extension:SyntaxHighlight_GeSHi, drop the ugly test and // the BC case. global $wgAutoloadClasses; if (isset($wgAutoloadClasses['ResourceLoaderGeSHiModule'])) { $output->addModuleStyles("ext.geshi.language.{$language}"); } else { // Backwards compatibility $output->addHeadItem(SyntaxHighlight_GeSHi::buildHeadItem($geshi), "source-{$language}"); } if ($wgUseSiteCss) { $output->addModuleStyles('ext.geshi.local'); } $output->setText($output->getText() . $code); return $output; } } } // No GeSHi, or GeSHi can't parse it, use plain <pre> $output->setText($output->getText() . "<pre class='mw-code mw-script' dir='ltr'>\n" . htmlspecialchars($text) . "\n</pre>\n"); return $output; }
/** * Initialise messages and ensure the GeSHi class is loaded * @return bool */ private static function initialise() { if( !self::$initialised ) { if( !class_exists( 'GeSHi' ) ) { require( 'geshi/geshi.php' ); } self::$initialised = true; } return true; }
/** * Initialise messages and ensure the GeSHi class is loaded * @return bool */ private static function initialise() { if (!self::$initialised) { if (!class_exists('GeSHi')) { require dirname(__FILE__) . '/geshi/geshi.php'; } self::$initialised = true; } return true; }
/** * Overrides the standard view for modules. Enables syntax highlighting when * possible. * * @param $text string * @param $title Title * @param $output OutputPage * @return bool */ public static function handleScriptView($text, $title, $output) { global $wgScribuntoUseGeSHi, $wgUseSiteCss; if ($title->getNamespace() == NS_MODULE) { $engine = Scribunto::newDefaultEngine(); $language = $engine->getGeSHiLanguage(); if ($wgScribuntoUseGeSHi && $language) { $geshi = SyntaxHighlight_GeSHi::prepare($text, $language); $geshi->set_language($language); if ($geshi instanceof GeSHi && !$geshi->error()) { $code = $geshi->parse_code(); if ($code) { $output->addHeadItem("source-{$language}", SyntaxHighlight_GeSHi::buildHeadItem($geshi)); $output->addHTML("<div dir=\"ltr\">{$code}</div>"); /** Wikia change begin - add support for MediaWiki:Geshi.css (CE-1024) **/ if ($wgUseSiteCss) { $output->addModuleStyles('ext.geshi.local'); } /** Wikia change end **/ return false; } } } // No GeSHi, or GeSHi can't parse it, use plain <pre> $output->addHTML("<pre class=\"mw-code mw-script\" dir=\"ltr\">\n"); $output->addHTML(htmlspecialchars($text)); $output->addHTML("\n</pre>\n"); return false; } else { return true; } }
/** * Overrides the standard view for modules. Enables syntax highlighting when * possible. * * @param $text string * @param $title Title * @param $output OutputPage * @return bool */ public static function handleScriptView($text, $title, $output) { global $wgScriptingUseGeSHi, $wgParser; if ($title->getNamespace() == NS_MODULE) { $engine = Scripting::getEngine($wgParser); $language = $engine->getGeSHiLangauge(); if ($wgScriptingUseGeSHi && $language) { $geshi = SyntaxHighlight_GeSHi::prepare($text, $language); $geshi->set_language($language); if ($geshi instanceof GeSHi && !$geshi->error()) { $code = $geshi->parse_code(); if ($code) { $output->addHeadItem("source-{$language}", SyntaxHighlight_GeSHi::buildHeadItem($geshi)); $output->addHTML("<div dir=\"ltr\">{$code}</div>"); return false; } } } // No GeSHi, or GeSHi can't parse it, use plain <pre> $output->addHTML("<pre class=\"mw-code mw-script\" dir=\"ltr\">\n"); $output->addHTML(htmlspecialchars($text)); $output->addHTML("\n</pre>\n"); return false; } else { return true; } }
/** * Wraps HTML representation of content. * * If the schema already exists and if the SyntaxHiglight GeSHi * extension is installed, use it to render code snippets * showing how to use schema. * * @see https://mediawiki.org/wiki/Extension:SyntaxHighlight_GeSHi * * @param $title Title * @param $revId int|null Revision ID * @param $options ParserOptions|null * @param $generateHtml bool Whether or not to generate HTML * @return ParserOutput */ public function getParserOutput(Title $title, $revId = null, ParserOptions $options = null, $generateHtml = true) { $out = parent::getParserOutput($title, $revId, $options, $generateHtml); if ($revId !== null && class_exists('SyntaxHighlight_GeSHi')) { $html = ''; $highlighter = new SyntaxHighlight_GeSHi(); foreach (self::getCodeSamples($title->getDBkey(), $revId) as $lang => $code) { $geshi = $highlighter->prepare($code, $lang); $out->addHeadItem($highlighter::buildHeadItem($geshi), "source-{$lang}"); $html .= Xml::tags('h2', array(), $lang) . $geshi->parse_code(); } // The glyph is '< >' from the icon font 'Entypo' (see ../modules). $html = Xml::tags('div', array('class' => 'mw-json-schema-code-glyph'), '') . Xml::tags('div', array('class' => 'mw-json-schema-code-samples'), $html); $out->setText($html . $out->mText); } return $out; }
/** * Overrides the standard view for modules. Enables syntax highlighting when * possible. * * @static * @param $text * @param $title Title * @param $output OutputPage * @return bool */ public static function handleScriptView( $text, $title, $output ) { global $wgScriptsUseGeSHi; if( $title->getNamespace() == NS_MODULE ) { if( $wgScriptsUseGeSHi ) { $geshi = SyntaxHighlight_GeSHi::prepare( $text, 'wikiscript' ); $geshi->set_language_path( dirname( __FILE__ ) . '/geshi' ); $geshi->set_language( 'wikiscript' ); if( $geshi instanceof GeSHi && !$geshi->error() ) { $code = $geshi->parse_code(); if( $code ) { $output->addHeadItem( "source-wikiscript", SyntaxHighlight_GeSHi::buildHeadItem( $geshi ) ); $output->addHTML( "<div dir=\"ltr\">{$code}</div>" ); return false; } } } // No GeSHi, or GeSHi can't parse it, use plain <pre> $output->addHTML( "<pre class=\"mw-code mw-script\" dir=\"ltr\">\n" ); $output->addHTML( htmlspecialchars( $text ) ); $output->addHTML( "\n</pre>\n" ); return false; } else { return true; } }