MDL-48204 mod_wiki: admin.php - fix syntax error
[moodle.git] / mod / wiki / admin.php
CommitLineData
ac0a82cf
RT
1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * Delete wiki pages or versions
20 *
21 * This will show options for deleting wiki pages or purging page versions
22 * If user have wiki:managewiki ability then only this page will show delete
23 * options
24 *
593b8385 25 * @package mod_wiki
ac0a82cf
RT
26 * @copyright 2011 Rajesh Taneja
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 */
29
30require_once('../../config.php');
31require_once($CFG->dirroot . '/mod/wiki/lib.php');
32require_once($CFG->dirroot . '/mod/wiki/locallib.php');
33require_once($CFG->dirroot . '/mod/wiki/pagelib.php');
34
35$pageid = required_param('pageid', PARAM_INT); // Page ID
36$delete = optional_param('delete', 0, PARAM_INT); // ID of the page to be deleted.
37$option = optional_param('option', 1, PARAM_INT); // Option ID
38$listall = optional_param('listall', 0, PARAM_INT); // list all pages
39$toversion = optional_param('toversion', 0, PARAM_INT); // max version to be deleted
40$fromversion = optional_param('fromversion', 0, PARAM_INT); // min version to be deleted
41
42if (!$page = wiki_get_page($pageid)) {
43 print_error('incorrectpageid', 'wiki');
44}
45if (!$subwiki = wiki_get_subwiki($page->subwikiid)) {
46 print_error('incorrectsubwikiid', 'wiki');
47}
48if (!$cm = get_coursemodule_from_instance("wiki", $subwiki->wikiid)) {
49 print_error('invalidcoursemodule');
50}
74df2951 51$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
ac0a82cf
RT
52if (!$wiki = wiki_get_wiki($subwiki->wikiid)) {
53 print_error('incorrectwikiid', 'wiki');
54}
55
cdbea7ee 56require_login($course, true, $cm);
ac0a82cf 57
3a7b9b76
MG
58if (!wiki_user_can_view($subwiki, $wiki)) {
59 print_error('cannotviewpage', 'wiki');
60}
ac0a82cf 61
1df23626 62$context = context_module::instance($cm->id);
ac0a82cf 63require_capability('mod/wiki:managewiki', $context);
476aea8d 64
ac0a82cf
RT
65//Delete page if a page ID to delete was supplied
66if (!empty($delete) && confirm_sesskey()) {
a481e32f
JO
67 if ($pageid != $delete) {
68 // Validate that we are deleting from the same subwiki.
8309373c 69 $deletepage = wiki_get_page($delete);
a481e32f
JO
70 if (!$deletepage || $deletepage->subwikiid != $page->subwikiid) {
71 print_error('incorrectsubwikiid', 'wiki');
72 }
73 }
ac0a82cf
RT
74 wiki_delete_pages($context, $delete, $page->subwikiid);
75 //when current wiki page is deleted, then redirect user to create that page, as
76 //current pageid is invalid after deletion.
77 if ($pageid == $delete) {
78 $params = array('swid' => $page->subwikiid, 'title' => $page->title);
79 $url = new moodle_url('/mod/wiki/create.php', $params);
80 redirect($url);
81 }
82}
83
84//delete version if toversion and fromversion are set.
85if (!empty($toversion) && !empty($fromversion) && confirm_sesskey()) {
86 //make sure all versions should not be deleted...
87 $versioncount = wiki_count_wiki_page_versions($pageid);
88 $versioncount -= 1; //ignore version 0
89 $totalversionstodelete = $toversion - $fromversion;
90 $totalversionstodelete += 1; //added 1 as toversion should be included
91
92 if (($totalversionstodelete >= $versioncount) || ($versioncount <= 1)) {
93 print_error('incorrectdeleteversions', 'wiki');
94 } else {
95 $versions = array();
96 for ($i = $fromversion; $i <= $toversion; $i++) {
97 //Add all version to deletion list which exist
98 if (wiki_get_wiki_page_version($pageid, $i)) {
99 array_push($versions, $i);
100 }
101 }
102 $purgeversions[$pageid] = $versions;
d6a54be3 103 wiki_delete_page_versions($purgeversions, $context);
ac0a82cf
RT
104 }
105}
106
107//show actual page
108$wikipage = new page_wiki_admin($wiki, $subwiki, $cm);
109
110$wikipage->set_page($page);
111$wikipage->print_header();
112$wikipage->set_view($option, empty($listall)?true:false);
113$wikipage->print_content();
114
a481e32f 115$wikipage->print_footer();