${1}',$html); // emphasized $html = preg_replace('/\'\'([^\'\n]+)\'\'?/','${1}',$html); //interwiki links $html = preg_replace_callback('/\[\[([^\|\n\]:]+)[\|]([^\]]+)\]\]/','helper_interwikilinks',$html); // without text $html = preg_replace_callback('/\[\[([^\|\n\]:]+)\]\]/','helper_interwikilinks',$html); // //$html = preg_replace('/{{([^}]+)+}}/','Interwiki: ${1}+${2}+${3}',$html); $html = preg_replace('/{{([^\|\n\}]+)([\|]?([^\}]+))+\}\}/','Interwiki: ${1} » ${3}',$html); // Template //$html = preg_replace('/{{([^}]*)}}/',' ',$html); // categories //$html = preg_replace('/\[\[([^\|\n\]]+)([\|]([^\]]+))?\]\]/','',$html); $html = preg_replace('/\[\[([^\|\n\]]{2})([\:]([^\]]+))?\]\]/','Translation: ${1} » ${3}',$html); $html = preg_replace('/\[\[([^\|\n\]]+)([\:]([^\]]+))?\]\]/','Category: ${1} - ${2}',$html); // image $html = preg_replace('/\[\[([^\|\n\]]+)([\|]([^\]]+))+\]\]/','Image: ${0}+${1}+${2}+${3}',$html); //links //$html = preg_replace('/\[([^\[\]\|\n\': ]+)\]/','${1}',$html); $html = preg_replace_callback('/\[([^\[\]\|\n\': ]+)\]/','helper_externlinks',$html); // with text //$html = preg_replace('/\[([^\[\]\|\n\' ]+)[\| ]([^\]\']+)\]/','${2}',$html); $html = preg_replace_callback('/\[([^\[\]\|\n\' ]+)[\| ]([^\]\']+)\]/','helper_externlinks',$html); // allowed tags $html = preg_replace('/<(\/?)(small|sup|sub|u)>/','<${1}${2}>',$html); $html = preg_replace('/\n*<br *\/?>\n*/',"\n",$html); $html = preg_replace('/<(\/?)(math|pre|code|nowiki)>/','<${1}pre>',$html); $html = preg_replace('/<!--/','',$html); // headings for($i=7;$i>0;$i--){ $html = preg_replace( '/\n+[=]{'.$i.'}([^=]+)[=]{'.$i.'}\n*/', '${1}', $html ); } //lists $html = preg_replace( '/(\n[ ]*[^#* ][^\n]*)\n(([ ]*[*]([^\n]*)\n)+)/', '${1}'."\n", $html ); $html = preg_replace( '/(\n[ ]*[^#* ][^\n]*)\n(([ ]*[#]([^\n]*)\n)+)/', '${1}
    '."\n".'${2}'.'
'."\n", $html ); $html = preg_replace('/\n[ ]*[\*#]+([^\n]*)/','
  • ${1}
  • ',$html); $html = preg_replace('/----/','
    ',$html); //$html = nl2br($html); // line breaks $html = preg_replace('/[\n\r]{4}/',"

    ",$html); $html = preg_replace('/[\n\r]{2}/',"
    ",$html); $html = preg_replace('/[>][<]/',"><",$html); return $html; } function helper_externlinks($matches){ $target = $matches[1]; $text = empty($matches[2])?$matches[1]:$matches[2]; return ''.$text.''; } function helper_interwikilinks($matches){ $target = $matches[1]; $text = empty($matches[2])?$matches[1]:$matches[2]; $class=" class=\"dunno\" "; /*static $links_checked_interwiki = 0; if(!$_GET["nocache"] && ++$links_checked_interwiki<10){ $data = cachedFunc("getPos",$target); if($data["pos"]) $class = " class=\"exists\" "; $class = " class=\"notexists\" "; }*/ return ''.$text.''; } function convertTables($text){ $lines = explode("\n",$text); $innertable = 0; $innertabledata = array(); foreach($lines as $line){ //echo "
    ".++$i.": ".htmlspecialchars($line)."
    "; $line = str_replace("position:relative","",$line); $line = str_replace("position:absolute","",$line); if(substr($line,0,2) == '{|'){ // inner table //echo "

    beginning inner table #$innertable

    "; $innertable++; } $innertabledata[$innertable] .= $line . "\n"; if($innertable){ // we're inside if(substr($line,0,2) == '|}'){ $innertableconverted = convertTable($innertabledata[$innertable]); $innertabledata[$innertable] = ""; $innertable--; $innertabledata[$innertable] .= $innertableconverted."\n"; } } } return $innertabledata[0]; } function convertTable($intext){ $text = $intext; $lines = explode("\n",$text); $intable = false; //var_dump($lines); foreach($lines as $line){ $line = trim($line); if(substr($line,0,1) == '{'){ //begin of the table $stuff = explode('| ',substr($line,1),2); $tableopen = true; $table = "\n"; } else if(substr($line,0,1) == '|'){ // table related $line = substr($line,1); if(substr($line,0,5) == '-----'){ // row break if($thopen) $table .="\n"; if($tdopen) $table .="\n"; if($rowopen) $table .="\t\n"; $table .= "\t\n"; $rowopen = true; $tdopen = false; $thopen = false; }else if(substr($line,0,1) == '}'){ // table end break; }else{ // td $stuff = explode('| ',$line,2); if($tdopen) $table .="\n"; if(count($stuff)==1) $table .= "\t\t\n"; if($tdopen) $table .="\n"; if($rowopen) $table .="\t\n"; if($tableopen) $table .="
    ".simpleText($stuff[0]); else $table .= "\t\t". simpleText($stuff[1]); $tdopen = true; } } else if(substr($line,0,1) == '!'){ // th $stuff = explode('| ',substr($line,1),2); if($thopen) $table .="\n"; if(count($stuff)==1) $table .= "\t\t".simpleText($stuff[0]); else $table .= "\t\t". simpleText($stuff[1]); $thopen = true; }else{ // plain text $table .= simpleText($line) ."\n"; } //echo "
    ".++$i.": ".htmlspecialchars($line)."
    "; //echo "

    Table so far:

    ".htmlspecialchars($table)."

    "; } if($thopen) $table .="
    \n"; //echo "
    "; //echo "

    Table at the end:

    ".htmlspecialchars($table)."

    "; //echo $table; return $table; }