×
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

    User:DrOwl/wikiCode: Difference between revisions

    Content added Content deleted
    imported>DrOwl
    mNo edit summary
    imported>DrOwl
    No edit summary
     
    (7 intermediate revisions by the same user not shown)
    Line 1: Line 1:
    == Discription ==
    add a code tag into wiki pages using some regex and the pre tag in a custom [[Mediawiki]] extension:


    add a code2 tag into wiki pages using some regex and the pre tag in a custom [[Mediawiki]] extension:
    < = &amp;lt;


    its for displaying code and such like below, but with out the messing about
    > = &amp;gt;


    we need to replace out any code that wiki might process...
    [ = &amp;#91;


    this is a first untestedversion with just monkey knolage of how to make it work
    ] = &amp;#92;
    === Symbols ===
    symbols wiki uses and there excape codes


    &lt; = &amp;lt;
    its for displaying code and such like below, but with outthe messing about


    &gt; = &amp;gt;
    this is a first untestedversion with justmonkey knolage of how to make it work
    === Syntax ===
    <nowiki><code>text</code></nowiki>


    &#35; = &amp;#35;
    ==== Example ====


    &#91; = &amp;#91;
    <nowiki><code>some code including html tags and such things... </code></nowiki>

    &#92; = &amp;#92;

    &#123; = &amp;#123;

    &#124; = &amp;#124;

    &#125; = &amp;#125;

    &#126; = &amp;#126;



    == Syntax ==
    <nowiki><code2>text</code2></nowiki>

    == Example ==

    <nowiki><code2>some code including &lt;b&gt; html&lt;/b&gt; tags and such things... </code2></nowiki>


    === example Result ===
    === example Result ===


    <pre>
    <pre>
    just the code form above displayed instead of "run" =)
    just the code form above displayed instead of "run" ie the &lt;b&gt; bit isnt in bold =)
    </pre>
    </pre>




    === Source ===
    == Source ==
    <highlightSyntax>

    <pre>
    <?php
    <?php
    # code Mediawiki extension
    # code Mediawiki extension
    # using regex
    # using regex
    # by DrOwl 21.06.2005 <- a Date in the Future ,ehe ;)
    # by DrOwl 21.06.2005 <- a Date in the Future ,ehe ;)
    # upDated 23.06.2006
    #modded from
    # added in a few more regEx's and renamed to code2
    # by mutante 25.03.2005


    #install extension hook
    #install extension hook
    Line 44: Line 62:
    global $wgParser;
    global $wgParser;
    #install parser hook for <code> tags
    #install parser hook for <code2> tags
    $wgParser->setHook( "code", "renderCode" );
    $wgParser->setHook( "code2", "renderCode" );
    }
    }


    function renderCode( $input ) {
    function renderCode( $input ) {
    global $wgOutputEncoding;
    global $wgOutputEncoding;
    # $input = mysql_escape_string($input);
    if (!$input) $input = "mu"; #ifno input then mu
    if (!$input) $input = "mu"; #if no input then mu


    $input =~ s/&/&amp;/g;
    $input =~ s/&/&amp;/g;
    $input =~ s/</&lt;/g;
    $input =~ s/</&lt;/g;
    $input =~ s/>/&gt;/g;
    $input =~ s/>/&gt;/g;
    $input =~ s/#/&#35;/g;
    $input =~ s/[/&#91;/g;
    $input =~ s/[/&#91;/g;
    $input =~ s/]/&#92;/g;
    $input =~ s/]/&#93;/g;
    $input =~ s/{/&#123;/g;
    $input =~ s/|/&#124;/g;
    $input =~ s/}/&#125;/g;
    $input =~ s/~/&#126;/g;


    $output="<nowiki><pre></nowiki>";
    $output="<nowiki><pre></nowiki>";
    Line 70: Line 91:


    ?>
    ?>
    </pre>



    </highlightSyntax>


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

    Latest revision as of 22:19, 23 June 2006

    Discription[edit]

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

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

    we need to replace out any code that wiki might process...

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

    Symbols[edit]

    symbols wiki uses and there excape codes

    < = &lt;

    > = &gt;

    # = &#35;

    [ = &#91;

    \ = &#92;

    { = &#123;

    | = &#124;

    } = &#125;

    ~ = &#126;


    Syntax[edit]

    <code2>text</code2>

    Example[edit]

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

    example Result[edit]

    just the code form above displayed instead of "run" ie the <b> bit isnt in bold  =)
    


    Source[edit]

    <highlightSyntax> <?php

    1. code Mediawiki extension
    2. using regex
    3. by DrOwl 21.06.2005 <- a Date in the Future ,ehe ;)
    4. upDated 23.06.2006
    5. added in a few more regEx's and renamed to code2
    1. install extension hook

    $wgExtensionFunctions[] = "wfCodeExtension";


    1. extension hook callback function

    function wfCodeExtension() {

     global $wgParser;
    
     #install parser hook for <code2> tags
     $wgParser->setHook( "code2", "renderCode" );
    

    }

    function renderCode( $input ) { global $wgOutputEncoding;

    if (!$input) $input = "mu"; #if no input then mu

    $input =~ s/&/&/g; $input =~ s/</</g; $input =~ s/>/>/g; $input =~ s/#/#/g; $input =~ s/[/[/g; $input =~ s/]/]/g; $input =~ s/{/{/g; $input =~ s/|/|/g; $input =~ s/}/}/g; $input =~ s/~/~/g;

    $output="<pre>"; $output."$input"; $output.="</pre>";

    return $output;

    }

    ?>

    </highlightSyntax>
    
    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.