Commit | Line | Data |
---|---|---|
00710f4c DC |
1 | <?php |
2 | ||
3 | // This file is part of Moodle - http://moodle.org/ | |
4 | // | |
5 | // Moodle is free software: you can redistribute it and/or modify | |
6 | // it under the terms of the GNU General Public License as published by | |
7 | // the Free Software Foundation, either version 3 of the License, or | |
8 | // (at your option) any later version. | |
9 | // | |
10 | // Moodle is distributed in the hope that it will be useful, | |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | // GNU General Public License for more details. | |
14 | // | |
15 | // You should have received a copy of the GNU General Public License | |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
18 | /** | |
19 | * This file contains several classes uses to render the diferent pages | |
20 | * of the wiki module | |
21 | * | |
593b8385 | 22 | * @package mod_wiki |
7db38cd5 SH |
23 | * @copyright 2009 Marc Alier, Jordi Piguillem marc.alier@upc.edu |
24 | * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu | |
00710f4c DC |
25 | * |
26 | * @author Jordi Piguillem | |
27 | * @author Marc Alier | |
28 | * @author David Jimenez | |
29 | * @author Josep Arus | |
30 | * @author Daniel Serrano | |
31 | * @author Kenneth Riba | |
32 | * | |
33 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
34 | */ | |
35 | ||
36 | require_once($CFG->dirroot . '/mod/wiki/edit_form.php'); | |
37 | require_once($CFG->dirroot . '/tag/lib.php'); | |
38 | ||
39 | /** | |
40 | * Class page_wiki contains the common code between all pages | |
41 | * | |
00710f4c DC |
42 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
43 | */ | |
44 | abstract class page_wiki { | |
45 | ||
46 | /** | |
47 | * @var object Current subwiki | |
48 | */ | |
49 | protected $subwiki; | |
50 | ||
51 | /** | |
52 | * @var int Current page | |
53 | */ | |
54 | protected $page; | |
55 | ||
56 | /** | |
57 | * @var string Current page title | |
58 | */ | |
59 | protected $title; | |
60 | ||
61 | /** | |
62 | * @var int Current group ID | |
63 | */ | |
64 | protected $gid; | |
65 | ||
cfdac90f DC |
66 | /** |
67 | * @var object module context object | |
68 | */ | |
69 | protected $modcontext; | |
70 | ||
74c6a62c JP |
71 | /** |
72 | * @var int Current user ID | |
73 | */ | |
74 | protected $uid; | |
00710f4c DC |
75 | /** |
76 | * @var array The tabs set used in wiki module | |
77 | */ | |
cfffb69c | 78 | protected $tabs = array('view' => 'view', 'edit' => 'edit', 'comments' => 'comments', |
ac0a82cf RT |
79 | 'history' => 'history', 'map' => 'map', 'files' => 'files', |
80 | 'admin' => 'admin'); | |
00710f4c DC |
81 | /** |
82 | * @var array tabs options | |
83 | */ | |
84 | protected $tabs_options = array(); | |
85 | /** | |
86 | * @var object wiki renderer | |
87 | */ | |
88 | protected $wikioutput; | |
4a28ff88 AG |
89 | /** |
90 | * @var stdClass course module. | |
91 | */ | |
92 | protected $cm; | |
00710f4c DC |
93 | |
94 | /** | |
95 | * page_wiki constructor | |
96 | * | |
97 | * @param $wiki. Current wiki | |
98 | * @param $subwiki. Current subwiki. | |
99 | * @param $cm. Current course_module. | |
100 | */ | |
101 | function __construct($wiki, $subwiki, $cm) { | |
102 | global $PAGE, $CFG; | |
103 | $this->subwiki = $subwiki; | |
4a28ff88 AG |
104 | $this->cm = $cm; |
105 | $this->modcontext = context_module::instance($this->cm->id); | |
00710f4c DC |
106 | |
107 | // initialise wiki renderer | |
108 | $this->wikioutput = $PAGE->get_renderer('mod_wiki'); | |
00710f4c DC |
109 | $PAGE->set_cacheable(true); |
110 | $PAGE->set_cm($cm); | |
111 | $PAGE->set_activity_record($wiki); | |
112 | // the search box | |
d3adc16e MG |
113 | if (!empty($subwiki->id)) { |
114 | $search = optional_param('searchstring', null, PARAM_ALPHANUMEXT); | |
115 | $PAGE->set_button(wiki_search_form($cm, $search, $subwiki)); | |
116 | } | |
00710f4c DC |
117 | } |
118 | ||
119 | /** | |
120 | * This method prints the top of the page. | |
121 | */ | |
122 | function print_header() { | |
123 | global $OUTPUT, $PAGE, $CFG, $USER, $SESSION; | |
124 | ||
8c6ca696 | 125 | $PAGE->set_heading($PAGE->course->fullname); |
00710f4c DC |
126 | |
127 | $this->set_url(); | |
128 | ||
129 | if (isset($SESSION->wikipreviousurl) && is_array($SESSION->wikipreviousurl)) { | |
130 | $this->process_session_url(); | |
131 | } | |
132 | $this->set_session_url(); | |
133 | ||
134 | $this->create_navbar(); | |
135 | $this->setup_tabs(); | |
136 | ||
137 | echo $OUTPUT->header(); | |
341e2460 | 138 | $wiki = $PAGE->activityrecord; |
876c0ac3 | 139 | echo $OUTPUT->heading($wiki->name); |
00710f4c DC |
140 | |
141 | echo $this->wikioutput->wiki_info(); | |
142 | ||
143 | // tabs are associated with pageid, so if page is empty, tabs should be disabled | |
144 | if (!empty($this->page) && !empty($this->tabs)) { | |
145 | echo $this->wikioutput->tabs($this->page, $this->tabs, $this->tabs_options); | |
146 | } | |
147 | } | |
148 | ||
149 | /** | |
150 | * Protected method to print current page title. | |
151 | */ | |
152 | protected function print_pagetitle() { | |
153 | global $OUTPUT; | |
154 | $html = ''; | |
155 | ||
876c0ac3 RW |
156 | $html .= $OUTPUT->container_start('wiki_headingtitle'); |
157 | $html .= $OUTPUT->heading(format_string($this->title), 3); | |
00710f4c DC |
158 | $html .= $OUTPUT->container_end(); |
159 | echo $html; | |
160 | } | |
161 | ||
162 | /** | |
163 | * Setup page tabs, if options is empty, will set up active tab automatically | |
164 | * @param array $options, tabs options | |
165 | */ | |
166 | protected function setup_tabs($options = array()) { | |
cfffb69c | 167 | global $CFG, $PAGE; |
4a28ff88 | 168 | $groupmode = groups_get_activity_groupmode($this->cm); |
cfffb69c JP |
169 | |
170 | if (empty($CFG->usecomments) || !has_capability('mod/wiki:viewcomment', $PAGE->context)){ | |
171 | unset($this->tabs['comments']); | |
172 | } | |
173 | ||
174 | if (!has_capability('mod/wiki:editpage', $PAGE->context)){ | |
175 | unset($this->tabs['edit']); | |
176 | } | |
177 | ||
dc0cabb4 | 178 | if ($groupmode and $groupmode == VISIBLEGROUPS) { |
4a28ff88 AG |
179 | $currentgroup = groups_get_activity_group($this->cm); |
180 | $manage = has_capability('mod/wiki:managewiki', $this->modcontext); | |
dc0cabb4 | 181 | $edit = has_capability('mod/wiki:editpage', $PAGE->context); |
6cf8f401 | 182 | if (!$manage and !($edit and groups_is_member($currentgroup))) { |
dc0cabb4 MG |
183 | unset($this->tabs['edit']); |
184 | } | |
dc0cabb4 MG |
185 | } |
186 | ||
00710f4c DC |
187 | if (empty($options)) { |
188 | $this->tabs_options = array('activetab' => substr(get_class($this), 10)); | |
189 | } else { | |
190 | $this->tabs_options = $options; | |
191 | } | |
192 | ||
193 | } | |
194 | ||
195 | /** | |
196 | * This method must be overwritten to print the page content. | |
197 | */ | |
198 | function print_content() { | |
199 | throw new coding_exception('Page wiki class does not implement method print_content()'); | |
200 | } | |
201 | ||
202 | /** | |
203 | * Method to set the current page | |
204 | * | |
205 | * @param object $page Current page | |
206 | */ | |
207 | function set_page($page) { | |
208 | global $PAGE; | |
209 | ||
210 | $this->page = $page; | |
211 | $this->title = $page->title; | |
4c4e6591 | 212 | // set_title calls format_string itself so no probs there |
00710f4c DC |
213 | $PAGE->set_title($this->title); |
214 | } | |
215 | ||
216 | /** | |
217 | * Method to set the current page title. | |
218 | * This method must be called when the current page is not created yet. | |
219 | * @param string $title Current page title. | |
220 | */ | |
221 | function set_title($title) { | |
222 | global $PAGE; | |
223 | ||
224 | $this->page = null; | |
225 | $this->title = $title; | |
4c4e6591 | 226 | // set_title calls format_string itself so no probs there |
00710f4c DC |
227 | $PAGE->set_title($this->title); |
228 | } | |
229 | ||
230 | /** | |
231 | * Method to set current group id | |
232 | * @param int $gid Current group id | |
233 | */ | |
234 | function set_gid($gid) { | |
235 | $this->gid = $gid; | |
236 | } | |
237 | ||
74c6a62c JP |
238 | /** |
239 | * Method to set current user id | |
240 | * @param int $uid Current user id | |
241 | */ | |
242 | function set_uid($uid) { | |
243 | $this->uid = $uid; | |
244 | } | |
245 | ||
00710f4c DC |
246 | /** |
247 | * Method to set the URL of the page. | |
248 | * This method must be overwritten by every type of page. | |
249 | */ | |
250 | protected function set_url() { | |
251 | throw new coding_exception('Page wiki class does not implement method set_url()'); | |
252 | } | |
253 | ||
254 | /** | |
255 | * Protected method to create the common items of the navbar in every page type. | |
256 | */ | |
257 | protected function create_navbar() { | |
258 | global $PAGE, $CFG; | |
259 | ||
110f4c93 | 260 | $PAGE->navbar->add(format_string($this->title), $CFG->wwwroot . '/mod/wiki/view.php?pageid=' . $this->page->id); |
00710f4c DC |
261 | } |
262 | ||
263 | /** | |
264 | * This method print the footer of the page. | |
265 | */ | |
266 | function print_footer() { | |
267 | global $OUTPUT; | |
268 | echo $OUTPUT->footer(); | |
269 | } | |
270 | ||
271 | protected function process_session_url() { | |
272 | global $USER, $SESSION; | |
273 | ||
274 | //delete locks if edit | |
275 | $url = $SESSION->wikipreviousurl; | |
276 | switch ($url['page']) { | |
277 | case 'edit': | |
278 | wiki_delete_locks($url['params']['pageid'], $USER->id, $url['params']['section'], false); | |
279 | break; | |
280 | } | |
281 | } | |
282 | ||
283 | protected function set_session_url() { | |
284 | global $SESSION; | |
285 | unset($SESSION->wikipreviousurl); | |
286 | } | |
287 | ||
288 | } | |
289 | ||
290 | /** | |
291 | * View a wiki page | |
292 | * | |
00710f4c DC |
293 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
294 | */ | |
295 | class page_wiki_view extends page_wiki { | |
00710f4c DC |
296 | |
297 | function print_header() { | |
298 | global $PAGE; | |
299 | ||
300 | parent::print_header(); | |
301 | ||
12c9bbbd | 302 | $this->wikioutput->wiki_print_subwiki_selector($PAGE->activityrecord, $this->subwiki, $this->page, 'view'); |
00710f4c DC |
303 | |
304 | if (!empty($this->page)) { | |
305 | echo $this->wikioutput->prettyview_link($this->page); | |
306 | } | |
307 | ||
308 | //echo $this->wikioutput->page_index(); | |
309 | ||
310 | $this->print_pagetitle(); | |
311 | } | |
312 | ||
313 | function print_content() { | |
314 | global $PAGE, $CFG; | |
315 | ||
00710f4c DC |
316 | if (wiki_user_can_view($this->subwiki)) { |
317 | ||
318 | if (!empty($this->page)) { | |
cfdac90f | 319 | wiki_print_page_content($this->page, $this->modcontext, $this->subwiki->id); |
00710f4c DC |
320 | $wiki = $PAGE->activityrecord; |
321 | } else { | |
322 | print_string('nocontent', 'wiki'); | |
323 | // TODO: fix this part | |
324 | $swid = 0; | |
325 | if (!empty($this->subwiki)) { | |
326 | $swid = $this->subwiki->id; | |
327 | } | |
328 | } | |
329 | } else { | |
033e8461 | 330 | echo get_string('cannotviewpage', 'wiki'); |
00710f4c DC |
331 | } |
332 | } | |
333 | ||
334 | function set_url() { | |
335 | global $PAGE, $CFG; | |
336 | $params = array(); | |
337 | ||
4a28ff88 AG |
338 | if (isset($this->cm->id)) { |
339 | $params['id'] = $this->cm->id; | |
00710f4c DC |
340 | } else if (!empty($this->page) and $this->page != null) { |
341 | $params['pageid'] = $this->page->id; | |
342 | } else if (!empty($this->gid)) { | |
4a28ff88 | 343 | $params['wid'] = $this->cm->instance; |
00710f4c DC |
344 | $params['group'] = $this->gid; |
345 | } else if (!empty($this->title)) { | |
346 | $params['swid'] = $this->subwiki->id; | |
347 | $params['title'] = $this->title; | |
348 | } else { | |
349 | print_error(get_string('invalidparameters', 'wiki')); | |
350 | } | |
4c4e6591 | 351 | $PAGE->set_url(new moodle_url($CFG->wwwroot . '/mod/wiki/view.php', $params)); |
00710f4c DC |
352 | } |
353 | ||
00710f4c | 354 | protected function create_navbar() { |
4c4e6591 | 355 | global $PAGE; |
00710f4c | 356 | |
110f4c93 | 357 | $PAGE->navbar->add(format_string($this->title)); |
00710f4c DC |
358 | $PAGE->navbar->add(get_string('view', 'wiki')); |
359 | } | |
360 | } | |
361 | ||
362 | /** | |
363 | * Wiki page editing page | |
364 | * | |
00710f4c DC |
365 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
366 | */ | |
367 | class page_wiki_edit extends page_wiki { | |
368 | ||
369 | public static $attachmentoptions; | |
370 | ||
371 | protected $sectioncontent; | |
372 | /** @var string the section name needed to be edited */ | |
373 | protected $section; | |
374 | protected $overridelock = false; | |
375 | protected $versionnumber = -1; | |
376 | protected $upload = false; | |
377 | protected $attachments = 0; | |
378 | protected $deleteuploads = array(); | |
379 | protected $format; | |
380 | ||
381 | function __construct($wiki, $subwiki, $cm) { | |
382 | global $CFG, $PAGE; | |
383 | parent::__construct($wiki, $subwiki, $cm); | |
23c79945 | 384 | self::$attachmentoptions = array('subdirs' => false, 'maxfiles' => - 1, 'maxbytes' => $CFG->maxbytes, 'accepted_types' => '*'); |
00710f4c | 385 | $PAGE->requires->js_init_call('M.mod_wiki.renew_lock', null, true); |
00710f4c DC |
386 | } |
387 | ||
388 | protected function print_pagetitle() { | |
389 | global $OUTPUT; | |
390 | ||
391 | $title = $this->title; | |
392 | if (isset($this->section)) { | |
393 | $title .= ' : ' . $this->section; | |
394 | } | |
876c0ac3 RW |
395 | echo $OUTPUT->container_start('wiki_clear wiki_headingtitle'); |
396 | echo $OUTPUT->heading(format_string($title), 3); | |
00710f4c DC |
397 | echo $OUTPUT->container_end(); |
398 | } | |
399 | ||
400 | function print_header() { | |
401 | global $OUTPUT, $PAGE; | |
402 | $PAGE->requires->data_for_js('wiki', array('renew_lock_timeout' => LOCK_TIMEOUT - 5, 'pageid' => $this->page->id, 'section' => $this->section)); | |
403 | ||
404 | parent::print_header(); | |
405 | ||
406 | $this->print_pagetitle(); | |
407 | ||
408 | print '<noscript>' . $OUTPUT->box(get_string('javascriptdisabledlocks', 'wiki'), 'errorbox') . '</noscript>'; | |
409 | } | |
410 | ||
411 | function print_content() { | |
412 | global $PAGE; | |
413 | ||
00710f4c DC |
414 | if (wiki_user_can_edit($this->subwiki)) { |
415 | $this->print_edit(); | |
416 | } else { | |
033e8461 | 417 | echo get_string('cannoteditpage', 'wiki'); |
00710f4c DC |
418 | } |
419 | } | |
420 | ||
421 | protected function set_url() { | |
422 | global $PAGE, $CFG; | |
423 | ||
424 | $params = array('pageid' => $this->page->id); | |
425 | ||
426 | if (isset($this->section)) { | |
427 | $params['section'] = $this->section; | |
428 | } | |
429 | ||
430 | $PAGE->set_url($CFG->wwwroot . '/mod/wiki/edit.php', $params); | |
431 | } | |
432 | ||
433 | protected function set_session_url() { | |
434 | global $SESSION; | |
435 | ||
436 | $SESSION->wikipreviousurl = array('page' => 'edit', 'params' => array('pageid' => $this->page->id, 'section' => $this->section)); | |
437 | } | |
438 | ||
439 | protected function process_session_url() { | |
440 | } | |
441 | ||
442 | function set_section($sectioncontent, $section) { | |
443 | $this->sectioncontent = $sectioncontent; | |
444 | $this->section = $section; | |
445 | } | |
446 | ||
447 | public function set_versionnumber($versionnumber) { | |
448 | $this->versionnumber = $versionnumber; | |
449 | } | |
450 | ||
451 | public function set_overridelock($override) { | |
452 | $this->overridelock = $override; | |
453 | } | |
454 | ||
455 | function set_format($format) { | |
456 | $this->format = $format; | |
457 | } | |
458 | ||
459 | public function set_upload($upload) { | |
460 | $this->upload = $upload; | |
461 | } | |
462 | ||
463 | public function set_attachments($attachments) { | |
464 | $this->attachments = $attachments; | |
465 | } | |
466 | ||
467 | public function set_deleteuploads($deleteuploads) { | |
468 | $this->deleteuploads = $deleteuploads; | |
469 | } | |
470 | ||
471 | protected function create_navbar() { | |
472 | global $PAGE, $CFG; | |
473 | ||
474 | parent::create_navbar(); | |
475 | ||
476 | $PAGE->navbar->add(get_string('edit', 'wiki')); | |
477 | } | |
478 | ||
479 | protected function check_locks() { | |
480 | global $OUTPUT, $USER, $CFG; | |
481 | ||
482 | if (!wiki_set_lock($this->page->id, $USER->id, $this->section, true)) { | |
483 | print $OUTPUT->box(get_string('pageislocked', 'wiki'), 'generalbox boxwidthnormal boxaligncenter'); | |
484 | ||
485 | if ($this->overridelock) { | |
486 | $params = 'pageid=' . $this->page->id; | |
487 | ||
488 | if ($this->section) { | |
1323bf55 | 489 | $params .= '§ion=' . urlencode($this->section); |
00710f4c DC |
490 | } |
491 | ||
492 | $form = '<form method="post" action="' . $CFG->wwwroot . '/mod/wiki/overridelocks.php?' . $params . '">'; | |
493 | $form .= '<input type="hidden" name="sesskey" value="' . sesskey() . '" />'; | |
494 | $form .= '<input type="submit" value="' . get_string('overridelocks', 'wiki') . '" />'; | |
495 | $form .= '</form>'; | |
496 | ||
497 | print $OUTPUT->box($form, 'generalbox boxwidthnormal boxaligncenter'); | |
498 | } | |
499 | return false; | |
500 | } | |
501 | return true; | |
502 | } | |
503 | ||
504 | protected function print_edit($content = null) { | |
505 | global $CFG, $OUTPUT, $USER, $PAGE; | |
506 | ||
507 | if (!$this->check_locks()) { | |
508 | return; | |
509 | } | |
510 | ||
511 | //delete old locks (> 1 hour) | |
512 | wiki_delete_old_locks(); | |
513 | ||
514 | $version = wiki_get_current_version($this->page->id); | |
515 | $format = $version->contentformat; | |
516 | ||
517 | if ($content == null) { | |
518 | if (empty($this->section)) { | |
519 | $content = $version->content; | |
520 | } else { | |
521 | $content = $this->sectioncontent; | |
522 | } | |
523 | } | |
524 | ||
525 | $versionnumber = $version->version; | |
526 | if ($this->versionnumber >= 0) { | |
527 | if ($version->version != $this->versionnumber) { | |
528 | print $OUTPUT->box(get_string('wrongversionlock', 'wiki'), 'errorbox'); | |
529 | $versionnumber = $this->versionnumber; | |
530 | } | |
531 | } | |
532 | ||
00710f4c DC |
533 | $url = $CFG->wwwroot . '/mod/wiki/edit.php?pageid=' . $this->page->id; |
534 | if (!empty($this->section)) { | |
1323bf55 | 535 | $url .= "§ion=" . urlencode($this->section); |
00710f4c DC |
536 | } |
537 | ||
4c4e6591 SH |
538 | $params = array( |
539 | 'attachmentoptions' => page_wiki_edit::$attachmentoptions, | |
540 | 'format' => $version->contentformat, | |
541 | 'version' => $versionnumber, | |
542 | 'pagetitle' => $this->page->title, | |
543 | 'contextid' => $this->modcontext->id | |
544 | ); | |
00710f4c DC |
545 | |
546 | $data = new StdClass(); | |
547 | $data->newcontent = $content; | |
548 | $data->version = $versionnumber; | |
549 | $data->format = $format; | |
550 | ||
551 | switch ($format) { | |
552 | case 'html': | |
553 | $data->newcontentformat = FORMAT_HTML; | |
e9de1cf4 RT |
554 | // Append editor context to editor options, giving preference to existing context. |
555 | page_wiki_edit::$attachmentoptions = array_merge(array('context' => $this->modcontext), page_wiki_edit::$attachmentoptions); | |
cfdac90f | 556 | $data = file_prepare_standard_editor($data, 'newcontent', page_wiki_edit::$attachmentoptions, $this->modcontext, 'mod_wiki', 'attachments', $this->subwiki->id); |
00710f4c | 557 | break; |
74c6a62c | 558 | default: |
12c9bbbd | 559 | break; |
4c4e6591 | 560 | } |
00710f4c DC |
561 | |
562 | if ($version->contentformat != 'html') { | |
00710f4c | 563 | $params['fileitemid'] = $this->subwiki->id; |
12c9bbbd DC |
564 | $params['component'] = 'mod_wiki'; |
565 | $params['filearea'] = 'attachments'; | |
00710f4c DC |
566 | } |
567 | ||
568 | $form = new mod_wiki_edit_form($url, $params); | |
569 | ||
00710f4c | 570 | if ($formdata = $form->get_data()) { |
00710f4c DC |
571 | if (!empty($CFG->usetags)) { |
572 | $data->tags = $formdata->tags; | |
573 | } | |
574 | } else { | |
575 | if (!empty($CFG->usetags)) { | |
1d2c29ca | 576 | $data->tags = tag_get_tags_array('wiki_pages', $this->page->id); |
00710f4c DC |
577 | } |
578 | } | |
579 | ||
580 | $form->set_data($data); | |
581 | $form->display(); | |
582 | } | |
583 | ||
00710f4c DC |
584 | } |
585 | ||
586 | /** | |
587 | * Class that models the behavior of wiki's view comments page | |
588 | * | |
00710f4c DC |
589 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
590 | */ | |
591 | class page_wiki_comments extends page_wiki { | |
592 | ||
593 | function print_header() { | |
594 | ||
595 | parent::print_header(); | |
596 | ||
597 | $this->print_pagetitle(); | |
598 | ||
599 | } | |
600 | ||
601 | function print_content() { | |
cfdac90f | 602 | global $CFG, $OUTPUT, $USER, $PAGE; |
00710f4c DC |
603 | require_once($CFG->dirroot . '/mod/wiki/locallib.php'); |
604 | ||
605 | $page = $this->page; | |
606 | $subwiki = $this->subwiki; | |
607 | $wiki = $PAGE->activityrecord; | |
cfdac90f | 608 | list($context, $course, $cm) = get_context_info_array($this->modcontext->id); |
00710f4c | 609 | |
cfdac90f | 610 | require_capability('mod/wiki:viewcomment', $this->modcontext, NULL, true, 'noviewcommentpermission', 'wiki'); |
00710f4c | 611 | |
cfdac90f | 612 | $comments = wiki_get_comments($this->modcontext->id, $page->id); |
00710f4c | 613 | |
cfdac90f | 614 | if (has_capability('mod/wiki:editcomment', $this->modcontext)) { |
00710f4c DC |
615 | echo '<div class="midpad"><a href="' . $CFG->wwwroot . '/mod/wiki/editcomments.php?action=add&pageid=' . $page->id . '">' . get_string('addcomment', 'wiki') . '</a></div>'; |
616 | } | |
617 | ||
618 | $options = array('swid' => $this->page->subwikiid, 'pageid' => $page->id); | |
619 | $version = wiki_get_current_version($this->page->id); | |
620 | $format = $version->contentformat; | |
621 | ||
622 | if (empty($comments)) { | |
876c0ac3 | 623 | echo html_writer::tag('p', get_string('nocomments', 'wiki'), array('class' => 'bold')); |
00710f4c DC |
624 | } |
625 | ||
9ffd2726 JP |
626 | foreach ($comments as $comment) { |
627 | ||
628 | $user = wiki_get_user_info($comment->userid); | |
00710f4c | 629 | |
1df23626 | 630 | $fullname = fullname($user, has_capability('moodle/site:viewfullnames', context_course::instance($course->id))); |
00710f4c DC |
631 | $by = new stdclass(); |
632 | $by->name = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $user->id . '&course=' . $course->id . '">' . $fullname . '</a>'; | |
9ffd2726 | 633 | $by->date = userdate($comment->timecreated); |
00710f4c DC |
634 | |
635 | $t = new html_table(); | |
636 | $cell1 = new html_table_cell($OUTPUT->user_picture($user, array('popup' => true))); | |
637 | $cell2 = new html_table_cell(get_string('bynameondate', 'forum', $by)); | |
638 | $cell3 = new html_table_cell(); | |
639 | $cell3->atributtes ['width'] = "80%"; | |
640 | $cell4 = new html_table_cell(); | |
641 | $cell5 = new html_table_cell(); | |
642 | ||
643 | $row1 = new html_table_row(); | |
644 | $row1->cells[] = $cell1; | |
645 | $row1->cells[] = $cell2; | |
646 | $row2 = new html_table_row(); | |
647 | $row2->cells[] = $cell3; | |
648 | ||
649 | if ($format != 'html') { | |
650 | if ($format == 'creole') { | |
9ffd2726 | 651 | $parsedcontent = wiki_parse_content('creole', $comment->content, $options); |
00710f4c | 652 | } else if ($format == 'nwiki') { |
9ffd2726 | 653 | $parsedcontent = wiki_parse_content('nwiki', $comment->content, $options); |
00710f4c DC |
654 | } |
655 | ||
1a4596e4 | 656 | $cell4->text = format_text(html_entity_decode($parsedcontent['parsed_text'], ENT_QUOTES, 'UTF-8'), FORMAT_HTML); |
00710f4c | 657 | } else { |
110f4c93 | 658 | $cell4->text = format_text($comment->content, FORMAT_HTML); |
00710f4c DC |
659 | } |
660 | ||
661 | $row2->cells[] = $cell4; | |
662 | ||
9bf1b716 | 663 | $t->data = array($row1, $row2); |
00710f4c | 664 | |
9bf1b716 | 665 | $actionicons = false; |
cfdac90f | 666 | if ((has_capability('mod/wiki:managecomment', $this->modcontext))) { |
9ffd2726 JP |
667 | $urledit = new moodle_url('/mod/wiki/editcomments.php', array('commentid' => $comment->id, 'pageid' => $page->id, 'action' => 'edit')); |
668 | $urldelet = new moodle_url('/mod/wiki/instancecomments.php', array('commentid' => $comment->id, 'pageid' => $page->id, 'action' => 'delete')); | |
9bf1b716 | 669 | $actionicons = true; |
cfdac90f | 670 | } else if ((has_capability('mod/wiki:editcomment', $this->modcontext)) and ($USER->id == $user->id)) { |
9ffd2726 JP |
671 | $urledit = new moodle_url('/mod/wiki/editcomments.php', array('commentid' => $comment->id, 'pageid' => $page->id, 'action' => 'edit')); |
672 | $urldelet = new moodle_url('/mod/wiki/instancecomments.php', array('commentid' => $comment->id, 'pageid' => $page->id, 'action' => 'delete')); | |
9bf1b716 JP |
673 | $actionicons = true; |
674 | } | |
675 | ||
cfffb69c | 676 | if ($actionicons) { |
ae41a70b FM |
677 | $cell6 = new html_table_cell($OUTPUT->action_icon($urledit, new pix_icon('t/edit', get_string('edit'), |
678 | '', array('class' => 'iconsmall'))) . $OUTPUT->action_icon($urldelet, new pix_icon('t/delete', | |
679 | get_string('delete'), '', array('class' => 'iconsmall')))); | |
00710f4c DC |
680 | $row3 = new html_table_row(); |
681 | $row3->cells[] = $cell5; | |
682 | $row3->cells[] = $cell6; | |
9bf1b716 | 683 | $t->data[] = $row3; |
00710f4c DC |
684 | } |
685 | ||
367a75fa | 686 | echo html_writer::tag('div', html_writer::table($t), array('class'=>'no-overflow')); |
00710f4c DC |
687 | |
688 | } | |
689 | } | |
690 | ||
691 | function set_url() { | |
692 | global $PAGE, $CFG; | |
693 | $PAGE->set_url($CFG->wwwroot . '/mod/wiki/comments.php', array('pageid' => $this->page->id)); | |
694 | } | |
695 | ||
696 | protected function create_navbar() { | |
697 | global $PAGE, $CFG; | |
698 | ||
699 | parent::create_navbar(); | |
700 | $PAGE->navbar->add(get_string('comments', 'wiki')); | |
701 | } | |
702 | ||
703 | } | |
704 | ||
705 | /** | |
706 | * Class that models the behavior of wiki's edit comment | |
707 | * | |
00710f4c DC |
708 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
709 | */ | |
710 | class page_wiki_editcomment extends page_wiki { | |
711 | private $comment; | |
712 | private $action; | |
713 | private $form; | |
714 | private $format; | |
715 | ||
716 | function set_url() { | |
717 | global $PAGE, $CFG; | |
718 | $PAGE->set_url($CFG->wwwroot . '/mod/wiki/comments.php', array('pageid' => $this->page->id)); | |
719 | } | |
720 | ||
721 | function print_header() { | |
722 | parent::print_header(); | |
723 | $this->print_pagetitle(); | |
724 | } | |
725 | ||
726 | function print_content() { | |
727 | global $PAGE; | |
728 | ||
cfdac90f | 729 | require_capability('mod/wiki:editcomment', $this->modcontext, NULL, true, 'noeditcommentpermission', 'wiki'); |
00710f4c DC |
730 | |
731 | if ($this->action == 'add') { | |
732 | $this->add_comment_form(); | |
733 | } else if ($this->action == 'edit') { | |
734 | $this->edit_comment_form($this->comment); | |
735 | } | |
736 | } | |
737 | ||
738 | function set_action($action, $comment) { | |
739 | global $CFG; | |
740 | require_once($CFG->dirroot . '/mod/wiki/comments_form.php'); | |
741 | ||
742 | $this->action = $action; | |
743 | $this->comment = $comment; | |
744 | $version = wiki_get_current_version($this->page->id); | |
745 | $this->format = $version->contentformat; | |
746 | ||
747 | if ($this->format == 'html') { | |
748 | $destination = $CFG->wwwroot . '/mod/wiki/instancecomments.php?pageid=' . $this->page->id; | |
749 | $this->form = new mod_wiki_comments_form($destination); | |
750 | } | |
751 | } | |
752 | ||
753 | protected function create_navbar() { | |
754 | global $PAGE, $CFG; | |
755 | ||
756 | $PAGE->navbar->add(get_string('comments', 'wiki'), $CFG->wwwroot . '/mod/wiki/comments.php?pageid=' . $this->page->id); | |
757 | ||
758 | if ($this->action == 'add') { | |
759 | $PAGE->navbar->add(get_string('insertcomment', 'wiki')); | |
760 | } else { | |
761 | $PAGE->navbar->add(get_string('editcomment', 'wiki')); | |
762 | } | |
763 | } | |
764 | ||
54352ac9 | 765 | protected function setup_tabs($options = array()) { |
00710f4c DC |
766 | parent::setup_tabs(array('linkedwhenactive' => 'comments', 'activetab' => 'comments')); |
767 | } | |
768 | ||
769 | private function add_comment_form() { | |
770 | global $CFG; | |
771 | require_once($CFG->dirroot . '/mod/wiki/editors/wiki_editor.php'); | |
772 | ||
773 | $pageid = $this->page->id; | |
774 | ||
775 | if ($this->format == 'html') { | |
48346fb1 AB |
776 | $com = new stdClass(); |
777 | $com->action = 'add'; | |
778 | $com->commentoptions = array('trusttext' => true, 'maxfiles' => 0); | |
779 | $this->form->set_data($com); | |
00710f4c DC |
780 | $this->form->display(); |
781 | } else { | |
e0f0c304 | 782 | wiki_print_editor_wiki($this->page->id, null, $this->format, -1, null, false, null, 'addcomments'); |
00710f4c DC |
783 | } |
784 | } | |
785 | ||
786 | private function edit_comment_form($com) { | |
787 | global $CFG; | |
788 | require_once($CFG->dirroot . '/mod/wiki/comments_form.php'); | |
789 | require_once($CFG->dirroot . '/mod/wiki/editors/wiki_editor.php'); | |
790 | ||
791 | if ($this->format == 'html') { | |
00710f4c DC |
792 | $com->action = 'edit'; |
793 | $com->entrycomment_editor['text'] = $com->content; | |
48346fb1 | 794 | $com->commentoptions = array('trusttext' => true, 'maxfiles' => 0); |
00710f4c | 795 | |
48346fb1 | 796 | $this->form->set_data($com); |
00710f4c DC |
797 | $this->form->display(); |
798 | } else { | |
48346fb1 | 799 | wiki_print_editor_wiki($this->page->id, $com->content, $this->format, -1, null, false, array(), 'editcomments', $com->id); |
00710f4c DC |
800 | } |
801 | ||
802 | } | |
803 | ||
804 | } | |
805 | ||
806 | /** | |
807 | * Wiki page search page | |
808 | * | |
00710f4c DC |
809 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
810 | */ | |
811 | class page_wiki_search extends page_wiki { | |
812 | private $search_result; | |
813 | ||
814 | protected function create_navbar() { | |
815 | global $PAGE, $CFG; | |
816 | ||
86cfd273 | 817 | $PAGE->navbar->add(format_string($this->title)); |
00710f4c DC |
818 | } |
819 | ||
820 | function set_search_string($search, $searchcontent) { | |
821 | $swid = $this->subwiki->id; | |
822 | if ($searchcontent) { | |
823 | $this->search_result = wiki_search_all($swid, $search); | |
824 | } else { | |
825 | $this->search_result = wiki_search_title($swid, $search); | |
826 | } | |
827 | ||
828 | } | |
829 | ||
830 | function set_url() { | |
831 | global $PAGE, $CFG; | |
832 | $PAGE->set_url($CFG->wwwroot . '/mod/wiki/search.php'); | |
833 | } | |
d3adc16e MG |
834 | |
835 | function print_header() { | |
836 | global $PAGE; | |
837 | ||
838 | parent::print_header(); | |
839 | ||
840 | $wiki = $PAGE->activityrecord; | |
841 | $page = (object)array('title' => $wiki->firstpagetitle); | |
842 | $this->wikioutput->wiki_print_subwiki_selector($wiki, $this->subwiki, $page, 'search'); | |
843 | } | |
844 | ||
00710f4c DC |
845 | function print_content() { |
846 | global $PAGE; | |
847 | ||
cfdac90f | 848 | require_capability('mod/wiki:viewpage', $this->modcontext, NULL, true, 'noviewpagepermission', 'wiki'); |
00710f4c | 849 | |
cfdac90f | 850 | echo $this->wikioutput->search_result($this->search_result, $this->subwiki); |
00710f4c DC |
851 | } |
852 | } | |
853 | ||
854 | /** | |
855 | * | |
856 | * Class that models the behavior of wiki's | |
857 | * create page | |
858 | * | |
859 | */ | |
860 | class page_wiki_create extends page_wiki { | |
861 | ||
862 | private $format; | |
863 | private $swid; | |
af49fc36 | 864 | private $wid; |
00710f4c DC |
865 | private $action; |
866 | private $mform; | |
5dedd64d | 867 | private $groups; |
00710f4c DC |
868 | |
869 | function print_header() { | |
870 | $this->set_url(); | |
871 | parent::print_header(); | |
872 | } | |
873 | ||
874 | function set_url() { | |
875 | global $PAGE, $CFG; | |
876 | ||
877 | $params = array(); | |
4c4e6591 | 878 | $params['swid'] = $this->swid; |
00710f4c DC |
879 | if ($this->action == 'new') { |
880 | $params['action'] = 'new'; | |
af49fc36 | 881 | $params['wid'] = $this->wid; |
00710f4c DC |
882 | if ($this->title != get_string('newpage', 'wiki')) { |
883 | $params['title'] = $this->title; | |
884 | } | |
00710f4c DC |
885 | } else { |
886 | $params['action'] = 'create'; | |
00710f4c | 887 | } |
4c4e6591 | 888 | $PAGE->set_url(new moodle_url('/mod/wiki/create.php', $params)); |
00710f4c DC |
889 | } |
890 | ||
891 | function set_format($format) { | |
892 | $this->format = $format; | |
893 | } | |
894 | ||
af49fc36 AB |
895 | function set_wid($wid) { |
896 | $this->wid = $wid; | |
897 | } | |
898 | ||
00710f4c DC |
899 | function set_swid($swid) { |
900 | $this->swid = $swid; | |
901 | } | |
902 | ||
5dedd64d AG |
903 | function set_availablegroups($group) { |
904 | $this->groups = $group; | |
905 | } | |
906 | ||
00710f4c | 907 | function set_action($action) { |
74c6a62c | 908 | global $PAGE; |
00710f4c DC |
909 | $this->action = $action; |
910 | ||
911 | require_once(dirname(__FILE__) . '/create_form.php'); | |
5dedd64d | 912 | $url = new moodle_url('/mod/wiki/create.php', array('action' => 'create', 'wid' => $PAGE->activityrecord->id, 'group' => $this->gid, 'uid' => $this->uid)); |
00710f4c | 913 | $formats = wiki_get_formats(); |
5dedd64d | 914 | $options = array('formats' => $formats, 'defaultformat' => $PAGE->activityrecord->defaultformat, 'forceformat' => $PAGE->activityrecord->forceformat, 'groups' => $this->groups); |
00710f4c DC |
915 | if ($this->title != get_string('newpage', 'wiki')) { |
916 | $options['disable_pagetitle'] = true; | |
917 | } | |
918 | $this->mform = new mod_wiki_create_form($url->out(false), $options); | |
919 | } | |
920 | ||
921 | protected function create_navbar() { | |
922 | global $PAGE; | |
4c4e6591 | 923 | // navigation_node::get_content formats this before printing. |
00710f4c DC |
924 | $PAGE->navbar->add($this->title); |
925 | } | |
926 | ||
927 | function print_content($pagetitle = '') { | |
928 | global $PAGE; | |
929 | ||
00710f4c | 930 | // @TODO: Change this to has_capability and show an alternative interface. |
cfdac90f | 931 | require_capability('mod/wiki:createpage', $this->modcontext, NULL, true, 'nocreatepermission', 'wiki'); |
6bdfef5d | 932 | $data = new stdClass(); |
00710f4c DC |
933 | if (!empty($pagetitle)) { |
934 | $data->pagetitle = $pagetitle; | |
935 | } | |
936 | $data->pageformat = $PAGE->activityrecord->defaultformat; | |
937 | ||
938 | $this->mform->set_data($data); | |
939 | $this->mform->display(); | |
940 | } | |
941 | ||
97f2eb45 | 942 | function create_page($pagetitle) { |
5dedd64d AG |
943 | global $USER, $PAGE; |
944 | ||
00710f4c | 945 | $data = $this->mform->get_data(); |
5dedd64d AG |
946 | if (isset($data->groupinfo)) { |
947 | $groupid = $data->groupinfo; | |
9daabc71 AG |
948 | } else if (!empty($this->gid)) { |
949 | $groupid = $this->gid; | |
5dedd64d AG |
950 | } else { |
951 | $groupid = '0'; | |
952 | } | |
6947c57a RT |
953 | if (empty($this->subwiki)) { |
954 | // If subwiki is not set then try find one and set else create one. | |
70a9f27b | 955 | if (!$this->subwiki = wiki_get_subwiki_by_group($this->wid, $groupid, $this->uid)) { |
6947c57a RT |
956 | $swid = wiki_add_subwiki($PAGE->activityrecord->id, $groupid, $this->uid); |
957 | $this->subwiki = wiki_get_subwiki($swid); | |
958 | } | |
74c6a62c | 959 | } |
97f2eb45 | 960 | if ($data) { |
b7921fc4 | 961 | $this->set_title($data->pagetitle); |
97f2eb45 DC |
962 | $id = wiki_create_page($this->subwiki->id, $data->pagetitle, $data->pageformat, $USER->id); |
963 | } else { | |
b7921fc4 | 964 | $this->set_title($pagetitle); |
97f2eb45 DC |
965 | $id = wiki_create_page($this->subwiki->id, $pagetitle, $PAGE->activityrecord->defaultformat, $USER->id); |
966 | } | |
b7921fc4 DV |
967 | $this->page = $id; |
968 | return $id; | |
00710f4c DC |
969 | } |
970 | } | |
971 | ||
972 | class page_wiki_preview extends page_wiki_edit { | |
973 | ||
974 | private $newcontent; | |
975 | ||
976 | function __construct($wiki, $subwiki, $cm) { | |
977 | global $PAGE, $CFG, $OUTPUT; | |
978 | parent::__construct($wiki, $subwiki, $cm); | |
979 | $buttons = $OUTPUT->update_module_button($cm->id, 'wiki'); | |
980 | $PAGE->set_button($buttons); | |
980c237e | 981 | |
00710f4c DC |
982 | } |
983 | ||
984 | function print_header() { | |
985 | global $PAGE, $CFG; | |
986 | ||
987 | parent::print_header(); | |
988 | ||
989 | } | |
990 | ||
991 | function print_content() { | |
992 | global $PAGE; | |
993 | ||
cfdac90f | 994 | require_capability('mod/wiki:editpage', $this->modcontext, NULL, true, 'noeditpermission', 'wiki'); |
00710f4c DC |
995 | |
996 | $this->print_preview(); | |
997 | } | |
998 | ||
999 | function set_newcontent($newcontent) { | |
1000 | $this->newcontent = $newcontent; | |
1001 | } | |
1002 | ||
1003 | function set_url() { | |
1004 | global $PAGE, $CFG; | |
1005 | ||
1006 | $params = array('pageid' => $this->page->id | |
1007 | ); | |
1008 | ||
1009 | if (isset($this->section)) { | |
1010 | $params['section'] = $this->section; | |
1011 | } | |
1012 | ||
1013 | $PAGE->set_url($CFG->wwwroot . '/mod/wiki/edit.php', $params); | |
1014 | } | |
1015 | ||
54352ac9 | 1016 | protected function setup_tabs($options = array()) { |
00710f4c DC |
1017 | parent::setup_tabs(array('linkedwhenactive' => 'view', 'activetab' => 'view')); |
1018 | } | |
1019 | ||
1020 | protected function check_locks() { | |
1021 | return true; | |
1022 | } | |
1023 | ||
1024 | protected function print_preview() { | |
d4800079 | 1025 | global $CFG, $PAGE, $OUTPUT; |
00710f4c DC |
1026 | |
1027 | $version = wiki_get_current_version($this->page->id); | |
1028 | $format = $version->contentformat; | |
1029 | $content = $version->content; | |
1030 | ||
980c237e DC |
1031 | $url = $CFG->wwwroot . '/mod/wiki/edit.php?pageid=' . $this->page->id; |
1032 | if (!empty($this->section)) { | |
1323bf55 | 1033 | $url .= "§ion=" . urlencode($this->section); |
980c237e | 1034 | } |
4c4e6591 SH |
1035 | $params = array( |
1036 | 'attachmentoptions' => page_wiki_edit::$attachmentoptions, | |
1037 | 'format' => $this->format, | |
1038 | 'version' => $this->versionnumber, | |
1039 | 'contextid' => $this->modcontext->id | |
1040 | ); | |
980c237e DC |
1041 | |
1042 | if ($this->format != 'html') { | |
980c237e DC |
1043 | $params['component'] = 'mod_wiki'; |
1044 | $params['filearea'] = 'attachments'; | |
1045 | $params['fileitemid'] = $this->page->id; | |
1046 | } | |
1047 | $form = new mod_wiki_edit_form($url, $params); | |
1048 | ||
1049 | ||
23c79945 | 1050 | $options = array('swid' => $this->page->subwikiid, 'pageid' => $this->page->id, 'pretty_print' => true); |
00710f4c | 1051 | |
980c237e | 1052 | if ($data = $form->get_data()) { |
d4800079 DC |
1053 | if (isset($data->newcontent)) { |
1054 | // wiki fromat | |
1055 | $text = $data->newcontent; | |
1056 | } else { | |
1057 | // html format | |
1058 | $text = $data->newcontent_editor['text']; | |
1059 | } | |
1060 | $parseroutput = wiki_parse_content($data->contentformat, $text, $options); | |
1061 | $this->set_newcontent($text); | |
f159bd75 | 1062 | echo $OUTPUT->notification(get_string('previewwarning', 'wiki'), 'notifyproblem'); |
7cacd29f | 1063 | $content = format_text($parseroutput['parsed_text'], FORMAT_HTML, array('overflowdiv'=>true, 'filter'=>false)); |
980c237e DC |
1064 | echo $OUTPUT->box($content, 'generalbox wiki_previewbox'); |
1065 | $content = $this->newcontent; | |
1066 | } | |
00710f4c DC |
1067 | |
1068 | $this->print_edit($content); | |
1069 | } | |
1070 | ||
1071 | } | |
1072 | ||
1073 | /** | |
1074 | * | |
1075 | * Class that models the behavior of wiki's | |
1076 | * view differences | |
1077 | * | |
1078 | */ | |
1079 | class page_wiki_diff extends page_wiki { | |
1080 | ||
1081 | private $compare; | |
1082 | private $comparewith; | |
1083 | ||
1084 | function print_header() { | |
1085 | global $OUTPUT; | |
1086 | ||
1087 | parent::print_header(); | |
1088 | ||
1089 | $this->print_pagetitle(); | |
6bdfef5d | 1090 | $vstring = new stdClass(); |
00710f4c DC |
1091 | $vstring->old = $this->compare; |
1092 | $vstring->new = $this->comparewith; | |
14cdc257 | 1093 | echo html_writer::tag('div', get_string('comparewith', 'wiki', $vstring), array('class' => 'wiki_headingtitle')); |
00710f4c DC |
1094 | } |
1095 | ||
1096 | /** | |
1097 | * Print the diff view | |
1098 | */ | |
1099 | function print_content() { | |
1100 | global $PAGE; | |
1101 | ||
cfdac90f | 1102 | require_capability('mod/wiki:viewpage', $this->modcontext, NULL, true, 'noviewpagepermission', 'wiki'); |
00710f4c DC |
1103 | |
1104 | $this->print_diff_content(); | |
1105 | } | |
1106 | ||
1107 | function set_url() { | |
1108 | global $PAGE, $CFG; | |
1109 | ||
1110 | $PAGE->set_url($CFG->wwwroot . '/mod/wiki/diff.php', array('pageid' => $this->page->id, 'comparewith' => $this->comparewith, 'compare' => $this->compare)); | |
1111 | } | |
1112 | ||
1113 | function set_comparison($compare, $comparewith) { | |
1114 | $this->compare = $compare; | |
1115 | $this->comparewith = $comparewith; | |
1116 | } | |
1117 | ||
1118 | protected function create_navbar() { | |
1119 | global $PAGE, $CFG; | |
1120 | ||
1121 | parent::create_navbar(); | |
83cfd144 | 1122 | $PAGE->navbar->add(get_string('history', 'wiki'), $CFG->wwwroot . '/mod/wiki/history.php?pageid=' . $this->page->id); |
00710f4c DC |
1123 | $PAGE->navbar->add(get_string('diff', 'wiki')); |
1124 | } | |
1125 | ||
54352ac9 | 1126 | protected function setup_tabs($options = array()) { |
00710f4c DC |
1127 | parent::setup_tabs(array('linkedwhenactive' => 'history', 'activetab' => 'history')); |
1128 | } | |
1129 | ||
1130 | /** | |
1131 | * Given two versions of a page, prints a page displaying the differences between them. | |
1132 | * | |
cfdac90f DC |
1133 | * @global object $CFG |
1134 | * @global object $OUTPUT | |
1135 | * @global object $PAGE | |
00710f4c DC |
1136 | */ |
1137 | private function print_diff_content() { | |
1138 | global $CFG, $OUTPUT, $PAGE; | |
1139 | ||
1140 | $pageid = $this->page->id; | |
1141 | $total = wiki_count_wiki_page_versions($pageid) - 1; | |
1142 | ||
1143 | $oldversion = wiki_get_wiki_page_version($pageid, $this->compare); | |
cfdac90f | 1144 | |
00710f4c DC |
1145 | $newversion = wiki_get_wiki_page_version($pageid, $this->comparewith); |
1146 | ||
1147 | if ($oldversion && $newversion) { | |
1148 | ||
cfdac90f DC |
1149 | $oldtext = format_text(file_rewrite_pluginfile_urls($oldversion->content, 'pluginfile.php', $this->modcontext->id, 'mod_wiki', 'attachments', $this->subwiki->id)); |
1150 | $newtext = format_text(file_rewrite_pluginfile_urls($newversion->content, 'pluginfile.php', $this->modcontext->id, 'mod_wiki', 'attachments', $this->subwiki->id)); | |
00710f4c DC |
1151 | list($diff1, $diff2) = ouwiki_diff_html($oldtext, $newtext); |
1152 | $oldversion->diff = $diff1; | |
1153 | $oldversion->user = wiki_get_user_info($oldversion->userid); | |
1154 | $newversion->diff = $diff2; | |
1155 | $newversion->user = wiki_get_user_info($newversion->userid); | |
1156 | ||
1157 | echo $this->wikioutput->diff($pageid, $oldversion, $newversion, array('total' => $total)); | |
1158 | } else { | |
1159 | print_error('versionerror', 'wiki'); | |
1160 | } | |
1161 | } | |
1162 | } | |
1163 | ||
1164 | /** | |
1165 | * | |
1166 | * Class that models the behavior of wiki's history page | |
1167 | * | |
1168 | */ | |
1169 | class page_wiki_history extends page_wiki { | |
1170 | /** | |
1171 | * @var int $paging current page | |
1172 | */ | |
1173 | private $paging; | |
1174 | ||
1175 | /** | |
1176 | * @var int @rowsperpage Items per page | |
1177 | */ | |
1178 | private $rowsperpage = 10; | |
1179 | ||
1180 | /** | |
1181 | * @var int $allversion if $allversion != 0, all versions will be printed in a signle table | |
1182 | */ | |
1183 | private $allversion; | |
1184 | ||
1185 | function __construct($wiki, $subwiki, $cm) { | |
1186 | global $PAGE; | |
1187 | parent::__construct($wiki, $subwiki, $cm); | |
1188 | $PAGE->requires->js_init_call('M.mod_wiki.history', null, true); | |
1189 | } | |
1190 | ||
1191 | function print_header() { | |
1192 | parent::print_header(); | |
1193 | $this->print_pagetitle(); | |
1194 | } | |
1195 | ||
d92b5e7f DC |
1196 | function print_pagetitle() { |
1197 | global $OUTPUT; | |
1198 | $html = ''; | |
1199 | ||
14cdc257 | 1200 | $html .= $OUTPUT->container_start('wiki_headingtitle'); |
876c0ac3 | 1201 | $html .= $OUTPUT->heading_with_help(format_string($this->title), 'history', 'wiki', '', '', 3); |
d92b5e7f DC |
1202 | $html .= $OUTPUT->container_end(); |
1203 | echo $html; | |
1204 | } | |
1205 | ||
00710f4c DC |
1206 | function print_content() { |
1207 | global $PAGE; | |
1208 | ||
cfdac90f | 1209 | require_capability('mod/wiki:viewpage', $this->modcontext, NULL, true, 'noviewpagepermission', 'wiki'); |
00710f4c DC |
1210 | |
1211 | $this->print_history_content(); | |
1212 | } | |
1213 | ||
1214 | function set_url() { | |
1215 | global $PAGE, $CFG; | |
1216 | $PAGE->set_url($CFG->wwwroot . '/mod/wiki/history.php', array('pageid' => $this->page->id)); | |
1217 | } | |
1218 | ||
1219 | function set_paging($paging) { | |
1220 | $this->paging = $paging; | |
1221 | } | |
1222 | ||
1223 | function set_allversion($allversion) { | |
1224 | $this->allversion = $allversion; | |
1225 | } | |
1226 | ||
1227 | protected function create_navbar() { | |
1228 | global $PAGE, $CFG; | |
1229 | ||
1230 | parent::create_navbar(); | |
1231 | $PAGE->navbar->add(get_string('history', 'wiki')); | |
1232 | } | |
1233 | ||
1234 | /** | |
1235 | * Prints the history for a given wiki page | |
1236 | * | |
cfdac90f DC |
1237 | * @global object $CFG |
1238 | * @global object $OUTPUT | |
1239 | * @global object $PAGE | |
00710f4c DC |
1240 | */ |
1241 | private function print_history_content() { | |
1242 | global $CFG, $OUTPUT, $PAGE; | |
1243 | ||
1244 | $pageid = $this->page->id; | |
1245 | $offset = $this->paging * $this->rowsperpage; | |
1246 | // vcount is the latest version | |
1247 | $vcount = wiki_count_wiki_page_versions($pageid) - 1; | |
1248 | if ($this->allversion) { | |
1249 | $versions = wiki_get_wiki_page_versions($pageid, 0, $vcount); | |
1250 | } else { | |
1251 | $versions = wiki_get_wiki_page_versions($pageid, $offset, $this->rowsperpage); | |
1252 | } | |
1253 | // We don't want version 0 to be displayed | |
1254 | // version 0 is blank page | |
1255 | if (end($versions)->version == 0) { | |
1256 | array_pop($versions); | |
1257 | } | |
1258 | ||
1259 | $contents = array(); | |
1260 | ||
1261 | $version0page = wiki_get_wiki_page_version($this->page->id, 0); | |
1262 | $creator = wiki_get_user_info($version0page->userid); | |
1263 | $a = new StdClass; | |
1264 | $a->date = userdate($this->page->timecreated, get_string('strftimedaydatetime', 'langconfig')); | |
6b3e5ab9 | 1265 | $a->username = fullname($creator); |
14cdc257 | 1266 | echo html_writer::tag ('div', get_string('createddate', 'wiki', $a), array('class' => 'wiki_headingtime')); |
00710f4c DC |
1267 | if ($vcount > 0) { |
1268 | ||
1269 | /// If there is only one version, we don't need radios nor forms | |
1270 | if (count($versions) == 1) { | |
1271 | ||
1272 | $row = array_shift($versions); | |
1273 | ||
1274 | $username = wiki_get_user_info($row->userid); | |
1275 | $picture = $OUTPUT->user_picture($username); | |
1276 | $date = userdate($row->timecreated, get_string('strftimedate', 'langconfig')); | |
1277 | $time = userdate($row->timecreated, get_string('strftimetime', 'langconfig')); | |
1278 | $versionid = wiki_get_version($row->id); | |
1279 | $versionlink = new moodle_url('/mod/wiki/viewversion.php', array('pageid' => $pageid, 'versionid' => $versionid->id)); | |
4a28ff88 | 1280 | $userlink = new moodle_url('/user/view.php', array('id' => $username->id, 'course' => $this->cm->course)); |
c4238816 | 1281 | $contents[] = array('', html_writer::link($versionlink->out(false), $row->version), $picture . html_writer::link($userlink->out(false), fullname($username)), $time, $OUTPUT->container($date, 'wiki_histdate')); |
00710f4c DC |
1282 | |
1283 | $table = new html_table(); | |
1284 | $table->head = array('', get_string('version'), get_string('user'), get_string('modified'), ''); | |
1285 | $table->data = $contents; | |
1286 | $table->attributes['class'] = 'mdl-align'; | |
1287 | ||
1288 | echo html_writer::table($table); | |
1289 | ||
1290 | } else { | |
1291 | ||
1292 | $checked = $vcount - $offset; | |
00710f4c DC |
1293 | $rowclass = array(); |
1294 | ||
1295 | foreach ($versions as $version) { | |
1296 | $user = wiki_get_user_info($version->userid); | |
1297 | $picture = $OUTPUT->user_picture($user, array('popup' => true)); | |
1298 | $date = userdate($version->timecreated, get_string('strftimedate')); | |
9f2dc66f | 1299 | $rowclass[] = 'wiki_histnewdate'; |
00710f4c DC |
1300 | $time = userdate($version->timecreated, get_string('strftimetime', 'langconfig')); |
1301 | $versionid = wiki_get_version($version->id); | |
1302 | if ($versionid) { | |
1303 | $url = new moodle_url('/mod/wiki/viewversion.php', array('pageid' => $pageid, 'versionid' => $versionid->id)); | |
1304 | $viewlink = html_writer::link($url->out(false), $version->version); | |
1305 | } else { | |
1306 | $viewlink = $version->version; | |
1307 | } | |
4a28ff88 | 1308 | $userlink = new moodle_url('/user/view.php', array('id' => $version->userid, 'course' => $this->cm->course)); |
c4238816 | 1309 | $contents[] = array($this->choose_from_radio(array($version->version => null), 'compare', 'M.mod_wiki.history()', $checked - 1, true) . $this->choose_from_radio(array($version->version => null), 'comparewith', 'M.mod_wiki.history()', $checked, true), $viewlink, $picture . html_writer::link($userlink->out(false), fullname($user)), $time, $OUTPUT->container($date, 'wiki_histdate')); |
00710f4c DC |
1310 | } |
1311 | ||
1312 | $table = new html_table(); | |
00710f4c | 1313 | |
f8be7ad4 JP |
1314 | $icon = $OUTPUT->help_icon('diff', 'wiki'); |
1315 | ||
1316 | $table->head = array(get_string('diff', 'wiki') . $icon, get_string('version'), get_string('user'), get_string('modified'), ''); | |
00710f4c | 1317 | $table->data = $contents; |
41a42c1d | 1318 | $table->attributes['class'] = 'generaltable mdl-align'; |
00710f4c DC |
1319 | $table->rowclasses = $rowclass; |
1320 | ||
a6d81a73 | 1321 | // Print the form. |
41a42c1d SH |
1322 | echo html_writer::start_tag('form', array('action'=>new moodle_url('/mod/wiki/diff.php'), 'method'=>'get', 'id'=>'diff')); |
1323 | echo html_writer::tag('div', html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'pageid', 'value'=>$pageid))); | |
00710f4c | 1324 | echo html_writer::table($table); |
41a42c1d SH |
1325 | echo html_writer::start_tag('div', array('class'=>'mdl-align')); |
1326 | echo html_writer::empty_tag('input', array('type'=>'submit', 'class'=>'wiki_form-button', 'value'=>get_string('comparesel', 'wiki'))); | |
1327 | echo html_writer::end_tag('div'); | |
1328 | echo html_writer::end_tag('form'); | |
00710f4c DC |
1329 | } |
1330 | } else { | |
1331 | print_string('nohistory', 'wiki'); | |
1332 | } | |
1333 | if (!$this->allversion) { | |
1334 | //$pagingbar = moodle_paging_bar::make($vcount, $this->paging, $this->rowsperpage, $CFG->wwwroot.'/mod/wiki/history.php?pageid='.$pageid.'&'); | |
1335 | // $pagingbar->pagevar = $pagevar; | |
1336 | echo $OUTPUT->paging_bar($vcount, $this->paging, $this->rowsperpage, $CFG->wwwroot . '/mod/wiki/history.php?pageid=' . $pageid . '&'); | |
1337 | //print_paging_bar($vcount, $paging, $rowsperpage,$CFG->wwwroot.'/mod/wiki/history.php?pageid='.$pageid.'&','paging'); | |
1338 | } else { | |
1339 | $link = new moodle_url('/mod/wiki/history.php', array('pageid' => $pageid)); | |
1340 | $OUTPUT->container(html_writer::link($link->out(false), get_string('viewperpage', 'wiki', $this->rowsperpage)), 'mdl-align'); | |
1341 | } | |
1342 | if ($vcount > $this->rowsperpage && !$this->allversion) { | |
1343 | $link = new moodle_url('/mod/wiki/history.php', array('pageid' => $pageid, 'allversion' => 1)); | |
1344 | $OUTPUT->container(html_writer::link($link->out(false), get_string('viewallhistory', 'wiki')), 'mdl-align'); | |
1345 | } | |
1346 | } | |
1347 | ||
1348 | /** | |
1349 | * Given an array of values, creates a group of radio buttons to be part of a form | |
1350 | * | |
1351 | * @param array $options An array of value-label pairs for the radio group (values as keys). | |
1352 | * @param string $name Name of the radiogroup (unique in the form). | |
1353 | * @param string $onclick Function to be executed when the radios are clicked. | |
1354 | * @param string $checked The value that is already checked. | |
1355 | * @param bool $return If true, return the HTML as a string, otherwise print it. | |
1356 | * | |
1357 | * @return mixed If $return is false, returns nothing, otherwise returns a string of HTML. | |
1358 | */ | |
1359 | private function choose_from_radio($options, $name, $onclick = '', $checked = '', $return = false) { | |
1360 | ||
1361 | static $idcounter = 0; | |
1362 | ||
1363 | if (!$name) { | |
1364 | $name = 'unnamed'; | |
1365 | } | |
1366 | ||
1367 | $output = '<span class="radiogroup ' . $name . "\">\n"; | |
1368 | ||
1369 | if (!empty($options)) { | |
1370 | $currentradio = 0; | |
1371 | foreach ($options as $value => $label) { | |
1372 | $htmlid = 'auto-rb' . sprintf('%04d', ++$idcounter); | |
1373 | $output .= ' <span class="radioelement ' . $name . ' rb' . $currentradio . "\">"; | |
1374 | $output .= '<input name="' . $name . '" id="' . $htmlid . '" type="radio" value="' . $value . '"'; | |
1375 | if ($value == $checked) { | |
1376 | $output .= ' checked="checked"'; | |
1377 | } | |
1378 | if ($onclick) { | |
1379 | $output .= ' onclick="' . $onclick . '"'; | |
1380 | } | |
1381 | if ($label === '') { | |
1382 | $output .= ' /> <label for="' . $htmlid . '">' . $value . '</label></span>' . "\n"; | |
1383 | } else { | |
1384 | $output .= ' /> <label for="' . $htmlid . '">' . $label . '</label></span>' . "\n"; | |
1385 | } | |
1386 | $currentradio = ($currentradio + 1) % 2; | |
1387 | } | |
1388 | } | |
1389 | ||
1390 | $output .= '</span>' . "\n"; | |
1391 | ||
1392 | if ($return) { | |
1393 | return $output; | |
1394 | } else { | |
1395 | echo $output; | |
1396 | } | |
1397 | } | |
1398 | } | |
1399 | ||
1400 | /** | |
1401 | * Class that models the behavior of wiki's map page | |
1402 | * | |
1403 | */ | |
1404 | class page_wiki_map extends page_wiki { | |
1405 | ||
1406 | /** | |
1407 | * @var int wiki view option | |
1408 | */ | |
1409 | private $view; | |
1410 | ||
1411 | function print_header() { | |
1412 | parent::print_header(); | |
1413 | $this->print_pagetitle(); | |
1414 | } | |
1415 | ||
1416 | function print_content() { | |
1417 | global $CFG, $PAGE; | |
1418 | ||
cfdac90f | 1419 | require_capability('mod/wiki:viewpage', $this->modcontext, NULL, true, 'noviewpagepermission', 'wiki'); |
00710f4c DC |
1420 | |
1421 | if ($this->view > 0) { | |
1422 | //echo '<div><a href="' . $CFG->wwwroot . '/mod/wiki/map.php?pageid=' . $this->page->id . '">' . get_string('backtomapmenu', 'wiki') . '</a></div>'; | |
d92b5e7f | 1423 | } |
00710f4c DC |
1424 | |
1425 | switch ($this->view) { | |
1426 | case 1: | |
1427 | echo $this->wikioutput->menu_map($this->page->id, $this->view); | |
1428 | $this->print_contributions_content(); | |
1429 | break; | |
1430 | case 2: | |
1431 | echo $this->wikioutput->menu_map($this->page->id, $this->view); | |
1432 | $this->print_navigation_content(); | |
1433 | break; | |
1434 | case 3: | |
1435 | echo $this->wikioutput->menu_map($this->page->id, $this->view); | |
1436 | $this->print_orphaned_content(); | |
1437 | break; | |
1438 | case 4: | |
1439 | echo $this->wikioutput->menu_map($this->page->id, $this->view); | |
1440 | $this->print_index_content(); | |
1441 | break; | |
00710f4c DC |
1442 | case 6: |
1443 | echo $this->wikioutput->menu_map($this->page->id, $this->view); | |
1444 | $this->print_updated_content(); | |
1445 | break; | |
3ef5218b | 1446 | case 5: |
00710f4c DC |
1447 | default: |
1448 | echo $this->wikioutput->menu_map($this->page->id, $this->view); | |
1449 | $this->print_page_list_content(); | |
1450 | } | |
1451 | } | |
1452 | ||
1453 | function set_view($option) { | |
1454 | $this->view = $option; | |
1455 | } | |
1456 | ||
00710f4c DC |
1457 | function set_url() { |
1458 | global $PAGE, $CFG; | |
1459 | $PAGE->set_url($CFG->wwwroot . '/mod/wiki/map.php', array('pageid' => $this->page->id)); | |
1460 | } | |
1461 | ||
1462 | protected function create_navbar() { | |
1463 | global $PAGE; | |
1464 | ||
1465 | parent::create_navbar(); | |
1466 | $PAGE->navbar->add(get_string('map', 'wiki')); | |
1467 | } | |
1468 | ||
1469 | /** | |
1470 | * Prints the contributions tab content | |
1471 | * | |
1472 | * @uses $OUTPUT, $USER | |
1473 | * | |
1474 | */ | |
1475 | private function print_contributions_content() { | |
1476 | global $CFG, $OUTPUT, $USER; | |
1477 | $page = $this->page; | |
1478 | ||
1479 | if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) { | |
1480 | $fresh = wiki_refresh_cachedcontent($page); | |
1481 | $page = $fresh['page']; | |
1482 | } | |
1483 | ||
1484 | $swid = $this->subwiki->id; | |
1485 | ||
1486 | $table = new html_table(); | |
b7d0b32f | 1487 | $table->head = array(get_string('contributions', 'wiki') . $OUTPUT->help_icon('contributions', 'wiki')); |
12f756f9 | 1488 | $table->attributes['class'] = 'wiki_editor generalbox'; |
00710f4c DC |
1489 | $table->data = array(); |
1490 | $table->rowclasses = array(); | |
1491 | ||
1492 | $lastversions = array(); | |
1493 | $pages = array(); | |
1494 | $users = array(); | |
1495 | ||
1496 | if ($contribs = wiki_get_contributions($swid, $USER->id)) { | |
1497 | foreach ($contribs as $contrib) { | |
1498 | if (!array_key_exists($contrib->pageid, $pages)) { | |
1499 | $page = wiki_get_page($contrib->pageid); | |
1500 | $pages[$contrib->pageid] = $page; | |
1501 | } else { | |
1502 | continue; | |
1503 | } | |
1504 | ||
1505 | if (!array_key_exists($page->id, $lastversions)) { | |
1506 | $version = wiki_get_last_version($page->id); | |
1507 | $lastversions[$page->id] = $version; | |
1508 | } else { | |
1509 | $version = $lastversions[$page->id]; | |
1510 | } | |
1511 | ||
1512 | if (!array_key_exists($version->userid, $users)) { | |
1513 | $user = wiki_get_user_info($version->userid); | |
1514 | $users[$version->userid] = $user; | |
1515 | } else { | |
1516 | $user = $users[$version->userid]; | |
1517 | } | |
1518 | ||
4c4e6591 | 1519 | $link = wiki_parser_link($page->title, array('swid' => $swid)); |
00710f4c DC |
1520 | $class = ($link['new']) ? 'class="wiki_newentry"' : ''; |
1521 | ||
4c4e6591 | 1522 | $linkpage = '<a href="' . $link['url'] . '"' . $class . '>' . format_string($link['content'], true, array('context' => $this->modcontext)) . '</a>'; |
00710f4c DC |
1523 | $icon = $OUTPUT->user_picture($user, array('popup' => true)); |
1524 | ||
1525 | $table->data[] = array("$icon $linkpage"); | |
1526 | } | |
1527 | } else { | |
1528 | $table->data[] = array(get_string('nocontribs', 'wiki')); | |
1529 | } | |
1530 | echo html_writer::table($table); | |
1531 | } | |
1532 | ||
1533 | /** | |
1534 | * Prints the navigation tab content | |
1535 | * | |
1536 | * @uses $OUTPUT | |
1537 | * | |
1538 | */ | |
1539 | private function print_navigation_content() { | |
1540 | global $OUTPUT; | |
1541 | $page = $this->page; | |
1542 | ||
1543 | if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) { | |
1544 | $fresh = wiki_refresh_cachedcontent($page); | |
1545 | $page = $fresh['page']; | |
1546 | } | |
1547 | ||
1548 | $tolinks = wiki_get_linked_to_pages($page->id); | |
1549 | $fromlinks = wiki_get_linked_from_pages($page->id); | |
1550 | ||
1551 | $table = new html_table(); | |
1552 | $table->attributes['class'] = 'wiki_navigation_from'; | |
d92b5e7f | 1553 | $table->head = array(get_string('navigationfrom', 'wiki') . $OUTPUT->help_icon('navigationfrom', 'wiki') . ':'); |
00710f4c DC |
1554 | $table->data = array(); |
1555 | $table->rowclasses = array(); | |
1556 | foreach ($fromlinks as $link) { | |
1557 | $lpage = wiki_get_page($link->frompageid); | |
1558 | $link = new moodle_url('/mod/wiki/view.php', array('pageid' => $lpage->id)); | |
110f4c93 | 1559 | $table->data[] = array(html_writer::link($link->out(false), format_string($lpage->title))); |
00710f4c DC |
1560 | $table->rowclasses[] = 'mdl-align'; |
1561 | } | |
1562 | ||
1563 | $table_left = html_writer::table($table); | |
1564 | ||
1565 | $table = new html_table(); | |
1566 | $table->attributes['class'] = 'wiki_navigation_to'; | |
d92b5e7f | 1567 | $table->head = array(get_string('navigationto', 'wiki') . $OUTPUT->help_icon('navigationto', 'wiki') . ':'); |
00710f4c DC |
1568 | $table->data = array(); |
1569 | $table->rowclasses = array(); | |
1570 | foreach ($tolinks as $link) { | |
1571 | if ($link->tomissingpage) { | |
1572 | $viewlink = new moodle_url('/mod/wiki/create.php', array('swid' => $page->subwikiid, 'title' => $link->tomissingpage, 'action' => 'new')); | |
af857b05 | 1573 | $table->data[] = array(html_writer::link($viewlink->out(false), format_string($link->tomissingpage), array('class' => 'wiki_newentry'))); |
00710f4c DC |
1574 | } else { |
1575 | $lpage = wiki_get_page($link->topageid); | |
1576 | $viewlink = new moodle_url('/mod/wiki/view.php', array('pageid' => $lpage->id)); | |
110f4c93 | 1577 | $table->data[] = array(html_writer::link($viewlink->out(false), format_string($lpage->title))); |
00710f4c DC |
1578 | } |
1579 | $table->rowclasses[] = 'mdl-align'; | |
1580 | } | |
1581 | $table_right = html_writer::table($table); | |
1582 | echo $OUTPUT->container($table_left . $table_right, 'wiki_navigation_container'); | |
1583 | } | |
1584 | ||
1585 | /** | |
1586 | * Prints the index page tab content | |
1587 | * | |
1588 | * | |
1589 | */ | |
1590 | private function print_index_content() { | |
d92b5e7f | 1591 | global $OUTPUT; |
00710f4c DC |
1592 | $page = $this->page; |
1593 | ||
1594 | if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) { | |
1595 | $fresh = wiki_refresh_cachedcontent($page); | |
1596 | $page = $fresh['page']; | |
1597 | } | |
1598 | ||
4c4e6591 | 1599 | // navigation_node get_content calls format string for us |
00710f4c DC |
1600 | $node = new navigation_node($page->title); |
1601 | ||
1602 | $keys = array(); | |
1603 | $tree = array(); | |
1604 | $tree = wiki_build_tree($page, $node, $keys); | |
1605 | ||
1606 | $table = new html_table(); | |
d92b5e7f | 1607 | $table->head = array(get_string('pageindex', 'wiki') . $OUTPUT->help_icon('pageindex', 'wiki')); |
12f756f9 | 1608 | $table->attributes['class'] = 'wiki_editor generalbox'; |
00710f4c DC |
1609 | $table->data[] = array($this->render_navigation_node($tree)); |
1610 | ||
1611 | echo html_writer::table($table); | |
1612 | } | |
1613 | ||
1614 | /** | |
1615 | * Prints the page list tab content | |
1616 | * | |
1617 | * | |
1618 | */ | |
1619 | private function print_page_list_content() { | |
d92b5e7f | 1620 | global $OUTPUT; |
00710f4c DC |
1621 | $page = $this->page; |
1622 | ||
1623 | if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) { | |
1624 | $fresh = wiki_refresh_cachedcontent($page); | |
1625 | $page = $fresh['page']; | |
1626 | } | |
1627 | ||
1628 | $pages = wiki_get_page_list($this->subwiki->id); | |
1629 | ||
1630 | $stdaux = new stdClass(); | |
1631 | $strspecial = get_string('special', 'wiki'); | |
1632 | ||
1633 | foreach ($pages as $page) { | |
4c4e6591 SH |
1634 | // We need to format the title here to account for any filtering |
1635 | $letter = format_string($page->title, true, array('context' => $this->modcontext)); | |
2f1e464a | 1636 | $letter = core_text::substr($letter, 0, 1); |
4c4e6591 | 1637 | if (preg_match('/^[a-zA-Z]$/', $letter)) { |
2f1e464a | 1638 | $letter = core_text::strtoupper($letter); |
4c4e6591 | 1639 | $stdaux->{$letter}[] = wiki_parser_link($page); |
00710f4c | 1640 | } else { |
4c4e6591 | 1641 | $stdaux->{$strspecial}[] = wiki_parser_link($page); |
00710f4c DC |
1642 | } |
1643 | } | |
1644 | ||
1645 | $table = new html_table(); | |
d92b5e7f | 1646 | $table->head = array(get_string('pagelist', 'wiki') . $OUTPUT->help_icon('pagelist', 'wiki')); |
12f756f9 | 1647 | $table->attributes['class'] = 'wiki_editor generalbox'; |
00710f4c DC |
1648 | $table->align = array('center'); |
1649 | foreach ($stdaux as $key => $elem) { | |
1650 | $table->data[] = array($key); | |
1651 | foreach ($elem as $e) { | |
4c4e6591 | 1652 | $table->data[] = array(html_writer::link($e['url'], format_string($e['content'], true, array('context' => $this->modcontext)))); |
00710f4c DC |
1653 | } |
1654 | } | |
1655 | echo html_writer::table($table); | |
1656 | } | |
1657 | ||
1658 | /** | |
1659 | * Prints the orphaned tab content | |
1660 | * | |
1661 | * | |
1662 | */ | |
1663 | private function print_orphaned_content() { | |
9e11d507 JP |
1664 | global $OUTPUT; |
1665 | ||
00710f4c DC |
1666 | $page = $this->page; |
1667 | ||
1668 | if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) { | |
1669 | $fresh = wiki_refresh_cachedcontent($page); | |
1670 | $page = $fresh['page']; | |
1671 | } | |
1672 | ||
1673 | $swid = $this->subwiki->id; | |
1674 | ||
1675 | $table = new html_table(); | |
b7d0b32f | 1676 | $table->head = array(get_string('orphaned', 'wiki') . $OUTPUT->help_icon('orphaned', 'wiki')); |
12f756f9 | 1677 | $table->attributes['class'] = 'wiki_editor generalbox'; |
00710f4c DC |
1678 | $table->data = array(); |
1679 | $table->rowclasses = array(); | |
1680 | ||
1681 | if ($orphanedpages = wiki_get_orphaned_pages($swid)) { | |
1682 | foreach ($orphanedpages as $page) { | |
110f4c93 | 1683 | $link = wiki_parser_link($page->title, array('swid' => $swid)); |
00710f4c | 1684 | $class = ($link['new']) ? 'class="wiki_newentry"' : ''; |
110f4c93 | 1685 | $table->data[] = array('<a href="' . $link['url'] . '"' . $class . '>' . format_string($link['content']) . '</a>'); |
00710f4c DC |
1686 | } |
1687 | } else { | |
1688 | $table->data[] = array(get_string('noorphanedpages', 'wiki')); | |
1689 | } | |
1690 | ||
1691 | echo html_writer::table($table); | |
1692 | } | |
1693 | ||
1694 | /** | |
1695 | * Prints the updated tab content | |
1696 | * | |
1697 | * @uses $COURSE, $OUTPUT | |
1698 | * | |
1699 | */ | |
1700 | private function print_updated_content() { | |
1701 | global $COURSE, $OUTPUT; | |
1702 | $page = $this->page; | |
1703 | ||
1704 | if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) { | |
1705 | $fresh = wiki_refresh_cachedcontent($page); | |
1706 | $page = $fresh['page']; | |
1707 | } | |
1708 | ||
1709 | $swid = $this->subwiki->id; | |
1710 | ||
1711 | $table = new html_table(); | |
d92b5e7f | 1712 | $table->head = array(get_string('updatedpages', 'wiki') . $OUTPUT->help_icon('updatedpages', 'wiki')); |
12f756f9 | 1713 | $table->attributes['class'] = 'wiki_editor generalbox'; |
00710f4c DC |
1714 | $table->data = array(); |
1715 | $table->rowclasses = array(); | |
1716 | ||
1717 | if ($pages = wiki_get_updated_pages_by_subwiki($swid)) { | |
1718 | $strdataux = ''; | |
1719 | foreach ($pages as $page) { | |
1720 | $user = wiki_get_user_info($page->userid); | |
1721 | $strdata = strftime('%d %b %Y', $page->timemodified); | |
1722 | if ($strdata != $strdataux) { | |
1723 | $table->data[] = array($OUTPUT->heading($strdata, 4)); | |
1724 | $strdataux = $strdata; | |
1725 | } | |
110f4c93 | 1726 | $link = wiki_parser_link($page->title, array('swid' => $swid)); |
00710f4c DC |
1727 | $class = ($link['new']) ? 'class="wiki_newentry"' : ''; |
1728 | ||
110f4c93 | 1729 | $linkpage = '<a href="' . $link['url'] . '"' . $class . '>' . format_string($link['content']) . '</a>'; |
00710f4c DC |
1730 | $icon = $OUTPUT->user_picture($user, array($COURSE->id)); |
1731 | $table->data[] = array("$icon $linkpage"); | |
1732 | } | |
1733 | } else { | |
1734 | $table->data[] = array(get_string('noupdatedpages', 'wiki')); | |
1735 | } | |
1736 | ||
1737 | echo html_writer::table($table); | |
1738 | } | |
1739 | ||
1740 | protected function render_navigation_node($items, $attrs = array(), $expansionlimit = null, $depth = 1) { | |
1741 | ||
1742 | // exit if empty, we don't want an empty ul element | |
1743 | if (count($items) == 0) { | |
1744 | return ''; | |
1745 | } | |
1746 | ||
1747 | // array of nested li elements | |
1748 | $lis = array(); | |
1749 | foreach ($items as $item) { | |
1750 | if (!$item->display) { | |
1751 | continue; | |
1752 | } | |
1753 | $content = $item->get_content(); | |
1754 | $title = $item->get_title(); | |
1755 | if ($item->icon instanceof renderable) { | |
1756 | $icon = $this->wikioutput->render($item->icon); | |
1757 | $content = $icon . ' ' . $content; // use CSS for spacing of icons | |
1758 | } | |
1759 | if ($item->helpbutton !== null) { | |
1760 | $content = trim($item->helpbutton) . html_writer::tag('span', $content, array('class' => 'clearhelpbutton')); | |
1761 | } | |
1762 | ||
1763 | if ($content === '') { | |
1764 | continue; | |
1765 | } | |
1766 | ||
1767 | if ($item->action instanceof action_link) { | |
1768 | //TODO: to be replaced with something else | |
1769 | $link = $item->action; | |
1770 | if ($item->hidden) { | |
1771 | $link->add_class('dimmed'); | |
1772 | } | |
1773 | $content = $this->output->render($link); | |
1774 | } else if ($item->action instanceof moodle_url) { | |
1775 | $attributes = array(); | |
1776 | if ($title !== '') { | |
1777 | $attributes['title'] = $title; | |
1778 | } | |
1779 | if ($item->hidden) { | |
1780 | $attributes['class'] = 'dimmed_text'; | |
1781 | } | |
1782 | $content = html_writer::link($item->action, $content, $attributes); | |
1783 | ||
1784 | } else if (is_string($item->action) || empty($item->action)) { | |
1785 | $attributes = array(); | |
1786 | if ($title !== '') { | |
1787 | $attributes['title'] = $title; | |
1788 | } | |
1789 | if ($item->hidden) { | |
1790 | $attributes['class'] = 'dimmed_text'; | |
1791 | } | |
1792 | $content = html_writer::tag('span', $content, $attributes); | |
1793 | } | |
1794 | ||
1795 | // this applies to the li item which contains all child lists too | |
1796 | $liclasses = array($item->get_css_type(), 'depth_' . $depth); | |
1797 | if ($item->has_children() && (!$item->forceopen || $item->collapse)) { | |
1798 | $liclasses[] = 'collapsed'; | |
1799 | } | |
1800 | if ($item->isactive === true) { | |
1801 | $liclasses[] = 'current_branch'; | |
1802 | } | |
1803 | $liattr = array('class' => join(' ', $liclasses)); | |
1804 | // class attribute on the div item which only contains the item content | |
1805 | $divclasses = array('tree_item'); | |
1806 | if ((empty($expansionlimit) || $item->type != $expansionlimit) && ($item->children->count() > 0 || ($item->nodetype == navigation_node::NODETYPE_BRANCH && $item->children->count() == 0 && isloggedin()))) { | |
1807 | $divclasses[] = 'branch'; | |
1808 | } else { | |
1809 | $divclasses[] = 'leaf'; | |
1810 | } | |
1811 | if (!empty($item->classes) && count($item->classes) > 0) { | |
1812 | $divclasses[] = join(' ', $item->classes); | |
1813 | } | |
1814 | $divattr = array('class' => join(' ', $divclasses)); | |
1815 | if (!empty($item->id)) { | |
1816 | $divattr['id'] = $item->id; | |
1817 | } | |
1818 | $content = html_writer::tag('p', $content, $divattr) . $this->render_navigation_node($item->children, array(), $expansionlimit, $depth + 1); | |
1819 | if (!empty($item->preceedwithhr) && $item->preceedwithhr === true) { | |
1820 | $content = html_writer::empty_tag('hr') . $content; | |
1821 | } | |
1822 | $content = html_writer::tag('li', $content, $liattr); | |
1823 | $lis[] = $content; | |
1824 | } | |
1825 | ||
1826 | if (count($lis)) { | |
1827 | return html_writer::tag('ul', implode("\n", $lis), $attrs); | |
1828 | } else { | |
1829 | return ''; | |
1830 | } | |
1831 | } | |
1832 | ||
1833 | } | |
1834 | ||
1835 | /** | |
1836 | * Class that models the behavior of wiki's restore version page | |
1837 | * | |
1838 | */ | |
1839 | class page_wiki_restoreversion extends page_wiki { | |
1840 | private $version; | |
1841 | ||
1842 | function print_header() { | |
1843 | parent::print_header(); | |
1844 | $this->print_pagetitle(); | |
1845 | } | |
1846 | ||
1847 | function print_content() { | |
846f6886 | 1848 | global $PAGE; |
00710f4c | 1849 | |
846f6886 MG |
1850 | $wiki = $PAGE->activityrecord; |
1851 | if (wiki_user_can_edit($this->subwiki, $wiki)) { | |
1852 | $this->print_restoreversion(); | |
1853 | } else { | |
1854 | echo get_string('cannoteditpage', 'wiki'); | |
1855 | } | |
00710f4c | 1856 | |
00710f4c DC |
1857 | } |
1858 | ||
1859 | function set_url() { | |
1860 | global $PAGE, $CFG; | |
1861 | $PAGE->set_url($CFG->wwwroot . '/mod/wiki/viewversion.php', array('pageid' => $this->page->id, 'versionid' => $this->version->id)); | |
1862 | } | |
1863 | ||
1864 | function set_versionid($versionid) { | |
1865 | $this->version = wiki_get_version($versionid); | |
1866 | } | |
1867 | ||
1868 | protected function create_navbar() { | |
1869 | global $PAGE, $CFG; | |
1870 | ||
1871 | parent::create_navbar(); | |
1872 | $PAGE->navbar->add(get_string('restoreversion', 'wiki')); | |
1873 | } | |
1874 | ||
54352ac9 | 1875 | protected function setup_tabs($options = array()) { |
00710f4c DC |
1876 | parent::setup_tabs(array('linkedwhenactive' => 'history', 'activetab' => 'history')); |
1877 | } | |
1878 | ||
1879 | /** | |
1880 | * Prints the restore version content | |
1881 | * | |
1882 | * @uses $CFG | |
1883 | * | |
1884 | * @param page $page The page whose version will be restored | |
1885 | * @param int $versionid The version to be restored | |
1886 | * @param bool $confirm If false, shows a yes/no confirmation page. | |
1887 | * If true, restores the old version and redirects the user to the 'view' tab. | |
1888 | */ | |
1889 | private function print_restoreversion() { | |
48346fb1 | 1890 | global $OUTPUT; |
00710f4c DC |
1891 | |
1892 | $version = wiki_get_version($this->version->id); | |
1893 | ||
48346fb1 AB |
1894 | $optionsyes = array('confirm'=>1, 'pageid'=>$this->page->id, 'versionid'=>$version->id, 'sesskey'=>sesskey()); |
1895 | $restoreurl = new moodle_url('/mod/wiki/restoreversion.php', $optionsyes); | |
1896 | $return = new moodle_url('/mod/wiki/viewversion.php', array('pageid'=>$this->page->id, 'versionid'=>$version->id)); | |
1897 | ||
14cdc257 RW |
1898 | echo $OUTPUT->container_start('wiki-form-center'); |
1899 | echo html_writer::tag('div', get_string('restoreconfirm', 'wiki', $version->version)); | |
caf8d39b | 1900 | echo $OUTPUT->container_start(false, 'wiki_restoreform'); |
48346fb1 | 1901 | echo '<form class="wiki_restore_yes" action="' . $restoreurl . '" method="post" id="restoreversion">'; |
00710f4c DC |
1902 | echo '<div><input type="submit" name="confirm" value="' . get_string('yes') . '" /></div>'; |
1903 | echo '</form>'; | |
48346fb1 | 1904 | echo '<form class="wiki_restore_no" action="' . $return . '" method="post">'; |
00710f4c DC |
1905 | echo '<div><input type="submit" name="norestore" value="' . get_string('no') . '" /></div>'; |
1906 | echo '</form>'; | |
caf8d39b | 1907 | echo $OUTPUT->container_end(); |
14cdc257 | 1908 | echo $OUTPUT->container_end(); |
00710f4c DC |
1909 | } |
1910 | } | |
00710f4c | 1911 | /** |
48346fb1 | 1912 | * Class that models the behavior of wiki's delete comment confirmation page |
00710f4c | 1913 | * |
48346fb1 AB |
1914 | */ |
1915 | class page_wiki_deletecomment extends page_wiki { | |
1916 | private $commentid; | |
1917 | ||
1918 | function print_header() { | |
1919 | parent::print_header(); | |
1920 | $this->print_pagetitle(); | |
1921 | } | |
1922 | ||
1923 | function print_content() { | |
1924 | $this->printconfirmdelete(); | |
1925 | } | |
1926 | ||
1927 | function set_url() { | |
1928 | global $PAGE; | |
1929 | $PAGE->set_url('/mod/wiki/instancecomments.php', array('pageid' => $this->page->id, 'commentid' => $this->commentid)); | |
1930 | } | |
1931 | ||
1932 | public function set_action($action, $commentid, $content) { | |
1933 | $this->action = $action; | |
1934 | $this->commentid = $commentid; | |
1935 | $this->content = $content; | |
1936 | } | |
1937 | ||
1938 | protected function create_navbar() { | |
1939 | global $PAGE; | |
1940 | ||
1941 | parent::create_navbar(); | |
1942 | $PAGE->navbar->add(get_string('deletecommentcheck', 'wiki')); | |
1943 | } | |
1944 | ||
54352ac9 | 1945 | protected function setup_tabs($options = array()) { |
48346fb1 AB |
1946 | parent::setup_tabs(array('linkedwhenactive' => 'comments', 'activetab' => 'comments')); |
1947 | } | |
1948 | ||
1949 | /** | |
1950 | * Prints the comment deletion confirmation form | |
1951 | * | |
1952 | * @param page $page The page whose version will be restored | |
1953 | * @param int $versionid The version to be restored | |
1954 | * @param bool $confirm If false, shows a yes/no confirmation page. | |
1955 | * If true, restores the old version and redirects the user to the 'view' tab. | |
1956 | */ | |
1957 | private function printconfirmdelete() { | |
1958 | global $OUTPUT; | |
1959 | ||
1960 | $strdeletecheck = get_string('deletecommentcheck', 'wiki'); | |
1961 | $strdeletecheckfull = get_string('deletecommentcheckfull', 'wiki'); | |
1962 | ||
1963 | //ask confirmation | |
1964 | $optionsyes = array('confirm'=>1, 'pageid'=>$this->page->id, 'action'=>'delete', 'commentid'=>$this->commentid, 'sesskey'=>sesskey()); | |
1965 | $deleteurl = new moodle_url('/mod/wiki/instancecomments.php', $optionsyes); | |
1966 | $return = new moodle_url('/mod/wiki/comments.php', array('pageid'=>$this->page->id)); | |
1967 | ||
f7bfb405 RW |
1968 | echo $OUTPUT->container_start('wiki-form-center'); |
1969 | echo html_writer::tag('p', $strdeletecheckfull); | |
caf8d39b | 1970 | echo $OUTPUT->container_start(false, 'wiki_deletecommentform'); |
48346fb1 AB |
1971 | echo '<form class="wiki_deletecomment_yes" action="' . $deleteurl . '" method="post" id="deletecomment">'; |
1972 | echo '<div><input type="submit" name="confirmdeletecomment" value="' . get_string('yes') . '" /></div>'; | |
1973 | echo '</form>'; | |
1974 | echo '<form class="wiki_deletecomment_no" action="' . $return . '" method="post">'; | |
1975 | echo '<div><input type="submit" name="norestore" value="' . get_string('no') . '" /></div>'; | |
1976 | echo '</form>'; | |
caf8d39b | 1977 | echo $OUTPUT->container_end(); |
f7bfb405 | 1978 | echo $OUTPUT->container_end(); |
48346fb1 AB |
1979 | } |
1980 | } | |
1981 | ||
1982 | /** | |
00710f4c DC |
1983 | * Class that models the behavior of wiki's |
1984 | * save page | |
1985 | * | |
1986 | */ | |
1987 | class page_wiki_save extends page_wiki_edit { | |
1988 | ||
1989 | private $newcontent; | |
1990 | ||
1991 | function print_header() { | |
1992 | } | |
1993 | ||
1994 | function print_content() { | |
1995 | global $PAGE; | |
1996 | ||
4a28ff88 | 1997 | $context = context_module::instance($this->cm->id); |
00710f4c DC |
1998 | require_capability('mod/wiki:editpage', $context, NULL, true, 'noeditpermission', 'wiki'); |
1999 | ||
2000 | $this->print_save(); | |
2001 | } | |
2002 | ||
2003 | function set_newcontent($newcontent) { | |
2004 | $this->newcontent = $newcontent; | |
2005 | } | |
2006 | ||
2007 | protected function set_session_url() { | |
2008 | } | |
2009 | ||
2010 | protected function print_save() { | |
2011 | global $CFG, $USER, $OUTPUT, $PAGE; | |
2012 | ||
00710f4c DC |
2013 | $url = $CFG->wwwroot . '/mod/wiki/edit.php?pageid=' . $this->page->id; |
2014 | if (!empty($this->section)) { | |
1323bf55 | 2015 | $url .= "§ion=" . urlencode($this->section); |
00710f4c DC |
2016 | } |
2017 | ||
4c4e6591 SH |
2018 | $params = array( |
2019 | 'attachmentoptions' => page_wiki_edit::$attachmentoptions, | |
2020 | 'format' => $this->format, | |
2021 | 'version' => $this->versionnumber, | |
2022 | 'contextid' => $this->modcontext->id | |
2023 | ); | |
00710f4c DC |
2024 | |
2025 | if ($this->format != 'html') { | |
00710f4c | 2026 | $params['fileitemid'] = $this->page->id; |
12c9bbbd DC |
2027 | $params['component'] = 'mod_wiki'; |
2028 | $params['filearea'] = 'attachments'; | |
00710f4c DC |
2029 | } |
2030 | ||
2031 | $form = new mod_wiki_edit_form($url, $params); | |
2032 | ||
2033 | $save = false; | |
2034 | $data = false; | |
2035 | if ($data = $form->get_data()) { | |
2036 | if ($this->format == 'html') { | |
cfdac90f | 2037 | $data = file_postupdate_standard_editor($data, 'newcontent', page_wiki_edit::$attachmentoptions, $this->modcontext, 'mod_wiki', 'attachments', $this->subwiki->id); |
00710f4c DC |
2038 | } |
2039 | ||
2040 | if (isset($this->section)) { | |
2041 | $save = wiki_save_section($this->page, $this->section, $data->newcontent, $USER->id); | |
2042 | } else { | |
2043 | $save = wiki_save_page($this->page, $data->newcontent, $USER->id); | |
2044 | } | |
2045 | } | |
2046 | ||
2047 | if ($save && $data) { | |
00710f4c | 2048 | if (!empty($CFG->usetags)) { |
cc033d48 | 2049 | tag_set('wiki_pages', $this->page->id, $data->tags, 'mod_wiki', $this->modcontext->id); |
00710f4c DC |
2050 | } |
2051 | ||
2052 | $message = '<p>' . get_string('saving', 'wiki') . '</p>'; | |
2053 | ||
2054 | if (!empty($save['sections'])) { | |
2055 | foreach ($save['sections'] as $s) { | |
2056 | $message .= '<p>' . get_string('repeatedsection', 'wiki', $s) . '</p>'; | |
2057 | } | |
2058 | } | |
2059 | ||
2060 | if ($this->versionnumber + 1 != $save['version']) { | |
2061 | $message .= '<p>' . get_string('wrongversionsave', 'wiki') . '</p>'; | |
2062 | } | |
2063 | ||
2064 | if (isset($errors) && !empty($errors)) { | |
2065 | foreach ($errors as $e) { | |
2066 | $message .= "<p>" . get_string('filenotuploadederror', 'wiki', $e->get_filename()) . "</p>"; | |
2067 | } | |
2068 | } | |
2069 | ||
2070 | //deleting old locks | |
2071 | wiki_delete_locks($this->page->id, $USER->id, $this->section); | |
4f6c447b | 2072 | $url = new moodle_url('/mod/wiki/view.php', array('pageid' => $this->page->id, 'group' => $this->subwiki->groupid)); |
5dedd64d | 2073 | redirect($url); |
00710f4c DC |
2074 | } else { |
2075 | print_error('savingerror', 'wiki'); | |
2076 | } | |
2077 | } | |
2078 | } | |
2079 | ||
2080 | /** | |
2081 | * Class that models the behavior of wiki's view an old version of a page | |
2082 | * | |
2083 | */ | |
2084 | class page_wiki_viewversion extends page_wiki { | |
2085 | ||
2086 | private $version; | |
2087 | ||
2088 | function print_header() { | |
2089 | parent::print_header(); | |
2090 | $this->print_pagetitle(); | |
2091 | } | |
2092 | ||
2093 | function print_content() { | |
2094 | global $PAGE; | |
2095 | ||
cfdac90f | 2096 | require_capability('mod/wiki:viewpage', $this->modcontext, NULL, true, 'noviewpagepermission', 'wiki'); |
00710f4c DC |
2097 | |
2098 | $this->print_version_view(); | |
2099 | } | |
2100 | ||
2101 | function set_url() { | |
2102 | global $PAGE, $CFG; | |
2103 | $PAGE->set_url($CFG->wwwroot . '/mod/wiki/viewversion.php', array('pageid' => $this->page->id, 'versionid' => $this->version->id)); | |
2104 | } | |
2105 | ||
2106 | function set_versionid($versionid) { | |
2107 | $this->version = wiki_get_version($versionid); | |
2108 | } | |
2109 | ||
2110 | protected function create_navbar() { | |
2111 | global $PAGE, $CFG; | |
2112 | ||
2113 | parent::create_navbar(); | |
83cfd144 | 2114 | $PAGE->navbar->add(get_string('history', 'wiki'), $CFG->wwwroot . '/mod/wiki/history.php?pageid=' . $this->page->id); |
00710f4c DC |
2115 | $PAGE->navbar->add(get_string('versionnum', 'wiki', $this->version->version)); |
2116 | } | |
2117 | ||
54352ac9 | 2118 | protected function setup_tabs($options = array()) { |
00710f4c DC |
2119 | parent::setup_tabs(array('linkedwhenactive' => 'history', 'activetab' => 'history', 'inactivetabs' => array('edit'))); |
2120 | } | |
2121 | ||
2122 | /** | |
2123 | * Given an old page version, output the version content | |
2124 | * | |
cfdac90f DC |
2125 | * @global object $CFG |
2126 | * @global object $OUTPUT | |
2127 | * @global object $PAGE | |
00710f4c DC |
2128 | */ |
2129 | private function print_version_view() { | |
2130 | global $CFG, $OUTPUT, $PAGE; | |
00710f4c DC |
2131 | $pageversion = wiki_get_version($this->version->id); |
2132 | ||
2133 | if ($pageversion) { | |
2134 | $restorelink = new moodle_url('/mod/wiki/restoreversion.php', array('pageid' => $this->page->id, 'versionid' => $this->version->id)); | |
14cdc257 | 2135 | echo html_writer::tag('div', get_string('viewversion', 'wiki', $pageversion->version) . '<br />' . |
876c0ac3 | 2136 | html_writer::link($restorelink->out(false), '(' . get_string('restorethis', 'wiki') . |
14cdc257 | 2137 | ')', array('class' => 'wiki_restore')) . ' ', array('class' => 'wiki_headingtitle')); |
00710f4c DC |
2138 | $userinfo = wiki_get_user_info($pageversion->userid); |
2139 | $heading = '<p><strong>' . get_string('modified', 'wiki') . ':</strong> ' . userdate($pageversion->timecreated, get_string('strftimedatetime', 'langconfig')); | |
2140 | $viewlink = new moodle_url('/user/view.php', array('id' => $userinfo->id)); | |
2141 | $heading .= ' <strong>' . get_string('user') . ':</strong> ' . html_writer::link($viewlink->out(false), fullname($userinfo)); | |
2142 | $heading .= ' → ' . $OUTPUT->user_picture(wiki_get_user_info($pageversion->userid), array('popup' => true)) . '</p>'; | |
14cdc257 | 2143 | echo $OUTPUT->container($heading, 'wiki_headingtime', 'mdl-align wiki_modifieduser'); |
00710f4c | 2144 | $options = array('swid' => $this->subwiki->id, 'pretty_print' => true, 'pageid' => $this->page->id); |
cfdac90f DC |
2145 | |
2146 | $pageversion->content = file_rewrite_pluginfile_urls($pageversion->content, 'pluginfile.php', $this->modcontext->id, 'mod_wiki', 'attachments', $this->subwiki->id); | |
2147 | ||
00710f4c | 2148 | $parseroutput = wiki_parse_content($pageversion->contentformat, $pageversion->content, $options); |
caf8d39b | 2149 | $content = $OUTPUT->container(format_text($parseroutput['parsed_text'], FORMAT_HTML, array('overflowdiv'=>true)), false, '', '', true); |
00710f4c DC |
2150 | echo $OUTPUT->box($content, 'generalbox wiki_contentbox'); |
2151 | ||
2152 | } else { | |
2153 | print_error('versionerror', 'wiki'); | |
2154 | } | |
2155 | } | |
2156 | } | |
2157 | ||
2158 | class page_wiki_confirmrestore extends page_wiki_save { | |
2159 | ||
2160 | private $version; | |
2161 | ||
2162 | function set_url() { | |
2163 | global $PAGE, $CFG; | |
2164 | $PAGE->set_url($CFG->wwwroot . '/mod/wiki/viewversion.php', array('pageid' => $this->page->id, 'versionid' => $this->version->id)); | |
2165 | } | |
2166 | ||
2f8d2634 MG |
2167 | function print_header() { |
2168 | $this->set_url(); | |
2169 | } | |
2170 | ||
00710f4c DC |
2171 | function print_content() { |
2172 | global $CFG, $PAGE; | |
2173 | ||
00710f4c | 2174 | $version = wiki_get_version($this->version->id); |
846f6886 MG |
2175 | $wiki = $PAGE->activityrecord; |
2176 | if (wiki_user_can_edit($this->subwiki, $wiki) && | |
2177 | wiki_restore_page($this->page, $version, $this->modcontext)) { | |
00710f4c DC |
2178 | redirect($CFG->wwwroot . '/mod/wiki/view.php?pageid=' . $this->page->id, get_string('restoring', 'wiki', $version->version), 3); |
2179 | } else { | |
2180 | print_error('restoreerror', 'wiki', $version->version); | |
2181 | } | |
2182 | } | |
2183 | ||
2184 | function set_versionid($versionid) { | |
2185 | $this->version = wiki_get_version($versionid); | |
2186 | } | |
2187 | } | |
2188 | ||
2189 | class page_wiki_prettyview extends page_wiki { | |
2190 | ||
74eab231 RW |
2191 | function __construct($wiki, $subwiki, $cm) { |
2192 | global $PAGE; | |
231b0b30 | 2193 | $PAGE->set_pagelayout('embedded'); |
74eab231 RW |
2194 | parent::__construct($wiki, $subwiki, $cm); |
2195 | } | |
2196 | ||
2197 | function print_header() { | |
2198 | global $OUTPUT; | |
2199 | $this->set_url(); | |
2200 | ||
231b0b30 | 2201 | echo $OUTPUT->header(); |
be27bd59 RW |
2202 | // Print dialog link. |
2203 | $printtext = get_string('print', 'wiki'); | |
2204 | $printlinkatt = array('onclick' => 'window.print();return false;', 'class' => 'printicon'); | |
2205 | $printiconlink = html_writer::link('#', $printtext, $printlinkatt); | |
2206 | echo html_writer::tag('div', $printiconlink, array('class' => 'displayprinticon')); | |
74eab231 | 2207 | echo html_writer::tag('h1', format_string($this->title), array('id' => 'wiki_printable_title')); |
00710f4c DC |
2208 | } |
2209 | ||
2210 | function print_content() { | |
2211 | global $PAGE; | |
2212 | ||
cfdac90f | 2213 | require_capability('mod/wiki:viewpage', $this->modcontext, NULL, true, 'noviewpagepermission', 'wiki'); |
00710f4c DC |
2214 | |
2215 | $this->print_pretty_view(); | |
2216 | } | |
2217 | ||
2218 | function set_url() { | |
2219 | global $PAGE, $CFG; | |
2220 | ||
2221 | $PAGE->set_url($CFG->wwwroot . '/mod/wiki/prettyview.php', array('pageid' => $this->page->id)); | |
2222 | } | |
2223 | ||
00710f4c DC |
2224 | private function print_pretty_view() { |
2225 | $version = wiki_get_current_version($this->page->id); | |
2226 | ||
2227 | $content = wiki_parse_content($version->contentformat, $version->content, array('printable' => true, 'swid' => $this->subwiki->id, 'pageid' => $this->page->id, 'pretty_print' => true)); | |
2228 | ||
831ca534 BK |
2229 | $html = $content['parsed_text']; |
2230 | $id = $this->subwiki->wikiid; | |
2231 | if ($cm = get_coursemodule_from_instance("wiki", $id)) { | |
2232 | $context = context_module::instance($cm->id); | |
2233 | $html = file_rewrite_pluginfile_urls($html, 'pluginfile.php', $context->id, 'mod_wiki', 'attachments', $this->subwiki->id); | |
2234 | } | |
00710f4c | 2235 | echo '<div id="wiki_printable_content">'; |
831ca534 | 2236 | echo format_text($html, FORMAT_HTML); |
00710f4c DC |
2237 | echo '</div>'; |
2238 | } | |
2239 | } | |
2240 | ||
2241 | class page_wiki_handlecomments extends page_wiki { | |
2242 | private $action; | |
2243 | private $content; | |
2244 | private $commentid; | |
2245 | private $format; | |
2246 | ||
2247 | function print_header() { | |
2248 | $this->set_url(); | |
2249 | } | |
2250 | ||
2251 | public function print_content() { | |
d6887efc | 2252 | global $CFG, $PAGE, $USER; |
00710f4c | 2253 | |
cfffb69c | 2254 | if ($this->action == 'add') { |
cfdac90f | 2255 | if (has_capability('mod/wiki:editcomment', $this->modcontext)) { |
9bf1b716 JP |
2256 | $this->add_comment($this->content, $this->commentid); |
2257 | } | |
2258 | } else if ($this->action == 'edit') { | |
2259 | $comment = wiki_get_comment($this->commentid); | |
cfdac90f | 2260 | $edit = has_capability('mod/wiki:editcomment', $this->modcontext); |
d6887efc | 2261 | $owner = ($comment->userid == $USER->id); |
cfffb69c | 2262 | if ($owner && $edit) { |
9bf1b716 JP |
2263 | $this->add_comment($this->content, $this->commentid); |
2264 | } | |
00710f4c | 2265 | } else if ($this->action == 'delete') { |
9bf1b716 | 2266 | $comment = wiki_get_comment($this->commentid); |
cfdac90f | 2267 | $manage = has_capability('mod/wiki:managecomment', $this->modcontext); |
d6887efc | 2268 | $owner = ($comment->userid == $USER->id); |
cfffb69c | 2269 | if ($owner || $manage) { |
9bf1b716 | 2270 | $this->delete_comment($this->commentid); |
d6887efc | 2271 | redirect($CFG->wwwroot . '/mod/wiki/comments.php?pageid=' . $this->page->id, get_string('deletecomment', 'wiki'), 2); |
9bf1b716 | 2272 | } |
00710f4c DC |
2273 | } |
2274 | ||
2275 | } | |
2276 | ||
2277 | public function set_url() { | |
2278 | global $PAGE, $CFG; | |
2279 | $PAGE->set_url($CFG->wwwroot . '/mod/wiki/comments.php', array('pageid' => $this->page->id)); | |
2280 | } | |
2281 | ||
2282 | public function set_action($action, $commentid, $content) { | |
2283 | $this->action = $action; | |
2284 | $this->commentid = $commentid; | |
2285 | $this->content = $content; | |
2286 | ||
2287 | $version = wiki_get_current_version($this->page->id); | |
2288 | $format = $version->contentformat; | |
2289 | ||
2290 | $this->format = $format; | |
2291 | } | |
2292 | ||
2293 | private function add_comment($content, $idcomment) { | |
2294 | global $CFG, $PAGE; | |
2295 | require_once($CFG->dirroot . "/mod/wiki/locallib.php"); | |
2296 | ||
2297 | $pageid = $this->page->id; | |
00710f4c | 2298 | |
cfdac90f | 2299 | wiki_add_comment($this->modcontext, $pageid, $content, $this->format); |
00710f4c DC |
2300 | |
2301 | if (!$idcomment) { | |
2302 | redirect($CFG->wwwroot . '/mod/wiki/comments.php?pageid=' . $pageid, get_string('createcomment', 'wiki'), 2); | |
2303 | } else { | |
2304 | $this->delete_comment($idcomment); | |
d6887efc | 2305 | redirect($CFG->wwwroot . '/mod/wiki/comments.php?pageid=' . $pageid, get_string('editingcomment', 'wiki'), 2); |
00710f4c DC |
2306 | } |
2307 | } | |
2308 | ||
2309 | private function delete_comment($commentid) { | |
2310 | global $CFG, $PAGE; | |
2311 | ||
00710f4c DC |
2312 | $pageid = $this->page->id; |
2313 | ||
cfdac90f | 2314 | wiki_delete_comment($commentid, $this->modcontext, $pageid); |
00710f4c DC |
2315 | } |
2316 | ||
2317 | } | |
2318 | ||
2319 | class page_wiki_lock extends page_wiki_edit { | |
2320 | ||
2321 | public function print_header() { | |
2322 | $this->set_url(); | |
2323 | } | |
2324 | ||
2325 | protected function set_url() { | |
2326 | global $PAGE, $CFG; | |
2327 | ||
2328 | $params = array('pageid' => $this->page->id); | |
2329 | ||
2330 | if ($this->section) { | |
2331 | $params['section'] = $this->section; | |
2332 | } | |
2333 | ||
2334 | $PAGE->set_url($CFG->wwwroot . '/mod/wiki/lock.php', $params); | |
2335 | } | |
2336 | ||
2337 | protected function set_session_url() { | |
2338 | } | |
2339 | ||
2340 | public function print_content() { | |
2341 | global $USER, $PAGE; | |
2342 | ||
cfdac90f | 2343 | require_capability('mod/wiki:editpage', $this->modcontext, NULL, true, 'noeditpermission', 'wiki'); |
00710f4c DC |
2344 | |
2345 | wiki_set_lock($this->page->id, $USER->id, $this->section); | |
2346 | } | |
2347 | ||
2348 | public function print_footer() { | |
2349 | } | |
2350 | } | |
2351 | ||
2352 | class page_wiki_overridelocks extends page_wiki_edit { | |
2353 | function print_header() { | |
2354 | $this->set_url(); | |
2355 | } | |
2356 | ||
2357 | function print_content() { | |
2358 | global $CFG, $PAGE; | |
2359 | ||
cfdac90f | 2360 | require_capability('mod/wiki:overridelock', $this->modcontext, NULL, true, 'nooverridelockpermission', 'wiki'); |
00710f4c DC |
2361 | |
2362 | wiki_delete_locks($this->page->id, null, $this->section, true, true); | |
2363 | ||
2364 | $args = "pageid=" . $this->page->id; | |
2365 | ||
2366 | if (!empty($this->section)) { | |
1323bf55 | 2367 | $args .= "§ion=" . urlencode($this->section); |
00710f4c DC |
2368 | } |
2369 | ||
2370 | redirect($CFG->wwwroot . '/mod/wiki/edit.php?' . $args, get_string('overridinglocks', 'wiki'), 2); | |
2371 | } | |
2372 | ||
2373 | function set_url() { | |
2374 | global $PAGE, $CFG; | |
2375 | ||
2376 | $params = array('pageid' => $this->page->id); | |
2377 | ||
2378 | if (!empty($this->section)) { | |
2379 | $params['section'] = $this->section; | |
2380 | } | |
2381 | ||
2382 | $PAGE->set_url($CFG->wwwroot . '/mod/wiki/overridelocks.php', $params); | |
2383 | } | |
2384 | ||
2385 | protected function set_session_url() { | |
2386 | } | |
2387 | ||
2388 | private function print_overridelocks() { | |
2389 | global $CFG; | |
2390 | ||
2391 | wiki_delete_locks($this->page->id, null, $this->section, true, true); | |
2392 | ||
2393 | $args = "pageid=" . $this->page->id; | |
2394 | ||
2395 | if (!empty($this->section)) { | |
1323bf55 | 2396 | $args .= "§ion=" . urlencode($this->section); |
00710f4c DC |
2397 | } |
2398 | ||
2399 | redirect($CFG->wwwroot . '/mod/wiki/edit.php?' . $args, get_string('overridinglocks', 'wiki'), 2); | |
2400 | } | |
2401 | ||
2402 | } | |
ac0a82cf RT |
2403 | |
2404 | /** | |
2405 | * This class will let user to delete wiki pages and page versions | |
2406 | * | |
2407 | */ | |
2408 | class page_wiki_admin extends page_wiki { | |
2409 | ||
2410 | public $view, $action; | |
2411 | public $listorphan = false; | |
2412 | ||
2413 | /** | |
2414 | * Constructor | |
2415 | * | |
2416 | * @global object $PAGE | |
2417 | * @param mixed $wiki instance of wiki | |
2418 | * @param mixed $subwiki instance of subwiki | |
2419 | * @param stdClass $cm course module | |
2420 | */ | |
2421 | function __construct($wiki, $subwiki, $cm) { | |
2422 | global $PAGE; | |
2423 | parent::__construct($wiki, $subwiki, $cm); | |
2424 | $PAGE->requires->js_init_call('M.mod_wiki.deleteversion', null, true); | |
2425 | } | |
2426 | ||
2427 | /** | |
2428 | * Prints header for wiki page | |
2429 | */ | |
2430 | function print_header() { | |
2431 | parent::print_header(); | |
2432 | $this->print_pagetitle(); | |
2433 | } | |
2434 | ||
2435 | /** | |
2436 | * This function will display administration view to users with managewiki capability | |
2437 | */ | |
2438 | function print_content() { | |
2439 | //make sure anyone trying to access this page has managewiki capabilities | |
2440 | require_capability('mod/wiki:managewiki', $this->modcontext, NULL, true, 'noviewpagepermission', 'wiki'); | |
2441 | ||
2442 | //update wiki cache if timedout | |
2443 | $page = $this->page; | |
2444 | if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) { | |
2445 | $fresh = wiki_refresh_cachedcontent($page); | |
2446 | $page = $fresh['page']; | |
2447 | } | |
2448 | ||
2449 | //dispaly admin menu | |
2450 | echo $this->wikioutput->menu_admin($this->page->id, $this->view); | |
2451 | ||
2452 | //Display appropriate admin view | |
2453 | switch ($this->view) { | |
2454 | case 1: //delete page view | |
2455 | $this->print_delete_content($this->listorphan); | |
2456 | break; | |
2457 | case 2: //delete version view | |
2458 | $this->print_delete_version(); | |
2459 | break; | |
2460 | default: //default is delete view | |
2461 | $this->print_delete_content($this->listorphan); | |
2462 | break; | |
2463 | } | |
2464 | } | |
2465 | ||
2466 | /** | |
2467 | * Sets admin view option | |
2468 | * | |
2469 | * @param int $view page view id | |
2470 | * @param bool $listorphan is only valid for view 1. | |
2471 | */ | |
2472 | public function set_view($view, $listorphan = true) { | |
2473 | $this->view = $view; | |
2474 | $this->listorphan = $listorphan; | |
2475 | } | |
2476 | ||
2477 | /** | |
2478 | * Sets page url | |
2479 | * | |
2480 | * @global object $PAGE | |
2481 | * @global object $CFG | |
2482 | */ | |
2483 | function set_url() { | |
2484 | global $PAGE, $CFG; | |
2485 | $PAGE->set_url($CFG->wwwroot . '/mod/wiki/admin.php', array('pageid' => $this->page->id)); | |
2486 | } | |
2487 | ||
2488 | /** | |
2489 | * sets navigation bar for the page | |
2490 | * | |
2491 | * @global object $PAGE | |
2492 | */ | |
2493 | protected function create_navbar() { | |
2494 | global $PAGE; | |
2495 | ||
2496 | parent::create_navbar(); | |
2497 | $PAGE->navbar->add(get_string('admin', 'wiki')); | |
2498 | } | |
2499 | ||
2500 | /** | |
2501 | * Show wiki page delete options | |
2502 | * | |
2503 | * @param bool $showorphan | |
2504 | */ | |
2505 | protected function print_delete_content($showorphan = true) { | |
2506 | $contents = array(); | |
2507 | $table = new html_table(); | |
9ff5e869 | 2508 | $table->head = array('', get_string('pagename','wiki')); |
ac0a82cf RT |
2509 | $table->attributes['class'] = 'generaltable mdl-align'; |
2510 | $swid = $this->subwiki->id; | |
2511 | if ($showorphan) { | |
2512 | if ($orphanedpages = wiki_get_orphaned_pages($swid)) { | |
2513 | $this->add_page_delete_options($orphanedpages, $swid, $table); | |
2514 | } else { | |
2515 | $table->data[] = array('', get_string('noorphanedpages', 'wiki')); | |
2516 | } | |
2517 | } else { | |
2518 | if ($pages = wiki_get_page_list($swid)) { | |
2519 | $this->add_page_delete_options($pages, $swid, $table); | |
2520 | } else { | |
2521 | $table->data[] = array('', get_string('nopages', 'wiki')); | |
2522 | } | |
2523 | } | |
2524 | ||
2525 | ///Print the form | |
2526 | echo html_writer::start_tag('form', array( | |
2527 | 'action' => new moodle_url('/mod/wiki/admin.php'), | |
2528 | 'method' => 'post')); | |
2529 | echo html_writer::tag('div', html_writer::empty_tag('input', array( | |
2530 | 'type' => 'hidden', | |
2531 | 'name' => 'pageid', | |
2532 | 'value' => $this->page->id))); | |
2533 | ||
2534 | echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'option', 'value' => $this->view)); | |
2535 | echo html_writer::table($table); | |
2536 | echo html_writer::start_tag('div', array('class' => 'mdl-align')); | |
2537 | if (!$showorphan) { | |
2538 | echo html_writer::empty_tag('input', array( | |
2539 | 'type' => 'submit', | |
2540 | 'class' => 'wiki_form-button', | |
2541 | 'value' => get_string('listorphan', 'wiki'), | |
2542 | 'sesskey' => sesskey())); | |
2543 | } else { | |
2544 | echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'listall', 'value'=>'1')); | |
2545 | echo html_writer::empty_tag('input', array( | |
2546 | 'type' => 'submit', | |
2547 | 'class' => 'wiki_form-button', | |
2548 | 'value' => get_string('listall', 'wiki'), | |
2549 | 'sesskey' => sesskey())); | |
2550 | } | |
2551 | echo html_writer::end_tag('div'); | |
2552 | echo html_writer::end_tag('form'); | |
2553 | } | |
2554 | ||
2555 | /** | |
2556 | * helper function for print_delete_content. This will add data to the table. | |
2557 | * | |
2558 | * @global object $OUTPUT | |
2559 | * @param array $pages objects of wiki pages in subwiki | |
2560 | * @param int $swid id of subwiki | |
2561 | * @param object $table reference to the table in which data needs to be added | |
2562 | */ | |
2563 | protected function add_page_delete_options($pages, $swid, &$table) { | |
2564 | global $OUTPUT; | |
2565 | foreach ($pages as $page) { | |
2566 | $link = wiki_parser_link($page->title, array('swid' => $swid)); | |
2567 | $class = ($link['new']) ? 'class="wiki_newentry"' : ''; | |
2568 | $pagelink = '<a href="' . $link['url'] . '"' . $class . '>' . format_string($link['content']) . '</a>'; | |
2569 | $urledit = new moodle_url('/mod/wiki/edit.php', array('pageid' => $page->id, 'sesskey' => sesskey())); | |
2570 | $urldelete = new moodle_url('/mod/wiki/admin.php', array( | |
2571 | 'pageid' => $this->page->id, | |
2572 | 'delete' => $page->id, | |
2573 | 'option' => $this->view, | |
2574 | 'listall' => !$this->listorphan?'1': '', | |
2575 | 'sesskey' => sesskey())); | |
2576 | ||
2577 | $editlinks = $OUTPUT->action_icon($urledit, new pix_icon('t/edit', get_string('edit'))); | |
2578 | $editlinks .= $OUTPUT->action_icon($urldelete, new pix_icon('t/delete', get_string('delete'))); | |
2579 | $table->data[] = array($editlinks, $pagelink); | |
2580 | } | |
2581 | } | |
2582 | ||
2583 | /** | |
2584 | * Prints lists of versions which can be deleted | |
2585 | * | |
52cbd9cb SH |
2586 | * @global core_renderer $OUTPUT |
2587 | * @global moodle_page $PAGE | |
ac0a82cf RT |
2588 | */ |
2589 | private function print_delete_version() { | |
537c237b | 2590 | global $OUTPUT, $PAGE; |
ac0a82cf RT |
2591 | $pageid = $this->page->id; |
2592 | ||
2593 | // versioncount is the latest version | |
2594 | $versioncount = wiki_count_wiki_page_versions($pageid) - 1; | |
2595 | $versions = wiki_get_wiki_page_versions($pageid, 0, $versioncount); | |
2596 | ||
2597 | // We don't want version 0 to be displayed | |
2598 | // version 0 is blank page | |
2599 | if (end($versions)->version == 0) { | |
2600 | array_pop($versions); | |
2601 | } | |
2602 | ||
2603 | $contents = array(); | |
2604 | $version0page = wiki_get_wiki_page_version($this->page->id, 0); | |
2605 | $creator = wiki_get_user_info($version0page->userid); | |
2606 | $a = new stdClass(); | |
2607 | $a->date = userdate($this->page->timecreated, get_string('strftimedaydatetime', 'langconfig')); | |
140af2a0 | 2608 | $a->username = fullname($creator); |
876c0ac3 | 2609 | echo $OUTPUT->heading(get_string('createddate', 'wiki', $a), 4); |
ac0a82cf RT |
2610 | if ($versioncount > 0) { |
2611 | /// If there is only one version, we don't need radios nor forms | |
2612 | if (count($versions) == 1) { | |
2613 | $row = array_shift($versions); | |
2614 | $username = wiki_get_user_info($row->userid); | |
2615 | $picture = $OUTPUT->user_picture($username); | |
2616 | $date = userdate($row->timecreated, get_string('strftimedate', 'langconfig')); | |
2617 | $time = userdate($row->timecreated, get_string('strftimetime', 'langconfig')); | |
2618 | $versionid = wiki_get_version($row->id); | |
2619 | $versionlink = new moodle_url('/mod/wiki/viewversion.php', array('pageid' => $pageid, 'versionid' => $versionid->id)); | |
4a28ff88 | 2620 | $userlink = new moodle_url('/user/view.php', array('id' => $username->id, 'course' => $this->cm->course)); |
ac0a82cf RT |
2621 | $picturelink = $picture . html_writer::link($userlink->out(false), fullname($username)); |
2622 | $historydate = $OUTPUT->container($date, 'wiki_histdate'); | |
2623 | $contents[] = array('', html_writer::link($versionlink->out(false), $row->version), $picturelink, $time, $historydate); | |
2624 | ||
2625 | //Show current version | |
2626 | $table = new html_table(); | |
2627 | $table->head = array('', get_string('version'), get_string('user'), get_string('modified'), ''); | |
2628 | $table->data = $contents; | |
2629 | $table->attributes['class'] = 'mdl-align'; | |
2630 | ||
2631 | echo html_writer::table($table); | |
2632 | } else { | |
2633 | $lastdate = ''; | |
2634 | $rowclass = array(); | |
2635 | ||
2636 | foreach ($versions as $version) { | |
2637 | $user = wiki_get_user_info($version->userid); | |
2638 | $picture = $OUTPUT->user_picture($user, array('popup' => true)); | |
2639 | $date = userdate($version->timecreated, get_string('strftimedate')); | |
2640 | if ($date == $lastdate) { | |
2641 | $date = ''; | |
2642 | $rowclass[] = ''; | |
2643 | } else { | |
2644 | $lastdate = $date; | |
2645 | $rowclass[] = 'wiki_histnewdate'; | |
2646 | } | |
2647 | ||
2648 | $time = userdate($version->timecreated, get_string('strftimetime', 'langconfig')); | |
2649 | $versionid = wiki_get_version($version->id); | |
2650 | if ($versionid) { | |
2651 | $url = new moodle_url('/mod/wiki/viewversion.php', array('pageid' => $pageid, 'versionid' => $versionid->id)); | |
2652 | $viewlink = html_writer::link($url->out(false), $version->version); | |
2653 | } else { | |
2654 | $viewlink = $version->version; | |
2655 | } | |
2656 | ||
4a28ff88 | 2657 | $userlink = new moodle_url('/user/view.php', array('id' => $version->userid, 'course' => $this->cm->course)); |
ac0a82cf RT |
2658 | $picturelink = $picture . html_writer::link($userlink->out(false), fullname($user)); |
2659 | $historydate = $OUTPUT->container($date, 'wiki_histdate'); | |
2660 | $radiofromelement = $this->choose_from_radio(array($version->version => null), 'fromversion', 'M.mod_wiki.deleteversion()', $versioncount, true); | |
2661 | $radiotoelement = $this->choose_from_radio(array($version->version => null), 'toversion', 'M.mod_wiki.deleteversion()', $versioncount, true); | |
2662 | $contents[] = array( $radiofromelement . $radiotoelement, $viewlink, $picturelink, $time, $historydate); | |
2663 | } | |
2664 | ||
2665 | $table = new html_table(); | |
2666 | $table->head = array(get_string('deleteversions', 'wiki'), get_string('version'), get_string('user'), get_string('modified'), ''); | |
2667 | $table->data = $contents; | |
2668 | $table->attributes['class'] = 'generaltable mdl-align'; | |
2669 | $table->rowclasses = $rowclass; | |
2670 | ||
2671 | ///Print the form | |
2672 | echo html_writer::start_tag('form', array('action'=>new moodle_url('/mod/wiki/admin.php'), 'method' => 'post')); | |
2673 | echo html_writer::tag('div', html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'pageid', 'value' => $pageid))); | |
2674 | echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'option', 'value' => $this->view)); | |
2675 | echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())); | |
2676 | echo html_writer::table($table); | |
2677 | echo html_writer::start_tag('div', array('class' => 'mdl-align')); | |
2678 | echo html_writer::empty_tag('input', array('type' => 'submit', 'class' => 'wiki_form-button', 'value' => get_string('deleteversions', 'wiki'))); | |
2679 | echo html_writer::end_tag('div'); | |
2680 | echo html_writer::end_tag('form'); | |
2681 | } | |
2682 | } else { | |
2683 | print_string('nohistory', 'wiki'); | |
2684 | } | |
2685 | } | |
2686 | ||
2687 | /** | |
2688 | * Given an array of values, creates a group of radio buttons to be part of a form | |
2689 | * helper function for print_delete_version | |
2690 | * | |
2691 | * @param array $options An array of value-label pairs for the radio group (values as keys). | |
2692 | * @param string $name Name of the radiogroup (unique in the form). | |
2693 | * @param string $onclick Function to be executed when the radios are clicked. | |
2694 | * @param string $checked The value that is already checked. | |
2695 | * @param bool $return If true, return the HTML as a string, otherwise print it. | |
2696 | * | |
2697 | * @return mixed If $return is false, returns nothing, otherwise returns a string of HTML. | |
2698 | */ | |
2699 | private function choose_from_radio($options, $name, $onclick = '', $checked = '', $return = false) { | |
2700 | ||
2701 | static $idcounter = 0; | |
2702 | ||
2703 | if (!$name) { | |
2704 | $name = 'unnamed'; | |
2705 | } | |
2706 | ||
2707 | $output = '<span class="radiogroup ' . $name . "\">\n"; | |
2708 | ||
2709 | if (!empty($options)) { | |
2710 | $currentradio = 0; | |
2711 | foreach ($options as $value => $label) { | |
2712 | $htmlid = 'auto-rb' . sprintf('%04d', ++$idcounter); | |
2713 | $output .= ' <span class="radioelement ' . $name . ' rb' . $currentradio . "\">"; | |
2714 | $output .= '<input name="' . $name . '" id="' . $htmlid . '" type="radio" value="' . $value . '"'; | |
2715 | if ($value == $checked) { | |
2716 | $output .= ' checked="checked"'; | |
2717 | } | |
2718 | if ($onclick) { | |
2719 | $output .= ' onclick="' . $onclick . '"'; | |
2720 | } | |
2721 | if ($label === '') { | |
2722 | $output .= ' /> <label for="' . $htmlid . '">' . $value . '</label></span>' . "\n"; | |
2723 | } else { | |
2724 | $output .= ' /> <label for="' . $htmlid . '">' . $label . '</label></span>' . "\n"; | |
2725 | } | |
2726 | $currentradio = ($currentradio + 1) % 2; | |
2727 | } | |
2728 | } | |
2729 | ||
2730 | $output .= '</span>' . "\n"; | |
2731 | ||
2732 | if ($return) { | |
2733 | return $output; | |
2734 | } else { | |
2735 | echo $output; | |
2736 | } | |
2737 | } | |
2738 | } |