diff --git a/filter/algebra/algebradebug.php b/filter/algebra/algebradebug.php index 24eb0310821..52cf0680eb2 100644 --- a/filter/algebra/algebradebug.php +++ b/filter/algebra/algebradebug.php @@ -12,20 +12,21 @@ require_once($CFG->libdir.'/filelib.php'); require_once($CFG->dirroot.'/filter/tex/lib.php'); + $action = optional_param('action', '', PARAM_ALPHANUM); + $algebra = optional_param('algebra', '', PARAM_RAW); + require_login(); require_capability('moodle/site:config', context_system::instance()); + if ($action || $algebra) { + require_sesskey(); + } - $query = urldecode($_SERVER['QUERY_STRING']); - - if ($query) { - $output = $query; - $splitpos = strpos($query,'&')-8; - $algebra = substr($query,8,$splitpos); + if ($algebra && $action) { $md5 = md5($algebra); - if (strpos($query,'ShowDB') || strpos($query,'DeleteDB')) { + if ($action == 'ShowDB' || $action == 'DeleteDB') { $texcache = $DB->get_record("cache_filters", array("filter"=>"algebra", "md5key"=>$md5)); } - if (strpos($query,'ShowDB')) { + if ($action == 'ShowDB') { if ($texcache) { $output = "DB cache_filters entry for $algebra\n"; $output .= "id = $texcache->id\n"; @@ -38,7 +39,7 @@ $output = "DB cache_filters entry for $algebra not found\n"; } } - if (strpos($query,'DeleteDB')) { + if ($action == 'DeleteDB') { if ($texcache) { $output = "Deleting DB cache_filters entry for $algebra\n"; $result = $DB->delete_records("cache_filters", array("id"=>$texcache->id)); @@ -52,17 +53,17 @@ $output = "Could not delete DB cache_filters entry for $algebra\nbecause it could not be found.\n"; } } - if (strpos($query,'TeXStage1')) { + if ($action == 'TeXStage1') { $output = algebra2tex($algebra); } - if (strpos($query,'TeXStage2')) { + if ($action == 'TexStage2') { $output = algebra2tex($algebra); $output = refineTeX($output); } - if (strpos($query,'ShowImage')||strpos($query,'SlashArguments')) { + if ($action == 'ShowImage'|| $action == 'SlashArguments') { $output = algebra2tex($algebra); $output = refineTeX($output); - if (strpos($query,'ShowImage')) { + if ($action == 'ShowImage') { tex2image($output, $md5); } else { slasharguments($output, $md5); @@ -283,19 +284,20 @@ function slasharguments($texexp, $md5) { value="sin(z)/(x^2+y^2)" />