Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-26069 detect missing file postprocessing

  • Loading branch information...
commit 893fe4b6b26f69191b12def20f54a0df10882890 1 parent 8cdc85a
@skodak skodak authored
Showing with 45 additions and 1 deletion.
  1. +31 −0 brokenfile.php
  2. +7 −1 lib/filelib.php
  3. +7 −0 lib/weblib.php
View
31 brokenfile.php
@@ -0,0 +1,31 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * 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');
View
8 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
}
View
7 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.
Please sign in to comment.
Something went wrong with that request. Please try again.