define('AJAX_SCRIPT', true);
- require_once(dirname(__FILE__) . '/../../../config.php');
+ require_once(__DIR__ . '/../../../config.php');
require_once($CFG->libdir . '/filestorage/file_storage.php');
-$contextid = required_param('contextid', PARAM_INT);
-$elementid = required_param('elementid', PARAM_ALPHANUMEXT);
-$pagehash = required_param('pagehash', PARAM_ALPHANUMEXT);
-$pageinstance = required_param('pageinstance', PARAM_ALPHANUMEXT);
+// Clean up actions.
+$actions = array_map(function($actionparams) {
+ $action = isset($actionparams['action']) ? $actionparams['action'] : null;
+ $params = [];
+ $keys = [
+ 'action' => PARAM_ALPHA,
+ 'contextid' => PARAM_INT,
+ 'elementid' => PARAM_ALPHANUMEXT,
+ 'pagehash' => PARAM_ALPHANUMEXT,
+ 'pageinstance' => PARAM_ALPHANUMEXT
+ ];
+
+ if ($action == 'save') {
+ $keys['drafttext'] = PARAM_RAW;
+ } else if ($action == 'resume') {
+ $keys['draftid'] = PARAM_INT;
+ }
+
+ foreach ($keys as $key => $type) {
+ // Replicate required_param().
+ if (!isset($actionparams[$key])) {
+ print_error('missingparam', '', '', $key);
+ }
+ $params[$key] = clean_param($actionparams[$key], $type);
+ }
+
+ return $params;
+}, isset($_REQUEST['actions']) ? $_REQUEST['actions'] : []);
+
$now = time();
// This is the oldest time any autosave text will be recovered from.
// This is so that there is a good chance the draft files will still exist (there are many variables so