MDL-18552 different TeX trouble fix; backported from HEAD

This commit is contained in:
skodak
2009-03-31 12:23:46 +00:00
parent 321f304e32
commit b3b7f01ea7
12 changed files with 66 additions and 28 deletions
+3
View File
@@ -16,6 +16,8 @@
}
}
require_once($CFG->dirroot.'/filter/tex/lib.php');
$CFG->texfilterdir = "filter/tex";
$CFG->algebrafilterdir = "filter/algebra";
$CFG->algebraimagedir = "filter/algebra";
@@ -233,6 +235,7 @@ function tex2image($texexp, $md5, $return=false) {
}
$commandpath = "";
$cmd = "";
$texexp = tex_sanitize_formula($texexp);
$texexp = escapeshellarg($texexp);
switch (PHP_OS) {
case "Linux":
+2
View File
@@ -17,6 +17,7 @@
}
require_once($CFG->libdir.'/filelib.php');
require_once($CFG->dirroot.'/filter/tex/lib.php');
$CFG->texfilterdir = 'filter/tex';
$CFG->algebrafilterdir = 'filter/algebra';
@@ -51,6 +52,7 @@
$texexp = str_replace('>','>',$texexp);
$texexp = preg_replace('!\r\n?!',' ',$texexp);
$texexp = '\Large ' . $texexp;
$texexp = tex_sanitize_formula($texexp);
$texexp = escapeshellarg($texexp);
if ((PHP_OS == "WINNT") || (PHP_OS == "WIN32") || (PHP_OS == "Windows")) {
-23
View File
@@ -117,16 +117,6 @@ function tex_filter ($courseid, $text) {
//if (isadmin()) { error_reporting (E_ALL); }; //for debugging
// TeX blacklist. MDL-18552
$tex_blacklist = array(
'include','def','command','loop','repeat','open','toks','output',
'input','catcode','name','^^',
'\every','\errhelp','\errorstopmode','\scrollmode','\nonstopmode',
'\batchmode','\read','\write','csname','\newhelp','\uppercase',
'\lowercase','\relax','\aftergroup',
'\afterassignment','\expandafter','\noexpand','\special'
);
// <tex> TeX expression </tex>
// or $$ TeX expression $$
// or \[ TeX expression \] // original tag of MathType and TeXaide (dlnsk)
@@ -147,19 +137,6 @@ function tex_filter ($courseid, $text) {
$align = "text-top";
$texexp = preg_replace('/^align=top /','',$texexp);
}
/// Check $texexp against blacklist (whitelisting could be more complete but also harder to maintain). MDL-18552
$invalidcommands = array();
foreach($tex_blacklist as $command) {
if (stristr($texexp, $command)) { /// Found invalid command. Annotate.
$invalidcommands[] = $command;
}
}
if (!empty($invalidcommands)) { /// Invalid commands found. Output error and continue with next TeX element
$invalidstr = get_string('invalidtexcommand', 'error', implode(', ', $invalidcommands));
$text = str_replace( $matches[0][$i], $invalidstr, $text);
continue;
}
/// Everything is ok, let's process the expression
$md5 = md5($texexp);
if (! $texcache = get_record("cache_filters","filter","tex", "md5key", $md5)) {
$texcache->filter = 'tex';
+4 -2
View File
@@ -44,9 +44,11 @@
* @return string the latex document
*/
function construct_latex_document( $formula, $fontsize=12 ) {
// $fontsize don't affects to formula's size. $density can change size
global $CFG;
$formula = tex_sanitize_formula($formula);
// $fontsize don't affects to formula's size. $density can change size
$doc = "\\documentclass[{$fontsize}pt]{article}\n";
$doc .= $CFG->filter_tex_latexpreamble;
$doc .= "\\pagestyle{empty}\n";
+37
View File
@@ -0,0 +1,37 @@
<?php //$Id$
function tex_sanitize_formula($texexp) {
/// Check $texexp against blacklist (whitelisting could be more complete but also harder to maintain)
$tex_blacklist = array(
'include','def','command','loop','repeat','open','toks','output',
'input','catcode','name','^^',
'\every','\errhelp','\errorstopmode','\scrollmode','\nonstopmode',
'\batchmode','\read','\write','csname','\newhelp','\uppercase',
'\lowercase','\relax','\aftergroup',
'\afterassignment','\expandafter','\noexpand','\special'
);
return str_ireplace($tex_blacklist, 'forbiddenkeyword', $texexp);
}
/**
* Purge all caches when settings changed.
*/
function filter_tex_updatedcallback($name) {
global $CFG;
if (file_exists("$CFG->dataroot/filter/tex")) {
remove_dir("$CFG->dataroot/filter/tex");
}
if (file_exists("$CFG->dataroot/filter/algebra")) {
remove_dir("$CFG->dataroot/filter/algebra");
}
if (file_exists("$CFG->dataroot/temp/latex")) {
remove_dir("$CFG->dataroot/temp/latex");
}
delete_records('cache_filters', 'filter', 'tex');
delete_records('cache_filters', 'filter', 'algebra');
}
?>
+2
View File
@@ -17,6 +17,7 @@
}
require_once($CFG->libdir.'/filelib.php');
require_once($CFG->dirroot.'/filter/tex/lib.php');
require_once('defaultsettings.php' );
require_once('latex.php');
@@ -65,6 +66,7 @@
$texexp = str_replace('&gt;','>',$texexp);
$texexp = preg_replace('!\r\n?!',' ',$texexp);
$texexp = '\Large ' . $texexp;
$texexp = tex_sanitize_formula($texexp);
$texexp = escapeshellarg($texexp);
if ((PHP_OS == "WINNT") || (PHP_OS == "WIN32") || (PHP_OS == "Windows")) {
+3
View File
@@ -14,6 +14,8 @@
}
}
require_once($CFG->dirroot.'/filter/tex/lib.php');
$CFG->texfilterdir = "filter/tex";
$CFG->teximagedir = "filter/tex";
@@ -114,6 +116,7 @@
}
$commandpath = "";
$cmd = "";
$texexp = tex_sanitize_formula($texexp);
$texexp = escapeshellarg($texexp);
switch (PHP_OS) {
case "Linux":
+2
View File
@@ -6,6 +6,7 @@
$nomoodlecookie = true; // Because it interferes with caching
require_once("../../config.php");
require_once($CFG->dirroot.'/filter/tex/lib.php');
if (empty($CFG->textfilters)) {
error ('Filter not enabled!');
@@ -32,6 +33,7 @@
make_upload_directory($CFG->teximagedir);
}
$pathname = "$CFG->dataroot/$CFG->teximagedir/$image";
$texexp = tex_sanitize_formula($texexp);
$texexp = escapeshellarg($texexp);
switch (PHP_OS) {
-1
View File
@@ -33,7 +33,6 @@ $string['invalidcourse'] = 'Invalid course';
$string['invalidfieldname'] = '\"$a\" is not a valid field name';
$string['invalidfiletype'] = '\"$a\" is not a valid file type';
$string['invalidmd5'] = 'Invalid md5';
$string['invalidtexcommand'] = 'Forbidden TeX command ($a)';
$string['invalidxmlfile'] = '\"$a\" is not a valid XML file';
$string['missingfield'] = 'Field \"$a\" is missing';
$string['missingrequiredfield'] = 'Some required field is missing';
+6
View File
@@ -2003,6 +2003,12 @@ function main_upgrade($oldversion=0) {
notify('...update complete. Remember to update your language packs to get the most recent country names definitions and codes. This is especially important for sites with users from Congo (now CD), Timor (now TL), Kosovo (now RS), Wales (now GB), Serbia (RS) and Montenegro (ME). Users based in Montenegro (ME) will need to manually update their profile.', 'notifysuccess');
$db->debug = true;
}
if ($result && $oldversion < 2006050591) {
require_once("$CFG->dirroot/filter/tex/lib.php");
filter_tex_updatedcallback(null);
}
return $result;
}
+6 -1
View File
@@ -1621,7 +1621,12 @@ function main_upgrade($oldversion=0) {
notify('...update complete. Remember to update your language packs to get the most recent country names definitions and codes. This is especially important for sites with users from Congo (now CD), Timor (now TL), Kosovo (now RS), Wales (now GB), Serbia (RS) and Montenegro (ME). Users based in Montenegro (ME) will need to manually update their profile.', 'notifysuccess');
$db->debug = true;
}
if ($result && $oldversion < 2006050591) {
require_once("$CFG->dirroot/filter/tex/lib.php");
filter_tex_updatedcallback(null);
}
return $result;
}
+1 -1
View File
@@ -6,7 +6,7 @@
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)
$version = 2006050590; // YYYYMMDD = date of the 1.6 branch (don't change)
$version = 2006050591; // YYYYMMDD = date of the 1.6 branch (don't change)
// X = release number 1.6.[0,1,2,3...]
// Y = micro-increments between releases