Use ContentGetParserOutput hook instead of ShowRawCssJs

Depends on I58679856 in core MediaWiki.

This breaks compatibility with MW < 1.24.

Bug: 64859
Change-Id: Idf4ad4397101a4d19be2ac773cd4bad52188d903
This commit is contained in:
Bartosz Dziewoński 2014-05-10 23:28:07 +02:00 committed by Legoktm
parent 0138535793
commit d7b87ac836
2 changed files with 5 additions and 44 deletions

View file

@ -229,41 +229,6 @@ class SyntaxHighlight_GeSHi {
return $enclose;
}
/**
* Hook into Article::view() to provide syntax highlighting for
* custom CSS and JavaScript pages.
*
* B/C for MW 1.20 and before. 1.21 and later use renderHook() instead.
*
* @param string $text
* @param Title $title
* @param OutputPage $output
* @return bool
*/
public static function viewHook( $text, $title, $output ) {
global $wgUseSiteCss;
// Determine the language
$matches = array();
preg_match( '!\.(css|js)$!u', $title->getText(), $matches );
$lang = isset( $matches[1] ) && $matches[1] == 'css' ? 'css' : 'javascript';
// Attempt to format
$geshi = self::prepare( $text, $lang );
if( $geshi instanceof GeSHi ) {
$out = $geshi->parse_code();
if( !$geshi->error() ) {
// Done
$output->addHeadItem( "source-$lang", self::buildHeadItem( $geshi ) );
$output->addHTML( "<div dir=\"ltr\">{$out}</div>" );
if( $wgUseSiteCss ) {
$output->addModuleStyles( 'ext.geshi.local' );
}
return false;
}
}
// Bottle out
return true;
}
/**
* Hook into Content::getParserOutput to provide syntax highlighting for
* script content.
@ -272,7 +237,7 @@ class SyntaxHighlight_GeSHi {
* @since MW 1.21
*/
public static function renderHook( Content $content, Title $title,
ParserOptions $options, $generateHtml, ParserOutput &$output
$revId, ParserOptions $options, $generateHtml, ParserOutput &$output
) {
global $wgSyntaxHighlightModels, $wgUseSiteCss;
@ -382,11 +347,14 @@ class SyntaxHighlight_GeSHi {
* Prepare a CSS snippet suitable for use as a ParserOutput/OutputPage
* head item.
*
* Not used anymore, kept for backwards-compatibility with other extensions.
*
* @deprecated
* @param GeSHi $geshi
* @return string
*/
public static function buildHeadItem( $geshi ) {
wfDeprecated( __METHOD__ );
$css = array();
$css[] = '<style type="text/css">/*<![CDATA[*/';
$css[] = self::getCSS( $geshi );

View file

@ -58,14 +58,7 @@ $wgAutoloadClasses['ResourceLoaderGeSHiLocalModule'] = $dir . 'ResourceLoaderGeS
$wgHooks['ExtensionTypes'][] = 'SyntaxHighlight_GeSHi::extensionTypes';
$wgHooks['ResourceLoaderRegisterModules'][] = 'SyntaxHighlight_GeSHi::resourceLoaderRegisterModules';
//if ( defined( 'MW_SUPPORTS_CONTENTHANDLER' ) ) {
// since MW 1.21
// $wgHooks['ContentGetParserOutput'][] = 'SyntaxHighlight_GeSHi::renderHook';
//} else {
// B/C until 1.20
$wgHooks['ShowRawCssJs'][] = 'SyntaxHighlight_GeSHi::viewHook';
//}
$wgHooks['ContentGetParserOutput'][] = 'SyntaxHighlight_GeSHi::renderHook';
// Module to load MediaWiki:Geshi.css.
$wgResourceModules['ext.geshi.local'] = array( 'class' => 'ResourceLoaderGeSHiLocalModule' );