MDL-19380 uploadlib cleanup before readding of antivirus integration
authorPetr Skoda <skodak@moodle.org>
Wed, 14 Jul 2010 08:40:48 +0000 (08:40 +0000)
committerPetr Skoda <skodak@moodle.org>
Wed, 14 Jul 2010 08:40:48 +0000 (08:40 +0000)
15 files changed:
admin/handlevirus.php
admin/uploadpicture.php
backup/lib.php
enrol/authorize/uploadcsv.php
group/group_form.php
lib/deprecatedlib.php
lib/form/file.php
lib/formslib.php
lib/moodlelib.php
lib/uploadlib.php
mod/data/preset.php
question/import.php
repository/repository_ajax.php
user/edit_form.php
user/editadvanced_form.php

index 5a131fa..318f9dc 100644 (file)
@@ -6,6 +6,8 @@
  * php -d error_log=/path/to/log thisfile.php will override the default error log for php cli, which is stderr, so if you want this script to just print stuff out, use php thisfile.php instead.
  */
 
+die('TODO: MDL-19380');
+
 $fd = fopen('php://stdin','r');
 if (!$fd) {
     exit();
index e078cd4..172b0a1 100644 (file)
@@ -21,7 +21,6 @@
 ///////////////////////////////////////////////////////////////////////////
 
 require_once('../config.php');
-require_once($CFG->libdir.'/uploadlib.php');
 require_once($CFG->libdir.'/adminlib.php');
 require_once($CFG->libdir.'/gdlib.php');
 require_once('uploadpicture_form.php');
index ab30f7d..ec23bf0 100644 (file)
@@ -9,7 +9,6 @@
     define('RESTORETO_EXISTING_DELETING', 3);
     define('RESTORETO_EXISTING_ADDING',   4);
 
-    require_once($CFG->libdir.'/uploadlib.php');
     require_once($CFG->libdir . '/completionlib.php');
 
     //Sets a name/value pair in config_plugin table
             if (copy($from_file,$to_file)) {
                 chmod($to_file,$CFG->directorypermissions);
                 if (!empty($log_clam)) {
-                    clam_log_upload($to_file,null,true);
+                    //clam_log_upload($to_file,null,true);
                 }
                 return true;
             }
index d61df38..11da31f 100644 (file)
@@ -17,7 +17,6 @@
 
 /// Load libraries
 require_once('../../config.php');
-require_once($CFG->libdir.'/uploadlib.php');
 require_once($CFG->dirroot.'/enrol/authorize/const.php');
 require_once($CFG->dirroot.'/enrol/authorize/localfuncs.php');
 require_once($CFG->libdir.'/eventslib.php');
index 538042b..a030d64 100644 (file)
@@ -82,10 +82,6 @@ class group_form extends moodleform {
         return $errors;
     }
 
-    function get_um() {
-        return $this->_upload_manager;
-    }
-
     function get_editor_options() {
         return $this->_customdata['editoroptions'];
     }
index dba3b0d..dc31ce5 100644 (file)
@@ -87,6 +87,40 @@ function get_file_url($path, $options=null, $type='coursefile') {
     return $ffurl;
 }
 
+/**
+ * If there has been an error uploading a file, print the appropriate error message
+ * Numerical constants used as constant definitions not added until PHP version 4.2.0
+ * @deprecated removed - use new file api
+ */
+function print_file_upload_error($filearray = '', $returnerror = false) {
+    throw new coding_error('print_file_upload_error() can not be used any more, please use new file API');
+}
+
+/**
+ * Handy function for resolving file conflicts
+ * @deprecated removed - use new file api
+ */
+
+function resolve_filename_collisions($destination,$files,$format='%s_%d.%s') {
+    throw new coding_error('resolve_filename_collisions() can not be used any more, please use new file API');
+}
+
+/**
+ * Checks a file name for any conflicts
+ * @deprecated removed - use new file api
+ */
+function check_potential_filename($destination,$filename,$files) {
+    throw new coding_error('check_potential_filename() can not be used any more, please use new file API');
+}
+
+/**
+ * This function prints out a number of upload form elements.
+ * @deprecated removed - use new file api
+ */
+function upload_print_form_fragment($numfiles=1, $names=null, $descriptions=null, $uselabels=false, $labelnames=null, $coursebytes=0, $modbytes=0, $return=false) {
+    throw new coding_error('upload_print_form_fragment() can not be used any more, please use new file API');
+}
+
 /**
  * Return the authentication plugin title
  *
@@ -99,6 +133,7 @@ function auth_get_plugin_title($authtype) {
 }
 
 
+
 /**
  * Enrol someone without using the default role in a course
  * @deprecated
index 7f12a06..2f69f60 100644 (file)
@@ -15,6 +15,7 @@ class MoodleQuickForm_file extends HTML_QuickForm_file{
      */
     var $_helpbutton='';
     function MoodleQuickForm_file($elementName=null, $elementLabel=null, $attributes=null) {
+        debugging('file forms element is deprecated, please use new filepicker instead');
         parent::HTML_QuickForm_file($elementName, $elementLabel, $attributes);
     }
     /**
index 590b46c..7bec97f 100644 (file)
@@ -42,7 +42,6 @@ require_once 'HTML/QuickForm/DHTMLRulesTableless.php';
 require_once 'HTML/QuickForm/Renderer/Tableless.php';
 
 require_once $CFG->libdir.'/filelib.php';
-require_once $CFG->libdir.'/uploadlib.php'; // TODO: remove
 
 define('EDITOR_UNLIMITED_FILES', -1);
 
@@ -230,7 +229,8 @@ abstract class moodleform {
     }
 
     /**
-     * Internal method. Validates all old-style uploaded files.
+     * Internal method. Validates all old-style deprecated uploaded files.
+     * The new way is to upload files via repository api.
      *
      * @global object
      * @global object
@@ -283,7 +283,7 @@ abstract class moodleform {
             }
 
 /*
-  // TODO: rethink the file scanning
+  // TODO: rethink the file scanning MDL-19380
             if ($CFG->runclamonupload) {
                 if (!clam_scan_moodle_file($_FILES[$elname], $COURSE)) {
                     $errors[$elname] = $_FILES[$elname]['uploadlog'];
@@ -329,7 +329,6 @@ abstract class moodleform {
      * note: $slashed param removed
      *
      * @param mixed $default_values object or array of default values
-     * @param bool $slased true if magic quotes applied to data values
      */
     function set_data($default_values) {
         if (is_object($default_values)) {
@@ -339,10 +338,10 @@ abstract class moodleform {
     }
 
     /**
-     * @param bool $um
+     * @deprecated
      */
     function set_upload_manager($um=false) {
-        debugging('Not used anymore, please fix code!');
+        debugging('Old file uploads can not be used any more, please use new filepicker element');
     }
 
     /**
@@ -809,8 +808,6 @@ abstract class moodleform {
 
     /**
      * Abstract method - always override!
-     *
-     * If you need special handling of uploaded files, create instance of $this->_upload_manager here.
      */
     protected abstract function definition();
 
index 166f0bd..c204d19 100644 (file)
@@ -5292,118 +5292,6 @@ function get_max_upload_sizes($sitebytes=0, $coursebytes=0, $modulebytes=0) {
     return $filesize;
 }
 
-/**
- * If there has been an error uploading a file, print the appropriate error message
- * Numerical constants used as constant definitions not added until PHP version 4.2.0
- *
- * $filearray is a 1-dimensional sub-array of the $_FILES array
- * eg $filearray = $_FILES['userfile1']
- * If left empty then the first element of the $_FILES array will be used
- *
- * @uses $_FILES
- * @param array $filearray  A 1-dimensional sub-array of the $_FILES array
- * @param bool $returnerror If true then a string error message will be returned. Otherwise the user will be notified of the error in a notify() call.
- * @return bool|string
- */
-function print_file_upload_error($filearray = '', $returnerror = false) {
-    global $OUTPUT;
-    if ($filearray == '' or !isset($filearray['error'])) {
-
-        if (empty($_FILES)) return false;
-
-        $files = $_FILES; /// so we don't mess up the _FILES array for subsequent code
-        $filearray = array_shift($files); /// use first element of array
-    }
-
-    switch ($filearray['error']) {
-
-        case 0: // UPLOAD_ERR_OK
-            if ($filearray['size'] > 0) {
-                $errmessage = get_string('uploadproblem', $filearray['name']);
-            } else {
-                $errmessage = get_string('uploadnofilefound'); /// probably a dud file name
-            }
-            break;
-
-        case 1: // UPLOAD_ERR_INI_SIZE
-            $errmessage = get_string('uploadserverlimit');
-            break;
-
-        case 2: // UPLOAD_ERR_FORM_SIZE
-            $errmessage = get_string('uploadformlimit');
-            break;
-
-        case 3: // UPLOAD_ERR_PARTIAL
-            $errmessage = get_string('uploadpartialfile');
-            break;
-
-        case 4: // UPLOAD_ERR_NO_FILE
-            $errmessage = get_string('uploadnofilefound');
-            break;
-
-        default:
-            $errmessage = get_string('uploadproblem', $filearray['name']);
-    }
-
-    if ($returnerror) {
-        return $errmessage;
-    } else {
-        echo $OUTPUT->notification($errmessage);
-        return true;
-    }
-
-}
-
-/**
- * Handy function for resolving file conflicts
- *
- * handy function to loop through an array of files and resolve any filename conflicts
- * both in the array of filenames and for what is already on disk.
- * not really compatible with the similar function in uploadlib.php
- * but this could be used for files/index.php for moving files around.
- * @see check_potential_filename()
- *
- * @param string $destination destination folder
- * @param array $files
- * @param string $format
- * @return array Array of now resolved file names
- */
-
-function resolve_filename_collisions($destination,$files,$format='%s_%d.%s') {
-    foreach ($files as $k => $f) {
-        if (check_potential_filename($destination,$f,$files)) {
-            $bits = explode('.', $f);
-            for ($i = 1; true; $i++) {
-                $try = sprintf($format, $bits[0], $i, $bits[1]);
-                if (!check_potential_filename($destination,$try,$files)) {
-                    $files[$k] = $try;
-                    break;
-                }
-            }
-        }
-    }
-    return $files;
-}
-
-/**
- * Checks a file name for any conflicts
- * @see resolve_filename_collisions()
- *
- * @param string $destination Destination directory
- * @param string $filename Desired filename
- * @param array $files Array of other file names to check against
- */
-function check_potential_filename($destination,$filename,$files) {
-    if (file_exists($destination.'/'.$filename)) {
-        return true;
-    }
-    if (count(array_keys($files,$filename)) > 1) {
-        return true;
-    }
-    return false;
-}
-
-
 /**
  * Returns an array with all the filenames in all subdirectories, relative to the given rootdir.
  *
index 9adb556..2633543 100644 (file)
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
-/** {@see eventslib.php} */
-require_once($CFG->libdir.'/eventslib.php');
-
-//error_reporting(E_ALL ^ E_NOTICE);
 /**
  * This class handles all aspects of fileuploading
  *
@@ -506,46 +502,6 @@ FOR EXAMPLE CLAM_HANDLE_INFECTED_FILE AND CLAM_REPLACE_INFECTED_FILE USED FROM C
 UPLOAD_PRINT_FORM_FRAGMENT DOESN'T REALLY BELONG IN THE CLASS BUT CERTAINLY IN THIS FILE
 ***************************************************************************************/
 
-
-/**
- * This function prints out a number of upload form elements.
- *
- * @global object
- * @param int $numfiles The number of elements required (optional, defaults to 1)
- * @param array $names Array of element names to use (optional, defaults to FILE_n)
- * @param array $descriptions Array of strings to be printed out before each file bit.
- * @param boolean $uselabels -Whether to output text fields for file descriptions or not (optional, defaults to false)
- * @param array $labelnames Array of element names to use for labels (optional, defaults to LABEL_n)
- * @param int $coursebytes $coursebytes and $maxbytes are used to calculate upload max size ( using {@link get_max_upload_file_size})
- * @param int $modbytes $coursebytes and $maxbytes are used to calculate upload max size ( using {@link get_max_upload_file_size})
- * @param boolean $return -Whether to return the string (defaults to false - string is echoed)
- * @return string Form returned as string if $return is true
- */
-function upload_print_form_fragment($numfiles=1, $names=null, $descriptions=null, $uselabels=false, $labelnames=null, $coursebytes=0, $modbytes=0, $return=false) {
-    global $CFG;
-    $maxbytes = get_max_upload_file_size($CFG->maxbytes, $coursebytes, $modbytes);
-    $str = '<input type="hidden" name="MAX_FILE_SIZE" value="'. $maxbytes .'" />'."\n";
-    for ($i = 0; $i < $numfiles; $i++) {
-        if (is_array($descriptions) && !empty($descriptions[$i])) {
-            $str .= '<strong>'. $descriptions[$i] .'</strong><br />';
-        }
-        $name = ((is_array($names) && !empty($names[$i])) ? $names[$i] : 'FILE_'.$i);
-        $str .= '<input type="file" size="50" name="'. $name .'" alt="'. $name .'" /><br />'."\n";
-        if ($uselabels) {
-            $lname = ((is_array($labelnames) && !empty($labelnames[$i])) ? $labelnames[$i] : 'LABEL_'.$i);
-            $str .= get_string('uploadlabel').' <input type="text" size="50" name="'. $lname .'" alt="'. $lname
-                .'" /><br /><br />'."\n";
-        }
-    }
-    if ($return) {
-        return $str;
-    }
-    else {
-        echo $str;
-    }
-}
-
-
 /**
  * Deals with an infected file - either moves it to a quarantinedir
  * (specified in CFG->quarantinedir) or deletes it.
index af0525c..930c936 100644 (file)
@@ -30,7 +30,6 @@
 
 require_once('../../config.php');
 require_once('lib.php');
-require_once($CFG->libdir.'/uploadlib.php');
 require_once($CFG->libdir.'/xmlize.php');
 
 $id       = optional_param('id', 0, PARAM_INT);    // course module id
index 760ec77..b5c8b87 100644 (file)
@@ -11,7 +11,6 @@
 
 require_once("../config.php");
 require_once("editlib.php"); // Includes lib/questionlib.php
-require_once($CFG->libdir . '/uploadlib.php');
 require_once("import_form.php");
 
 list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) =
index 4da7131..1d87852 100755 (executable)
@@ -263,6 +263,7 @@ switch ($action) {
         }
         break;
     case 'upload':
+        // TODO: add file scanning MDL-19380 into each plugin
         $result = $repo->upload();
         echo json_encode($result);
         break;
index 2e57797..bb529d9 100644 (file)
@@ -142,10 +142,6 @@ class user_edit_form extends moodleform {
 
         return $errors;
     }
-
-    function get_um() {
-        return $this->_upload_manager;
-    }
 }
 
 
index 9a71424..95483f4 100644 (file)
@@ -43,7 +43,7 @@ class user_editadvanced_form extends moodleform {
             $auth_options[$auth] = get_string('pluginname', "auth_{$auth}");
         }
         $mform->addElement('select', 'auth', get_string('chooseauthmethod','auth'), $auth_options);
-        $mform->addHelpButton('auth', 'chooseauthmethod', 'auth');        
+        $mform->addHelpButton('auth', 'chooseauthmethod', 'auth');
 
         if (!empty($CFG->passwordpolicy)){
             $mform->addElement('static', 'passwordpolicyinfo', '', print_password_policy());
@@ -117,9 +117,9 @@ class user_editadvanced_form extends moodleform {
         global $CFG, $DB;
 
         $usernew = (object)$usernew;
-        $usernew->username = trim($usernew->username);        
-        
-        $user = $DB->get_record('user', array('id'=>$usernew->id));        
+        $usernew->username = trim($usernew->username);
+
+        $user = $DB->get_record('user', array('id'=>$usernew->id));
         $err = array();
 
         if (!empty($usernew->newpassword)) {
@@ -137,7 +137,7 @@ class user_editadvanced_form extends moodleform {
             if ($DB->record_exists('user', array('username'=>$usernew->username, 'mnethostid'=>$CFG->mnet_localhost_id))) {
                 $err['username'] = get_string('usernameexists');
             }
-            //check allowed characters                         
+            //check allowed characters
             if ($usernew->username !== moodle_strtolower($usernew->username)) {
                 $err['username'] = get_string('usernamelowercase');
             } else {
@@ -164,10 +164,6 @@ class user_editadvanced_form extends moodleform {
             return $err;
         }
     }
-
-    function get_um() {
-        return $this->_upload_manager;
-    }
 }