示例#1
0
    public function page_index() {
        global $CFG;
        $output = '';
        // Checking wiki instance
        if (!$wiki = wiki_get_wiki($this->page->cm->instance)) {
            return false;
        }

        // @TODO: Fix call to wiki_get_subwiki_by_group
        $gid = groups_get_activity_group($this->page->cm);
        $gid = !empty($gid) ? $gid : 0;
        if (!$subwiki = wiki_get_subwiki_by_group($this->page->cm->instance, $gid)) {
            return false;
        }
        $swid = $subwiki->id;
        $pages = wiki_get_page_list($swid);
        $selectoptions = array();
        foreach ($pages as $page) {
            $selectoptions[$page->id] = $page->title;
        }
        $label = get_string('pageindex', 'wiki') . ': ';
        $select = new single_select(new moodle_url('/mod/wiki/view.php'), 'pageid', $selectoptions);
        $select->label = $label;
        return $this->output->container($this->output->render($select), 'wiki_index');
    }
示例#2
0
/**
 * Delete pages and all related data
 *
 * @param mixed $context context in which page needs to be deleted.
 * @param mixed $pageids id's of pages to be deleted
 * @param int $subwikiid id of the subwiki for which all pages should be deleted
 */
function wiki_delete_pages($context, $pageids = null, $subwikiid = null)
{
    global $DB;
    if (!empty($pageids) && is_int($pageids)) {
        $pageids = array($pageids);
    } else {
        if (!empty($subwikiid)) {
            $pageids = wiki_get_page_list($subwikiid);
        }
    }
    //If there is no pageid then return as we can't delete anything.
    if (empty($pageids)) {
        return;
    }
    /// Delete page and all it's relevent data
    foreach ($pageids as $pageid) {
        if (is_object($pageid)) {
            $pageid = $pageid->id;
        }
        //Delete page comments
        $comments = wiki_get_comments($context->id, $pageid);
        foreach ($comments as $commentid => $commentvalue) {
            wiki_delete_comment($commentid, $context, $pageid);
        }
        //Delete page tags
        $tags = tag_get_tags_array('wiki_pages', $pageid);
        foreach ($tags as $tagid => $tagvalue) {
            tag_delete_instance('wiki_pages', $pageid, $tagid);
        }
        //Delete Synonym
        wiki_delete_synonym($subwikiid, $pageid);
        //Delete all page versions
        wiki_delete_page_versions(array($pageid => array(0)));
        //Delete all page locks
        wiki_delete_locks($pageid);
        //Delete all page links
        wiki_delete_links(null, $pageid);
        //Delete page
        $params = array('id' => $pageid);
        $DB->delete_records('wiki_pages', $params);
    }
}
示例#3
0
文件: lib.php 项目: dg711/moodle
/**
 * Implements callback to reset course
 *
 * @param stdClass $data
 * @return boolean|array
 */
