Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MOD-WIKI MDL-26213

1. Rewrite the image urls in diff.php and viewdiff.php
2. Fxied image urls in search.php
3. Add modcontext variable to avoid using duplicated
get_context_instance calls
  • Loading branch information...
commit 1a6a1487f44f3ba128dc76b5ce97d6fd49bb2e07 1 parent a5286ae
@dcai dcai authored stronk7 committed
Showing with 59 additions and 93 deletions.
  1. +1 −1  mod/wiki/lock.php
  2. +56 −90 mod/wiki/pagelib.php
  3. +2 −2 mod/wiki/renderer.php
View
2  mod/wiki/lock.php
@@ -66,7 +66,7 @@
print_error('invalidsection', 'wiki');
}
-require_course_login($course->id);
+require_course_login($course->id, false, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/wiki:editpage', $context);
View
146 mod/wiki/pagelib.php
@@ -65,6 +65,11 @@
protected $gid;
/**
+ * @var object module context object
+ */
+ protected $modcontext;
+
+ /**
* @var int Current user ID
*/
protected $uid;
@@ -92,6 +97,7 @@
function __construct($wiki, $subwiki, $cm) {
global $PAGE, $CFG;
$this->subwiki = $subwiki;
+ $this->modcontext = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
// initialise wiki renderer
$this->wikioutput = $PAGE->get_renderer('mod_wiki');
@@ -291,11 +297,10 @@ function print_header() {
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_print_page_content($this->page, $this->modcontext, $this->subwiki->id);
$wiki = $PAGE->activityrecord;
} else {
print_string('nocontent', 'wiki');
@@ -398,7 +403,6 @@ function print_header() {
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 {
@@ -519,9 +523,6 @@ protected function print_edit($content = null) {
}
}
- $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;
@@ -537,16 +538,16 @@ protected function print_edit($content = null) {
switch ($format) {
case 'html':
$data->newcontentformat = FORMAT_HTML;
- $data = file_prepare_standard_editor($data, 'newcontent', page_wiki_edit::$attachmentoptions, $context, 'mod_wiki', 'attachments', $this->subwiki->id);
+ $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, $context->id, 'mod_wiki', 'attachments', $this->subwiki->id);
+ //file_prepare_draft_area($draftitemid, $this->modcontext->id, 'mod_wiki', 'attachments', $this->subwiki->id);
//$data->attachments = $draftitemid;
}
if ($version->contentformat != 'html') {
- $params['contextid'] = $context->id;
+ $params['contextid'] = $this->modcontext->id;
$params['component'] = 'mod_wiki';
$params['filearea'] = 'attachments';
$params['fileitemid'] = $this->subwiki->id;
@@ -560,7 +561,7 @@ protected function print_edit($content = null) {
if ($formdata = $form->get_data()) {
if ($format != 'html') {
- $errors = $this->process_uploads($context);
+ $errors = $this->process_uploads($this->modcontext);
if (!empty($errors)) {
$contenterror = "";
foreach ($errors as $e) {
@@ -610,21 +611,19 @@ function print_header() {
}
function print_content() {
- global $CFG, $OUTPUT, $USER, $PAGE, $COURSE;
+ global $CFG, $OUTPUT, $USER, $PAGE;
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);
+ list($context, $course, $cm) = get_context_info_array($this->modcontext->id);
- require_capability('mod/wiki:viewcomment', $context, NULL, true, 'noviewcommentpermission', 'wiki');
+ require_capability('mod/wiki:viewcomment', $this->modcontext, NULL, true, 'noviewcommentpermission', 'wiki');
- $comments = wiki_get_comments($context->id, $page->id);
+ $comments = wiki_get_comments($this->modcontext->id, $page->id);
- if (has_capability('mod/wiki:editcomment', $context)) {
+ if (has_capability('mod/wiki:editcomment', $this->modcontext)) {
echo '<div class="midpad"><a href="' . $CFG->wwwroot . '/mod/wiki/editcomments.php?action=add&amp;pageid=' . $page->id . '">' . get_string('addcomment', 'wiki') . '</a></div>';
}
@@ -676,11 +675,11 @@ function print_content() {
$t->data = array($row1, $row2);
$actionicons = false;
- if ((has_capability('mod/wiki:managecomment', $context))) {
+ if ((has_capability('mod/wiki:managecomment', $this->modcontext))) {
$urledit = new moodle_url('/mod/wiki/editcomments.php', array('commentid' => $comment->id, 'pageid' => $page->id, 'action' => 'edit'));
$urldelet = new moodle_url('/mod/wiki/instancecomments.php', array('commentid' => $comment->id, 'pageid' => $page->id, 'action' => 'delete'));
$actionicons = true;
- } else if ((has_capability('mod/wiki:editcomment', $context)) and ($USER->id == $user->id)) {
+ } else if ((has_capability('mod/wiki:editcomment', $this->modcontext)) and ($USER->id == $user->id)) {
$urledit = new moodle_url('/mod/wiki/editcomments.php', array('commentid' => $comment->id, 'pageid' => $page->id, 'action' => 'edit'));
$urldelet = new moodle_url('/mod/wiki/instancecomments.php', array('commentid' => $comment->id, 'pageid' => $page->id, 'action' => 'delete'));
$actionicons = true;
@@ -738,8 +737,7 @@ function print_header() {
function print_content() {
global $PAGE;
- $context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
- require_capability('mod/wiki:editcomment', $context, NULL, true, 'noeditcommentpermission', 'wiki');
+ require_capability('mod/wiki:editcomment', $this->modcontext, NULL, true, 'noeditcommentpermission', 'wiki');
if ($this->action == 'add') {
$this->add_comment_form();
@@ -848,10 +846,9 @@ function set_url() {
function print_content() {
global $PAGE;
- $context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
- require_capability('mod/wiki:viewpage', $context, NULL, true, 'noviewpagepermission', 'wiki');
+ require_capability('mod/wiki:viewpage', $this->modcontext, NULL, true, 'noviewpagepermission', 'wiki');
- echo $this->wikioutput->search_result($this->search_result);
+ echo $this->wikioutput->search_result($this->search_result, $this->subwiki);
}
}
@@ -928,10 +925,8 @@ protected function create_navbar() {
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');
+ require_capability('mod/wiki:createpage', $this->modcontext, NULL, true, 'nocreatepermission', 'wiki');
$data = new stdClass();
if (!empty($pagetitle)) {
$data->pagetitle = $pagetitle;
@@ -980,8 +975,7 @@ 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');
+ require_capability('mod/wiki:editpage', $this->modcontext, NULL, true, 'noeditpermission', 'wiki');
$this->print_preview();
}
@@ -1017,7 +1011,6 @@ protected function print_preview() {
$version = wiki_get_current_version($this->page->id);
$format = $version->contentformat;
$content = $version->content;
- $context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
$url = $CFG->wwwroot . '/mod/wiki/edit.php?pageid=' . $this->page->id;
if (!empty($this->section)) {
@@ -1026,7 +1019,7 @@ protected function print_preview() {
$params = array('attachmentoptions' => page_wiki_edit::$attachmentoptions, 'format' => $this->format, 'version' => $this->versionnumber);
if ($this->format != 'html') {
- $params['contextid'] = $context->id;
+ $params['contextid'] = $this->modcontext->id;
$params['component'] = 'mod_wiki';
$params['filearea'] = 'attachments';
$params['fileitemid'] = $this->page->id;
@@ -1086,8 +1079,7 @@ function print_header() {
function print_content() {
global $PAGE;
- $context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
- require_capability('mod/wiki:viewpage', $context, NULL, true, 'noviewpagepermission', 'wiki');
+ require_capability('mod/wiki:viewpage', $this->modcontext, NULL, true, 'noviewpagepermission', 'wiki');
$this->print_diff_content();
}
@@ -1118,12 +1110,9 @@ protected function setup_tabs() {
/**
* 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.
+ * @global object $CFG
+ * @global object $OUTPUT
+ * @global object $PAGE
*/
private function print_diff_content() {
global $CFG, $OUTPUT, $PAGE;
@@ -1132,12 +1121,13 @@ private function print_diff_content() {
$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);
+ $oldtext = format_text(file_rewrite_pluginfile_urls($oldversion->content, 'pluginfile.php', $this->modcontext->id, 'mod_wiki', 'attachments', $this->subwiki->id));
+ $newtext = format_text(file_rewrite_pluginfile_urls($newversion->content, 'pluginfile.php', $this->modcontext->id, 'mod_wiki', 'attachments', $this->subwiki->id));
list($diff1, $diff2) = ouwiki_diff_html($oldtext, $newtext);
$oldversion->diff = $diff1;
$oldversion->user = wiki_get_user_info($oldversion->userid);
@@ -1196,8 +1186,7 @@ function 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');
+ require_capability('mod/wiki:viewpage', $this->modcontext, NULL, true, 'noviewpagepermission', 'wiki');
$this->print_history_content();
}
@@ -1225,16 +1214,9 @@ protected function create_navbar() {
/**
* 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.
+ * @global object $CFG
+ * @global object $OUTPUT
+ * @global object $PAGE
*/
private function print_history_content() {
global $CFG, $OUTPUT, $PAGE;
@@ -1431,8 +1413,7 @@ function print_header() {
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');
+ require_capability('mod/wiki:viewpage', $this->modcontext, 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>';
@@ -1866,8 +1847,7 @@ function print_header() {
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');
+ require_capability('mod/wiki:managewiki', $this->modcontext, NULL, true, 'nomanagewikipermission', 'wiki');
$this->print_restoreversion();
}
@@ -1951,9 +1931,6 @@ 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;
@@ -1962,7 +1939,7 @@ protected function print_save() {
$params = array('attachmentoptions' => page_wiki_edit::$attachmentoptions, 'format' => $this->format, 'version' => $this->versionnumber);
if ($this->format != 'html') {
- $params['contextid'] = $context->id;
+ $params['contextid'] = $this->modcontext->id;
$params['component'] = 'mod_wiki';
$params['filearea'] = 'attachments';
$params['fileitemid'] = $this->page->id;
@@ -1974,7 +1951,7 @@ protected function print_save() {
$data = false;
if ($data = $form->get_data()) {
if ($this->format == 'html') {
- $data = file_postupdate_standard_editor($data, 'newcontent', page_wiki_edit::$attachmentoptions, $context, 'mod_wiki', 'attachments', $this->subwiki->id);
+ $data = file_postupdate_standard_editor($data, 'newcontent', page_wiki_edit::$attachmentoptions, $this->modcontext, 'mod_wiki', 'attachments', $this->subwiki->id);
}
if (isset($this->section)) {
@@ -1986,7 +1963,7 @@ protected function print_save() {
if ($save && $data) {
if ($this->format != 'html') {
- $errors = $this->process_uploads($context);
+ $errors = $this->process_uploads($this->modcontext);
}
if (!empty($CFG->usetags)) {
tag_set('wiki_pages', $this->page->id, $data->tags);
@@ -2036,8 +2013,7 @@ function print_header() {
function print_content() {
global $PAGE;
- $context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
- require_capability('mod/wiki:viewpage', $context, NULL, true, 'noviewpagepermission', 'wiki');
+ require_capability('mod/wiki:viewpage', $this->modcontext, NULL, true, 'noviewpagepermission', 'wiki');
$this->print_version_view();
}
@@ -2066,15 +2042,12 @@ protected function setup_tabs() {
/**
* 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.
+ * @global object $CFG
+ * @global object $OUTPUT
+ * @global object $PAGE
*/
private function print_version_view() {
global $CFG, $OUTPUT, $PAGE;
- $cm = $PAGE->cm;
$pageversion = wiki_get_version($this->version->id);
if ($pageversion) {
@@ -2087,6 +2060,9 @@ private function print_version_view() {
$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);
+
+ $pageversion->content = file_rewrite_pluginfile_urls($pageversion->content, 'pluginfile.php', $this->modcontext->id, 'mod_wiki', 'attachments', $this->subwiki->id);
+
$parseroutput = wiki_parse_content($pageversion->contentformat, $pageversion->content, $options);
$content = print_container(format_text($parseroutput['parsed_text'], FORMAT_HTML, array('overflowdiv'=>true)), false, '', '', true);
echo $OUTPUT->box($content, 'generalbox wiki_contentbox');
@@ -2109,8 +2085,7 @@ function set_url() {
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');
+ require_capability('mod/wiki:managewiki', $this->modcontext, NULL, true, 'nomanagewikipermission', 'wiki');
$version = wiki_get_version($this->version->id);
if (wiki_restore_page($this->page, $version->content, $version->userid)) {
@@ -2138,8 +2113,7 @@ function print_header() {
function print_content() {
global $PAGE;
- $context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
- require_capability('mod/wiki:viewpage', $context, NULL, true, 'noviewpagepermission', 'wiki');
+ require_capability('mod/wiki:viewpage', $this->modcontext, NULL, true, 'noviewpagepermission', 'wiki');
$this->print_pretty_view();
}
@@ -2174,22 +2148,20 @@ function print_header() {
public function print_content() {
global $CFG, $PAGE, $USER;
- $context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
-
if ($this->action == 'add') {
- if (has_capability('mod/wiki:editcomment', $context)) {
+ if (has_capability('mod/wiki:editcomment', $this->modcontext)) {
$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);
+ $edit = has_capability('mod/wiki:editcomment', $this->modcontext);
$owner = ($comment->userid == $USER->id);
if ($owner && $edit) {
$this->add_comment($this->content, $this->commentid);
}
} else if ($this->action == 'delete') {
$comment = wiki_get_comment($this->commentid);
- $manage = has_capability('mod/wiki:managecomment', $context);
+ $manage = has_capability('mod/wiki:managecomment', $this->modcontext);
$owner = ($comment->userid == $USER->id);
if ($owner || $manage) {
$this->delete_comment($this->commentid);
@@ -2220,10 +2192,8 @@ private function add_comment($content, $idcomment) {
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);
+ wiki_add_comment($this->modcontext, $pageid, $content, $this->format);
if (!$idcomment) {
redirect($CFG->wwwroot . '/mod/wiki/comments.php?pageid=' . $pageid, get_string('createcomment', 'wiki'), 2);
@@ -2236,11 +2206,9 @@ private function add_comment($content, $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);
+ wiki_delete_comment($commentid, $this->modcontext, $pageid);
}
}
@@ -2269,8 +2237,7 @@ 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');
+ require_capability('mod/wiki:editpage', $this->modcontext, NULL, true, 'noeditpermission', 'wiki');
wiki_set_lock($this->page->id, $USER->id, $this->section);
}
@@ -2287,8 +2254,7 @@ function print_header() {
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');
+ require_capability('mod/wiki:overridelock', $this->modcontext, NULL, true, 'nooverridelockpermission', 'wiki');
wiki_delete_locks($this->page->id, null, $this->section, true, true);
View
4 mod/wiki/renderer.php
@@ -52,7 +52,7 @@ public function page_index() {
return $this->output->container($this->output->render($select), 'wiki_index');
}
- public function search_result($records) {
+ public function search_result($records, $subwiki) {
global $CFG, $PAGE;
$table = new html_table();
$context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
@@ -63,7 +63,7 @@ public function search_result($records) {
$table->head = array('title' => format_string($page->title) . ' (' . html_writer::link($CFG->wwwroot . '/mod/wiki/view.php?pageid=' . $page->id, get_string('view', 'wiki')) . ')');
$table->align = array('title' => 'left');
$table->width = '100%';
- $table->data = array(array(file_rewrite_pluginfile_urls(format_text($page->cachedcontent, FORMAT_HTML), 'pluginfile.php', $context->id, 'mod_wiki', 'attachments', $page->id)));
+ $table->data = array(array(file_rewrite_pluginfile_urls(format_text($page->cachedcontent, FORMAT_HTML), 'pluginfile.php', $context->id, 'mod_wiki', 'attachments', $subwiki->id)));
$table->colclasses = array('wikisearchresults');
$html .= html_writer::table($table);
}
Please sign in to comment.
Something went wrong with that request. Please try again.