User:Fxparlant/Geshi

From Meta, a Wikimedia project coordination wiki

Jump to: navigation, search
Blue Glass Arrow.svg MediaWiki logo.png
This page should be moved to MediaWiki.org.
Please do not move the page by hand. It will be imported by a MediaWiki.org administrator with the full edit history. In the meantime, you may continue to edit the page as normal.

There is an updated version available at GeSHiHighlight, it includes the ability to display uploaded files.


I had a few problems to get geshi working. Here is my code: Of course the extension must be declared, see my LocalSettings.php, at the bottom.


<?php
# GeSHiHighlight.php
# 
# By: E. Rogan Creswick (aka: Largos)
# largos@ciscavate.org
# ciscavate.org/wiki/
#
# 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)


                                                                                                                                         
#$wgSyntaxSettings = new SyntaxSettings;
$wgExtensionFunctions[] = "wfSyntaxExtension";                                                                                                                 
                                                                                                                                                               
function wfSyntaxExtension() {                                                                                                                                 
        global $wgParser;
 
        $langArray = array("actionscript","ada","apache","asm","asp","bash",
                           "caddcl","cadlisp","c","cpp","css","delphi",
                           "html4strict","html4","java","javascript","lisp", "lua",
                           "nsis","oobas","pascal","perl","php-brief","php",
                           "python","qbasic","sql","vb","visualfoxpro","xml");
        
        foreach ( $langArray as $lang ){                                                       
                                                                                                                                        
                $wgParser->setHook( $lang, create_function( '$text', '$geshi = new GeSHi($text, ' . $lang . ', "extensions/geshi/geshi"); $geshi->enable_classes(); $geshi->set_header_type(GESHI_HEADER_PRE); $geshi->set_overall_class("code"); $geshi->set_url_for_keyword_group(1, ""); $geshi->set_url_for_keyword_group(2, ""); $geshi->set_encoding("utf-8"); $geshi->set_url_for_keyword_group(3, ""); $geshi->set_url_for_keyword_group(4, "");return $geshi->parse_code();'));
        }                                                                                                                                                      
}                                                                                                                                                              
?>