diff --git a/brokenfile.php b/brokenfile.php new file mode 100644 index 0000000000000..3153ade18cf2e --- /dev/null +++ b/brokenfile.php @@ -0,0 +1,31 @@ +. + +/** + * This is an empty file which is used in order to prevent + * error logs in the serverlog. + * + * Sometimes developer forgets to postprocess files when saving + * submitted form data or forget to replace the file placeholders + * with the current area information. + * + * @package core + * @subpackage file + * @copyright 2011 Petr Skoda (http://skodak.org) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +@header('HTTP/1.0 404 not found'); diff --git a/lib/filelib.php b/lib/filelib.php index 05bc0577ef357..adaaedc225bae 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -321,7 +321,7 @@ function file_get_unused_draft_itemid() { * @return string if $text was passed in, the rewritten $text is returned. Otherwise NULL. */ function file_prepare_draft_area(&$draftitemid, $contextid, $component, $filearea, $itemid, array $options=null, $text=null) { - global $CFG, $USER; + global $CFG, $USER, $CFG; $options = (array)$options; if (!isset($options['subdirs'])) { @@ -351,6 +351,12 @@ function file_prepare_draft_area(&$draftitemid, $contextid, $component, $fileare $fs->create_file_from_storedfile($file_record, $file); } } + if (!is_null($text)) { + // at this point there should not be any draftfile links yet, + // because this is a new text from database that should still contain the @@pluginfile@@ links + // this happens when developers forget to post process the text + $text = str_replace("\"$CFG->httpswwwroot/draftfile.php", "\"$CFG->httpswwwroot/brokenfile.php#", $text); + } } else { // nothing to do } diff --git a/lib/weblib.php b/lib/weblib.php index 2537afc7d5f50..7d2ddc328f86d 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -1106,6 +1106,13 @@ function format_text($text, $format = FORMAT_MOODLE, $options = NULL, $courseid_ $text = $filtermanager->filter_text($text, $context, array('originalformat' => $format)); break; } + if ($options['filter']) { + // at this point there should not be any draftfile links any more, + // this happens when developers forget to post process the text. + // The only potential problem is that somebody might try to format + // the text before storing into database which would be itself big bug. + $text = str_replace("\"$CFG->httpswwwroot/draftfile.php", "\"$CFG->httpswwwroot/brokenfile.php#", $text); + } // Warn people that we have removed this old mechanism, just in case they // were stupid enough to rely on it.