×
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
    Revision as of 21:29, 19 June 2006 by imported>DrOwl

    add a code tag into wiki pages using some regex and the pre tag in a custom Mediawiki extension:

    < = &lt;

    > = &gt;

    [ = &#91;

    ] = &#92;

    its for displaying code and such like below, but with outthe messing about

    this is a first untestedversion with justmonkey knolage of how to make it work

    Syntax

    <code>text</code>

    Example

    <code>some code including html tags and such things... </code>

    example Result

    just the code form above displayed instead of "run" =)
    


    Source

    <?php
    # code Mediawiki extension
    # using regex
    # by DrOwl 21.06.2005  <- a Date in the Future ,ehe ;)
    #modded from
    # by mutante 25.03.2005
    
    #install extension hook
    $wgExtensionFunctions[] = "wfCodeExtension";
    
    
    #extension hook callback function
    function wfCodeExtension() { 
      global $wgParser;
     
      #install parser hook for <code> tags
      $wgParser->setHook( "code", "renderCode" );
    }
    
    function renderCode( $input ) {
    global $wgOutputEncoding;
     
        # $input = mysql_escape_string($input);
        
    if (!$input) $input = "mu"; #ifno input then mu
    
    $input =~ s/&/&/g;
    $input =~ s/</</g;
    $input =~ s/>/>/g;
    $input =~ s/[/[/g;
    $input =~ s/]/\/g;
    $input =~ s/|/|/g;
    
    $output="<pre>";
    $output."$input";
    $output.="<nowiki>

    </nowiki>";

    return $output;

    }

    ?>

    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.