require_login($course, true, $cm); if (!wiki_user_can_view($subwiki, $wiki)) { print_error('cannotviewpage', 'wiki'); } $context = context_module::instance($cm->id); require_capability('mod/wiki:managewiki', $context); //Delete page if a page ID to delete was supplied if (!empty($delete) && confirm_sesskey()) { if ($pageid != $delete) { // Validate that we are deleting from the same subwiki. $deletepage = wiki_get_page($delete); if (!$deletepage || $deletepage->subwikiid != $page->subwikiid) { print_error('incorrectsubwikiid', 'wiki'); } } wiki_delete_pages($context, $delete, $page->subwikiid); //when current wiki page is deleted, then redirect user to create that page, as //current pageid is invalid after deletion. if ($pageid == $delete) { $params = array('swid' => $page->subwikiid, 'title' => $page->title); $url = new moodle_url('/mod/wiki/create.php', $params); redirect($url); } } //delete version if toversion and fromversion are set. if (!empty($toversion) && !empty($fromversion) && confirm_sesskey()) { //make sure all versions should not be deleted... $versioncount = wiki_count_wiki_page_versions($pageid); $versioncount -= 1; //ignore version 0 $totalversionstodelete = $toversion - $fromversion;
/** * Implements callback to reset course * * @param stdClass $data * @return boolean|array */ function wiki_reset_userdata($data) { global $CFG, $DB; require_once $CFG->dirroot . '/mod/wiki/pagelib.php'; require_once $CFG->dirroot . "/mod/wiki/locallib.php"; $componentstr = get_string('modulenameplural', 'wiki'); $status = array(); //get the wiki(s) in this course. if (!($wikis = $DB->get_records('wiki', array('course' => $data->courseid)))) { return false; } if (empty($data->reset_wiki_comments) && empty($data->reset_wiki_tags) && empty($data->reset_wiki_pages)) { return $status; } foreach ($wikis as $wiki) { if (!($cm = get_coursemodule_from_instance('wiki', $wiki->id, $data->courseid))) { continue; } $context = context_module::instance($cm->id); // Remove tags or all pages. if (!empty($data->reset_wiki_pages) || !empty($data->reset_wiki_tags)) { // Get subwiki information. $subwikis = wiki_get_subwikis($wiki->id); foreach ($subwikis as $subwiki) { // Get existing pages. if ($pages = wiki_get_page_list($subwiki->id)) { // If the wiki page isn't selected then we are only removing tags. if (empty($data->reset_wiki_pages)) { // Go through each page and delete the tags. foreach ($pages as $page) { core_tag_tag::remove_all_item_tags('mod_wiki', 'wiki_pages', $page->id); } } else { // Otherwise we are removing pages and tags. wiki_delete_pages($context, $pages, $subwiki->id); } } if (!empty($data->reset_wiki_pages)) { // Delete any subwikis. $DB->delete_records('wiki_subwikis', array('id' => $subwiki->id), IGNORE_MISSING); // Delete any attached files. $fs = get_file_storage(); $fs->delete_area_files($context->id, 'mod_wiki', 'attachments'); } } if (!empty($data->reset_wiki_pages)) { $status[] = array('component' => $componentstr, 'item' => get_string('deleteallpages', 'wiki'), 'error' => false); } if (!empty($data->reset_wiki_tags)) { $status[] = array('component' => $componentstr, 'item' => get_string('tagsdeleted', 'wiki'), 'error' => false); } } // Remove all comments. if (!empty($data->reset_wiki_comments) || !empty($data->reset_wiki_pages)) { $DB->delete_records_select('comments', "contextid = ? AND commentarea='wiki_page'", array($context->id)); if (!empty($data->reset_wiki_comments)) { $status[] = array('component' => $componentstr, 'item' => get_string('deleteallcomments'), 'error' => false); } } } return $status; }
/** * Test page_deleted and page_version_deleted and page_locks_deleted event. */ public function test_page_deleted() { global $DB; $this->setUp(); $page = $this->wikigenerator->create_first_page($this->wiki); $context = context_module::instance($this->wiki->cmid); $oldversions = $DB->get_records('wiki_versions', array('pageid' => $page->id)); $oldversion = array_shift($oldversions); // Triggering and capturing the event. $sink = $this->redirectEvents(); wiki_delete_pages($context, array($page->id)); $events = $sink->get_events(); $this->assertCount(4, $events); $event = array_shift($events); // Checking that the event contains the page_version_deleted event. $this->assertInstanceOf('\\mod_wiki\\event\\page_version_deleted', $event); $this->assertEquals($context, $event->get_context()); $this->assertEquals($page->id, $event->other['pageid']); $this->assertEquals($oldversion->id, $event->objectid); $expected = array($this->course->id, 'wiki', 'admin', 'admin.php?pageid=' . $page->id, $page->id, $this->wiki->cmid); $this->assertEventLegacyLogData($expected, $event); // Checking that the event contains the page_deleted event. $event = array_pop($events); $this->assertInstanceOf('\\mod_wiki\\event\\page_deleted', $event); $this->assertEquals($context, $event->get_context()); $this->assertEquals($page->id, $event->objectid); $expected = array($this->course->id, 'wiki', 'admin', 'admin.php?pageid=' . $page->id, $page->id, $this->wiki->cmid); $this->assertEventLegacyLogData($expected, $event); // Checking that the event contains the expected values. $event = array_pop($events); $this->assertInstanceOf('\\mod_wiki\\event\\page_locks_deleted', $event); $this->assertEquals($context, $event->get_context()); $this->assertEquals($page->id, $event->objectid); $expected = array($this->course->id, 'wiki', 'overridelocks', 'view.php?pageid=' . $page->id, $page->id, $this->wiki->cmid); $this->assertEventLegacyLogData($expected, $event); // Delete all pages. $page1 = $this->wikigenerator->create_first_page($this->wiki); $page2 = $this->wikigenerator->create_content($this->wiki); $page3 = $this->wikigenerator->create_content($this->wiki, array('title' => 'Custom title')); // Triggering and capturing the event. $sink = $this->redirectEvents(); wiki_delete_pages($context, array($page1->id, $page2->id)); $events = $sink->get_events(); $this->assertCount(8, $events); $event = array_pop($events); // Checking that the event contains the expected values. $this->assertInstanceOf('\\mod_wiki\\event\\page_deleted', $event); $this->assertEquals($context, $event->get_context()); $this->assertEquals($page2->id, $event->objectid); $expected = array($this->course->id, 'wiki', 'admin', 'admin.php?pageid=' . $page2->id, $page2->id, $this->wiki->cmid); $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); }