function wiki_reset_userdata($data)
{
    global $CFG, $DB;
    require_once $CFG->dirroot . '/mod/wiki/pagelib.php';
    require_once $CFG->dirroot . "/mod/wiki/locallib.php";
    $componentstr = get_string('modulenameplural', 'wiki');
    $status = array();
    //get the wiki(s) in this course.
    if (!($wikis = $DB->get_records('wiki', array('course' => $data->courseid)))) {
        return false;
    }
    if (empty($data->reset_wiki_comments) && empty($data->reset_wiki_tags) && empty($data->reset_wiki_pages)) {
        return $status;
    }
    foreach ($wikis as $wiki) {
        if (!($cm = get_coursemodule_from_instance('wiki', $wiki->id, $data->courseid))) {
            continue;
        }
        $context = context_module::instance($cm->id);
        // Remove tags or all pages.
        if (!empty($data->reset_wiki_pages) || !empty($data->reset_wiki_tags)) {
            // Get subwiki information.
            $subwikis = wiki_get_subwikis($wiki->id);
            foreach ($subwikis as $subwiki) {
                // Get existing pages.
                if ($pages = wiki_get_page_list($subwiki->id)) {
                    // If the wiki page isn't selected then we are only removing tags.
                    if (empty($data->reset_wiki_pages)) {
                        // Go through each page and delete the tags.
                        foreach ($pages as $page) {
                            core_tag_tag::remove_all_item_tags('mod_wiki', 'wiki_pages', $page->id);
                        }
                    } else {
                        // Otherwise we are removing pages and tags.
                        wiki_delete_pages($context, $pages, $subwiki->id);
                    }
                }
                if (!empty($data->reset_wiki_pages)) {
                    // Delete any subwikis.
                    $DB->delete_records('wiki_subwikis', array('id' => $subwiki->id), IGNORE_MISSING);
                    // Delete any attached files.
                    $fs = get_file_storage();
                    $fs->delete_area_files($context->id, 'mod_wiki', 'attachments');
                }
            }
            if (!empty($data->reset_wiki_pages)) {
                $status[] = array('component' => $componentstr, 'item' => get_string('deleteallpages', 'wiki'), 'error' => false);
            }
            if (!empty($data->reset_wiki_tags)) {
                $status[] = array('component' => $componentstr, 'item' => get_string('tagsdeleted', 'wiki'), 'error' => false);
            }
        }
        // Remove all comments.
        if (!empty($data->reset_wiki_comments) || !empty($data->reset_wiki_pages)) {
            $DB->delete_records_select('comments', "contextid = ? AND commentarea='wiki_page'", array($context->id));
            if (!empty($data->reset_wiki_comments)) {
                $status[] = array('component' => $componentstr, 'item' => get_string('deleteallcomments'), 'error' => false);
            }
        }
    }
    return $status;
}
示例#4
0
文件: pagelib.php 项目: Burick/moodle
    /**
     * Show wiki page delete options
     *
     * @param bool $showorphan
     */
    protected function print_delete_content($showorphan = true) {
        $contents = array();
        $table = new html_table();
        $table->head = array('', get_string('pagename','wiki'));
        $table->attributes['class'] = 'generaltable mdl-align';
        $swid = $this->subwiki->id;
        if ($showorphan) {
            if ($orphanedpages = wiki_get_orphaned_pages($swid)) {
                $this->add_page_delete_options($orphanedpages, $swid, $table);
            } else {
                $table->data[] = array('', get_string('noorphanedpages', 'wiki'));
            }
        } else {
            if ($pages = wiki_get_page_list($swid)) {
                $this->add_page_delete_options($pages, $swid, $table);
            } else {
                $table->data[] = array('', get_string('nopages', 'wiki'));
            }
        }

        ///Print the form
        echo html_writer::start_tag('form', array(
                                                'action' => new moodle_url('/mod/wiki/admin.php'),
                                                'method' => 'post'));
        echo html_writer::tag('div', html_writer::empty_tag('input', array(
                                                                         'type'  => 'hidden',
                                                                         'name'  => 'pageid',
                                                                         'value' => $this->page->id)));

        echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'option', 'value' => $this->view));
        echo html_writer::table($table);
        echo html_writer::start_tag('div', array('class' => 'mdl-align'));
        if (!$showorphan) {
            echo html_writer::empty_tag('input', array(
                                                     'type'    => 'submit',
                                                     'class'   => 'wiki_form-button',
                                                     'value'   => get_string('listorphan', 'wiki'),
                                                     'sesskey' => sesskey()));
        } else {
            echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'listall', 'value'=>'1'));
            echo html_writer::empty_tag('input', array(
                                                     'type'    => 'submit',
                                                     'class'   => 'wiki_form-button',
                                                     'value'   => get_string('listall', 'wiki'),
                                                     'sesskey' => sesskey()));
        }
        echo html_writer::end_tag('div');
        echo html_writer::end_tag('form');
    }
