comment out entries that are the same as in en, use wfMsgNoDb( )
[lhc/web/wiklou.git] / includes / Parser.php
index ed67b7a..79aa4e7 100644 (file)
@@ -1,12 +1,12 @@
 <?php
 
-include_once('Tokenizer.php');
+require_once('Tokenizer.php');
 
 if( $GLOBALS['wgUseWikiHiero'] ){
-       include_once('wikihiero.php');
+       require_once('extensions/wikihiero/wikihiero.php');
 }
 if( $GLOBALS['wgUseTimeline'] ){
-       include_once('extensions/timeline/Timeline.php');
+       require_once('extensions/timeline/Timeline.php');
 }
 
 # PHP Parser
@@ -220,8 +220,12 @@ class Parser
 
                $text = Parser::extractTags("math", $text, $math_content, $uniq_prefix);
                foreach( $math_content as $marker => $content ){
-                       if( $render && $this->mOptions->getUseTeX() ){
-                               $math_content[$marker] = renderMath( $content );
+                       if( $render ) {
+                               if( $this->mOptions->getUseTeX() ) {
+                                       $math_content[$marker] = renderMath( $content );
+                               } else {
+                                       $math_content[$marker] = "&lt;math&gt;$content&lt;math&gt;";
+                               }
                        } else {
                                $math_content[$marker] = "<math>$content</math>";
                        }
@@ -405,7 +409,19 @@ class Parser
        /* interface with html tidy, used if $wgUseTidy = true */
        function tidy ( $text ) {
                global $wgTidyConf, $wgTidyBin, $wgTidyOpts;
+               global $wgInputEncoding, $wgOutputEncoding;
                $cleansource = '';
+               switch(strtoupper($wgOutputEncoding)) {
+                       case 'ISO-8859-1':
+                               $wgTidyOpts .= ($wgInputEncoding == $wgOutputEncoding)? ' -latin1':' -raw';
+                               break;
+                       case 'UTF-8':
+                               $wgTidyOpts .= ($wgInputEncoding == $wgOutputEncoding)? ' -utf8':' -raw';
+                               break;
+                       default:
+                               $wgTidyOpts .= ' -raw';
+                       }
+
                $text = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'.
 ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>'.
 '<head><title>test</title></head><body>'.$text.'</body></html>';
@@ -1528,26 +1544,34 @@ class Parser
        # Cleans up HTML, removes dangerous tags and attributes
        /* private */ function removeHTMLtags( $text )
        {
-               global $wgUseTidy;
+               global $wgUseTidy, $wgUserHtml;
                $fname = "Parser::removeHTMLtags";
                wfProfileIn( $fname );
-               $htmlpairs = array( # Tags that must be closed
-                       "b", "del", "i", "ins", "u", "font", "big", "small", "sub", "sup", "h1",
-                       "h2", "h3", "h4", "h5", "h6", "cite", "code", "em", "s",
-                       "strike", "strong", "tt", "var", "div", "center",
-                       "blockquote", "ol", "ul", "dl", "table", "caption", "pre",
-                       "ruby", "rt" , "rb" , "rp", "p"
-               );
-               $htmlsingle = array(
-                       "br", "hr", "li", "dt", "dd"
-               );
-               $htmlnest = array( # Tags that can be nested--??
-                       "table", "tr", "td", "th", "div", "blockquote", "ol", "ul",
-                       "dl", "font", "big", "small", "sub", "sup"
-               );
-               $tabletags = array( # Can only appear inside table
-                       "td", "th", "tr"
-               );
+               
+               if( $wgUserHtml ) {
+                       $htmlpairs = array( # Tags that must be closed
+                               "b", "del", "i", "ins", "u", "font", "big", "small", "sub", "sup", "h1",
+                               "h2", "h3", "h4", "h5", "h6", "cite", "code", "em", "s",
+                               "strike", "strong", "tt", "var", "div", "center",
+                               "blockquote", "ol", "ul", "dl", "table", "caption", "pre",
+                               "ruby", "rt" , "rb" , "rp", "p"
+                       );
+                       $htmlsingle = array(
+                               "br", "hr", "li", "dt", "dd"
+                       );
+                       $htmlnest = array( # Tags that can be nested--??
+                               "table", "tr", "td", "th", "div", "blockquote", "ol", "ul",
+                               "dl", "font", "big", "small", "sub", "sup"
+                       );
+                       $tabletags = array( # Can only appear inside table
+                               "td", "th", "tr"
+                       );
+               } else {
+                       $htmlpairs = array();
+                       $htmlsingle = array();
+                       $htmlnest = array();
+                       $tabletags = array();
+               }
 
                $htmlsingle = array_merge( $tabletags, $htmlsingle );
                $htmlelements = array_merge( $htmlsingle, $htmlpairs );
@@ -1650,6 +1674,8 @@ class Parser
 
        /* private */ function formatHeadings( $text )
        {
+               global $wgInputEncoding;
+               
                $doNumberHeadings = $this->mOptions->getNumberHeadings();
                $doShowToc = $this->mOptions->getShowToc();
                if( !$this->mTitle->userCanEdit() ) {
@@ -1750,7 +1776,7 @@ class Parser
                        # strip out HTML
                        $canonized_headline = preg_replace( "/<.*?" . ">/","",$canonized_headline );
                        $tocline = trim( $canonized_headline );
-                       $canonized_headline = preg_replace("/[ \\?&\\/<>\\(\\)\\[\\]=,+']+/", '_', html_entity_decode( $tocline));
+                       $canonized_headline = preg_replace("/[ \\?&\\/<>\\(\\)\\[\\]=,+']+/", '_', urlencode( do_html_entity_decode( $tocline, ENT_COMPAT, $wgInputEncoding ) ) );
                        $refer[$headlineCount] = $canonized_headline;
 
                        # count how many in assoc. array so we can track dupes in anchors