Exemplo n.º 1
0
    /**
     * Prints the navigation tab content
     *
     * @uses $OUTPUT
     *
     */
    private function print_navigation_content() {
        global $OUTPUT;
        $page = $this->page;

        if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) {
            $fresh = wiki_refresh_cachedcontent($page);
            $page = $fresh['page'];
        }

        $tolinks = wiki_get_linked_to_pages($page->id);
        $fromlinks = wiki_get_linked_from_pages($page->id);

        $table = new html_table();
        $table->attributes['class'] = 'wiki_navigation_from';
        $table->head = array(get_string('navigationfrom', 'wiki') . $OUTPUT->help_icon('navigationfrom', 'wiki') . ':');
        $table->data = array();
        $table->rowclasses = array();
        foreach ($fromlinks as $link) {
            $lpage = wiki_get_page($link->frompageid);
            $link = new moodle_url('/mod/wiki/view.php', array('pageid' => $lpage->id));
            $table->data[] = array(html_writer::link($link->out(false), format_string($lpage->title)));
            $table->rowclasses[] = 'mdl-align';
        }

        $table_left = html_writer::table($table);

        $table = new html_table();
        $table->attributes['class'] = 'wiki_navigation_to';
        $table->head = array(get_string('navigationto', 'wiki') . $OUTPUT->help_icon('navigationto', 'wiki') . ':');
        $table->data = array();
        $table->rowclasses = array();
        foreach ($tolinks as $link) {
            if ($link->tomissingpage) {
                $viewlink = new moodle_url('/mod/wiki/create.php', array('swid' => $page->subwikiid, 'title' => $link->tomissingpage, 'action' => 'new'));
                $table->data[] = array(html_writer::link($viewlink->out(false), format_string($link->tomissingpage), array('class' => 'wiki_newentry')));
            } else {
                $lpage = wiki_get_page($link->topageid);
                $viewlink = new moodle_url('/mod/wiki/view.php', array('pageid' => $lpage->id));
                $table->data[] = array(html_writer::link($viewlink->out(false), format_string($lpage->title)));
            }
            $table->rowclasses[] = 'mdl-align';
        }
        $table_right = html_writer::table($table);
        echo $OUTPUT->container($table_left . $table_right, 'wiki_navigation_container');
    }
Exemplo n.º 2
0
 *
 * @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);
