2 /// Extended by Michael Schneider
4 require_once("../../config.php");
5 require_once("lib.php");
7 optional_variable($id); // Course Module ID, or
8 optional_variable($a); // wiki ID
9 optional_variable($page, false); // Pagename
10 optional_variable($confirm, "");
11 optional_variable($action,""); // Admin Action
12 optional_variable($userid, 0); // User wiki.
13 optional_variable($groupid, 0); // Group wiki.
15 $action = clean_text($action);
18 if (! $cm = get_record("course_modules", "id", $id)) {
19 error("Course Module ID was incorrect");
22 if (! $course = get_record("course", "id", $cm->course
)) {
23 error("Course is misconfigured");
26 if (! $wiki = get_record("wiki", "id", $cm->instance
)) {
27 error("Course module is incorrect");
31 if (! $wiki = get_record("wiki", "id", $a)) {
32 error("Course module is incorrect");
34 if (! $course = get_record("course", "id", $wiki->course
)) {
35 error("Course is misconfigured");
37 if (! $cm = get_coursemodule_from_instance("wiki", $wiki->id
, $course->id
)) {
38 error("Course Module ID was incorrect");
42 require_login($course->id
, false, $cm);
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 # Check for dangerous events (hacking) !
76 if(in_array($action,array("removepages","strippages","revertpages"))) {
77 if(!($wiki->wtype
=="student" ||
isteacher($course->id
))) {
78 add_to_log($course->id
, "wiki", "hack", "", $wiki->name
.": Tried to trick admin.php with action=$action.");
79 error("Hack attack detected !");
83 # Database and Binary Handler
84 include_once($CFG->dirroot
."/mod/wiki/ewikimoodlelib.php");
85 include_once($CFG->dirroot
."/mod/wiki/ewiki/plugins/moodle/moodle_binary_store.php");
87 /// The wiki_entry->pagename is set to the specified value of the wiki,
88 /// or the default value in the 'lang' file if the specified value was empty.
89 define("EWIKI_PAGE_INDEX",$wiki_entry->pagename
);
90 # The mighty Wiki itself
91 include_once($CFG->dirroot
."/mod/wiki/ewiki/ewiki.php");
93 $strwikis = get_string("modulenameplural", "wiki");
94 $strwiki = get_string("modulename", "wiki");
97 if ($form = data_submitted()) {
100 if(!$form->deleteversions ||
0 > $form->deleteversions ||
$form->deleteversions
> 1000) {
101 $focus="form.deleteversions";
102 $err->deleteversions
=get_string("deleteversionserror","wiki");
104 if(!$form->changesfield ||
0 > $form->changesfield ||
$form->changesfield
> 100000) {
105 $focus="form.changesfield";
106 $err->changesfield
=get_string("changesfielderror","wiki");
108 if($form->authorfieldpattern
=="") {
109 $focus="form.authorfieldpattern";
110 $err->authorfieldpattern
=get_string("authorfieldpatternerror","wiki");
117 print_header_simple("$wiki_entry->pagename", "",
118 "<A HREF=\"index.php?id=$course->id\">$strwikis</A> -> <A HREF=\"view.php?id=$id\">".format_string($wiki->name
,true)."</a> ->".
119 get_string("administration","wiki"),
120 $focus, "", true, update_module_button($cm->id
, $course->id
, $strwiki),
121 navmenu($course, $cm));
124 ////////////////////////////////////////////////////////////
125 /// Check if the Form has been submitted and display confirmation
126 ////////////////////////////////////////////////////////////
127 if ($form = data_submitted()) {
128 check_for_restricted_user($USER->username
, "$CFG->wwwroot/course/view.php?id=$course->id");
130 /// Get additional info
134 $addloginfo=@join
(", ", $form->pagestodelete
);
137 $addloginfo=@join
(", ", $form->pagestostrip
);
140 $addloginfo=$form->pagetocheck
;
143 // No additional info
146 // No additional info
149 add_to_log($course->id
, "wiki", $action, "admin.php?action=$action&userid=$userid&groupid=$groupid&id=$id", $wiki->name
.($addloginfo?
": ".$addloginfo:""));
150 $link="admin.php?action=$action".($userid?
"&userid=".$userid:"").($groupid?
"&groupid=".$groupid:"")."&id=$id&page=$page";
154 if(!$confirm && $form->pagestodelete
) {
155 notice_yesno(get_string("removepagecheck", "wiki")."<br />".join(", ", $form->pagestodelete
),
156 $link."&confirm=".urlencode(join(" ",$form->pagestodelete
)), $link);
157 print_footer($course);
164 if(!$confirm && $form->pagestostrip
) {
166 $strippages=wiki_admin_strip_versions($form->pagestostrip
,$form->version
, $err);
168 foreach($strippages as $cnfid => $cnfver) {
169 $confirm.="&confirm[$cnfid]=".urlencode(join(" ",$cnfver));
172 notice_yesno(get_string("strippagecheck", "wiki")."<br />".join(", ", $form->pagestostrip
),
173 $link.$confirm, $link);
174 print_footer($course);
182 if(!$confirm && $form->pagetocheck
) {
183 $confirm="&confirm=".$form->pagetocheck
;
184 notice_yesno(get_string("checklinkscheck", "wiki").$form->pagetocheck
,
185 $link.$confirm, $link);
186 print_footer($course);
192 // pageflagstatus is used in setpageflags.html
193 $pageflagstatus=wiki_admin_setpageflags($form->flags
);
198 $confirm="&confirm[changesfield]=".urlencode($form->changesfield
).
199 "&confirm[authorfieldpattern]=".urlencode($form->authorfieldpattern
).
200 "&confirm[howtooperate]=".urlencode($form->howtooperate
).
201 "&confirm[deleteversions]=".urlencode($form->deleteversions
);
202 $revertedpages=wiki_admin_revert("", $form->authorfieldpattern
, $form->changesfield
, $form->howtooperate
, $form->deleteversions
);
204 notice_yesno(get_string("revertpagescheck", "wiki")."<br />".$revertedpages,
205 $link.$confirm, $link);
206 print_footer($course);
209 $err->remark
=get_string("nochangestorevert","wiki");
214 default: error("No such Wiki-Admin action: $action");
219 /// Actions which need a confirmation. If confirmed, do the action
220 $redirect="view.php?".($groupid?
"&groupid=".$groupid:"").($userid?
"&userid=".$userid:"")."&id=$id&page=$page";
221 if($confirm && !$err) {
224 $ret=wiki_admin_remove(split(" ",$confirm), $course, $wiki, $userid, $groupid);
226 redirect($redirect, get_string("pagesremoved","wiki"), 1);
233 foreach($confirm as $pageid => $versions) {
234 $strippages[$pageid]=split(" ",$versions);
236 $ret=wiki_admin_strip($strippages);
238 redirect($redirect, get_string("pagesstripped","wiki"), 1);
244 $ret=wiki_admin_checklinks($confirm);
245 redirect($redirect, get_string("linkschecked","wiki")."<br />".$ret, 5);
248 $revertedpages=wiki_admin_revert(1, $confirm["authorfieldpattern"], $confirm["changesfield"], $confirm["howtooperate"], $confirm["deleteversions"]);
249 redirect($redirect, get_string("pagesreverted","wiki"), 1);
252 # No confirmation needed
254 default: error("No such action '$action' with confirmation");
259 /// The top row contains links to other wikis, if applicable.
260 if ($wiki_list = wiki_get_other_wikis($wiki, $USER, $course, $wiki_entry->id
)) {
261 if (isset($wiki_list['selected'])) {
262 $selected = $wiki_list['selected'];
263 unset($wiki_list['selected']);
265 echo '<tr><td colspan="2">';
267 echo '<form name="otherwikis" action="'.$CFG->wwwroot
.'/mod/wiki/admin.php">';
268 echo '<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr>';
269 echo '<td class="sideblockheading"> '
270 .$WIKI_TYPES[$wiki->wtype
].' '
271 .get_string('modulename', 'wiki').' for '
272 .wiki_get_owner($wiki_entry).':</td>';
274 echo '<td class="sideblockheading" align="right">'
275 .get_string('otherwikis', 'wiki').': ';
276 $script = 'self.location=document.otherwikis.wikiselect.options[document.otherwikis.wikiselect.selectedIndex].value';
280 $wiki_admin_list=array();
281 while(list($key,$val)=each($wiki_list)) {
282 $wiki_admin_list[$key."&action=$action"]=$val;
284 choose_from_menu($wiki_admin_list, "wikiselect", $selected, "choose", $script);
286 echo '</tr></table>';
297 echo '<table border="0" width="100%">';
299 # echo '<tr><td align="center">';
300 # $specialpages=array("SearchPages", "PageIndex","NewestPages","MostVisitedPages","MostOftenChangedPages","UpdatedPages","FileDownload","FileUpload","OrphanedPages","WantedPages");
301 # wiki_print_page_actions($cm->id, $specialpages, $ewiki_id, $ewiki_action, $wiki->ewikiacceptbinary, $canedit);
305 echo '<td align="center">';
306 wiki_print_search_form($cm->id
, $q, $userid, $groupid, false);
309 /// Internal Wikilinks
311 /// TODO: DOES NOT WORK !!!!
312 echo '<td align="center">';
313 wiki_print_wikilinks_block($cm->id
, $wiki->ewikiacceptbinary
);
316 /// Administrative Links
317 echo '<td align="center">';
318 wiki_print_administration_actions($wiki, $cm->id
, $userid, $groupid, $page, $wiki->htmlmode
!=2, $course);
321 # if($wiki->htmlmode!=2) {
322 # echo '<td align="center">';
323 # helpbutton('formattingrules', get_string('formattingrules', 'wiki'), 'wiki');
324 # echo get_string("formattingrules","wiki");
328 echo '</tr></table>';
332 print_simple_box_start( 'center', '100%', '', '20');
334 # "setpageflags", "removepages", "strippages", "checklinks", "revertpages"
335 print_heading_with_help(get_string($action,"wiki"), $action, "wiki");
336 include $action.".html";
337 print_simple_box_end();
340 print_footer($course);