Skip to content

Commit

Permalink
Merge branch 'MDL-74466' of https://github.com/paulholden/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
HuongNV13 committed Dec 13, 2023
2 parents ffe51e3 + 70323bc commit 9493b23
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 66 deletions.
75 changes: 32 additions & 43 deletions admin/repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,11 @@

admin_externalpage_setup($pagename);

$sesskeyurl = $CFG->wwwroot.'/'.$CFG->admin.'/repository.php?sesskey=' . sesskey();
$baseurl = $CFG->wwwroot.'/'.$CFG->admin.'/repository.php';

$configstr = get_string('manage', 'repository');
// The URL used for redirection, and that all edit related URLs will be based off.
$baseurl = new moodle_url('/admin/repository.php');

$return = true;

if (!empty($action)) {
require_sesskey();
}

/**
* Helper function that generates a moodle_url object
* relevant to the repository
*/
function repository_action_url($repository) {
global $baseurl;
return new moodle_url($baseurl, array('sesskey'=>sesskey(), 'repos'=>$repository));
}

if (($action == 'edit') || ($action == 'new')) {
$pluginname = '';
if ($action == 'edit') {
Expand Down Expand Up @@ -182,26 +167,20 @@ function repository_action_url($repository) {
}
}
} else if ($action == 'show') {
if (!confirm_sesskey()) {
throw new \moodle_exception('confirmsesskeybad', '', $baseurl);
}
require_sesskey();
$class = \core_plugin_manager::resolve_plugininfo_class('repository');
$class::enable_plugin($repository, 1);
$return = true;
} else if ($action == 'hide') {
if (!confirm_sesskey()) {
throw new \moodle_exception('confirmsesskeybad', '', $baseurl);
}
require_sesskey();
$class = \core_plugin_manager::resolve_plugininfo_class('repository');
$class::enable_plugin($repository, 0);
$return = true;
} else if ($action == 'delete') {
$repositorytype = repository::get_type_by_typename($repository);
if ($sure) {
$PAGE->set_pagetype('admin-repository-' . $repository);
if (!confirm_sesskey()) {
throw new \moodle_exception('confirmsesskeybad', '', $baseurl);
}
require_sesskey();

if ($repositorytype->delete($downloadcontents)) {
// Include this information into config changes table.
Expand All @@ -220,20 +199,15 @@ function repository_action_url($repository) {
$output = $OUTPUT->box_start('generalbox', 'notice');
$output .= html_writer::tag('p', $message);

$removeurl = new moodle_url($sesskeyurl);
$removeurl->params(array(
$removeurl = new moodle_url($baseurl, [
'action' =>'delete',
'repos' => $repository,
'sure' => 'yes',
));
]);

$removeanddownloadurl = new moodle_url($sesskeyurl);
$removeanddownloadurl->params(array(
'action' =>'delete',
'repos'=> $repository,
'sure' => 'yes',
$removeanddownloadurl = new moodle_url($removeurl, [
'downloadcontents' => 1,
));
]);

$output .= $OUTPUT->single_button($removeurl, get_string('continueuninstall', 'repository'));
$output .= $OUTPUT->single_button($removeanddownloadurl, get_string('continueuninstallanddownload', 'repository'));
Expand All @@ -245,9 +219,11 @@ function repository_action_url($repository) {
$return = false;
}
} else if ($action == 'moveup') {
require_sesskey();
$repositorytype = repository::get_type_by_typename($repository);
$repositorytype->move_order('up');
} else if ($action == 'movedown') {
require_sesskey();
$repositorytype = repository::get_type_by_typename($repository);
$repositorytype->move_order('down');
} else {
Expand Down Expand Up @@ -339,8 +315,7 @@ function repository_action_url($repository) {
$userinstancenumbertext = "";
}

$settings .= '<a href="' . $sesskeyurl . '&amp;action=edit&amp;repos=' . $typename . '">' . $settingsstr .'</a>';

$settings = html_writer::link(new moodle_url($baseurl, ['action' => 'edit', 'repos' => $typename]), $settingsstr);
$settings .= $OUTPUT->container_start('mdl-left');
$settings .= '<br/>';
$settings .= $admininstancenumbertext;
Expand All @@ -357,22 +332,34 @@ function repository_action_url($repository) {
$currentaction = 'hide';
}

$select = new single_select(repository_action_url($typename, 'repos'), 'action', $actionchoicesforexisting, $currentaction, null, 'applyto' . basename($typename));
// Active toggle.
$selectaction = new moodle_url($baseurl, ['sesskey' => sesskey(), 'repos' => $typename]);
$select = new single_select($selectaction, 'action', $actionchoicesforexisting, $currentaction, null,
'applyto' . basename($typename));
$select->set_label(get_string('action'), array('class' => 'accesshide'));

// Display up/down link
$updown = '';
$spacer = $OUTPUT->spacer(array('height'=>15, 'width'=>15)); // should be done with CSS instead

if ($updowncount > 1) {
$updown .= "<a href=\"$sesskeyurl&amp;action=moveup&amp;repos=".$typename."\">";
$updown .= $OUTPUT->pix_icon('t/up', get_string('moveup')) . "</a>&nbsp;";
$moveupaction = new moodle_url($baseurl, [
'sesskey' => sesskey(),
'action' => 'moveup',
'repos' => $typename,
]);
$updown .= html_writer::link($moveupaction, $OUTPUT->pix_icon('t/up', get_string('moveup'))) . '&nbsp;';
}
else {
$updown .= $spacer;
}
if ($updowncount < $totalrepositorytypes) {
$updown .= "<a href=\"$sesskeyurl&amp;action=movedown&amp;repos=".$typename."\">";
$updown .= $OUTPUT->pix_icon('t/down', get_string('movedown')) . "</a>&nbsp;";
$movedownaction = new moodle_url($baseurl, [
'sesskey' => sesskey(),
'action' => 'movedown',
'repos' => $typename,
]);
$updown .= html_writer::link($movedownaction, $OUTPUT->pix_icon('t/down', get_string('movedown'))) . '&nbsp;';
}
else {
$updown .= $spacer;
Expand Down Expand Up @@ -400,7 +387,9 @@ function repository_action_url($repository) {
foreach ($plugins as $plugin => $dir) {
// Check that it has not already been listed
if (!in_array($plugin, $alreadyplugins)) {
$select = new single_select(repository_action_url($plugin, 'repos'), 'action', $actionchoicesfornew, 'delete', null, 'applyto' . basename($plugin));
$selectaction = new moodle_url($baseurl, ['sesskey' => sesskey(), 'repos' => $plugin]);
$select = new single_select($selectaction, 'action', $actionchoicesfornew, 'delete', null,
'applyto' . basename($plugin));
$select->set_label(get_string('action'), array('class' => 'accesshide'));
$uninstall = '';
if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url('repository_' . $plugin, 'manage')) {
Expand Down
19 changes: 9 additions & 10 deletions admin/repositoryinstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
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_PLUGIN);
Expand All @@ -43,12 +41,8 @@

admin_externalpage_setup($pagename, '', null, new moodle_url('/admin/repositoryinstance.php'));

$baseurl = new moodle_url("/$CFG->admin/repositoryinstance.php", array('sesskey'=>sesskey()));

$parenturl = new moodle_url("/$CFG->admin/repository.php", array(
'sesskey'=>sesskey(),
'action'=>'edit',
));
// The URL used for redirection, and that all edit related URLs will be based off.
$parenturl = new moodle_url('/admin/repository.php', ['action' => 'edit']);

if ($new) {
$parenturl->param('repos', $new);
Expand Down Expand Up @@ -116,6 +110,7 @@
$return = false;
}
} else if (!empty($hide)) {
require_sesskey();
$instance = repository::get_type_by_typename($hide);
$instance->hide();
core_plugin_manager::reset_caches();
Expand All @@ -129,6 +124,7 @@
throw new repository_exception('nopermissiontoaccess', 'repository');
}
if ($sure) {
require_sesskey();
if ($instance->delete($downloadcontents)) {
$deletedstr = get_string('instancedeleted', 'repository');
core_plugin_manager::reset_caches();
Expand All @@ -141,14 +137,17 @@

echo $OUTPUT->header();
echo $OUTPUT->box_start('generalbox', 'notice');
$continueurl = new moodle_url($baseurl, array(

$continueurl = new moodle_url($PAGE->url, [
'type' => $type,
'delete' => $delete,
'sure' => 'yes',
));
]);

$continueanddownloadurl = new moodle_url($continueurl, array(
'downloadcontents' => 1
));

$message = get_string('confirmdelete', 'repository', $instance->name);
echo html_writer::tag('p', $message);

Expand Down
4 changes: 1 addition & 3 deletions lib/classes/plugininfo/repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,8 @@ public function load_settings(part_of_admin_tree $adminroot, $parentnodename, $h
if ($hassiteconfig && $this->is_enabled()) {
// Completely no access to repository setting when it is not enabled.
$sectionname = $this->get_settings_section_name();
$settingsurl = new moodle_url('/admin/repository.php',
array('sesskey' => sesskey(), 'action' => 'edit', 'repos' => $this->name));
$settings = new admin_externalpage($sectionname, $this->displayname,
$settingsurl, 'moodle/site:config', false);
new moodle_url('/admin/repository.php', ['action' => 'edit', 'repos' => $this->name]), 'moodle/site:config', false);
$adminroot->add($parentnodename, $settings);
}
}
Expand Down
4 changes: 2 additions & 2 deletions repository/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1497,10 +1497,10 @@ public static function display_instances_list($context, $typename = null) {
//if the context is SYSTEM, so we call it from administration page
$admin = ($context->id == SYSCONTEXTID) ? true : false;
if ($admin) {
$baseurl = new moodle_url('/'.$CFG->admin.'/repositoryinstance.php', array('sesskey'=>sesskey()));
$baseurl = new moodle_url('/admin/repositoryinstance.php');
$output .= $OUTPUT->heading(get_string('siteinstances', 'repository'));
} else {
$baseurl = new moodle_url('/repository/manage_instances.php', array('contextid'=>$context->id, 'sesskey'=>sesskey()));
$baseurl = new moodle_url('/repository/manage_instances.php', ['contextid' => $context->id]);
}

$namestr = get_string('name');
Expand Down
9 changes: 1 addition & 8 deletions repository/manage_instances.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@
$usercourseid = optional_param('usercourseid', SITEID, PARAM_INT); // Extra: used for user context only

$url = new moodle_url('/repository/manage_instances.php');

$baseurl = new moodle_url('/repository/manage_instances.php');
$baseurl->param('sesskey', sesskey());

if ($edit){
$url->param('edit', $edit);
Expand Down Expand Up @@ -168,9 +166,6 @@
exit;

} else if ($fromform = $mform->get_data()){
if (!confirm_sesskey()) {
throw new \moodle_exception('confirmsesskeybad', '', $baseurl);
}
if ($edit) {
$settings = array();
$settings['name'] = $fromform->name;
Expand Down Expand Up @@ -199,9 +194,7 @@
}
} else if (!empty($delete)) {
if ($sure) {
if (!confirm_sesskey()) {
throw new \moodle_exception('confirmsesskeybad', '', $baseurl);
}
require_sesskey();
if ($instance->delete()) {
$deletedstr = get_string('instancedeleted', 'repository');
redirect($baseurl, $deletedstr, 3);
Expand Down

0 comments on commit 9493b23

Please sign in to comment.