global $IP;
include( "./LocalSettings.php" );
include( "$IP/Setup.php" );
header( "Content-type: text/xml; charset={$wgInputEncoding}" );
print "<";
print "?xml version=\"1.0\" encoding=\"utf-8\"?";
print ">";
?>
texvc
print "
function xlinkToMathImage ( $tex, $outputhash )
{
global $wgMathPath;
return "";
}
function texvc_cgi_renderMath( $tex )
{
global $wgMathDirectory, $wgTmpDirectory, $wgInputEncoding;
$mf = wfMsg( "math_failure" );
$munk = wfMsg( "math_unknown_error" );
$image = "";
$outhtml = "";
$outtex = "";
$fname = "texvc_cgi_renderMath";
$md5 = md5($tex);
$md5_sql = mysql_escape_string(pack("H32", $md5));
$sql = "SELECT math_outputhash,math_html_conservativeness,math_html,math_mathml 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 "".$mf." (".$munk."): ".wfEscapeHTML($tex)."
";
$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 "".$mf." (".$errmsg.substr($contents, 1)."): ".wfEscapeHTML($tex)."
";
}
$outmd5 = substr ($contents, 1, 32);
if (!preg_match("/^[a-f0-9]{32}$/", $outmd5))
return "".$mf." (".$munk."): ".wfEscapeHTML($tex)."
";
$outmd5_sql = mysql_escape_string(pack("H32", $outmd5));
$sql = "INSERT INTO math VALUES ('".$md5_sql."', '".$outmd5_sql."', ".$conservativeness.", ".$sql_html.", ".$sql_mathml.")";
$res = wfQuery( $sql, $fname );
// we don't really care if it fails
} else {
$rpage = wfFetchObject ( $res );
$outmd5 = unpack ("H32md5", $rpage->math_outputhash);
$outmd5 = $outmd5 ['md5'];
$outhtml = $rpage->math_html;
$conservativeness = $rpage->math_html_conservativeness;
$mathml = $rpage->math_mathml;
}
if ($mathml == '')
$mathml = "Failed to generate MathML
";
else
$mathml = "MathML
";
$image = "Image
" . xlinkToMathImage ( $tex, $outmd5 );
$cmd = "./math/texvc_tex ".escapeshellarg($tex)." ".escapeshellarg($wgInputEncoding);
$outtex = `$cmd`;
if ( $outhtml == '' )
$outhtml = "Failed to generate HTML
";
else
if ( $conservativeness == 2)
$outhtml = "HTML (conservative)
" . $outhtml;
else if ( $conservativeness == 1)
$outhtml = "HTML (moderate)
" . $outhtml;
else
$outhtml = "HTML (liberal)
" . $outhtml;
if ( $outtex == '' )
$outtex = "Failed to generate TeX
";
else
$outtex = "TeX
" . wfEscapeHTML($outtex);
return $outtex . $outhtml . $mathml . $image;
}
global $math;
if ($math != '')
print texvc_cgi_renderMath($math);
?>