Automatic installer.php lang files by installer_builder (20070310)
[moodle.git] / mod / wiki / admin.php
blobde78172d865e004b3931ff88593cef929567e8b8
1 <?PHP // $Id$
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.
15 if ($id) {
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");
28 } else {
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 .= '&amp;userid='.$userid;
45 if (isset($groupid) && $groupid!=0) $ewbase .= '&amp;groupid='.$groupid;
46 $ewscript = $ewbase.'&amp;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 ?
58 if(!$action) {
59 error(get_string("noadministrationaction","wiki"));
62 /// Correct Action ?
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");
95 /// Validate Form
96 if ($form = data_submitted()) {
97 switch($action) {
98 case "revertpages":
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");
111 break;
112 default: break;
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");
128 /// Moodle Log
129 /// Get additional info
130 $addloginfo="";
131 switch($action) {
132 case "removepages":
133 $addloginfo=@join(", ", $form->pagestodelete);
134 break;
135 case "strippages":
136 $addloginfo=@join(", ", $form->pagestostrip);
137 break;
138 case "checklinks":
139 $addloginfo=$form->pagetocheck;
140 break;
141 case "setpageflags":
142 // No additional info
143 break;
144 case "revertpages":
145 // No additional info
146 break;
148 add_to_log($course->id, "wiki", $action, "admin.php?action=$action&amp;userid=$userid&amp;groupid=$groupid&amp;id=$id", $wiki->name.($addloginfo?": ".$addloginfo:""));
149 $link="admin.php?action=$action".($userid?"&amp;userid=".$userid:"").($groupid?"&amp;groupid=".$groupid:"")."&amp;id=$id&amp;page=$page";
150 switch($action) {
151 case "removepages":
152 if($form->proceed) {
153 if(!$confirm && $form->pagestodelete) {
154 notice_yesno(get_string("removepagecheck", "wiki")."<br />".join(", ", $form->pagestodelete),
155 $link."&amp;confirm=".urlencode(join(" ",$form->pagestodelete)), $link);
156 print_footer($course);
157 exit;
160 break;
161 case "strippages":
162 if($form->proceed) {
163 if(!$confirm && $form->pagestostrip) {
164 $err=array();
165 $strippages=wiki_admin_strip_versions($form->pagestostrip,$form->version, $err);
166 $confirm="";
167 foreach($strippages as $cnfid => $cnfver) {
168 $confirm.="&confirm[$cnfid]=".urlencode(join(" ",$cnfver));
170 if(count($err)==0) {
171 notice_yesno(get_string("strippagecheck", "wiki")."<br />".join(", ", $form->pagestostrip),
172 $link.$confirm, $link);
173 print_footer($course);
174 exit;
178 break;
179 case "checklinks":
180 if($form->proceed) {
181 if(!$confirm && $form->pagetocheck) {
182 $confirm="&amp;confirm=".$form->pagetocheck;
183 notice_yesno(get_string("checklinkscheck", "wiki").$form->pagetocheck,
184 $link.$confirm, $link);
185 print_footer($course);
186 exit;
189 break;
190 case "setpageflags":
191 // pageflagstatus is used in setpageflags.html
192 $pageflagstatus=wiki_admin_setpageflags($form->flags);
193 break;
194 case "revertpages":
195 if(!$err) {
196 if(!$confirm) {
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);
202 if($revertedpages) {
203 notice_yesno(get_string("revertpagescheck", "wiki")."<br />".$revertedpages,
204 $link.$confirm, $link);
205 print_footer($course);
206 exit;
207 } else {
208 $err->remark=get_string("nochangestorevert","wiki");
212 break;
213 default: error("No such Wiki-Admin action: $action");
214 break;
218 /// Actions which need a confirmation. If confirmed, do the action
219 $redirect="view.php?".($groupid?"&amp;groupid=".$groupid:"").($userid?"&amp;userid=".$userid:"")."&amp;id=$id&amp;page=$page";
220 if($confirm && !$err) {
221 switch($action) {
222 case "removepages":
223 $ret=wiki_admin_remove(split(" ",$confirm), $course, $wiki, $userid, $groupid);
224 if(!$ret) {
225 redirect($redirect, get_string("pagesremoved","wiki"), 1);
226 } else {
227 error($ret);
229 exit;
230 case "strippages":
231 $strippages=array();
232 foreach($confirm as $pageid => $versions) {
233 $strippages[$pageid]=split(" ",$versions);
235 $ret=wiki_admin_strip($strippages);
236 if(!$ret) {
237 redirect($redirect, get_string("pagesstripped","wiki"), 1);
238 } else {
239 error($ret);
241 exit;
242 case "checklinks":
243 $ret=wiki_admin_checklinks($confirm);
244 redirect($redirect, get_string("linkschecked","wiki")."<br />".$ret, 5);
245 exit;
246 case "revertpages":
247 $revertedpages=wiki_admin_revert(1, $confirm["authorfieldpattern"], $confirm["changesfield"], $confirm["howtooperate"], $confirm["deleteversions"]);
248 redirect($redirect, get_string("pagesreverted","wiki"), 1);
249 exit;
250 case "setpageflags":
251 # No confirmation needed
252 break;
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">&nbsp;'
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').':&nbsp;&nbsp;';
275 $script = 'self.location=document.otherwikis.wikiselect.options[document.otherwikis.wikiselect.selectedIndex].value';
277 /// Add Admin-Action
278 reset($wiki_list);
279 $wiki_admin_list=array();
280 while(list($key,$val)=each($wiki_list)) {
281 $wiki_admin_list[$key."&amp;action=$action"]=$val;
283 choose_from_menu($wiki_admin_list, "wikiselect", $selected, "choose", $script);
284 echo '</td>';
285 echo '</tr></table>';
286 echo '</form>';
288 echo '</td>';
289 echo '</tr>';
292 if ($wiki_entry) {
295 /// Page Actions
296 echo '<table border="0" width="100%">';
297 echo '<tr>';
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);
301 # echo '</td>';
303 /// Searchform
304 echo '<td align="center">';
305 wiki_print_search_form($cm->id, $q, $userid, $groupid, false);
306 echo '</td>';
308 /// Internal Wikilinks
310 /// TODO: DOES NOT WORK !!!!
311 echo '<td align="center">';
312 wiki_print_wikilinks_block($cm->id, $wiki->ewikiacceptbinary);
313 echo '</td>';
315 /// Administrative Links
316 echo '<td align="center">';
317 wiki_print_administration_actions($wiki, $cm->id, $userid, $groupid, $page, $wiki->htmlmode!=2, $course);
318 echo '</td>';
320 # if($wiki->htmlmode!=2) {
321 # echo '<td align="center">';
322 # helpbutton('formattingrules', get_string('formattingrules', 'wiki'), 'wiki');
323 # echo get_string("formattingrules","wiki");
324 # echo '</td>';
327 echo '</tr></table>';
330 // The wiki Contents
331 print_simple_box_start( 'center', '100%', '', '20');
332 // Do the Action
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();
338 /// Finish the page
339 print_footer($course);
340 exit;