Skip to content

Commit

Permalink
MDL-26069 detect missing file postprocessing
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Jan 29, 2011
1 parent 8cdc85a commit 893fe4b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
31 changes: 31 additions & 0 deletions brokenfile.php
Original file line number Diff line number Diff line change
@@ -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');
8 changes: 7 additions & 1 deletion lib/filelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 7 additions & 0 deletions lib/weblib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 893fe4b

Please sign in to comment.