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



    s23
    3,185Articles

    Talk:Figlet Extension

    ok we stilll need to do playing for the excapecommands and such... maybe we can just run some tr RegXs for doggy chars... there must be a way formaking it safe =) ill checkout the perl version =)

    +the passthrough command works in my tests ie, using

    <pre> <?php passthru('echo moo | /home/drowl/figlet/figlet -d /home/drowl/figlet/fonts'); ?> </pre>

    returns the multi line figlet on my shell

    may be its to do with this $output. thing... could we "$figlet = s/\n/<br \/>/g" ie replace the newline char with a html br

    +still need to add the font tags =)

    --DrOwl 00:32, 23 May 2005 (CEST)


    hummm found [escapeshellcmd()] and [exec()]

    oki i see =) simple really just need to chek it out with php instead of perl =)

    i guessit willbe similer becouse its just somenice regex =)

    #!/usr/bin/perl -w
    #Figlet-CGI 0.1 by Matthew Borowski
    #(C)1999 WorldServe Consulting http://www.worldserve.net
    #License: BSD
    #Make sure to set the variables below
    #
    #use the CGI.pm object-oriented module
    use strict;
    use CGI;
    my ($query, $text, $fontname, $fontpath, $maxfontname, $maxtext, $figlet, $fontnameext, @newtext);
    #set your font path here (directory with your .flf files) with trailing slash
    $fontpath = "/home/drowl/figlet/fonts/";
    #set the full path to figlet here
    $figlet = "/home/drowl/figlet/figlet";
    #set the maximum length of $fontname
    $maxfontname = "30";
    #set the maximum length of $text
    $maxtext = "50";
    #
    #
    #process the query (either GET or POST)
    $query = new CGI;
    #print the content-type out
    print $query->header;
    
    #make sure font is specified, else quit
    unless ($query->param('fontname')){
       #print the starting html
       print $query->start_html("Figlet Error");
       print "<p>Sorry, you didn't select a fontname.\n";
       exit;
    }
    else {
       #set the text variable
       $fontname = $query->param('fontname');
       #escape out the single-quotes so we can enclose in single quote below
       $fontname =~ s:\':\'\\'\':g;
    }
    #if font is longer than $maxfontname characters, quit
    if (length($query->param('fontname')) > $maxfontname){
       #print the starting html
       print $query->start_html("Figlet Error");
       print "<p>Sorry, your text is too long (longer than $maxfontname characters).\n";
       exit;
    }
    #if fontname doesn't end in .flf, then quit
    $fontnameext = substr($fontname, -4);
    unless ($fontnameext eq ".flf"){
       print $query->start_html("Figlet Error");
       print "<p>Sorry, your fontname does not end in .flf\n";
       exit;
    }
    #unless we can open the file, exit
    unless(-r "$fontpath$fontname"){
       print $query->start_html("Figlet Error");
       print "<p>Invalid font. Cannot open $fontname.\n";
       exit;
    }
       
    #make sure text is specified, else quit
    unless ($query->param('text')){
       #print the starting html
       print $query->start_html("Figlet Error");
       print "<p>Sorry, you didn't specify any text.\n";
       exit;
    }
    else {
       #set the text variable
       $text = $query->param('text');
       #escape out the single-quotes so we can enclose in single quote below
       $text =~ s:\':\'\\'\':g;
    }
    #if text is longer than $maxtext characters, quit
    if (length($query->param('text')) > $maxtext){
       #print the starting html
       print $query->start_html("Figlet Error");
       print "<p>Sorry, your text is too long (longer than $maxtext characters).\n";
       exit;
    }
    #print the starting html
    print $query->start_html("Figlet: $text");
    
    #print the main part of the page
    print <<END;
    
    <h2>FnorD here is your words</h2>
    <p>YoU wanTed to see '$text' in the StYle of  $fontname
    <hr>
    END
    
    #newtext variable becomes the output of the figlet command
    @newtext=`echo '$text' | $figlet -d '/home/drowl/figlet/fonts' -f '$fontpath$fontname'`;
    #turn the < and > signs into proper HTML formatting (< and >)
    s/</</g for @newtext;
    s/>/>/g for @newtext;
    
    print "<p><pre>\n @newtext</pre>\n";
    print "<hr>\n";
    print "<A href=/index.php target=master>Home</a>  <A href=/figlet.php target=master>Figlet</a><br>\n";
    print "<p><font size=-1> method $ENV{'REQUEST_METHOD'} by $ENV{'REMOTE_USER'} $ENV{'REMOTE_HOST'} ($ENV{'REMOTE_ADDR'}) with $ENV{'HTTP_USER_AGENT'}</font>\n";
    print $query->end_html;
    
    #END
    

    --DrOwl 00:49, 23 May 2005 (CEST)


    Installed it now and testing. Returns the figlet now, but BEFORE all other html. Trying to fix...

    getting this help: < dammit> mutante: try using popen("figlet $input","r");

    stay tuned... mutante 13:12, 21 May 2005 (CEST)

    
    13:06 < mutante> hmm,while trying to write a mediawiki extension i always get the output i return BEFORE all other html in
                     the wiki pages instead of inline...what could i be doing wrong
    13:08 < mutante> $output=system ("figlet $input"); <maybe connected to using a system command to create output
    13:08 < dammit> of course, PECL would do the job
    13:09 < mutante> it returns what i want, just before the rest of all html
    13:09 < dammit> haha, figlet ;-)
    13:09 < mutante> yea *g*
    13:09 < dammit> mutante: try using popen("figlet $input","r");
    13:09 < dammit> and don't forget to escape special characters in your $input
    13:09 < dammit> or you'll end up in h4x0red box
    13:10 < mutante> dammit: $input = mysql_escape_string($input);  good enough?
    13:12 < dammit> *shrug* :)
    13:12 < dammit> then make it "figlet '$input'"
    13:12 < JeLuF> mutante: No. mysql_escape_string is for SQL commands, not for shell commands
    13:13 < mutante> JeLuF: oh,yea,is there something like "bash_escape_string" ?
    13:14 < mutante> i guess i need to be afraid of ;'s
    13:14 < JeLuF> or $( or ` or or or
    13:14 < hendrik> escapeshellcmd
    13:15 < JeLuF> mutante: http://de2.php.net/manual-lookup.php?pattern=escape
    13:15 < mutante> does this sound good: $input =~ /[Aa-Zz]|[1-0];
    13:15 < TimStarling> use wfEscapeShellArg, it works on windows, kind of
    13:15 < mutante> thanks for all the help
    

    output info[edit]

    some intresting info here http://meta.wikimedia.org/wiki/MediaWiki_extensions_FAQ#How_do_I_render_wikitext_in_my_extension.3F

    How do I render wikitext in my extension?[edit]

    Use the already defined $wgOut OutputPage object to parse it.

    function myHook($input) {
      global $wgOut;
      return $wgOut->parse('some wiki text');
    }
    

    The parse method by default adds <p> tags around the generated HTML. This may not be what you want if you want to include the HTML inline with other content that you are generating programmatically. To disable this feature, just provide an additional argument with a value of false. For example:

      $wgOut->parse('some wiki text');
      # Returns '<p>some wiki text</p>'
    
      $wgOut->parse('some wiki text',false);
      # Returns 'some wiki text'
    

    You can also use the Parser object instead of accessing the global:

     function myHook($input, $argv, &$parser)
     {
         $output = $parser->parse("<big>$input</big>", $parser->mTitle,
                                  $parser->mOptions, true, false);
         $text = $output->getText();
         [...]
     }
    

    On MediaWiki 1.6.3, neither forms strip UNIQ's (which replace nowiki, pre, math, and other tags). Is it possible to render completely wikitext to HTML in an extension? --Shellreef 00:07, 1 June 2006 (UTC)


    Alternative approach to extending Wikitext[edit]

    The above options indeed replace all but the last extension tag with those wacky UNIQ3421234asD-w-QWE texts. Playing around a bit, I went to the source: Parser.php. This is strictly speaking not an extension-fix — it's another way to accomplish the same task. Open Parser.php, and right at the beginning of function parse() include:

    include "./extensions/custom_tags.php";

    Then, create that custom_tags.php file and fill in whatever replace-rules you need:

    $text = preg_replace ("#\[t](.+?)\[/t]#is", "<div class=\"trans\">\\1</div>", $text);
    $text = preg_replace ("#\[pas](.+?)\[/pas]#is", "<div class=\"passage\">\\1</div>", $text);

    And so on and so forth. I'm creating our tags in BBCode style, but you can do any replacements you want in this way. Tested with 1.6.6. (People, mention the software version number on which your hacks work!) —Madhava 22:38, 8 June 2006 (UTC)

    Actually, it's better to stick the include towards the end of the function, just before:
    wfRunHooks( 'ParserAfterTidy', array( &$this, &$text ) );
    
    I noticed some quirks with paragraph creation etc. if they were in the beginning - content with divs didn't receive < p > tags. --Madhava 18:09, 12 June 2006 (UTC)

    I moved the Figlet Extension page from your user space, if you dont mind. I put it into Category:Figlet, and fixed various things, like the figlet extension is working again (needed to reinstall figlet on server, its in debian 'non-free' & the template for them works again. Added extension credits into our extension ,so it now shows on Special:Version, had to remove the "ctype_alnum" for some reason etc.. Ah yeah, and the Syntax Highlighting extension is also reinstalled and updated. enjoy.. mutante 07:49, 6 November 2006 (CET)

    Oh, just one thing, i seem to be missing the selfmade fonts like "23" and maybe others we had. Also wasnt succesful finding it in backups, maybe you have it still on your server? would be nice. mutante 07:51, 6 November 2006 (CET)

    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.