Incorrect variable name used for parameter.
[moodle-linuxchix.git] / mod / wiki / admin.php
blob49349d8e3fe1b83f0446613285fc0d67e6044817
1 <?PHP // $Id$
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);
17 if ($id) {
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");
30 } else {
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 .= '&amp;userid='.$userid;
47 if (isset($groupid) && $groupid!=0) $ewbase .= '&amp;groupid='.$groupid;
48 $ewscript = $ewbase.'&amp;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 ?
60 if(!$action) {
61 error(get_string("noadministrationaction","wiki"));
64 /// Correct Action ?
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");
96 /// Validate Form
97 if ($form = data_submitted()) {
98 switch($action) {
99 case "revertpages":
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");
112 break;
113 default: break;
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");
129 /// Moodle Log
130 /// Get additional info
131 $addloginfo="";
132 switch($action) {
133 case "removepages":
134 $addloginfo=@join(", ", $form->pagestodelete);
135 break;
136 case "strippages":
137 $addloginfo=@join(", ", $form->pagestostrip);
138 break;
139 case "checklinks":
140 $addloginfo=$form->pagetocheck;
141 break;
142 case "setpageflags":
143 // No additional info
144 break;
145 case "revertpages":
146 // No additional info
147 break;
149 add_to_log($course->id, "wiki", $action, "admin.php?action=$action&amp;userid=$userid&amp;groupid=$groupid&amp;id=$id", $wiki->name.($addloginfo?": ".$addloginfo:""));
150 $link="admin.php?action=$action".($userid?"&amp;userid=".$userid:"").($groupid?"&amp;groupid=".$groupid:"")."&amp;id=$id&amp;page=$page";
151 switch($action) {
152 case "removepages":
153 if($form->proceed) {
154 if(!$confirm && $form->pagestodelete) {
155 notice_yesno(get_string("removepagecheck", "wiki")."<br />".join(", ", $form->pagestodelete),
156 $link."&amp;confirm=".urlencode(join(" ",$form->pagestodelete)), $link);
157 print_footer($course);
158 exit;
161 break;
162 case "strippages":
163 if($form->proceed) {
164 if(!$confirm && $form->pagestostrip) {
165 $err=array();
166 $strippages=wiki_admin_strip_versions($form->pagestostrip,$form->version, $err);
167 $confirm="";
168 foreach($strippages as $cnfid => $cnfver) {
169 $confirm.="&confirm[$cnfid]=".urlencode(join(" ",$cnfver));
171 if(count($err)==0) {
172 notice_yesno(get_string("strippagecheck", "wiki")."<br />".join(", ", $form->pagestostrip),
173 $link.$confirm, $link);
174 print_footer($course);
175 exit;
179 break;
180 case "checklinks":
181 if($form->proceed) {
182 if(!$confirm && $form->pagetocheck) {
183 $confirm="&amp;confirm=".$form->pagetocheck;
184 notice_yesno(get_string("checklinkscheck", "wiki").$form->pagetocheck,
185 $link.$confirm, $link);
186 print_footer($course);
187 exit;
190 break;
191 case "setpageflags":
192 // pageflagstatus is used in setpageflags.html
193 $pageflagstatus=wiki_admin_setpageflags($form->flags);
194 break;
195 case "revertpages":
196 if(!$err) {
197 if(!$confirm) {
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);
203 if($revertedpages) {
204 notice_yesno(get_string("revertpagescheck", "wiki")."<br />".$revertedpages,
205 $link.$confirm, $link);
206 print_footer($course);
207 exit;
208 } else {
209 $err->remark=get_string("nochangestorevert","wiki");
213 break;
214 default: error("No such Wiki-Admin action: $action");
215 break;
219 /// Actions which need a confirmation. If confirmed, do the action
220 $redirect="view.php?".($groupid?"&amp;groupid=".$groupid:"").($userid?"&amp;userid=".$userid:"")."&amp;id=$id&amp;page=$page";
221 if($confirm && !$err) {
222 switch($action) {
223 case "removepages":
224 $ret=wiki_admin_remove(split(" ",$confirm), $course, $wiki, $userid, $groupid);
225 if(!$ret) {
226 redirect($redirect, get_string("pagesremoved","wiki"), 1);
227 } else {
228 error($ret);
230 exit;
231 case "strippages":
232 $strippages=array();
233 foreach($confirm as $pageid => $versions) {
234 $strippages[$pageid]=split(" ",$versions);
236 $ret=wiki_admin_strip($strippages);
237 if(!$ret) {
238 redirect($redirect, get_string("pagesstripped","wiki"), 1);
239 } else {
240 error($ret);
242 exit;
243 case "checklinks":
244 $ret=wiki_admin_checklinks($confirm);
245 redirect($redirect, get_string("linkschecked","wiki")."<br />".$ret, 5);
246 exit;
247 case "revertpages":
248 $revertedpages=wiki_admin_revert(1, $confirm["authorfieldpattern"], $confirm["changesfield"], $confirm["howtooperate"], $confirm["deleteversions"]);
249 redirect($redirect, get_string("pagesreverted","wiki"), 1);
250 exit;
251 case "setpageflags":
252 # No confirmation needed
253 break;
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">&nbsp;'
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').':&nbsp;&nbsp;';
276 $script = 'self.location=document.otherwikis.wikiselect.options[document.otherwikis.wikiselect.selectedIndex].value';
278 /// Add Admin-Action
279 reset($wiki_list);
280 $wiki_admin_list=array();
281 while(list($key,$val)=each($wiki_list)) {
282 $wiki_admin_list[$key."&amp;action=$action"]=$val;
284 choose_from_menu($wiki_admin_list, "wikiselect", $selected, "choose", $script);
285 echo '</td>';
286 echo '</tr></table>';
287 echo '</form>';
289 echo '</td>';
290 echo '</tr>';
293 if ($wiki_entry) {
296 /// Page Actions
297 echo '<table border="0" width="100%">';
298 echo '<tr>';
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);
302 # echo '</td>';
304 /// Searchform
305 echo '<td align="center">';
306 wiki_print_search_form($cm->id, $q, $userid, $groupid, false);
307 echo '</td>';
309 /// Internal Wikilinks
311 /// TODO: DOES NOT WORK !!!!
312 echo '<td align="center">';
313 wiki_print_wikilinks_block($cm->id, $wiki->ewikiacceptbinary);
314 echo '</td>';
316 /// Administrative Links
317 echo '<td align="center">';
318 wiki_print_administration_actions($wiki, $cm->id, $userid, $groupid, $page, $wiki->htmlmode!=2, $course);
319 echo '</td>';
321 # if($wiki->htmlmode!=2) {
322 # echo '<td align="center">';
323 # helpbutton('formattingrules', get_string('formattingrules', 'wiki'), 'wiki');
324 # echo get_string("formattingrules","wiki");
325 # echo '</td>';
328 echo '</tr></table>';
331 // The wiki Contents
332 print_simple_box_start( 'center', '100%', '', '20');
333 // Do the Action
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();
339 /// Finish the page
340 print_footer($course);
341 exit;