first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,75 @@
<?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/>.
/**
* Defines backup_wiki_activity_task class
*
* @package mod_wiki
* @category backup
* @copyright 2010 Jordi Piguillem <pigui0@hotmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/wiki/backup/moodle2/backup_wiki_stepslib.php');
require_once($CFG->dirroot . '/mod/wiki/backup/moodle2/backup_wiki_settingslib.php');
/**
* Provides all the settings and steps to perform one complete backup of the activity
*/
class backup_wiki_activity_task extends backup_activity_task {
/**
* No specific settings for this activity
*/
protected function define_my_settings() {
}
/**
* Defines a backup step to store the instance data in the wiki.xml file
*/
protected function define_my_steps() {
$this->add_step(new backup_wiki_activity_structure_step('wiki_structure', 'wiki.xml'));
}
/**
* Encodes URLs to the index.php and view.php scripts
*
* @param string $content some HTML text that eventually contains URLs to the activity instance scripts
* @return string the content with the URLs encoded
*/
public static function encode_content_links($content) {
global $CFG;
$base = preg_quote($CFG->wwwroot, "/");
// Link to the list of wikis
$search = "/(" . $base . "\/mod\/wiki\/index.php\?id\=)([0-9]+)/";
$content = preg_replace($search, '$@WIKIINDEX*$2@$', $content);
// Link to wiki view by moduleid
$search = "/(" . $base . "\/mod\/wiki\/view.php\?id\=)([0-9]+)/";
$content = preg_replace($search, '$@WIKIVIEWBYID*$2@$', $content);
// Link to wiki view by pageid
$search = "/(" . $base . "\/mod\/wiki\/view.php\?pageid\=)([0-9]+)/";
$content = preg_replace($search, '$@WIKIPAGEBYID*$2@$', $content);
return $content;
}
}
@@ -0,0 +1,27 @@
<?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/>.
/**
* @package mod_wiki
* @subpackage backup-moodle2
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// This activity has not particular settings but the inherited from the generic
// backup_activity_task so here there isn't any class definition, like the ones
// existing in /backup/moodle2/backup_settingslib.php (activities section)
@@ -0,0 +1,131 @@
<?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/>.
/**
* @package mod_wiki
* @subpackage backup-moodle2
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Define all the backup steps that will be used by the backup_wiki_activity_task
*/
/**
* Define the complete wiki structure for backup, with file and id annotations
*/
class backup_wiki_activity_structure_step extends backup_activity_structure_step {
protected function define_structure() {
// To know if we are including userinfo
$userinfo = $this->get_setting_value('userinfo');
// Define each element separated
$wiki = new backup_nested_element('wiki', array('id'), array('name', 'intro', 'introformat', 'timecreated', 'timemodified', 'firstpagetitle', 'wikimode', 'defaultformat', 'forceformat', 'editbegin', 'editend'));
$subwikis = new backup_nested_element('subwikis');
$subwiki = new backup_nested_element('subwiki', array('id'), array('groupid', 'userid'));
$pages = new backup_nested_element('pages');
$page = new backup_nested_element('page', array('id'), array('title', 'cachedcontent', 'timecreated', 'timemodified', 'timerendered', 'userid', 'pageviews', 'readonly'));
$synonyms = new backup_nested_element('synonyms');
$synonym = new backup_nested_element('synonym', array('id'), array('pageid', 'pagesynonym'));
$links = new backup_nested_element('links');
$link = new backup_nested_element('link', array('id'), array('frompageid', 'topageid', 'tomissingpage'));
$versions = new backup_nested_element('versions');
$version = new backup_nested_element('version', array('id'), array('content', 'contentformat', 'version', 'timecreated', 'userid'));
$tags = new backup_nested_element('tags');
$tag = new backup_nested_element('tag', array('id'), array('name', 'rawname'));
// Build the tree
$wiki->add_child($subwikis);
$subwikis->add_child($subwiki);
$subwiki->add_child($pages);
$pages->add_child($page);
$subwiki->add_child($synonyms);
$synonyms->add_child($synonym);
$subwiki->add_child($links);
$links->add_child($link);
$page->add_child($versions);
$versions->add_child($version);
$page->add_child($tags);
$tags->add_child($tag);
// Define sources
$wiki->set_source_table('wiki', array('id' => backup::VAR_ACTIVITYID));
// All these source definitions only happen if we are including user info
if ($userinfo) {
$subwiki->set_source_sql('
SELECT *
FROM {wiki_subwikis}
WHERE wikiid = ?', array(backup::VAR_PARENTID));
$page->set_source_table('wiki_pages', array('subwikiid' => backup::VAR_PARENTID));
$synonym->set_source_table('wiki_synonyms', array('subwikiid' => backup::VAR_PARENTID));
$link->set_source_table('wiki_links', array('subwikiid' => backup::VAR_PARENTID));
$version->set_source_table('wiki_versions', array('pageid' => backup::VAR_PARENTID));
$tag->set_source_sql('SELECT t.id, t.name, t.rawname
FROM {tag} t
JOIN {tag_instance} ti ON ti.tagid = t.id
WHERE ti.itemtype = ?
AND ti.component = ?
AND ti.itemid = ?', array(
backup_helper::is_sqlparam('wiki_pages'),
backup_helper::is_sqlparam('mod_wiki'),
backup::VAR_PARENTID));
}
// Define id annotations
$subwiki->annotate_ids('group', 'groupid');
$subwiki->annotate_ids('user', 'userid');
$page->annotate_ids('user', 'userid');
$version->annotate_ids('user', 'userid');
// Define file annotations
$wiki->annotate_files('mod_wiki', 'intro', null); // This file area hasn't itemid
$subwiki->annotate_files('mod_wiki', 'attachments', 'id'); // This file area hasn't itemid
// Return the root element (wiki), wrapped into standard activity structure
return $this->prepare_activity_structure($wiki);
}
}
@@ -0,0 +1,120 @@
<?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/>.
/**
* @package mod_wiki
* @subpackage backup-moodle2
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/wiki/backup/moodle2/restore_wiki_stepslib.php'); // Because it exists (must)
/**
* wiki restore task that provides all the settings and steps to perform one
* complete restore of the activity
*/
class restore_wiki_activity_task extends restore_activity_task {
/**
* Define (add) particular settings this activity can have
*/
protected function define_my_settings() {
// No particular settings for this activity
}
/**
* Define (add) particular steps this activity can have
*/
protected function define_my_steps() {
// wiki only has one structure step
$this->add_step(new restore_wiki_activity_structure_step('wiki_structure', 'wiki.xml'));
}
/**
* Define the contents in the activity that must be
* processed by the link decoder
*/
public static function define_decode_contents() {
$contents = array();
$contents[] = new restore_decode_content('wiki', array('intro'), 'wiki');
$contents[] = new restore_decode_content('wiki_versions', array('content'), 'wiki_version');
$contents[] = new restore_decode_content('wiki_pages', array('cachedcontent'), 'wiki_page');
return $contents;
}
/**
* Define the decoding rules for links belonging
* to the activity to be executed by the link decoder
*/
public static function define_decode_rules() {
$rules = array();
$rules[] = new restore_decode_rule('WIKIINDEX', '/mod/wiki/index.php?id=$1', 'course');
$rules[] = new restore_decode_rule('WIKIVIEWBYID', '/mod/wiki/view.php?id=$1', 'course_module');
$rules[] = new restore_decode_rule('WIKIPAGEBYID', '/mod/wiki/view.php?pageid=$1', 'wiki_page');
return $rules;
}
/**
* Define the restore log rules that will be applied
* by the {@link restore_logs_processor} when restoring
* wiki logs. It must return one array
* of {@link restore_log_rule} objects
*/
public static function define_restore_log_rules() {
$rules = array();
$rules[] = new restore_log_rule('wiki', 'add', 'view.php?id={course_module}', '{wiki}');
$rules[] = new restore_log_rule('wiki', 'update', 'view.php?id={course_module}', '{wiki}');
$rules[] = new restore_log_rule('wiki', 'view', 'view.php?id={course_module}', '{wiki}');
$rules[] = new restore_log_rule('wiki', 'comments', 'comments.php?id={course_module}', '{wiki}');
$rules[] = new restore_log_rule('wiki', 'diff', 'diff.php?id={course_module}', '{wiki}');
$rules[] = new restore_log_rule('wiki', 'edit', 'edit.php?id={course_module}', '{wiki}');
$rules[] = new restore_log_rule('wiki', 'history', 'history.php?id={course_module}', '{wiki}');
$rules[] = new restore_log_rule('wiki', 'map', 'map.php?id={course_module}', '{wiki}');
$rules[] = new restore_log_rule('wiki', 'overridelocks', 'overridelocks.php?id={course_module}', '{wiki}');
/// TODO: Examine these 2 rules, because module is not "wiki", and it shouldn't happen
$rules[] = new restore_log_rule('restore', 'restore', 'view.php?id={course_module}', '{wiki}');
$rules[] = new restore_log_rule('createpage', 'createpage', 'view.php?id={course_module}', '{wiki}');
return $rules;
}
/**
* Define the restore log rules that will be applied
* by the {@link restore_logs_processor} when restoring
* course logs. It must return one array
* of {@link restore_log_rule} objects
*
* Note this rules are applied when restoring course logs
* by the restore final task, but are defined here at
* activity level. All them are rules not linked to any module instance (cmid = 0)
*/
public static function define_restore_log_rules_for_course() {
$rules = array();
$rules[] = new restore_log_rule('wiki', 'view all', 'index.php?id={course}', null);
return $rules;
}
}
@@ -0,0 +1,177 @@
<?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/>.
/**
* @package mod_wiki
* @subpackage backup-moodle2
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Define all the restore steps that will be used by the restore_wiki_activity_task
*/
/**
* Structure step to restore one wiki activity
*/
class restore_wiki_activity_structure_step extends restore_activity_structure_step {
protected function define_structure() {
$paths = array();
$userinfo = $this->get_setting_value('userinfo');
$paths[] = new restore_path_element('wiki', '/activity/wiki');
if ($userinfo) {
$paths[] = new restore_path_element('wiki_subwiki', '/activity/wiki/subwikis/subwiki');
$paths[] = new restore_path_element('wiki_page', '/activity/wiki/subwikis/subwiki/pages/page');
$paths[] = new restore_path_element('wiki_version', '/activity/wiki/subwikis/subwiki/pages/page/versions/version');
$paths[] = new restore_path_element('wiki_tag', '/activity/wiki/subwikis/subwiki/pages/page/tags/tag');
$paths[] = new restore_path_element('wiki_synonym', '/activity/wiki/subwikis/subwiki/synonyms/synonym');
$paths[] = new restore_path_element('wiki_link', '/activity/wiki/subwikis/subwiki/links/link');
}
// Return the paths wrapped into standard activity structure
return $this->prepare_activity_structure($paths);
}
protected function process_wiki($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->course = $this->get_courseid();
// Any changes to the list of dates that needs to be rolled should be same during course restore and course reset.
// See MDL-9367.
$data->editbegin = $this->apply_date_offset($data->editbegin);
$data->editend = $this->apply_date_offset($data->editend);
$data->defaultformat = clean_param($data->defaultformat, PARAM_ALPHA);
// insert the wiki record
$newitemid = $DB->insert_record('wiki', $data);
// immediately after inserting "activity" record, call this
$this->apply_activity_instance($newitemid);
}
protected function process_wiki_subwiki($data) {
global $DB;
$data = (object) $data;
$oldid = $data->id;
$data->wikiid = $this->get_new_parentid('wiki');
// If the groupid is not equal to zero, get the mapping for the group.
if ((int) $data->groupid !== 0) {
$data->groupid = $this->get_mappingid('group', $data->groupid);
}
// If the userid is not equal to zero, get the mapping for the user.
if ((int) $data->userid !== 0) {
$data->userid = $this->get_mappingid('user', $data->userid);
}
// If these values are not equal to false then a mapping was successfully made.
if ($data->groupid !== false && $data->userid !== false) {
$newitemid = $DB->insert_record('wiki_subwikis', $data);
} else {
$newitemid = false;
}
$this->set_mapping('wiki_subwiki', $oldid, $newitemid, true);
}
protected function process_wiki_page($data) {
global $DB;
$data = (object) $data;
$oldid = $data->id;
$data->subwikiid = $this->get_new_parentid('wiki_subwiki');
$data->userid = $this->get_mappingid('user', $data->userid);
// Check that we were able to get a parentid for this page.
if ($data->subwikiid !== false) {
$newitemid = $DB->insert_record('wiki_pages', $data);
} else {
$newitemid = false;
}
$this->set_mapping('wiki_page', $oldid, $newitemid, true);
}
protected function process_wiki_version($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->pageid = $this->get_new_parentid('wiki_page');
$data->userid = $this->get_mappingid('user', $data->userid);
$data->contentformat = clean_param($data->contentformat, PARAM_ALPHA);
$newitemid = $DB->insert_record('wiki_versions', $data);
$this->set_mapping('wiki_version', $oldid, $newitemid);
}
protected function process_wiki_synonym($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->subwikiid = $this->get_new_parentid('wiki_subwiki');
$data->pageid = $this->get_mappingid('wiki_page', $data->pageid);
$newitemid = $DB->insert_record('wiki_synonyms', $data);
// No need to save this mapping as far as nothing depend on it
// (child paths, file areas nor links decoder)
}
protected function process_wiki_link($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->subwikiid = $this->get_new_parentid('wiki_subwiki');
$data->frompageid = $this->get_mappingid('wiki_page', $data->frompageid);
$data->topageid = $this->get_mappingid('wiki_page', $data->topageid);
$newitemid = $DB->insert_record('wiki_links', $data);
// No need to save this mapping as far as nothing depend on it
// (child paths, file areas nor links decoder)
}
protected function process_wiki_tag($data) {
global $CFG, $DB;
$data = (object)$data;
$oldid = $data->id;
if (!core_tag_tag::is_enabled('mod_wiki', 'wiki_pages')) { // Tags disabled in server, nothing to process.
return;
}
$tag = $data->rawname;
$itemid = $this->get_new_parentid('wiki_page');
$wikiid = $this->get_new_parentid('wiki');
$context = context_module::instance($this->task->get_moduleid());
core_tag_tag::add_item_tag('mod_wiki', 'wiki_pages', $itemid, $context, $tag);
}
protected function after_execute() {
// Add wiki related files, no need to match by itemname (just internally handled context)
$this->add_related_files('mod_wiki', 'intro', null);
$this->add_related_files('mod_wiki', 'attachments', 'wiki_subwiki');
}
}