×
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>DrOwl
    (copy from muts media wiki)
     
    imported>DrOwl
    No edit summary
     
    (34 intermediate revisions by 2 users not shown)
    Line 1: Line 1:
    Integrate [[RSS]] feeds into wiki pages using [http://magpierss.sourceforge.net/ magpieRSS] (a [[PHP]] [[RSS]] parser class) in a custom [[Mediawiki]] extension:
    Integrate [[figlet]] text into wiki pages using [http://figletlink/ figletlink] in a custom [[Mediawiki]] extension:


    === Syntax ===
    (For example to [http://is-root.de/wiki/index.php/RecentChangesOfOurNeighbors interwiki syndicate RecentChanges pages].)


    <nowiki><figlet>text</figlet></nowiki> (default font=standard)
    [[User:mutante|mutante]] 20:57, 25 Mar 2005 (UTC)


    <nowiki><figlet font=fontname>text</figlet></nowiki> (set another font)


    <nowiki><figlet>$fonts</figlet></nowiki> (show font list)
    === Syntax ===
    <nowiki><rss>URL</rss></nowiki>


    <nowiki><figlet font=$self>$self</figlet></nowiki> (special for template usage, $self=pagename)
    ==== Example ====


    === Example ===
    <nowiki><rss>http://slashdot.org/slashdot.rss</rss></nowiki>


    <nowiki><figlet>moo</figlet></nowiki>

    <figlet>moo</figlet>
    === Result ===
    === Result ===


    <figlet font=digital>moo</figlet>
    <rss>http://slashdot.org/slashdot.rss</rss>



    (not installed on wikipedia, but [http://is-root.de/wiki/index.php/MediawikiExtensions/RSS here])
    === Example ===

    <nowiki><figlet>$fonts</figlet></nowiki>

    === Result ===

    <figlet>$fonts</figlet>


    For all fonts also see [[:Category:Figlet]]


    === Source ===
    === Source ===


    Historic: The original idea by [[User:DrOwl|DrOwl]]: "this is a first untested version with just monkey knolage of how to make it work"
    <pre>

    <highlightSyntax>
    <?php
    <?php
    # RSS-Feed Mediawiki extension
    # Figlet Mediawiki extension
    # using shell figlet
    # using magpieRSS (http://magpierss.sourceforge.net/)
    # by DrOwl 21.06.2005 modded from
    # by mutante 25.03.2005
    # 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;
    }
    ?>
    </highlightSyntax>


    === Current Source ===
    require_once('magpierss-0.71.1/rss_fetch.inc');
    $wgExtensionFunctions[] = "wfRssExtension";


    <highlightSyntax>
    function wfRssExtension() {
    <?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;
    global $wgParser;
    #install parser hook for <figlet> tags
    $wgParser->setHook( "rss", "renderRss" );
    $wgParser->setHook( "figlet", "renderFiglet" );
    }
    }




    $wgExtensionCredits['parserhook'][] = array(
    function renderRss( $input ) {
    '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) {
    # $input = mysql_escape_string($input);
    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: '''";
    $rss = fetch_rss($input);


    foreach ($fonts as $font) {
    $output="<table><tr><th>Channel Title: </th><th>" . $rss->channel['title'] . "</th></tr>";
    $font=trim($font);
    $output.="<tr><td>";
    $syntax.="[[figlet/fonts/$font|$font]] ";
    foreach ($rss->items as $item) {
    $href = $item['link'];
    $title = $item['title'];
    $output.="<td colspan='2'><a href='$href'>$title</a></td></tr>";
    }
    }
    $output.="</table>";


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


    $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"];
    </pre>
    $userfont=explode("/",$userfont);
    $userfont=$userfont[2];
    }


    $uinput=escapeshellarg($input);
    === Improved Version by [[User:Duesentrieb|Duesentrieb]] ===
    $userfont=escapeshellarg($userfont);


    $figlet=shell_exec("figlet -f $userfont $uinput");
    : Also have a look at [[User:Duesentrieb/RSS]] for a modified version with a few more features -- [[User:Duesentrieb|Duesentrieb]] 01:29, 2 May 2005 (UTC)


    if (!$figlet) {
    This includes converting different charsets using iconv and an option to hide the description (shortened list). Thanks for your help , [[User:Duesentrieb|Duesentrieb]], I didnt feel like messing with the charset conversion especially. [[User:mutante|mutante]] 22:31, 5 May 2005 (UTC)


    $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("<!","&#60;&#33;",$figlet);
    $figlet = str_replace("</","&#60;&#47;",$figlet);
    # actual output

    $output.=$figlet;

    if ($comment) {
    $output.=$comment;
    }

    }

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

    return $output;
    }
    ?>
    </highlightSyntax>


    See ongoing [[User_talk:DrOwl/wikiFiglet|talk]].


    We use [http://meta.wikimedia.org/wiki/Syntax_Highlighting_Extension Syntax Highlighting Extension] here to highlight the [[PHP]] source.


    [[Category:Mediawiki Extensions]]
    [[Category:Mediawiki Extensions]]
    [[Category:Figlet]]

    Latest revision as of 09:56, 11 July 2008

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

    Syntax[edit]

    <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[edit]

    <figlet>moo</figlet>

    <figlet>moo</figlet>

    Result[edit]

    <figlet font=digital>moo</figlet>


    Example[edit]

    <figlet>$fonts</figlet>

    Result[edit]

    <figlet>$fonts</figlet>


    For all fonts also see Category:Figlet

    Source[edit]

    Historic: The original idea by DrOwl: "this is a first untested version with just monkey knolage of how to make it work"

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

    Current Source[edit]

    <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' => 'DrOwl / mutante',
           '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>

    See ongoing talk.

    We use Syntax Highlighting Extension here to highlight the PHP source.

    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.