course)) {
error("Course is misconfigured");
}
if (! $wiki = get_record("wiki", "id", $cm->instance)) {
error("Course module is incorrect");
}
} else {
if (! $wiki = get_record("wiki", "id", $a)) {
error("Course module is incorrect");
}
if (! $course = get_record("course", "id", $wiki->course)) {
error("Course is misconfigured");
}
if (! $cm = get_coursemodule_from_instance("wiki", $wiki->id, $course->id)) {
error("Course Module ID was incorrect");
}
}
require_login($course->id, false, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/wiki:manage', $context);
/// Build the ewsiki script constant
$ewbase = 'view.php?id='.$id;
if (isset($userid) && $userid!=0) $ewbase .= '&userid='.$userid;
if (isset($groupid) && $groupid!=0) $ewbase .= '&groupid='.$groupid;
$ewscript = $ewbase.'&page=';
define("EWIKI_SCRIPT", $ewscript);
if($wiki->ewikiacceptbinary) {
define("EWIKI_UPLOAD_MAXSIZE", get_max_upload_file_size());
define("EWIKI_SCRIPT_BINARY", $ewbase."&binary=");
}
/// Add the course module 'groupmode' to the wiki object, for easy access.
$wiki->groupmode = $cm->groupmode;
/// Is an Action given ?
if(!$action) {
print_error("noadministrationaction","wiki");
}
/// Correct Action ?
if(!in_array($action, array("setpageflags", "removepages", "strippages", "checklinks", "revertpages"))) {
error("Unknown action '$action'","wiki");
}
/// May the User administrate it ?
if (($wiki_entry = wiki_get_entry($wiki, $course, $userid, $groupid)) === false || wiki_can_edit_entry($wiki_entry, $wiki, $USER, $course) === false) {
print_error("notadministratewiki","wiki");
}
$canedit = wiki_can_edit_entry($wiki_entry, $wiki, $USER, $course);
# Check for dangerous events (hacking) !
if(in_array($action,array("removepages","strippages","revertpages"))) {
if(!($wiki->wtype=="student" || ($wiki->wtype=="group" and $canedit) || wiki_is_teacher($wiki))) {
add_to_log($course->id, "wiki", "hack", "", $wiki->name.": Tried to trick admin.php with action=$action.");
error("Hack attack detected !");
}
}
# Database and Binary Handler
include_once($CFG->dirroot."/mod/wiki/ewikimoodlelib.php");
include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/moodle/moodle_binary_store.php");
/// The wiki_entry->pagename is set to the specified value of the wiki,
/// or the default value in the 'lang' file if the specified value was empty.
define("EWIKI_PAGE_INDEX",$wiki_entry->pagename);
# The mighty Wiki itself
include_once($CFG->dirroot."/mod/wiki/ewiki/ewiki.php");
$strwikis = get_string("modulenameplural", "wiki");
$strwiki = get_string("modulename", "wiki");
/// Validate Form
if ($form = data_submitted()) {
switch($action) {
case "revertpages":
if(!$form->deleteversions || 0 > $form->deleteversions || $form->deleteversions > 1000) {
$focus="form.deleteversions";
$err->deleteversions=get_string("deleteversionserror","wiki");
}
if(!$form->changesfield || 0 > $form->changesfield || $form->changesfield > 100000) {
$focus="form.changesfield";
$err->changesfield=get_string("changesfielderror","wiki");
}
if($form->authorfieldpattern=="") {
$focus="form.authorfieldpattern";
$err->authorfieldpattern=get_string("authorfieldpatternerror","wiki");
}
break;
default: break;
}
}
$navigation = build_navigation(get_string("administration","wiki"), $cm);
print_header_simple("$wiki_entry->pagename", "", $navigation,
$focus, "", true, update_module_button($cm->id, $course->id, $strwiki),
navmenu($course, $cm));
////////////////////////////////////////////////////////////
/// Check if the Form has been submitted and display confirmation
////////////////////////////////////////////////////////////
if ($form = data_submitted()) {
/// Moodle Log
/// Get additional info
$addloginfo="";
switch($action) {
case "removepages":
$addloginfo=@join(", ", $form->pagestodelete);
break;
case "strippages":
$addloginfo=@join(", ", $form->pagestostrip);
break;
case "checklinks":
$addloginfo=$form->pagetocheck;
break;
case "setpageflags":
// No additional info
break;
case "revertpages":
// No additional info
break;
}
add_to_log($course->id, "wiki", $action, "admin.php?action=$action&userid=$userid&groupid=$groupid&id=$id", $wiki->name.($addloginfo?": ".$addloginfo:""));
$link="admin.php?action=$action".($userid?"&userid=".$userid:"").($groupid?"&groupid=".$groupid:"")."&id=$id&page=$page";
switch($action) {
case "removepages":
if($form->proceed) {
if(!$confirm && $form->pagestodelete) {
notice_yesno(get_string("removepagecheck", "wiki")."
".join(", ", $form->pagestodelete),
$link."&confirm=".urlencode(join(" ",$form->pagestodelete)), $link);
print_footer($course);
exit;
}
}
break;
case "strippages":
if($form->proceed) {
if(!$confirm && $form->pagestostrip) {
$err=array();
$strippages=wiki_admin_strip_versions($form->pagestostrip,$form->version, $err);
$confirm="";
foreach($strippages as $cnfid => $cnfver) {
$confirm.="&confirm[$cnfid]=".urlencode(join(" ",$cnfver));
}
if(count($err)==0) {
$pagestostrip=array();
foreach($form->pagestostrip as $pagetostrip) {
$pagestostrip[]=htmlspecialchars(urldecode($pagetostrip));
}
notice_yesno(get_string("strippagecheck", "wiki")."
".join(", ", $pagestostrip),
$link.$confirm, $link);
print_footer($course);
exit;
}
}
}
break;
case "checklinks":
if($form->proceed) {
if(!$confirm && $form->pagetocheck) {
$confirm="&confirm=".$form->pagetocheck;
notice_yesno(get_string("checklinkscheck", "wiki").$form->pagetocheck,
$link.$confirm, $link);
print_footer($course);
exit;
}
}
break;
case "setpageflags":
// pageflagstatus is used in setpageflags.html
$pageflagstatus=wiki_admin_setpageflags($form->flags);
break;
case "revertpages":
if(!$err) {
if(!$confirm) {
$confirm="&confirm[changesfield]=".urlencode($form->changesfield).
"&confirm[authorfieldpattern]=".urlencode($form->authorfieldpattern).
"&confirm[howtooperate]=".urlencode($form->howtooperate).
"&confirm[deleteversions]=".urlencode($form->deleteversions);
$revertedpages=wiki_admin_revert("", $form->authorfieldpattern, $form->changesfield, $form->howtooperate, $form->deleteversions);
if($revertedpages) {
notice_yesno(get_string("revertpagescheck", "wiki")."
".$revertedpages,
$link.$confirm, $link);
print_footer($course);
exit;
} else {
$err->remark=get_string("nochangestorevert","wiki");
}
}
}
break;
default: error("No such Wiki-Admin action: $action");
break;
}
}
/// Actions which need a confirmation. If confirmed, do the action
$redirect="view.php?".($groupid?"&groupid=".$groupid:"").($userid?"&userid=".$userid:"")."&id=$id&page=$page";
if($confirm && !$err) {
switch($action) {
case "removepages":
$ret=wiki_admin_remove(split(" ",$confirm), $course, $wiki, $userid, $groupid);
if(!$ret) {
redirect($redirect, get_string("pagesremoved","wiki"), 1);
} else {
error($ret);
}
exit;
case "strippages":
$strippages=array();
foreach($confirm as $pageid => $versions) {
$strippages[$pageid]=split(" ",$versions);
}
$ret=wiki_admin_strip($strippages);
if(!$ret) {
redirect($redirect, get_string("pagesstripped","wiki"), 1);
} else {
error($ret);
}
exit;
case "checklinks":
$ret=wiki_admin_checklinks($confirm);
redirect($redirect, get_string("linkschecked","wiki")."
".$ret, 5);
exit;
case "revertpages":
$revertedpages=wiki_admin_revert(1, $confirm["authorfieldpattern"], $confirm["changesfield"], $confirm["howtooperate"], $confirm["deleteversions"]);
redirect($redirect, get_string("pagesreverted","wiki"), 1);
exit;
case "setpageflags":
# No confirmation needed
break;
default: error("No such action '$action' with confirmation");
}
}
/// The top row contains links to other wikis, if applicable.
if ($wiki_list = wiki_get_other_wikis($wiki, $USER, $course, $wiki_entry->id)) {
if (isset($wiki_list['selected'])) {
$selected = $wiki_list['selected'];
unset($wiki_list['selected']);
}
echo '
'; # $specialpages=array("SearchPages", "PageIndex","NewestPages","MostVisitedPages","MostOftenChangedPages","UpdatedPages","FileDownload","FileUpload","OrphanedPages","WantedPages"); # wiki_print_page_actions($cm->id, $specialpages, $ewiki_id, $ewiki_action, $wiki->ewikiacceptbinary, $canedit); # echo ' | '; /// Searchform echo ''; wiki_print_search_form($cm->id, $q, $userid, $groupid, false); echo ' | '; /// Internal Wikilinks /// TODO: DOES NOT WORK !!!! echo ''; wiki_print_wikilinks_block($cm->id, $wiki->ewikiacceptbinary); echo ' | '; /// Administrative Links echo ''; wiki_print_administration_actions($wiki, $cm->id, $userid, $groupid, $page, $wiki->htmlmode!=2, $course); echo ' | '; # if($wiki->htmlmode!=2) { # echo ''; # helpbutton('formattingrules', get_string('formattingrules', 'wiki'), 'wiki'); # echo get_string("formattingrules","wiki"); # echo ' | '; # } echo '