Exemplo n.º 3
0
}
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
if (!($wiki = wiki_get_wiki($subwiki->wikiid))) {
    print_error('incorrectwikiid', 'wiki');
}
require_login($course, true, $cm);
if (!wiki_user_can_view($subwiki, $wiki)) {
    print_error('cannotviewpage', 'wiki');
}
$context = context_module::instance($cm->id);
require_capability('mod/wiki:managewiki', $context);
//Delete page if a page ID to delete was supplied
if (!empty($delete) && confirm_sesskey()) {
    if ($pageid != $delete) {
        // Validate that we are deleting from the same subwiki.
        $deletepage = wiki_get_page($delete);
        if (!$deletepage || $deletepage->subwikiid != $page->subwikiid) {
            print_error('incorrectsubwikiid', 'wiki');
        }
    }
    wiki_delete_pages($context, $delete, $page->subwikiid);
    //when current wiki page is deleted, then redirect user to create that page, as
    //current pageid is invalid after deletion.
    if ($pageid == $delete) {
        $params = array('swid' => $page->subwikiid, 'title' => $page->title);
        $url = new moodle_url('/mod/wiki/create.php', $params);
        redirect($url);
    }
}
//delete version if toversion and fromversion are set.
if (!empty($toversion) && !empty($fromversion) && confirm_sesskey()) {
Exemplo n.º 4
0
 /**
  * Test new_page. We won't test all the possible cases because that's already
  * done in the tests for wiki_create_page.
  */
 public function test_new_page()
 {
     $this->create_individual_wikis_with_groups();
     $sectioncontent = '<h1>Title1</h1>Text inside section';
     $pagecontent = $sectioncontent . '<h1>Title2</h1>Text inside section';
     $pagetitle = 'Page Title';
     // Test user with full capabilities.
     $this->setUser($this->student);
     // Test on existing subwiki.
     $result = mod_wiki_external::new_page($pagetitle, $pagecontent, 'html', $this->fpsepg1indstu->subwikiid);
     $result = external_api::clean_returnvalue(mod_wiki_external::new_page_returns(), $result);
     $this->assertInternalType('int', $result['pageid']);
     $version = wiki_get_current_version($result['pageid']);
     $this->assertEquals($pagecontent, $version->content);
     $this->assertEquals('html', $version->contentformat);
     $page = wiki_get_page($result['pageid']);
     $this->assertEquals($pagetitle, $page->title);
     // Test existing page creation.
     try {
         mod_wiki_external::new_page($pagetitle, $pagecontent, 'html', $this->fpsepg1indstu->subwikiid);
         $this->fail('Exception expected due to creation of an existing page.');
     } catch (moodle_exception $e) {
         $this->assertEquals('pageexists', $e->errorcode);
     }
     // Test on non existing subwiki. Add student to group2 to have a new subwiki to be created.
     $this->getDataGenerator()->create_group_member(array('userid' => $this->student->id, 'groupid' => $this->group2->id));
     $result = mod_wiki_external::new_page($pagetitle, $pagecontent, 'html', null, $this->wikisepind->id, $this->student->id, $this->group2->id);
     $result = external_api::clean_returnvalue(mod_wiki_external::new_page_returns(), $result);
     $this->assertInternalType('int', $result['pageid']);
     $version = wiki_get_current_version($result['pageid']);
     $this->assertEquals($pagecontent, $version->content);
     $this->assertEquals('html', $version->contentformat);
     $page = wiki_get_page($result['pageid']);
     $this->assertEquals($pagetitle, $page->title);
     $subwiki = wiki_get_subwiki($page->subwikiid);
     $expected = new StdClass();
     $expected->id = $subwiki->id;
     $expected->wikiid = $this->wikisepind->id;
     $expected->groupid = $this->group2->id;
     $expected->userid = $this->student->id;
     $this->assertEquals($expected, $subwiki);
     // Check page creation for a user not in course.
     $this->studentnotincourse = self::getDataGenerator()->create_user();
     $this->anothercourse = $this->getDataGenerator()->create_course();
     $this->groupnotincourse = $this->getDataGenerator()->create_group(array('courseid' => $this->anothercourse->id));
     try {
         mod_wiki_external::new_page($pagetitle, $pagecontent, 'html', null, $this->wikisepind->id, $this->studentnotincourse->id, $this->groupnotincourse->id);
         $this->fail('Exception expected due to creation of an invalid subwiki creation.');
     } catch (moodle_exception $e) {
         $this->assertEquals('cannoteditpage', $e->errorcode);
     }
 }
Exemplo n.º 5
0
 /**
  * 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;
 }
Exemplo n.º 6
0
 function content_wiki_page($url)
 {
     return wiki_get_page($url);
 }
Exemplo n.º 7
0
 /**
  * Trigger the page viewed event and update the module completion status.
  *
  * @param int $pageid The page ID.
  * @return array of warnings and status result.
  * @since Moodle 3.1
  * @throws moodle_exception if page is not valid.
  */
 public static function view_page($pageid)
 {
     $params = self::validate_parameters(self::view_page_parameters(), array('pageid' => $pageid));
     $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');
     }
     // Permission validation.
     list($course, $cm) = get_course_and_cm_from_instance($wiki, 'wiki');
     $context = context_module::instance($cm->id);
     self::validate_context($context);
     // Check if user can view this wiki.
     if (!($subwiki = wiki_get_subwiki($page->subwikiid))) {
         throw new moodle_exception('incorrectsubwikiid', 'wiki');
     }
     if (!wiki_user_can_view($subwiki, $wiki)) {
         throw new moodle_exception('cannotviewpage', 'wiki');
     }
     // Trigger page_viewed event and completion.
     wiki_page_view($wiki, $page, $course, $cm, $context);
     $result = array();
     $result['status'] = true;
     $result['warnings'] = $warnings;
     return $result;
 }
Exemplo n.º 8
0
 /**
  * Generates a page in wiki.
  *
  * @param stdClass wiki object returned from create_instance (if known)
  * @param stdClass|array $record data to insert as wiki entry.
  * @return stdClass
  * @throws coding_exception if neither $record->wikiid nor $wiki->id is specified
  */
 public function create_page($wiki, $record = array())
 {
     global $CFG, $USER;
     require_once $CFG->dirroot . '/mod/wiki/locallib.php';
     $this->pagecount++;
     $record = (array) $record + array('title' => 'wiki page ' . $this->pagecount, 'wikiid' => $wiki->id, 'subwikiid' => 0, 'group' => 0, 'content' => 'Wiki page content ' . $this->pagecount, 'format' => $wiki->defaultformat);
     if (empty($record['wikiid']) && empty($record['subwikiid'])) {
         throw new coding_exception('wiki page generator requires either wikiid or subwikiid');
     }
     if (!$record['subwikiid']) {
         if (!isset($record['userid'])) {
             $record['userid'] = $wiki->wikimode == 'individual' ? $USER->id : 0;
         }
         if ($subwiki = wiki_get_subwiki_by_group($record['wikiid'], $record['group'], $record['userid'])) {
             $record['subwikiid'] = $subwiki->id;
         } else {
             $record['subwikiid'] = wiki_add_subwiki($record['wikiid'], $record['group'], $record['userid']);
         }
     }
     if ($wikipage = wiki_get_page_by_title($record['subwikiid'], $record['title'])) {
         $rv = wiki_save_page($wikipage, $record['content'], $USER->id);
         return $rv['page'];
     }
     $pageid = wiki_create_page($record['subwikiid'], $record['title'], $record['format'], $USER->id);
     $wikipage = wiki_get_page($pageid);
     $rv = wiki_save_page($wikipage, $record['content'], $USER->id);
     return $rv['page'];
 }
