Figlet Extension
From S23Wiki
Integrate figlet text into wiki pages using figletlink in a custom Mediawiki extension:
Contents |
[edit] Syntax
<figlet>text</figlet> (default font=standard)
<figlet font=fontname>text</figlet> (set another font)
<figlet>$fonts</figlet> (show font list)
<figlet font=$self>$self</figlet> (special for template usage, $self=pagename)
[edit] Example
<figlet>moo</figlet>
_ __ ___ ___ ___
| '_ ` _ \ / _ \ / _ \
| | | | | | (_) | (_) |
|_| |_| |_|\___/ \___/
[edit] Result
+-+-+-+ |m|o|o| +-+-+-+
[edit] Example
<figlet>$fonts</figlet>
[edit] Result
Available figlet fonts: banner big block bubble digital ivrit lean mini mnemonic script shadow slant small smscript smshadow smslant standard term
For all fonts also see Category:Figlet
[edit] Source
Historic: The original idea by DrOwl: "this is a first untested version with just monkey knolage of how to make it work"
<?php
# Figlet Mediawiki extension
# using shell figlet
# by DrOwl 21.06.2005 modded from
# by mutante 25.03.2005
# modded again 21.05.2005 ,mutante
# modded again Owl & mutante 20.06.2006 - the slightly more secure 23 line version
$wgExtensionFunctions[] = "wfFigletExtension";
#extension hook callback function
function wfFigletExtension() {
global $wgParser;
#install parser hook for <figlet> tags
$wgParser->setHook( "figlet", "renderFiglet" );
}
function renderFiglet( $input ) {
global $wgOutputEncoding;
$input = mysql_escape_string($input);
$output="<pre>";
$output.=shell_exec("figlet " . escapeshellarg($input));
$output.="</pre>";
return $output;
}
?>
[edit] Current Source
<?php
# Figlet Mediawiki extension
# using shell figlet
# by DrOwl 21.06.2005 modded from
# by mutante 25.03.2005
# modded again 21.05.2005 ,mutante
# modded again Owl & mutante 20.06.2006 - the slightly more secure 23 line version
# modded again, mutante 22.06.2006 - the advanced version with fonts
# modded again, mutante 06.11.2006 - fixed bug (ctype_alnum) & added ExtensionCredits
$wgExtensionFunctions[] = "wfFigletExtension";
#extension hook callback function
function wfFigletExtension() {
global $wgParser;
#install parser hook for <figlet> tags
$wgParser->setHook( "figlet", "renderFiglet" );
}
$wgExtensionCredits['parserhook'][] = array(
'name' => 'figlet extension',
'author' => '[[User:DrOwl|DrOwl]] / [[User:Mutante|mutante]]',
'url' => 'http://s23.org/wiki/Figlet Extension',
'version' => '0.23',
);
function renderFiglet( $input, $argv, &$parser) {
global $wgOutputEncoding;
$baseurl="http://s23.org/wiki/";
# if ($argv["font"] && $argv["font"] <80 && ctype_alnum($argv["font"])) {
# <- this didnt work anymore after mediawiki and php upgrade somehow, removed "ctype_alnum", 061106
if ($argv["font"] && $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.="[[figlet/fonts/$font|$font]] ";
}
$parsesyntax = $localParser->parse($syntax, $parser->mTitle, $parser->mOptions);
$output.=$parsesyntax->getText();
} else {
$output="<pre>";
if ($input =="\$self") {
# $nt = Title::makeTitle( $row->page_namespace, $row->page_title );
# $input = $nt->getFullURL();
$title=$_GET["title"];
$title=explode("/",$title);
$title=$title[2];
$input=$title;
$fileinfocmd="head -n8 /usr/share/figlet/".$title.".flf";
$description=`$fileinfocmd`;
$comment="<br \>This font for [[figlet]] is called \"'''$title'''\".
File info: $description
You can create it with the wiki syntax: '''<nowiki><figlet font=$title>text</figlet></nowiki>'''.
Other fonts are in [[:Category:Figlet|Category:Figlet]].";
$parsecomment = $localParser->parse($comment, $parser->mTitle, $parser->mOptions);
$comment=$parsecomment->getText();
}
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|Category:Figlet]] or via '''<nowiki><figlet>$fonts</figlet></nowiki>'''.";
$parsesyntax = $localParser->parse($syntax, $parser->mTitle, $parser->mOptions);
$output.=$parsesyntax->getText();
} else {
# do we also need to fix <! here?
$figlet = str_replace("<!","<!",$figlet);
$figlet = str_replace("</","</",$figlet);
# actual output
$output.=$figlet;
if ($comment) {
$output.=$comment;
}
}
$output.="</pre>";
# $output.="userfont: $userfont uinput: $uinput";
}
return $output;
}
?>
See ongoing talk.
We use Syntax Highlighting Extension here to highlight the PHP source.

