Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

2275 lines (1834 sloc) 76.732 kb
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains several classes uses to render the diferent pages
* of the wiki module
*
* @package mod-wiki-2.0
* @copyrigth 2009 Marc Alier, Jordi Piguillem marc.alier@upc.edu
* @copyrigth 2009 Universitat Politecnica de Catalunya http://www.upc.edu
*
* @author Jordi Piguillem
* @author Marc Alier
* @author David Jimenez
* @author Josep Arus
* @author Daniel Serrano
* @author Kenneth Riba
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once($CFG->dirroot . '/mod/wiki/edit_form.php');
require_once($CFG->dirroot . '/tag/lib.php');
/**
* Class page_wiki contains the common code between all pages
*
* @package mod-wiki
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class page_wiki {
/**
* @var object Current subwiki
*/
protected $subwiki;
/**
* @var int Current page
*/
protected $page;
/**
* @var string Current page title
*/
protected $title;
/**
* @var int Current group ID
*/
protected $gid;
/**
* @var int Current user ID
*/
protected $uid;
/**
* @var array The tabs set used in wiki module
*/
protected $tabs = array('view', 'edit', 'comments', 'history', 'map');
/**
* @var array tabs options
*/
protected $tabs_options = array();
/**
* @var object wiki renderer
*/
protected $wikioutput;
/**
* page_wiki constructor
*
* @param $wiki. Current wiki
* @param $subwiki. Current subwiki.
* @param $cm. Current course_module.
*/
function __construct($wiki, $subwiki, $cm) {
global $PAGE, $CFG;
$this->subwiki = $subwiki;
// initialise wiki renderer
$this->wikioutput = $PAGE->get_renderer('mod_wiki');
$PAGE->set_cacheable(true);
$PAGE->set_cm($cm);
$PAGE->set_activity_record($wiki);
// the search box
$PAGE->set_button(wiki_search_form($cm));
}
/**
* This method prints the top of the page.
*/
function print_header() {
global $OUTPUT, $PAGE, $CFG, $USER, $SESSION;
$PAGE->set_heading($PAGE->course->fullname);
$this->set_url();
if (isset($SESSION->wikipreviousurl) && is_array($SESSION->wikipreviousurl)) {
$this->process_session_url();
}
$this->set_session_url();
$this->create_navbar();
$this->setup_tabs();
echo $OUTPUT->header();
echo $this->wikioutput->wiki_info();
// tabs are associated with pageid, so if page is empty, tabs should be disabled
if (!empty($this->page) && !empty($this->tabs)) {
echo $this->wikioutput->tabs($this->page, $this->tabs, $this->tabs_options);
}
}
/**
* Protected method to print current page title.
*/
protected function print_pagetitle() {
global $OUTPUT;
$html = '';
$html .= $OUTPUT->container_start();
$html .= $OUTPUT->heading($this->title, 2, 'wiki_headingtitle');
$html .= $OUTPUT->container_end();
echo $html;
}
/**
* Setup page tabs, if options is empty, will set up active tab automatically
* @param array $options, tabs options
*/
protected function setup_tabs($options = array()) {
if (empty($options)) {
$this->tabs_options = array('activetab' => substr(get_class($this), 10));
} else {
$this->tabs_options = $options;
}
}
/**
* This method must be overwritten to print the page content.
*/
function print_content() {
throw new coding_exception('Page wiki class does not implement method print_content()');
}
/**
* Method to set the current page
*
* @param object $page Current page
*/
function set_page($page) {
global $PAGE;
$this->page = $page;
$this->title = $page->title;
$PAGE->set_title($this->title);
}
/**
* Method to set the current page title.
* This method must be called when the current page is not created yet.
* @param string $title Current page title.
*/
function set_title($title) {
global $PAGE;
$this->page = null;
$this->title = $title;
$PAGE->set_title($this->title);
}
/**
* Method to set current group id
* @param int $gid Current group id
*/
function set_gid($gid) {
$this->gid = $gid;
}
/**
* Method to set current user id
* @param int $uid Current user id
*/
function set_uid($uid) {
$this->uid = $uid;
}
/**
* Method to set the URL of the page.
* This method must be overwritten by every type of page.
*/
protected function set_url() {
throw new coding_exception('Page wiki class does not implement method set_url()');
}
/**
* Protected method to create the common items of the navbar in every page type.
*/
protected function create_navbar() {
global $PAGE, $CFG;
$PAGE->navbar->add($this->title, $CFG->wwwroot . '/mod/wiki/view.php?pageid=' . $this->page->id);
}
/**
* This method print the footer of the page.
*/
function print_footer() {
global $OUTPUT;
echo $OUTPUT->footer();
}
protected function process_session_url() {
global $USER, $SESSION;
//delete locks if edit
$url = $SESSION->wikipreviousurl;
switch ($url['page']) {
case 'edit':
wiki_delete_locks($url['params']['pageid'], $USER->id, $url['params']['section'], false);
break;
}
}
protected function set_session_url() {
global $SESSION;
unset($SESSION->wikipreviousurl);
}
}
/**
* View a wiki page
*
* @package mod-wiki
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class page_wiki_view extends page_wiki {
/**
* @var int the coursemodule id
*/
private $coursemodule;
function print_header() {
global $PAGE;
parent::print_header();
$this->wikioutput->wiki_print_subwiki_selector($PAGE->activityrecord, $this->subwiki, $this->page);
if (!empty($this->page)) {
echo $this->wikioutput->prettyview_link($this->page);
}
//echo $this->wikioutput->page_index();
$this->print_pagetitle();
}
function print_content() {
global $PAGE, $CFG;
$context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
if (wiki_user_can_view($this->subwiki)) {
if (!empty($this->page)) {
wiki_print_page_content($this->page, $context, $this->subwiki->id);
$wiki = $PAGE->activityrecord;
} else {
print_string('nocontent', 'wiki');
// TODO: fix this part
$swid = 0;
if (!empty($this->subwiki)) {
$swid = $this->subwiki->id;
}
}
} else {
// @TODO: Tranlate it
echo "You can not view this page";
}
}
function set_url() {
global $PAGE, $CFG;
$params = array();
if (isset($this->coursemodule)) {
$params['id'] = $this->coursemodule;
} else if (!empty($this->page) and $this->page != null) {
$params['pageid'] = $this->page->id;
} else if (!empty($this->gid)) {
$params['wid'] = $PAGE->cm->instance;
$params['group'] = $this->gid;
} else if (!empty($this->title)) {
$params['swid'] = $this->subwiki->id;
$params['title'] = $this->title;
} else {
print_error(get_string('invalidparameters', 'wiki'));
}
$PAGE->set_url($CFG->wwwroot . '/mod/wiki/view.php', $params);
}
function set_coursemodule($id) {
$this->coursemodule = $id;
}
protected function create_navbar() {
global $PAGE, $CFG;
$PAGE->navbar->add($this->title);
$PAGE->navbar->add(get_string('view', 'wiki'));
}
}
/**
* Wiki page editing page
*
* @package mod-wiki
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class page_wiki_edit extends page_wiki {
public static $attachmentoptions;
protected $sectioncontent;
/** @var string the section name needed to be edited */
protected $section;
protected $overridelock = false;
protected $versionnumber = -1;
protected $upload = false;
protected $attachments = 0;
protected $deleteuploads = array();
protected $format;
function __construct($wiki, $subwiki, $cm) {
global $CFG, $PAGE;
parent::__construct($wiki, $subwiki, $cm);
self::$attachmentoptions = array(
'subdirs' => false,
'maxfiles' => -1,
'maxbytes' => $CFG->maxbytes,
'accepted_types'=>'*'
);
$PAGE->requires->js_init_call('M.mod_wiki.renew_lock', null, true);
$PAGE->requires->yui2_lib('connection');
}
protected function print_pagetitle() {
global $OUTPUT;
$title = $this->title;
if (isset($this->section)) {
$title .= ' : ' . $this->section;
}
echo $OUTPUT->container_start('wiki_clear');
echo $OUTPUT->heading($title, 2, 'wiki_headingtitle');
echo $OUTPUT->container_end();
}
function print_header() {
global $OUTPUT, $PAGE;
$PAGE->requires->data_for_js('wiki', array('renew_lock_timeout' => LOCK_TIMEOUT - 5, 'pageid' => $this->page->id, 'section' => $this->section));
parent::print_header();
$this->print_pagetitle();
print '<noscript>' . $OUTPUT->box(get_string('javascriptdisabledlocks', 'wiki'), 'errorbox') . '</noscript>';
}
function print_content() {
global $PAGE;
$context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
if (wiki_user_can_edit($this->subwiki)) {
$this->print_edit();
} else {
// @TODO: Translate it
echo "You can not edit this page";
}
}
protected function set_url() {
global $PAGE, $CFG;
$params = array('pageid' => $this->page->id);
if (isset($this->section)) {
$params['section'] = $this->section;
}
$PAGE->set_url($CFG->wwwroot . '/mod/wiki/edit.php', $params);
}
protected function set_session_url() {
global $SESSION;
$SESSION->wikipreviousurl = array('page' => 'edit', 'params' => array('pageid' => $this->page->id, 'section' => $this->section));
}
protected function process_session_url() {
}
function set_section($sectioncontent, $section) {
$this->sectioncontent = $sectioncontent;
$this->section = $section;
}
public function set_versionnumber($versionnumber) {
$this->versionnumber = $versionnumber;
}
public function set_overridelock($override) {
$this->overridelock = $override;
}
function set_format($format) {
$this->format = $format;
}
public function set_upload($upload) {
$this->upload = $upload;
}
public function set_attachments($attachments) {
$this->attachments = $attachments;
}
public function set_deleteuploads($deleteuploads) {
$this->deleteuploads = $deleteuploads;
}
protected function create_navbar() {
global $PAGE, $CFG;
parent::create_navbar();
$PAGE->navbar->add(get_string('edit', 'wiki'));
}
protected function check_locks() {
global $OUTPUT, $USER, $CFG;
if (!wiki_set_lock($this->page->id, $USER->id, $this->section, true)) {
print $OUTPUT->box(get_string('pageislocked', 'wiki'), 'generalbox boxwidthnormal boxaligncenter');
if ($this->overridelock) {
$params = 'pageid=' . $this->page->id;
if ($this->section) {
$params .= '&section=' . $this->section;
}
$form = '<form method="post" action="' . $CFG->wwwroot . '/mod/wiki/overridelocks.php?' . $params . '">';
$form .= '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
$form .= '<input type="submit" value="' . get_string('overridelocks', 'wiki') . '" />';
$form .= '</form>';
print $OUTPUT->box($form, 'generalbox boxwidthnormal boxaligncenter');
}
return false;
}
return true;
}
protected function print_edit($content = null) {
global $CFG, $OUTPUT, $USER, $PAGE;
if (!$this->check_locks()) {
return;
}
//delete old locks (> 1 hour)
wiki_delete_old_locks();
$version = wiki_get_current_version($this->page->id);
$format = $version->contentformat;
if ($content == null) {
if (empty($this->section)) {
$content = $version->content;
} else {
$content = $this->sectioncontent;
}
}
$versionnumber = $version->version;
if ($this->versionnumber >= 0) {
if ($version->version != $this->versionnumber) {
print $OUTPUT->box(get_string('wrongversionlock', 'wiki'), 'errorbox');
$versionnumber = $this->versionnumber;
}
}
$cm = $PAGE->cm;
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$url = $CFG->wwwroot . '/mod/wiki/edit.php?pageid=' . $this->page->id;
if (!empty($this->section)) {
$url .= "&section=" . $this->section;
}
$params = array('attachmentoptions' => page_wiki_edit::$attachmentoptions, 'format' => $version->contentformat, 'version' => $versionnumber);
$data = new StdClass();
$data->newcontent = $content;
$data->version = $versionnumber;
$data->format = $format;
switch ($format) {
case 'html':
$data->newcontentformat = FORMAT_HTML;
$data = file_prepare_standard_editor($data, 'newcontent', page_wiki_edit::$attachmentoptions, $context, 'wiki_attachments', $this->subwiki->id);
break;
default:
//$draftitemid = file_get_submitted_draft_itemid('attachments');
//file_prepare_draft_area($draftitemid, $context->id, 'wiki_attachments', $this->subwiki->id);
//$data->attachments = $draftitemid;
}
if ($version->contentformat != 'html') {
$params['contextid'] = $context->id;
$params['filearea'] = 'wiki_attachments';
$params['fileitemid'] = $this->subwiki->id;
}
$form = new mod_wiki_edit_form($url, $params);
if ($formdata = $form->get_data()) {
if ($format != 'html') {
$errors = $this->process_uploads($context);
if (!empty($errors)) {
$contenterror = "";
foreach ($errors as $e) {
$contenterror .= "<p>" . get_string('filenotuploadederror', 'wiki', $e->get_filename()) . "</p>";
}
print $OUTPUT->box($contenterror, 'errorbox');
}
}
if (!empty($CFG->usetags)) {
$data->tags = $formdata->tags;
}
} else {
if (!empty($CFG->usetags)) {
$data->tags = tag_get_tags_array('wiki', $this->page->id);
}
}
$form->set_data($data);
$form->display();
}
protected function process_uploads($context) {
global $PAGE, $OUTPUT;
if ($this->upload) {
file_save_draft_area_files($this->attachments, $context->id, 'wiki_attachments', $this->subwiki->id);
return null;
//return wiki_process_attachments($this->attachments, $this->deleteuploads, $context->id, 'wiki_attachments', $this->subwiki->id);
}
}
}
/**
* Class that models the behavior of wiki's view comments page
*
* @package mod-wiki
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class page_wiki_comments extends page_wiki {
function print_header() {
parent::print_header();
$this->print_pagetitle();
}
function print_content() {
global $CFG, $OUTPUT, $USER, $PAGE, $COURSE;
require_once($CFG->dirroot . '/mod/wiki/locallib.php');
$page = $this->page;
$subwiki = $this->subwiki;
$wiki = $PAGE->activityrecord;
$cm = $PAGE->cm;
$course = $COURSE;
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/wiki:viewcomment', $context, NULL, true, 'noviewcommentpermission', 'wiki');
$comments = wiki_get_comments($context, $page->id);
if (has_capability('mod/wiki:editcomment', $context)) {
echo '<div class="midpad"><a href="' . $CFG->wwwroot . '/mod/wiki/editcomments.php?action=add&amp;pageid=' . $page->id . '">' . get_string('addcomment', 'wiki') . '</a></div>';
}
$options = array('swid' => $this->page->subwikiid, 'pageid' => $page->id);
$version = wiki_get_current_version($this->page->id);
$format = $version->contentformat;
if (empty($comments)) {
echo $OUTPUT->heading(get_string('nocomments', 'wiki'));
}
foreach ($comments as $num) {
$user = wiki_get_user_info($num->userid);
$fullname = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
$by = new stdclass();
$by->name = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $user->id . '&amp;course=' . $course->id . '">' . $fullname . '</a>';
$by->date = userdate($num->timecreated);
$t = new html_table();
$cell1 = new html_table_cell($OUTPUT->user_picture($user, array('popup' => true)));
$cell2 = new html_table_cell(get_string('bynameondate', 'forum', $by));
$cell3 = new html_table_cell();
$cell3->atributtes ['width'] = "80%";
$cell4 = new html_table_cell();
$cell5 = new html_table_cell();
$row1 = new html_table_row();
$row1->cells[] = $cell1;
$row1->cells[] = $cell2;
$row2 = new html_table_row();
$row2->cells[] = $cell3;
if ($format != 'html') {
if ($format == 'creole') {
$parsedcontent = wiki_parse_content('creole', $num->content, $options);
} else if ($format == 'nwiki') {
$parsedcontent = wiki_parse_content('nwiki', $num->content, $options);
}
$cell4->text = html_entity_decode($parsedcontent['parsed_text']);
} else {
$cell4->text = $num->content;
}
$row2->cells[] = $cell4;
if ((has_capability('mod/wiki:managecomment', $context)) and ($USER->id == $num->userid)) {
$urledit = new moodle_url('/mod/wiki/editcomments.php', array('commentid' => $num->id, 'pageid' => $page->id, 'action' => 'edit'));
$urldelet = new moodle_url('/mod/wiki/instancecomments.php', array('commentid' => $num->id, 'pageid' => $page->id, 'action' => 'delete'));
$cell6 = new html_table_cell($OUTPUT->action_icon($urledit, new pix_icon('t/edit', get_string('edit'))) . $OUTPUT->action_icon($urldelet, new pix_icon('t/delete', get_string('delete'))));
$row3 = new html_table_row();
$row3->cells[] = $cell5;
$row3->cells[] = $cell6;
$t->data = array($row1, $row2, $row3);
} else {
$t->data = array($row1, $row2);
}
echo html_writer::table($t);
}
}
function set_url() {
global $PAGE, $CFG;
$PAGE->set_url($CFG->wwwroot . '/mod/wiki/comments.php', array('pageid' => $this->page->id));
}
protected function create_navbar() {
global $PAGE, $CFG;
parent::create_navbar();
$PAGE->navbar->add(get_string('comments', 'wiki'));
}
}
/**
* Class that models the behavior of wiki's edit comment
*
* @package mod-wiki
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class page_wiki_editcomment extends page_wiki {
private $comment;
private $action;
private $form;
private $format;
function set_url() {
global $PAGE, $CFG;
$PAGE->set_url($CFG->wwwroot . '/mod/wiki/comments.php', array('pageid' => $this->page->id));
}
function print_header() {
parent::print_header();
$this->print_pagetitle();
}
function print_content() {
global $PAGE;
$context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
require_capability('mod/wiki:editcomment', $context, NULL, true, 'noeditcommentpermission', 'wiki');
if ($this->action == 'add') {
$this->add_comment_form();
} else if ($this->action == 'edit') {
$this->edit_comment_form($this->comment);
}
}
function set_action($action, $comment) {
global $CFG;
require_once($CFG->dirroot . '/mod/wiki/comments_form.php');
$this->action = $action;
$this->comment = $comment;
$version = wiki_get_current_version($this->page->id);
$this->format = $version->contentformat;
if ($this->format == 'html') {
$destination = $CFG->wwwroot . '/mod/wiki/instancecomments.php?pageid=' . $this->page->id;
$this->form = new mod_wiki_comments_form($destination);
}
}
protected function create_navbar() {
global $PAGE, $CFG;
$PAGE->navbar->add(get_string('comments', 'wiki'), $CFG->wwwroot . '/mod/wiki/comments.php?pageid=' . $this->page->id);
if ($this->action == 'add') {
$PAGE->navbar->add(get_string('insertcomment', 'wiki'));
} else {
$PAGE->navbar->add(get_string('editcomment', 'wiki'));
}
}
protected function setup_tabs() {
parent::setup_tabs(array('linkedwhenactive' => 'comments', 'activetab' => 'comments'));
}
private function add_comment_form() {
global $CFG;
require_once($CFG->dirroot . '/mod/wiki/editors/wiki_editor.php');
$pageid = $this->page->id;
if ($this->format == 'html') {
$this->form->display();
} else {
wiki_print_editor_wiki($this->page->id, null, $this->format, -1, null, false, null, 'fromcomments');
}
}
private function edit_comment_form($com) {
global $CFG;
require_once($CFG->dirroot . '/mod/wiki/comments_form.php');
require_once($CFG->dirroot . '/mod/wiki/editors/wiki_editor.php');
if ($this->format == 'html') {
$commentoptions = array('trusttext' => true, 'maxfiles' => 0);
$com->action = 'edit';
$com->entrycomment_editor['text'] = $com->content;
$this->form->set_data($com, $commentoptions);
$this->form->display();
} else {
$action = 'edit';
$commentid = $com->id;
$pageid = $this->page->id;
$destination = $CFG->wwwroot . '/mod/wiki/instancecomments.php?pageid=' . $pageid . '&id=' . $commentid . '&action=' . $action;
wiki_print_editor_wiki($this->page->id, $com->content, $this->format, -1, null, false, array(), 'fromcomments', $commentid);
}
}
}
/**
* Wiki page search page
*
* @package mod-wiki
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class page_wiki_search extends page_wiki {
private $search_result;
protected function create_navbar() {
global $PAGE, $CFG;
$PAGE->navbar->add($PAGE->activityrecord->name, $CFG->wwwroot . '/mod/wiki/view.php?id=' . $PAGE->cm->id);
}
function set_search_string($search, $searchcontent) {
$swid = $this->subwiki->id;
if ($searchcontent) {
$this->search_result = wiki_search_all($swid, $search);
} else {
$this->search_result = wiki_search_title($swid, $search);
}
}
function set_url() {
global $PAGE, $CFG;
$PAGE->set_url($CFG->wwwroot . '/mod/wiki/search.php');
}
function print_content() {
global $PAGE;
$context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
require_capability('mod/wiki:viewpage', $context, NULL, true, 'noviewpagepermission', 'wiki');
echo $this->wikioutput->search_result($this->search_result);
}
}
/**
*
* Class that models the behavior of wiki's
* create page
*
*/
class page_wiki_create extends page_wiki {
private $format;
private $swid;
private $action;
private $mform;
function print_header() {
$this->set_url();
parent::print_header();
}
function set_url() {
global $PAGE, $CFG;
$params = array();
if ($this->action == 'new') {
$params['action'] = 'new';
$params['swid'] = $this->swid;
if ($this->title != get_string('newpage', 'wiki')) {
$params['title'] = $this->title;
}
$PAGE->set_url($CFG->wwwroot . '/mod/wiki/create.php', $params);
} else {
$params['action'] = 'create';
$params['swid'] = $this->swid;
$PAGE->set_url($CFG->wwwroot . '/mod/wiki/create.php', $params);
}
}
function set_format($format) {
$this->format = $format;
}
function set_swid($swid) {
$this->swid = $swid;
}
function set_action($action) {
global $PAGE;
$this->action = $action;
require_once(dirname(__FILE__) . '/create_form.php');
$url = new moodle_url('/mod/wiki/create.php', array('action' => 'create', 'wid' => $PAGE->activityrecord->id, 'gid' => $this->gid, 'uid' => $this->uid));
$formats = wiki_get_formats();
$options = array('formats' => $formats);
if ($this->title != get_string('newpage', 'wiki')) {
$options['disable_pagetitle'] = true;
}
$this->mform = new mod_wiki_create_form($url->out(false), $options);
}
protected function create_navbar() {
global $PAGE;
$PAGE->navbar->add($this->title);
}
function print_content($pagetitle = '') {
global $PAGE;
$context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
// @TODO: Change this to has_capability and show an alternative interface.
require_capability('mod/wiki:createpage', $context, NULL, true, 'nocreatepermission', 'wiki');
$data = new stdclass;
if (!empty($pagetitle)) {
$data->pagetitle = $pagetitle;
}
$data->pageformat = $PAGE->activityrecord->defaultformat;
$this->mform->set_data($data);
$this->mform->display();
}
function create_page() {
global $USER, $CFG, $PAGE;
$data = $this->mform->get_data();
if (empty($this->subwiki)){
$swid = wiki_add_subwiki($PAGE->activityrecord->id, $this->gid, $this->uid);
$this->subwiki = wiki_get_subwiki($swid);
}
$id = wiki_create_page($this->subwiki->id, $data->pagetitle, $data->pageformat, $USER->id);
redirect($CFG->wwwroot . '/mod/wiki/edit.php?pageid=' . $id);
}
}
class page_wiki_preview extends page_wiki_edit {
private $newcontent;
function __construct($wiki, $subwiki, $cm) {
global $PAGE, $CFG, $OUTPUT;
parent::__construct($wiki, $subwiki, $cm);
$buttons = $OUTPUT->update_module_button($cm->id, 'wiki');
$PAGE->set_button($buttons);
}
function print_header() {
global $PAGE, $CFG;
parent::print_header();
}
function print_content() {
global $PAGE;
$context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
require_capability('mod/wiki:editpage', $context, NULL, true, 'noeditpermission', 'wiki');
$this->print_preview();
}
function set_newcontent($newcontent) {
$this->newcontent = $newcontent;
}
function set_url() {
global $PAGE, $CFG;
$params = array('pageid' => $this->page->id
);
if (isset($this->section)) {
$params['section'] = $this->section;
}
$PAGE->set_url($CFG->wwwroot . '/mod/wiki/edit.php', $params);
}
protected function setup_tabs() {
parent::setup_tabs(array('linkedwhenactive' => 'view', 'activetab' => 'view'));
}
protected function check_locks() {
return true;
}
protected function print_preview() {
global $CFG, $OUTPUT;
$version = wiki_get_current_version($this->page->id);
$format = $version->contentformat;
$content = $version->content;
$options = array('swid' => $this->page->subwikiid, 'pageid' => $this->page->id, 'pretty_print' => true);
$parseroutput = wiki_parse_content($format, $this->newcontent, $options);
echo $OUTPUT->notification(get_string('previewwarning', 'wiki'), 'notifyproblem wiki_info');
echo $OUTPUT->box($parseroutput['parsed_text'], 'generalbox wiki_previewbox');
$content = $this->newcontent;
$this->print_edit($content);
}
}
/**
*
* Class that models the behavior of wiki's
* view differences
*
*/
class page_wiki_diff extends page_wiki {
private $compare;
private $comparewith;
function print_header() {
global $OUTPUT;
parent::print_header();
$this->print_pagetitle();
$vstring = new stdclass;
$vstring->old = $this->compare;
$vstring->new = $this->comparewith;
echo $OUTPUT->heading(get_string('comparewith', 'wiki', $vstring));
}
/**
* Print the diff view
*/
function print_content() {
global $PAGE;
$context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
require_capability('mod/wiki:viewpage', $context, NULL, true, 'noviewpagepermission', 'wiki');
$this->print_diff_content();
}
function set_url() {
global $PAGE, $CFG;
$PAGE->set_url($CFG->wwwroot . '/mod/wiki/diff.php', array('pageid' => $this->page->id, 'comparewith' => $this->comparewith, 'compare' => $this->compare));
}
function set_comparison($compare, $comparewith) {
$this->compare = $compare;
$this->comparewith = $comparewith;
}
protected function create_navbar() {
global $PAGE, $CFG;
parent::create_navbar();
$PAGE->navbar->add(get_string('history', 'wiki'), $CFG->wwwroot . '/mod/wiki/history.php?pageid' . $this->page->id);
$PAGE->navbar->add(get_string('diff', 'wiki'));
}
protected function setup_tabs() {
parent::setup_tabs(array('linkedwhenactive' => 'history', 'activetab' => 'history'));
}
/**
* Given two versions of a page, prints a page displaying the differences between them.
*
* @uses $CFG
*
* @param int $pageid The page id whose versions will be displayed.
* @param int $cm The course id, needed to print user images.
* @param int $compare The first version number to be compared.
* @param int $comparewith The second version number to be compared.
*/
private function print_diff_content() {
global $CFG, $OUTPUT, $PAGE;
$pageid = $this->page->id;
$total = wiki_count_wiki_page_versions($pageid) - 1;
$oldversion = wiki_get_wiki_page_version($pageid, $this->compare);
$newversion = wiki_get_wiki_page_version($pageid, $this->comparewith);
if ($oldversion && $newversion) {
$oldtext = format_text($oldversion->content);
$newtext = format_text($newversion->content);
list($diff1, $diff2) = ouwiki_diff_html($oldtext, $newtext);
$oldversion->diff = $diff1;
$oldversion->user = wiki_get_user_info($oldversion->userid);
$newversion->diff = $diff2;
$newversion->user = wiki_get_user_info($newversion->userid);
echo $this->wikioutput->diff($pageid, $oldversion, $newversion, array('total' => $total));
} else {
print_error('versionerror', 'wiki');
}
}
}
/**
*
* Class that models the behavior of wiki's history page
*
*/
class page_wiki_history extends page_wiki {
/**
* @var int $paging current page
*/
private $paging;
/**
* @var int @rowsperpage Items per page
*/
private $rowsperpage = 10;
/**
* @var int $allversion if $allversion != 0, all versions will be printed in a signle table
*/
private $allversion;
function __construct($wiki, $subwiki, $cm) {
global $PAGE;
parent::__construct($wiki, $subwiki, $cm);
$PAGE->requires->js_init_call('M.mod_wiki.history', null, true);
}
function print_header() {
parent::print_header();
$this->print_pagetitle();
}
function print_content() {
global $PAGE;
$context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
require_capability('mod/wiki:viewpage', $context, NULL, true, 'noviewpagepermission', 'wiki');
$this->print_history_content();
}
function set_url() {
global $PAGE, $CFG;
$PAGE->set_url($CFG->wwwroot . '/mod/wiki/history.php', array('pageid' => $this->page->id));
}
function set_paging($paging) {
$this->paging = $paging;
}
function set_allversion($allversion) {
$this->allversion = $allversion;
}
protected function create_navbar() {
global $PAGE, $CFG;
parent::create_navbar();
$PAGE->navbar->add(get_string('history', 'wiki'));
}
/**
* Prints the history for a given wiki page
*
* @uses $CFG
*
* @param int $pageid The page id whose history should be displayed.
* @param int $cm The course id, needed to print user images.
* @param wikipage $wikipage
* @param int $allversion This tells how results should be displayed.
* If $allversion == 0 : Only $rowsperpage will be displayed at a time, and $paging is the page being displayed.
* If $allversion != 0 : All versions will be printed in a single table.
* @param int $paging Desired page to be displayed, this is ignored if $allversion!=0.
* @param int $rowsperpage How many rows to be displayed in each page, this is ignored if $allversion!=0.
*/
private function print_history_content() {
global $CFG, $OUTPUT, $PAGE;
$pageid = $this->page->id;
$offset = $this->paging * $this->rowsperpage;
// vcount is the latest version
$vcount = wiki_count_wiki_page_versions($pageid) - 1;
if ($this->allversion) {
$versions = wiki_get_wiki_page_versions($pageid, 0, $vcount);
} else {
$versions = wiki_get_wiki_page_versions($pageid, $offset, $this->rowsperpage);
}
// We don't want version 0 to be displayed
// version 0 is blank page
if (end($versions)->version == 0) {
array_pop($versions);
}
$contents = array();
$version0page = wiki_get_wiki_page_version($this->page->id, 0);
$creator = wiki_get_user_info($version0page->userid);
$a = new StdClass;
$a->date = userdate($this->page->timecreated, get_string('strftimedaydatetime', 'langconfig'));
$a->username = $creator->username;
echo $OUTPUT->heading(get_string('createddate', 'wiki', $a), 4, 'wiki_headingtime');
if ($vcount > 0) {
/// If there is only one version, we don't need radios nor forms
if (count($versions) == 1) {
$row = array_shift($versions);
$username = wiki_get_user_info($row->userid);
$picture = $OUTPUT->user_picture($username);
$date = userdate($row->timecreated, get_string('strftimedate', 'langconfig'));
$time = userdate($row->timecreated, get_string('strftimetime', 'langconfig'));
$versionid = wiki_get_version($row->id);
$versionlink = new moodle_url('/mod/wiki/viewversion.php', array('pageid' => $pageid, 'versionid' => $versionid->id));
$userlink = new moodle_url('/user/view.php', array('id' => $username->id));
$contents[] = array('', html_writer::link($versionlink->out(false), $row->version), $picture . html_writer::link($userlink->out(false), fullname($username)), $time, print_container($date, false, 'wiki_histdate', '', true));
$table = new html_table();
$table->head = array('', get_string('version'), get_string('user'), get_string('modified'), '');
$table->data = $contents;
$table->attributes['class'] = 'mdl-align';
echo html_writer::table($table);
} else {
$checked = $vcount - $offset;
$lastdate = '';
$rowclass = array();
foreach ($versions as $version) {
$user = wiki_get_user_info($version->userid);
$picture = $OUTPUT->user_picture($user, array('popup' => true));
$date = userdate($version->timecreated, get_string('strftimedate'));
if ($date == $lastdate) {
$date = '';
$rowclass[] = '';
} else {
$lastdate = $date;
$rowclass[] = 'wiki_histnewdate';
}
$time = userdate($version->timecreated, get_string('strftimetime', 'langconfig'));
$versionid = wiki_get_version($version->id);
if ($versionid) {
$url = new moodle_url('/mod/wiki/viewversion.php', array('pageid' => $pageid, 'versionid' => $versionid->id));
$viewlink = html_writer::link($url->out(false), $version->version);
} else {
$viewlink = $version->version;
}
$userlink = new moodle_url('/user/view.php', array('id' => $version->userid));
$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, print_container($date, false, 'wiki_histdate', '', true));
}
$table = new html_table();
$icon = $OUTPUT->help_icon('diff', 'wiki', get_string('diff', 'wiki'));
$table->head = array($icon, get_string('version'), get_string('user'), get_string('modified'), '');
$table->data = $contents;
$table->attributes['class'] = 'mdl-align';
$table->rowclasses = $rowclass;
/*$table = new StdClass();
$table->head = array(helpbutton('diff', 'diff', 'wiki', true, false, '', true, ''),
get_string('version'),
get_string('user'),
get_string('modified'),
'');
$table->data = $contents;
$table->class = 'mdl-align';
$table->rowclass = $rowclass;*/
///Print the form
echo '<form action="' . $CFG->wwwroot . '/mod/wiki/diff.php" method="get" id="diff">';
echo '<div><input type="hidden" name="pageid" value="' . $pageid . '" /></div>';
echo html_writer::table($table);
echo '<div><input class="wiki_form-button" type="submit" value="' . get_string('comparesel', 'wiki') . '"/></div>';
echo '</form>';
}
} else {
print_string('nohistory', 'wiki');
}
if (!$this->allversion) {
//$pagingbar = moodle_paging_bar::make($vcount, $this->paging, $this->rowsperpage, $CFG->wwwroot.'/mod/wiki/history.php?pageid='.$pageid.'&amp;');
// $pagingbar->pagevar = $pagevar;
echo $OUTPUT->paging_bar($vcount, $this->paging, $this->rowsperpage, $CFG->wwwroot . '/mod/wiki/history.php?pageid=' . $pageid . '&amp;');
//print_paging_bar($vcount, $paging, $rowsperpage,$CFG->wwwroot.'/mod/wiki/history.php?pageid='.$pageid.'&amp;','paging');
} else {
$link = new moodle_url('/mod/wiki/history.php', array('pageid' => $pageid));
$OUTPUT->container(html_writer::link($link->out(false), get_string('viewperpage', 'wiki', $this->rowsperpage)), 'mdl-align');
}
if ($vcount > $this->rowsperpage && !$this->allversion) {
$link = new moodle_url('/mod/wiki/history.php', array('pageid' => $pageid, 'allversion' => 1));
$OUTPUT->container(html_writer::link($link->out(false), get_string('viewallhistory', 'wiki')), 'mdl-align');
}
}
/**
* Given an array of values, creates a group of radio buttons to be part of a form
*
* @param array $options An array of value-label pairs for the radio group (values as keys).
* @param string $name Name of the radiogroup (unique in the form).
* @param string $onclick Function to be executed when the radios are clicked.
* @param string $checked The value that is already checked.
* @param bool $return If true, return the HTML as a string, otherwise print it.
*
* @return mixed If $return is false, returns nothing, otherwise returns a string of HTML.
*/
private function choose_from_radio($options, $name, $onclick = '', $checked = '', $return = false) {
static $idcounter = 0;
if (!$name) {
$name = 'unnamed';
}
$output = '<span class="radiogroup ' . $name . "\">\n";
if (!empty($options)) {
$currentradio = 0;
foreach ($options as $value => $label) {
$htmlid = 'auto-rb' . sprintf('%04d', ++$idcounter);
$output .= ' <span class="radioelement ' . $name . ' rb' . $currentradio . "\">";
$output .= '<input name="' . $name . '" id="' . $htmlid . '" type="radio" value="' . $value . '"';
if ($value == $checked) {
$output .= ' checked="checked"';
}
if ($onclick) {
$output .= ' onclick="' . $onclick . '"';
}
if ($label === '') {
$output .= ' /> <label for="' . $htmlid . '">' . $value . '</label></span>' . "\n";
} else {
$output .= ' /> <label for="' . $htmlid . '">' . $label . '</label></span>' . "\n";
}
$currentradio = ($currentradio + 1) % 2;
}
}
$output .= '</span>' . "\n";
if ($return) {
return $output;
} else {
echo $output;
}
}
}
/**
* Class that models the behavior of wiki's map page
*
*/
class page_wiki_map extends page_wiki {
/**
* @var int wiki view option
*/
private $view;
function print_header() {
parent::print_header();
$this->print_pagetitle();
}
function print_content() {
global $CFG, $PAGE;
$context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
require_capability('mod/wiki:viewpage', $context, NULL, true, 'noviewpagepermission', 'wiki');
if ($this->view > 0) {
//echo '<div><a href="' . $CFG->wwwroot . '/mod/wiki/map.php?pageid=' . $this->page->id . '">' . get_string('backtomapmenu', 'wiki') . '</a></div>';
}
switch ($this->view) {
case 1:
echo $this->wikioutput->menu_map($this->page->id, $this->view);
$this->print_contributions_content();
break;
case 2:
echo $this->wikioutput->menu_map($this->page->id, $this->view);
$this->print_navigation_content();
break;
case 3:
echo $this->wikioutput->menu_map($this->page->id, $this->view);
$this->print_orphaned_content();
break;
case 4:
echo $this->wikioutput->menu_map($this->page->id, $this->view);
$this->print_index_content();
break;
case 5:
echo $this->wikioutput->menu_map($this->page->id, $this->view);
$this->print_page_list_content();
break;
case 6:
echo $this->wikioutput->menu_map($this->page->id, $this->view);
$this->print_updated_content();
break;
default:
echo $this->wikioutput->menu_map($this->page->id, $this->view);
$this->print_page_list_content();
}
}
function set_view($option) {
$this->view = $option;
}
function print_menu_map() {
$options = array('contributions', 'links', 'orphaned', 'pageindex', 'pagelist', 'updatedpages');
$items = array();
foreach ($options as $opt) {
$items[] = get_string($opt, 'wiki');
}
$table = new html_table();
$table->head = array(get_string('mapmenu', 'wiki'));
$table->attributes['class'] = 'wiki_editor generalbox';
$table->data = array();
$table->rowclasses = array();
foreach ($items as $key => $item) {
$link = new moodle_url('/mod/wiki/map.php', array('pageid' => $this->page->id, 'option' => $key + 1));
$table->data[] = array(html_writer::link($link, $item));
}
echo html_writer::table($table);
}
function set_url() {
global $PAGE, $CFG;
$PAGE->set_url($CFG->wwwroot . '/mod/wiki/map.php', array('pageid' => $this->page->id));
}
protected function create_navbar() {
global $PAGE;
parent::create_navbar();
$PAGE->navbar->add(get_string('map', 'wiki'));
}
/**
* Prints the contributions tab content
*
* @uses $OUTPUT, $USER
*
*/
private function print_contributions_content() {
global $CFG, $OUTPUT, $USER;
$page = $this->page;
if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) {
$fresh = wiki_refresh_cachedcontent($page);
$page = $fresh['page'];
}
$swid = $this->subwiki->id;
$table = new html_table();
$table->head = array(get_string('contributions', 'wiki'));
$table->attributes['class'] = 'wiki_editor generalbox';
$table->data = array();
$table->rowclasses = array();
$lastversions = array();
$pages = array();
$users = array();
if ($contribs = wiki_get_contributions($swid, $USER->id)) {
foreach ($contribs as $contrib) {
if (!array_key_exists($contrib->pageid, $pages)) {
$page = wiki_get_page($contrib->pageid);
$pages[$contrib->pageid] = $page;
} else {
continue;
}
if (!array_key_exists($page->id, $lastversions)) {
$version = wiki_get_last_version($page->id);
$lastversions[$page->id] = $version;
} else {
$version = $lastversions[$page->id];
}
if (!array_key_exists($version->userid, $users)) {
$user = wiki_get_user_info($version->userid);
$users[$version->userid] = $user;
} else {
$user = $users[$version->userid];
}
$link = wiki_parser_link(wiki_trim_string($page->title), array('swid' => $swid));
$class = ($link['new']) ? 'class="wiki_newentry"' : '';
$linkpage = '<a href="' . $link['url'] . '"' . $class . '>' . $link['content'] . '</a>';
$icon = $OUTPUT->user_picture($user, array('popup' => true));
$table->data[] = array("$icon&nbsp;$linkpage");
}
} else {
$table->data[] = array(get_string('nocontribs', 'wiki'));
}
echo html_writer::table($table);
}
/**
* Prints the navigation tab content
*
* @uses $OUTPUT
*
*/
private function print_navigation_content() {
global $OUTPUT;
$page = $this->page;
if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) {
$fresh = wiki_refresh_cachedcontent($page);
$page = $fresh['page'];
}
$tolinks = wiki_get_linked_to_pages($page->id);
$fromlinks = wiki_get_linked_from_pages($page->id);
$table = new html_table();
$table->attributes['class'] = 'wiki_navigation_from';
$table->head = array(get_string('navigationfrom', 'wiki') . ':');
$table->data = array();
$table->rowclasses = array();
foreach ($fromlinks as $link) {
$lpage = wiki_get_page($link->frompageid);
$link = new moodle_url('/mod/wiki/view.php', array('pageid' => $lpage->id));
$table->data[] = array(html_writer::link($link->out(false), $lpage->title));
$table->rowclasses[] = 'mdl-align';
}
$table_left = html_writer::table($table);
$table = new html_table();
$table->attributes['class'] = 'wiki_navigation_to';
$table->head = array(get_string('navigationto', 'wiki') . ':');
$table->data = array();
$table->rowclasses = array();
foreach ($tolinks as $link) {
if ($link->tomissingpage) {
$viewlink = new moodle_url('/mod/wiki/create.php', array('swid' => $page->subwikiid, 'title' => $link->tomissingpage, 'action' => 'new'));
$table->data[] = array(html_writer::link($viewlink->out(false), $link->tomissingpage, array('class' => 'wiki_newentry')));
} else {
$lpage = wiki_get_page($link->topageid);
$viewlink = new moodle_url('/mod/wiki/view.php', array('pageid' => $lpage->id));
$table->data[] = array(html_writer::link($viewlink->out(false), $lpage->title));
}
$table->rowclasses[] = 'mdl-align';
}
$table_right = html_writer::table($table);
echo $OUTPUT->container($table_left . $table_right, 'wiki_navigation_container');
}
/**
* Prints the index page tab content
*
*
*/
private function print_index_content() {
$page = $this->page;
if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) {
$fresh = wiki_refresh_cachedcontent($page);
$page = $fresh['page'];
}
$node = new navigation_node($page->title);
$keys = array();
$tree = array();
$tree = wiki_build_tree($page, $node, $keys);
$table = new html_table();
$table->head = array(get_string('pageindex', 'wiki'));
$table->attributes['class'] = 'wiki_editor generalbox';
$table->data[] = array($this->render_navigation_node($tree));
echo html_writer::table($table);
}
/**
* Prints the page list tab content
*
*
*/
private function print_page_list_content() {
$page = $this->page;
if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) {
$fresh = wiki_refresh_cachedcontent($page);
$page = $fresh['page'];
}
$pages = wiki_get_page_list($this->subwiki->id);
$stdaux = new stdClass();
$strspecial = get_string('special', 'wiki');
foreach ($pages as $page) {
$letter = strtoupper(substr($page->title, 0, 1));
if (preg_match('/[A-Z]/', $letter)) {
$stdaux->{
$letter}
[] = wiki_parser_link($page);
} else {
$stdaux->{
$strspecial}
[] = wiki_parser_link($page);
}
}
$table = new html_table();
$table->head = array(get_string('pagelist', 'wiki'));
$table->attributes['class'] = 'wiki_editor generalbox';
$table->align = array('center');
foreach ($stdaux as $key => $elem) {
$table->data[] = array($key);
foreach ($elem as $e) {
$table->data[] = array(html_writer::link($e['url'], $e['content']));
}
}
echo html_writer::table($table);
}
/**
* Prints the orphaned tab content
*
*
*/
private function print_orphaned_content() {
$page = $this->page;
if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) {
$fresh = wiki_refresh_cachedcontent($page);
$page = $fresh['page'];
}
$swid = $this->subwiki->id;
$table = new html_table();
$table->head = array(get_string('orphaned', 'wiki'));
$table->attributes['class'] = 'wiki_editor generalbox';
$table->data = array();
$table->rowclasses = array();
if ($orphanedpages = wiki_get_orphaned_pages($swid)) {
foreach ($orphanedpages as $page) {
$link = wiki_parser_link(wiki_trim_string($page->title), array('swid' => $swid));
$class = ($link['new']) ? 'class="wiki_newentry"' : '';
$table->data[] = array('<a href="' . $link['url'] . '"' . $class . '>' . $link['content'] . '</a>');
}
} else {
$table->data[] = array(get_string('noorphanedpages', 'wiki'));
}
echo html_writer::table($table);
}
/**
* Prints the updated tab content
*
* @uses $COURSE, $OUTPUT
*
*/
private function print_updated_content() {
global $COURSE, $OUTPUT;
$page = $this->page;
if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) {
$fresh = wiki_refresh_cachedcontent($page);
$page = $fresh['page'];
}
$swid = $this->subwiki->id;
$table = new html_table();
$table->head = array(get_string('updatedpages', 'wiki'));
$table->attributes['class'] = 'wiki_editor generalbox';
$table->data = array();
$table->rowclasses = array();
if ($pages = wiki_get_updated_pages_by_subwiki($swid)) {
$strdataux = '';
foreach ($pages as $page) {
$user = wiki_get_user_info($page->userid);
$strdata = strftime('%d %b %Y', $page->timemodified);
if ($strdata != $strdataux) {
$table->data[] = array($OUTPUT->heading($strdata, 4));
$strdataux = $strdata;
}
$link = wiki_parser_link(wiki_trim_string($page->title), array('swid' => $swid));
$class = ($link['new']) ? 'class="wiki_newentry"' : '';
$linkpage = '<a href="' . $link['url'] . '"' . $class . '>' . $link['content'] . '</a>';
$icon = $OUTPUT->user_picture($user, array($COURSE->id));
$table->data[] = array("$icon&nbsp;$linkpage");
}
} else {
$table->data[] = array(get_string('noupdatedpages', 'wiki'));
}
echo html_writer::table($table);
}
protected function render_navigation_node($items, $attrs = array(), $expansionlimit = null, $depth = 1) {
// exit if empty, we don't want an empty ul element
if (count($items) == 0) {
return '';
}
// array of nested li elements
$lis = array();
foreach ($items as $item) {
if (!$item->display) {
continue;
}
$content = $item->get_content();
$title = $item->get_title();
if ($item->icon instanceof renderable) {
$icon = $this->wikioutput->render($item->icon);
$content = $icon . '&nbsp;' . $content; // use CSS for spacing of icons
}
if ($item->helpbutton !== null) {
$content = trim($item->helpbutton) . html_writer::tag('span', $content, array('class' => 'clearhelpbutton'));
}
if ($content === '') {
continue;
}
if ($item->action instanceof action_link) {
//TODO: to be replaced with something else
$link = $item->action;
if ($item->hidden) {
$link->add_class('dimmed');
}
$content = $this->output->render($link);
} else if ($item->action instanceof moodle_url) {
$attributes = array();
if ($title !== '') {
$attributes['title'] = $title;
}
if ($item->hidden) {
$attributes['class'] = 'dimmed_text';
}
$content = html_writer::link($item->action, $content, $attributes);
} else if (is_string($item->action) || empty($item->action)) {
$attributes = array();
if ($title !== '') {
$attributes['title'] = $title;
}
if ($item->hidden) {
$attributes['class'] = 'dimmed_text';
}
$content = html_writer::tag('span', $content, $attributes);
}
// this applies to the li item which contains all child lists too
$liclasses = array($item->get_css_type(), 'depth_' . $depth);
if ($item->has_children() && (!$item->forceopen || $item->collapse)) {
$liclasses[] = 'collapsed';
}
if ($item->isactive === true) {
$liclasses[] = 'current_branch';
}
$liattr = array('class' => join(' ', $liclasses));
// class attribute on the div item which only contains the item content
$divclasses = array('tree_item');
if ((empty($expansionlimit) || $item->type != $expansionlimit) && ($item->children->count() > 0 || ($item->nodetype == navigation_node::NODETYPE_BRANCH && $item->children->count() == 0 && isloggedin()))) {
$divclasses[] = 'branch';
} else {
$divclasses[] = 'leaf';
}
if (!empty($item->classes) && count($item->classes) > 0) {
$divclasses[] = join(' ', $item->classes);
}
$divattr = array('class' => join(' ', $divclasses));
if (!empty($item->id)) {
$divattr['id'] = $item->id;
}
$content = html_writer::tag('p', $content, $divattr) . $this->render_navigation_node($item->children, array(), $expansionlimit, $depth + 1);
if (!empty($item->preceedwithhr) && $item->preceedwithhr === true) {
$content = html_writer::empty_tag('hr') . $content;
}
$content = html_writer::tag('li', $content, $liattr);
$lis[] = $content;
}
if (count($lis)) {
return html_writer::tag('ul', implode("\n", $lis), $attrs);
} else {
return '';
}
}
}
/**
* Class that models the behavior of wiki's restore version page
*
*/
class page_wiki_restoreversion extends page_wiki {
private $version;
function print_header() {
parent::print_header();
$this->print_pagetitle();
}
function print_content() {
global $CFG, $PAGE;
$context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
require_capability('mod/wiki:managewiki', $context, NULL, true, 'nomanagewikipermission', 'wiki');
$this->print_restoreversion();
}
function set_url() {
global $PAGE, $CFG;
$PAGE->set_url($CFG->wwwroot . '/mod/wiki/viewversion.php', array('pageid' => $this->page->id, 'versionid' => $this->version->id));
}
function set_versionid($versionid) {
$this->version = wiki_get_version($versionid);
}
protected function create_navbar() {
global $PAGE, $CFG;
parent::create_navbar();
$PAGE->navbar->add(get_string('restoreversion', 'wiki'));
}
protected function setup_tabs() {
parent::setup_tabs(array('linkedwhenactive' => 'history', 'activetab' => 'history'));
}
/**
* Prints the restore version content
*
* @uses $CFG
*
* @param page $page The page whose version will be restored
* @param int $versionid The version to be restored
* @param bool $confirm If false, shows a yes/no confirmation page.
* If true, restores the old version and redirects the user to the 'view' tab.
*/
private function print_restoreversion() {
global $CFG, $OUTPUT;
$version = wiki_get_version($this->version->id);
echo $OUTPUT->heading(get_string('restoreconfirm', 'wiki', $version->version), 2);
print_container_start(false, 'wiki_restoreform');
echo '<form class="wiki_restore_yes" action="' . $CFG->wwwroot . '/mod/wiki/restoreversion.php?pageid=' . $this->page->id . '&amp;versionid=' . $version->id . '" method="post" id="restoreversion">';
echo '<div><input type="submit" name="confirm" value="' . get_string('yes') . '" /></div>';
echo '</form>';
echo '<form class="wiki_restore_no" action="' . $CFG->wwwroot . '/mod/wiki/viewversion.php?pageid=' . $this->page->id . '&amp;versionid=' . $version->id . '" method="post">';
echo '<div><input type="submit" name="norestore" value="' . get_string('no') . '" /></div>';
echo '</form>';
print_container_end();
}
}
/**
*
* Class that models the behavior of wiki's
* save page
*
*/
class page_wiki_save extends page_wiki_edit {
private $newcontent;
function print_header() {
}
function print_content() {
global $PAGE;
$context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
require_capability('mod/wiki:editpage', $context, NULL, true, 'noeditpermission', 'wiki');
$this->print_save();
}
function set_newcontent($newcontent) {
$this->newcontent = $newcontent;
}
protected function set_session_url() {
}
protected function print_save() {
global $CFG, $USER, $OUTPUT, $PAGE;
$cm = $PAGE->cm;
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$url = $CFG->wwwroot . '/mod/wiki/edit.php?pageid=' . $this->page->id;
if (!empty($this->section)) {
$url .= "&section=" . $this->section;
}
$params = array('attachmentoptions' => page_wiki_edit::$attachmentoptions, 'format' => $this->format, 'version' => $this->versionnumber);
if ($this->format != 'html') {
$params['contextid'] = $context->id;
$params['filearea'] = 'wiki_attachments';
$params['fileitemid'] = $this->page->id;
}
$form = new mod_wiki_edit_form($url, $params);
$save = false;
$data = false;
if ($data = $form->get_data()) {
if ($this->format == 'html') {
$data = file_postupdate_standard_editor($data, 'newcontent', page_wiki_edit::$attachmentoptions, $context, 'wiki_attachments', $this->subwiki->id);
}
if (isset($this->section)) {
$save = wiki_save_section($this->page, $this->section, $data->newcontent, $USER->id);
} else {
$save = wiki_save_page($this->page, $data->newcontent, $USER->id);
}
}
if ($save && $data) {
if ($this->format != 'html') {
$errors = $this->process_uploads($context);
}
if (!empty($CFG->usetags)) {
tag_set('wiki', $this->page->id, $data->tags);
}
$message = '<p>' . get_string('saving', 'wiki') . '</p>';
if (!empty($save['sections'])) {
foreach ($save['sections'] as $s) {
$message .= '<p>' . get_string('repeatedsection', 'wiki', $s) . '</p>';
}
}
if ($this->versionnumber + 1 != $save['version']) {
$message .= '<p>' . get_string('wrongversionsave', 'wiki') . '</p>';
}
if (isset($errors) && !empty($errors)) {
foreach ($errors as $e) {
$message .= "<p>" . get_string('filenotuploadederror', 'wiki', $e->get_filename()) . "</p>";
}
}
//deleting old locks
wiki_delete_locks($this->page->id, $USER->id, $this->section);
redirect($CFG->wwwroot . '/mod/wiki/view.php?pageid=' . $this->page->id);
} else {
print_error('savingerror', 'wiki');
}
}
}
/**
* Class that models the behavior of wiki's view an old version of a page
*
*/
class page_wiki_viewversion extends page_wiki {
private $version;
function print_header() {
parent::print_header();
$this->print_pagetitle();
}
function print_content() {
global $PAGE;
$context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
require_capability('mod/wiki:viewpage', $context, NULL, true, 'noviewpagepermission', 'wiki');
$this->print_version_view();
}
function set_url() {
global $PAGE, $CFG;
$PAGE->set_url($CFG->wwwroot . '/mod/wiki/viewversion.php', array('pageid' => $this->page->id, 'versionid' => $this->version->id));
}
function set_versionid($versionid) {
$this->version = wiki_get_version($versionid);
}
protected function create_navbar() {
global $PAGE, $CFG;
parent::create_navbar();
$PAGE->navbar->add(get_string('history', 'wiki'), $CFG->wwwroot . '/mod/wiki/history.php?pageid' . $this->page->id);
$PAGE->navbar->add(get_string('versionnum', 'wiki', $this->version->version));
}
protected function setup_tabs() {
parent::setup_tabs(array('linkedwhenactive' => 'history', 'activetab' => 'history', 'inactivetabs' => array('edit')));
}
/**
* Given an old page version, output the version content
*
* @uses $CFG
*
* @param page $page The page whose version will be displayed.
* @param int $cm The course id, needed to print user images.
* @param int $version The version number to be displayed.
*/
private function print_version_view() {
global $CFG, $OUTPUT, $PAGE;
$cm = $PAGE->cm;
$pageversion = wiki_get_version($this->version->id);
if ($pageversion) {
$restorelink = new moodle_url('/mod/wiki/restoreversion.php', array('pageid' => $this->page->id, 'versionid' => $this->version->id));
echo $OUTPUT->heading(get_string('viewversion', 'wiki', $pageversion->version) . '<br />' . html_writer::link($restorelink->out(false), '(' . get_string('restorethis', 'wiki') . ')', array('class' => 'wiki_restore')) . '&nbsp;', 4);
$userinfo = wiki_get_user_info($pageversion->userid);
$heading = '<p><strong>' . get_string('modified', 'wiki') . ':</strong>&nbsp;' . userdate($pageversion->timecreated, get_string('strftimedatetime', 'langconfig'));
$viewlink = new moodle_url('/user/view.php', array('id' => $userinfo->id));
$heading .= '&nbsp;&nbsp;&nbsp;<strong>' . get_string('user') . ':</strong>&nbsp;' . html_writer::link($viewlink->out(false), fullname($userinfo));
$heading .= '&nbsp;&nbsp;&rarr;&nbsp;' . $OUTPUT->user_picture(wiki_get_user_info($pageversion->userid), array('popup' => true)) . '</p>';
print_container($heading, false, 'mdl-align wiki_modifieduser wiki_headingtime');
$options = array('swid' => $this->subwiki->id, 'pretty_print' => true, 'pageid' => $this->page->id);
$parseroutput = wiki_parse_content($pageversion->contentformat, $pageversion->content, $options);
$content = print_container($parseroutput['parsed_text'], false, '', '', true);
echo $OUTPUT->box($content, 'generalbox wiki_contentbox');
} else {
print_error('versionerror', 'wiki');
}
}
}
class page_wiki_confirmrestore extends page_wiki_save {
private $version;
function set_url() {
global $PAGE, $CFG;
$PAGE->set_url($CFG->wwwroot . '/mod/wiki/viewversion.php', array('pageid' => $this->page->id, 'versionid' => $this->version->id));
}
function print_content() {
global $CFG, $PAGE;
$context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
require_capability('mod/wiki:managewiki', $context, NULL, true, 'nomanagewikipermission', 'wiki');
$version = wiki_get_version($this->version->id);
if (wiki_restore_page($this->page, $version->content, $version->userid)) {
redirect($CFG->wwwroot . '/mod/wiki/view.php?pageid=' . $this->page->id, get_string('restoring', 'wiki', $version->version), 3);
} else {
print_error('restoreerror', 'wiki', $version->version);
}
}
function set_versionid($versionid) {
$this->version = wiki_get_version($versionid);
}
}
class page_wiki_prettyview extends page_wiki {
function print_header() {
global $CFG, $OUTPUT;
echo $OUTPUT->doctype();
echo '<html>';
echo '<head>';
echo $OUTPUT->standard_head_html();
echo '</head>';
echo '<body>';
echo '<h1 id="wiki_printable_title">' . $this->title . '</h1>';
}
function print_content() {
global $PAGE;
$context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
require_capability('mod/wiki:viewpage', $context, NULL, true, 'noviewpagepermission', 'wiki');
$this->print_pretty_view();
}
function set_url() {
global $PAGE, $CFG;
$PAGE->set_url($CFG->wwwroot . '/mod/wiki/prettyview.php', array('pageid' => $this->page->id));
}
function print_footer() {
echo '</body>';
echo '</html>';
}
private function print_pretty_view() {
$version = wiki_get_current_version($this->page->id);
$content = wiki_parse_content($version->contentformat, $version->content, array('printable' => true, 'swid' => $this->subwiki->id, 'pageid' => $this->page->id, 'pretty_print' => true));
echo '<div id="wiki_printable_content">';
echo $content['parsed_text'];
echo '</div>';
}
}
class page_wiki_handlecomments extends page_wiki {
private $action;
private $content;
private $commentid;
private $format;
function print_header() {
$this->set_url();
}
public function print_content() {
global $PAGE;
$context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
require_capability('mod/wiki:managecomment', $context, NULL, true, 'nomanagecommentpermission', 'wiki');
if ($this->action == 'add' or $this->action == 'edit') {
$this->add_comment($this->content, $this->commentid);
} else if ($this->action == 'delete') {
$this->delete_comment($this->commentid);
}
}
public function set_url() {
global $PAGE, $CFG;
$PAGE->set_url($CFG->wwwroot . '/mod/wiki/comments.php', array('pageid' => $this->page->id));
}
public function set_action($action, $commentid, $content) {
$this->action = $action;
$this->commentid = $commentid;
$this->content = $content;
$version = wiki_get_current_version($this->page->id);
$format = $version->contentformat;
$this->format = $format;
}
private function add_comment($content, $idcomment) {
global $CFG, $PAGE;
require_once($CFG->dirroot . "/mod/wiki/locallib.php");
$pageid = $this->page->id;
$cm = $PAGE->cm;
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
wiki_add_comment($context, $pageid, $content, $this->format);
if (!$idcomment) {
redirect($CFG->wwwroot . '/mod/wiki/comments.php?pageid=' . $pageid, get_string('createcomment', 'wiki'), 2);
} else {
$this->delete_comment($idcomment);
}
}
private function delete_comment($commentid) {
global $CFG, $PAGE;
$cm = $PAGE->cm;
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$pageid = $this->page->id;
wiki_delete_comment($commentid, $context, $pageid);
redirect($CFG->wwwroot . '/mod/wiki/comments.php?pageid=' . $pageid, get_string('deletecomment', 'wiki'), 2);
}
}
class page_wiki_lock extends page_wiki_edit {
public function print_header() {
$this->set_url();
}
protected function set_url() {
global $PAGE, $CFG;
$params = array('pageid' => $this->page->id);
if ($this->section) {
$params['section'] = $this->section;
}
$PAGE->set_url($CFG->wwwroot . '/mod/wiki/lock.php', $params);
}
protected function set_session_url() {
}
public function print_content() {
global $USER, $PAGE;
$context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
require_capability('mod/wiki:editpage', $context, NULL, true, 'noeditpermission', 'wiki');
wiki_set_lock($this->page->id, $USER->id, $this->section);
}
public function print_footer() {
}
}
class page_wiki_overridelocks extends page_wiki_edit {
function print_header() {
$this->set_url();
}
function print_content() {
global $CFG, $PAGE;
$context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
require_capability('mod/wiki:overridelock', $context, NULL, true, 'nooverridelockpermission', 'wiki');
wiki_delete_locks($this->page->id, null, $this->section, true, true);
$args = "pageid=" . $this->page->id;
if (!empty($this->section)) {
$args .= "&section=" . $this->section;
}
redirect($CFG->wwwroot . '/mod/wiki/edit.php?' . $args, get_string('overridinglocks', 'wiki'), 2);
}
function set_url() {
global $PAGE, $CFG;
$params = array('pageid' => $this->page->id);
if (!empty($this->section)) {
$params['section'] = $this->section;
}
$PAGE->set_url($CFG->wwwroot . '/mod/wiki/overridelocks.php', $params);
}
protected function set_session_url() {
}
private function print_overridelocks() {
global $CFG;
wiki_delete_locks($this->page->id, null, $this->section, true, true);
$args = "pageid=" . $this->page->id;
if (!empty($this->section)) {
$args .= "&section=" . $this->section;
}
redirect($CFG->wwwroot . '/mod/wiki/edit.php?' . $args, get_string('overridinglocks', 'wiki'), 2);
}
}
Jump to Line
Something went wrong with that request. Please try again.