2 /// Extended by Michael Schneider
3 /// This page prints a particular instance of wiki
7 require_once("../../config.php");
8 require_once("lib.php");
9 #require_once("$CFG->dirroot/course/lib.php"); // For side-blocks
10 require_once($CFG->libdir
. '/ajax/ajaxlib.php');
11 require_js(array('yui_yahoo','yui_connection'));
13 $ewiki_action = optional_param('ewiki_action', '', PARAM_ALPHA
); // Action on Wiki-Page
14 $id = optional_param('id', 0, PARAM_INT
); // Course Module ID, or
15 $wid = optional_param('wid', 0, PARAM_INT
); // Wiki ID
16 $page = optional_param('page', false); // Wiki Page Name
17 $q = optional_param('q',""); // Search Context
18 $userid = optional_param('userid', 0, PARAM_INT
); // User wiki.
19 $groupid = optional_param('groupid', 0, PARAM_INT
); // Group wiki.
20 $canceledit = optional_param('canceledit','', PARAM_ALPHA
); // Editing has been cancelled
21 $cacheme = optional_param('allowcache', 1, PARAM_INT
); // Set this to 0 to try and disable page caching.
23 // Only want to add edit log entries if we have made some changes ie submitted a form
24 $editsave = optional_param('thankyou', '');
27 // Split page command into action and page
28 $actions = explode('/', $page,2);
29 if(count($actions)==2) {
30 $pagename=$actions[1];
32 $pagename=$actions[0];
40 if (! $cm = get_coursemodule_from_id('wiki', $id)) {
41 error("Course Module ID was incorrect");
44 if (! $course = get_record("course", "id", $cm->course
)) {
45 error("Course is misconfigured");
48 if (! $wiki = get_record("wiki", "id", $cm->instance
)) {
49 error("Course module is incorrect");
53 if (! $wiki = get_record("wiki", "id", $wid)) {
54 error("Course module is incorrect");
56 if (! $course = get_record("course", "id", $wiki->course
)) {
57 error("Course is misconfigured");
59 if (! $cm = get_coursemodule_from_instance("wiki", $wiki->id
, $course->id
)) {
60 error("Course Module ID was incorrect");
63 $_REQUEST["id"] = $id;
66 require_course_login($course, true, $cm);
68 /// Add the course module 'groupmode' to the wiki object, for easy access.
69 $wiki->groupmode
= $cm->groupmode
;
72 $moodle_format=FORMAT_MOODLE
;
74 ### SAVE ID from Moodle
75 $moodleID=@$_REQUEST["id"];
77 /// Globally disable CamelCase, if the option is selected for this wiki.
78 $moodle_disable_camel_case = ($wiki->disablecamelcase
== 1);
80 if (($wiki_entry = wiki_get_default_entry($wiki, $course, $userid, $groupid))) {
81 // OK, now we know the entry ID, we can do lock etc.
83 // If true, we are 'really' on an editing page, not just on edit/something
84 $reallyedit=$actions[0]=='edit' && !$canceledit && !$editsave;
86 // Remove lock when we go to another wiki page (such as the cancel page)
88 wiki_release_lock($wiki_entry->id
,$pagename);
89 } else if(array_key_exists('content',$_POST)) {
90 // Do not allow blank content because it causes problems (the wiki decides
91 // the page should automatically go into edit mode, but Moodle doesn't realise
92 // this and filters out the JS)
93 if($_POST['content']=='') {
94 $_POST['content']="\n";
95 $_REQUEST['content']="\n";
98 // We must have the edit lock in order to be permitted to save
99 list($ok,$lock)=wiki_obtain_lock($wiki_entry->id
,$pagename);
101 $strsavenolock=get_string('savenolock','wiki');
102 error($strsavenolock,$CFG->wwwroot
.'/mod/wiki/view.php?id='.$cm->id
.'&page=view/'.urlencode($pagename));
106 /// ################# EWIKI Part ###########################
107 /// The wiki_entry->pagename is set to the specified value of the wiki,
108 /// or the default value in the 'lang' file if the specified value was empty.
109 define("EWIKI_PAGE_INDEX",$wiki_entry->pagename
);
111 /// If the page has a ' in it, it may have slashes added to it. Remove them if it does.
112 $page = ($page === false) ?
stripslashes(EWIKI_PAGE_INDEX
) : stripslashes($page);
114 /// # Prevent ewiki getting id as PageID...
115 unset($_REQUEST["id"]);
119 unset($_SERVER["QUERY_STRING"]);
120 if (isset($HTTP_GET_VARS)) {
121 unset($HTTP_GET_VARS["id"]);
123 if (isset($HTTP_POST_VARS)) {
124 unset($HTTP_POST_VARS["id"]);
128 /// #-- predefine some of the configuration constants
131 /// EWIKI_NAME is defined in ewikimoodlelibs, so that also admin.php can use this
132 #define("EWIKI_NAME", $wiki_entry->pagename);
134 /// Search Hilighting
135 if($ewiki_title=="SearchPages") {
136 $qArgument="&q=".urlencode($q);
139 /// Build the ewsiki script constant
140 /// ewbase will also be needed by EWIKI_SCRIPT_BINARY
141 $ewbase = 'view.php?id='.$moodleID;
142 if (isset($userid) && $userid!=0) $ewbase .= '&userid='.$userid;
143 if (isset($groupid) && $groupid!=0) $ewbase .= '&groupid='.$groupid;
144 $ewscript = $ewbase.'&page=';
145 define("EWIKI_SCRIPT", $ewscript);
146 define("EWIKI_SCRIPT_URL", $ewscript);
148 /// # Settings for this specific Wiki
149 define("EWIKI_PRINT_TITLE", $wiki->ewikiprinttitle
);
151 define("EWIKI_INIT_PAGES", wiki_content_dir($wiki));
153 /// # Moodle always addslashes to everything so we are going to strip them always
154 /// # to allow wiki itself to add them again. It's a triple add-strip-add but
155 /// # was the only way to solve the problem without modifying how the rest of
156 /// # the module works.
157 include($CFG->dirroot
."/mod/wiki/ewiki/fragments/strip_wonderful_slashes.php");
159 if (ini_get("register_globals")) {
160 # include($CFG->dirroot."/mod/wiki/ewiki/fragments/strike_register_globals.php");
164 include_once($CFG->dirroot
."/mod/wiki/ewikimoodlelib.php");
166 //include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/email_protect.php");
167 include_once($CFG->dirroot
."/mod/wiki/ewiki/plugins/patchsaving.php");
168 include_once($CFG->dirroot
."/mod/wiki/ewiki/plugins/notify.php");
169 include_once($CFG->dirroot
."/mod/wiki/ewiki/plugins/feature/imgresize_gd.php");
170 include_once($CFG->dirroot
."/mod/wiki/ewiki/plugins/moodle/moodle_highlight.php");
171 include_once($CFG->dirroot
."/mod/wiki/ewiki/plugins/moodle/f_fixhtml.php");
172 #include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/moodle/wikinews.php");
173 include_once($CFG->dirroot
."/mod/wiki/ewiki/plugins/moodle/sitemap.php");
174 include_once($CFG->dirroot
."/mod/wiki/ewiki/plugins/moodle/moodle_wikidump.php");
175 include_once($CFG->dirroot
."/mod/wiki/ewiki/plugins/aview/backlinks.php");
176 #include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/markup/css.php");
177 include_once($CFG->dirroot
."/mod/wiki/ewiki/plugins/markup/footnotes.php");
178 include_once($CFG->dirroot
."/mod/wiki/ewiki/plugins/moodle/diff.php");
179 include_once($CFG->dirroot
."/mod/wiki/ewiki/plugins/page/pageindex.php");
180 include_once($CFG->dirroot
."/mod/wiki/ewiki/plugins/page/orphanedpages.php");
181 include_once($CFG->dirroot
."/mod/wiki/ewiki/plugins/moodle/wantedpages.php");
184 if($wiki->ewikiacceptbinary
) {
185 define("EWIKI_UPLOAD_MAXSIZE", get_max_upload_file_size());
186 define("EWIKI_SCRIPT_BINARY", $ewbase."&binary=");
187 define("EWIKI_ALLOW_BINARY",1);
188 define("EWIKI_IMAGE_CACHING",1);
189 #define("EWIKI_AUTOVIEW",1);
190 include_once($CFG->dirroot
."/mod/wiki/ewiki/plugins/lib/mime_magic.php");
191 include_once($CFG->dirroot
."/mod/wiki/ewiki/plugins/aview/downloads.php");
192 include_once($CFG->dirroot
."/mod/wiki/ewiki/plugins/moodle/downloads.php");
193 #include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/db/binary_store.php");
194 include_once($CFG->dirroot
."/mod/wiki/ewiki/plugins/moodle/moodle_binary_store.php");
196 define("EWIKI_SCRIPT_BINARY", 0);
197 define("EWIKI_ALLOW_BINARY",0);
200 # The mighty Wiki itself
201 include_once($CFG->dirroot
."/mod/wiki/ewiki/ewiki.php");
204 if ($delim = strpos($page, EWIKI_ACTION_SEP_CHAR
)) {
205 @$page = substr($page, $delim +
1);
210 # Language-stuff: eWiki gets language from Browser. Lets correct it. Empty arrayelements do no harm
211 $ewiki_t["languages"]=array(current_language(), $course->lang
, $CFG->lang
,"en","c");
213 # Check Access Rights
214 $canedit = wiki_can_edit_entry($wiki_entry, $wiki, $USER, $course);
217 unset($ewiki_plugins["action"]["edit"]);
218 unset($ewiki_plugins["action"]["info"]);
223 if($wiki->htmlmode
== 0) {
225 $ewiki_config["htmlentities"]=array(); // HTML is managed by moodle
226 $moodle_format=FORMAT_TEXT
;
228 if($wiki->htmlmode
== 1) {
230 include_once($CFG->dirroot
."/mod/wiki/ewiki/plugins/moodle/moodle_rescue_html.php");
231 $moodle_format=FORMAT_HTML
;
233 if($wiki->htmlmode
== 2) {
235 $moodle_format=FORMAT_HTML
;
237 $ewiki_config["htmlentities"]=array(); // HTML is allowed
238 $ewiki_config["wiki_link_regex"] = "\007 [!~]?(
239 \#?\[[^<>\[\]\n]+\] |
240 \^[-".EWIKI_CHARS_U
.EWIKI_CHARS_L
."]{3,} |
241 \b([\w]{3,}:)*([".EWIKI_CHARS_U
."]+[".EWIKI_CHARS_L
."]+){2,}\#?[\w\d]* |
242 \w[-_.+\w]+@(\w[-_\w]+[.])+\w{2,} ) \007x";
245 global $ewiki_author, $USER;
246 $ewiki_author=fullname($USER);
247 $content=ewiki_page($page);
250 ### RESTORE ID from Moodle
251 $_REQUEST["id"]=$moodleID;
253 /// ################# EWIKI Part ###########################
257 $content2 = '<div class="boxaligncenter">'.get_string('nowikicreated', 'wiki').'</div>';
261 # Group wiki, ...: No page and no ewiki_title
262 if(!isset($ewiki_title)) {
268 if ($editsave != NULL) { /// We've submitted an edit and have been redirected back here
269 add_to_log($course->id
, "wiki", 'edit',
270 addslashes("view.php?id=$cm->id&groupid=$groupid&userid=$userid&page=$ewiki_title"),
271 format_string($wiki->name
,true).": ".$ewiki_title, $cm->id
, $userid);
272 } else if ($ewiki_action != 'edit') {
273 add_to_log($course->id
, "wiki", $ewiki_action,
274 addslashes("view.php?id=$cm->id&groupid=$groupid&userid=$userid&page=$ewiki_title"),
275 format_string($wiki->name
,true).": ".$ewiki_title, $cm->id
, $userid);
279 /// Print the page header
281 $strwikis = get_string("modulenameplural", "wiki");
282 $strwiki = get_string("modulename", "wiki");
284 $crumbs[] = array('name' => $strwikis, 'link' => "index.php?id=$course->id", 'type' => 'activity');
285 $crumbs[] = array('name' => format_string($wiki->name
,true), 'link' => "view.php?id=$moodleID", 'type' => 'activityinstace');
287 $navigation = build_navigation($crumbs);
289 print_header_simple($ewiki_title?
$ewiki_title:format_string($wiki->name
), "", $navigation,
290 "", "", $cacheme, update_module_button($cm->id
, $course->id
, $strwiki),
291 navmenu($course, $cm));
295 echo ' <div id="wikiPageActions">
297 /// The top row contains links to other wikis, if applicable.
298 if ($wiki_entry && $wiki_list = wiki_get_other_wikis($wiki, $USER, $course, $wiki_entry->id
)) {
299 //echo "wiki list ";print_r($wiki_list);
302 if (isset($wiki_list['selected'])) {
303 $selected = $wiki_list['selected'];
304 unset($wiki_list['selected']);
306 echo '<tr><td colspan="2">';
308 echo '<form id="otherwikis" action="'.$CFG->wwwroot
.'/mod/wiki/view.php">';
309 echo '<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr>';
310 echo '<td class="sideblockheading"> '
311 .$WIKI_TYPES[$wiki->wtype
].' '
312 .get_string('modulename', 'wiki')." ".get_string('for',"wiki")." "
313 .wiki_get_owner($wiki_entry).':</td>';
315 echo '<td class="sideblockheading">'
316 .get_string('otherwikis', 'wiki').': ';
317 $script = 'self.location=getElementById(\'otherwikis\').wikiselect.options[getElementById(\'otherwikis\').wikiselect.selectedIndex].value';
318 choose_from_menu($wiki_list, "wikiselect", $selected, "choose", $script);
320 echo '</tr></table>';
328 $specialpages=array("WikiExport", "SiteMap", "SearchPages", "PageIndex","NewestPages","MostVisitedPages","MostOftenChangedPages","UpdatedPages","FileDownload","FileUpload","OrphanedPages","WantedPages");
330 echo '<table border="0" width="100%">';
334 echo '<td class="wikisearchform">';
335 wiki_print_search_form($cm->id
, $q, $userid, $groupid, false);
338 /// Internal Wikilinks
339 echo '<td class="wikilinksblock">';
340 wiki_print_wikilinks_block($cm->id
, $wiki->ewikiacceptbinary
);
343 /// Administrative Links
345 echo '<td class="wikiadminactions">';
346 wiki_print_administration_actions($wiki, $cm->id
, $userid, $groupid, $ewiki_title, $wiki->htmlmode
!=2, $course);
351 echo '<td class="howtowiki">';
352 helpbutton('howtowiki', get_string('howtowiki', 'wiki'), 'wiki');
355 echo '</tr></table>';
359 <div id="wiki-view" class="mwiki">
362 if($wiki_entry && $ewiki_title==$wiki_entry->pagename
&& !empty($wiki->summary
)) {
363 if (trim(strip_tags($wiki->summary
))) {
364 print_box(format_text($wiki->summary
, FORMAT_MOODLE
), 'generalbox', 'intro');
370 if (!empty($canedit)) { /// Print tabs with commands for this page
371 $tabs = array('view', 'edit','links','info');
372 if ($wiki->ewikiacceptbinary
) {
373 $tabs[] = 'attachments';
379 foreach ($tabs as $tab) {
380 $tabname = get_string("tab$tab", 'wiki');
381 $row[] = new tabobject($tabname, $ewbase.'&page='.$tab.'/'.$ewiki_id, $tabname);
382 if ($ewiki_action == "$tab" or in_array($page, $specialpages)) {
383 $currenttab = $tabname;
388 print_tabs($tabrows, $currenttab);
391 /// Insert a link to force page refresh if new content isn't showing.
393 // build new URL + query string
394 $queries = preg_split('/[?&]/', me());
395 $nqueries = count($queries);
396 $me = $queries[0] . '?';
397 for($i=1; $i < $nqueries; $i++
)
399 if( !strstr($queries[$i], 'allowcache') )
400 $me .= $queries[$i] . '&';
402 $me .= 'allowcache=0';
405 $linkdesc = get_string('reloadlinkdescription', 'wiki');
406 $linktext = get_string('reloadlinktext', 'wiki');
407 echo "<div class='wikilinkright'><a href='$me' title='$linkdesc'><input type='button' value='$linktext' /></a></div>";
409 print_simple_box_start('center', '100%', '', '20');
411 /// Don't filter any pages containing wiki actions (except view). A wiki page containing
412 /// actions will have the form [action]/[pagename]. If the action is 'view' or the '/'
413 /// isn't there (so the action defaults to 'view'), filter it.
414 /// If the page does not yet exist, the display will default to 'edit'.
415 if((count($actions) < 2 ||
$actions[0] == "view") && $wiki_entry &&
416 record_exists('wiki_pages', 'pagename', addslashes($page), 'wiki', $wiki_entry->id
)) {
417 print(format_text($content, $moodle_format));
418 } else if($actions[0]=='edit' && $reallyedit) {
419 // Check the page isn't locked before printing out standard wiki content. (Locking
420 // is implemented as a wrapper over the existing wiki.)
421 list($gotlock,$lock)=wiki_obtain_lock($wiki_entry->id
,$pagename);
423 $modcontext = get_context_instance(CONTEXT_MODULE
, $cm->id
);
424 $canoverridelock = has_capability('mod/wiki:overridelock', $modcontext);
427 $a->since
=userdate($lock->lockedsince
);
428 $a->seen
=userdate($lock->lockedseen
);
429 $user=get_record('user','id',$lock->lockedby
);
430 $a->name
=fullname($user,
431 has_capability('moodle/site:viewfullnames', $modcontext));
433 print_string('pagelocked','wiki',$a);
435 if($canoverridelock) {
436 $pageesc=htmlspecialchars($page);
437 $stroverrideinfo=get_string('overrideinfo','wiki');
438 $stroverridebutton=get_string('overridebutton','wiki');
441 <form id='overridelock' method='post' action='overridelock.php'>
443 <input type='hidden' name='sesskey' value='$sesskey' />
444 <input type='hidden' name='id' value='$id' />
445 <input type='hidden' name='page' value='$pageesc' />
447 <input type='submit' value='$stroverridebutton' />
453 // OK, the page is now locked to us. Put in the AJAX for keeping the lock
454 $strlockcancelled=get_string('lockcancelled','wiki');
455 $strnojslockwarning=get_string('nojslockwarning','wiki');
456 $intervalms=WIKI_LOCK_RECONFIRM
*1000;
458 <script type='text/javascript'>
460 function handleResponse(o) {
461 if(o.responseText=='cancel') {
462 document.forms['ewiki'].elements['preview'].disabled=true;
463 document.forms['ewiki'].elements['save'].disabled=true;
464 clearInterval(intervalID);
465 alert('$strlockcancelled');
468 function handleFailure(o) {
471 intervalID=setInterval(function() {
472 YAHOO.util.Connect.asyncRequest('POST','confirmlock.php',
473 {success:handleResponse,failure:handleFailure},'lockid={$lock->id}');
487 print_simple_box_end();
495 print_footer($course);