MDL-28666 Extends repository to support references

1. Allow repository to create references to external contents
2. Extends files API to handle file references
3. Generic file caching
4. Backup/restore file references
5. Download external contents if repository uninstalled
6. Allow filepicker to display iframe
7. PHPUnit test suits
This commit is contained in:
Dongsheng Cai
2012-05-21 11:57:51 +08:00
committed by Marina Glancy
parent 4f7f2a8828
commit 6723372514
61 changed files with 3112 additions and 697 deletions
+63 -30
View File
@@ -1,18 +1,35 @@
<?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/>.
require_once(dirname(dirname(__FILE__)) . '/config.php');
require_once($CFG->dirroot . '/repository/lib.php');
require_once($CFG->libdir . '/adminlib.php');
require_sesskey();
// id of repository
$edit = optional_param('edit', 0, PARAM_INT);
$new = optional_param('new', '', PARAM_FORMAT);
$new = optional_param('new', '', PARAM_PLUGIN);
$hide = optional_param('hide', 0, PARAM_INT);
$delete = optional_param('delete', 0, PARAM_INT);
$sure = optional_param('sure', '', PARAM_ALPHA);
$type = optional_param('type', '', PARAM_PLUGIN);
$downloadcontents = optional_param('downloadcontents', '', PARAM_ALPHA);
$context = get_context_instance(CONTEXT_SYSTEM);
$context = context_system::instance();
$pagename = 'repositorycontroller';
@@ -25,15 +42,19 @@ if ($edit){
}
admin_externalpage_setup($pagename);
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
require_capability('moodle/site:config', $context);
$baseurl = new moodle_url("/$CFG->admin/repositoryinstance.php", array('sesskey'=>sesskey()));
$parenturl = new moodle_url("/$CFG->admin/repository.php", array(
'sesskey'=>sesskey(),
'action'=>'edit',
));
$sesskeyurl = "$CFG->wwwroot/$CFG->admin/repositoryinstance.php?sesskey=" . sesskey();
$baseurl = "$CFG->wwwroot/$CFG->admin/repository.php?session=". sesskey() .'&action=edit&repos=';
if ($new) {
$baseurl .= $new;
}
else {
$baseurl .= $type;
$parenturl->param('repos', $new);
} else {
$parenturl->param('repos', $type);
}
$return = true;
@@ -48,7 +69,7 @@ if (!empty($edit) || !empty($new)) {
$typeid = $instance->options['typeid'];
} else {
$plugin = $new;
$typeid = $new;
$typeid = null;
$instance = null;
}
@@ -57,12 +78,9 @@ if (!empty($edit) || !empty($new)) {
// end setup, begin output
if ($mform->is_cancelled()){
redirect($baseurl);
redirect($parenturl);
exit;
} else if ($fromform = $mform->get_data()){
if (!confirm_sesskey()) {
print_error('confirmsesskeybad', '', $baseurl);
}
if ($edit) {
$settings = array();
$settings['name'] = $fromform->name;
@@ -77,13 +95,13 @@ if (!empty($edit) || !empty($new)) {
}
$success = $instance->set_option($settings);
} else {
$success = repository::static_function($plugin, 'create', $plugin, 0, get_system_context(), $fromform);
$success = repository::static_function($plugin, 'create', $plugin, 0, $context, $fromform);
$data = data_submitted();
}
if ($success) {
redirect($baseurl);
redirect($parenturl);
} else {
print_error('instancenotsaved', 'repository', $baseurl);
print_error('instancenotsaved', 'repository', $parenturl);
}
exit;
} else {
@@ -95,9 +113,6 @@ if (!empty($edit) || !empty($new)) {
$return = false;
}
} else if (!empty($hide)) {
if (!confirm_sesskey()) {
print_error('confirmsesskeybad', '', $baseurl);
}
$instance = repository::get_type_by_typename($hide);
$instance->hide();
$return = true;
@@ -108,25 +123,43 @@ if (!empty($edit) || !empty($new)) {
throw new repository_exception('readonlyinstance', 'repository');
}
if ($sure) {
if (!confirm_sesskey()) {
print_error('confirmsesskeybad', '', $baseurl);
}
if ($instance->delete()) {
$deletedstr = get_string('instancedeleted', 'repository');
redirect($baseurl, $deletedstr, 3);
if (!empty($downloadcontents) and $downloadcontents == 'yes') {
$downloadcontents = true;
} else {
print_error('instancenotdeleted', 'repository', $baseurl);
$downloadcontents = false;
}
if ($instance->delete($downloadcontents)) {
$deletedstr = get_string('instancedeleted', 'repository');
redirect($parenturl, $deletedstr, 3);
} else {
print_error('instancenotdeleted', 'repository', $parenturl);
}
exit;
}
echo $OUTPUT->header();
echo $OUTPUT->confirm(get_string('confirmdelete', 'repository', $instance->name), "$sesskeyurl&type=$type'&delete=$delete'&sure=yes", "$CFG->wwwroot/$CFG->admin/repositoryinstance.php?session=". sesskey());
echo $OUTPUT->box_start('generalbox', 'notice');
$continueurl = new moodle_url($baseurl, array(
'type' => $type,
'delete' => $delete,
'sure' => 'yes',
));
$continueanddownloadurl = new moodle_url($continueurl, array(
'downloadcontents' => 'yes'
));
$message = get_string('confirmdelete', 'repository', $instance->name);
echo html_writer::tag('p', $message);
echo $OUTPUT->single_button($continueurl, get_string('continueuninstall', 'repository'));
echo $OUTPUT->single_button($continueanddownloadurl, get_string('continueuninstallanddownload', 'repository'));
echo $OUTPUT->single_button($parenturl, get_string('cancel'));
echo $OUTPUT->box_end();
$return = false;
}
if (!empty($return)) {
redirect($baseurl);
redirect($parenturl);
}
echo $OUTPUT->footer();