Example #1
0
    public function print_content() {
        global $USER, $PAGE;

        require_capability('mod/wiki:editpage', $this->modcontext, NULL, true, 'noeditpermission', 'wiki');

        wiki_set_lock($this->page->id, $USER->id, $this->section);
    }
 /**
  * Test edit_page. We won't test all the possible cases because that's already
  * done in the tests for wiki_save_section / wiki_save_page.
  */
 public function test_edit_page()
 {
     $this->create_individual_wikis_with_groups();
     // Test user with full capabilities.
     $this->setUser($this->student);
     $newpage = $this->getDataGenerator()->get_plugin_generator('mod_wiki')->create_page($this->wikisepind, array('group' => $this->group1->id, 'content' => 'Test'));
     // Test edit whole page.
     $sectioncontent = '<h1>Title1</h1>Text inside section';
     $newpagecontent = $sectioncontent . '<h1>Title2</h1>Text inside section';
     $result = mod_wiki_external::edit_page($newpage->id, $newpagecontent);
     $result = external_api::clean_returnvalue(mod_wiki_external::edit_page_returns(), $result);
     $this->assertInternalType('int', $result['pageid']);
     $version = wiki_get_current_version($result['pageid']);
     $this->assertEquals($newpagecontent, $version->content);
     // Test edit section.
     $newsectioncontent = '<h1>Title2</h1>New test2';
     $section = 'Title2';
     $result = mod_wiki_external::edit_page($newpage->id, $newsectioncontent, $section);
     $result = external_api::clean_returnvalue(mod_wiki_external::edit_page_returns(), $result);
     $this->assertInternalType('int', $result['pageid']);
     $expected = $sectioncontent . $newsectioncontent;
     $version = wiki_get_current_version($result['pageid']);
     $this->assertEquals($expected, $version->content);
     // Test locked section.
     $newsectioncontent = '<h1>Title2</h1>New test2';
     $section = 'Title2';
     try {
         // Using user 1 to avoid other users to edit.
         wiki_set_lock($newpage->id, 1, $section, true);
         mod_wiki_external::edit_page($newpage->id, $newsectioncontent, $section);
         $this->fail('Exception expected due to locked section');
     } catch (moodle_exception $e) {
         $this->assertEquals('pageislocked', $e->errorcode);
     }
     // Test edit non existing section.
     $newsectioncontent = '<h1>Title3</h1>New test3';
     $section = 'Title3';
     try {
         mod_wiki_external::edit_page($newpage->id, $newsectioncontent, $section);
         $this->fail('Exception expected due to non existing section in the page.');
     } catch (moodle_exception $e) {
         $this->assertEquals('invalidsection', $e->errorcode);
     }
 }
