Figlet Extension

Integrate figlet text into wiki pages using figletlink in a custom Mediawiki extension:

this is a first untested version with just monkey knolage of how to make it work

Syntax
text (default font=standard)

text (set another font)

$fonts (show font list)

$self (special for template usage, $self=pagename)

Example
moo

example Result

 * '_ ` _ \ / _ \ / _ \
 * | | | | | (_) | (_) |
 * _| |_| |_|\___/ \___/

test Result
`cat /etc/passwd`

(not installed on anything this is only beta i dont have figlet installed on this server)

Source
 setHook( "figlet", "renderFiglet" ); } function renderFiglet( $input ) { global $wgOutputEncoding; $input = mysql_escape_string($input); $output=" "; $output.=shell_exec("figlet " . escapeshellarg($input)); $output.=" "; return $output; } ?> 
 * 1) Figlet Mediawiki extension
 * 2) using shell figlet
 * 3) by DrOwl 21.06.2005 modded from
 * 4) by mutante 25.03.2005
 * 5) modded again 21.05.2005 ,mutante
 * 6) modded again Owl & mutante 20.06.2006 - the slightly more secure 23 line version
 * 1) extension hook callback function
 * 1) install parser hook for tags

 setHook( "figlet", "renderFiglet" ); }
 * 1) Figlet Mediawiki extension
 * 2) using shell figlet
 * 3) by DrOwl 21.06.2005 modded from
 * 4) by mutante 25.03.2005
 * 5) modded again 21.05.2005 ,mutante
 * 6) modded again Owl & mutante 20.06.2006 - the slightly more secure 23 line version
 * 7) modded again, mutante 22.06.2006 - the advanced version with fonts
 * 1) extension hook callback function
 * 1) install parser hook for tags

function renderFiglet( $input, $argv, &$parser) { global $wgOutputEncoding; $baseurl="http://s23.org/wiki/";

if ($argv["font"] && $argv["font"] <80 && ctype_alnum($argv["font"])) { $userfont=$argv["font"]; } else { $userfont="standard"; }

$input = mysql_escape_string($input); $localParser = new Parser;

if ($input == "\$fonts") {

$fonts.=shell_exec("cd /usr/share/figlet; ls *.flf | cut -d. -f 1| xargs"); $fonts=explode(" ",$fonts);

$syntax.=" Available figlet fonts: ";

foreach ($fonts as $font) { $font=trim($font); $syntax.="$font "; }

$parsesyntax = $localParser->parse($syntax, $parser->mTitle, $parser->mOptions);

$output.=$parsesyntax->getText;

} else {

$output=" ";

if ($input =="\$self") { $title=$_GET["title"]; $title=explode("/",$title); $title=$title[2]; $input=$title; $fileinfocmd="head -n8 /usr/share/figlet/".$title.".flf"; $description=`$fileinfocmd`; $comment="This font for figlet is called \"$title\". File info: $description You can create it with the wiki syntax:  text . Other fonts are in Category:Figlet."; $parsecomment = $localParser->parse($comment, $parser->mTitle, $parser->mOptions); $comment=$parsecomment->getText; }
 * 1) $nt = Title::makeTitle( $row->page_namespace, $row->page_title );
 * 2) $input = $nt->getFullURL;

if ($userfont == "\$self") { $userfont=$_GET["title"]; $userfont=explode("/",$userfont); $userfont=$userfont[2]; }

$uinput=escapeshellarg($input); $userfont=escapeshellarg($userfont);

$figlet=shell_exec("figlet -f $userfont $uinput");

if (!$figlet) {

$syntax.="Figlet error: could not find the fontfile (or other fnord), fontname given: $userfont check available fonts in Category:Figlet or via  $fonts ."; $parsesyntax = $localParser->parse($syntax, $parser->mTitle, $parser->mOptions); $output.=$parsesyntax->getText;

} else {

$figlet = str_replace("<!","&#60;&#33;",$figlet); $figlet = str_replace(" 

not installed yet, see ongoing talk.

To avoid problems with  inside code in a  , use    blah blah code         blah blah more code   .

Even better solution now is using , installed Syntax Highlighting Extension.