r87976 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87975‎ | r87976 | r87977 >
Date:13:27, 13 May 2011
Author:brion
Status:ok
Tags:
Comment:
* (bug 10201) SyntaxHighlight_GeSHi now shows the text unformatted along with warning if the language is invalid or unrecognized.

Uses a simple <pre> which may not be ideal but works ok. :D
Consolidated a few repeat lines.
Modified paths:
  • /trunk/extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.class.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.class.php
@@ -35,20 +35,20 @@
3636 if ( !is_null( $wgSyntaxHighlightDefaultLang ) ) {
3737 $lang = $wgSyntaxHighlightDefaultLang;
3838 } else {
39 - $error = self::formatError( htmlspecialchars( wfMsgForContent( 'syntaxhighlight-err-language' ) ) );
 39+ $error = self::formatLanguageError( $text );
4040 wfProfileOut( __METHOD__ );
4141 return $error;
4242 }
4343 }
4444 $lang = strtolower( $lang );
4545 if( !preg_match( '/^[a-z_0-9-]*$/', $lang ) ) {
46 - $error = self::formatError( htmlspecialchars( wfMsgForContent( 'syntaxhighlight-err-language' ) ) );
 46+ $error = self::formatLanguageError( $text );
4747 wfProfileOut( __METHOD__ );
4848 return $error;
4949 }
5050 $geshi = self::prepare( $text, $lang );
5151 if( !$geshi instanceof GeSHi ) {
52 - $error = self::formatError( htmlspecialchars( wfMsgForContent( 'syntaxhighlight-err-language' ) ) );
 52+ $error = self::formatLanguageError( $text );
5353 wfProfileOut( __METHOD__ );
5454 return $error;
5555 }
@@ -77,9 +77,15 @@
7878 }
7979 // Format
8080 $out = $geshi->parse_code();
 81+ if ( $geshi->error == GESHI_ERROR_NO_SUCH_LANG ) {
 82+ // Common error :D
 83+ $error = self::formatLanguageError( $text );
 84+ wfProfileOut( __METHOD__ );
 85+ return $error;
 86+ }
8187 $err = $geshi->error();
8288 if( $err ) {
83 - // Error!
 89+ // Other unknown error!
8490 $error = self::formatError( $err );
8591 wfProfileOut( __METHOD__ );
8692 return $error;
@@ -278,6 +284,18 @@
279285 }
280286
281287 /**
 288+ * Format an 'unknown language' error message and append formatted
 289+ * plain text to it.
 290+ *
 291+ * @param string $text
 292+ * @return string HTML fragment
 293+ */
 294+ private static function formatLanguageError( $text ) {
 295+ $error = self::formatError( htmlspecialchars( wfMsgForContent( 'syntaxhighlight-err-language' ) ), $text );
 296+ return $error . '<pre>' . htmlspecialchars( $text ) . '</pre>';
 297+ }
 298+
 299+ /**
282300 * Format an error message
283301 *
284302 * @param string $error

Status & tagging log