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);
41 $context = get_context_instance(CONTEXT_MODULE
, $cm->id
);
42 require_capability('mod/wiki:manage', $context);
44 /// Build the ewsiki script constant
45 $ewbase = 'view.php?id='.$id;
46 if (isset($userid) && $userid!=0) $ewbase .= '&userid='.$userid;
47 if (isset($groupid) && $groupid!=0) $ewbase .= '&groupid='.$groupid;
48 $ewscript = $ewbase.'&page=';
49 define("EWIKI_SCRIPT", $ewscript);
50 if($wiki->ewikiacceptbinary
) {
51 define("EWIKI_UPLOAD_MAXSIZE", get_max_upload_file_size());
52 define("EWIKI_SCRIPT_BINARY", $ewbase."&binary=");
56 /// Add the course module 'groupmode' to the wiki object, for easy access.
57 $wiki->groupmode
= $cm->groupmode
;
59 /// Is an Action given ?
61 error(get_string("noadministrationaction","wiki"));
65 if(!in_array($action, array("setpageflags", "removepages", "strippages", "checklinks", "revertpages"))) {
66 error("Unknown action '$action'","wiki");
70 /// May the User administrate it ?
71 if (($wiki_entry = wiki_get_entry($wiki, $course, $userid, $groupid)) === false ||
wiki_can_edit_entry($wiki_entry, $wiki, $USER, $course) === false) {
72 error(get_string("notadministratewiki","wiki"));
75 $canedit = wiki_can_edit_entry($wiki_entry, $wiki, $USER, $course);
76 # Check for dangerous events (hacking) !
77 if(in_array($action,array("removepages","strippages","revertpages"))) {
78 if(!($wiki->wtype
=="student" ||
($wiki->wtype
=="group" and $canedit) ||
wiki_is_teacher($wiki))) {
79 add_to_log($course->id
, "wiki", "hack", "", $wiki->name
.": Tried to trick admin.php with action=$action.");
80 error("Hack attack detected !");
84 # Database and Binary Handler
85 include_once($CFG->dirroot
."/mod/wiki/ewikimoodlelib.php");
86 include_once($CFG->dirroot
."/mod/wiki/ewiki/plugins/moodle/moodle_binary_store.php");
88 /// The wiki_entry->pagename is set to the specified value of the wiki,
89 /// or the default value in the 'lang' file if the specified value was empty.
90 define("EWIKI_PAGE_INDEX",$wiki_entry->pagename
);
91 # The mighty Wiki itself
92 include_once($CFG->dirroot
."/mod/wiki/ewiki/ewiki.php");
94 $strwikis = get_string("modulenameplural", "wiki");
95 $strwiki = get_string("modulename", "wiki");
98 if ($form = data_submitted()) {
101 if(!$form->deleteversions ||
0 > $form->deleteversions ||
$form->deleteversions
> 1000) {
102 $focus="form.deleteversions";
103 $err->deleteversions
=get_string("deleteversionserror","wiki");
105 if(!$form->changesfield ||
0 > $form->changesfield ||
$form->changesfield
> 100000) {
106 $focus="form.changesfield";
107 $err->changesfield
=get_string("changesfielderror","wiki");
109 if($form->authorfieldpattern
=="") {
110 $focus="form.authorfieldpattern";
111 $err->authorfieldpattern
=get_string("authorfieldpatternerror","wiki");
118 $navlinks[] = array('name' => $strwikis, 'link' => "index.php?id=$course->id", 'type' => 'activity');
119 $navlinks[] = array('name' => format_string($wiki->name
,true), 'link' => "view.php?id=$moodleID", 'type' => 'activityinstace');
120 $navlinks[] = array('name' => get_string("administration","wiki"), 'link' => '', 'type' => 'title');
122 $navigation = build_navigation($navlinks);
124 print_header_simple("$wiki_entry->pagename", "", $navigation,
125 $focus, "", true, update_module_button($cm->id
, $course->id
, $strwiki),
126 navmenu($course, $cm));
129 ////////////////////////////////////////////////////////////
130 /// Check if the Form has been submitted and display confirmation
131 ////////////////////////////////////////////////////////////
132 if ($form = data_submitted()) {
134 /// Get additional info
138 $addloginfo=@join
(", ", $form->pagestodelete
);
141 $addloginfo=@join
(", ", $form->pagestostrip
);
144 $addloginfo=$form->pagetocheck
;
147 // No additional info
150 // No additional info
153 add_to_log($course->id
, "wiki", $action, "admin.php?action=$action&userid=$userid&groupid=$groupid&id=$id", $wiki->name
.($addloginfo?
": ".$addloginfo:""));
154 $link="admin.php?action=$action".($userid?
"&userid=".$userid:"").($groupid?
"&groupid=".$groupid:"")."&id=$id&page=$page";
158 if(!$confirm && $form->pagestodelete
) {
159 notice_yesno(get_string("removepagecheck", "wiki")."<br />".join(", ", $form->pagestodelete
),
160 $link."&confirm=".urlencode(join(" ",$form->pagestodelete
)), $link);
161 print_footer($course);
168 if(!$confirm && $form->pagestostrip
) {
170 $strippages=wiki_admin_strip_versions($form->pagestostrip
,$form->version
, $err);
172 foreach($strippages as $cnfid => $cnfver) {
173 $confirm.="&confirm[$cnfid]=".urlencode(join(" ",$cnfver));
176 $pagestostrip=array();
177 foreach($form->pagestostrip
as $pagetostrip) {
178 $pagestostrip[]=htmlspecialchars(urldecode($pagetostrip));
180 notice_yesno(get_string("strippagecheck", "wiki")."<br />".join(", ", $pagestostrip),
181 $link.$confirm, $link);
182 print_footer($course);
190 if(!$confirm && $form->pagetocheck
) {
191 $confirm="&confirm=".$form->pagetocheck
;
192 notice_yesno(get_string("checklinkscheck", "wiki").$form->pagetocheck
,
193 $link.$confirm, $link);
194 print_footer($course);
200 // pageflagstatus is used in setpageflags.html
201 $pageflagstatus=wiki_admin_setpageflags($form->flags
);
206 $confirm="&confirm[changesfield]=".urlencode($form->changesfield
).
207 "&confirm[authorfieldpattern]=".urlencode($form->authorfieldpattern
).
208 "&confirm[howtooperate]=".urlencode($form->howtooperate
).
209 "&confirm[deleteversions]=".urlencode($form->deleteversions
);
210 $revertedpages=wiki_admin_revert("", $form->authorfieldpattern
, $form->changesfield
, $form->howtooperate
, $form->deleteversions
);
212 notice_yesno(get_string("revertpagescheck", "wiki")."<br />".$revertedpages,
213 $link.$confirm, $link);
214 print_footer($course);
217 $err->remark
=get_string("nochangestorevert","wiki");
222 default: error("No such Wiki-Admin action: $action");
227 /// Actions which need a confirmation. If confirmed, do the action
228 $redirect="view.php?".($groupid?
"&groupid=".$groupid:"").($userid?
"&userid=".$userid:"")."&id=$id&page=$page";
229 if($confirm && !$err) {
232 $ret=wiki_admin_remove(split(" ",$confirm), $course, $wiki, $userid, $groupid);
234 redirect($redirect, get_string("pagesremoved","wiki"), 1);
241 foreach($confirm as $pageid => $versions) {
242 $strippages[$pageid]=split(" ",$versions);
244 $ret=wiki_admin_strip($strippages);
246 redirect($redirect, get_string("pagesstripped","wiki"), 1);
252 $ret=wiki_admin_checklinks($confirm);
253 redirect($redirect, get_string("linkschecked","wiki")."<br />".$ret, 5);
256 $revertedpages=wiki_admin_revert(1, $confirm["authorfieldpattern"], $confirm["changesfield"], $confirm["howtooperate"], $confirm["deleteversions"]);
257 redirect($redirect, get_string("pagesreverted","wiki"), 1);
260 # No confirmation needed
262 default: error("No such action '$action' with confirmation");
267 /// The top row contains links to other wikis, if applicable.
268 if ($wiki_list = wiki_get_other_wikis($wiki, $USER, $course, $wiki_entry->id
)) {
269 if (isset($wiki_list['selected'])) {
270 $selected = $wiki_list['selected'];
271 unset($wiki_list['selected']);
273 echo '<tr><td colspan="2">';
275 echo '<form id="otherwikis" action="'.$CFG->wwwroot
.'/mod/wiki/admin.php">';
276 echo '<fieldset class="invisiblefieldset">';
277 echo '<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr>';
278 echo '<td class="sideblockheading"> '
279 .$WIKI_TYPES[$wiki->wtype
].' '
280 .get_string('modulename', 'wiki').' for '
281 .wiki_get_owner($wiki_entry).':</td>';
283 echo '<td class="sideblockheading" align="right">'
284 .get_string('otherwikis', 'wiki').': ';
285 $script = 'self.location=getElementById(\'otherwikis\').wikiselect.options[getElementById(\'otherwikis\').wikiselect.selectedIndex].value';
289 $wiki_admin_list=array();
290 while(list($key,$val)=each($wiki_list)) {
291 $wiki_admin_list[$key."&action=$action"]=$val;
293 choose_from_menu($wiki_admin_list, "wikiselect", $selected, "choose", $script);
295 echo '</tr></table>';
296 echo '</fieldset></form>';
306 echo '<table border="0" width="100%">';
308 # echo '<tr><td align="center">';
309 # $specialpages=array("SearchPages", "PageIndex","NewestPages","MostVisitedPages","MostOftenChangedPages","UpdatedPages","FileDownload","FileUpload","OrphanedPages","WantedPages");
310 # wiki_print_page_actions($cm->id, $specialpages, $ewiki_id, $ewiki_action, $wiki->ewikiacceptbinary, $canedit);
314 echo '<td align="center">';
315 wiki_print_search_form($cm->id
, $q, $userid, $groupid, false);
318 /// Internal Wikilinks
320 /// TODO: DOES NOT WORK !!!!
321 echo '<td align="center">';
322 wiki_print_wikilinks_block($cm->id
, $wiki->ewikiacceptbinary
);
325 /// Administrative Links
326 echo '<td align="center">';
327 wiki_print_administration_actions($wiki, $cm->id
, $userid, $groupid, $page, $wiki->htmlmode
!=2, $course);
330 # if($wiki->htmlmode!=2) {
331 # echo '<td align="center">';
332 # helpbutton('formattingrules', get_string('formattingrules', 'wiki'), 'wiki');
333 # echo get_string("formattingrules","wiki");
337 echo '</tr></table>';
341 print_simple_box_start( 'center', '100%', '', '20');
343 # "setpageflags", "removepages", "strippages", "checklinks", "revertpages"
344 print_heading_with_help(get_string($action,"wiki"), $action, "wiki");
345 include $action.".html";
346 print_simple_box_end();
349 print_footer($course);