1.先下载GeSHi最新版http://sourceforge.net/projects/geshi/files/;
2.解压文件夹geshi到mediawiki的extensions目录下,目录结构应该是
/extensions/genshi/genshi/genshi.php
3.为了节省空间可以删除contrib和docs两个文件夹;
4.新建一个GeSHiHighlight.php文件,文件代码为:
<?php
# GeSHiHighlight.php
#
# By: E. Rogan Creswick (aka: Largos)
# creswick@gmail.com
# wiki.ciscavate.org
#
# License: GeSHi Highlight is released under the Gnu Public License (GPL), and comes with no warranties.
# The text of the GPL can be found here: http://www.gnu.org/licenses/gpl.html
# Loosely based on SyntaxHighlight.php by Coffman, (www.wickle.com)
# you want to change the below two lines
require_once("geshi.php"); // i asume geshi.php is in the same directory as GeSHiHighlight.php (that is 'extensions' dir)
define("GESHI_PATH","extensions/geshi/geshi");// definition where are stored geshi language parsing files
# ok, end of editing :)
class SyntaxSettings {};
$wgSyntaxSettings = new SyntaxSettings;
$wgExtensionFunctions[] = "wfSyntaxExtension";
function wfSyntaxExtension() {
global $wgParser;
$langArray = geshi_list_languages(GESHI_PATH);
# $langArray = array("actionscript","ada","apache","asm","asp","bash",
# "caddcl","cadlisp","c","cpp","css","delphi",
# "html4strict","java","javascript","lisp", "lua",
# "nsis","oobas","pascal","perl","php-brief","php",
# "python","qbasic","sql","vb","visualfoxpro","xml");
foreach ( $langArray as $lang ){
if ($lang == "" || $lang == "div") continue;
$wgParser->setHook( $lang,
create_function( '$text', '$geshi = new GeSHi(trim($text,"nr"), "' ."$lang". '", GESHI_PATH);
return $geshi->parse_code();'));
}
}
/**
* function: geshi_list_languages
* -------------------------
* List supported languages by reading the files in the geshi/geshi subdirectory
* (added by JeffK -- Jeff, any more contact info?) -- I haven't tested the code is is, will do that shortly. -Rogan
*
*/
function geshi_list_languages ( $path = '/geshi' )
{
$lang_list = array();
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) { // Loop over the directory.
if(is_dir($file)) continue; // Drop anything that is a directory, cause we want files only
if( ".php" == substr($file, strrpos($file, "."),4)) // process only .php files
{
$lang_list[]= substr($file, 0, strrpos($file, "."));
}
}
closedir($handle);
}
sort($lang_list); //sort the output, i like ordered lists in Wiki Version page :)
return $lang_list;
}
?>
5.GeSHiHighlight.php文件上传到/extensions/genshi/genshi/中。和genshi.php同一个目录;
6.在mediawiki的根目录下的LocalSettings.php中$wgSitename前添加代码:
include("extensions/geshi/GeSHiHighlight.php");
7.使用方法:
大多数语言都是支持的,比如C语言可以这么用:
<c>
int
mmc_format_ext3 (MmcPartition *partition) {
char device[128];
strcpy(device, partition->device_index);
// Run mke2fs
char *const mke2fs[] = {MKE2FS_BIN, "-j", device, NULL};
if(run_exec_process(mke2fs))
return -1;
// Run tune2fs
char *const tune2fs[] = {TUNE2FS_BIN, "-j", "-C", "1", device, NULL};
if(run_exec_process(tune2fs))
return -1;
// Run e2fsck
char *const e2fsck[] = {E2FSCK_BIN, "-fy", device, NULL};
if(run_exec_process(e2fsck))
return -1;
return 0;
}
</c>
保存后即可。

发表回复