Extension:GeSHiCodeTag

See also: Extension:SyntaxHighlight GeSHi.

Introduction
I've been searching for a good syntax-highlighting code extension for MediaWiki but unfortunately I can't find one that fit my needs. So I decided to just create one myself since I'll also be using it heavily on my site. I also wrote the code as readable and customizale as possible so you can easily extend its features. Feel free to email me for questions/comments/suggestions/errors. Hope you all like my first (and hopefully not the last) MediaWiki extension!

README
Features:
 * Two types of code tags: simple and advanced.
 * Ability to list all languages supported by GeSHi.
 * Ability to disable/enable the code tags
 * Extendability and readability of the code.

Requirements:
 * GeSHi

Tested on: (If you've tested it and it's working on a different version please add it here! Thanks!) Compatibility note: This extension was tested on Media Wiki version 1.13.2 (and 1.14.0) and there were incompatibility problems with the edit screen interface which can easily be fixed with a few minor changes. In the GeshiCodeTag.php file, change the top couple of lines to the following: So in the above code, the $codeTag["simple"] was set to 0 making &#60;code&#62; in MediaWiki's interface not being interfered with. Then the only change that you will need to keep in mind is that to use GeSHi, you need to use &#60;code php&#62;&#60;/code&#62; as the other option (above it in the code) will just mess up the MediaWiki interface in a minor way.
 * MediaWiki 1.19.2, 1.17.0, 1.16.0, 1.15.3, 1.15.0, 1.14.0 1.12.0 1.11.0, 1.10.1, 1.10.0, 1.9.3, 1.9.2, 1.8.2, 1.7.1, 1.6.8, 1.5.8, 1.5.7, 1.5.3 (but see Issues below)
 * GeSHi 1.0.8.4, 1.0.8.3, 1.0.7.22, 1.0.7.21, 1.0.7.20, 1.0.7.19, 1.0.7.17, 1.0.7.12
 * PHP 5.3.9, 5.3.3, 5.3.2, 5.2.5, 5.2.4, 5.2.1, 5.1.4, 5.1.2, 5.04 (for php5.3 see Issues below or Discussion)

Instructions:


 * 1) Download Geshi, extract it and place the entire folder content under yourWikiSite/extensions/
 * 2) Copy the GeshiCodeTag Source below and save it as GeshiCodeTag.php (Note: Be sure to change the $languagesPath depending on the path of your Geshi extension)
 * 3) Place GeshiCodeTag.php to yourWikiSite/extensions/
 * 4) Add the include tag below prior to the variable $wgSiteName in yourWikiSite/LocalSettings.php

'''That's it! Copy the "Tag Examples" below to see if it's working correctly'''

Usage
There are two code tags that you can use:


 * 1) Simple Tag Format:      <'languages'>source code here
 * 2) Advanced Tag Format:

Tag Examples

- simple code tag echo "Hello World";

- advanced code tag

- advanced code tag with line numbers

- default code tag

- display a list of supported languages

DEMO: https://www.cs.colostate.edu/wiki/Test_GeSHiCodeTag

ChangeLog

 * Added 'version' and 'description' in the extension details. (as suggested by Servel333 in the discussion) --Paul516 04:06, 24 May 2008 (UTC)
 * Added changes suggested by Jonyo in the Discussion. It allows GeshiCodeTag to be interleaved with a list. --Paul516 08:17, 9 May 2007 (UTC)
 * Add default language "text" to satisfy legacy wiki code with

Templates or variables must be added which expand to nothing so they don't render as a red link, (my ones look like this example). Also an extra line must be added to the GeSHiCodeTag.php file just before the geshi object is instantiated in the hook function to force the templates to expand.

Change the following block of code: to

Issues

 * In MediaWiki 1.5.3 the active links to keywords are followed by the "external link" icon which makes the code hard to read. To suppress the icons, replace the two occurrences of




 * with




 * MediaWiki version less than 1.5 will only work in Simple Mode since older versions don't accept arguments in tags
 * MediaWiki versions (1.5.3, 1.5.7, 1.8.3, 1.9.2, 1.12.0, 1.16.0 and probably others) - the "div.php" lang definition errantly highlights the MediaWiki copyrightwarning system message and other text in &lt;div&gt;&lt;/div&gt; tags.
 * The easiest fix is to delete the div.php language module from the geshi installation folder, or to rename it e.g. to div.php_
 * Alternatively, the extension code can be modified by removing "div" from the list of languages used in "simple" mode. If you need to highlight "div" code you can use the "advanced" syntax


 * For PHP 5.3 support some small changes needed. Changed function could be seen in discussion.

Discussion
Extension talk:GeSHiCodeTag for any questions/comments/suggestions regarding GeSHiCodeTag