Exemplo n.º 9
0
 /**
  * Generates a page in wiki.
  *
  * @param stdClass wiki object returned from create_instance (if known)
  * @param stdClass|array $record data to insert as wiki entry.
  * @return stdClass
  * @throws coding_exception if neither $record->wikiid nor $wiki->id is specified
  */
 public function create_page($wiki, $record = array())
 {
     global $CFG, $USER;
     require_once $CFG->dirroot . '/mod/wiki/locallib.php';
     $this->pagecount++;
     $record = (array) $record + array('title' => 'wiki page ' . $this->pagecount, 'wikiid' => $wiki->id, 'subwikiid' => 0, 'group' => 0, 'content' => 'Wiki page content ' . $this->pagecount, 'format' => $wiki->defaultformat);
     if (empty($record['wikiid']) && empty($record['subwikiid'])) {
         throw new coding_exception('wiki page generator requires either wikiid or subwikiid');
     }
     if (!$record['subwikiid']) {
         if (!isset($record['userid'])) {
             $record['userid'] = $wiki->wikimode == 'individual' ? $USER->id : 0;
         }
         if ($subwiki = wiki_get_subwiki_by_group($record['wikiid'], $record['group'], $record['userid'])) {
             $record['subwikiid'] = $subwiki->id;
         } else {
             $record['subwikiid'] = wiki_add_subwiki($record['wikiid'], $record['group'], $record['userid']);
         }
     }
     $wikipage = wiki_get_page_by_title($record['subwikiid'], $record['title']);
     if (!$wikipage) {
         $pageid = wiki_create_page($record['subwikiid'], $record['title'], $record['format'], $USER->id);
         $wikipage = wiki_get_page($pageid);
     }
     $rv = wiki_save_page($wikipage, $record['content'], $USER->id);
     if (array_key_exists('tags', $record)) {
         $tags = is_array($record['tags']) ? $record['tags'] : preg_split('/,/', $record['tags']);
         if (empty($wiki->cmid)) {
             $cm = get_coursemodule_from_instance('wiki', $wiki->id, isset($wiki->course) ? $wiki->course : 0);
             $wiki->cmid = $cm->id;
         }
         core_tag_tag::set_item_tags('mod_wiki', 'wiki_pages', $wikipage->id, context_module::instance($wiki->cmid), $tags);
     }
     return $rv['page'];
 }
Exemplo n.º 10
0
 function ReturnContents()
 {
     global $CORE;
     if (!check_locked()) {
         // Getting the content and printing it to page
         if (!$this->wiki) {
             $content_type = "wiki";
             if (nav_inside('/admin') >= 0) {
                 $this->PAGE->AppendTitle('Администрирование', true);
             }
             $this->PAGE->TPrint(content_static_page($this->URL));
         } else {
             $content_type = "system";
             $this->PAGE->TPrint(wiki_get_page($this->URL));
         }
     } else {
         die;
     }
 }
Exemplo n.º 11
0
 /**
  * Get a page contents.
  *
  * @param int $pageid The page ID.
  * @return array of warnings and page data.
  * @since Moodle 3.1
  */
 public static function get_page_contents($pageid)
 {
     $params = self::validate_parameters(self::get_page_contents_parameters(), array('pageid' => $pageid));
     $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');
     }
     // Permission validation.
     $cm = get_coursemodule_from_instance('wiki', $wiki->id, $wiki->course);
     $context = context_module::instance($cm->id);
     self::validate_context($context);
     // Check if user can view this wiki.
     if (!($subwiki = wiki_get_subwiki($page->subwikiid))) {
         throw new moodle_exception('incorrectsubwikiid', 'wiki');
     }
     if (!wiki_user_can_view($subwiki, $wiki)) {
         throw new moodle_exception('cannotviewpage', 'wiki');
     }
     $returnedpage = array();
     $returnedpage['id'] = $page->id;
     $returnedpage['wikiid'] = $wiki->id;
     $returnedpage['subwikiid'] = $page->subwikiid;
     $returnedpage['groupid'] = $subwiki->groupid;
     $returnedpage['userid'] = $subwiki->userid;
     $returnedpage['title'] = $page->title;
     // Refresh page cached content if needed.
     if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) {
         if ($content = wiki_refresh_cachedcontent($page)) {
             $page = $content['page'];
         }
     }
     list($returnedpage['cachedcontent'], $returnedpage['contentformat']) = external_format_text($page->cachedcontent, FORMAT_HTML, $context->id, 'mod_wiki', 'attachments', $subwiki->id);
     $returnedpage['caneditpage'] = wiki_user_can_edit($subwiki);
     $result = array();
     $result['page'] = $returnedpage;
     $result['warnings'] = $warnings;
     return $result;
 }