# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: moodle/admin/uploaduser.php
--- moodle/admin/uploaduser.php Base (1.101)
+++ moodle/admin/uploaduser.php Locally Modified (Based On 1.101)
@@ -72,7 +72,7 @@
         'maildisplay', 'maildigest', 'htmleditor', 'ajax', 'autosubscribe',
         'mnethostid', 'institution', 'department', 'idnumber', 'skype',
         'msn', 'aim', 'yahoo', 'icq', 'phone1', 'phone2', 'address',
-        'url', 'description', 'oldusername', 'emailstop', 'deleted',
+        'url', 'description', 'descriptionsummary', 'descriptiontrust', 'oldusername', 'emailstop', 'deleted',
         'password');
 
 $PRF_FIELDS = array();
Index: moodle/admin/uploaduser_form.php
--- moodle/admin/uploaduser_form.php Base (1.13)
+++ moodle/admin/uploaduser_form.php Locally Modified (Based On 1.13)
@@ -1,4 +1,5 @@
-<?php // $Id: uploaduser_form.php,v 1.13 2009/05/17 21:10:07 skodak Exp $
+<?php
+
 require_once $CFG->libdir.'/formslib.php';
 
 class admin_uploaduser_form1 extends moodleform {
@@ -212,10 +213,11 @@
         $mform->setDefault('lang', $templateuser->lang);
         $mform->setAdvanced('lang');
 
-        $mform->addElement('htmleditor', 'description', get_string('userdescription'));
-        $mform->setType('description', PARAM_CLEAN);
-        $mform->setHelpButton('description', array('text2', get_string('helptext')));
-        $mform->setAdvanced('description');
+        $editoroptions = array('maxfiles'=>0, 'maxbytes'=>0, 'trusttext'=>false, 'forcehttps'=>false);
+        $mform->addElement('editor', 'description_editor', get_string('userdescription'), null, $editoroptions);
+        $mform->setType('description_editor', PARAM_RAW);
+        $mform->setHelpButton('description_editor', array('text2', get_string('helptext')));
+        $mform->setAdvanced('description_editor');
 
         $mform->addElement('text', 'url', get_string('webpage'), 'maxlength="255" size="50"');
         $mform->setAdvanced('url');
Index: moodle/blocks/course_summary/block_course_summary.php
--- moodle/blocks/course_summary/block_course_summary.php Base (1.32)
+++ moodle/blocks/course_summary/block_course_summary.php Locally Modified (Based On 1.32)
@@ -26,6 +26,8 @@
         $this->content = new object();
         $options = new object();
         $options->noclean = true;    // Don't clean Javascripts etc
+        $context = get_context_instance(CONTEXT_COURSE, $this->page->course->id);
+        $this->page->course->summary = file_rewrite_pluginfile_urls($this->page->course->summary, 'pluginfile.php', $context->id, 'course_summary', $this->page->course->id);
         $this->content->text = format_text($this->page->course->summary, FORMAT_HTML, $options);
         if ($this->page->user_is_editing()) {
             if($this->page->course->id == SITEID) {
Index: moodle/course/edit.php
--- moodle/course/edit.php Base (1.122)
+++ moodle/course/edit.php Locally Modified (Based On 1.122)
@@ -1,4 +1,4 @@
-<?php // $Id: edit.php,v 1.122 2009/09/16 08:19:22 samhemelryk Exp $
+<?php
       // Edit course settings
 
     require_once('../config.php');
@@ -24,8 +24,8 @@
         }
         require_login($course->id);
         $category = $DB->get_record('course_categories', array('id'=>$course->category));
-        require_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id));
-
+        $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+        require_capability('moodle/course:update', $coursecontext);
     } else if ($categoryid) { // creating new course in this category
         $course = null;
         require_login();
@@ -45,7 +45,8 @@
         $PAGE->url->param('category',$categoryid);
     }
 
-/// prepare course
+    /// Prepare course and the editor
+    $editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>true);
     if (!empty($course)) {
         $allowedmods = array();
         if (!empty($course)) {
@@ -60,12 +61,15 @@
             }
             $course->allowedmods = $allowedmods;
         }
+        $course = file_prepare_standard_editor($course, 'summary', $editoroptions, $coursecontext, 'course_summary', $course->id);
+    } else {
+        $course = file_prepare_standard_editor($course, 'summary', $editoroptions, get_context_instance(CONTEXT_SYSTEM), 'course_summary', null);
     }
 
 /// first create the form
-    $editform = new course_edit_form('edit.php', compact('course', 'category'));
+    $editform = new course_edit_form('edit.php', compact('course', 'category', 'editoroptions'));
     // now override defaults if course already exists