示例#5
0
/**
 * Delete pages and all related data
 *
 * @param mixed $context context in which page needs to be deleted.
 * @param mixed $pageids id's of pages to be deleted
 * @param int $subwikiid id of the subwiki for which all pages should be deleted
 */
function wiki_delete_pages($context, $pageids = null, $subwikiid = null)
{
    global $DB, $CFG;
    if (!empty($pageids) && is_int($pageids)) {
        $pageids = array($pageids);
    } else {
        if (!empty($subwikiid)) {
            $pageids = wiki_get_page_list($subwikiid);
        }
    }
    //If there is no pageid then return as we can't delete anything.
    if (empty($pageids)) {
        return;
    }
    /// Delete page and all it's relevent data
    foreach ($pageids as $pageid) {
        if (is_object($pageid)) {
            $pageid = $pageid->id;
        }
        //Delete page comments
        $comments = wiki_get_comments($context->id, $pageid);
        foreach ($comments as $commentid => $commentvalue) {
            wiki_delete_comment($commentid, $context, $pageid);
        }
        //Delete page tags
        core_tag_tag::remove_all_item_tags('mod_wiki', 'wiki_pages', $pageid);
        //Delete Synonym
        wiki_delete_synonym($subwikiid, $pageid);
        //Delete all page versions
        wiki_delete_page_versions(array($pageid => array(0)), $context);
        //Delete all page locks
        wiki_delete_locks($pageid);
        //Delete all page links
        wiki_delete_links(null, $pageid);
        $params = array('id' => $pageid);
        // Get page before deleting.
        $page = $DB->get_record('wiki_pages', $params);
        //Delete page
        $DB->delete_records('wiki_pages', $params);
        // Trigger page_deleted event.
        $event = \mod_wiki\event\page_deleted::create(array('context' => $context, 'objectid' => $pageid, 'other' => array('subwikiid' => $subwikiid)));
        $event->add_record_snapshot('wiki_pages', $page);
        $event->trigger();
    }
}
 /**
  * Prints the page list tab content
  *
  *
  */
 private function print_page_list_content()
 {
     global $OUTPUT;
     $page = $this->page;
     if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) {
         $fresh = wiki_refresh_cachedcontent($page);
         $page = $fresh['page'];
     }
     $pages = wiki_get_page_list($this->subwiki->id);
     $stdaux = new stdClass();
     $strspecial = get_string('special', 'wiki');
     foreach ($pages as $page) {
         $letter = strtoupper(substr($page->title, 0, 1));
         if (preg_match('/[A-Z]/', $letter)) {
             $stdaux->{$letter}[] = wiki_parser_link($page);
         } else {
             $stdaux->{$strspecial}[] = wiki_parser_link($page);
         }
     }
     $table = new html_table();
     $table->head = array(get_string('pagelist', 'wiki') . $OUTPUT->help_icon('pagelist', 'wiki'));
     $table->attributes['class'] = 'wiki_editor generalbox';
     $table->align = array('center');
     foreach ($stdaux as $key => $elem) {
         $table->data[] = array($key);
         foreach ($elem as $e) {
             $table->data[] = array(html_writer::link($e['url'], $e['content']));
         }
     }
     echo html_writer::table($table);
 }
