Permalink
Browse files

[MDL-23432]

Fixing this issue and some other problems with comments interface and capabilities.
  • Loading branch information...
Jordi Piguillem
Jordi Piguillem committed Aug 3, 2010
1 parent e0a5073 commit 9bf1b7166fadb842e123d8f48b402c3fce553407
Showing with 35 additions and 10 deletions.
  1. +5 −0 mod/wiki/locallib.php
  2. +30 −10 mod/wiki/pagelib.php
View
@@ -1070,6 +1070,11 @@ function wiki_process_attachments($draftitemid, $deleteuploads, $contextid, $fil
return $errors;
}
function wiki_get_comment($commentid){
global $DB;
return $DB->get_record('comment', 'id', $commentid);
}
/**
* Returns all comments by context and pageid
*
View
@@ -666,18 +666,25 @@ function print_content() {
$row2->cells[] = $cell4;
if ((has_capability('mod/wiki:managecomment', $context)) and ($USER->id == $user->id)) {
$t->data = array($row1, $row2);
$actionicons = false;
if ((has_capability('mod/wiki:managecomment', $context))) {
$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'));
$actionicons = true;
} else if ((has_capability('mod/wiki:editcomment', $context)) and ($USER->id == $user->id)) {
$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'));
$actionicons = true;
}
if ($actionicons){
$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);
$t->data[] = $row3;
}
echo html_writer::table($t);
@@ -2134,15 +2141,28 @@ function print_header() {
}
public function print_content() {
global $PAGE;
global $PAGE, $USER;
$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);
if ($this->action == 'add'){
if (has_capability('mod/wiki:editcomment', $context)){
$this->add_comment($this->content, $this->commentid);
}
} else if ($this->action == 'edit') {
$comment = wiki_get_comment($this->commentid);
$edit = has_capability('mod/wiki:editcomment', $context);
$owner = $comment->userid == $USER->id;
if ($owner && $edit){
$this->add_comment($this->content, $this->commentid);
}
} else if ($this->action == 'delete') {
$this->delete_comment($this->commentid);
$comment = wiki_get_comment($this->commentid);
$manage = has_capability('mod/wiki:managecomment', $context);
$owner = $comment->userid == $USER->id;
if ($owner || $manage){
$this->delete_comment($this->commentid);
}
}
}

0 comments on commit 9bf1b71

Please sign in to comment.