[Scummvm-cvs-logs] SF.net SVN: scummvm:[55947] wiki/trunk/extensions/SyntaxHighlight_GeSHI

criezy at users.sourceforge.net criezy at users.sourceforge.net
Thu Apr 14 20:45:34 CEST 2011


Revision: 55947
          http://scummvm.svn.sourceforge.net/scummvm/?rev=55947&view=rev
Author:   criezy
Date:     2011-04-14 18:45:34 +0000 (Thu, 14 Apr 2011)

Log Message:
-----------
WIKI: Modify syntax highlighting extension for backward compatibility

Historically we used a slightly different extension that used a different hook and
language strings. To avoid having to modify all the wiki page that used the old
extension, support for old parser hook tag  and language strings has been
added to this new extension.

Modified Paths:
--------------
    wiki/trunk/extensions/SyntaxHighlight_GeSHI/SyntaxHighlight_GeSHi.class.php
    wiki/trunk/extensions/SyntaxHighlight_GeSHI/SyntaxHighlight_GeSHi.php

Modified: wiki/trunk/extensions/SyntaxHighlight_GeSHI/SyntaxHighlight_GeSHi.class.php
===================================================================
--- wiki/trunk/extensions/SyntaxHighlight_GeSHI/SyntaxHighlight_GeSHi.class.php	2011-04-14 18:40:01 UTC (rev 55946)
+++ wiki/trunk/extensions/SyntaxHighlight_GeSHI/SyntaxHighlight_GeSHi.class.php	2011-04-14 18:45:34 UTC (rev 55947)
@@ -1,5 +1,21 @@
 <?php
 
+/**
+ * Modifications by criezy:
+ * backward compatibility for ScummVM wiki syntax highlighting.
+ *
+ * Accept type="C++" in adition to lang="cpp"
+ *
+ * lines 49-50:
+ * + } else if ( isset( $args['type'] ) ) {
+ * + 	$lang = strtolower( $args['type'] );
+ *
+ * lines 62-64:
+ * + if( $lang === 'c++' ) {
+ * + 	$lang = 'cpp';
+ * + }
+ */
+
 class SyntaxHighlight_GeSHi {
 
 	/**
@@ -21,21 +37,42 @@
 	 * @return string
 	 */
 	public static function parserHook( $text, $args = array(), $parser ) {
+		global $wgSyntaxHighlightDefaultLang;
+		wfProfileIn( __METHOD__ );
 		self::initialise();
 		$text = rtrim( $text );
 		// Don't trim leading spaces away, just the linefeeds
 		$text = preg_replace( '/^\n+/', '', $text );
 		// Validate language
-		if( isset( $args['lang'] ) ) {
-			$lang = strtolower( $args['lang'] );
+		if( isset( $args['lang'] ) && $args['lang'] ) {
+			$lang = $args['lang'];
+		} else if ( isset( $args['type'] ) ) {
+			$lang = strtolower( $args['type'] );
 		} 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 = $wgSyntaxHighlightDefaultLang;
+			} else {
+				$error = self::formatError( htmlspecialchars( wfMsgForContent( 'syntaxhighlight-err-language' ) ) );
+				wfProfileOut( __METHOD__ );
+				return $error;
+			}
 		}
-		if( !preg_match( '/^[a-z_0-9-]*$/', $lang ) )
-			return self::formatError( htmlspecialchars( wfMsgForContent( 'syntaxhighlight-err-language' ) ) );
+		$lang = strtolower( $lang );
+		if( $lang === 'c++' ) {
+			$lang = 'cpp';
+		}
+		if( !preg_match( '/^[a-z_0-9-]*$/', $lang ) ) {
+			$error = self::formatError( htmlspecialchars( wfMsgForContent( 'syntaxhighlight-err-language' ) ) );
+			wfProfileOut( __METHOD__ );
+			return $error;
+		}
 		$geshi = self::prepare( $text, $lang );
-		if( !$geshi instanceof GeSHi )
-			return self::formatError( htmlspecialchars( wfMsgForContent( 'syntaxhighlight-err-language' ) ) );
+		if( !$geshi instanceof GeSHi ) {
+			$error = self::formatError( htmlspecialchars( wfMsgForContent( 'syntaxhighlight-err-language' ) ) );
+			wfProfileOut( __METHOD__ );
+			return $error;
+		}
 
 		$enclose = self::getEncloseType( $args );
 
@@ -60,19 +97,22 @@
 		$err = $geshi->error();
 		if( $err ) {
 			// Error!
-			return self::formatError( $err );
+			$error = self::formatError( $err );
+			wfProfileOut( __METHOD__ );
+			return $error;
+		}
+		// Armour for Parser::doBlockLevels()
+		if( $enclose === GESHI_HEADER_DIV )
+			$out = str_replace( "\n", '', $out );
+		// Register CSS
+		$parser->mOutput->addHeadItem( self::buildHeadItem( $geshi ), "source-{$lang}" );
+		if ( $enclose === GESHI_HEADER_NONE ) {
+			$out = '<span class="mw-geshi '.$lang.' source-'.$lang.'"> '.$out . '</span>';
 		} else {
-			// Armour for Parser::doBlockLevels()
-			if( $enclose === GESHI_HEADER_DIV )
-				$out = str_replace( "\n", '', $out );
-			// Register CSS
-			$parser->mOutput->addHeadItem( self::buildHeadItem( $geshi ), "source-{$lang}" );
-			if ( $enclose === GESHI_HEADER_NONE ) {
-				return '<span class="'.$lang.' source-'.$lang.'"> '.$out . '</span>';
-			} else {
-				return '<div dir="ltr" style="text-align: left;">' . $out . '</div>';
-			}
+			$out = '<div dir="ltr" class="mw-geshi" style="text-align: left;">' . $out . '</div>';
 		}
+		wfProfileOut( __METHOD__ );
+		return $out;
 	}
 	
 	/**
@@ -292,4 +332,14 @@
 		}
 		return true;
 	}
+
+	/**
+	 * Get the GeSHI's version information while Special:Version is read
+	 */
+	public static function hSpecialVersion_GeSHi( &$sp, &$extensionTypes ) {
+		global $wgExtensionCredits;
+		require_once( 'geshi/geshi.php' );
+		$wgExtensionCredits['parserhook']['SyntaxHighlight_GeSHi']['version'] = GESHI_VERSION;
+		return true;
+	}
 }

