From 72521f6b301f789d321c6969403626680aa5d0d1 Mon Sep 17 00:00:00 2001 From: X! Date: Sun, 17 May 2009 15:21:37 +0000 Subject: [PATCH] Add optional $wgSyntaxHighlightDefaultLang parameter; allows people to set a default language that shows up if the lang parameter is missing. --- SyntaxHighlight_GeSHi.class.php | 8 +++++++- SyntaxHighlight_GeSHi.php | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/SyntaxHighlight_GeSHi.class.php b/SyntaxHighlight_GeSHi.class.php index 5aff235f..71a7dcea 100644 --- a/SyntaxHighlight_GeSHi.class.php +++ b/SyntaxHighlight_GeSHi.class.php @@ -21,6 +21,7 @@ class SyntaxHighlight_GeSHi { * @return string */ public static function parserHook( $text, $args = array(), $parser ) { + global $wgSyntaxHighlightDefaultLang; self::initialise(); $text = rtrim( $text ); // Don't trim leading spaces away, just the linefeeds @@ -29,7 +30,12 @@ class SyntaxHighlight_GeSHi { if( isset( $args['lang'] ) ) { $lang = strtolower( $args['lang'] ); } else { - return self::formatError( htmlspecialchars( wfMsgForContent( 'syntaxhighlight-err-language' ) ) ); + // language is not specified. Check if default exists, if yes, use it. + if ( !is_null($wgSyntaxHighlightDefaultLang) ) { + $lang = strtolower($wgSyntaxHighlightDefaultLang); + } else { + return self::formatError( htmlspecialchars( wfMsgForContent( 'syntaxhighlight-err-language' ) ) ); + } } if( !preg_match( '/^[a-z_0-9-]*$/', $lang ) ) return self::formatError( htmlspecialchars( wfMsgForContent( 'syntaxhighlight-err-language' ) ) ); diff --git a/SyntaxHighlight_GeSHi.php b/SyntaxHighlight_GeSHi.php index f8784480..b8550e7b 100644 --- a/SyntaxHighlight_GeSHi.php +++ b/SyntaxHighlight_GeSHi.php @@ -50,6 +50,7 @@ $wgExtensionCredits['parserhook']['SyntaxHighlight_GeSHi'] = array( 'url' => 'http://www.mediawiki.org/wiki/Extension:SyntaxHighlight_GeSHi', ); +$wgSyntaxHighlightDefaultLang = null; //Change this in LocalSettings.php $dir = dirname(__FILE__) . '/'; $wgExtensionMessagesFiles['SyntaxHighlight_GeSHi'] = $dir . 'SyntaxHighlight_GeSHi.i18n.php'; $wgAutoloadClasses['SyntaxHighlight_GeSHi'] = $dir . 'SyntaxHighlight_GeSHi.class.php';