Trying to cut these monster files to manageable size... moving math support functions...
authorBrion Vibber <brion@users.mediawiki.org>
Sat, 30 Aug 2003 10:04:59 +0000 (10:04 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sat, 30 Aug 2003 10:04:59 +0000 (10:04 +0000)
includes/Math.php [new file with mode: 0644]
includes/OutputPage.php

diff --git a/includes/Math.php b/includes/Math.php
new file mode 100644 (file)
index 0000000..60fe6a8
--- /dev/null
@@ -0,0 +1,116 @@
+<?
+
+function linkToMathImage ( $tex, $outputhash )
+{
+    global $wgMathPath;
+    return "<img src=\"".$wgMathPath."/".$outputhash.".png\" alt=\"".wfEscapeHTML($tex)."\">";
+}
+
+function renderMath( $tex )
+{
+    global $wgUser, $wgMathDirectory, $wgTmpDirectory, $wgInputEncoding;
+    $mf   = wfMsg( "math_failure" );
+    $munk = wfMsg( "math_unknown_error" );
+
+    $fname = "renderMath";
+
+    $math = $wgUser->getOption("math");
+    if ($math == 3)
+       return ('$ '.wfEscapeHTML($tex).' $');
+
+    $md5 = md5($tex);
+    $md5_sql = mysql_escape_string(pack("H32", $md5));
+    if ($math == 0)
+       $sql = "SELECT math_outputhash FROM math WHERE math_inputhash = '".$md5_sql."'";
+    else
+       $sql = "SELECT math_outputhash,math_html_conservativeness,math_html FROM math WHERE math_inputhash = '".$md5_sql."'";
+
+    $res = wfQuery( $sql, $fname );
+    if ( wfNumRows( $res ) == 0 )
+    {
+       $cmd = "./math/texvc ".escapeshellarg($wgTmpDirectory)." ".
+                     escapeshellarg($wgMathDirectory)." ".escapeshellarg($tex)." ".escapeshellarg($wgInputEncoding);
+       $contents = `$cmd`;
+
+       if (strlen($contents) == 0)
+           return "<b>".$mf." (".$munk."): ".wfEscapeHTML($tex)."</b>";
+       $retval = substr ($contents, 0, 1);
+       if (($retval == "C") || ($retval == "M") || ($retval == "L")) {
+           if ($retval == "C")
+               $conservativeness = 2;
+           else if ($retval == "M")
+               $conservativeness = 1;
+           else
+               $conservativeness = 0;
+           $outdata = substr ($contents, 33);
+
+           $i = strpos($outdata, "\000");
+
+           $outhtml = substr($outdata, 0, $i);
+           $mathml = substr($outdata, $i+1);
+
+           $sql_html = "'".mysql_escape_string($outhtml)."'";
+           $sql_mathml = "'".mysql_escape_string($mathml)."'";
+       } else if (($retval == "c") || ($retval == "m") || ($retval == "l"))  {
+           $outhtml = substr ($contents, 33);
+           if ($retval == "c")
+               $conservativeness = 2;
+           else if ($retval == "m")
+               $conservativeness = 1;
+           else
+               $conservativeness = 0;
+           $sql_html = "'".mysql_escape_string($outhtml)."'";
+           $mathml = '';
+           $sql_mathml = 'NULL';
+       } else if ($retval == "X") {
+           $outhtml = '';
+           $mathml = substr ($contents, 33);
+           $sql_html = 'NULL';
+           $sql_mathml = "'".mysql_escape_string($mathml)."'";
+           $conservativeness = 0;
+       } else if ($retval == "+") {
+           $outhtml = '';
+           $mathml = '';
+           $sql_html = 'NULL';
+           $sql_mathml = 'NULL';
+           $conservativeness = 0;
+       } else {
+           if ($retval == "E")
+               $errmsg = wfMsg( "math_lexing_error" );
+           else if ($retval == "S")
+               $errmsg = wfMsg( "math_syntax_error" );
+           else if ($retval == "F")
+               $errmsg = wfMsg( "math_unknown_function" );
+           else
+               $errmsg = $munk;
+           return "<h3>".$mf." (".$errmsg.substr($contents, 1)."): ".wfEscapeHTML($tex)."</h3>";
+       }
+
+       $outmd5 = substr ($contents, 1, 32);
+       if (!preg_match("/^[a-f0-9]{32}$/", $outmd5))
+           return "<b>".$mf." (".$munk."): ".wfEscapeHTML($tex)."</b>";
+
+       $outmd5_sql = mysql_escape_string(pack("H32", $outmd5));
+
+       $sql = "REPLACE INTO math VALUES ('".$md5_sql."', '".$outmd5_sql."', ".$conservativeness.", ".$sql_html.", ".$sql_mathml.")";
+       
+       $res = wfQuery( $sql, $fname );
+       # we don't really care if it fails
+
+       if (($math == 0) || ($rpage->math_html == '') || (($math == 1) && ($conservativeness != 2)) || (($math == 4) && ($conservativeness == 0)))
+           return linkToMathImage($tex, $outmd5);
+       else
+           return $outhtml;
+    } else {
+       $rpage = wfFetchObject ( $res );
+       $outputhash = unpack( "H32md5", $rpage->math_outputhash . "                " );
+       $outputhash = $outputhash ['md5'];
+       
+       if (($math == 0) || ($rpage->math_html == '') || (($math == 1) && ($rpage->math_html_conservativeness != 2)) || (($math == 4) && ($rpage->math_html_conservativeness == 0)))
+           return linkToMathImage ( $tex, $outputhash );
+       else
+           return $rpage->math_html;
+    }
+}
+
+?>
index 80bb8a0..0cec21b 100644 (file)
@@ -1,118 +1,7 @@
 <?
 # See design.doc
 
-function linkToMathImage ( $tex, $outputhash )
-{
-    global $wgMathPath;
-    return "<img src=\"".$wgMathPath."/".$outputhash.".png\" alt=\"".wfEscapeHTML($tex)."\">";
-}
-
-function renderMath( $tex )
-{
-    global $wgUser, $wgMathDirectory, $wgTmpDirectory, $wgInputEncoding;
-    $mf   = wfMsg( "math_failure" );
-    $munk = wfMsg( "math_unknown_error" );
-
-    $fname = "renderMath";
-
-    $math = $wgUser->getOption("math");
-    if ($math == 3)
-       return ('$ '.wfEscapeHTML($tex).' $');
-
-    $md5 = md5($tex);
-    $md5_sql = mysql_escape_string(pack("H32", $md5));
-    if ($math == 0)
-       $sql = "SELECT math_outputhash FROM math WHERE math_inputhash = '".$md5_sql."'";
-    else
-       $sql = "SELECT math_outputhash,math_html_conservativeness,math_html FROM math WHERE math_inputhash = '".$md5_sql."'";
-
-    $res = wfQuery( $sql, $fname );
-    if ( wfNumRows( $res ) == 0 )
-    {
-       $cmd = "./math/texvc ".escapeshellarg($wgTmpDirectory)." ".
-                     escapeshellarg($wgMathDirectory)." ".escapeshellarg($tex)." ".escapeshellarg($wgInputEncoding);
-       $contents = `$cmd`;
-
-       if (strlen($contents) == 0)
-           return "<b>".$mf." (".$munk."): ".wfEscapeHTML($tex)."</b>";
-       $retval = substr ($contents, 0, 1);
-       if (($retval == "C") || ($retval == "M") || ($retval == "L")) {
-           if ($retval == "C")
-               $conservativeness = 2;
-           else if ($retval == "M")
-               $conservativeness = 1;
-           else
-               $conservativeness = 0;
-           $outdata = substr ($contents, 33);
-
-           $i = strpos($outdata, "\000");
-
-           $outhtml = substr($outdata, 0, $i);
-           $mathml = substr($outdata, $i+1);
-
-           $sql_html = "'".mysql_escape_string($outhtml)."'";
-           $sql_mathml = "'".mysql_escape_string($mathml)."'";
-       } else if (($retval == "c") || ($retval == "m") || ($retval == "l"))  {
-           $outhtml = substr ($contents, 33);
-           if ($retval == "c")
-               $conservativeness = 2;
-           else if ($retval == "m")
-               $conservativeness = 1;
-           else
-               $conservativeness = 0;
-           $sql_html = "'".mysql_escape_string($outhtml)."'";
-           $mathml = '';
-           $sql_mathml = 'NULL';
-       } else if ($retval == "X") {
-           $outhtml = '';
-           $mathml = substr ($contents, 33);
-           $sql_html = 'NULL';
-           $sql_mathml = "'".mysql_escape_string($mathml)."'";
-           $conservativeness = 0;
-       } else if ($retval == "+") {
-           $outhtml = '';
-           $mathml = '';
-           $sql_html = 'NULL';
-           $sql_mathml = 'NULL';
-           $conservativeness = 0;
-       } else {
-           if ($retval == "E")
-               $errmsg = wfMsg( "math_lexing_error" );
-           else if ($retval == "S")
-               $errmsg = wfMsg( "math_syntax_error" );
-           else if ($retval == "F")
-               $errmsg = wfMsg( "math_unknown_function" );
-           else
-               $errmsg = $munk;
-           return "<h3>".$mf." (".$errmsg.substr($contents, 1)."): ".wfEscapeHTML($tex)."</h3>";
-       }
-
-       $outmd5 = substr ($contents, 1, 32);
-       if (!preg_match("/^[a-f0-9]{32}$/", $outmd5))
-           return "<b>".$mf." (".$munk."): ".wfEscapeHTML($tex)."</b>";
-
-       $outmd5_sql = mysql_escape_string(pack("H32", $outmd5));
-
-       $sql = "REPLACE INTO math VALUES ('".$md5_sql."', '".$outmd5_sql."', ".$conservativeness.", ".$sql_html.", ".$sql_mathml.")";
-       
-       $res = wfQuery( $sql, $fname );
-       # we don't really care if it fails
-
-       if (($math == 0) || ($rpage->math_html == '') || (($math == 1) && ($conservativeness != 2)) || (($math == 4) && ($conservativeness == 0)))
-           return linkToMathImage($tex, $outmd5);
-       else
-           return $outhtml;
-    } else {
-       $rpage = wfFetchObject ( $res );
-       $outputhash = unpack( "H32md5", $rpage->math_outputhash . "                " );
-       $outputhash = $outputhash ['md5'];
-       
-       if (($math == 0) || ($rpage->math_html == '') || (($math == 1) && ($rpage->math_html_conservativeness != 2)) || (($math == 4) && ($rpage->math_html_conservativeness == 0)))
-           return linkToMathImage ( $tex, $outputhash );
-       else
-           return $rpage->math_html;
-    }
-}
+if($wgUseTeX) include_once( "Math.php" );
 
 class OutputPage {
        var $mHeaders, $mCookies, $mMetatags, $mKeywords;
@@ -942,8 +831,8 @@ return $r ;
                $e2 = "/^([{$tc}]+)]](.*)\$/sD";
                wfProfileOut();
 
-               wfProfileIn( "$fname-loop" );
                foreach ( $a as $line ) {
+                       wfProfileIn( "$fname-loop" );
                        if ( preg_match( $e1, $line, $m ) ) { # page with alternate text
                                
                                $text = $m[2];
@@ -957,6 +846,7 @@ return $r ;
                        
                        else { # Invalid form; output directly
                                $s .= "[[" . $line ;
+                               wfProfileOut();
                                continue;
                        }
                        if(substr($m[1],0,1)=="/") { # subpage
@@ -1023,9 +913,9 @@ return $r ;
                                if ( "" == $text ) { $text = $link; }
                                $s .= $sk->makeLink( $link, $text, "", $trail );
                        }
+                       wfProfileOut();
                }
                wfProfileOut();
-               wfProfileOut();
                return $s;
        }