×
Create a new article
Write your page title here:
We currently have 3,189 articles on s23. Type your article name above or create one of the articles listed here!



    s23
    3,189Articles

    Figlet Extension: Difference between revisions

    Content added Content deleted
    imported>mutante
    m (User:DrOwl/wikiFiglet moved to Figlet Extension: hard to find in userspace)
    imported>mutante
    m (new fixed version)
    Line 67: Line 67:
    # modded again Owl & mutante 20.06.2006 - the slightly more secure 23 line version
    # 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 22.06.2006 - the advanced version with fonts
    # modded again, mutante 06.11.2006 - fixed bug (ctype_alnum) & added ExtensionCredits
    $wgExtensionFunctions[] = "wfFigletExtension";
    $wgExtensionFunctions[] = "wfFigletExtension";
    #extension hook callback function
    #extension hook callback function
    Line 74: Line 75:
    $wgParser->setHook( "figlet", "renderFiglet" );
    $wgParser->setHook( "figlet", "renderFiglet" );
    }
    }


    $wgExtensionCredits['parserhook'][] = array(
    'name' => 'figlet extension',
    'author' => 'mutante / DrOwl',
    'url' => 'http://s23.org/wiki/Figlet Extension',
    'version' => '0.23',
    );


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


    if ($argv["font"] && $argv["font"] <80 && ctype_alnum($argv["font"])) {
    # 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"];
    $userfont=$argv["font"];
    } else {
    } else {
    Line 159: Line 170:


    $output.="</pre>";
    $output.="</pre>";
    # $output.="userfont: $userfont uinput: $uinput";
    }
    }



    Revision as of 06:36, 6 November 2006

    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

    <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)

    Example

    <figlet font=23>moo</figlet>

    example Result

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

    test Result

    <figlet font=`cat /etc/passwd`>`cat /etc/passwd`</figlet>

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

    Source

    <highlightSyntax> <?php

    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

    $wgExtensionFunctions[] = "wfFigletExtension";

    1. extension hook callback function

    function wfFigletExtension() { global $wgParser;

    1. install parser hook for <figlet> tags

    $wgParser->setHook( "figlet", "renderFiglet" ); } function renderFiglet( $input ) { global $wgOutputEncoding; $input = mysql_escape_string($input);

    $output="

    ";
    $output.=shell_exec("figlet " . escapeshellarg($input));
    $output.="

    ";

    return $output; } ?> </highlightSyntax>

    <highlightSyntax> <?php

    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
    8. modded again, mutante 06.11.2006 - fixed bug (ctype_alnum) & added ExtensionCredits

    $wgExtensionFunctions[] = "wfFigletExtension";

    1. extension hook callback function

    function wfFigletExtension() { global $wgParser;

    1. install parser hook for <figlet> tags

    $wgParser->setHook( "figlet", "renderFiglet" );

      }
    


    $wgExtensionCredits['parserhook'][] = array(

           'name' => 'figlet extension',
           'author' => 'mutante / DrOwl',
           'url' => 'http://s23.org/wiki/Figlet Extension',
           'version' => '0.23',
    

    );

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

    1. if ($argv["font"] && $argv["font"] <80 && ctype_alnum($argv["font"])) {
    2. <- 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.="$font "; }

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

    $output.=$parsesyntax->getText();

    } else {

    $output="

    ";
    
    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: '''<figlet font=$title>text</figlet>'''.
    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 '''<figlet>$fonts</figlet>'''.";
    $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.="

    ";

    1. $output.="userfont: $userfont uinput: $uinput";

    }

    return $output; } ?> </highlightSyntax>

    not installed yet, see ongoing talk.

    To avoid problems with </pre> inside code in a <pre>, use <pre>blah blah code <nowiki></pre></nowiki> blah blah more code </pre>.

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

    Cookies help us deliver our services. By using our services, you agree to our use of cookies.
    Cookies help us deliver our services. By using our services, you agree to our use of cookies.