forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview.php
489 lines (416 loc) · 19.4 KB
/
view.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
<?php // $Id$
/// Extended by Michael Schneider
/// This page prints a particular instance of wiki
global $CFG,$USER;
require_once("../../config.php");
require_once("lib.php");
#require_once("$CFG->dirroot/course/lib.php"); // For side-blocks
require_once($CFG->libdir . '/ajax/ajaxlib.php');
require_js(array('yui_yahoo', 'yui_event', 'yui_connection'));
$ewiki_action = optional_param('ewiki_action', '', PARAM_ALPHA); // Action on Wiki-Page
$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or
$wid = optional_param('wid', 0, PARAM_INT); // Wiki ID
$page = optional_param('page', false); // Wiki Page Name
$q = optional_param('q',""); // Search Context
$userid = optional_param('userid', 0, PARAM_INT); // User wiki.
$groupid = optional_param('groupid', 0, PARAM_INT); // Group wiki.
$canceledit = optional_param('canceledit','', PARAM_ALPHA); // Editing has been cancelled
$cacheme = optional_param('allowcache', 1, PARAM_INT); // Set this to 0 to try and disable page caching.
// Only want to add edit log entries if we have made some changes ie submitted a form
$editsave = optional_param('thankyou', '');
if($page) {
// Split page command into action and page
$actions = explode('/', $page,2);
if(count($actions)==2) {
$pagename=$actions[1];
} else {
$pagename=$actions[0];
}
} else {
$actions=array('');
$pagename='';
}
if ($id) {
if (! $cm = get_coursemodule_from_id('wiki', $id)) {
print_error("Course Module ID was incorrect");
}
if (! $course = get_record("course", "id", $cm->course)) {
print_error("Course is misconfigured");
}
if (! $wiki = get_record("wiki", "id", $cm->instance)) {
print_error("Course module is incorrect");
}
} else {
if (! $wiki = get_record("wiki", "id", $wid)) {
print_error("Course module is incorrect");
}
if (! $course = get_record("course", "id", $wiki->course)) {
print_error("Course is misconfigured");
}
if (! $cm = get_coursemodule_from_instance("wiki", $wiki->id, $course->id)) {
print_error("Course Module ID was incorrect");
}
}
require_course_login($course, true, $cm);
/// Add the course module info to the wiki object, for easy access.
$wiki->groupmode = $cm->groupmode;
$wiki->groupingid = $cm->groupingid;
$wiki->groupmembersonly = $cm->groupmembersonly;
$wiki->cmid = $cm->id;
/// Default format:
$moodle_format=FORMAT_MOODLE;
/// Globally disable CamelCase, if the option is selected for this wiki.
$moodle_disable_camel_case = ($wiki->disablecamelcase == 1);
if (($wiki_entry = wiki_get_default_entry($wiki, $course, $userid, $groupid))) {
// OK, now we know the entry ID, we can do lock etc.
// If true, we are 'really' on an editing page, not just on edit/something
$reallyedit=$actions[0]=='edit' && !$canceledit && !$editsave;
// Remove lock when we go to another wiki page (such as the cancel page)
if(!$reallyedit) {
wiki_release_lock($wiki_entry->id,$pagename);
} else if(array_key_exists('content',$_POST)) {
// Do not allow blank content because it causes problems (the wiki decides
// the page should automatically go into edit mode, but Moodle doesn't realise
// this and filters out the JS)
if($_POST['content']=='') {
$_POST['content']="\n";
$_REQUEST['content']="\n";
}
// We must have the edit lock in order to be permitted to save
list($ok,$lock)=wiki_obtain_lock($wiki_entry->id,$pagename);
if(!$ok) {
$strsavenolock=get_string('savenolock','wiki');
print_error($strsavenolock, '', $CFG->wwwroot.'/mod/wiki/view.php?id='.$cm->id.'&page=view/'.urlencode($pagename));
}
}
/// ################# EWIKI Part ###########################
/// 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);
/// If the page has a ' in it, it may have slashes added to it. Remove them if it does.
$page = ($page === false) ? stripslashes(EWIKI_PAGE_INDEX) : stripslashes($page);
/// # Prevent ewiki getting id as PageID...
unset($_REQUEST["id"]);
unset($_GET["id"]);
unset($_POST["id"]);
unset($_POST["id"]);
unset($_SERVER["QUERY_STRING"]);
if (isset($HTTP_GET_VARS)) {
unset($HTTP_GET_VARS["id"]);
}
if (isset($HTTP_POST_VARS)) {
unset($HTTP_POST_VARS["id"]);
}
global $ewiki_title;
/// #-- predefine some of the configuration constants
/// EWIKI_NAME is defined in ewikimoodlelibs, so that also admin.php can use this
#define("EWIKI_NAME", $wiki_entry->pagename);
/// Search Hilighting
if($ewiki_title=="SearchPages") {
$qArgument="&q=".urlencode($q);
}
/// Build the ewsiki script constant
/// ewbase will also be needed by EWIKI_SCRIPT_BINARY
$ewbase = 'view.php?id='.$cm->id;
if (isset($userid) && $userid!=0) $ewbase .= '&userid='.$userid;
if (isset($groupid) && $groupid!=0) $ewbase .= '&groupid='.$groupid;
$ewscript = $ewbase.'&page=';
define("EWIKI_SCRIPT", $ewscript);
define("EWIKI_SCRIPT_URL", $ewscript);
/// # Settings for this specific Wiki
define("EWIKI_PRINT_TITLE", $wiki->ewikiprinttitle);
define("EWIKI_INIT_PAGES", wiki_content_dir($wiki));
/// # Moodle always addslashes to everything so we are going to strip them always
/// # to allow wiki itself to add them again. It's a triple add-strip-add but
/// # was the only way to solve the problem without modifying how the rest of
/// # the module works.
include($CFG->dirroot."/mod/wiki/ewiki/fragments/strip_wonderful_slashes.php");
if (ini_get("register_globals")) {
# include($CFG->dirroot."/mod/wiki/ewiki/fragments/strike_register_globals.php");
}
# Database Handler
include_once($CFG->dirroot."/mod/wiki/ewikimoodlelib.php");
# Plugins
//include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/email_protect.php");
include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/patchsaving.php");
include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/notify.php");
include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/feature/imgresize_gd.php");
include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/moodle/moodle_highlight.php");
include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/moodle/f_fixhtml.php");
#include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/moodle/wikinews.php");
include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/moodle/sitemap.php");
include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/moodle/moodle_wikidump.php");
include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/aview/backlinks.php");
#include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/markup/css.php");
include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/markup/footnotes.php");
include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/moodle/diff.php");
include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/page/pageindex.php");
include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/page/orphanedpages.php");
include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/moodle/wantedpages.php");
# Binary Handling
if($wiki->ewikiacceptbinary) {
define("EWIKI_UPLOAD_MAXSIZE", get_max_upload_file_size());
define("EWIKI_SCRIPT_BINARY", $ewbase."&binary=");
define("EWIKI_ALLOW_BINARY",1);
define("EWIKI_IMAGE_CACHING",1);
#define("EWIKI_AUTOVIEW",1);
include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/lib/mime_magic.php");
include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/aview/downloads.php");
include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/moodle/downloads.php");
#include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/db/binary_store.php");
include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/moodle/moodle_binary_store.php");
} else {
define("EWIKI_SCRIPT_BINARY", 0);
define("EWIKI_ALLOW_BINARY",0);
}
# The mighty Wiki itself
include_once($CFG->dirroot."/mod/wiki/ewiki/ewiki.php");
if($canceledit) {
if ($delim = strpos($page, EWIKI_ACTION_SEP_CHAR)) {
@$page = substr($page, $delim + 1);
} else {
@$page="";
}
}
# Language-stuff: eWiki gets language from Browser. Lets correct it. Empty arrayelements do no harm
$ewiki_t["languages"]=array(current_language(), $course->lang, $CFG->lang,"en","c");
# Check Access Rights
$canedit = wiki_can_edit_entry($wiki_entry, $wiki, $USER, $course);
if (!$canedit) {
# Protected Mode
unset($ewiki_plugins["action"]["edit"]);
unset($ewiki_plugins["action"]["info"]);
}
# HTML Handling
$ewiki_use_editor=0;
if($wiki->htmlmode == 0) {
# No HTML
$ewiki_config["htmlentities"]=array(); // HTML is managed by moodle
$moodle_format=FORMAT_TEXT;
}
if($wiki->htmlmode == 1) {
# Safe HTML
include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/moodle/moodle_rescue_html.php");
$moodle_format=FORMAT_HTML;
}
if($wiki->htmlmode == 2) {
# HTML Only
$moodle_format=FORMAT_HTML;
$ewiki_use_editor=1;
$ewiki_config["htmlentities"]=array(); // HTML is allowed
$ewiki_config["wiki_link_regex"] = "\007 [!~]?(
\#?\[[^<>\[\]\n]+\] |
\^[-".EWIKI_CHARS_U.EWIKI_CHARS_L."]{3,} |
\b([\w]{3,}:)*([".EWIKI_CHARS_U."]+[".EWIKI_CHARS_L."]+){2,}\#?[\w\d]* |
\w[-_.+\w]+@(\w[-_\w]+[.])+\w{2,} ) \007x";
}
global $ewiki_author, $USER;
$ewiki_author=fullname($USER);
$content=ewiki_page($page);
$content2='';
/// ################# EWIKI Part ###########################
}
else {
$content = '';
$content2 = '<div class="boxaligncenter">'.get_string('nowikicreated', 'wiki').'</div>';
}
# Group wiki, ...: No page and no ewiki_title
if(!isset($ewiki_title)) {
$ewiki_title="";
}
/// Moodle Log
if ($editsave != NULL) { /// We've submitted an edit and have been redirected back here
add_to_log($course->id, "wiki", 'edit',
addslashes("view.php?id=$cm->id&groupid=$groupid&userid=$userid&page=$ewiki_title"),
format_string($wiki->name,true).": ".$ewiki_title, $cm->id, $userid);
} else if ($ewiki_action != 'edit') {
add_to_log($course->id, "wiki", $ewiki_action,
addslashes("view.php?id=$cm->id&groupid=$groupid&userid=$userid&page=$ewiki_title"),
format_string($wiki->name,true).": ".$ewiki_title, $cm->id, $userid);
}
/// Print the page header
$strwikis = get_string("modulenameplural", "wiki");
$strwiki = get_string("modulename", "wiki");
$navigation = build_navigation('', $cm);
print_header_simple($ewiki_title?$ewiki_title:format_string($wiki->name), "", $navigation,
"", "", $cacheme, update_module_button($cm->id, $course->id, $strwiki),
navmenu($course, $cm));
/// Print Page
echo ' <div id="wikiPageActions">
';
/// The top row contains links to other wikis, if applicable.
if ($wiki_entry && $wiki_list = wiki_get_other_wikis($wiki, $USER, $course, $wiki_entry->id)) {
//echo "wiki list ";print_r($wiki_list);
$selected="";
if (isset($wiki_list['selected'])) {
$selected = $wiki_list['selected'];
unset($wiki_list['selected']);
}
echo '<tr><td colspan="2">';
echo '<form id="otherwikis" action="'.$CFG->wwwroot.'/mod/wiki/view.php">';
echo '<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr>';
echo '<td class="sideblockheading"> '
.$WIKI_TYPES[$wiki->wtype].' '
.get_string('modulename', 'wiki')." ".get_string('for',"wiki")." "
.wiki_get_owner($wiki_entry).':</td>';
echo '<td class="sideblockheading">'
.get_string('otherwikis', 'wiki').': ';
$script = 'self.location=getElementById(\'otherwikis\').wikiselect.options[getElementById(\'otherwikis\').wikiselect.selectedIndex].value';
choose_from_menu($wiki_list, "wikiselect", $selected, "choose", $script);
echo '</td>';
echo '</tr></table>';
echo '</form>';
echo '</td>';
echo '</tr>';
}
if ($wiki_entry) {
$specialpages=array("WikiExport", "SiteMap", "SearchPages", "PageIndex","NewestPages","MostVisitedPages","MostOftenChangedPages","UpdatedPages","FileDownload","FileUpload","OrphanedPages","WantedPages");
/// Page Actions
echo '<table border="0" width="100%">';
echo '<tr>';
/// Searchform
echo '<td class="wikisearchform">';
wiki_print_search_form($cm->id, $q, $userid, $groupid, false);
echo '</td>';
/// Internal Wikilinks
echo '<td class="wikilinksblock">';
wiki_print_wikilinks_block($cm->id, $wiki->ewikiacceptbinary);
echo '</td>';
/// Administrative Links
if($canedit) {
echo '<td class="wikiadminactions">';
wiki_print_administration_actions($wiki, $cm->id, $userid, $groupid, $ewiki_title, $wiki->htmlmode!=2, $course);
echo '</td>';
}
/// Formatting Rules
echo '<td class="howtowiki">';
helpbutton('howtowiki', get_string('howtowiki', 'wiki'), 'wiki');
echo '</td>';
echo '</tr></table>';
}
echo '</div>
<div id="wiki-view" class="mwiki">
';
if($wiki_entry && $ewiki_title==$wiki_entry->pagename && !empty($wiki->summary)) {
if (trim(strip_tags($wiki->summary))) {
print_box(format_text($wiki->summary, FORMAT_MOODLE), 'generalbox', 'intro');
}
}
// The wiki Contents
if (!empty($canedit)) { /// Print tabs with commands for this page
$tabs = array('view', 'edit','links','info');
if ($wiki->ewikiacceptbinary) {
$tabs[] = 'attachments';
}
$tabrows = array();
$row = array();
$currenttab = '';
foreach ($tabs as $tab) {
$tabname = get_string("tab$tab", 'wiki');
$row[] = new tabobject($tabname, $ewbase.'&page='.$tab.'/'.$ewiki_id, $tabname);
if ($ewiki_action == "$tab" or in_array($page, $specialpages)) {
$currenttab = $tabname;
}
}
$tabrows[] = $row;
print_tabs($tabrows, $currenttab);
}
/// Insert a link to force page refresh if new content isn't showing.
// build new URL + query string
$queries = preg_split('/[?&]/', me());
$nqueries = count($queries);
$me = $queries[0] . '?';
for($i=1; $i < $nqueries; $i++)
{
if( !strstr($queries[$i], 'allowcache') )
$me .= $queries[$i] . '&';
}
$me .= 'allowcache=0';
// Insert the link
$linkdesc = get_string('reloadlinkdescription', 'wiki');
$linktext = get_string('reloadlinktext', 'wiki');
echo "<div class='wikilinkright'><a href='$me' title='$linkdesc'><input type='button' value='$linktext' /></a></div>";
print_simple_box_start('center', '100%', '', '20');
/// Don't filter any pages containing wiki actions (except view). A wiki page containing
/// actions will have the form [action]/[pagename]. If the action is 'view' or the '/'
/// isn't there (so the action defaults to 'view'), filter it.
/// If the page does not yet exist, the display will default to 'edit'.
if((count($actions) < 2 || $actions[0] == "view") && $wiki_entry &&
record_exists('wiki_pages', 'pagename', addslashes($page), 'wiki', $wiki_entry->id)) {
print(format_text($content, $moodle_format));
} else if($actions[0]=='edit' && $reallyedit) {
// Check the page isn't locked before printing out standard wiki content. (Locking
// is implemented as a wrapper over the existing wiki.)
list($gotlock,$lock)=wiki_obtain_lock($wiki_entry->id,$pagename);
if(!$gotlock) {
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
$canoverridelock = has_capability('mod/wiki:overridelock', $modcontext);
$a=new stdClass;
$a->since=userdate($lock->lockedsince);
$a->seen=userdate($lock->lockedseen);
$user=get_record('user','id',$lock->lockedby);
$a->name=fullname($user,
has_capability('moodle/site:viewfullnames', $modcontext));
print_string('pagelocked','wiki',$a);
if($canoverridelock) {
$pageesc=htmlspecialchars($page);
$stroverrideinfo=get_string('overrideinfo','wiki');
$stroverridebutton=get_string('overridebutton','wiki');
$sesskey=sesskey();
print "
<form id='overridelock' method='post' action='overridelock.php'>
<div>
<input type='hidden' name='sesskey' value='$sesskey' />
<input type='hidden' name='id' value='$cm->id' />
<input type='hidden' name='page' value='$pageesc' />
$stroverrideinfo
<input type='submit' value='$stroverridebutton' />
</div>
</form>
";
}
} else {
if (ajaxenabled()) {
// OK, the page is now locked to us. Put in the AJAX for keeping the lock
$strlockcancelled=addslashes(get_string('lockcancelled','wiki'));
$strnojslockwarning=get_string('nojslockwarning','wiki');
$intervalms=WIKI_LOCK_RECONFIRM*1000;
print "
<script type='text/javascript'>
var intervalID;
function handleResponse(o) {
if(o.responseText=='cancel') {
document.forms['ewiki'].elements['preview'].disabled=true;
document.forms['ewiki'].elements['save'].disabled=true;
clearInterval(intervalID);
alert('$strlockcancelled');
}
}
function handleFailure(o) {
// Ignore for now
}
intervalID=setInterval(function() {
YAHOO.util.Connect.asyncRequest('POST','confirmlock.php',
{success:handleResponse,failure:handleFailure},'lockid={$lock->id}');
},$intervalms);
</script>
<noscript><p>
$strnojslockwarning
</p></noscript>
";
}
// Print editor etc
print $content;
}
} else {
print $content;
}
print $content2;
print_simple_box_end();
echo "<br />";
/// Finish the page
echo '
</div>
';
print_footer($course);
?>