allow other content-types
[lhc/web/wiklou.git] / includes / Math.php
index f22226c..3506394 100644 (file)
@@ -1,12 +1,18 @@
 <?php
-#
-# Takes LaTeX fragments, sends them to a helper program (texvc) for rendering
-# to rasterized PNG and HTML and MathML approximations. An appropriate
-# rendering form is picked and returned.
-#
-# by Tomasz Wegrzanowski, with additions by Brion Vibber (2003, 2004)
-#
+/**
+ * Contain everything related to <math> </math> parsing
+ * @package MediaWiki
+ */
 
+/**
+ * Takes LaTeX fragments, sends them to a helper program (texvc) for rendering
+ * to rasterized PNG and HTML and MathML approximations. An appropriate
+ * rendering form is picked and returned.
+ * 
+ * by Tomasz Wegrzanowski, with additions by Brion Vibber (2003, 2004)
+ *
+ * @package MediaWiki
+ */
 class MathRenderer {
        var $mode = MW_MATH_MODERN;
        var $tex = '';
@@ -27,6 +33,7 @@ class MathRenderer {
        function render() {
                global $wgMathDirectory, $wgTmpDirectory, $wgInputEncoding;
                global $wgTexvc;
+               $fname = 'MathRenderer::render';
        
                if( $this->mode == MW_MATH_SOURCE ) {
                        # No need to render or parse anything more!
@@ -89,11 +96,11 @@ class MathRenderer {
                                        $this->conservativeness = 0;
                                $this->mathml = NULL;
                        } else if ($retval == 'X') {
-                               $outhtml = NULL;
+                               $this->html = NULL;
                                $this->mathml = substr ($contents, 33);
                                $this->conservativeness = 0;
                        } else if ($retval == '+') {
-                               $this->outhtml = NULL;
+                               $this->html = NULL;
                                $this->mathml = NULL;
                                $this->conservativeness = 0;
                        } else {
@@ -116,20 +123,22 @@ class MathRenderer {
                        }
                        
                        # Now save it back to the DB:
-                       $outmd5_sql = pack('H32', $this->hash);
-               
-                       $md5_sql = pack('H32', $this->md5); # Binary packed, not hex
+                       if ( !wfReadOnly() ) {
+                               $outmd5_sql = pack('H32', $this->hash);
                        
-                       $dbw =& wfGetDB( DB_MASTER );
-                       $dbw->replace( 'math', array( 'math_inputhash' ),
-                         array( 
-                               'math_inputhash' => $md5_sql, 
-                               'math_outputhash' => $outmd5_sql,
-                               'math_html_conservativeness' => $this->conservativeness,
-                               'math_html' => $outhtml,
-                               'math_mathml' => $mathml,
-                         ), $fname, array( 'IGNORE' ) 
-                       );
+                               $md5_sql = pack('H32', $this->md5); # Binary packed, not hex
+                               
+                               $dbw =& wfGetDB( DB_MASTER );
+                               $dbw->replace( 'math', array( 'math_inputhash' ),
+                                 array( 
+                                       'math_inputhash' => $md5_sql, 
+                                       'math_outputhash' => $outmd5_sql,
+                                       'math_html_conservativeness' => $this->conservativeness,
+                                       'math_html' => $this->html,
+                                       'math_mathml' => $this->mathml,
+                                 ), $fname, array( 'IGNORE' ) 
+                               );
+                       }
                        
                }
                
@@ -150,7 +159,7 @@ class MathRenderer {
 
                $this->md5 = md5( $this->tex );
                $dbr =& wfGetDB( DB_SLAVE );
-               $rpage = $dbr->getArray( 'math', 
+               $rpage = $dbr->selectRow( 'math', 
                        array( 'math_outputhash','math_html_conservativeness','math_html','math_mathml' ),
                        array( 'math_inputhash' => pack("H32", $this->md5)), # Binary packed, not hex
                        $fname
@@ -174,7 +183,9 @@ class MathRenderer {
                return false;
        }
 
-       # Select among PNG, HTML, or MathML output depending on 
+       /**
+        * Select among PNG, HTML, or MathML output depending on
+        */
        function _doRender() {
                if( $this->mode == MW_MATH_MATHML && $this->mathml != '' ) {
                        return "<math xmlns='http://www.w3.org/1998/Math/MathML'>{$this->mathml}</math>";