(bug 27714) Load MediaWiki:Geshi.css using ResourceLoader. Modified patch by Lewis Cawte

This commit is contained in:
Roan Kattouw 2011-11-20 18:07:20 +00:00
parent 50223b619b
commit 4227b5510d
2 changed files with 12 additions and 16 deletions

View file

@ -21,7 +21,7 @@ class SyntaxHighlight_GeSHi {
* @return string
*/
public static function parserHook( $text, $args = array(), $parser ) {
global $wgSyntaxHighlightDefaultLang, $wgUseTidy;
global $wgSyntaxHighlightDefaultLang, $wgUseSiteCss, $wgUseTidy;
wfProfileIn( __METHOD__ );
self::initialise();
$text = rtrim( $text );
@ -103,6 +103,10 @@ class SyntaxHighlight_GeSHi {
// Register CSS
$parser->mOutput->addHeadItem( self::buildHeadItem( $geshi ), "source-{$lang}" );
if( $wgUseSiteCss ) {
$parser->mOutput->addModuleStyles( 'ext.geshi.local' );
}
$encloseTag = $enclose === GESHI_HEADER_NONE ? 'span' : 'div';
$attribs = Sanitizer::validateTagAttributes( $args, $encloseTag );
@ -220,6 +224,7 @@ class SyntaxHighlight_GeSHi {
* @return bool
*/
public static function viewHook( $text, $title, $output ) {
global $wgUseSiteCss;
// Determine the language
$matches = array();
preg_match( '!\.(css|js)$!u', $title->getText(), $matches );
@ -232,6 +237,9 @@ class SyntaxHighlight_GeSHi {
// Done
$output->addHeadItem( "source-$lang", self::buildHeadItem( $geshi ) );
$output->addHTML( "<div dir=\"ltr\">{$out}</div>" );
if( $wgUseSiteCss ) {
$output->addModuleStyles( 'ext.geshi.local' );
}
return false;
}
}
@ -279,14 +287,6 @@ class SyntaxHighlight_GeSHi {
$css[] = $geshi->get_stylesheet( false );
$css[] = '/*]]>*/';
$css[] = '</style>';
if( $wgUseSiteCss ) {
$title = Title::makeTitle( NS_MEDIAWIKI, 'Geshi.css' );
$q = "usemsgcache=yes&action=raw&ctype=text/css&smaxage={$wgSquidMaxage}";
$css[] = '<style type="text/css">/*<![CDATA[*/';
$css[] = '@import "' . $title->getLocalUrl( $q ) . '";';
$css[] = '/*]]>*/';
$css[] = '</style>';
}
return implode( "\n", $css );
}

View file

@ -54,14 +54,10 @@ $wgExtensionMessagesFiles['SyntaxHighlight_GeSHi'] = $dir . 'SyntaxHighlight_GeS
$wgAutoloadClasses['SyntaxHighlight_GeSHi'] = $dir . 'SyntaxHighlight_GeSHi.class.php';
$wgHooks['ShowRawCssJs'][] = 'SyntaxHighlight_GeSHi::viewHook';
$wgHooks['ParserFirstCallInit'][] = 'efSyntaxHighlight_GeSHiSetup';
$wgHooks['ExtensionTypes'][] = 'SyntaxHighlight_GeSHi::hSpecialVersion_GeSHi';
if ( version_compare( $wgVersion, '1.17alpha', '>=' ) ) {
// For MediaWiki 1.17 alpha and later.
$wgHooks['ExtensionTypes'][] = 'SyntaxHighlight_GeSHi::hSpecialVersion_GeSHi';
} else {
// For pre-MediaWiki 1.17 alpha.
$wgHooks['SpecialVersionExtensionTypes'][] = 'SyntaxHighlight_GeSHi::hOldSpecialVersion_GeSHi';
}
$wgAutoloadClasses['HighlightGeSHilocal'] = $dir . 'SyntaxHighlight_GeSHi.local.php';
$wgResourceModules['ext.geshi.local'] = array( 'class' => 'HighlightGeSHilocal' );
/**
* Register parser hook