Modified: wiki/trunk/extensions/SyntaxHighlight_GeSHI/SyntaxHighlight_GeSHi.php
===================================================================
--- wiki/trunk/extensions/SyntaxHighlight_GeSHI/SyntaxHighlight_GeSHi.php	2011-04-14 18:40:01 UTC (rev 55946)
+++ wiki/trunk/extensions/SyntaxHighlight_GeSHI/SyntaxHighlight_GeSHi.php	2011-04-14 18:45:34 UTC (rev 55947)
@@ -19,6 +19,14 @@
  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  * http://www.gnu.org/copyleft/gpl.html
  */
+ 
+ /**
+ * Modifications: backward compatibility for ScummVM wiki syntax highlighting.
+ * Accept tag <syntax> in addition to <source>
+ *
+ * lines 71:
+ * + $wgParser->setHook( 'syntax', array( 'SyntaxHighlight_GeSHi', 'parserHook' ) );
+ */
 
 /**
  * @addtogroup Extensions
@@ -33,39 +41,34 @@
  * A language is specified like: <source lang="c">void main() {}</source>
  * If you forget, or give an unsupported value, the extension spits out
  * some help text and a list of all supported languages.
- *
- * The extension has been tested with GeSHi 1.0.8 and MediaWiki 1.14a
- * as of 2008-09-28.
  */
 
 if( !defined( 'MEDIAWIKI' ) )
 	die();
 
 $wgExtensionCredits['parserhook']['SyntaxHighlight_GeSHi'] = array(
+	'path'           => __FILE__,
 	'name'           => 'SyntaxHighlight',
-	'svn-date' => '$LastChangedDate: 2008-09-28 15:30:45 +0000 (Sun, 28 Sep 2008) $',
-	'svn-revision' => '$LastChangedRevision: 41349 $',
 	'author'         => array( 'Brion Vibber', 'Tim Starling', 'Rob Church', 'Niklas Laxström' ),
 	'description'    => 'Provides syntax highlighting using [http://qbnz.com/highlighter/ GeSHi Highlighter]',
 	'descriptionmsg' => 'syntaxhighlight-desc',
 	'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';
 $wgHooks['ShowRawCssJs'][] = 'SyntaxHighlight_GeSHi::viewHook';
-if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) {
-	$wgHooks['ParserFirstCallInit'][] = 'efSyntaxHighlight_GeSHiSetup';
-} else {
-	$wgExtensionFunctions[] = 'efSyntaxHighlight_GeSHiSetup';
-}
+$wgHooks['SpecialVersionExtensionTypes'][] = 'SyntaxHighlight_GeSHi::hSpecialVersion_GeSHi';
+$wgHooks['ParserFirstCallInit'][] = 'efSyntaxHighlight_GeSHiSetup';
 
 /**
  * Register parser hook
  */
-function efSyntaxHighlight_GeSHiSetup() {
-	global $wgParser;
-	$wgParser->setHook( 'source', array( 'SyntaxHighlight_GeSHi', 'parserHook' ) );
+function efSyntaxHighlight_GeSHiSetup( &$parser ) {
+	$parser->setHook( 'source', array( 'SyntaxHighlight_GeSHi', 'parserHook' ) );
+	$parser->setHook( 'syntax', array( 'SyntaxHighlight_GeSHi', 'parserHook' ) );
+	$parser->setHook( 'syntaxhighlight', array( 'SyntaxHighlight_GeSHi', 'parserHook' ) );
 	return true;
 }


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list