-    if (!empty($course)) {
+    if (!empty($course->id)) {
         $course->enrolpassword = $course->password; // we need some other name for password field MDL-9929
         $editform->set_data($course);
     }
@@ -84,13 +88,22 @@
         //preprocess data
         $data->timemodified = time();
 
-        if (empty($course)) {
+        if (empty($course->id)) {
+            // In creating the course
             if (!$course = create_course($data)) {
                 print_error('coursenotcreated');
             }
 
+            // Get the context of the newly created course
             $context = get_context_instance(CONTEXT_COURSE, $course->id);
 
+            // Save the files used in the summary editor
+            $editordata = new stdClass;
+            $editordata->id = $course->id;
+            $editordata->summary_editor = $data->summary_editor;
+            $editordata = file_postupdate_standard_editor($editordata, 'summary', $editoroptions, $context, 'course_summary', $course->id);
+            $DB->update_record('course', $editordata);
+
             // assign default role to creator if not already having permission to manage course assignments
             if (!has_capability('moodle/course:view', $context) or !has_capability('moodle/role:assign', $context)) {
                 role_assign($CFG->creatornewroleid, $USER->id, 0, $context->id);
@@ -109,6 +122,8 @@
             }
 
         } else {
+            // Save any changes to the files used in the editor
+            $data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $coursecontext, 'course_summary', $data->id);
             if (!update_course($data)) {
                 print_error('coursenotupdated');
             }
@@ -126,7 +141,7 @@
     $stradministration = get_string("administration");
     $strcategories = get_string("categories");
 
-    if (!empty($course)) {
+    if (!empty($course->id)) {
         $PAGE->navbar->add($streditcoursesettings);
         $title = $streditcoursesettings;
         $fullname = $course->fullname;
Index: moodle/course/edit_form.php
--- moodle/course/edit_form.php Base (1.70)
+++ moodle/course/edit_form.php Locally Modified (Based On 1.70)
@@ -1,4 +1,4 @@
-<?php  //$Id: edit_form.php,v 1.70 2009/10/02 07:05:02 nicolasconnault Exp $
+<?php
 
 require_once($CFG->libdir.'/formslib.php');
 
@@ -12,13 +12,13 @@
 
         $course   = $this->_customdata['course'];
         $category = $this->_customdata['category'];
+        $editoroptions = $this->_customdata['editoroptions'];
 
         $systemcontext = get_context_instance(CONTEXT_SYSTEM);
         $categorycontext = get_context_instance(CONTEXT_COURSECAT, $category->id);
 
         $disable_meta = false; // basic meta course state protection; server-side security checks not needed
-
-        if (!empty($course)) {
+        if (!empty($course->id)) {
             $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
             $context = $coursecontext;
 
@@ -71,7 +71,7 @@
         $mform->setDefault('category', $category->id);
         $mform->setType('category', PARAM_INT);
 
-        if ($course and !has_capability('moodle/course:changecategory', $coursecontext)) {
+        if (!empty($course->id) and !has_capability('moodle/course:changecategory', $coursecontext)) {
             $mform->hardFreeze('category');
             $mform->setConstant('category', $category->id);
         }
@@ -88,7 +88,7 @@
         $mform->setHelpButton('fullname', array('coursefullname', get_string('fullnamecourse')), true);
         $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
         $mform->setType('fullname', PARAM_MULTILANG);
-        if ($course and !has_capability('moodle/course:changefullname', $coursecontext)) {
+        if (!empty($course->id) and !has_capability('moodle/course:changefullname', $coursecontext)) {
             $mform->hardFreeze('fullname');
             $mform->setConstant('fullname', $course->fullname);
         }
@@ -99,7 +99,7 @@
         $mform->setHelpButton('shortname', array('courseshortname', get_string('shortnamecourse')), true);
         $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
         $mform->setType('shortname', PARAM_MULTILANG);
-        if ($course and !has_capability('moodle/course:changeshortname', $coursecontext)) {
+        if (!empty($course->id) and !has_capability('moodle/course:changeshortname', $coursecontext)) {
             $mform->hardFreeze('shortname');
             $mform->setConstant('shortname', $course->shortname);
         }
@@ -109,17 +109,18 @@
         $mform->addElement('text','idnumber', get_string('idnumbercourse'),'maxlength="100"  size="10"');
         $mform->setHelpButton('idnumber', array('courseidnumber', get_string('idnumbercourse')), true);
         $mform->setType('idnumber', PARAM_RAW);
-        if ($course and !has_capability('moodle/course:changeidnumber', $coursecontext)) {
+        if (!empty($course->id) and !has_capability('moodle/course:changeidnumber', $coursecontext)) {
             $mform->hardFreeze('idnumber');
             $mform->setConstants('idnumber', $course->idnumber);
         }
 
-        $mform->addElement('htmleditor','summary', get_string('summary'), array('rows'=> '10', 'cols'=>'65'));
-        $mform->setHelpButton('summary', array('text2', get_string('helptext')), true);
-        $mform->setType('summary', PARAM_RAW);
 
-        if ($course and !has_capability('moodle/course:changesummary', $coursecontext)) {
-            $mform->hardFreeze('summary');
+        $mform->addElement('editor','summary_editor', get_string('summary'), null, $editoroptions);
+        $mform->setHelpButton('summary_editor', array('text2', get_string('helptext')), true);
+        $mform->setType('summary_editor', PARAM_RAW);
+
+        if (!empty($course->id) and !has_capability('moodle/course:changesummary', $coursecontext)) {
+            $mform->hardFreeze('summary_editor');
         }
 
         $courseformats = get_plugin_list('format');
@@ -211,7 +212,7 @@
 
 
         $roles = get_assignable_roles($context);
-        if (!empty($course)) {
+        if (!empty($course->id)) {
             // add current default role, so that it is selectable even when user can not assign it
             if ($current_role = $DB->get_record('role', array('id'=>$course->defaultrole))) {
                 $roles[$current_role->id] = strip_tags(format_string($current_role->name, true));
@@ -311,7 +312,7 @@
         $mform->addElement('select', 'visible', get_string('availability'), $choices);
         $mform->setHelpButton('visible', array('courseavailability', get_string('availability')), true);
         $mform->setDefault('visible', $courseconfig->visible);
-        if ($course and !has_capability('moodle/course:visibility', $coursecontext)) {
+        if (!empty($course->id) and !has_capability('moodle/course:visibility', $coursecontext)) {
             $mform->hardFreeze('visible');
             $mform->setConstant('visible', $course->visible);
         }
@@ -322,7 +323,7 @@
         $mform->setDefault('enrolpassword', $courseconfig->enrolpassword);
         $mform->setType('enrolpassword', PARAM_RAW);
 
-        if (empty($course) or ($course->password !== '' and $course->id != SITEID)) {
+        if (empty($course->id) or ($course->password !== '' and $course->id != SITEID)) {
             // do not require password in existing courses that do not have password yet - backwards compatibility ;-)
             if (!empty($CFG->enrol_manual_requirekey)) {
                 $mform->addRule('enrolpassword', get_string('required'), 'required', null, 'client');
@@ -339,7 +340,7 @@
 
         // If we are creating a course, its enrol method isn't yet chosen, BUT the site has a default enrol method which we can use here
         $enrol_object = $CFG;
-        if (!empty($course)) {
+        if (!empty($course->id)) {
             $enrol_object = $course;
         }
         // If the print_entry method exists and the course enrol method isn't manual (both set or inherited from site), show cost
Index: moodle/course/editcategory.php
--- moodle/course/editcategory.php Base (1.28)
+++ moodle/course/editcategory.php Locally Modified (Based On 1.28)
@@ -1,4 +1,4 @@
-<?php // $Id$
+<?php
 /**
  * Page for creating or editing course category name/parent/description.
  * When called with an id parameter, edits the category with that id.
@@ -18,8 +18,10 @@
         print_error('unknowcategory');
     }
     $PAGE->set_url('course/editcategory.php', array('id' => $id));
-    require_capability('moodle/category:manage', get_context_instance(CONTEXT_COURSECAT, $id));
+    $categorycontext = get_context_instance(CONTEXT_COURSECAT, $id);
+    require_capability('moodle/category:manage', $categorycontext);
     $strtitle = get_string('editcategorysettings');
+    $editorcontext = $categorycontext;
 } else {
     $parent = required_param('parent', PARAM_INT);
     $PAGE->set_url('course/editcategory.php', array('parent' => $parent));
@@ -36,9 +38,13 @@
     $category->parent = $parent;
     require_capability('moodle/category:manage', $context);
     $strtitle = get_string("addnewcategory");
+    $editorcontext = null;
 }
 
-$mform = new editcategory_form('editcategory.php', $category);
+$editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>true);
+$category = file_prepare_standard_editor($category, 'description', $editoroptions, $editorcontext, 'category_description', $category->id);
+
+$mform = new editcategory_form('editcategory.php', compact('category', 'editoroptions'));
 $mform->set_data($category);
 
 if ($mform->is_cancelled()) {
@@ -52,7 +58,7 @@
 } else if ($data = $mform->get_data()) {
     $newcategory = new stdClass();
     $newcategory->name = $data->name;
-    $newcategory->description = $data->description;
+    $newcategory->description_editor = $data->description_editor;
     $newcategory->parent = $data->parent; // if $data->parent = 0, the new category will be a top-level category
 
     if (isset($data->theme) && !empty($CFG->allowcategorythemes)) {
@@ -66,17 +72,20 @@
             $parent_cat = $DB->get_record('course_categories', array('id' => $newcategory->parent));
             move_category($newcategory, $parent_cat);
         }
-        $DB->update_record('course_categories', $newcategory);
-        fix_course_sortorder();
-
     } else {
         // Create a new category.
+        $newcategory->description = $data->description_editor['text'];
         $newcategory->sortorder = 999;
         $newcategory->id = $DB->insert_record('course_categories', $newcategory);
         $newcategory->context = get_context_instance(CONTEXT_COURSECAT, $newcategory->id);
+        $categorycontext = $newcategory->context;
         mark_context_dirty($newcategory->context->path);
-        fix_course_sortorder(); // Required to build course_categories.depth and .path.
     }
+
+    $newcategory = file_postupdate_standard_editor($newcategory, 'description', $editoroptions, $categorycontext, 'category_description', $newcategory->id);
+    $DB->update_record('course_categories', $newcategory);
+    fix_course_sortorder();
+
     redirect('category.php?id='.$newcategory->id.'&categoryedit=on');
 }
 
Index: moodle/course/editcategory_form.php
--- moodle/course/editcategory_form.php Base (1.9)
+++ moodle/course/editcategory_form.php Locally Modified (Based On 1.9)
@@ -6,7 +6,8 @@
     function definition() {
         global $CFG;
         $mform =& $this->_form;
-        $category = $this->_customdata;
+        $category = $this->_customdata['category'];
+        $editoroptions = $this->_customdata['editoroptions'];
 
         // get list of categories to use as parents, with site as the first one
         $options = array(get_string('top'));
@@ -24,15 +25,15 @@
         $mform->addElement('select', 'parent', get_string('parentcategory'), $options);
         $mform->addElement('text', 'name', get_string('categoryname'), array('size'=>'30'));
         $mform->addRule('name', get_string('required'), 'required', null);
-        $mform->addElement('htmleditor', 'description', get_string('description'));
-        $mform->setType('description', PARAM_RAW);
+        $mform->addElement('editor', 'description_editor', get_string('description'), null, $editoroptions);
+        $mform->setType('description_editor', PARAM_RAW);
         if (!empty($CFG->allowcategorythemes)) {
             $themes=array();
             $themes[''] = get_string('forceno');
             $themes += get_list_of_themes();
             $mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
         }
-        $mform->setHelpButton('description', array('writing', 'richtext2'), false, 'editorhelpbutton');
+        $mform->setHelpButton('description_editor', array('writing', 'richtext2'), false, 'editorhelpbutton');
 
         $mform->addElement('hidden', 'id', 0);
         $mform->setType('id', PARAM_INT);
Index: moodle/course/info.php
--- moodle/course/info.php Base (1.36)
+++ moodle/course/info.php Locally Modified (Based On 1.36)
@@ -59,7 +59,8 @@
 
     echo $OUTPUT->box_start('generalbox info');
 
-    echo format_text($course->summary, FORMAT_MOODLE, NULL, $course->id);
+    $course->summary = file_rewrite_pluginfile_urls($course->summary, 'pluginfile.php', $context->id, 'course_summary', $course->id);
+    echo format_text($course->summary, $course->summaryformat, NULL, $course->id);
 
     if ($managerroles = get_config('', 'coursemanager')) {
         $coursemanagerroles = split(',', $managerroles);
Index: moodle/course/lib.php
--- moodle/course/lib.php Base (1.697)
+++ moodle/course/lib.php Locally Modified (Based On 1.697)
@@ -2174,6 +2174,9 @@
         $context = get_context_instance(CONTEXT_COURSE, $course->id);
     }
 
+    // Rewrite file URLs so that they are correct
+    $course->summary = file_rewrite_pluginfile_urls($course->summary, 'pluginfile.php', $context->id, 'course_summary', $course->id);
+
     $linkcss = $course->visible ? '' : ' class="dimmed" ';
 
     echo '<div class="coursebox clearfix">';
@@ -3590,3 +3593,388 @@
     global $DB;
     return $DB->get_record('course', array('idnumber' => $idnumber));
 }
+
+/**
+ * This class pertains to course requests and contains methods associated with
+ * create, approving, and removing course requests.
+ *
+ * @copyright 2009 Sam Hemelryk
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @since Moodle 2.0
+ *
+ * @property-read int $id
+ * @property-read string $fullname
+ * @property-read string $shortname
+ * @property-read string $summary
+ * @property-read int $summaryformat
+ * @property-read int $summarytrust
+ * @property-read string $reason
+ * @property-read int $requester
+ * @property-read string $password
+ */
+class course_request {
+
+    /**
+     * This is the stdClass that stores the properties for the course request
+     * and is externally acccessed through the __get magic method
+     * @var stdClass
+     */
+    protected $properties;
+
+    /**
+     * An array of options for the summary editor used by course request forms.
+     * This is initially set by {@link summary_editor_options()}
+     * @var array
+     * @static
+     */
+    protected static $summaryeditoroptions;
+
+    /**
+     * The context used when working with files for the summary editor
+     * This is initially set by {@link summary_editor_context()}
+     * @var stdClass
+     * @static
+     */
+    protected static $summaryeditorcontext;
+
+    /**
+     * The string used to identify the file area for course_requests
+     * This is initially set by {@link summary_editor_context()}
+     * @var string
+     * @static
+     */
+    protected static $summaryeditorfilearea = 'course_request_summary';
+
+    /**
+     * Static function to prepare the summary editor for working with a course
+     * request.
+     *
+     * @static
+     * @param null|stdClass $data Optional, an object containing the default values
+     *                       for the form, these may be modified when preparing the
+     *                       editor so this should be called before creating the form
+     * @return stdClass An object that can be used to set the default values for
+     *                   an mforms form
+     */
+    public static function prepare($data=null) {
+        if ($data === null) {
+            $data = new stdClass;
+        }
+        $data = file_prepare_standard_editor($data, 'summary', self::summary_editor_options(), self::summary_editor_context(), self::summary_editor_filearea(), null);
+        return $data;
+    }
+
+    /**
+     * Static function to create a new course request when passed an array of properties
+     * for it.
+     *
+     * This function also handles saving any files that may have been used in the editor
+     *
+     * @static
+     * @param stdClass $data
+     * @return course_request The newly created course request
+     */
+    public static function create($data) {
+        global $USER, $DB, $CFG;
+        $data->requester = $USER->id;
+        $editorused = (!empty($data->summary_editor));
+        // Has summary_editor been set. If so we have come through with a editor and
+        // may need to save files
+        if ($editorused && empty($data->summary)) {
+            // Summary is a required field so copy the text over
+            $data->summary = $data->summary_editor['text'];
+        }
+        $data->id = $DB->insert_record('course_request', $data);
+        if ($editorused) {
+            // Save any files and then update the course with the fixed data
+            $data = file_postupdate_standard_editor($data, 'summary', self::summary_editor_options(), self::summary_editor_context(), self::summary_editor_filearea(), $data->id);
+            $DB->update_record('course_request', $data);
+        }
+        // Create a new course_request object and return it
+        $request = new course_request($data);
+
+        // Notify the admin if required.
+        if ($CFG->courserequestnotify) {
+            $users = get_users_from_config($CFG->courserequestnotify, 'moodle/site:approvecourse');
+            
+            $a = new stdClass;
+            $a->link = "$CFG->wwwroot/course/pending.php";
+            $a->user = fullname($USER);
+            $subject = get_string('courserequest');
+            $message = get_string('courserequestnotifyemail', 'admin', $a);
+            foreach ($users as $user) {
+                $this->notify($user, $USER, 'courserequested', $subject, $message);
+            }
+        }
+
+        return $request;
+    }
+
+    /**
+     * Returns an array of options to use with a summary editor
+     *
+     * @uses course_request::$summaryeditoroptions
+     * @return array An array of options to use with the editor
+     */
+    public static function summary_editor_options() {
+        global $CFG;
+        if (self::$summaryeditoroptions === null) {
+            self::$summaryeditoroptions = array('maxfiles' => 0, 'maxbytes'=>0, 'trusttext'=>true);
+        }
+        return self::$summaryeditoroptions;
+    }
+
+    /**
+     * Returns the context to use with the summary editor
+     *
+     * @uses course_request::$summaryeditorcontext
+     * @return stdClass The context to use
+     */
+    public static function summary_editor_context() {
+        return null;
+    }
+
+    /**
+     * Returns the filearea to use with the summary editor
+     *
+     * @uses course_request::$summaryeditorfilearea
+     * @return string The filearea to use with the summary editor
+     */
+    public static function summary_editor_filearea() {
+        return self::$summaryeditorfilearea;
+    }
+
+    /**
+     * Loads the properties for this course request object. Id is required and if
+     * only id is provided then we load the rest of the properties from the database
+     *
+     * @param stdClass|int $properties Either an object containing properties
+     *                      or the course_request id to load
+     */
+    public function __construct($properties) {
+        global $DB;
+        if (empty($properties->id)) {
+            if (empty($properties)) {
+                throw new coding_exception('You must provide a course request id when creating a course_request object');
+            }
+            $id = $properties;
+            $properties = new stdClass;
+            $properties->id = (int)$id;
+            unset($id);
+        }
+        if (empty($properties->requester)) {
+            if (!($this->properties = $DB->get_record('course_request', array('id' => $properties->id)))) {
+                print_error('unknowncourserequest');
+            }
+        } else {
+            $this->properties = $properties;
+        }
+        $this->properties->collision = null;
+    }
+
+    /**
+     * Returns the requested property
+     *
+     * @param string $key
+     * @return mixed
+     */
+    public function __get($key) {
+        if ($key === 'summary' && self::summary_editor_context() !== null) {
+            return file_rewrite_pluginfile_urls($this->properties->summary, 'pluginfile.php', self::summary_editor_context()->id, self::summary_editor_filearea(), $this->properties->id);
+        }
+        return $this->properties->$key;
+    }
+
+    /**
+     * Override this to ensure empty($request->blah) calls return a reliable answer...
+     *
+     * This is required because we define the __get method
+     *
+     * @param mixed $key
+     * @return bool True is it not empty, false otherwise
+     */
+    public function __isset($key) {
+        return (!empty($this->properties->$key));
+    }
+
+    /**
+     * Returns the user who requested this course
+     *
+     * Uses a static var to cache the results and cut down the number of db queries
+     *
+     * @staticvar array $requesters An array of cached users
+     * @return stdClass The user who requested the course
+     */
+    public function get_requester() {
+        global $DB;
+        static $requesters= array();
+        if (!array_key_exists($this->properties->requester, $requesters)) {
+            $requesters[$this->properties->requester] = $DB->get_record('user', array('id'=>$this->properties->requester));
+        }
+        return $requesters[$this->properties->requester];
+    }
+
+    /**
+     * Checks that the shortname used by the course does not conflict with any other
+     * courses that exist
+     *
+     * @param string|null $shortnamemark The string to append to the requests shortname
+     *                     should a conflict be found
+     * @return bool true is there is a conflict, false otherwise
+     */
+    public function check_shortname_collision($shortnamemark = '[*]') {
+        global $DB;
+
+        if ($this->properties->collision !== null) {
+            return $this->properties->collision;
+        }
+
+        if (empty($this->properties->shortname)) {
+            debugging('Attempting to check a course request shortname before it has been set', DEBUG_DEVELOPER);
+            $this->properties->collision = false;
+        } else if ($DB->record_exists('course', array('shortname' => $this->properties->shortname))) {
+            if (!empty($shortnamemark)) {
+                $this->properties->shortname .= ' '.$shortnamemark;
+            }
+            $this->properties->collision = true;
+        } else {
+            $this->properties->collision = false;
+        }
+        return $this->properties->collision;
+    }
+
+    /**
+     * This function approves the request turning it into a course
+     *
+     * This function converts the course request into a course, at the same time
+     * transfering any files used in the summary to the new course and then removing
+     * the course request and the files associated with it.
+     *
+     * @return int The id of the course that was created from this request
+     */
+    public function approve() {
+        global $CFG, $DB, $USER;
+        $category = get_course_category($CFG->defaultrequestcategory);
+        $courseconfig = get_config('moodlecourse');
+
+        // Transfer appropriate settings
+        $course = clone($this->properties);
+        unset($course->id);
+        unset($course->reason);
+        unset($course->requester);
+
+        // Set category
+        $course->category = $category->id;
+        $course->sortorder = $category->sortorder; // place as the first in category
+
+        // Set misc settings
+        $course->requested = 1;
+        if (!empty($CFG->restrictmodulesfor) && $CFG->restrictmodulesfor != 'none' && !empty($CFG->restrictbydefault)) {
+            $course->restrictmodules = 1;
+        }
+
+        // Apply course default settings
+        $course->format             = $courseconfig->format;
+        $course->numsections        = $courseconfig->numsections;
+        $course->hiddensections     = $courseconfig->hiddensections;
+        $course->newsitems          = $courseconfig->newsitems;
+        $course->showgrades         = $courseconfig->showgrades;
+        $course->showreports        = $courseconfig->showreports;
+        $course->maxbytes           = $courseconfig->maxbytes;
+        $course->enrol              = $courseconfig->enrol;
+        $course->enrollable         = $courseconfig->enrollable;
+        $course->enrolperiod        = $courseconfig->enrolperiod;
+        $course->expirynotify       = $courseconfig->expirynotify;
+        $course->notifystudents     = $courseconfig->notifystudents;
+        $course->expirythreshold    = $courseconfig->expirythreshold;
+        $course->groupmode          = $courseconfig->groupmode;
+        $course->groupmodeforce     = $courseconfig->groupmodeforce;
+        $course->visible            = $courseconfig->visible;
+        $course->enrolpassword      = $courseconfig->enrolpassword;
+        $course->guest              = $courseconfig->guest;
+        $course->lang               = $courseconfig->lang;
+
+        // Insert the record
+        $course->id = $DB->insert_record('course', $course);
+        if ($course->id) {
+            $course = $DB->get_record('course', array('id' => $course->id));
+            blocks_add_default_course_blocks($course);
+            $course->context = get_context_instance(CONTEXT_COURSE, $course->id);
+            role_assign($CFG->creatornewroleid, $this->properties->requester, 0, $course->context->id); // assing teacher role
+            if (!empty($CFG->restrictmodulesfor) && $CFG->restrictmodulesfor != 'none' && !empty($CFG->restrictbydefault)) {
+                // if we're all or requested we're ok.
+                $allowedmods = explode(',',$CFG->defaultallowedmodules);
+                update_restricted_mods($course, $allowedmods);
+            }
+            $this->copy_summary_files_to_course($course);
+            $this->delete();
+            fix_course_sortorder();
+
+            $user = $DB->get_record('user', array('id' => $this->properties->requester));
+            $a->name = $course->fullname;
+            $a->url = $CFG->wwwroot.'/course/view.php?id=' . $course->id;
+            $this->notify($user, $USER, 'courserequestapproved', get_string('courseapprovedsubject'), get_string('courseapprovedemail2', 'moodle', $a));
+
+            return $course->id;
+        }
+        return false;
+    }
+
+    public function reject($notice) {
+        global $USER;
+        $this->notify($user, $USER, 'courserequestrejected', get_string('courserejectsubject'), get_string('courserejectemail', 'moodle', $notice));
+        $this->delete();
+    }
+
+    /**
+     * Deletes the course request and any associated files
+     */
+    public function delete() {
+        global $DB;
+        $DB->delete_records('course_request', array('id' => $this->properties->id));
+        if (self::summary_editor_context() !== null) {
+            $fs = get_file_storage();
+            $files = $fs->get_area_files(self::summary_editor_context()->id, self::summary_editor_filearea(), $this->properties->id);
+            foreach ($files as $file) {
+                $file->delete();
+            }
+        }
+    }
+
+    /**
+     * This function copies all files used in the summary for the request to the
+     * summary of the course.
+     *
+     * This function copies, original files are left associated with the request
+     * and are removed only when the request is deleted
+     *
+     * @param stdClass $course An object representing the course to copy files to
+     */
+    protected function copy_summary_files_to_course($course) {
+        if (self::summary_editor_context() !== null) {
+            $fs = get_file_storage();
+            $files = $fs->get_area_files(self::summary_editor_context()->id, self::summary_editor_filearea(), $this->properties->id);
+            foreach ($files as $file) {
+                if (!$file->is_directory()) {
+                    $filerecord = array('contextid'=>$course->context->id, 'filearea'=>'course_summary', 'itemid'=>$course->id, 'filepath'=>$file->get_filepath(), 'filename'=>$file->get_filename());
+                    $fs->create_file_from_storedfile($filerecord, $file);
+                }
+            }
+        }
+    }
+
+    protected function notify($touser, $fromuser, $name='courserequested', $subject, $message) {
+        $eventdata = new object();
+        $eventdata->modulename        = 'moodle';
+        $eventdata->component         = 'course';
+        $eventdata->name              = $name;
+        $eventdata->userfrom          = $fromuser;
+        $eventdata->userto            = $touser;
+        $eventdata->subject = get_string('courserequest');
+        $eventdata->fullmessage = $message;
+        $eventdata->fullmessageformat = FORMAT_PLAIN;
+        $eventdata->fullmessagehtml   = '';
+        $eventdata->smallmessage      = '';
+        events_trigger('message_send', $eventdata);
+    }
+}
Index: moodle/course/pending.php
--- moodle/course/pending.php Base (1.30)
+++ moodle/course/pending.php Locally Modified (Based On 1.30)
@@ -1,4 +1,4 @@
-<?php  // $Id: pending.php,v 1.30 2009/09/27 06:20:47 mudrd8mz Exp $
+<?php
 
 ///////////////////////////////////////////////////////////////////////////
 //                                                                       //
@@ -28,7 +28,7 @@
  *
  * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  * @package course
- *//** */
+ */
 
     require_once(dirname(__FILE__) . '/../config.php');
     require_once($CFG->libdir . '/adminlib.php');
@@ -47,79 +47,10 @@
 /// Process approval of a course.
     if (!empty($approve) and confirm_sesskey()) {
     /// Load the request.
-        if (!$course = $DB->get_record('course_request', array('id' => $approve))) {
-            print_error('unknowncourserequest');
-        }
+    $course = new course_request($approve);
+    $courseid = $course->approve();
 
-    /// Get the category courses are added to.
-        $category = get_course_category($CFG->defaultrequestcategory);
-
-    /// Build up a course record based on the request.
-        $course->category = $category->id;
-        $course->sortorder = $category->sortorder; // place as the first in category 
-        $course->requested = 1;
-        unset($course->reason);
-        unset($course->id);
-        $teacherid = $course->requester;
-        unset($course->requester);
-        if (!empty($CFG->restrictmodulesfor) && $CFG->restrictmodulesfor != 'none' && !empty($CFG->restrictbydefault)) {
-            $course->restrictmodules = 1;
-        }
-
-    /// Apply course default settings
-        $courseconfig = get_config('moodlecourse');
-        $course->format             = $courseconfig->format;
-        $course->numsections        = $courseconfig->numsections;
-        $course->hiddensections     = $courseconfig->hiddensections;
-        $course->newsitems          = $courseconfig->newsitems;
-        $course->showgrades         = $courseconfig->showgrades;
-        $course->showreports        = $courseconfig->showreports;
-        $course->maxbytes           = $courseconfig->maxbytes;
-        $course->enrol              = $courseconfig->enrol;
-        $course->enrollable         = $courseconfig->enrollable;
-        $course->enrolperiod        = $courseconfig->enrolperiod;
-        $course->expirynotify       = $courseconfig->expirynotify;
-        $course->notifystudents     = $courseconfig->notifystudents;
-        $course->expirythreshold    = $courseconfig->expirythreshold;
-        $course->groupmode          = $courseconfig->groupmode;
-        $course->groupmodeforce     = $courseconfig->groupmodeforce;
-        $course->visible            = $courseconfig->visible;
-        $course->enrolpassword      = $courseconfig->enrolpassword;
-        $course->guest              = $courseconfig->guest;
-        $course->lang               = $courseconfig->lang;
-
-    /// Insert the record.
-        if ($courseid = $DB->insert_record('course', $course)) {
-            $course = $DB->get_record('course', array('id' => $courseid));
-            blocks_add_default_course_blocks($course);
-            $context = get_context_instance(CONTEXT_COURSE, $courseid);
-            role_assign($CFG->creatornewroleid, $teacherid, 0, $context->id); // assing teacher role
-            if (!empty($CFG->restrictmodulesfor) && $CFG->restrictmodulesfor != 'none' && !empty($CFG->restrictbydefault)) {
-                // if we're all or requested we're ok.
-                $allowedmods = explode(',',$CFG->defaultallowedmodules);
-                update_restricted_mods($course,$allowedmods);
-            }
-            $DB->delete_records('course_request', array('id'=>$approve));
-            $success = 1;
-            fix_course_sortorder();
-        }
-        if (!empty($success)) {
-            $user = $DB->get_record('user', array('id' => $teacherid));
-            $a->name = $course->fullname;
-            $a->url = $CFG->wwwroot.'/course/view.php?id=' . $courseid;
-            $eventdata = new object();
-            $eventdata->modulename        = 'moodle';
-            $eventdata->component         = 'course';
-            $eventdata->name              = 'courserequestapproved';
-            $eventdata->userfrom          = $USER;
-            $eventdata->userto            = $user;
-            $eventdata->subject           = get_string('courseapprovedsubject');
-            $eventdata->fullmessage       = get_string('courseapprovedemail2', 'moodle', $a);
-            $eventdata->fullmessageformat = FORMAT_PLAIN;
-            $eventdata->fullmessagehtml   = '';
-            $eventdata->smallmessage      = '';
-            events_trigger('message_send', $eventdata);
-
+    if ($courseid !== false) {
             redirect($CFG->wwwroot.'/course/edit.php?id=' . $courseid);
         } else {
             print_error('courseapprovedfailed');
@@ -128,15 +59,13 @@
 
 /// Process rejection of a course.
     if (!empty($reject)) {
-    /// Load the request.
-        if (!$course = $DB->get_record('course_request', array('id' => $reject))) {
-            print_error('unknowncourserequest');
-        }
+    // Load the request.
+    $course = new course_request($reject);
 
-    /// Prepare the form.
+    // Prepare the form.
         $rejectform = new reject_request_form($baseurl);
         $default = new stdClass();
-        $default->reject = $reject;
+    $default->reject = $course->id;
         $rejectform->set_data($default);
 
     /// Standard form processing if statement.
@@ -144,23 +73,9 @@
             redirect($baseurl);
     
         } else if ($data = $rejectform->get_data()) {
-        /// Send an email to the requester.
-            $user = $DB->get_record('user', array('id' => $course->requester));
-            $eventdata = new object();
-            $eventdata->modulename        = 'moodle';
-            $eventdata->component         = 'course';
-            $eventdata->name              = 'courserequestrejected';
-            $eventdata->userfrom          = $USER;
-            $eventdata->userto            = $user;
-            $eventdata->subject           = get_string('courserejectsubject');
-            $eventdata->fullmessage       = get_string('courserejectemail', 'moodle', $data->rejectnotice);
-            $eventdata->fullmessageformat = FORMAT_PLAIN;
-            $eventdata->fullmessagehtml   = '';
-            $eventdata->smallmessage      = '';
-            events_trigger('message_send', $eventdata);
 
-        /// Delete the request
-            $DB->delete_records('course_request', array('id' => $course->id));
+        /// Reject the request
+        $course->reject($data->rejectnotice);
 
         /// Redirect back to the course listing.
             redirect($baseurl, get_string('courserejected'));
@@ -190,29 +105,31 @@
                 get_string('requestedby'), get_string('summary'), get_string('requestreason'), get_string('action'));
         $strrequireskey = get_string('requireskey');
 
-    /// Loop over requested courses.
+    // Loop over requested courses.
+    $keyicon = new html_image();
+    $keyicon->src = $OUTPUT->old_icon_url('i/key');
+    $keyicon->alt = $strrequireskey;
+    $keyicon->add_class('icon');
+    $keyicon = $OUTPUT->image($keyicon);
+    
         foreach ($pending as $course) {
-            $requester = $DB->get_record('user', array('id'=>$course->requester));
-            $row = array();
+        $course = new course_request($course);
 
-        /// Check here for shortname collisions and warn about them.
-            if ($DB->record_exists('course', array('shortname' => $course->shortname))) {
-                $course->shortname .= ' [*]';
-                $collision = 1;
-            }
+        // Check here for shortname collisions and warn about them.
+        $course->check_shortname_collision();
 
-        /// Show an enrolment key icon in the first column if applicable.
+        $row = array();
+        // Show an enrolment key icon in the first column if applicable.
             if (!empty($course->password)) {
-                $row[] = '<img hspace="1" alt="'.$strrequireskey.'" class="icon" src="'.$OUTPUT->old_icon_url('i/key') . '" />';
+            $row[] = $keyicon;
             } else {
                 $row[] = '';
             }
-
-        /// Info in the other columns.
+        // Info in the other columns.
             $row[] = format_string($course->shortname);
             $row[] = format_string($course->fullname);
-            $row[] = fullname($requester);
-            $row[] = format_string($course->summary);
+        $row[] = fullname($course->get_requester());
+        $row[] = $course->summary;
             $row[] = format_string($course->reason);
             $row[] = $OUTPUT->button(html_form::make_button($baseurl, array('approve' => $course->id, 'sesskey' => sesskey()), get_string('approve'), 'get')) .
                     $OUTPUT->button(html_form::make_button($baseurl, array('reject' => $course->id), get_string('rejectdots'), 'get'));
@@ -233,4 +150,3 @@
 /// Finish off the page.
     echo $OUTPUT->button(html_form::make_button($CFG->wwwroot . '/course/index.php', array(), get_string('backtocourselisting')));
     echo $OUTPUT->footer();
-?>
Index: moodle/course/request.php
--- moodle/course/request.php Base (1.26)
+++ moodle/course/request.php Locally Modified (Based On 1.26)
@@ -24,6 +24,7 @@
  */
 
 require_once(dirname(__FILE__) . '/../config.php');
+require_once($CFG->dirroot . '/course/lib.php');
 require_once($CFG->dirroot . '/course/request_form.php');
 
 $PAGE->set_url(new moodle_url($CFG->wwwroot.'/course/request.php'));
@@ -39,65 +40,31 @@
 if (empty($CFG->enablecourserequests)) {
     print_error('courserequestdisabled', '', $returnurl);
 }
-$systemcontext = get_context_instance(CONTEXT_SYSTEM);
-require_capability('moodle/course:request', $systemcontext);
+require_capability('moodle/course:request', get_context_instance(CONTEXT_SYSTEM));
 
 /// Set up the form.
-$requestform = new course_request_form($CFG->wwwroot . '/course/request.php');
+$data = course_request::prepare();
+$requestform = new course_request_form($CFG->wwwroot . '/course/request.php', compact('editoroptions'));
+$requestform->set_data($data);
 
 $strtitle = get_string('courserequest');
+$PAGE->set_title($strtitle);
+$PAGE->set_heading($strtitle);
 
 /// Standard form processing if statement.
 if ($requestform->is_cancelled()){
     redirect($returnurl);
 
 } else if ($data = $requestform->get_data()) {
-    $PAGE->set_title($strtitle);
-    $PAGE->set_heading($strtitle);
-    $PAGE->navbar->add($strtitle);
-    $PAGE->set_focuscontrol($requestform->focus());
-    echo $OUTPUT->header();
-    echo $OUTPUT->heading($strtitle);
+    $request = course_request::create($data);
 
-/// Record the request.
-    $data->requester = $USER->id;
-    $DB->insert_record('course_request', $data);
-
-/// Notify the admin if required.
-    if ($CFG->courserequestnotify) {
-        $users = get_users_from_config($CFG->courserequestnotify, 'moodle/site:approvecourse');
-        foreach ($users as $user) {
-            $eventdata = new object();
-            $eventdata->modulename        = 'moodle';
-            $eventdata->component         = 'course';
-            $eventdata->name              = 'courserequested';
-            $eventdata->userfrom          = $USER;
-            $eventdata->userto            = $user;
-            $eventdata->subject = get_string('courserequest');
-            $a = new object();
-            $a->link = "$CFG->wwwroot/course/pending.php";
-            $a->user = fullname($USER);
-            $eventdata->fullmessage = get_string('courserequestnotifyemail', 'admin', $a);
-            $eventdata->fullmessageformat = FORMAT_PLAIN;
-            $eventdata->fullmessagehtml   = '';
-            $eventdata->smallmessage      = '';
-            events_trigger('message_send', $eventdata);
-        }
-    }
-
-/// and redirect back to the course listing.
+    // and redirect back to the course listing.
     notice(get_string('courserequestsuccess'), $returnurl);
 }
 
-/// Show the request form.
-
-$PAGE->set_title($strtitle);
-$PAGE->set_heading($strtitle);
 $PAGE->navbar->add($strtitle);
-$PAGE->set_focuscontrol($requestform->focus());
 echo $OUTPUT->header();
 echo $OUTPUT->heading($strtitle);
+// Show the request form.
 $requestform->display();
 echo $OUTPUT->footer();
-
-?>
\ No newline at end of file
Index: moodle/course/request_form.php
--- moodle/course/request_form.php Base (1.18)
+++ moodle/course/request_form.php Locally Modified (Based On 1.18)
@@ -1,4 +1,4 @@
-<?php  // $Id: request_form.php,v 1.18 2009/09/26 17:07:09 skodak Exp $
+<?php
 
 ///////////////////////////////////////////////////////////////////////////
 //                                                                       //
@@ -29,7 +29,7 @@
  *
  * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  * @package course
- *//** */
+ */
 
 require_once($CFG->libdir.'/formslib.php');
 
@@ -64,9 +64,9 @@
         $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
         $mform->setType('shortname', PARAM_MULTILANG);
 
-        $mform->addElement('htmleditor', 'summary', get_string('summary'), array('rows'=>'15', 'cols'=>'50'));
-        $mform->setHelpButton('summary', array('text2', get_string('helptext')), true);
-        $mform->setType('summary', PARAM_RAW);
+        $mform->addElement('editor', 'summary_editor', get_string('summary'), null, course_request::summary_editor_options());
+        $mform->setHelpButton('summary_editor', array('text2', get_string('helptext')), true);
+        $mform->setType('summary_editor', PARAM_RAW);
 
         $mform->addElement('passwordunmask', 'password', get_string('enrolmentkey'), 'size="25"');
         $mform->setHelpButton('password', array('enrolmentkey', get_string('enrolmentkey')), true);
Index: moodle/course/search.php
--- moodle/course/search.php Base (1.85)
+++ moodle/course/search.php Locally Modified (Based On 1.85)
@@ -227,6 +227,13 @@
 
         if (!$adminediting) {
             foreach ($courses as $course) {
+
+                if (isset($course->context)) {
+                    $coursecontext = $course->context;
+                } else {
+                    $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+                }
+
                 $course->summary .= "<br /><p class=\"category\">";
                 $course->summary .= "$strcategory: <a href=\"category.php?id=$course->category\">";
                 $course->summary .= $displaylist[$course->category];
Index: moodle/lib/db/install.xml
--- moodle/lib/db/install.xml Base (1.217)
+++ moodle/lib/db/install.xml Locally Modified (Based On 1.217)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="lib/db" VERSION="20091006" COMMENT="XMLDB file for core Moodle tables"
+<XMLDB PATH="lib/db" VERSION="20091020" COMMENT="XMLDB file for core Moodle tables"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
 >
@@ -75,8 +75,10 @@
         <FIELD NAME="fullname" TYPE="char" LENGTH="254" NOTNULL="true" SEQUENCE="false" PREVIOUS="password" NEXT="shortname"/>
         <FIELD NAME="shortname" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" PREVIOUS="fullname" NEXT="idnumber"/>
         <FIELD NAME="idnumber" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" PREVIOUS="shortname" NEXT="summary"/>
-        <FIELD NAME="summary" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="idnumber" NEXT="format"/>
-        <FIELD NAME="format" TYPE="char" LENGTH="10" NOTNULL="true" DEFAULT="topics" SEQUENCE="false" PREVIOUS="summary" NEXT="showgrades"/>
+        <FIELD NAME="summary" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="idnumber" NEXT="summaryformat"/>
+        <FIELD NAME="summaryformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="summary" NEXT="summarytrust"/>
+        <FIELD NAME="summarytrust" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="summaryformat" NEXT="format"/>
+        <FIELD NAME="format" TYPE="char" LENGTH="10" NOTNULL="true" DEFAULT="topics" SEQUENCE="false" PREVIOUS="summarytrust" NEXT="showgrades"/>
         <FIELD NAME="showgrades" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="format" NEXT="modinfo"/>
         <FIELD NAME="modinfo" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false" PREVIOUS="showgrades" NEXT="newsitems"/>
         <FIELD NAME="newsitems" TYPE="int" LENGTH="5" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="modinfo" NEXT="guest"/>
@@ -124,8 +126,10 @@
       <FIELDS>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="name"/>
         <FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="id" NEXT="description"/>
-        <FIELD NAME="description" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="name" NEXT="parent"/>
-        <FIELD NAME="parent" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="description" NEXT="sortorder"/>
+        <FIELD NAME="description" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="name" NEXT="descriptionformat"/>
+        <FIELD NAME="descriptionformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="description" NEXT="descriptiontrust"/>
+        <FIELD NAME="descriptiontrust" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="descriptionformat" NEXT="parent"/>
+        <FIELD NAME="parent" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="descriptiontrust" NEXT="sortorder"/>
         <FIELD NAME="sortorder" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="parent" NEXT="coursecount"/>
         <FIELD NAME="coursecount" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="sortorder" NEXT="visible"/>
         <FIELD NAME="visible" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="false" DEFAULT="1" SEQUENCE="false" PREVIOUS="coursecount" NEXT="timemodified"/>
@@ -258,8 +262,10 @@
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="fullname"/>
         <FIELD NAME="fullname" TYPE="char" LENGTH="254" NOTNULL="true" SEQUENCE="false" PREVIOUS="id" NEXT="shortname"/>
         <FIELD NAME="shortname" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" PREVIOUS="fullname" NEXT="summary"/>
-        <FIELD NAME="summary" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" PREVIOUS="shortname" NEXT="reason"/>
-        <FIELD NAME="reason" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" PREVIOUS="summary" NEXT="requester"/>
+        <FIELD NAME="summary" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" PREVIOUS="shortname" NEXT="summaryformat"/>
+        <FIELD NAME="summaryformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="summary" NEXT="summarytrust"/>
+        <FIELD NAME="summarytrust" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="summaryformat" NEXT="reason"/>
+        <FIELD NAME="reason" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" PREVIOUS="summarytrust" NEXT="requester"/>
         <FIELD NAME="requester" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="reason" NEXT="password"/>
         <FIELD NAME="password" TYPE="char" LENGTH="50" NOTNULL="true" SEQUENCE="false" PREVIOUS="requester"/>
       </FIELDS>
@@ -589,8 +595,10 @@
         <FIELD NAME="secret" TYPE="char" LENGTH="15" NOTNULL="true" SEQUENCE="false" PREVIOUS="lastip" NEXT="picture"/>
         <FIELD NAME="picture" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="secret" NEXT="url"/>
         <FIELD NAME="url" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="picture" NEXT="description"/>
-        <FIELD NAME="description" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="url" NEXT="mailformat"/>
-        <FIELD NAME="mailformat" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="description" NEXT="maildigest"/>
\ No newline at end of file
+        <FIELD NAME="description" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="url" NEXT="descriptionformat"/>
+        <FIELD NAME="descriptionformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="description" NEXT="descriptiontrust"/>
+        <FIELD NAME="descriptiontrust" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="descriptionformat" NEXT="mailformat"/>
+        <FIELD NAME="mailformat" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="descriptiontrust" NEXT="maildigest"/>
\ No newline at end of file
         <FIELD NAME="maildigest" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="mailformat" NEXT="maildisplay"/>
         <FIELD NAME="maildisplay" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="2" SEQUENCE="false" PREVIOUS="maildigest" NEXT="htmleditor"/>
         <FIELD NAME="htmleditor" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="maildisplay" NEXT="ajax"/>
Index: moodle/lib/db/upgrade.php
--- moodle/lib/db/upgrade.php Base (1.338)
+++ moodle/lib/db/upgrade.php Locally Modified (Based On 1.338)
@@ -2598,6 +2598,32 @@
         upgrade_main_savepoint($result, 2009100605);
     }
 
+    if ($result && $oldversion < 2009102100) {
+
+        // An array used to store the table name and keys of summary and trust fields
+        // to be added
+        $extendtables = array();
+        $extendtables['course'] = array('summaryformat', 'summarytrust');
+        $extendtables['course_categories'] = array('descriptionformat', 'descriptiontrust');
+        $extendtables['course_request'] = array('summaryformat', 'summarytrust');
+        $extendtables['user'] = array('descriptionformat', 'descriptiontrust');
+        
+
+        foreach ($extendtables as $table=>$newfields) {
+            $table = new xmldb_table($table);
+            foreach ($newfields as $field) {
+                $field = new xmldb_field($field, XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+                if (!$dbman->field_exists($table, $field)) {
+                    $dbman->add_field($table, $field);
+                }
+            }
+        }
+
+        unset($extendtables);
+
+        upgrade_main_savepoint($result, 2009102100);
+    }
+
     return $result;
 }
 
Index: moodle/lib/file/file_browser.php
--- moodle/lib/file/file_browser.php Base (1.22)
+++ moodle/lib/file/file_browser.php Locally Modified (Based On 1.22)
@@ -288,7 +288,7 @@
             return null;
         }
 
-        if (!is_null($filearea) and !in_array($filearea, array('course_intro', 'course_content', 'course_section', 'course_backup'))) {
+        if (!is_null($filearea) and !in_array($filearea, array('course_intro', 'course_content', 'course_section', 'course_backup', 'course_summary'))) {
             // file area does not exist, sorry
             $filearea = null;
         }
Index: moodle/pluginfile.php
--- moodle/pluginfile.php Base (1.16)
+++ moodle/pluginfile.php Locally Modified (Based On 1.16)
@@ -102,7 +102,21 @@
         }
 
         send_stored_file($file, 10*60, 0, true); // download MUST be forced - security!
+    } else if ($filearea === 'course_request_summary') {
 
+        if ($CFG->forcelogin) {
+            require_login();
+        }
+
+        $fullpath = $context->id.$filearea.implode('/', $args);
+
+        if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
+            send_file_not_found();
+        }
+
+        session_get_instance()->write_close(); // unlock session during fileserving
+        send_stored_file($file, 60*60, 0, false); // TODO: change timeout?
+        
     } else {
         send_file_not_found();
     }
Index: moodle/user/edit.php
--- moodle/user/edit.php Base (1.196)
+++ moodle/user/edit.php Locally Modified (Based On 1.196)
@@ -129,8 +129,10 @@
 profile_load_data($user);
 
 
-//create form
-$userform = new user_edit_form();
+// Prepare the editor and create form
+$editoroptions = array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>false, 'forcehttps'=>false);
+$user = file_prepare_standard_editor($user, 'description', $editoroptions, $personalcontext, 'user_profile', $user->id);
+$userform = new user_edit_form(null, array('editoroptions'=>$editoroptions));
 if (empty($user->country)) {
     // MDL-16308 - we must unset the value here so $CFG->country can be used as default one
     unset($user->country);
@@ -236,14 +238,6 @@
 $strparticipants  = get_string('participants');
 $userfullname     = fullname($user, true);
 
-$link = null;
-if (has_capability('moodle/course:viewparticipants', $coursecontext) || has_capability('moodle/site:viewparticipants', $systemcontext)) {
-    $link = new moodle_url($CFG->wwwroot."/user/index.php", array('id'=>$course->id));
-}
-$PAGE->navbar->add($strparticipants, $link);
-$link = new moodle_url($CFG->wwwroot.'/user/view.php', array('id'=>$user->id, 'course'=>$course->id));
-$PAGE->navbar->add($userfullname, $link);
-$PAGE->navbar->add($streditmyprofile);
\ No newline at end of file
 $PAGE->set_title("$course->shortname: $streditmyprofile");
 $PAGE->set_heading($course->fullname);
 
Index: moodle/user/edit_form.php
--- moodle/user/edit_form.php Base (1.39)
+++ moodle/user/edit_form.php Locally Modified (Based On 1.39)
@@ -9,6 +9,11 @@
         global $CFG, $COURSE;
 
         $mform =& $this->_form;
+        if (array_key_exists('editoroptions', $this->_customdata)) {
+            $editoroptions = $this->_customdata['editoroptions'];
+        } else {
+            $editoroptions = null;
+        }
         //Accessibility: "Required" is bad legend text.
         $strgeneral  = get_string('general');
         $strrequired = get_string('required');
@@ -23,10 +28,10 @@
         $mform->addElement('header', 'moodle', $strgeneral);
 
         /// shared fields
-        useredit_shared_definition($mform);
+        useredit_shared_definition($mform, $editoroptions);
 
         /// extra settigs
-        $mform->addRule('description', $strrequired, 'required', null, 'client');
+        $mform->addRule('description_editor', $strrequired, 'required', null, 'client');
         if (!empty($CFG->gdversion) and !empty($CFG->disableuserimages)) {
             $mform->removeElement('deletepicture');
             $mform->removeElement('imagefile');
@@ -67,7 +72,7 @@
 
             // remove description
             if (empty($user->description) && !empty($CFG->profilesforenrolledusersonly) && !$DB->record_exists('role_assignments', array('userid'=>$userid))) {
-                $mform->removeElement('description');
+                $mform->removeElement('description_editor');
             }
 
             // print picture
Index: moodle/user/editadvanced.php
--- moodle/user/editadvanced.php Base (1.60)
+++ moodle/user/editadvanced.php Locally Modified (Based On 1.60)
@@ -113,8 +113,17 @@
     $user->interests = tag_get_tags_array('user', $id);
 }
 
+if ($user->id !== -1) {
+    $user->context = get_context_instance(CONTEXT_USER, $user->id);
+    $editoroptions = array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>false, 'forcehttps'=>false);
+    $user = file_prepare_standard_editor($user, 'description', $editoroptions, $user->context, 'user_profile', $user->id);
+} else {
+    // This is a new user, we don't want to add files here
+    $editoroptions = array('maxfiles'=>0, 'maxbytes'=>0, 'trusttext'=>false, 'forcehttps'=>false);
+}
+
 //create form
-$userform = new user_editadvanced_form();
+$userform = new user_editadvanced_form(null, array('editoroptions'=>$editoroptions));
 $userform->set_data($user);
 
 if ($usernew = $userform->get_data()) {
@@ -134,6 +143,7 @@
     if ($usernew->id == -1) {
         //TODO check out if it makes sense to create account with this auth plugin and what to do with the password
         unset($usernew->id);
+        $usernew = file_postupdate_standard_editor($usernew, 'description', $editoroptions, null, 'user_profile', null);
         $usernew->mnethostid = $CFG->mnet_localhost_id; // always local user
         $usernew->confirmed  = 1;
         $usernew->password = hash_internal_user_password($usernew->newpassword);
@@ -141,6 +151,7 @@
         $usercreated = true;
 
     } else {
+        $usernew = file_postupdate_standard_editor($usernew, 'description', $editoroptions, $user->context, 'user_profile', $usernew->id);
\ No newline at end of file
         $DB->update_record('user', $usernew);
         // pass a true $userold here
         if (! $authplugin->user_update($user, $userform->get_data())) {
Index: moodle/user/editadvanced_form.php
--- moodle/user/editadvanced_form.php Base (1.33)
+++ moodle/user/editadvanced_form.php Locally Modified (Based On 1.33)
@@ -9,6 +9,7 @@
         global $USER, $CFG, $COURSE;
 
         $mform =& $this->_form;
+        $editoroptions = $this->_customdata['editoroptions'];
         //Accessibility: "Required" is bad legend text.
         $strgeneral  = get_string('general');
         $strrequired = get_string('required');
@@ -42,7 +43,7 @@
         $mform->addElement('advcheckbox', 'preference_auth_forcepasswordchange', get_string('forcepasswordchange'));
         $mform->setHelpButton('preference_auth_forcepasswordchange',array('forcepasswordchange', get_string('forcepasswordchange')));
         /// shared fields
-        useredit_shared_definition($mform);
+        useredit_shared_definition($mform, $editoroptions);
 
         /// Next the customisable profile fields
         profile_definition($mform);
Index: moodle/user/editlib.php
--- moodle/user/editlib.php Base (1.30)
+++ moodle/user/editlib.php Locally Modified (Based On 1.30)
@@ -1,4 +1,4 @@
-<?php  //$Id: editlib.php,v 1.30 2009/06/11 03:34:50 jerome Exp $
+<?php
 
 function cancel_email_update($userid) {
     unset_user_preference('newemail', $userid);
@@ -74,7 +74,7 @@
     tag_set('user', $user->id, $interests);
 }
 
-function useredit_shared_definition(&$mform) {
+function useredit_shared_definition(&$mform, $editoroptions = null) {
     global $CFG, $USER, $DB;
 
     $user = $DB->get_record('user', array('id' => $USER->id));
@@ -228,10 +228,14 @@
         $mform->setAdvanced('theme');
     }
 
-    $mform->addElement('htmleditor', 'description', get_string('userdescription'));
-    $mform->setType('description', PARAM_CLEAN);
-    $mform->setHelpButton('description', array('text2', get_string('helptext')));
+    if ($editoroptions === null) {
+        $editoroptions = array('maxfiles'=>0, 'maxbytes'=>0, 'trusttext'=>false, 'forcehttps'=>false);
+    }
 
+    $mform->addElement('editor', 'description_editor', get_string('userdescription'), null, $editoroptions);
+    $mform->setType('description_editor', PARAM_CLEAN);
+    $mform->setHelpButton('description_editor', array('text2', get_string('helptext')));
+
     if (!empty($CFG->gdversion)) {
         $mform->addElement('header', 'moodle_picture', get_string('pictureof'));//TODO: Accessibility fix fieldset legend
 
Index: moodle/version.php
--- moodle/version.php Base (1.1290)
+++ moodle/version.php Locally Modified (Based On 1.1290)
@@ -6,7 +6,7 @@
 // This is compared against the values stored in the database to determine
 // whether upgrades should be performed (see lib/db/*.php)
 
-    $version = 2009100605;  // YYYYMMDD   = date of the last version bump
+    $version = 2009102100;  // YYYYMMDD   = date of the last version bump
                             //         XX = daily increments
 
     $release = '2.0 dev (Build: 20091020)';  // Human-friendly version name
