2 /// Extended by Michael Schneider
4 require_once("../../config.php");
5 require_once("lib.php");
7 $id = optional_param('id', '', PARAM_INT
); // Course Module ID, or
8 $a = optional_param('a', '', PARAM_INT
); // wiki ID
9 $page = optional_param('page', false, PARAM_CLEAN
); // Pagename
10 $confirm = optional_param('confirm', '', PARAM_RAW
);
11 $action = optional_param('action', '', PARAM_ACTION
); // Admin Action
12 $userid = optional_param('userid', 0, PARAM_INT
); // User wiki.
13 $groupid = optional_param('groupid', 0, PARAM_INT
); // Group wiki.
16 if (! $cm = get_coursemodule_from_id('wiki', $id)) {
17 error("Course Module ID was incorrect");
20 if (! $course = get_record("course", "id", $cm->course
)) {
21 error("Course is misconfigured");
24 if (! $wiki = get_record("wiki", "id", $cm->instance
)) {
25 error("Course module is incorrect");
29 if (! $wiki = get_record("wiki", "id", $a)) {
30 error("Course module is incorrect");
32 if (! $course = get_record("course", "id", $wiki->course
)) {
33 error("Course is misconfigured");
35 if (! $cm = get_coursemodule_from_instance("wiki", $wiki->id
, $course->id
)) {
36 error("Course Module ID was incorrect");
40 require_login($course->id
, false, $cm);
42 /// Build the ewsiki script constant
43 $ewbase = 'view.php?id='.$id;
44 if (isset($userid) && $userid!=0) $ewbase .= '&userid='.$userid;
45 if (isset($groupid) && $groupid!=0) $ewbase .= '&groupid='.$groupid;
46 $ewscript = $ewbase.'&page=';
47 define("EWIKI_SCRIPT", $ewscript);
48 if($wiki->ewikiacceptbinary
) {
49 define("EWIKI_UPLOAD_MAXSIZE", get_max_upload_file_size());
50 define("EWIKI_SCRIPT_BINARY", $ewbase."&binary=");
54 /// Add the course module 'groupmode' to the wiki object, for easy access.
55 $wiki->groupmode
= $cm->groupmode
;
57 /// Is an Action given ?
59 error(get_string("noadministrationaction","wiki"));
63 if(!in_array($action, array("setpageflags", "removepages", "strippages", "checklinks", "revertpages"))) {
64 error("Unknown action '$action'","wiki");
68 /// May the User administrate it ?
69 if (($wiki_entry = wiki_get_entry($wiki, $course, $userid, $groupid)) === false ||
wiki_can_edit_entry($wiki_entry, $wiki, $USER, $course) === false) {
70 error(get_string("notadministratewiki","wiki"));
73 $canedit = wiki_can_edit_entry($wiki_entry, $wiki, $USER, $course);
74 # Check for dangerous events (hacking) !
75 if(in_array($action,array("removepages","strippages","revertpages"))) {
76 if(!($wiki->wtype
=="student" ||
($wiki->wtype
=="group" and $canedit) ||
isteacher($course->id
))) {
77 add_to_log($course->id
, "wiki", "hack", "", $wiki->name
.": Tried to trick admin.php with action=$action.");
78 error("Hack attack detected !");
82 # Database and Binary Handler
83 include_once($CFG->dirroot
."/mod/wiki/ewikimoodlelib.php");
84 include_once($CFG->dirroot
."/mod/wiki/ewiki/plugins/moodle/moodle_binary_store.php");
86 /// The wiki_entry->pagename is set to the specified value of the wiki,
87 /// or the default value in the 'lang' file if the specified value was empty.
88 define("EWIKI_PAGE_INDEX",$wiki_entry->pagename
);
89 # The mighty Wiki itself
90 include_once($CFG->dirroot
."/mod/wiki/ewiki/ewiki.php");
92 $strwikis = get_string("modulenameplural", "wiki");
93 $strwiki = get_string("modulename", "wiki");
96 if ($form = data_submitted()) {
99 if(!$form->deleteversions ||
0 > $form->deleteversions ||
$form->deleteversions
> 1000) {
100 $focus="form.deleteversions";
101 $err->deleteversions
=get_string("deleteversionserror","wiki");
103 if(!$form->changesfield ||
0 > $form->changesfield ||
$form->changesfield
> 100000) {
104 $focus="form.changesfield";
105 $err->changesfield
=get_string("changesfielderror","wiki");
107 if($form->authorfieldpattern
=="") {
108 $focus="form.authorfieldpattern";
109 $err->authorfieldpattern
=get_string("authorfieldpatternerror","wiki");
116 print_header_simple("$wiki_entry->pagename", "",
117 "<A HREF=\"index.php?id=$course->id\">$strwikis</A> -> <A HREF=\"view.php?id=$id\">".format_string($wiki->name
,true)."</a> ->".
118 get_string("administration","wiki"),
119 $focus, "", true, update_module_button($cm->id
, $course->id
, $strwiki),
120 navmenu($course, $cm));
123 ////////////////////////////////////////////////////////////
124 /// Check if the Form has been submitted and display confirmation
125 ////////////////////////////////////////////////////////////
126 if ($form = data_submitted()) {
127 check_for_restricted_user($USER->username
, "$CFG->wwwroot/course/view.php?id=$course->id");
129 /// Get additional info
133 $addloginfo=@join
(", ", $form->pagestodelete
);
136 $addloginfo=@join
(", ", $form->pagestostrip
);
139 $addloginfo=$form->pagetocheck
;
142 // No additional info
145 // No additional info
148 add_to_log($course->id
, "wiki", $action, "admin.php?action=$action&userid=$userid&groupid=$groupid&id=$id", $wiki->name
.($addloginfo?
": ".$addloginfo:""));
149 $link="admin.php?action=$action".($userid?
"&userid=".$userid:"").($groupid?
"&groupid=".$groupid:"")."&id=$id&page=$page";
153 if(!$confirm && $form->pagestodelete
) {
154 notice_yesno(get_string("removepagecheck", "wiki")."<br />".join(", ", $form->pagestodelete
),
155 $link."&confirm=".urlencode(join(" ",$form->pagestodelete
)), $link);
156 print_footer($course);
163 if(!$confirm && $form->pagestostrip
) {
165 $strippages=wiki_admin_strip_versions($form->pagestostrip
,$form->version
, $err);
167 foreach($strippages as $cnfid => $cnfver) {
168 $confirm.="&confirm[$cnfid]=".urlencode(join(" ",$cnfver));
171 notice_yesno(get_string("strippagecheck", "wiki")."<br />".join(", ", $form->pagestostrip
),
172 $link.$confirm, $link);
173 print_footer($course);
181 if(!$confirm && $form->pagetocheck
) {
182 $confirm="&confirm=".$form->pagetocheck
;
183 notice_yesno(get_string("checklinkscheck", "wiki").$form->pagetocheck
,
184 $link.$confirm, $link);
185 print_footer($course);
191 // pageflagstatus is used in setpageflags.html
192 $pageflagstatus=wiki_admin_setpageflags($form->flags
);
197 $confirm="&confirm[changesfield]=".urlencode($form->changesfield
).
198 "&confirm[authorfieldpattern]=".urlencode($form->authorfieldpattern
).
199 "&confirm[howtooperate]=".urlencode($form->howtooperate
).
200 "&confirm[deleteversions]=".urlencode($form->deleteversions
);
201 $revertedpages=wiki_admin_revert("", $form->authorfieldpattern
, $form->changesfield
, $form->howtooperate
, $form->deleteversions
);
203 notice_yesno(get_string("revertpagescheck", "wiki")."<br />".$revertedpages,
204 $link.$confirm, $link);
205 print_footer($course);
208 $err->remark
=get_string("nochangestorevert","wiki");
213 default: error("No such Wiki-Admin action: $action");
218 /// Actions which need a confirmation. If confirmed, do the action
219 $redirect="view.php?".($groupid?
"&groupid=".$groupid:"").($userid?
"&userid=".$userid:"")."&id=$id&page=$page";
220 if($confirm && !$err) {
223 $ret=wiki_admin_remove(split(" ",$confirm), $course, $wiki, $userid, $groupid);
225 redirect($redirect, get_string("pagesremoved","wiki"), 1);
232 foreach($confirm as $pageid => $versions) {
233 $strippages[$pageid]=split(" ",$versions);
235 $ret=wiki_admin_strip($strippages);
237 redirect($redirect, get_string("pagesstripped","wiki"), 1);
243 $ret=wiki_admin_checklinks($confirm);
244 redirect($redirect, get_string("linkschecked","wiki")."<br />".$ret, 5);
247 $revertedpages=wiki_admin_revert(1, $confirm["authorfieldpattern"], $confirm["changesfield"], $confirm["howtooperate"], $confirm["deleteversions"]);
248 redirect($redirect, get_string("pagesreverted","wiki"), 1);
251 # No confirmation needed
253 default: error("No such action '$action' with confirmation");
258 /// The top row contains links to other wikis, if applicable.
259 if ($wiki_list = wiki_get_other_wikis($wiki, $USER, $course, $wiki_entry->id
)) {
260 if (isset($wiki_list['selected'])) {
261 $selected = $wiki_list['selected'];
262 unset($wiki_list['selected']);
264 echo '<tr><td colspan="2">';
266 echo '<form name="otherwikis" action="'.$CFG->wwwroot
.'/mod/wiki/admin.php">';
267 echo '<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr>';
268 echo '<td class="sideblockheading"> '
269 .$WIKI_TYPES[$wiki->wtype
].' '
270 .get_string('modulename', 'wiki').' for '
271 .wiki_get_owner($wiki_entry).':</td>';
273 echo '<td class="sideblockheading" align="right">'
274 .get_string('otherwikis', 'wiki').': ';
275 $script = 'self.location=document.otherwikis.wikiselect.options[document.otherwikis.wikiselect.selectedIndex].value';
279 $wiki_admin_list=array();
280 while(list($key,$val)=each($wiki_list)) {
281 $wiki_admin_list[$key."&action=$action"]=$val;
283 choose_from_menu($wiki_admin_list, "wikiselect", $selected, "choose", $script);
285 echo '</tr></table>';
296 echo '<table border="0" width="100%">';
298 # echo '<tr><td align="center">';
299 # $specialpages=array("SearchPages", "PageIndex","NewestPages","MostVisitedPages","MostOftenChangedPages","UpdatedPages","FileDownload","FileUpload","OrphanedPages","WantedPages");
300 # wiki_print_page_actions($cm->id, $specialpages, $ewiki_id, $ewiki_action, $wiki->ewikiacceptbinary, $canedit);
304 echo '<td align="center">';
305 wiki_print_search_form($cm->id
, $q, $userid, $groupid, false);
308 /// Internal Wikilinks
310 /// TODO: DOES NOT WORK !!!!
311 echo '<td align="center">';
312 wiki_print_wikilinks_block($cm->id
, $wiki->ewikiacceptbinary
);
315 /// Administrative Links
316 echo '<td align="center">';
317 wiki_print_administration_actions($wiki, $cm->id
, $userid, $groupid, $page, $wiki->htmlmode
!=2, $course);
320 # if($wiki->htmlmode!=2) {
321 # echo '<td align="center">';
322 # helpbutton('formattingrules', get_string('formattingrules', 'wiki'), 'wiki');
323 # echo get_string("formattingrules","wiki");
327 echo '</tr></table>';
331 print_simple_box_start( 'center', '100%', '', '20');
333 # "setpageflags", "removepages", "strippages", "checklinks", "revertpages"
334 print_heading_with_help(get_string($action,"wiki"), $action, "wiki");
335 include $action.".html";
336 print_simple_box_end();
339 print_footer($course);