示例#7
0
 /**
  * Returns the list of pages from a specific subwiki.
  *
  * @param int $wikiid The wiki instance ID.
  * @param int $groupid The group ID. If not defined, use current group.
  * @param int $userid The user ID. If not defined, use current user.
  * @param array $options Several options like sort by, sort direction, ...
  * @return array Containing a list of warnings and a list of pages.
  * @since Moodle 3.1
  */
 public static function get_subwiki_pages($wikiid, $groupid = -1, $userid = 0, $options = array())
 {
     $returnedpages = array();
     $warnings = array();
     $params = self::validate_parameters(self::get_subwiki_pages_parameters(), array('wikiid' => $wikiid, 'groupid' => $groupid, 'userid' => $userid, 'options' => $options));
     // Get wiki instance.
     if (!($wiki = wiki_get_wiki($params['wikiid']))) {
         throw new moodle_exception('incorrectwikiid', 'wiki');
     }
     list($course, $cm) = get_course_and_cm_from_instance($wiki, 'wiki');
     $context = context_module::instance($cm->id);
     self::validate_context($context);
     // Determine groupid and userid to use.
     list($groupid, $userid) = self::determine_group_and_user($cm, $wiki, $params['groupid'], $params['userid']);
     // Get subwiki and validate it.
     $subwiki = wiki_get_subwiki_by_group_and_user_with_validation($wiki, $groupid, $userid);
     if ($subwiki === false) {
         throw new moodle_exception('cannotviewpage', 'wiki');
     } else {
         if ($subwiki->id != -1) {
             // Set sort param.
             $options = $params['options'];
             if (!empty($options['sortby'])) {
                 if ($options['sortdirection'] != 'ASC' && $options['sortdirection'] != 'DESC') {
                     // Invalid sort direction. Use default.
                     $options['sortdirection'] = 'ASC';
                 }
                 $sort = $options['sortby'] . ' ' . $options['sortdirection'];
             }
             $pages = wiki_get_page_list($subwiki->id, $sort);
             $caneditpages = wiki_user_can_edit($subwiki);
             $firstpage = wiki_get_first_page($subwiki->id);
             foreach ($pages as $page) {
                 $retpage = array('id' => $page->id, 'subwikiid' => $page->subwikiid, 'title' => external_format_string($page->title, $context->id), 'timecreated' => $page->timecreated, 'timemodified' => $page->timemodified, 'timerendered' => $page->timerendered, 'userid' => $page->userid, 'pageviews' => $page->pageviews, 'readonly' => $page->readonly, 'caneditpage' => $caneditpages, 'firstpage' => $page->id == $firstpage->id);
                 // Refresh page cached content if needed.
                 if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) {
                     if ($content = wiki_refresh_cachedcontent($page)) {
                         $page = $content['page'];
                     }
                 }
                 list($cachedcontent, $contentformat) = external_format_text($page->cachedcontent, FORMAT_HTML, $context->id, 'mod_wiki', 'attachments', $subwiki->id);
                 if ($options['includecontent']) {
                     // Return the page content.
                     $retpage['cachedcontent'] = $cachedcontent;
                     $retpage['contentformat'] = $contentformat;
                 } else {
                     // Return the size of the content.
                     if (function_exists('mb_strlen') && (int) ini_get('mbstring.func_overload') & 2) {
                         $retpage['contentsize'] = mb_strlen($cachedcontent, '8bit');
                     } else {
                         $retpage['contentsize'] = strlen($cachedcontent);
                     }
                 }
                 $returnedpages[] = $retpage;
             }
         }
     }
     $result = array();
     $result['pages'] = $returnedpages;
     $result['warnings'] = $warnings;
     return $result;
 }
