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,37 @@
<?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/>.
/**
* Activity base class.
*
* @package mod_wiki
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_wiki\analytics\indicator;
defined('MOODLE_INTERNAL') || die();
/**
* Activity base class.
*
* @package mod_wiki
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class activity_base extends \core_analytics\local\indicator\community_of_inquiry_activity {
}
@@ -0,0 +1,56 @@
<?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/>.
/**
* Cognitive depth indicator - wiki.
*
* @package mod_wiki
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_wiki\analytics\indicator;
defined('MOODLE_INTERNAL') || die();
/**
* Cognitive depth indicator - wiki.
*
* @package mod_wiki
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class cognitive_depth extends activity_base {
/**
* Returns the name.
*
* If there is a corresponding '_help' string this will be shown as well.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('indicator:cognitivedepth', 'mod_wiki');
}
public function get_indicator_type() {
return self::INDICATOR_COGNITIVE;
}
public function get_cognitive_depth_level(\cm_info $cm) {
return self::COGNITIVE_LEVEL_2;
}
}
@@ -0,0 +1,56 @@
<?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/>.
/**
* Social breadth indicator - wiki.
*
* @package mod_wiki
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_wiki\analytics\indicator;
defined('MOODLE_INTERNAL') || die();
/**
* Social breadth indicator - wiki.
*
* @package mod_wiki
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class social_breadth extends activity_base {
/**
* Returns the name.
*
* If there is a corresponding '_help' string this will be shown as well.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('indicator:socialbreadth', 'mod_wiki');
}
public function get_indicator_type() {
return self::INDICATOR_SOCIAL;
}
public function get_social_breadth_level(\cm_info $cm) {
return self::SOCIAL_LEVEL_1;
}
}
@@ -0,0 +1,56 @@
<?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/>.
/**
* The mod_wiki comment created event.
*
* @package mod_wiki
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_wiki\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_wiki comment created event class.
*
* @package mod_wiki
* @since Moodle 2.7
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class comment_created extends \core\event\comment_created {
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/wiki/comments.php', array('pageid' => $this->other['itemid']));
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' added a comment with id '$this->objectid' on the page with id " .
"'{$this->other['itemid']}' for the wiki with course module id '$this->contextinstanceid'.";
}
}
@@ -0,0 +1,56 @@
<?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/>.
/**
* The mod_wiki comment deleted event.
*
* @package mod_wiki
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_wiki\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_wiki comment deleted event class.
*
* @package mod_wiki
* @since Moodle 2.7
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class comment_deleted extends \core\event\comment_deleted {
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/wiki/comments.php', array('pageid' => $this->other['itemid']));
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' deleted a comment with id '$this->objectid' on the page with id " .
"'{$this->other['itemid']}' for the wiki with course module id '$this->contextinstanceid'.";
}
}
@@ -0,0 +1,70 @@
<?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/>.
/**
* The mod_wiki comments viewed event.
*
* @package mod_wiki
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_wiki\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_wiki comments viewed event class.
*
* @package mod_wiki
* @since Moodle 2.7
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class comments_viewed extends \core\event\comments_viewed {
/**
* Init method.
*
* @return void
*/
protected function init() {
parent::init();
$this->data['objecttable'] = 'wiki_pages';
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' viewed the comments for the page with id '$this->objectid' for the wiki " .
"with course module id '$this->contextinstanceid'.";
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/wiki/comments.php', array('pageid' => $this->objectid));
}
public static function get_objectid_mapping() {
return array('db' => 'wiki_pages', 'restore' => 'wiki_page');
}
}
@@ -0,0 +1,37 @@
<?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/>.
/**
* The mod_wiki instance list viewed event.
*
* @package mod_wiki
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_wiki\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_wiki instance list viewed event class.
*
* @package mod_wiki
* @since Moodle 2.7
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_module_instance_list_viewed extends \core\event\course_module_instance_list_viewed {
}
@@ -0,0 +1,52 @@
<?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/>.
/**
* The mod_wiki course module viewed event.
*
* @package mod_wiki
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_wiki\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_wiki course module viewed event class.
*
* @package mod_wiki
* @since Moodle 2.7
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_module_viewed extends \core\event\course_module_viewed {
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'wiki';
}
public static function get_objectid_mapping() {
return array('db' => 'wiki', 'restore' => 'wiki');
}
}
+79
View File
@@ -0,0 +1,79 @@
<?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/>.
/**
* The mod_wiki page created event.
*
* @package mod_wiki
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_wiki\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_wiki page created event class.
*
* @package mod_wiki
* @since Moodle 2.7
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class page_created extends \core\event\base {
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'c';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'wiki_pages';
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventpagecreated', 'mod_wiki');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' created the page with id '$this->objectid' for the wiki with " .
"course module id '$this->contextinstanceid'.";
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/wiki/view.php', array('pageid' => $this->objectid));
}
public static function get_objectid_mapping() {
return array('db' => 'wiki_pages', 'restore' => 'wiki_page');
}
}
+92
View File
@@ -0,0 +1,92 @@
<?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/>.
/**
* The mod_wiki page deleted event.
*
* @package mod_wiki
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_wiki\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_wiki page deleted event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int subwikiid: (optional) id subwiki.
* }
*
* @package mod_wiki
* @since Moodle 2.7
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class page_deleted extends \core\event\base {
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'd';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'wiki_pages';
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventpagedeleted', 'mod_wiki');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' deleted the page with id '$this->objectid' for the wiki with " .
"course module id '$this->contextinstanceid'.";
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/wiki/admin.php', array('pageid' => $this->objectid));
}
public static function get_objectid_mapping() {
return array('db' => 'wiki_pages', 'restore' => 'wiki_page');
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['subwikiid'] = array('db' => 'wiki_subwikis', 'restore' => 'wiki_subwiki');
return $othermapped;
}
}
+111
View File
@@ -0,0 +1,111 @@
<?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/>.
/**
* The mod_wiki diff viewed event.
*
* @package mod_wiki
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_wiki\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_wiki diff viewed event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int comparewith: version number to compare with.
* - int compare: version number to compare.
* }
*
* @package mod_wiki
* @since Moodle 2.7
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class page_diff_viewed extends \core\event\base {
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'wiki_pages';
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventdiffviewed', 'mod_wiki');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' viewed the diff for the page with id '$this->objectid' for the wiki with " .
"course module id '$this->contextinstanceid'.";
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/wiki/diff.php', array(
'pageid' => $this->objectid,
'comparewith' => $this->other['comparewith'],
'compare' => $this->other['compare']
));
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['comparewith'])) {
throw new \coding_exception('The \'comparewith\' value must be set in other.');
}
if (!isset($this->other['compare'])) {
throw new \coding_exception('The \'compare\' value must be set in other.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'wiki_pages', 'restore' => 'wiki_page');
}
public static function get_other_mapping() {
// Nothing to map.
return false;
}
}
@@ -0,0 +1,79 @@
<?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/>.
/**
* The mod_wiki history viewed event.
*
* @package mod_wiki
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_wiki\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_wiki history viewed event class.
*
* @package mod_wiki
* @since Moodle 2.7
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class page_history_viewed extends \core\event\base {
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'wiki_pages';
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventhistoryviewed', 'mod_wiki');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' viewed the history for the page with id '$this->objectid' for the wiki with " .
"course module id '$this->contextinstanceid'.";
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/wiki/history.php', array('pageid' => $this->objectid));
}
public static function get_objectid_mapping() {
return array('db' => 'wiki_pages', 'restore' => 'wiki_page');
}
}
@@ -0,0 +1,90 @@
<?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/>.
/**
* The mod_wiki page locks deleted (override locks) event.
*
* @package mod_wiki
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_wiki\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_wiki page locks deleted (override locks) event class.
*
* @property-read array $other {
* Extra information about event.
*
* - string section: (optional) section name.
* }
*
* @package mod_wiki
* @since Moodle 2.7
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class page_locks_deleted extends \core\event\base {
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'd';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'wiki_pages';
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventpagelocksdeleted', 'mod_wiki');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' deleted locks for the page with id '$this->objectid' for the wiki with " .
"course module id '$this->contextinstanceid'.";
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/wiki/view.php', array('pageid' => $this->objectid));
}
public static function get_objectid_mapping() {
return array('db' => 'wiki_pages', 'restore' => 'wiki_page');
}
public static function get_other_mapping() {
// Nothing to map.
return false;
}
}
+103
View File
@@ -0,0 +1,103 @@
<?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/>.
/**
* The mod_wiki map viewed event.
*
* @package mod_wiki
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_wiki\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_wiki map viewed event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int option: map option viewed.
* }
*
* @package mod_wiki
* @since Moodle 2.7
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class page_map_viewed extends \core\event\base {
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'wiki_pages';
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventmapviewed', 'mod_wiki');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' viewed the wiki map for the page with id '$this->objectid' for the wiki with " .
"course module id '$this->contextinstanceid'.";
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/wiki/map.php', array('pageid' => $this->objectid));
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['option'])) {
throw new \coding_exception('The \'option\' value must be set in other, even if 0.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'wiki_pages', 'restore' => 'wiki_page');
}
public static function get_other_mapping() {
// Nothing to map.
return false;
}
}
+90
View File
@@ -0,0 +1,90 @@
<?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/>.
/**
* The mod_wiki page updated event.
*
* @package mod_wiki
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_wiki\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_wiki page updated event class.
*
* @property-read array $other {
* Extra information about event.
*
* - string newcontent: (optional) updated content.
* }
*
* @package mod_wiki
* @since Moodle 2.7
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class page_updated extends \core\event\base {
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'wiki_pages';
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventpageupdated', 'mod_wiki');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' updated the page with id '$this->objectid' for the wiki with " .
"course module id '$this->contextinstanceid'.";
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/wiki/view.php', array('pageid' => $this->objectid));
}
public static function get_objectid_mapping() {
return array('db' => 'wiki_pages', 'restore' => 'wiki_page');
}
public static function get_other_mapping() {
// Nothing to map.
return false;
}
}
@@ -0,0 +1,105 @@
<?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/>.
/**
* The mod_wiki page version deleted event.
*
* @package mod_wiki
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_wiki\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_wiki page version deleted event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int pageid: id wiki page.
* }
*
* @package mod_wiki
* @since Moodle 2.7
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class page_version_deleted extends \core\event\base {
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'd';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'wiki_versions';
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventpageversiondeleted', 'mod_wiki');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' deleted version '$this->objectid' for the page with id '{$this->other['pageid']}' " .
"for the wiki with course module id '$this->contextinstanceid'.";
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/wiki/admin.php', array('pageid' => $this->other['pageid']));
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['pageid'])) {
throw new \coding_exception('The \'pageid\' value must be set in other.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'wiki_versions', 'restore' => 'wiki_version');
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['pageid'] = array('db' => 'wiki_pages', 'restore' => 'wiki_page');
return $othermapped;
}
}
@@ -0,0 +1,106 @@
<?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/>.
/**
* The mod_wiki version restored event.
*
* @package mod_wiki
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_wiki\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_wiki version restored event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int pageid: id wiki page.
* }
*
* @package mod_wiki
* @since Moodle 2.7
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class page_version_restored extends \core\event\base {
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'wiki_versions';
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventversionrestored', 'mod_wiki');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' restored version '$this->objectid' for the page with id '{$this->other['pageid']}' " .
"for the wiki with course module id '$this->contextinstanceid'.";
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/wiki/viewversion.php', array('pageid' => $this->other['pageid'],
'versionid' => $this->objectid));
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['pageid'])) {
throw new \coding_exception('The pageid needs to be set in $other');
}
}
public static function get_objectid_mapping() {
return array('db' => 'wiki_versions', 'restore' => 'wiki_version');
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['pageid'] = array('db' => 'wiki_pages', 'restore' => 'wiki_page');
return $othermapped;
}
}
@@ -0,0 +1,106 @@
<?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/>.
/**
* The mod_wiki version viewed event.
*
* @package mod_wiki
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_wiki\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_wiki version viewed event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int versionid: id page version.
* }
*
* @package mod_wiki
* @since Moodle 2.7
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class page_version_viewed extends \core\event\base {
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'wiki_pages';
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventversionviewed', 'mod_wiki');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' viewed the version for the page with id '$this->objectid' for the wiki with " .
"course module id '$this->contextinstanceid'.";
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/wiki/viewversion.php', array('pageid' => $this->objectid,
'versionid' => $this->other['versionid']));
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['versionid'])) {
throw new \coding_exception('The versionid need to be set in $other');
}
}
public static function get_objectid_mapping() {
return array('db' => 'wiki_pages', 'restore' => 'wiki_page');
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['versionid'] = array('db' => 'wiki_versions', 'restore' => 'wiki_version');
return $othermapped;
}
}
+107
View File
@@ -0,0 +1,107 @@
<?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/>.
/**
* The mod_wiki page viewed event.
*
* @package mod_wiki
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_wiki\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_wiki page viewed event class.
*
* @property-read array $other {
* Extra information about the event.
*
* - string title: (optional) the wiki title
* - int wid: (optional) the wiki id
* - int group: (optional) the group id
* - string groupanduser: (optional) the groupid-userid
* }
*
* @package mod_wiki
* @since Moodle 2.7
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class page_viewed extends \core\event\base {
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'wiki_pages';
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventpageviewed', 'mod_wiki');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' viewed the page with id '$this->objectid' for the wiki with " .
"course module id '$this->contextinstanceid'.";
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
if (!empty($this->data['other']['wid'])) {
return new \moodle_url('/mod/wiki/view.php', array('wid' => $this->data['other']['wid'],
'title' => $this->data['other']['title'],
'uid' => $this->relateduserid,
'groupanduser' => $this->data['other']['groupanduser'],
'group' => $this->data['other']['group']
));
} else if (!empty($this->other['prettyview'])) {
return new \moodle_url('/mod/wiki/prettyview.php', array('pageid' => $this->objectid));
} else {
return new \moodle_url('/mod/wiki/view.php', array('pageid' => $this->objectid));
}
}
public static function get_objectid_mapping() {
return array('db' => 'wiki_pages', 'restore' => 'wiki_page');
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['wid'] = array('db' => 'wiki', 'restore' => 'wiki');
$othermapped['group'] = array('db' => 'groups', 'restore' => 'group');
return $othermapped;
}
}
File diff suppressed because it is too large Load Diff
+125
View File
@@ -0,0 +1,125 @@
<?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/>.
namespace mod_wiki\output;
use moodle_url;
use templatable;
use renderable;
/**
* Renderable class for the action bar elements in the wiki activity pages.
*
* @package mod_wiki
* @copyright 2021 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class action_bar implements templatable, renderable {
/** @var int $pageid The database module id. */
private $pageid;
/** @var moodle_url $currenturl The URL of the current page. */
private $currenturl;
/** @var bool $displayprint Whether to display print wiki button. */
private $displayprint;
/**
* The class constructor.
*
* @param int $pageid The wiki page id.
* @param moodle_url $pageurl The URL of the current page.
* @param bool $displayprint Whether to display print wiki button.
*/
public function __construct(int $pageid, moodle_url $pageurl, bool $displayprint = false) {
$this->pageid = $pageid;
$this->currenturl = $pageurl;
$this->displayprint = $displayprint;
}
/**
* Export the data for the mustache template.
*
* @param \renderer_base $output renderer to be used to render the action bar elements.
* @return array
*/
public function export_for_template(\renderer_base $output): array {
$urlselect = $this->get_action_selector();
$data = [
'urlselect' => $urlselect->export_for_template($output),
];
if ($this->displayprint) {
$printlink = new moodle_url('/mod/wiki/prettyview.php', ['pageid' => $this->pageid]);
$data['printbutton'] = \html_writer::link($printlink, get_string('print', 'mod_wiki'),
['class' => 'btn btn-secondary', 'target' => "_blank"]);
}
return $data;
}
/**
* Returns the URL selector object.
*
* @return \url_select The URL select object.
*/
private function get_action_selector(): \url_select {
global $PAGE;
$menu = [];
if (has_capability('mod/wiki:viewpage', $PAGE->context)) {
$viewlink = new moodle_url('/mod/wiki/view.php', ['pageid' => $this->pageid]);
$menu[$viewlink->out(false)] = get_string('view', 'mod_wiki');
}
if (has_capability('mod/wiki:editpage', $PAGE->context)) {
$editlink = new moodle_url('/mod/wiki/edit.php', ['pageid' => $this->pageid]);
$menu[$editlink->out(false)] = get_string('edit', 'mod_wiki');
}
if (has_capability('mod/wiki:viewcomment', $PAGE->context)) {
$commentslink = new moodle_url('/mod/wiki/comments.php', ['pageid' => $this->pageid]);
$menu[$commentslink->out(false)] = get_string('comments', 'mod_wiki');
}
if (has_capability('mod/wiki:viewpage', $PAGE->context)) {
$historylink = new moodle_url('/mod/wiki/history.php', ['pageid' => $this->pageid]);
$menu[$historylink->out(false)] = get_string('history', 'mod_wiki');
}
if (has_capability('mod/wiki:viewpage', $PAGE->context)) {
$maplink = new moodle_url('/mod/wiki/map.php', ['pageid' => $this->pageid]);
$menu[$maplink->out(false)] = get_string('map', 'mod_wiki');
}
if (has_capability('mod/wiki:viewpage', $PAGE->context)) {
$fileslink = new moodle_url('/mod/wiki/files.php', ['pageid' => $this->pageid]);
$menu[$fileslink->out(false)] = get_string('files', 'mod_wiki');
}
if (has_capability('mod/wiki:managewiki', $PAGE->context)) {
$adminlink = new moodle_url('/mod/wiki/admin.php', ['pageid' => $this->pageid]);
$menu[$adminlink->out(false)] = get_string('admin', 'mod_wiki');
}
return new \url_select($menu, $this->currenturl->out(false), null, 'wikiactionselect');
}
}
+632
View File
@@ -0,0 +1,632 @@
<?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/>.
/**
* Data provider.
*
* @package mod_wiki
* @copyright 2018 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_wiki\privacy;
use core_privacy\local\metadata\collection;
use core_privacy\local\request\approved_contextlist;
use core_privacy\local\request\approved_userlist;
use core_privacy\local\request\contextlist;
use context_user;
use context;
use core_privacy\local\request\helper;
use core_privacy\local\request\transform;
use core_privacy\local\request\userlist;
use core_privacy\local\request\writer;
defined('MOODLE_INTERNAL') || die();
/**
* Data provider class.
*
* @package mod_wiki
* @copyright 2018 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements
\core_privacy\local\metadata\provider,
\core_privacy\local\request\core_userlist_provider,
\core_privacy\local\request\plugin\provider {
/**
* Returns metadata.
*
* @param collection $collection The initialised collection to add items to.
* @return collection A listing of user data stored through this system.
*/
public static function get_metadata(collection $collection): collection {
$collection->add_database_table('wiki_subwikis', [
'userid' => 'privacy:metadata:wiki_subwikis:userid',
'groupid' => 'privacy:metadata:wiki_subwikis:groupid',
], 'privacy:metadata:wiki_subwikis');
$collection->add_database_table('wiki_pages', [
'userid' => 'privacy:metadata:wiki_pages:userid',
'title' => 'privacy:metadata:wiki_pages:title',
'cachedcontent' => 'privacy:metadata:wiki_pages:cachedcontent',
'timecreated' => 'privacy:metadata:wiki_pages:timecreated',
'timemodified' => 'privacy:metadata:wiki_pages:timemodified',
'timerendered' => 'privacy:metadata:wiki_pages:timerendered',
'pageviews' => 'privacy:metadata:wiki_pages:pageviews',
'readonly' => 'privacy:metadata:wiki_pages:readonly',
], 'privacy:metadata:wiki_pages');
$collection->add_database_table('wiki_versions', [
'userid' => 'privacy:metadata:wiki_versions:userid',
'content' => 'privacy:metadata:wiki_versions:content',
'contentformat' => 'privacy:metadata:wiki_versions:contentformat',
'version' => 'privacy:metadata:wiki_versions:version',
'timecreated' => 'privacy:metadata:wiki_versions:timecreated',
], 'privacy:metadata:wiki_versions');
$collection->add_database_table('wiki_locks', [
'userid' => 'privacy:metadata:wiki_locks:userid',
'sectionname' => 'privacy:metadata:wiki_locks:sectionname',
'lockedat' => 'privacy:metadata:wiki_locks:lockedat',
], 'privacy:metadata:wiki_locks');
$collection->link_subsystem('core_files', 'privacy:metadata:core_files');
$collection->link_subsystem('core_tag', 'privacy:metadata:core_tag');
$collection->link_subsystem('core_comment', 'privacy:metadata:core_comment');
// We do not report on wiki, wiki_synonyms, wiki_links because this is just context-related data.
return $collection;
}
/**
* Get the list of contexts that contain user information for the specified user.
*
* @param int $userid The user to search.
* @return contextlist $contextlist The contextlist containing the list of contexts used in this plugin.
*/
public static function get_contexts_for_userid(int $userid): contextlist {
$contextlist = new contextlist();
$contextlist->add_from_sql('SELECT ctx.id
FROM {modules} m
JOIN {course_modules} cm ON cm.module = m.id AND m.name = :modname
JOIN {context} ctx ON ctx.instanceid = cm.id AND ctx.contextlevel = :contextlevel
JOIN {wiki_subwikis} s ON cm.instance = s.wikiid
LEFT JOIN {wiki_pages} p ON p.subwikiid = s.id
LEFT JOIN {wiki_versions} v ON v.pageid = p.id AND v.userid = :userid3
LEFT JOIN {wiki_locks} l ON l.pageid = p.id AND l.userid = :userid4
LEFT JOIN {comments} com ON com.itemid = p.id AND com.commentarea = :commentarea
AND com.contextid = ctx.id AND com.userid = :userid5
WHERE s.userid = :userid1 OR p.userid = :userid2 OR v.id IS NOT NULL OR l.id IS NOT NULL OR com.id IS NOT NULL',
['modname' => 'wiki', 'contextlevel' => CONTEXT_MODULE, 'userid1' => $userid, 'userid2' => $userid,
'userid3' => $userid, 'userid4' => $userid, 'commentarea' => 'wiki_page', 'userid5' => $userid]);
return $contextlist;
}
/**
* Get the list of users who have data within a context.
*
* @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination.
*/
public static function get_users_in_context(userlist $userlist) {
$context = $userlist->get_context();
if (!is_a($context, \context_module::class)) {
return;
}
$params = [
'modname' => 'wiki',
'contextlevel' => CONTEXT_MODULE,
'contextid' => $context->id,
];
$sql = "
SELECT s.userid
FROM {modules} m
JOIN {course_modules} cm ON cm.module = m.id AND m.name = :modname
JOIN {context} ctx ON ctx.instanceid = cm.id AND ctx.contextlevel = :contextlevel
JOIN {wiki_subwikis} s ON cm.instance = s.wikiid
WHERE ctx.id = :contextid";
$userlist->add_from_sql('userid', $sql, $params);
$sql = "
SELECT p.userid
FROM {modules} m
JOIN {course_modules} cm ON cm.module = m.id AND m.name = :modname
JOIN {context} ctx ON ctx.instanceid = cm.id AND ctx.contextlevel = :contextlevel
JOIN {wiki_subwikis} s ON cm.instance = s.wikiid
JOIN {wiki_pages} p ON p.subwikiid = s.id
WHERE ctx.id = :contextid";
$userlist->add_from_sql('userid', $sql, $params);
$sql = "
SELECT v.userid
FROM {modules} m
JOIN {course_modules} cm ON cm.module = m.id AND m.name = :modname
JOIN {context} ctx ON ctx.instanceid = cm.id AND ctx.contextlevel = :contextlevel
JOIN {wiki_subwikis} s ON cm.instance = s.wikiid
JOIN {wiki_pages} p ON p.subwikiid = s.id
JOIN {wiki_versions} v ON v.pageid = p.id
WHERE ctx.id = :contextid";
$userlist->add_from_sql('userid', $sql, $params);
$sql = "
SELECT l.userid
FROM {modules} m
JOIN {course_modules} cm ON cm.module = m.id AND m.name = :modname
JOIN {context} ctx ON ctx.instanceid = cm.id AND ctx.contextlevel = :contextlevel
JOIN {wiki_subwikis} s ON cm.instance = s.wikiid
JOIN {wiki_pages} p ON p.subwikiid = s.id
JOIN {wiki_locks} l ON l.pageid = p.id
WHERE ctx.id = :contextid";
$userlist->add_from_sql('userid', $sql, $params);
\core_comment\privacy\provider::get_users_in_context_from_sql($userlist, 'com', 'mod_wiki', 'wiki_page', $context->id);
}
/**
* Add one subwiki to the export
*
* Each page is added as related data because all pages in one subwiki share the same filearea
*
* @param stdClass $user
* @param context $context
* @param array $subwiki
* @param string $wikimode
*/
protected static function export_subwiki($user, context $context, $subwiki, $wikimode) {
if (empty($subwiki)) {
return;
}
$subwikiid = key($subwiki);
$pages = $subwiki[$subwikiid]['pages'];
unset($subwiki[$subwikiid]['pages']);
writer::with_context($context)->export_data([$subwikiid], (object)$subwiki[$subwikiid]);
$allfiles = $wikimode === 'individual'; // Whether to export all files or only the ones that are used.
$alltexts = ''; // Store all texts that reference files to search which files are used.
foreach ($pages as $page => $entry) {
// Preprocess current page contents.
if (!$allfiles && self::text_has_files($entry['page']['cachedcontent'])) {
$alltexts .= $entry['page']['cachedcontent'];
}
$entry['page']['cachedcontent'] = format_text(writer::with_context($context)
->rewrite_pluginfile_urls([$subwikiid], 'mod_wiki', 'attachments',
$subwikiid, $entry['page']['cachedcontent']), FORMAT_HTML, ['context' => $context]);
// Add page tags.
$pagetags = \core_tag_tag::get_item_tags_array('mod_wiki', 'page', $entry['page']['id']);
if ($pagetags) {
$entry['page']['tags'] = $pagetags;
}
// Preprocess revisions.
if (!empty($entry['revisions'])) {
// For each revision this user has made preprocess the contents.
foreach ($entry['revisions'] as &$revision) {
if ((!$allfiles && self::text_has_files($revision['content']))) {
$alltexts .= $revision['content'];
}
$revision['content'] = writer::with_context($context)
->rewrite_pluginfile_urls([$subwikiid], 'mod_wiki', 'attachments', $subwikiid, $revision['content']);
}
}
$comments = self::get_page_comments($user, $context, $entry['page']['id'], !array_key_exists('userid', $entry['page']));
if ($comments) {
$entry['page']['comments'] = $comments;
}
writer::with_context($context)->export_related_data([$subwikiid], $page, $entry);
}
if ($allfiles) {
// Export all files.
writer::with_context($context)->export_area_files([$subwikiid], 'mod_wiki', 'attachments', $subwikiid);
} else {
// Analyze which files are used in the texts.
self::export_used_files($context, $subwikiid, $alltexts);
}
}
/**
* Retrieves page comments
*
* We can not use \core_comment\privacy\provider::export_comments() because it expects each item to have a separate
* subcontext and we store wiki pages as related data to subwiki because the files are shared between pages.
*
* @param stdClass $user
* @param \context $context
* @param int $pageid
* @param bool $onlyforthisuser
* @return array
*/
protected static function get_page_comments($user, \context $context, $pageid, $onlyforthisuser = true) {
global $USER, $DB;
$params = [
'contextid' => $context->id,
'commentarea' => 'wiki_page',
'itemid' => $pageid
];
$sql = "SELECT c.id, c.content, c.format, c.timecreated, c.userid
FROM {comments} c
WHERE c.contextid = :contextid AND
c.commentarea = :commentarea AND
c.itemid = :itemid";
if ($onlyforthisuser) {
$sql .= " AND c.userid = :userid";
$params['userid'] = $USER->id;
}
$sql .= " ORDER BY c.timecreated DESC";
$rs = $DB->get_recordset_sql($sql, $params);
$comments = [];
foreach ($rs as $record) {
if ($record->userid != $user->id) {
// Clean HTML in comments that were added by other users.
$comment = ['content' => format_text($record->content, $record->format, ['context' => $context])];
} else {
// Export comments made by this user as they are stored.
$comment = ['content' => $record->content, 'contentformat' => $record->format];
}
$comment += [
'time' => transform::datetime($record->timecreated),
'userid' => transform::user($record->userid),
];
$comments[] = (object)$comment;
}
$rs->close();
return $comments;
}
/**
* Check if text has embedded files
*
* @param string $str
* @return bool
*/
protected static function text_has_files($str) {
return strpos($str, '@@PLUGINFILE@@') !== false;
}
/**
* Analyze which files are used in the texts and export
* @param context $context
* @param int $subwikiid
* @param string $alltexts
* @return int|void
*/
protected static function export_used_files($context, $subwikiid, $alltexts) {
if (!self::text_has_files($alltexts)) {
return;
}
$fs = get_file_storage();
$files = $fs->get_area_files($context->id, 'mod_wiki', 'attachments', $subwikiid,
'filepath, filename', false);
if (empty($files)) {
return;
}
usort($files, function($file1, $file2) {
return strcmp($file2->get_filepath(), $file1->get_filename());
});
foreach ($files as $file) {
$filepath = $file->get_filepath() . $file->get_filename();
$needles = ['@@PLUGINFILE@@' . s($filepath),
'@@PLUGINFILE@@' . $filepath,
'@@PLUGINFILE@@' . str_replace(' ', '%20', $filepath),
'@@PLUGINFILE@@' . s($filepath),
'@@PLUGINFILE@@' . s(str_replace(' ', '%20', $filepath))
];
$needles = array_unique($needles);
$newtext = str_replace($needles, '', $alltexts);
if ($newtext !== $alltexts) {
$alltexts = $newtext;
writer::with_context($context)->export_file([$subwikiid], $file);
if (!self::text_has_files($alltexts)) {
return;
}
}
}
}
/**
* Export all user data for the specified user, in the specified contexts.
*
* @param approved_contextlist $contextlist The approved contexts to export information for.
*/
public static function export_user_data(approved_contextlist $contextlist) {
global $DB;
foreach ($contextlist as $context) {
if ($context->contextlevel != CONTEXT_MODULE) {
continue;
}
$user = $contextlist->get_user();
$rs = $DB->get_recordset_sql('SELECT w.wikimode, s.id AS subwikiid,
s.groupid AS subwikigroupid, s.userid AS subwikiuserid,
p.id AS pageid, p.userid AS pageuserid, p.title, p.cachedcontent, p.timecreated AS pagetimecreated,
p.timemodified AS pagetimemodified, p.timerendered AS pagetimerendered, p.pageviews, p.readonly,
v.id AS versionid, v.content, v.contentformat, v.version, v.timecreated AS versiontimecreated,
l.id AS lockid, l.sectionname, l.lockedat
FROM {course_modules} cm
JOIN {wiki} w ON w.id = cm.instance
JOIN {wiki_subwikis} s ON cm.instance = s.wikiid
LEFT JOIN {wiki_pages} p ON p.subwikiid = s.id
LEFT JOIN {wiki_versions} v ON v.pageid = p.id AND v.userid = :user4
LEFT JOIN {wiki_locks} l ON l.pageid = p.id AND l.userid = :user5
WHERE cm.id = :cmid AND (s.userid = :user1 OR p.userid = :user2 OR v.userid = :user3 OR l.userid = :user6 OR
EXISTS (SELECT 1 FROM {comments} com WHERE com.itemid = p.id AND com.commentarea = :commentarea
AND com.contextid = :ctxid AND com.userid = :user7)
)
ORDER BY s.id, p.id, v.id',
['cmid' => $context->instanceid,
'user1' => $user->id, 'user2' => $user->id, 'user3' => $user->id, 'user4' => $user->id,
'user5' => $user->id, 'user6' => $user->id, 'user7' => $user->id, 'commentarea' => 'wiki_page',
'ctxid' => $context->id]);
if (!$rs->current()) {
$rs->close();
continue;
}
$subwiki = [];
$wikimode = null;
foreach ($rs as $record) {
if ($wikimode === null) {
$wikimode = $record->wikimode;
}
if (!isset($subwiki[$record->subwikiid])) {
self::export_subwiki($user, $context, $subwiki, $wikimode);
$subwiki = [$record->subwikiid => [
'groupid' => $record->subwikigroupid,
'userid' => $record->subwikiuserid ? transform::user($record->subwikiuserid) : 0,
'pages' => []
]];
}
if (!$record->pageid) {
// This is an empty individual wiki.
continue;
}
// Prepend page title with the page id to guarantee uniqueness.
$pagetitle = format_string($record->title, true, ['context' => $context]);
$page = $record->pageid . ' ' . $pagetitle;
if (!isset($subwiki[$record->subwikiid]['pages'][$page])) {
// Export basic details about the page.
$subwiki[$record->subwikiid]['pages'][$page] = ['page' => [
'id' => $record->pageid,
'title' => $pagetitle,
'cachedcontent' => $record->cachedcontent,
]];
if ($record->pageuserid == $user->id) {
// This page belongs to this user. Export all details.
$subwiki[$record->subwikiid]['pages'][$page]['page'] += [
'userid' => transform::user($user->id),
'timecreated' => transform::datetime($record->pagetimecreated),
'timemodified' => transform::datetime($record->pagetimemodified),
'timerendered' => transform::datetime($record->pagetimerendered),
'pageviews' => $record->pageviews,
'readonly' => $record->readonly,
];
$subwiki[$record->subwikiid]['pages'][$page]['page']['userid'] = transform::user($user->id);
}
}
if ($record->versionid) {
$subwiki[$record->subwikiid]['pages'][$page]['revisions'][$record->versionid] = [
'content' => $record->content,
'contentformat' => $record->contentformat,
'version' => $record->version,
'timecreated' => transform::datetime($record->versiontimecreated)
];
}
if ($record->lockid) {
$subwiki[$record->subwikiid]['pages'][$page]['locks'][$record->lockid] = [
'sectionname' => $record->sectionname,
'lockedat' => transform::datetime($record->lockedat),
];
}
}
self::export_subwiki($user, $context, $subwiki, $wikimode);
if ($subwiki) {
// Export wiki itself.
$contextdata = helper::get_context_data($context, $user);
helper::export_context_files($context, $user);
writer::with_context($context)->export_data([], $contextdata);
}
$rs->close();
}
}
/**
* Delete all data for all users in the specified context.
*
* @param context $context The specific context to delete data for.
*/
public static function delete_data_for_all_users_in_context(context $context) {
global $DB;
if ($context->contextlevel != CONTEXT_MODULE) {
return;
}
$subwikis = $DB->get_fieldset_sql('SELECT s.id
FROM {course_modules} cm
JOIN {modules} m ON m.name = :wiki AND cm.module = m.id
JOIN {wiki_subwikis} s ON s.wikiid = cm.instance
WHERE cm.id = :cmid',
['cmid' => $context->instanceid, 'wiki' => 'wiki']);
if (!$subwikis) {
return;
}
$fs = get_file_storage();
$fs->delete_area_files($context->id, 'mod_wiki', 'attachments');
\core_tag\privacy\provider::delete_item_tags($context, 'mod_wiki', 'page');
\core_comment\privacy\provider::delete_comments_for_all_users($context, 'mod_wiki', 'wiki_page');
list($sql, $params) = $DB->get_in_or_equal($subwikis);
$DB->delete_records_select('wiki_locks', 'pageid IN (SELECT id FROM {wiki_pages} WHERE subwikiid '.$sql.')', $params);
$DB->delete_records_select('wiki_versions', 'pageid IN (SELECT id FROM {wiki_pages} WHERE subwikiid '.$sql.')', $params);
$DB->delete_records_select('wiki_synonyms', 'subwikiid '.$sql, $params);
$DB->delete_records_select('wiki_links', 'subwikiid '.$sql, $params);
$DB->delete_records_select('wiki_pages', 'subwikiid '.$sql, $params);
$DB->delete_records_select('wiki_subwikis', 'id '.$sql, $params);
$DB->delete_records('tag_instance', ['contextid' => $context->id, 'component' => 'mod_wiki', 'itemtype' => 'page']);
}
/**
* Delete all user data for the specified user, in the specified contexts.
*
* @param approved_contextlist $contextlist The approved contexts and user information to delete information for.
*/
public static function delete_data_for_user(approved_contextlist $contextlist) {
global $DB;
$contextids = $contextlist->get_contextids();
if (!$contextids) {
return;
}
// Remove only individual subwikis. Contributions to collaborative wikis is not considered personal contents.
list($ctxsql, $ctxparams) = $DB->get_in_or_equal($contextids, SQL_PARAMS_NAMED);
$subwikis = $DB->get_records_sql_menu('SELECT s.id, ctx.id AS ctxid
FROM {context} ctx
JOIN {course_modules} cm ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextmod
JOIN {modules} m ON m.name = :wiki AND cm.module = m.id
JOIN {wiki_subwikis} s ON s.wikiid = cm.instance AND s.userid = :userid
WHERE ctx.id ' . $ctxsql,
['userid' => (int)$contextlist->get_user()->id, 'wiki' => 'wiki', 'contextmod' => CONTEXT_MODULE] + $ctxparams);
if ($subwikis) {
// We found individual subwikis that need to be deleted completely.
$fs = get_file_storage();
foreach ($subwikis as $subwikiid => $contextid) {
$fs->delete_area_files($contextid, 'mod_wiki', 'attachments', $subwikiid);
\core_comment\privacy\provider::delete_comments_for_all_users_select(context::instance_by_id($contextid),
'mod_wiki', 'wiki_page', "IN (SELECT id FROM {wiki_pages} WHERE subwikiid=:subwikiid)",
['subwikiid' => $subwikiid]);
}
list($sql, $params) = $DB->get_in_or_equal(array_keys($subwikis), SQL_PARAMS_NAMED);
$DB->execute("DELETE FROM {tag_instance} WHERE component=:component AND itemtype=:itemtype AND itemid IN
(SELECT id FROM {wiki_pages} WHERE subwikiid $sql)",
['component' => 'mod_wiki', 'itemtype' => 'page'] + $params);
$DB->delete_records_select('wiki_locks', 'pageid IN (SELECT id FROM {wiki_pages} WHERE subwikiid ' . $sql . ')',
$params);
$DB->delete_records_select('wiki_versions', 'pageid IN (SELECT id FROM {wiki_pages} WHERE subwikiid ' . $sql . ')',
$params);
$DB->delete_records_select('wiki_synonyms', 'subwikiid ' . $sql, $params);
$DB->delete_records_select('wiki_links', 'subwikiid ' . $sql, $params);
$DB->delete_records_select('wiki_pages', 'subwikiid ' . $sql, $params);
$DB->delete_records_select('wiki_subwikis', 'id ' . $sql, $params);
}
// Remove comments made by this user on all other wiki pages.
\core_comment\privacy\provider::delete_comments_for_user($contextlist, 'mod_wiki', 'wiki_page');
}
/**
* Delete multiple users within a single context.
*
* @param approved_userlist $userlist The approved context and user information to delete information for.
*/
public static function delete_data_for_users(approved_userlist $userlist) {
global $DB;
$context = $userlist->get_context();
$userids = $userlist->get_userids();
if ($context->contextlevel != CONTEXT_MODULE) {
return;
}
// Remove only individual subwikis. Contributions to collaborative wikis is not considered personal contents.
list($insql, $inparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
$params = [
'wiki' => 'wiki',
'contextmod' => CONTEXT_MODULE,
'contextid' => $context->id,
];
$params = array_merge($inparams, $params);
$sql = "SELECT s.id
FROM {context} ctx
JOIN {course_modules} cm ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextmod
JOIN {modules} m ON m.name = :wiki AND cm.module = m.id
JOIN {wiki_subwikis} s ON s.wikiid = cm.instance
WHERE ctx.id = :contextid
AND s.userid {$insql}";
$subwikis = $DB->get_fieldset_sql($sql, $params);
if ($subwikis) {
// We found individual subwikis that need to be deleted completely.
$fs = get_file_storage();
foreach ($subwikis as $subwikiid) {
$fs->delete_area_files($context->id, 'mod_wiki', 'attachments', $subwikiid);
\core_comment\privacy\provider::delete_comments_for_all_users_select(context::instance_by_id($context->id),
'mod_wiki', 'wiki_page', "IN (SELECT id FROM {wiki_pages} WHERE subwikiid=:subwikiid)",
['subwikiid' => $subwikiid]);
}
list($insql, $inparams) = $DB->get_in_or_equal($subwikis, SQL_PARAMS_NAMED);
$params = ['component' => 'mod_wiki', 'itemtype' => 'page'];
$params = array_merge($inparams, $params);
$sql = "DELETE FROM {tag_instance}
WHERE component=:component
AND itemtype=:itemtype
AND itemid IN
(SELECT id
FROM {wiki_pages}
WHERE subwikiid $insql)";
$DB->execute($sql, $params);
$DB->delete_records_select('wiki_locks', "pageid IN (SELECT id FROM {wiki_pages} WHERE subwikiid {$insql})", $params);
$DB->delete_records_select('wiki_versions', "pageid IN (SELECT id FROM {wiki_pages} WHERE subwikiid {$insql})",
$params);
$DB->delete_records_select('wiki_synonyms', "subwikiid {$insql}", $params);
$DB->delete_records_select('wiki_links', "subwikiid {$insql}", $params);
$DB->delete_records_select('wiki_pages', "subwikiid {$insql}", $params);
$DB->delete_records_select('wiki_subwikis', "id {$insql}", $params);
}
// Remove comments made by this user on all other wiki pages.
\core_comment\privacy\provider::delete_comments_for_users($userlist, 'mod_wiki', 'wiki_page');
}
}
+46
View File
@@ -0,0 +1,46 @@
<?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/>.
/**
* Search area for mod_wiki activities.
*
* @package mod_wiki
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_wiki\search;
defined('MOODLE_INTERNAL') || die();
/**
* Search area for mod_wiki activities.
*
* @package mod_wiki
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class activity extends \core_search\base_activity {
/**
* Returns true if this area uses file indexing.
*
* @return bool
*/
public function uses_file_indexing() {
return true;
}
}
@@ -0,0 +1,220 @@
<?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/>.
/**
* Search area for mod_wiki collaborative pages.
*
* @package mod_wiki
* @copyright 2016 Eric Merrill {@link http://www.merrilldigital.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_wiki\search;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/wiki/locallib.php');
/**
* Search area for mod_wiki collaborative pages.
*
* @package mod_wiki
* @copyright 2016 Eric Merrill {@link http://www.merrilldigital.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class collaborative_page extends \core_search\base_mod {
/**
* @var array Cache of wiki records.
*/
protected $wikiscache = array();
/**
* Returns a recordset with all required page information.
*
* @param int $modifiedfrom
* @param \context|null $context Optional context to restrict scope of returned results
* @return moodle_recordset|null Recordset (or null if no results)
*/
public function get_document_recordset($modifiedfrom = 0, \context $context = null) {
global $DB;
list ($contextjoin, $contextparams) = $this->get_context_restriction_sql(
$context, 'wiki', 'w');
if ($contextjoin === null) {
return null;
}
$sql = "SELECT p.*, w.id AS wikiid, w.course AS courseid, s.groupid AS groupid
FROM {wiki_pages} p
JOIN {wiki_subwikis} s ON s.id = p.subwikiid
JOIN {wiki} w ON w.id = s.wikiid
$contextjoin
WHERE p.timemodified >= ?
AND w.wikimode = ?
ORDER BY p.timemodified ASC";
return $DB->get_recordset_sql($sql, array_merge($contextparams,
[$modifiedfrom, 'collaborative']));
}
/**
* Returns the document for a particular page.
*
* @param \stdClass $record A record containing, at least, the indexed document id and a modified timestamp
* @param array $options Options for document creation
* @return \core_search\document
*/
public function get_document($record, $options = array()) {
try {
$cm = $this->get_cm('wiki', $record->wikiid, $record->courseid);
$context = \context_module::instance($cm->id);
} catch (\dml_missing_record_exception $ex) {
// Notify it as we run here as admin, we should see everything.
debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document, not all required data is available: ' .
$ex->getMessage(), DEBUG_DEVELOPER);
return false;
} catch (\dml_exception $ex) {
// Notify it as we run here as admin, we should see everything.
debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document: ' . $ex->getMessage(), DEBUG_DEVELOPER);
return false;
}
// Make a page object without extra fields.
$page = clone $record;
unset($page->courseid);
unset($page->wikiid);
// Conversion based wiki_print_page_content().
// Check if we have passed the cache time.
if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) {
$content = wiki_refresh_cachedcontent($page);
$page = $content['page'];
}
// Convert to text.
$content = content_to_text($page->cachedcontent, FORMAT_MOODLE);
// Prepare associative array with data from DB.
$doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname);
$doc->set('title', content_to_text($record->title, false));
$doc->set('content', $content);
$doc->set('contextid', $context->id);
$doc->set('courseid', $record->courseid);
if ($record->groupid > 0) {
$doc->set('groupid', $record->groupid);
}
$doc->set('owneruserid', \core_search\manager::NO_OWNER_ID);
$doc->set('modified', $record->timemodified);
// Check if this document should be considered new.
if (isset($options['lastindexedtime']) && ($options['lastindexedtime'] < $record->timecreated)) {
// If the document was created after the last index time, it must be new.
$doc->set_is_new(true);
}
return $doc;
}
/**
* Can the current user see the document.
*
* @param int $id The internal search area entity id.
* @return bool True if the user can see it, false otherwise
*/
public function check_access($id) {
global $DB;
try {
$page = $DB->get_record('wiki_pages', array('id' => $id), '*', MUST_EXIST);
if (!isset($this->wikiscache[$page->subwikiid])) {
$sql = 'SELECT w.*
FROM {wiki_subwikis} s
JOIN {wiki} w ON w.id = s.wikiid
WHERE s.id = ?';
$this->wikiscache[$page->subwikiid] = $DB->get_record_sql($sql, array('id' => $page->subwikiid), MUST_EXIST);
}
$wiki = $this->wikiscache[$page->subwikiid];
$cminfo = $this->get_cm('wiki', $wiki->id, $wiki->course);
} catch (\dml_missing_record_exception $ex) {
return \core_search\manager::ACCESS_DELETED;
} catch (\dml_exception $ex) {
return \core_search\manager::ACCESS_DENIED;
}
// Recheck uservisible although it should have already been checked in core_search.
if ($cminfo->uservisible === false) {
return \core_search\manager::ACCESS_DENIED;
}
$context = \context_module::instance($cminfo->id);
if (!has_capability('mod/wiki:viewpage', $context)) {
return \core_search\manager::ACCESS_DENIED;
}
return \core_search\manager::ACCESS_GRANTED;
}
/**
* Returns a url to the page.
*
* @param \core_search\document $doc
* @return \moodle_url
*/
public function get_doc_url(\core_search\document $doc) {
$params = array('pageid' => $doc->get('itemid'));
return new \moodle_url('/mod/wiki/view.php', $params);
}
/**
* Returns a url to the wiki.
*
* @param \core_search\document $doc
* @return \moodle_url
*/
public function get_context_url(\core_search\document $doc) {
$contextmodule = \context::instance_by_id($doc->get('contextid'));
return new \moodle_url('/mod/wiki/view.php', array('id' => $contextmodule->instanceid));
}
/**
* Returns true if this area uses file indexing.
*
* @return bool
*/
public function uses_file_indexing() {
return true;
}
/**
* Return the context info required to index files for
* this search area.
*
* @return array
*/
public function get_search_fileareas() {
$fileareas = array('attachments'); // Filearea.
return $fileareas;
}
/**
* Confirms that data entries support group restrictions.
*
* @return bool True
*/
public function supports_group_restriction() {
return true;
}
}