Revert " MDL-45044 filter_tex: properly escape excutable pathnames for Windows"

This reverts commit 07a50c2f29.
This commit is contained in:
Eloy Lafuente (stronk7) 2014-06-26 10:03:25 +02:00
parent 9d5a2e6f1c
commit 65684fa600
4 changed files with 22 additions and 45 deletions

View file

@ -108,16 +108,14 @@
fclose( $fh );
// run latex on document
$pathlatex = escapeshellarg(trim($CFG->filter_tex_pathlatex, " '\""));
$command = "{$pathlatex} --interaction=nonstopmode --halt-on-error $tex";
$command = "{$CFG->filter_tex_pathlatex} --interaction=nonstopmode --halt-on-error $tex";
chdir( $this->temp_dir );
if ($this->execute($command, $log)) { // It allways False on Windows
// return false;
}
// run dvips (.dvi to .ps)
$pathdvips = escapeshellarg(trim($CFG->filter_tex_pathdvips, " '\""));
$command = "{$pathdvips} -E $dvi -o $ps";
$command = "{$CFG->filter_tex_pathdvips} -E $dvi -o $ps";
if ($this->execute($command, $log )) {
return false;
}
@ -128,8 +126,7 @@
} else {
$bg_opt = "";
}
$pathconvert = escapeshellarg(trim($CFG->filter_tex_pathconvert, " '\""));
$command = "{$pathconvert} -density $density -trim $bg_opt $ps $img";
$command = "{$CFG->filter_tex_pathconvert} -density $density -trim $bg_opt $ps $img";
if ($this->execute($command, $log )) {
return false;
}

View file

@ -116,13 +116,9 @@ function filter_tex_updatedcallback($name) {
return;
}
$pathlatex = trim($CFG->filter_tex_pathlatex, " '\"");
$pathdvips = trim($CFG->filter_tex_pathdvips, " '\"");
$pathconvert = trim($CFG->filter_tex_pathconvert, " '\"");
if (!(is_file($pathlatex) && is_executable($pathlatex) &&
is_file($pathdvips) && is_executable($pathdvips) &&
is_file($pathconvert) && is_executable($pathconvert))) {
if (!(is_file($CFG->filter_tex_pathlatex) && is_executable($CFG->filter_tex_pathlatex) &&
is_file($CFG->filter_tex_pathdvips) && is_executable($CFG->filter_tex_pathdvips) &&
is_file($CFG->filter_tex_pathconvert) && is_executable($CFG->filter_tex_pathconvert))) {
// LaTeX, dvips or convert are not available, and mimetex can only produce GIFs so...
set_config('filter_tex_convertformat', 'gif');
}

View file

@ -50,9 +50,9 @@ if ($ADMIN->fulltree) {
} else if (PHP_OS=='WINNT' or PHP_OS=='WIN32' or PHP_OS=='Windows') {
// note: you need Ghostscript installed (standard), miktex (standard)
// and ImageMagick (install at c:\ImageMagick)
$default_filter_tex_pathlatex = "c:\\texmf\\miktex\\bin\\latex.exe";
$default_filter_tex_pathdvips = "c:\\texmf\\miktex\\bin\\dvips.exe";
$default_filter_tex_pathconvert = "c:\\imagemagick\\convert.exe";
$default_filter_tex_pathlatex = "\"c:\\texmf\\miktex\\bin\\latex.exe\" ";
$default_filter_tex_pathdvips = "\"c:\\texmf\\miktex\\bin\\dvips.exe\" ";
$default_filter_tex_pathconvert = "\"c:\\imagemagick\\convert.exe\" ";
} else {
$default_filter_tex_pathlatex = '';
@ -60,16 +60,6 @@ if ($ADMIN->fulltree) {
$default_filter_tex_pathconvert = '';
}
$pathlatex = $CFG->filter_tex_pathlatex;
$pathdvips = $CFG->filter_tex_pathdvips;
$pathconvert = $CFG->filter_tex_pathconvert;
if (strrpos($pathlatex . $pathdvips . $pathconvert, '"') or
strrpos($pathlatex . $pathdvips . $pathconvert, "'")) {
set_config('filter_tex_pathlatex', trim($pathlatex, " '\""));
set_config('filter_tex_pathdvips', trim($pathdvips, " '\""));
set_config('filter_tex_pathconvert', trim($pathconvert, " '\""));
}
$items[] = new admin_setting_configexecutable('filter_tex_pathlatex', get_string('pathlatex', 'admin'), '', $default_filter_tex_pathlatex);
$items[] = new admin_setting_configexecutable('filter_tex_pathdvips', get_string('pathdvips', 'admin'), '', $default_filter_tex_pathdvips);
$items[] = new admin_setting_configexecutable('filter_tex_pathconvert', get_string('pathconvert', 'admin'), '', $default_filter_tex_pathconvert);
@ -84,4 +74,4 @@ if ($ADMIN->fulltree) {
$item->set_updatedcallback('filter_tex_updatedcallback');
$settings->add($item);
}
}
}

