imported>DrOwl No edit summary |
imported>DrOwl No edit summary |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== Discription == |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
we need to replace out any code that wiki might process... |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
symbols wiki uses and there excape codes |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
# = # |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
{ = { |
|||
| = | |
|||
} = } |
|||
~ = ~ |
|||
== Syntax == |
|||
⚫ | |||
⚫ | |||
⚫ | |||
=== 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 <b> bit isnt in bold =) |
||
</pre> |
</pre> |
||
== Source == |
|||
<highlightSyntax> |
|||
<code> |
|||
<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 < |
#install parser hook for <code2> tags |
||
$wgParser->setHook( " |
$wgParser->setHook( "code2", "renderCode" ); |
||
} |
} |
||
function renderCode( $input ) { |
function renderCode( $input ) { |
||
global $wgOutputEncoding; |
global $wgOutputEncoding; |
||
# $input = mysql_escape_string($input); |
|||
if (!$input) $input = "mu"; # |
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/]/&# |
$input =~ s/]/]/g; |
||
$input =~ s/{/{/g; |
|||
$input =~ s/|/|/g; |
$input =~ s/|/|/g; |
||
$input =~ s/}/}/g; |
|||
$input =~ s/~/~/g; |
|||
$output="<nowiki><pre></nowiki>"; |
$output="<nowiki><pre></nowiki>"; |
||
Line 71: | Line 91: | ||
?> |
?> |
||
</pre> |
|||
</highlightSyntax> |
|||
</code> |
|||
[[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
< = <
> = >
# = #
[ = [
\ = \
{ = {
| = |
} = }
~ = ~
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
- code Mediawiki extension
- using regex
- by DrOwl 21.06.2005 <- a Date in the Future ,ehe ;)
- upDated 23.06.2006
- added in a few more regEx's and renamed to code2
- install extension hook
$wgExtensionFunctions[] = "wfCodeExtension";
- 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>