mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 08:55:15 +02:00
MDL-26392 WIKI added file managment support to wiki editor
This commit is contained in:
parent
a56c68e3f4
commit
12c9bbbdd2
@ -57,7 +57,7 @@ if (!$cm = get_coursemodule_from_instance('wiki', $wiki->id)) {
|
||||
|
||||
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
|
||||
|
||||
require_course_login($course->id, true, $cm);
|
||||
require_login($course->id, true, $cm);
|
||||
|
||||
add_to_log($course->id, 'wiki', 'comments', 'comments.php?id=' . $cm->id, $wiki->id);
|
||||
|
||||
|
@ -38,7 +38,7 @@ $capabilities = array(
|
||||
)
|
||||
),
|
||||
|
||||
'mod/wiki:createpage' => array(
|
||||
'mod/wiki:createpage' => array(
|
||||
|
||||
'riskbitmask' => RISK_SPAM,
|
||||
|
||||
@ -89,6 +89,17 @@ $capabilities = array(
|
||||
)
|
||||
),
|
||||
|
||||
'mod/wiki:managefiles' => array(
|
||||
|
||||
'captype' => 'write',
|
||||
'contextlevel' => CONTEXT_MODULE,
|
||||
'archetypes' => array(
|
||||
'teacher' => CAP_ALLOW,
|
||||
'editingteacher' => CAP_ALLOW,
|
||||
'manager' => CAP_ALLOW
|
||||
)
|
||||
),
|
||||
|
||||
'mod/wiki:overridelock' => array(
|
||||
|
||||
'captype' => 'write',
|
||||
|
@ -66,7 +66,7 @@ if ($compare >= $comparewith) {
|
||||
print_error("A page version can only be compared with an older version.");
|
||||
}
|
||||
|
||||
require_course_login($course->id, true, $cm);
|
||||
require_login($course->id, true, $cm);
|
||||
add_to_log($course->id, "wiki", "diff", "diff.php?id=$cm->id", "$wiki->id");
|
||||
|
||||
$wikipage = new page_wiki_diff($wiki, $subwiki, $cm);
|
||||
|
@ -31,8 +31,7 @@ if (!defined('MOODLE_INTERNAL')) {
|
||||
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
|
||||
}
|
||||
|
||||
require_once($CFG->dirroot . "/mod/wiki/editors/wikieditor.php");
|
||||
require_once($CFG->dirroot . "/mod/wiki/editors/wikifiletable.php");
|
||||
require_once($CFG->dirroot . '/mod/wiki/editors/wikieditor.php');
|
||||
|
||||
class mod_wiki_edit_form extends moodleform {
|
||||
|
||||
@ -42,13 +41,12 @@ class mod_wiki_edit_form extends moodleform {
|
||||
$mform =& $this->_form;
|
||||
|
||||
$version = $this->_customdata['version'];
|
||||
$format = $this->_customdata['format'];
|
||||
$tags = !isset($this->_customdata['tags'])?"":$this->_customdata['tags'];
|
||||
|
||||
$format = $this->_customdata['format'];
|
||||
$tags = !isset($this->_customdata['tags'])?"":$this->_customdata['tags'];
|
||||
|
||||
if ($format != 'html') {
|
||||
$contextid = $this->_customdata['contextid'];
|
||||
$filearea = $this->_customdata['filearea'];
|
||||
$contextid = $this->_customdata['contextid'];
|
||||
$filearea = $this->_customdata['filearea'];
|
||||
$fileitemid = $this->_customdata['fileitemid'];
|
||||
}
|
||||
|
||||
@ -63,12 +61,25 @@ class mod_wiki_edit_form extends moodleform {
|
||||
|
||||
$fieldname = get_string('format' . $format, 'wiki');
|
||||
if ($format != 'html') {
|
||||
$mform->addElement('wikieditor', 'newcontent', $fieldname, array('cols' => 50, 'rows' => 20, 'wiki_format' => $format));
|
||||
// Use wiki editor
|
||||
$ft = new filetype_parser;
|
||||
$extensions = $ft->get_extensions('image');
|
||||
$fs = get_file_storage();
|
||||
$tree = $fs->get_area_tree($contextid, 'mod_wiki', 'attachments', $fileitemid);
|
||||
$files = array();
|
||||
foreach ($tree['files'] as $file) {
|
||||
$filename = $file->get_filename();
|
||||
foreach ($extensions as $ext) {
|
||||
if (preg_match('#'.$ext.'$#', $filename)) {
|
||||
$files[] = $filename;
|
||||
}
|
||||
}
|
||||
}
|
||||
$mform->addElement('wikieditor', 'newcontent', $fieldname, array('cols' => 100, 'rows' => 20, 'wiki_format' => $format, 'files'=>$files));
|
||||
$mform->addHelpButton('newcontent', 'format'.$format, 'wiki');
|
||||
} else {
|
||||
$mform->addElement('editor', 'newcontent_editor', $fieldname, null, page_wiki_edit::$attachmentoptions);
|
||||
$mform->addHelpButton('newcontent_editor', 'formathtml', 'wiki');
|
||||
|
||||
}
|
||||
|
||||
//hiddens
|
||||
@ -80,21 +91,6 @@ class mod_wiki_edit_form extends moodleform {
|
||||
$mform->addElement('hidden', 'contentformat');
|
||||
$mform->setDefault('contentformat', $format);
|
||||
|
||||
// if ($format != 'html') {
|
||||
// //uploads
|
||||
// $mform->addElement('header', 'attachments_tags', get_string('attachments', 'wiki'));
|
||||
// $mform->addElement('filemanager', 'attachments', get_string('attachments', 'wiki'), null, page_wiki_edit::$attachmentoptions);
|
||||
// $fileinfo = array(
|
||||
// 'contextid'=>$contextid,
|
||||
// 'component'=>'mod_wiki',
|
||||
// 'filearea'=>$filearea,
|
||||
// 'itemid'=>$fileitemid,
|
||||
// );
|
||||
//
|
||||
// $mform->addElement('wikifiletable', 'deleteuploads', get_string('wikifiletable', 'wiki'), null, $fileinfo, $format);
|
||||
// $mform->addElement('submit', 'editoption', get_string('upload', 'wiki'), array('id' => 'tags'));
|
||||
// }
|
||||
|
||||
if (!empty($CFG->usetags)) {
|
||||
$mform->addElement('header', 'tagshdr', get_string('tags', 'tag'));
|
||||
$mform->addElement('tags', 'tags', get_string('tags'));
|
||||
|
@ -17,8 +17,8 @@ if (clientPC.indexOf('opera')!=-1) {
|
||||
// copied and adapted from phpBB
|
||||
function insertTags(tagOpen, tagClose, sampleText) {
|
||||
|
||||
tagOpen = unescape(tagOpen);
|
||||
tagClose = unescape(tagClose);
|
||||
tagOpen = unescape(tagOpen);
|
||||
tagClose = unescape(tagClose);
|
||||
|
||||
var txtarea = document.forms['mform1'].newcontent;
|
||||
|
||||
@ -79,4 +79,4 @@ function insertTags(tagOpen, tagClose, sampleText) {
|
||||
}
|
||||
// reposition cursor if possible
|
||||
if (txtarea.createTextRange) txtarea.caretPos = document.selection.createRange().duplicate();
|
||||
}
|
||||
}
|
||||
|
@ -31,11 +31,17 @@ require_once($CFG->dirroot.'/lib/form/textarea.php');
|
||||
|
||||
class MoodleQuickForm_wikieditor extends MoodleQuickForm_textarea {
|
||||
|
||||
private $files;
|
||||
|
||||
function MoodleQuickForm_wikieditor($elementName = null, $elementLabel = null, $attributes = null) {
|
||||
if (isset($attributes['wiki_format'])) {
|
||||
$this->wikiformat = $attributes['wiki_format'];
|
||||
unset($attributes['wiki_format']);
|
||||
}
|
||||
if (isset($attributes['files'])) {
|
||||
$this->files = $attributes['files'];
|
||||
unset($attributes['files']);
|
||||
}
|
||||
|
||||
parent::MoodleQuickForm_textarea($elementName, $elementLabel, $attributes);
|
||||
}
|
||||
@ -71,7 +77,7 @@ class MoodleQuickForm_wikieditor extends MoodleQuickForm_textarea {
|
||||
}
|
||||
|
||||
private function getButtons() {
|
||||
global $PAGE, $CFG;
|
||||
global $PAGE, $OUTPUT, $CFG;
|
||||
|
||||
$editor = $this->wikiformat;
|
||||
|
||||
@ -81,6 +87,9 @@ class MoodleQuickForm_wikieditor extends MoodleQuickForm_textarea {
|
||||
$tag = $this->getTokens($editor, 'italic');
|
||||
$wiki_editor['italic'] = array('ed_italic.gif', get_string('wikiitalictext', 'wiki'), $tag[0], $tag[1], get_string('wikiitalictext', 'wiki'));
|
||||
|
||||
$imagetag = $this->getTokens($editor, 'image');
|
||||
$wiki_editor['image'] = array('ed_img.gif', get_string('wikiimage', 'wiki'), $imagetag[0], $imagetag[1], get_string('wikiimage', 'wiki'));
|
||||
|
||||
$tag = $this->getTokens($editor, 'link');
|
||||
$wiki_editor['internal'] = array('ed_internal.gif', get_string('wikiinternalurl', 'wiki'), $tag[0], $tag[1], get_string('wikiinternalurl', 'wiki'));
|
||||
|
||||
@ -91,9 +100,6 @@ class MoodleQuickForm_wikieditor extends MoodleQuickForm_textarea {
|
||||
$wiki_editor['u_list'] = array('ed_ul.gif', get_string('wikiunorderedlist', 'wiki'), '\\n'.$tag[0], '', '');
|
||||
$wiki_editor['o_list'] = array('ed_ol.gif', get_string('wikiorderedlist', 'wiki'), '\\n'.$tag[1], '', '');
|
||||
|
||||
$tag = $this->getTokens($editor, 'image');
|
||||
$wiki_editor['image'] = array('ed_img.gif', get_string('wikiimage', 'wiki'), $tag[0], $tag[1], get_string('wikiimage', 'wiki'));
|
||||
|
||||
$tag = $this->getTokens($editor, 'header');
|
||||
$wiki_editor['h1'] = array('ed_h1.gif', get_string('wikiheader', 'wiki', 1), '\\n'.$tag.' ', ' '.$tag.'\\n', get_string('wikiheader', 'wiki', 1));
|
||||
$wiki_editor['h2'] = array('ed_h2.gif', get_string('wikiheader', 'wiki', 2), '\\n'.$tag.$tag.' ', ' '.$tag.$tag.'\\n', get_string('wikiheader', 'wiki', 2));
|
||||
@ -107,13 +113,23 @@ class MoodleQuickForm_wikieditor extends MoodleQuickForm_textarea {
|
||||
|
||||
$PAGE->requires->js('/mod/wiki/editors/wiki/buttons.js');
|
||||
|
||||
$html = "";
|
||||
$html = '<div class="wikieditor-toolbar">';
|
||||
foreach ($wiki_editor as $button) {
|
||||
$html .= "<a href=\"javascript:insertTags";
|
||||
$html .= "('".$button[2]."','".$button[3]."','".$button[4]."');\">";
|
||||
$html .= "<img width=\"23\" height=\"22\" src=\"$CFG->wwwroot/mod/wiki/editors/wiki/images/$button[0]\" alt=\"".$button[1]."\" title=\"".$button[1]."\" />";
|
||||
$html .= html_writer::empty_tag('img', array('alt' => $button[1], 'src' => $CFG->wwwroot . '/mod/wiki/editors/wiki/images/' . $button[0]));
|
||||
$html .= "</a>";
|
||||
}
|
||||
$html .= "<select onchange=\"insertTags('{$imagetag[0]}', '{$imagetag[1]}', this.value)\">";
|
||||
$html .= "<option value='" . s(get_string('wikiimage', 'wiki')) . "'>" . get_string('insertimage', 'wiki') . '</option>';
|
||||
foreach ($this->files as $filename) {
|
||||
$html .= "<option value='".s($filename)."'>";
|
||||
$html .= $filename;
|
||||
$html .= '</option>';
|
||||
}
|
||||
$html .= '</select>';
|
||||
$html .= $OUTPUT->help_icon('insertimage', 'wiki');
|
||||
$html .= '</div>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
107
mod/wiki/files.php
Normal file
107
mod/wiki/files.php
Normal file
@ -0,0 +1,107 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Wiki files management
|
||||
*
|
||||
* @package mod-wiki-2.0
|
||||
* @copyrigth 2011 Dongsheng Cai <dongsheng@moodle.com>
|
||||
*
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once('../../config.php');
|
||||
require_once($CFG->dirroot . '/mod/wiki/lib.php');
|
||||
require_once($CFG->dirroot . '/mod/wiki/locallib.php');
|
||||
|
||||
$pageid = required_param('pageid', PARAM_INT); // Page ID
|
||||
$wid = optional_param('wid', 0, PARAM_INT); // Wiki ID
|
||||
$currentgroup = optional_param('group', 0, PARAM_INT); // Group ID
|
||||
$userid = optional_param('uid', 0, PARAM_INT); // User ID
|
||||
$groupanduser = optional_param('groupanduser', null, PARAM_TEXT);
|
||||
|
||||
if (!$page = wiki_get_page($pageid)) {
|
||||
print_error('incorrectpageid', 'wiki');
|
||||
}
|
||||
|
||||
if ($groupanduser) {
|
||||
list($currentgroup, $userid) = explode('-', $groupanduser);
|
||||
$currentgroup = clean_param($currentgroup, PARAM_INT);
|
||||
$userid = clean_param($userid, PARAM_INT);
|
||||
}
|
||||
|
||||
if ($wid) {
|
||||
// in group mode
|
||||
if (!$wiki = wiki_get_wiki($wid)) {
|
||||
print_error('incorrectwikiid', 'wiki');
|
||||
}
|
||||
if (!$subwiki = wiki_get_subwiki_by_group($wiki->id, $currentgroup, $userid)) {
|
||||
// create subwiki if doesn't exist
|
||||
$subwikiid = wiki_add_subwiki($wiki->id, $currentgroup, $userid);
|
||||
$subwiki = wiki_get_subwiki($subwikiid);
|
||||
}
|
||||
} else {
|
||||
// no group
|
||||
if (!$subwiki = wiki_get_subwiki($page->subwikiid)) {
|
||||
print_error('incorrectsubwikiid', 'wiki');
|
||||
}
|
||||
|
||||
// Checking wiki instance of that subwiki
|
||||
if (!$wiki = wiki_get_wiki($subwiki->wikiid)) {
|
||||
print_error('incorrectwikiid', 'wiki');
|
||||
}
|
||||
}
|
||||
|
||||
// Checking course module instance
|
||||
if (!$cm = get_coursemodule_from_instance("wiki", $subwiki->wikiid)) {
|
||||
print_error('invalidcoursemodule');
|
||||
}
|
||||
|
||||
// Checking course instance
|
||||
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
|
||||
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
|
||||
|
||||
$PAGE->set_url('/mod/wiki/files.php', array('pageid'=>$pageid));
|
||||
require_login($course, true, $cm);
|
||||
$PAGE->set_context($context);
|
||||
$PAGE->set_title(get_string('wikifiles', 'wiki'));
|
||||
$PAGE->set_heading(get_string('wikifiles', 'wiki'));
|
||||
$PAGE->navbar->add(format_string(get_string('wikifiles', 'wiki')));
|
||||
echo $OUTPUT->header();
|
||||
|
||||
$renderer = $PAGE->get_renderer('mod_wiki');
|
||||
|
||||
$tabitems = array('view' => 'view', 'edit' => 'edit', 'comments' => 'comments', 'history' => 'history', 'map' => 'map', 'files' => 'files');
|
||||
|
||||
$options = array('activetab'=>'files');
|
||||
echo $renderer->tabs($page, $tabitems, $options);
|
||||
|
||||
|
||||
echo $OUTPUT->box_start('generalbox');
|
||||
if (has_capability('mod/wiki:viewpage', $context)) {
|
||||
echo $renderer->wiki_print_subwiki_selector($PAGE->activityrecord, $subwiki, $page, 'files');
|
||||
echo $renderer->wiki_files_tree($context, $subwiki);
|
||||
} else {
|
||||
echo $OUTPUT->notification(get_string('cannotviewfiles', 'wiki'));
|
||||
}
|
||||
echo $OUTPUT->box_end();
|
||||
|
||||
if (has_capability('mod/wiki:managefiles', $context)) {
|
||||
echo $OUTPUT->single_button(new moodle_url('/mod/wiki/filesedit.php', array('subwiki'=>$subwiki->id, 'pageid'=>$pageid)), get_string('editfiles', 'wiki'), 'get');
|
||||
}
|
||||
echo $OUTPUT->footer();
|
97
mod/wiki/filesedit.php
Normal file
97
mod/wiki/filesedit.php
Normal file
@ -0,0 +1,97 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Manage files in wiki
|
||||
*
|
||||
* @package mod-wiki-2.0
|
||||
* @copyright 2011 Dongsheng Cai <dongsheng@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
|
||||
require_once('lib.php');
|
||||
require_once('locallib.php');
|
||||
require_once("$CFG->dirroot/mod/wiki/filesedit_form.php");
|
||||
require_once("$CFG->dirroot/repository/lib.php");
|
||||
|
||||
$subwikiid = required_param('subwiki', PARAM_INT);
|
||||
// not being used for file management, we use it to generate navbar link
|
||||
$pageid = optional_param('pageid', 0, PARAM_INT);
|
||||
$returnurl = optional_param('returnurl', '', PARAM_URL);
|
||||
|
||||
if (!$subwiki = wiki_get_subwiki($subwikiid)) {
|
||||
print_error('incorrectsubwikiid', 'wiki');
|
||||
}
|
||||
|
||||
// Checking wiki instance of that subwiki
|
||||
if (!$wiki = wiki_get_wiki($subwiki->wikiid)) {
|
||||
print_error('incorrectwikiid', 'wiki');
|
||||
}
|
||||
|
||||
// Checking course module instance
|
||||
if (!$cm = get_coursemodule_from_instance("wiki", $subwiki->wikiid)) {
|
||||
print_error('invalidcoursemodule');
|
||||
}
|
||||
|
||||
// Checking course instance
|
||||
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
|
||||
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
|
||||
require_login($course, true, $cm);
|
||||
require_capability('mod/wiki:managefiles', $context);
|
||||
|
||||
if (empty($returnurl)) {
|
||||
if (!empty($_SERVER["HTTP_REFERER"])) {
|
||||
$returnurl = $_SERVER["HTTP_REFERER"];
|
||||
} else {
|
||||
$returnurl = new moodle_url('/mod/wiki/files.php', array('subwiki'=>$subwiki->id));
|
||||
}
|
||||
}
|
||||
|
||||
$title = get_string('editfiles', 'wiki');
|
||||
|
||||
$struser = get_string('user');
|
||||
$url = new moodle_url('/mod/wiki/filesedit.php', array('subwiki'=>$subwiki->id, 'pageid'=>$pageid));
|
||||
$PAGE->set_url($url);
|
||||
$PAGE->set_context($context);
|
||||
$PAGE->set_title($title);
|
||||
$PAGE->set_heading($title);
|
||||
$PAGE->navbar->add(format_string(get_string('wikifiles', 'wiki')), $CFG->wwwroot . '/mod/wiki/files.php?pageid=' . $pageid);
|
||||
$PAGE->navbar->add(format_string($title));
|
||||
|
||||
$data = new stdClass();
|
||||
$data->returnurl = $returnurl;
|
||||
$data->subwikiid = $subwiki->id;
|
||||
$maxbytes = get_max_upload_file_size($CFG->maxbytes, $COURSE->maxbytes);
|
||||
$options = array('subdirs'=>0, 'maxbytes'=>$maxbytes, 'maxfiles'=>-1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
|
||||
file_prepare_standard_filemanager($data, 'files', $options, $context, 'mod_wiki', 'attachments', $subwiki->id);
|
||||
|
||||
$mform = new mod_wiki_filesedit_form(null, array('data'=>$data, 'options'=>$options));
|
||||
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect($returnurl);
|
||||
} else if ($formdata = $mform->get_data()) {
|
||||
$formdata = file_postupdate_standard_filemanager($formdata, 'files', $options, $context, 'mod_wiki', 'attachments', $subwiki->id);
|
||||
redirect($returnurl);
|
||||
}
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->box_start('generalbox');
|
||||
$mform->display();
|
||||
echo $OUTPUT->box_end();
|
||||
echo $OUTPUT->footer();
|
44
mod/wiki/filesedit_form.php
Normal file
44
mod/wiki/filesedit_form.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Edit wiki files form
|
||||
*
|
||||
* @package mod-wiki-2.0
|
||||
* @copyright 2011 Dongsheng Cai <dongsheng@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once("$CFG->libdir/formslib.php");
|
||||
|
||||
class mod_wiki_filesedit_form extends moodleform {
|
||||
function definition() {
|
||||
$mform = $this->_form;
|
||||
|
||||
$data = $this->_customdata['data'];
|
||||
$options = $this->_customdata['options'];
|
||||
|
||||
$mform->addElement('filemanager', 'files_filemanager', get_string('files'), null, $options);
|
||||
$mform->addElement('hidden', 'returnurl', $data->returnurl);
|
||||
$mform->addElement('hidden', 'subwiki', $data->subwikiid);
|
||||
|
||||
$this->add_action_buttons(true, get_string('savechanges'));
|
||||
|
||||
$this->set_data($data);
|
||||
}
|
||||
}
|
@ -58,7 +58,9 @@ if (!$cm = get_coursemodule_from_instance('wiki', $wiki->id)) {
|
||||
|
||||
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
|
||||
|
||||
require_course_login($course->id, true, $cm);
|
||||
require_login($course->id, true, $cm);
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
require_capability('mod/wiki:viewpage', $context);
|
||||
add_to_log($course->id, 'wiki', 'history', 'history.php?id=' . $cm->id, $wiki->id);
|
||||
|
||||
/// Print the page header
|
||||
|
@ -41,7 +41,7 @@ if (!$course = $DB->get_record('course', array('id' => $id))) {
|
||||
print_error('invalidcourseid');
|
||||
}
|
||||
|
||||
require_course_login($course->id, true);
|
||||
require_login($course->id, true);
|
||||
$PAGE->set_pagelayout('incourse');
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
|
||||
|
@ -19,7 +19,11 @@ $string['backhistory'] = 'Back to history';
|
||||
$string['backoldversion'] = 'Back to old version';
|
||||
$string['backpage'] = 'Back to page';
|
||||
$string['backtomapmenu'] = 'Back to map menu';
|
||||
$string['changerate']='Do you wish to change it?';
|
||||
$string['changerate'] = 'Do you wish to change it?';
|
||||
$string['insertimage'] = 'Insert an image...';
|
||||
$string['insertimage_help'] = 'This drop-down list will insert an image to the wiki editor. If you need to add more images to the wiki, please use "Files" tab.';
|
||||
$string['cannotmanagefiles'] = 'You don\'t have permission to manage the wiki files.';
|
||||
$string['cannotviewfiles'] = 'You don\'t have permission to view the wiki files.';
|
||||
$string['comparesel'] = 'Compare selected';
|
||||
$string['comments'] = 'Comments';
|
||||
$string['commentscount'] = 'Comments ({$a})';
|
||||
@ -48,9 +52,11 @@ $string['diff_help'] = 'Selected versions of the page may be compared in order t
|
||||
$string['edit'] = 'Edit';
|
||||
$string['editcomment'] = 'Edit comment';
|
||||
$string['editblocks'] = 'Turn edit blocks on';
|
||||
$string['editfiles'] = 'Edit wiki files';
|
||||
$string['editing'] = 'Editing wiki page';
|
||||
$string['editingcomment'] = 'Editing comment';
|
||||
$string['editingpage'] = 'Editing this page \'{$a}\'';
|
||||
$string['files'] = 'Files';
|
||||
$string['filenotuploadederror'] = 'File \'{$a}\' could not be uploaded correctly.';
|
||||
$string['filtername'] = 'Wiki auto-linking';
|
||||
$string['firstpagetitle'] = 'First page name';
|
||||
@ -187,6 +193,7 @@ $string['wikiattachments'] = 'Wiki attachments';
|
||||
$string['wikiboldtext'] = 'Bold text';
|
||||
$string['wikiexternalurl'] = 'External URL';
|
||||
$string['wikifiletable'] = 'Uploaded file list';
|
||||
$string['wikifiles'] = 'Wiki files';
|
||||
$string['wikiheader'] = 'Level {$a} Header';
|
||||
$string['wikihr'] = 'Horizontal rule';
|
||||
$string['wikiimage'] = 'Image';
|
||||
@ -208,6 +215,7 @@ $string['wiki:editcomment'] = 'Add comments to pages';
|
||||
$string['wiki:editpage'] = 'Save wiki pages';
|
||||
$string['wiki:managecomment'] = 'Manage wiki comments';
|
||||
$string['wiki:managewiki'] = 'Manage wiki settings';
|
||||
$string['wiki:managefiles'] = 'Manage wiki files';
|
||||
$string['wiki:overridelock'] = 'Override wiki locks';
|
||||
$string['wiki:viewcomment'] = 'View page comments';
|
||||
$string['wiki:viewpage'] = 'View wiki pages';
|
||||
|
@ -445,7 +445,7 @@ function wiki_pluginfile($course, $cm, $context, $filearea, $args, $forcedownloa
|
||||
return false;
|
||||
}
|
||||
|
||||
require_course_login($course, true, $cm);
|
||||
require_login($course, true, $cm);
|
||||
|
||||
require_once($CFG->dirroot . "/mod/wiki/locallib.php");
|
||||
|
||||
@ -495,6 +495,7 @@ function wiki_extend_navigation(navigation_node $navref, $course, $module, $cm)
|
||||
|
||||
require_once($CFG->dirroot . '/mod/wiki/locallib.php');
|
||||
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
$url = $PAGE->url;
|
||||
$userid = 0;
|
||||
if ($module->wikimode == 'individual') {
|
||||
@ -521,25 +522,43 @@ function wiki_extend_navigation(navigation_node $navref, $course, $module, $cm)
|
||||
$page = wiki_get_page_by_title($swid, $wiki->firstpagetitle);
|
||||
$pageid = $page->id;
|
||||
}
|
||||
$link = new moodle_url('/mod/wiki/create.php', array('action' => 'new', 'swid' => $swid));
|
||||
$node = $navref->add(get_string('newpage', 'wiki'), $link, navigation_node::TYPE_SETTING);
|
||||
|
||||
if (has_capability('mod/wiki:createpage', $context)) {
|
||||
$link = new moodle_url('/mod/wiki/create.php', array('action' => 'new', 'swid' => $swid));
|
||||
$node = $navref->add(get_string('newpage', 'wiki'), $link, navigation_node::TYPE_SETTING);
|
||||
}
|
||||
|
||||
if (is_numeric($pageid)) {
|
||||
|
||||
$link = new moodle_url('/mod/wiki/view.php', array('pageid' => $pageid));
|
||||
$node = $navref->add(get_string('view', 'wiki'), $link, navigation_node::TYPE_SETTING);
|
||||
if (has_capability('mod/wiki:viewpage', $context)) {
|
||||
$link = new moodle_url('/mod/wiki/view.php', array('pageid' => $pageid));
|
||||
$node = $navref->add(get_string('view', 'wiki'), $link, navigation_node::TYPE_SETTING);
|
||||
}
|
||||
|
||||
$link = new moodle_url('/mod/wiki/edit.php', array('pageid' => $pageid));
|
||||
$node = $navref->add(get_string('edit', 'wiki'), $link, navigation_node::TYPE_SETTING);
|
||||
if (has_capability('mod/wiki:editpage', $context)) {
|
||||
$link = new moodle_url('/mod/wiki/edit.php', array('pageid' => $pageid));
|
||||
$node = $navref->add(get_string('edit', 'wiki'), $link, navigation_node::TYPE_SETTING);
|
||||
}
|
||||
|
||||
$link = new moodle_url('/mod/wiki/comments.php', array('pageid' => $pageid));
|
||||
$node = $navref->add(get_string('comments', 'wiki'), $link, navigation_node::TYPE_SETTING);
|
||||
if (has_capability('mod/wiki:viewcomment', $context)) {
|
||||
$link = new moodle_url('/mod/wiki/comments.php', array('pageid' => $pageid));
|
||||
$node = $navref->add(get_string('comments', 'wiki'), $link, navigation_node::TYPE_SETTING);
|
||||
}
|
||||
|
||||
$link = new moodle_url('/mod/wiki/history.php', array('pageid' => $pageid));
|
||||
$node = $navref->add(get_string('history', 'wiki'), $link, navigation_node::TYPE_SETTING);
|
||||
if (has_capability('mod/wiki:viewpage', $context)) {
|
||||
$link = new moodle_url('/mod/wiki/history.php', array('pageid' => $pageid));
|
||||
$node = $navref->add(get_string('history', 'wiki'), $link, navigation_node::TYPE_SETTING);
|
||||
}
|
||||
|
||||
$link = new moodle_url('/mod/wiki/map.php', array('pageid' => $pageid));
|
||||
$node = $navref->add(get_string('map', 'wiki'), $link, navigation_node::TYPE_SETTING);
|
||||
if (has_capability('mod/wiki:viewpage', $context)) {
|
||||
$link = new moodle_url('/mod/wiki/map.php', array('pageid' => $pageid));
|
||||
$node = $navref->add(get_string('map', 'wiki'), $link, navigation_node::TYPE_SETTING);
|
||||
}
|
||||
|
||||
if (has_capability('mod/wiki:viewpage', $context)) {
|
||||
$link = new moodle_url('/mod/wiki/files.php', array('pageid' => $pageid));
|
||||
$node = $navref->add(get_string('files', 'wiki'), $link, navigation_node::TYPE_SETTING);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
@ -578,7 +578,21 @@ function wiki_parse_content($markup, $pagecontent, $options = array()) {
|
||||
$cm = get_coursemodule_from_instance("wiki", $subwiki->wikiid);
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
|
||||
$parser_options = array('link_callback' => '/mod/wiki/locallib.php:wiki_parser_link', 'link_callback_args' => array('swid' => $options['swid']), 'table_callback' => '/mod/wiki/locallib.php:wiki_parser_table', 'real_path_callback' => '/mod/wiki/locallib.php:wiki_parser_real_path', 'real_path_callback_args' => array('context' => $context, 'component' => 'mod_wiki', 'filearea' => 'attachments', 'pageid' => $options['pageid']), 'pageid' => $options['pageid'], 'pretty_print' => (isset($options['pretty_print']) && $options['pretty_print']), 'printable' => (isset($options['printable']) && $options['printable']));
|
||||
$parser_options = array('link_callback' => '/mod/wiki/locallib.php:wiki_parser_link',
|
||||
'link_callback_args' => array('swid' => $options['swid']),
|
||||
'table_callback' => '/mod/wiki/locallib.php:wiki_parser_table',
|
||||
'real_path_callback' => '/mod/wiki/locallib.php:wiki_parser_real_path',
|
||||
'real_path_callback_args' => array(
|
||||
'context' => $context,
|
||||
'component' => 'mod_wiki',
|
||||
'filearea' => 'attachments',
|
||||
'subwikiid'=> $subwiki->id,
|
||||
'pageid' => $options['pageid']
|
||||
),
|
||||
'pageid' => $options['pageid'],
|
||||
'pretty_print' => (isset($options['pretty_print']) && $options['pretty_print']),
|
||||
'printable' => (isset($options['printable']) && $options['printable'])
|
||||
);
|
||||
|
||||
return wiki_parser_proxy::parse($pagecontent, $markup, $parser_options);
|
||||
}
|
||||
@ -661,7 +675,7 @@ function wiki_parser_table($table) {
|
||||
/**
|
||||
* Returns an absolute path link, unless there is no such link.
|
||||
*
|
||||
* @param string url Link's URL
|
||||
* @param string url Link's URL or filename
|
||||
* @param stdClass context filearea params
|
||||
* @param string filearea
|
||||
* @param int fileareaid
|
||||
@ -669,13 +683,20 @@ function wiki_parser_table($table) {
|
||||
* @return File full path
|
||||
*/
|
||||
|
||||
function wiki_parser_real_path($url, $context, $filearea, $fileareaid) {
|
||||
function wiki_parser_real_path($url, $context, $component, $filearea, $swid) {
|
||||
global $CFG;
|
||||
|
||||
if (preg_match("/^(?:http|ftp)s?\:\/\//", $url)) {
|
||||
return $url;
|
||||
} else {
|
||||
return "{$CFG->wwwroot}/pluginfile.php/{$context->id}/$filearea/$fileareaid/$url";
|
||||
|
||||
$file = 'pluginfile.php';
|
||||
if (!$CFG->slasharguments) {
|
||||
$file = $file . '?file=';
|
||||
}
|
||||
$baseurl = "$CFG->wwwroot/$file/{$context->id}/$component/$filearea/$swid/";
|
||||
// it is a file in current file area
|
||||
return $baseurl . $url;
|
||||
}
|
||||
}
|
||||
|
||||
@ -995,85 +1016,6 @@ function wiki_delete_old_locks() {
|
||||
$DB->delete_records_select('wiki_locks', "lockedat < ?", array(time() - 3600));
|
||||
}
|
||||
|
||||
/**
|
||||
* File processing
|
||||
*/
|
||||
|
||||
/**
|
||||
* Uploads files to permanent disk space.
|
||||
*
|
||||
* @param int draftitemid Draft space ID
|
||||
* @param int contextid
|
||||
*
|
||||
* @return array of files that have not been inserted.
|
||||
*/
|
||||
|
||||
function wiki_process_attachments($draftitemid, $deleteuploads, $contextid, $filearea, $itemid, $options = null) {
|
||||
global $CFG, $USER;
|
||||
|
||||
if (empty($options)) {
|
||||
$options = page_wiki_edit::$attachmentoptions;
|
||||
}
|
||||
|
||||
$errors = array();
|
||||
|
||||
$usercontext = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$fs = get_file_storage();
|
||||
|
||||
$oldfiles = $fs->get_area_files($contextid, 'mod_wiki', 'attachments', $itemid, 'id');
|
||||
|
||||
foreach ($oldfiles as $file) {
|
||||
if (in_array($file->get_pathnamehash(), $deleteuploads)) {
|
||||
$file->delete();
|
||||
}
|
||||
}
|
||||
|
||||
$draftfiles = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid, 'id');
|
||||
$oldfiles = $fs->get_area_files($contextid, 'mod_wiki', 'attachments', $itemid, 'id');
|
||||
|
||||
$file_record = array('contextid' => $contextid, 'component' => 'mod_wiki', 'filearea' => 'attachments', 'itemid' => $itemid);
|
||||
//more or less a merge...
|
||||
$newhashes = array();
|
||||
foreach ($draftfiles as $file) {
|
||||
$newhash = sha1("/$contextid/mod_wiki/attachments/$itemid" . $file->get_filepath() . $file->get_filename());
|
||||
$newhashes[$newhash] = $file;
|
||||
}
|
||||
|
||||
$filecount = 0;
|
||||
foreach ($oldfiles as $file) {
|
||||
$oldhash = $file->get_pathnamehash();
|
||||
if (!$file->is_directory() && isset($newhashes[$oldhash])) {
|
||||
//repeated file: ERROR!!!
|
||||
unset($newhashes[$oldhash]);
|
||||
$errors[] = $file;
|
||||
}
|
||||
|
||||
if (!$file->is_directory()) {
|
||||
$filecount++;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($newhashes as $file) {
|
||||
if ($file->get_filepath() !== '/' or $file->is_directory()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($options['maxfiles'] and $options['maxfiles'] <= $filecount) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!$file->is_directory()) {
|
||||
$filecount++;
|
||||
$fs->create_file_from_storedfile($file_record, $file);
|
||||
}
|
||||
}
|
||||
|
||||
//delete all draft files
|
||||
$fs->delete_area_files($usercontext->id, 'user', 'draft', $draftitemid);
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
function wiki_get_comment($commentid){
|
||||
global $DB;
|
||||
return $DB->get_record('comments', array('id' => $commentid));
|
||||
|
@ -66,7 +66,7 @@ if (!empty($section) && !$sectioncontent = wiki_get_section_page($page, $section
|
||||
print_error('invalidsection', 'wiki');
|
||||
}
|
||||
|
||||
require_course_login($course->id, false, $cm);
|
||||
require_login($course->id, false, $cm);
|
||||
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
require_capability('mod/wiki:editpage', $context);
|
||||
|
@ -53,8 +53,9 @@ if (!$wiki = wiki_get_wiki($subwiki->wikiid)) {
|
||||
print_error('incorrectwikiid', 'wiki');
|
||||
}
|
||||
|
||||
require_course_login($course->id, true, $cm);
|
||||
|
||||
require_login($course->id, true, $cm);
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
require_capability('mod/wiki:viewpage', $context);
|
||||
add_to_log($course->id, "wiki", "map", "map.php?id=$cm->id", "$wiki->id");
|
||||
|
||||
/// Print page header
|
||||
|
@ -76,3 +76,20 @@ M.mod_wiki.history = function(Y, args) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
M.mod_wiki.init_tree = function(Y, expand_all, htmlid) {
|
||||
Y.use('yui2-treeview', function(Y) {
|
||||
var tree = new YAHOO.widget.TreeView(htmlid);
|
||||
|
||||
tree.subscribe("clickEvent", function(node, event) {
|
||||
// we want normal clicking which redirects to url
|
||||
return false;
|
||||
});
|
||||
|
||||
if (expand_all) {
|
||||
tree.expandAll();
|
||||
}
|
||||
|
||||
tree.render();
|
||||
});
|
||||
};
|
||||
|
@ -39,7 +39,6 @@ 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 {
|
||||
@ -77,7 +76,7 @@ abstract class page_wiki {
|
||||
* @var array The tabs set used in wiki module
|
||||
*/
|
||||
protected $tabs = array('view' => 'view', 'edit' => 'edit', 'comments' => 'comments',
|
||||
'history' => 'history', 'map' => 'map');
|
||||
'history' => 'history', 'map' => 'map', 'files' => 'files');
|
||||
/**
|
||||
* @var array tabs options
|
||||
*/
|
||||
@ -269,7 +268,6 @@ abstract class page_wiki {
|
||||
/**
|
||||
* 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 {
|
||||
@ -283,7 +281,7 @@ class page_wiki_view extends page_wiki {
|
||||
|
||||
parent::print_header();
|
||||
|
||||
$this->wikioutput->wiki_print_subwiki_selector($PAGE->activityrecord, $this->subwiki, $this->page);
|
||||
$this->wikioutput->wiki_print_subwiki_selector($PAGE->activityrecord, $this->subwiki, $this->page, 'view');
|
||||
|
||||
if (!empty($this->page)) {
|
||||
echo $this->wikioutput->prettyview_link($this->page);
|
||||
@ -352,7 +350,6 @@ class page_wiki_view extends page_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 {
|
||||
@ -541,16 +538,14 @@ class page_wiki_edit extends page_wiki {
|
||||
$data = file_prepare_standard_editor($data, 'newcontent', page_wiki_edit::$attachmentoptions, $this->modcontext, 'mod_wiki', 'attachments', $this->subwiki->id);
|
||||
break;
|
||||
default:
|
||||
//$draftitemid = file_get_submitted_draft_itemid('attachments');
|
||||
//file_prepare_draft_area($draftitemid, $this->modcontext->id, 'mod_wiki', 'attachments', $this->subwiki->id);
|
||||
//$data->attachments = $draftitemid;
|
||||
break;
|
||||
}
|
||||
|
||||
if ($version->contentformat != 'html') {
|
||||
$params['contextid'] = $this->modcontext->id;
|
||||
$params['component'] = 'mod_wiki';
|
||||
$params['filearea'] = 'attachments';
|
||||
$params['fileitemid'] = $this->subwiki->id;
|
||||
$params['contextid'] = $this->modcontext->id;
|
||||
$params['component'] = 'mod_wiki';
|
||||
$params['filearea'] = 'attachments';
|
||||
}
|
||||
|
||||
if (!empty($CFG->usetags)) {
|
||||
@ -560,16 +555,6 @@ class page_wiki_edit extends page_wiki {
|
||||
$form = new mod_wiki_edit_form($url, $params);
|
||||
|
||||
if ($formdata = $form->get_data()) {
|
||||
if ($format != 'html') {
|
||||
$errors = $this->process_uploads($this->modcontext);
|
||||
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;
|
||||
}
|
||||
@ -583,21 +568,11 @@ class page_wiki_edit extends page_wiki {
|
||||
$form->display();
|
||||
}
|
||||
|
||||
protected function process_uploads($context) {
|
||||
global $PAGE, $OUTPUT;
|
||||
|
||||
if ($this->upload) {
|
||||
file_save_draft_area_files($this->attachments, $context->id, 'mod_wiki', 'attachments', $this->subwiki->id);
|
||||
return null;
|
||||
//return wiki_process_attachments($this->attachments, $this->deleteuploads, $context->id, 'mod_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 {
|
||||
@ -715,7 +690,6 @@ class page_wiki_comments extends page_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 {
|
||||
@ -817,7 +791,6 @@ class page_wiki_editcomment extends page_wiki {
|
||||
/**
|
||||
* 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 {
|
||||
@ -1939,10 +1912,10 @@ class page_wiki_save extends page_wiki_edit {
|
||||
$params = array('attachmentoptions' => page_wiki_edit::$attachmentoptions, 'format' => $this->format, 'version' => $this->versionnumber);
|
||||
|
||||
if ($this->format != 'html') {
|
||||
$params['contextid'] = $this->modcontext->id;
|
||||
$params['component'] = 'mod_wiki';
|
||||
$params['filearea'] = 'attachments';
|
||||
$params['fileitemid'] = $this->page->id;
|
||||
$params['contextid'] = $context->id;
|
||||
$params['component'] = 'mod_wiki';
|
||||
$params['filearea'] = 'attachments';
|
||||
}
|
||||
|
||||
$form = new mod_wiki_edit_form($url, $params);
|
||||
@ -1962,9 +1935,6 @@ class page_wiki_save extends page_wiki_edit {
|
||||
}
|
||||
|
||||
if ($save && $data) {
|
||||
if ($this->format != 'html') {
|
||||
$errors = $this->process_uploads($this->modcontext);
|
||||
}
|
||||
if (!empty($CFG->usetags)) {
|
||||
tag_set('wiki_pages', $this->page->id, $data->tags);
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ if (!$wiki = wiki_get_wiki($subwiki->wikiid)) {
|
||||
print_error('incorrectwikiid', 'wiki');
|
||||
}
|
||||
|
||||
require_course_login($course->id, true, $cm);
|
||||
require_login($course->id, true, $cm);
|
||||
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
require_capability('mod/wiki:viewpage', $context);
|
||||
|
@ -134,7 +134,7 @@ class mod_wiki_renderer extends plugin_renderer_base {
|
||||
$newheading .= $this->output->container_end();
|
||||
|
||||
$oldheading = html_writer::tag('div', $oldheading, array('class'=>'wiki-diff-heading header clearfix'));
|
||||
$newheading = html_writer::tag('div', $newheading, array('class'=>'wiki-diff-heading header clearfix'));
|
||||
$newheading = html_writer::tag('div', $newheading, array('class'=>'wiki-diff-heading header clearfix'));
|
||||
|
||||
$output = '';
|
||||
$output .= html_writer::start_tag('div', array('class'=>'wiki-diff-container clearfix'));
|
||||
@ -238,16 +238,15 @@ class mod_wiki_renderer extends plugin_renderer_base {
|
||||
global $PAGE;
|
||||
return $this->output->box(format_module_intro('wiki', $this->page->activityrecord, $PAGE->cm->id), 'generalbox', 'intro');
|
||||
}
|
||||
|
||||
public function tabs($page, $tabitems, $options) {
|
||||
global $CFG;
|
||||
if (empty($page)) {
|
||||
return null;
|
||||
}
|
||||
$tabs = array();
|
||||
$baseurl = $CFG->wwwroot . '/mod/wiki/';
|
||||
$context = get_context_instance(CONTEXT_MODULE, $this->page->cm->id);
|
||||
|
||||
$pageid = null;
|
||||
if (isset($page)) {
|
||||
if (!empty($page)) {
|
||||
$pageid = $page->id;
|
||||
}
|
||||
|
||||
@ -267,6 +266,18 @@ class mod_wiki_renderer extends plugin_renderer_base {
|
||||
}
|
||||
|
||||
foreach ($tabitems as $tab) {
|
||||
if ($tab == 'edit' && !has_capability('mod/wiki:editpage', $context)) {
|
||||
continue;
|
||||
}
|
||||
if ($tab == 'comments' && !has_capability('mod/wiki:viewcomment', $context)) {
|
||||
continue;
|
||||
}
|
||||
if ($tab == 'files' && !has_capability('mod/wiki:viewpage', $context)) {
|
||||
continue;
|
||||
}
|
||||
if (($tab == 'view' || $tab == 'map' || $tab == 'history') && !has_capability('mod/wiki:viewpage', $context)) {
|
||||
continue;
|
||||
}
|
||||
$link = $baseurl . $tab . '.php?pageid=' . $pageid;
|
||||
if ($linked == $tab) {
|
||||
$tabs[] = new tabobject($tab, $link, get_string($tab, 'wiki'), '', true);
|
||||
@ -287,9 +298,19 @@ class mod_wiki_renderer extends plugin_renderer_base {
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function wiki_print_subwiki_selector($wiki, $subwiki, $page) {
|
||||
public function wiki_print_subwiki_selector($wiki, $subwiki, $page, $pagetype) {
|
||||
global $CFG, $USER;
|
||||
require_once($CFG->dirroot . '/user/lib.php');
|
||||
switch ($pagetype) {
|
||||
case 'view':
|
||||
$baseurl = new moodle_url('/mod/wiki/view.php');
|
||||
break;
|
||||
case 'files':
|
||||
$baseurl = new moodle_url('/mod/wiki/files.php');
|
||||
break;
|
||||
default:
|
||||
$baseurl = null;
|
||||
}
|
||||
|
||||
$cm = get_coursemodule_from_instance('wiki', $wiki->id);
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
@ -317,10 +338,13 @@ class mod_wiki_renderer extends plugin_renderer_base {
|
||||
|
||||
echo $this->output->container_start('wiki_right');
|
||||
$params = array('wid' => $wiki->id, 'title' => $page->title);
|
||||
$url = new moodle_url('/mod/wiki/view.php', $params);
|
||||
if ($pagetype == 'files') {
|
||||
$params['pageid'] = $page->id;
|
||||
}
|
||||
$baseurl->params($params);
|
||||
$name = 'uid';
|
||||
$selected = $subwiki->userid;
|
||||
echo $this->output->single_select($url, $name, $options, $selected);
|
||||
echo $this->output->single_select($baseurl, $name, $options, $selected);
|
||||
echo $this->output->container_end();
|
||||
}
|
||||
return;
|
||||
@ -332,10 +356,14 @@ class mod_wiki_renderer extends plugin_renderer_base {
|
||||
if ($wiki->wikimode == 'collaborative') {
|
||||
// We need to print a select to choose a course group
|
||||
|
||||
$params = 'wid=' . $wiki->id . '&title=' . urlencode($page->title);
|
||||
$params = array('wid'=>$wiki->id, 'title'=>$page->title);
|
||||
if ($pagetype == 'files') {
|
||||
$params['pageid'] = $page->id;
|
||||
}
|
||||
$baseurl->params($params);
|
||||
|
||||
echo $this->output->container_start('wiki_right');
|
||||
groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/wiki/view.php?' . $params);
|
||||
groups_print_activity_menu($cm, $baseurl->out());
|
||||
echo $this->output->container_end();
|
||||
return;
|
||||
} else if ($wiki->wikimode == 'individual') {
|
||||
@ -367,10 +395,13 @@ class mod_wiki_renderer extends plugin_renderer_base {
|
||||
}
|
||||
echo $this->output->container_start('wiki_right');
|
||||
$params = array('wid' => $wiki->id, 'title' => $page->title);
|
||||
$url = new moodle_url('/mod/wiki/view.php', $params);
|
||||
if ($pagetype == 'files') {
|
||||
$params['pageid'] = $page->id;
|
||||
}
|
||||
$baseurl->params($params);
|
||||
$name = 'groupanduser';
|
||||
$selected = $subwiki->groupid . '-' . $subwiki->userid;
|
||||
echo $this->output->single_select($url, $name, $options, $selected);
|
||||
echo $this->output->single_select($baseurl, $name, $options, $selected);
|
||||
echo $this->output->container_end();
|
||||
|
||||
return;
|
||||
@ -382,10 +413,14 @@ class mod_wiki_renderer extends plugin_renderer_base {
|
||||
CASE VISIBLEGROUPS:
|
||||
if ($wiki->wikimode == 'collaborative') {
|
||||
// We need to print a select to choose a course group
|
||||
$params = 'wid=' . $wiki->id . '&title=' . urlencode($page->title);
|
||||
$params = array('wid'=>$wiki->id, 'title'=>urlencode($page->title));
|
||||
if ($pagetype == 'files') {
|
||||
$params['pageid'] = $page->id;
|
||||
}
|
||||
$baseurl->params($params);
|
||||
|
||||
echo $this->output->container_start('wiki_right');
|
||||
groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/wiki/view.php?' . $params);
|
||||
groups_print_activity_menu($cm, $baseurl->out());
|
||||
echo $this->output->container_end();
|
||||
return;
|
||||
|
||||
@ -406,10 +441,13 @@ class mod_wiki_renderer extends plugin_renderer_base {
|
||||
|
||||
echo $this->output->container_start('wiki_right');
|
||||
$params = array('wid' => $wiki->id, 'title' => $page->title);
|
||||
$url = new moodle_url('/mod/wiki/view.php', $params);
|
||||
if ($pagetype == 'files') {
|
||||
$params['pageid'] = $page->id;
|
||||
}
|
||||
$baseurl->params($params);
|
||||
$name = 'groupanduser';
|
||||
$selected = $subwiki->groupid . '-' . $subwiki->userid;
|
||||
echo $this->output->single_select($url, $name, $options, $selected);
|
||||
echo $this->output->single_select($baseurl, $name, $options, $selected);
|
||||
echo $this->output->container_end();
|
||||
|
||||
return;
|
||||
@ -440,4 +478,60 @@ class mod_wiki_renderer extends plugin_renderer_base {
|
||||
$select->label = get_string('mapmenu', 'wiki') . ': ';
|
||||
return $this->output->container($this->output->render($select), 'midpad');
|
||||
}
|
||||
function wiki_files_tree($context, $subwiki) {
|
||||
return $this->render(new wiki_files_tree($context, $subwiki));
|
||||
}
|
||||
public function render_wiki_files_tree(wiki_files_tree $tree) {
|
||||
if (empty($tree->dir['subdirs']) && empty($tree->dir['files'])) {
|
||||
$html = $this->output->box(get_string('nofilesavailable', 'repository'));
|
||||
} else {
|
||||
$htmlid = 'wiki_files_tree_'.uniqid();
|
||||
$module = array('name'=>'mod_wiki', 'fullpath'=>'/mod/wiki/module.js');
|
||||
$this->page->requires->js_init_call('M.mod_wiki.init_tree', array(false, $htmlid), false, $module);
|
||||
$html = '<div id="'.$htmlid.'">';
|
||||
$html .= $this->htmllize_tree($tree, $tree->dir);
|
||||
$html .= '</div>';
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal function - creates htmls structure suitable for YUI tree.
|
||||
*/
|
||||
protected function htmllize_tree($tree, $dir) {
|
||||
global $CFG;
|
||||
$yuiconfig = array();
|
||||
$yuiconfig['type'] = 'html';
|
||||
|
||||
if (empty($dir['subdirs']) and empty($dir['files'])) {
|
||||
return '';
|
||||
}
|
||||
$result = '<ul>';
|
||||
foreach ($dir['subdirs'] as $subdir) {
|
||||
$image = $this->output->pix_icon("f/folder", $subdir['dirname'], 'moodle', array('class'=>'icon'));
|
||||
$result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>';
|
||||
}
|
||||
foreach ($dir['files'] as $file) {
|
||||
$url = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$tree->context->id.'/mod_wiki/attachments/' . $tree->subwiki->id . '/'. $file->get_filepath() . $file->get_filename(), true);
|
||||
$filename = $file->get_filename();
|
||||
$icon = mimeinfo("icon", $filename);
|
||||
$image = $this->output->pix_icon("f/$icon", $filename, 'moodle', array('class'=>'icon'));
|
||||
$result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.html_writer::link($url, $filename).'</div></li>';
|
||||
}
|
||||
$result .= '</ul>';
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
class wiki_files_tree implements renderable {
|
||||
public $context;
|
||||
public $dir;
|
||||
public $subwiki;
|
||||
public function __construct($context, $subwiki) {
|
||||
$fs = get_file_storage();
|
||||
$this->context = $context;
|
||||
$this->subwiki = $subwiki;
|
||||
$this->dir = $fs->get_area_tree($context->id, 'mod_wiki', 'attachments', $subwiki->id);
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ if (!$cm = get_coursemodule_from_id('wiki', $cmid)) {
|
||||
print_error('invalidcoursemodule');
|
||||
}
|
||||
|
||||
require_course_login($course, true, $cm);
|
||||
require_login($course, true, $cm);
|
||||
|
||||
// @TODO: Fix call to wiki_get_subwiki_by_group
|
||||
if (!$gid = groups_get_activity_group($cm)) {
|
||||
|
@ -352,4 +352,10 @@ a.wiki_edit_section {
|
||||
.wiki-diff-container .wiki-diff-rightside {margin-left:1%;}
|
||||
.wiki-diff-container .wiki-diff-heading,
|
||||
.wiki-diff-container .no-overflow {padding:10px;border:1px solid #DDD;}
|
||||
.wiki-diff-container .wiki-diff-rightside .wiki_diffversion {text-align:right;}
|
||||
.wiki-diff-container .wiki-diff-rightside .wiki_diffversion {text-align:right;}
|
||||
|
||||
.wikieditor-toolbar img{
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
@ -19,8 +19,7 @@
|
||||
* Code fragment to define the version of wiki
|
||||
* This fragment is called by moodle_needs_upgrading() and /admin/index.php
|
||||
*
|
||||
* @package mod
|
||||
* @subpackage wiki
|
||||
* @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
|
||||
*
|
||||
@ -33,6 +32,6 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$module->version = 2011011000; // The current module version (Date: YYYYMMDDXX)
|
||||
$module->version = 2011011001; // The current module version (Date: YYYYMMDDXX)
|
||||
$module->requires = 2010080300;
|
||||
$module->cron = 0; // Period for cron to check this module (secs)
|
||||
|
@ -251,7 +251,7 @@ if ($id) {
|
||||
} else {
|
||||
print_error('incorrectparameters');
|
||||
}
|
||||
require_course_login($course, true, $cm);
|
||||
require_login($course, true, $cm);
|
||||
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
require_capability('mod/wiki:viewpage', $context);
|
||||
|
@ -58,7 +58,7 @@ if (!$cm = get_coursemodule_from_instance('wiki', $wiki->id)) {
|
||||
|
||||
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
|
||||
|
||||
require_course_login($course->id, true, $cm);
|
||||
require_login($course->id, true, $cm);
|
||||
add_to_log($course->id, "wiki", "history", "history.php?id=$cm->id", "$wiki->id");
|
||||
|
||||
/// Print the page header
|
||||
|
Loading…
x
Reference in New Issue
Block a user