红联Linux门户
Linux帮助

mediawiki安装实现代码高亮的插件GeSHiHighLight

发布时间:2017-02-23 09:30:16来源:linux网站作者:斜月三星一太阳
1.下载新版本的GeSHi(http://qbnz.com/highlighter)
 
2.解压,复制geshi目录到mediawiki的扩展目录(extensions)下(建议删除contrib和docs两个目录及内容)
 
3.在mediawiki的扩展目录(ectensions)下,新建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/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,"\n\r"), "' ."$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;
?>
 
4.在mediawiki的根目录下的LocalSettings.php文件中加入
include("extensions/GeSHiHighlight.php");
该内容加在变量$wgSitename之前
 
附:ubuntu搭建mediawiki
1.搭建lamp环境,lamp指的是: Linux+Apache+Mysql/MariaDB+Perl/PHP/Python (我们安装的是Linux+apache2+postgresql+php)
sudo apt-get install php5 libapache2-mod-php5
(还需要安装php5-pgsql模块:sudo apt-get install php5-pgsql)
2.下载mediawiki
a)创建目录suz,并切换到该目录,下载mediawiki包
b)wget https://releases.wikimedia.org/mediawiki/1.28/mediawiki-1.28.0.tar.gz
c)解压缩 : tar -xzvf mediawiki-1.28.0.tar.gz
d)拷贝到apache2的根目录下: cp -r *** /var/www/html(或者不是根目录也OK,只是为了访问mediawiki下的index.php)
e)可以用mv命令重命名一下
3.安装mediawiki
a)通过浏览器访问index.php(http://domain/mediawiki)
b)根据提示进行postgresql的一些配置
c)wiki信息的一些设置
4.安装成功后,下载文件LocalSettings.php,并将该文件上传到mediawiki的根目录,也就是和index.php相同的目录
 
本文永久更新地址:http://www.linuxdiyf.com/linux/28618.html