コード例 #1
0
ファイル: locallib.php プロジェクト: esyacelga/sisadmaca
/**
 * This function is the parser callback to parse wiki links.
 *
 * It returns the necesary information to print a link.
 *
 * NOTE: Empty pages and non-existent pages must be print in red color.
 *
 * !!!!!! IMPORTANT !!!!!!
 * It is critical that you call format_string on the content before it is used.
 *
 * @param string|page_wiki $link name of a page
 * @param array $options
 * @return array Array('content' => string, 'url' => string, 'new' => bool, 'link_info' => array)
 *
 * @TODO Doc return and options
 */
function wiki_parser_link($link, $options = null)
{
    global $CFG;
    if (is_object($link)) {
        $parsedlink = array('content' => $link->title, 'url' => $CFG->wwwroot . '/mod/wiki/view.php?pageid=' . $link->id, 'new' => false, 'link_info' => array('link' => $link->title, 'pageid' => $link->id, 'new' => false));
        $version = wiki_get_current_version($link->id);
        if ($version->version == 0) {
            $parsedlink['new'] = true;
        }
        return $parsedlink;
    } else {
        $swid = $options['swid'];
        if ($page = wiki_get_page_by_title($swid, $link)) {
            $parsedlink = array('content' => $link, 'url' => $CFG->wwwroot . '/mod/wiki/view.php?pageid=' . $page->id, 'new' => false, 'link_info' => array('link' => $link, 'pageid' => $page->id, 'new' => false));
            $version = wiki_get_current_version($page->id);
            if ($version->version == 0) {
                $parsedlink['new'] = true;
            }
            return $parsedlink;
        } else {
            return array('content' => $link, 'url' => $CFG->wwwroot . '/mod/wiki/create.php?swid=' . $swid . '&title=' . urlencode($link) . '&action=new', 'new' => true, 'link_info' => array('link' => $link, 'new' => true, 'pageid' => 0));
        }
    }
}
コード例 #2
0
ファイル: pagelib.php プロジェクト: Burick/moodle
    public function set_action($action, $commentid, $content) {
        $this->action = $action;
        $this->commentid = $commentid;
        $this->content = $content;

        $version = wiki_get_current_version($this->page->id);
        $format = $version->contentformat;

        $this->format = $format;
    }
コード例 #3
0
ファイル: events_test.php プロジェクト: evltuma/moodle
 /**
  * Test page_version_restored event.
  */
 public function test_page_version_restored()
 {
     $this->setUp();
     $page = $this->wikigenerator->create_first_page($this->wiki);
     $context = context_module::instance($this->wiki->cmid);
     $version = wiki_get_current_version($page->id);
     // Triggering and capturing the event.
     $sink = $this->redirectEvents();
     wiki_restore_page($page, $version, $context);
     $events = $sink->get_events();
     $this->assertCount(2, $events);
     $event = array_pop($events);
     // Checking that the event contains the expected values.
     $this->assertInstanceOf('\\mod_wiki\\event\\page_version_restored', $event);
     $this->assertEquals($context, $event->get_context());
     $this->assertEquals($version->id, $event->objectid);
     $this->assertEquals($page->id, $event->other['pageid']);
     $expected = array($this->course->id, 'wiki', 'restore', 'view.php?pageid=' . $page->id, $page->id, $this->wiki->cmid);
     $this->assertEventLegacyLogData($expected, $event);
     $this->assertEventContextNotUsed($event);
 }
コード例 #4
0
 /**
  * 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);
     }
 }
コード例 #5
0
ファイル: external.php プロジェクト: jackdaniels79/moodle
 /**
  * Edit a page contents.
  *
  * @param int $pageid The page ID.
  * @param string $content Page contents.
  * @param int $section Section to be edited.
  * @return array of warnings and page data.
  * @since Moodle 3.1
  */
 public static function edit_page($pageid, $content, $section = null)
 {
     global $USER;
     $params = self::validate_parameters(self::edit_page_parameters(), array('pageid' => $pageid, 'content' => $content, '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_is_page_section_locked($page->id, $USER->id, $params['section'])) {
         throw new moodle_exception('pageislocked', 'wiki');
     }
     // Save content.
     if (!is_null($params['section'])) {
         $version = wiki_get_current_version($page->id);
         $content = wiki_parser_proxy::get_section($version->content, $version->contentformat, $params['section'], false);
         if (!$content) {
             throw new moodle_exception('invalidsection', 'wiki');
         }
         $save = wiki_save_section($page, $params['section'], $params['content'], $USER->id);
     } else {
         $save = wiki_save_page($page, $params['content'], $USER->id);
     }
     wiki_delete_locks($page->id, $USER->id, $params['section']);
     if (!$save) {
         throw new moodle_exception('savingerror', 'wiki');
     }
     $result = array();
     $result['pageid'] = $page->id;
     $result['warnings'] = $warnings;
     return $result;
 }