Extension:EmbedHighlightedCodeFromFile

What can this extension do?
embed source code from a file on a page, auto syntax highlighted. It's copied partially from Extension:Embed Document and requires geshi, so I just install Extension:SyntaxHighlight_GeSHi

Usage
use on your page:

Path/To/File.xyz

in one line. The path starts from the root of your public code repository (see installation). The language for highlighting is found from file suffix automatically by GeSHi

Download instructions
Please cut and paste the code found below and place it in. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

Installation
Install Extension:SyntaxHighlight_GeSHi

To install this extension, add the following to LocalSettings.php:

create a symlink code/ inside your MW root dir pointing to your public code repository. '''Ensure that everything below your defined root is okay for public viewing, ie. check for forgotten symlinks inside! Otherwise people may read access your operating system settings!'''

Code
markers, ";       $errormsg .= "allowed are onlya...zA...Z_/. ";        return $errormsg;    }

// test for ../ filesystem going up - dangerous! $pos = strstr( $input, '..' ); if (! $pos ===false ) { $errormsg = "Error: ../ path elements are not allowed, sorry! "; return $errormsg; }

$input = 'code/'.$input; if ( file_exists($input) ) { $path_parts = pathinfo($input); $ext = $path_parts["extension"];

$language = ''; $source = file_get_contents($input); $geshi =& new GeSHi($source, $language); $lang = $geshi->get_language_name_from_extension( $ext ); $geshi->set_language( $lang );

return $geshi->parse_code; }

}