root > WikiSense-trunk > util > stripNowiki.php

stripNowiki.php

application/x-php, 771 bytes (load raw)
<?php

function escapeWikiText( $text ) {
        $text = str_replace(
                array( '[',     '|',      '\'',    'ISBN ',     'RFC ',     '://',     "\n=",     '{{' ),
                array( '&#91;', '&#124;', '&#39;', 'ISBN&#32;', 'RFC&#32;', '&#58;//', "\n&#61;", '&#123;&#123;' ),
                htmlspecialchars($text) );
        return $text;
}

function recodeWikiText( $text ) {
   $text= str_replace('&#58;//','://',$text); #break urls - avoid triggering captcha protection
   $text= str_replace('&lt;/nowiki&gt;','</nowiki>',$text);
   return escapeWikiText( $text );
}

$f = "php://stdin";
if (sizeof($argv)>1) $f = $argv[1];

$text = file_get_contents($f);
if ($text===false) die("failed to read $f!\n");

$text = preg_replace('!<nowiki>(.*?)</nowiki>!sie', 'recodeWikiText("\1")', $text);

print $text;
?>