View file

@ -200,33 +200,27 @@
// first check if it is likely to work at all
$output .= "<h3>Checking executables</h3>\n";
$executables_exist = true;
$pathlatex = trim($CFG->filter_tex_pathlatex, " '\"");
if (is_file($pathlatex)) {
$output .= "latex executable ($pathlatex) is readable<br />\n";
if (is_file($CFG->filter_tex_pathlatex)) {
$output .= "latex executable ($CFG->filter_tex_pathlatex) is readable<br />\n";
}
else {
$executables_exist = false;
$output .= "<b>Error:</b> latex executable ($pathlatex) is not readable<br />\n";
$output .= "<b>Error:</b> latex executable ($CFG->filter_tex_pathlatex) is not readable<br />\n";
}
$pathlatex = escapeshellarg($pathlatex);
$pathdvips = trim($CFG->filter_tex_pathdvips, " '\"");
if (is_file($pathdvips)) {
$output .= "dvips executable ($pathdvips) is readable<br />\n";
if (is_file($CFG->filter_tex_pathdvips)) {
$output .= "dvips executable ($CFG->filter_tex_pathdvips) is readable<br />\n";
}
else {
$executables_exist = false;
$output .= "<b>Error:</b> dvips executable ($pathdvips) is not readable<br />\n";
$output .= "<b>Error:</b> dvips executable ($CFG->filter_tex_pathdvips) is not readable<br />\n";
}
$pathdvips = escapeshellarg($pathdvips);
$pathconvert = trim($CFG->filter_tex_pathconvert, " '\"");
if (is_file($pathconvert)) {
$output .= "convert executable ($pathconvert) is readable<br />\n";
if (is_file($CFG->filter_tex_pathconvert)) {
$output .= "convert executable ($CFG->filter_tex_pathconvert) is readable<br />\n";
}
else {
$executables_exist = false;
$output .= "<b>Error:</b> convert executable ($pathconvert) is not readable<br />\n";
$output .= "<b>Error:</b> convert executable ($CFG->filter_tex_pathconvert) is not readable<br />\n";
}
$pathconvert = escapeshellarg($pathconvert);
// knowing that it might work..
$md5 = md5($expression);
@ -250,15 +244,15 @@
chdir($latex->temp_dir);
// step 1: latex command
$cmd = "$pathlatex --interaction=nonstopmode --halt-on-error $tex";
$cmd = "$CFG->filter_tex_pathlatex --interaction=nonstopmode --halt-on-error $tex";
$output .= execute($cmd);
// step 2: dvips command
$cmd = "$pathdvips -E $dvi -o $ps";
$cmd = "$CFG->filter_tex_pathdvips -E $dvi -o $ps";
$output .= execute($cmd);
// step 3: convert command
$cmd = "$pathconvert -density 240 -trim $ps $img ";
$cmd = "$CFG->filter_tex_pathconvert -density 240 -trim $ps $img ";
$output .= execute($cmd);
if (!$graphic) {