示例#8
0
 /**
  * Returns the list of pages from a specific subwiki.
  *
  * @param int $wikiid The wiki instance ID.
  * @param int $groupid The group ID. If not defined, use current group.
  * @param int $userid The user ID. If not defined, use current user.
  * @param array $options Several options like sort by, sort direction, ...
  * @return array Containing a list of warnings and a list of pages.
  * @since Moodle 3.1
  */
 public static function get_subwiki_pages($wikiid, $groupid = -1, $userid = 0, $options = array())
 {
     global $USER, $DB;
     $returnedpages = array();
     $warnings = array();
     $params = self::validate_parameters(self::get_subwiki_pages_parameters(), array('wikiid' => $wikiid, 'groupid' => $groupid, 'userid' => $userid, 'options' => $options));
     // Get wiki instance.
     if (!($wiki = wiki_get_wiki($params['wikiid']))) {
         throw new moodle_exception('incorrectwikiid', 'wiki');
     }
     list($course, $cm) = get_course_and_cm_from_instance($wiki, 'wiki');
     $context = context_module::instance($cm->id);
     self::validate_context($context);
     // Determine group.
     $groupmode = groups_get_activity_groupmode($cm);
     if ($groupmode == NOGROUPS) {
         $groupid = 0;
     } else {
         if ($params['groupid'] == -1) {
             // Use current group.
             $groupid = groups_get_activity_group($cm);
             $groupid = !empty($groupid) ? $groupid : 0;
         } else {
             $groupid = $params['groupid'];
         }
     }
     // Determine user.
     if ($wiki->wikimode == 'collaborative') {
         // Collaborative wikis don't use userid in subwikis.
         $userid = 0;
     } else {
         if (empty($params['userid'])) {
             // Use current user.
             $userid = $USER->id;
         } else {
             $userid = $params['userid'];
         }
     }
     // Get subwiki based on group and user.
     if (!($subwiki = wiki_get_subwiki_by_group($cm->instance, $groupid, $userid))) {
         // The subwiki doesn't exist.
         // Validate if user is valid.
         if ($userid != 0 && $userid != $USER->id && !($user = $DB->get_record('user', array('id' => $userid)))) {
             throw new moodle_exception('invaliduserid', 'error');
         }
         // Validate that groupid is valid.
         if ($groupid != 0 && !groups_group_exists($groupid)) {
             throw new moodle_exception('cannotfindgroup', 'error');
         }
         // Valid data but subwiki not found. We'll simulate a subwiki object to check if the user would be able to see it
         // if it existed. If he's able to see it then we'll return an empty array because the subwiki has no pages.
         $subwiki = new stdClass();
         $subwiki->wikiid = $wiki->id;
         $subwiki->userid = $userid;
         $subwiki->groupid = $groupid;
         // Check that the user can view the subwiki. This function checks capabilities.
         if (!wiki_user_can_view($subwiki, $wiki)) {
             throw new moodle_exception('cannotviewpage', 'wiki');
         }
     } else {
         // Check that the user can view the subwiki. This function checks capabilities.
         if (!wiki_user_can_view($subwiki, $wiki)) {
             throw new moodle_exception('cannotviewpage', 'wiki');
         }
         // Set sort param.
         $options = $params['options'];
         if (!empty($options['sortby'])) {
             if ($options['sortdirection'] != 'ASC' && $options['sortdirection'] != 'DESC') {
                 // Invalid sort direction. Use default.
                 $options['sortdirection'] = 'ASC';
             }
             $sort = $options['sortby'] . ' ' . $options['sortdirection'];
         }
         $pages = wiki_get_page_list($subwiki->id, $sort);
         $caneditpages = wiki_user_can_edit($subwiki);
         $firstpage = wiki_get_first_page($subwiki->id);
         foreach ($pages as $page) {
             $retpage = array('id' => $page->id, 'subwikiid' => $page->subwikiid, 'title' => external_format_string($page->title, $context->id), 'timecreated' => $page->timecreated, 'timemodified' => $page->timemodified, 'timerendered' => $page->timerendered, 'userid' => $page->userid, 'pageviews' => $page->pageviews, 'readonly' => $page->readonly, 'caneditpage' => $caneditpages, 'firstpage' => $page->id == $firstpage->id);
             if ($options['includecontent']) {
                 // Refresh page cached content if needed.
                 if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) {
                     if ($content = wiki_refresh_cachedcontent($page)) {
                         $page = $content['page'];
                     }
                 }
                 list($retpage['cachedcontent'], $retpage['contentformat']) = external_format_text($page->cachedcontent, FORMAT_HTML, $context->id, 'mod_wiki', 'attachments', $subwiki->id);
             }
             $returnedpages[] = $retpage;
         }
     }
     $result = array();
     $result['pages'] = $returnedpages;
     $result['warnings'] = $warnings;
     return $result;
 }