function wiki_action_content(&$WS)
{
    if ($WS->wikibookinfo) {
        echo $WS->wikibookinfo->navibar;
    }
    $section = optional_param('section', '', PARAM_TEXT);
    $sectionnum = optional_param('sectionnum', 0, PARAM_INTEGER);
    $sectionhash = optional_param('sectionhash', '', PARAM_TEXT);
    $preview = optional_param('dfformpreview', '', PARAM_TEXT);
    $action = optional_param('dfformaction', '', PARAM_TEXT);
    $sectionstring = '';
    if ($section == '' && $sectionnum == 0) {
        // main page
        $section = '';
    } else {
        if ($action == 'edit' && $preview == '' && !wiki_is_uploading_modified()) {
            $section = '';
        } else {
            $section = urldecode($section);
            $sectionstring = strtolower(get_string('section', ''));
            if ($preview != '' || wiki_is_uploading_modified()) {
                $sectionstring = ' (' . $sectionstring . ' ' . $section . ')';
            } else {
                $sectionstring = ' (' . $sectionstring . ' ' . stripslashes($section) . ')';
            }
        }
    }
    //this is used for giving an appropiate format to the pagename when a simple id is given
    if (is_numeric($WS->page)) {
        echo '<h1>' . wiki_get_pagename_from_id($WS) . $sectionstring . '</h1>';
    } else {
        if (substr($WS->page, 0, strlen('discussion:')) == 'discussion:') {
            echo '<h1>';
            print_string('discussionabout', 'wiki');
            $pagename = substr($WS->page, strlen('discussion:'), strlen($WS->page));
            echo ': <i>' . format_text($pagename, FORMAT_PLAIN) . '</i></h1>';
        } else {
            if ($WS->pageaction == 'admin') {
                echo '<h1>' . get_string("admin", "wiki") . ": " . format_text($WS->page, FORMAT_PLAIN) . $sectionstring . '</h1>';
            } else {
                if ($WS->wikibookinfo) {
                    echo '<h1>' . format_text($WS->wikibookinfo->title, FORMAT_PLAIN) . $sectionstring . '</h1>';
                } else {
                    if ($WS->pageaction == 'info') {
                        echo '<h1>' . format_text($WS->page, FORMAT_PLAIN) . '</h1>' . '<h3>' . get_string('created_on', 'wiki') . ' ' . strftime('%A, %d %B %Y, %H:%M', $WS->pagedata->created);
                        if (wiki_grade_got_permission($WS)) {
                            // don't show the grade if the user hasn't permission
                            $grade = wiki_grade_get_wikigrade($WS);
                            echo '<br/>' . get_string('grade') . ': ' . $grade . '</h3>';
                        }
                    } else {
                        if ($section == '') {
                            echo '<h1>' . format_text($WS->page, FORMAT_PLAIN) . '</h1>';
                        } else {
                            if ($sectionhash != '') {
                                $stringhash = '&amp;sectionhash=' . $sectionhash;
                            } else {
                                $stringhash = '';
                            }
                            $WS->pagedata->editor = 'htmleditor';
                            // force htmleditor - wysiwyg (nadavkav)
                            echo '<h1><a href="view.php?id=' . $WS->linkid . '&amp;gid=' . $WS->groupmember->groupid . '&amp;uid=' . $WS->member->id . '&amp;page=view/' . urlencode($WS->page) . '&amp;editor=' . $WS->pagedata->editor . $stringhash . '">' . format_text($WS->page, FORMAT_PLAIN) . '</a>' . $sectionstring . '</h1>';
                        }
                    }
                }
            }
        }
    }
    print_box_start();
    if ($sectionhash != '') {
        $pagename = $WS->pagedata->pagename . '#' . $sectionhash;
    } else {
        $pagename = $WS->pagedata->pagename;
    }
    switch ($WS->pageaction) {
        case 'view':
            wiki_release_lock($WS, $WS->dfwiki->id, $pagename);
            wiki_view_content($WS);
            break;
        case 'edit':
            if (wiki_set_lock($WS)) {
                wiki_edit_content($WS);
            }
            break;
        case 'info':
            wiki_release_lock($WS, $WS->dfwiki->id, $pagename);
            wiki_info_content($WS);
            break;
        case 'discussion':
            wiki_release_lock($WS, $WS->dfwiki->id, $pagename);
            wiki_release_lock($WS, $WS->dfwiki->id, $WS->page);
            wiki_view_content($WS);
            break;
        case 'editdiscussion':
            if (wiki_set_lock($WS)) {
                wiki_edit_content($WS);
            }
            break;
        case 'adddiscussion':
            wiki_release_lock($WS, $WS->dfwiki->id, $pagename);
            wiki_edit_content($WS);
            break;
        case 'infodiscussion':
            wiki_release_lock($WS, $WS->dfwiki->id, $pagename);
            wiki_info_content($WS);
            break;
        case 'navigator':
            wiki_release_lock($WS, $WS->dfwiki->id, $pagename);
            wiki_navigator_content($WS);
            break;
        case 'admin':
            wiki_release_lock($WS, $WS->dfwiki->id, $pagename);
            wiki_admin($WS);
            break;
        default:
            print_string('nopageaction', 'wiki');
            break;
    }
    print_box_end();
    // show wiki tags
    wiki_tags_print_viewbox($WS);
    // add grade evaluation box if possible
    wiki_grade_print_page_evaluation_box($WS);
    if ($WS->wikibookinfo) {
        echo $WS->wikibookinfo->navibar;
    }
}
Example #4
0
 /**
  * Locks and retrieves info of page-section to be edited.
  *
  * @param int $pageid The page ID.
  * @param string $section Section page title.
  * @return array of warnings and page data.
  * @since Moodle 3.1
  */
 public static function get_page_for_editing($pageid, $section = null)
 {
     global $USER;
     $params = self::validate_parameters(self::get_page_for_editing_parameters(), array('pageid' => $pageid, 'section' => $section));
     $warnings = array();
     // Get wiki page.
     if (!($page = wiki_get_page($params['pageid']))) {
         throw new moodle_exception('incorrectpageid', 'wiki');
     }
     // Get wiki instance.
     if (!($wiki = wiki_get_wiki_from_pageid($params['pageid']))) {
         throw new moodle_exception('incorrectwikiid', 'wiki');
     }
     // Get subwiki instance.
     if (!($subwiki = wiki_get_subwiki($page->subwikiid))) {
         throw new moodle_exception('incorrectsubwikiid', 'wiki');
     }
     // Permission validation.
     $cm = get_coursemodule_from_instance('wiki', $wiki->id, $wiki->course);
     $context = context_module::instance($cm->id);
     self::validate_context($context);
     if (!wiki_user_can_edit($subwiki)) {
         throw new moodle_exception('cannoteditpage', 'wiki');
     }
     if (!wiki_set_lock($params['pageid'], $USER->id, $params['section'], true)) {
         throw new moodle_exception('pageislocked', 'wiki');
     }
     $version = wiki_get_current_version($page->id);
     if (empty($version)) {
         throw new moodle_exception('versionerror', 'wiki');
     }
     if (!is_null($params['section'])) {
         $content = wiki_parser_proxy::get_section($version->content, $version->contentformat, $params['section']);
     } else {
         $content = $version->content;
     }
     $pagesection = array();
     $pagesection['content'] = $content;
     $pagesection['contentformat'] = $version->contentformat;
     $pagesection['version'] = $version->version;
     $result = array();
     $result['pagesection'] = $pagesection;
     $result['warnings'] = $warnings;
     return $result;
 }
Example #5
0
    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);
    }