2 ########################
6 ########################
8 // change directory accordingly
9 require_once('geshi/geshi.php');
10 $languagesPath = "extensions/geshicodetag/geshi/geshi";
12 // 1 - ENABLED, 0 - DISABLED
13 $codeTag["simple"] = 1; // ex. <php> echo </php>
14 $codeTag["advanced"]["mode"] = 1; // ex. <code php n> echo </php>
18 strict mode - http://qbnz.com/highlighter/geshi-doc.html#using-strict-mode
19 ex. <img src="<?php echo rand(1, 100) ?>" />
21 $codeTag["advanced"]["strict"] = 0;
23 #############################################
25 $wgExtensionFunctions[] = "ExtensionCodeTag";
26 $wgExtensionCredits['parserhook'][] = array(
27 'name' => 'GeSHiCodeTag',
28 'author' => 'Paul Nolasco',
30 'description' => 'A tag to create a syntax-highlighted code using GeSHi',
31 'url' => 'http://www.mediawiki.org/wiki/Extension:GeSHiCodeTag'
35 function ExtensionCodeTag()
37 global $wgParser, $codeTag, $languages, $languagesPath;
41 if($codeTag["advanced"]["mode"])
42 $wgParser->setHook('code', 'AdvancedCodeTag');
44 if($codeTag["simple"])
45 foreach($languages as $lang)
47 $wgParser->setHook($lang,
48 create_function( '$source',
49 '$geshi = new GeSHi($source,\'' . $lang . '\', \'' . $languagesPath . '\');
50 return $geshi->parse_code();'
55 function ReadLanguages()
57 global $languages, $languagesPath;
59 $dirHandle = opendir($languagesPath)
60 or die("ERROR: Invalid directory path - [$languagesPath], Modify the value of \$languagesPath'");
62 $pattern = "^(.*)\.php$";
64 while ($file = readdir($dirHandle))
66 if( eregi($pattern, $file) )
67 $languages[] = eregi_replace($pattern, "\\1", $file);
72 function AdvancedCodeTag ($source, $settings){
74 global $languages, $languagesPath, $codeTag;
75 $language = array_shift($settings); // [arg1]
81 if($language == "list") // list all languages supported
82 return "<br>List of supported languages for <b>Geshi " . GESHI_VERSION
. "</b>:<br>"
83 . implode("<br>", $languages);
85 if($language != "" && !in_array($language, $languages)) // list languages if invalid argument
86 return "<br>Invalid language argument, \"<b>" . $language . "</b>\", select one from the list:<br>"
87 . implode("<br>", $languages);
90 $geshi = new GeSHi(trim($source), $language, $languagesPath);
91 $geshi->enable_strict_mode($codeTag["advanced"]["strict"]);
95 if(in_array('n',$settings)) // display line numbers
96 $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS
);
99 Add more GeSHi features from [ http://qbnz.com/highlighter/geshi-doc.html ]
101 if( in_array( '<PARAMETER NAME>', $settings ) )
103 $geshi-><GESHI FUNCTION CALL>
106 // removes newlines replaces with <br />
107 return str_replace("\n",'<br />', $geshi->parse_code());