Skip to content

Commit

Permalink
Merged branch 's9_MDL-26392_wiki_files_master' from git://github.com/…
Browse files Browse the repository at this point in the history
…dongsheng/moodle.git with fixes
  • Loading branch information
Sam Hemelryk committed Jun 7, 2011
2 parents e0f18a3 + 12c9bbb commit c464a23
Show file tree
Hide file tree
Showing 25 changed files with 535 additions and 205 deletions.
2 changes: 1 addition & 1 deletion mod/wiki/comments.php
Expand Up @@ -57,7 +57,7 @@

$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);

Expand Down
13 changes: 12 additions & 1 deletion mod/wiki/db/access.php
Expand Up @@ -38,7 +38,7 @@
)
),

'mod/wiki:createpage' => array(
'mod/wiki:createpage' => array(

'riskbitmask' => RISK_SPAM,

Expand Down Expand Up @@ -89,6 +89,17 @@
)
),

'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',
Expand Down
2 changes: 1 addition & 1 deletion mod/wiki/diff.php
Expand Up @@ -66,7 +66,7 @@
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);
Expand Down
44 changes: 20 additions & 24 deletions mod/wiki/edit_form.php
Expand Up @@ -31,8 +31,7 @@
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 {

Expand All @@ -42,13 +41,12 @@ protected function definition() {
$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'];
}

Expand All @@ -63,12 +61,25 @@ protected function definition() {

$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
Expand All @@ -80,21 +91,6 @@ protected function definition() {
$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'));
Expand Down
6 changes: 3 additions & 3 deletions mod/wiki/editors/wiki/buttons.js
Expand Up @@ -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;

Expand Down Expand Up @@ -79,4 +79,4 @@ function insertTags(tagOpen, tagClose, sampleText) {
}
// reposition cursor if possible
if (txtarea.createTextRange) txtarea.caretPos = document.selection.createRange().duplicate();
}
}
28 changes: 22 additions & 6 deletions mod/wiki/editors/wikieditor.php
Expand Up @@ -31,11 +31,17 @@

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);
}
Expand Down Expand Up @@ -71,7 +77,7 @@ private function printWikiEditor($textarea) {
}

private function getButtons() {
global $PAGE, $CFG;
global $PAGE, $OUTPUT, $CFG;

$editor = $this->wikiformat;

Expand All @@ -81,6 +87,9 @@ private function getButtons() {
$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'));

Expand All @@ -91,9 +100,6 @@ private function getButtons() {
$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));
Expand All @@ -107,13 +113,23 @@ private function getButtons() {

$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;
}
Expand Down
107 changes: 107 additions & 0 deletions mod/wiki/files.php
@@ -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();

0 comments on commit c464a23

Please sign in to comment.