本文整理汇总了PHP中wiki_get_wiki函数的典型用法代码示例。如果您正苦于以下问题:PHP wiki_get_wiki函数的具体用法?PHP wiki_get_wiki怎么用?PHP wiki_get_wiki使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wiki_get_wiki函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: page_index
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: wiki_user_can_edit
/**
* Checks if current user can edit a subwiki
*
* @param $subwiki
*/
function wiki_user_can_edit($subwiki)
{
global $USER;
$wiki = wiki_get_wiki($subwiki->wikiid);
$cm = get_coursemodule_from_instance('wiki', $wiki->id);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
// Working depending on activity groupmode
switch (groups_get_activity_groupmode($cm)) {
case NOGROUPS:
if ($wiki->wikimode == 'collaborative') {
// Collaborative Mode:
// There is a wiki for all the class.
//
// Only edit capbility needed
return has_capability('mod/wiki:editpage', $context);
} else {
if ($wiki->wikimode == 'individual') {
// Individual Mode
// There is a wiki per user
// Only the owner of that wiki can edit it
if ($subwiki->userid == $USER->id) {
return has_capability('mod/wiki:editpage', $context);
} else {
// Current user is not the owner of that wiki.
// User must have:
// mod/wiki:editpage capability
// and
// mod/wiki:managewiki capability
$edit = has_capability('mod/wiki:editpage', $context);
$manage = has_capability('mod/wiki:managewiki', $context);
return $edit && $manage;
}
} else {
//Error
return false;
}
}
case SEPARATEGROUPS:
if ($wiki->wikimode == 'collaborative') {
// Collaborative Mode:
// There is one wiki per group.
//
// Only members of subwiki group could edit that wiki
if ($subwiki->groupid == groups_get_activity_group($cm)) {
// Only edit capability needed
return has_capability('mod/wiki:editpage', $context);
} else {
// User is not part of that group
// User must have:
// mod/wiki:managewiki capability
// and
// moodle/site:accessallgroups capability
// and
// mod/wiki:editpage capability
$manage = has_capability('mod/wiki:managewiki', $context);
$access = has_capability('moodle/site:accessallgroups', $context);
$edit = has_capability('mod/wiki:editpage', $context);
return $manage && $access && $edit;
}
} else {
if ($wiki->wikimode == 'individual') {
// Individual Mode:
// Each person owns a wiki.
//
// Only the owner of that wiki can edit it
if ($subwiki->userid == $USER->id) {
return has_capability('mod/wiki:editpage', $context);
} else {
// Current user is not the owner of that wiki.
// User must have:
// mod/wiki:managewiki capability
// and
// moodle/site:accessallgroups capability
// and
// mod/wiki:editpage capability
$manage = has_capability('mod/wiki:managewiki', $context);
$access = has_capability('moodle/site:accessallgroups', $context);
$edit = has_capability('mod/wiki:editpage', $context);
return $manage && $access && $edit;
}
} else {
//Error
return false;
}
}
case VISIBLEGROUPS:
if ($wiki->wikimode == 'collaborative') {
// Collaborative Mode:
// There is one wiki per group.
//
// Only members of subwiki group could edit that wiki
if (groups_is_member($subwiki->groupid)) {
// Only edit capability needed
return has_capability('mod/wiki:editpage', $context);
} else {
//.........这里部分代码省略.........
示例3: wiki_extend_navigation
function wiki_extend_navigation(navigation_node $navref, $course, $module, $cm)
{
global $CFG, $PAGE, $USER;
require_once $CFG->dirroot . '/mod/wiki/locallib.php';
$context = context_module::instance($cm->id);
$url = $PAGE->url;
$userid = 0;
if ($module->wikimode == 'individual') {
$userid = $USER->id;
}
if (!($wiki = wiki_get_wiki($cm->instance))) {
return false;
}
if (!($gid = groups_get_activity_group($cm))) {
$gid = 0;
}
if (!($subwiki = wiki_get_subwiki_by_group($cm->instance, $gid, $userid))) {
return null;
} else {
$swid = $subwiki->id;
}
$pageid = $url->param('pageid');
$cmid = $url->param('id');
if (empty($pageid) && !empty($cmid)) {
// wiki main page
$page = wiki_get_page_by_title($swid, $wiki->firstpagetitle);
$pageid = $page->id;
}
if (wiki_can_create_pages($context)) {
$link = new moodle_url('/mod/wiki/create.php', array('action' => 'new', 'swid' => $swid));
$node = $navref->add(get_string('newpage', 'wiki'), $link, navigation_node::TYPE_SETTING);
}
if (is_numeric($pageid)) {
if (has_capability('mod/wiki:viewpage', $context)) {
$link = new moodle_url('/mod/wiki/view.php', array('pageid' => $pageid));
$node = $navref->add(get_string('view', 'wiki'), $link, navigation_node::TYPE_SETTING);
}
if (wiki_user_can_edit($subwiki)) {
$link = new moodle_url('/mod/wiki/edit.php', array('pageid' => $pageid));
$node = $navref->add(get_string('edit', 'wiki'), $link, navigation_node::TYPE_SETTING);
}
if (has_capability('mod/wiki:viewcomment', $context)) {
$link = new moodle_url('/mod/wiki/comments.php', array('pageid' => $pageid));
$node = $navref->add(get_string('comments', 'wiki'), $link, navigation_node::TYPE_SETTING);
}
if (has_capability('mod/wiki:viewpage', $context)) {
$link = new moodle_url('/mod/wiki/history.php', array('pageid' => $pageid));
$node = $navref->add(get_string('history', 'wiki'), $link, navigation_node::TYPE_SETTING);
}
if (has_capability('mod/wiki:viewpage', $context)) {
$link = new moodle_url('/mod/wiki/map.php', array('pageid' => $pageid));
$node = $navref->add(get_string('map', 'wiki'), $link, navigation_node::TYPE_SETTING);
}
if (has_capability('mod/wiki:viewpage', $context)) {
$link = new moodle_url('/mod/wiki/files.php', array('pageid' => $pageid));
$node = $navref->add(get_string('files', 'wiki'), $link, navigation_node::TYPE_SETTING);
}
if (has_capability('mod/wiki:managewiki', $context)) {
$link = new moodle_url('/mod/wiki/admin.php', array('pageid' => $pageid));
$node = $navref->add(get_string('admin', 'wiki'), $link, navigation_node::TYPE_SETTING);
}
}
}
示例4: print_error
// 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);
$subwiki = wiki_get_subwiki($subwikiid);
}
} else {
// no group
if (!($subwiki = wiki_get_subwiki($page->subwikiid))) {
print_error('incorrectsubwikiid', 'wiki');
}
// Checking wiki instance of that subwiki
if (!($wiki = wiki_get_wiki($subwiki->wikiid))) {
print_error('incorrectwikiid', 'wiki');
}
}
// Checking course module instance
if (!($cm = get_coursemodule_from_instance("wiki", $subwiki->wikiid))) {
print_error('invalidcoursemodule');
}
// Checking course instance
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$context = context_module::instance($cm->id);
$PAGE->set_url('/mod/wiki/files.php', array('pageid' => $pageid));
require_login($course, true, $cm);
if (!wiki_user_can_view($subwiki, $wiki)) {
print_error('cannotviewfiles', 'wiki');
}
示例5: optional_param
$uid = optional_param('uid', 0, PARAM_INT);
// 'create' action must be submitted by moodle form
// so sesskey must be checked
if ($action == 'create') {
if (!confirm_sesskey()) {
print_error('invalidsesskey');
}
}
if (!empty($swid)) {
$subwiki = wiki_get_subwiki($swid);
if (!($wiki = wiki_get_wiki($subwiki->wikiid))) {
print_error('incorrectwikiid', 'wiki');
}
} else {
$subwiki = wiki_get_subwiki_by_group($wid, $group, $uid);
if (!($wiki = wiki_get_wiki($wid))) {
print_error('incorrectwikiid', 'wiki');
}
}
if (!($cm = get_coursemodule_from_instance('wiki', $wiki->id))) {
print_error('invalidcoursemodule');
}
$groups = new stdClass();
if (groups_get_activity_groupmode($cm)) {
$modulecontext = context_module::instance($cm->id);
$canaccessgroups = has_capability('moodle/site:accessallgroups', $modulecontext);
if ($canaccessgroups) {
$groups->availablegroups = groups_get_all_groups($cm->course);
$allpart = new stdClass();
$allpart->id = '0';
$allpart->name = get_string('allparticipants');
示例6: new_page
/**
* Creates a new page.
*
* @param string $title New page title.
* @param string $content Page contents.
* @param int $contentformat Page contents format. If an invalid format is provided, default wiki format is used.
* @param int $subwikiid The Subwiki ID where to store the page.
* @param int $wikiid Page\'s wiki ID. Used if subwiki does not exists.
* @param int $userid Subwiki\'s user ID. Used if subwiki does not exists.
* @param int $groupid Subwiki\'s group ID. Used if subwiki does not exists.
* @return array of warnings and page data.
* @since Moodle 3.1
*/
public static function new_page($title, $content, $contentformat = null, $subwikiid = null, $wikiid = null, $userid = null, $groupid = null)
{
global $USER;
$params = self::validate_parameters(self::new_page_parameters(), array('title' => $title, 'content' => $content, 'contentformat' => $contentformat, 'subwikiid' => $subwikiid, 'wikiid' => $wikiid, 'userid' => $userid, 'groupid' => $groupid));
$warnings = array();
// Get wiki and subwiki instances.
if (!empty($params['subwikiid'])) {
if (!($subwiki = wiki_get_subwiki($params['subwikiid']))) {
throw new moodle_exception('incorrectsubwikiid', 'wiki');
}
if (!($wiki = wiki_get_wiki($subwiki->wikiid))) {
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);
} else {
if (!($wiki = wiki_get_wiki($params['wikiid']))) {
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);
// 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) {
// User cannot view page.
throw new moodle_exception('cannoteditpage', 'wiki');
} else {
if ($subwiki->id < 0) {
// Subwiki needed to check edit permissions.
if (!wiki_user_can_edit($subwiki)) {
throw new moodle_exception('cannoteditpage', 'wiki');
}
// Subwiki does not exists and it can be created.
$swid = wiki_add_subwiki($wiki->id, $groupid, $userid);
if (!($subwiki = wiki_get_subwiki($swid))) {
throw new moodle_exception('incorrectsubwikiid', 'wiki');
}
}
}
}
// Subwiki needed to check edit permissions.
if (!wiki_user_can_edit($subwiki)) {
throw new moodle_exception('cannoteditpage', 'wiki');
}
if ($page = wiki_get_page_by_title($subwiki->id, $params['title'])) {
throw new moodle_exception('pageexists', 'wiki');
}
// Ignore invalid formats and use default instead.
if (!$params['contentformat'] || $wiki->forceformat) {
$params['contentformat'] = $wiki->defaultformat;
} else {
$formats = wiki_get_formats();
if (!in_array($params['contentformat'], $formats)) {
$params['contentformat'] = $wiki->defaultformat;
}
}
$newpageid = wiki_create_page($subwiki->id, $params['title'], $params['contentformat'], $USER->id);
if (!($page = wiki_get_page($newpageid))) {
throw new moodle_exception('incorrectpageid', 'wiki');
}
// Save content.
$save = wiki_save_page($page, $params['content'], $USER->id);
if (!$save) {
throw new moodle_exception('savingerror', 'wiki');
}
$result = array();
$result['pageid'] = $page->id;
$result['warnings'] = $warnings;
return $result;
}
示例7: optional_param
require_once $CFG->dirroot . '/mod/wiki/pagelib.php';
$search = optional_param('searchstring', null, PARAM_ALPHANUMEXT);
$courseid = optional_param('courseid', 0, PARAM_INT);
$searchcontent = optional_param('searchwikicontent', 0, PARAM_INT);
$cmid = optional_param('cmid', 0, PARAM_INT);
$subwikiid = optional_param('subwikiid', 0, PARAM_INT);
$userid = optional_param('uid', 0, PARAM_INT);
if (!($course = $DB->get_record('course', array('id' => $courseid)))) {
print_error('invalidcourseid');
}
if (!($cm = get_coursemodule_from_id('wiki', $cmid))) {
print_error('invalidcoursemodule');
}
require_login($course, true, $cm);
// Checking wiki instance
if (!($wiki = wiki_get_wiki($cm->instance))) {
print_error('incorrectwikiid', 'wiki');
}
if ($subwikiid) {
// Subwiki id is specified.
$subwiki = wiki_get_subwiki($subwikiid);
if (!$subwiki || $subwiki->wikiid != $wiki->id) {
print_error('incorrectsubwikiid', 'wiki');
}
} else {
// Getting current group id
$gid = groups_get_activity_group($cm);
// Getting current user id
if ($wiki->wikimode == 'individual') {
$userid = $userid ? $userid : $USER->id;
} else {
示例8: wiki_git_commit
function wiki_git_commit($arr)
{
$files = array_key_exists('files', $arr) ? $arr['files'] : null;
$commit_msg = array_key_exists('commit_msg', $arr) ? $arr['commit_msg'] : 'Repo updated';
$resource_id = array_key_exists('resource_id', $arr) ? $arr['resource_id'] : json_return_and_die(array('message' => 'Wiki resource_id required for git commit', 'success' => false));
$observer = array_key_exists('observer', $arr) ? $arr['observer'] : json_return_and_die(array('message' => 'Observer required for git commit', 'success' => false));
$w = wiki_get_wiki($resource_id);
if (!$w['path']) {
return array('message' => 'Error reading wiki', 'success' => false);
}
$reponame = array_key_exists('title', $w['wiki']) ? urlencode($w['wiki']['title']) : 'repo';
if ($reponame === '') {
$reponame = 'repo';
}
$git = new GitRepo($observer['xchan_addr'], null, false, $w['wiki']['title'], $w['path']);
try {
$git->setIdentity($observer['xchan_name'], $observer['xchan_addr']);
if ($files === null) {
$options = array('all' => true);
// git commit option to include all changes
} else {
$options = array();
// git commit options
foreach ($files as $file) {
if (!$git->git->add($file)) {
// add specified files to the git repo stage
if (!$git->git->reset->hard()) {
json_return_and_die(array('message' => 'Error adding file to git stage: ' . $file . '. Error resetting git repo.', 'success' => false));
}
json_return_and_die(array('message' => 'Error adding file to git stage: ' . $file, 'success' => false));
}
}
}
if ($git->commit($commit_msg, $options)) {
json_return_and_die(array('message' => 'Wiki repo commit succeeded', 'success' => true));
} else {
json_return_and_die(array('message' => 'Wiki repo commit failed', 'success' => false));
}
} catch (\PHPGit\Exception\GitException $e) {
json_return_and_die(array('message' => 'GitRepo error thrown', 'success' => false));
}
}
示例9: view_wiki
/**
* Trigger the course module viewed event and update the module completion status.
*
* @param int $wikiid The wiki instance ID.
* @return array of warnings and status result.
* @since Moodle 3.1
*/
public static function view_wiki($wikiid)
{
$params = self::validate_parameters(self::view_wiki_parameters(), array('wikiid' => $wikiid));
$warnings = array();
// Get wiki instance.
if (!($wiki = wiki_get_wiki($params['wikiid']))) {
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.
// We don't use wiki_user_can_view because it requires to have a valid subwiki for the user.
if (!has_capability('mod/wiki:viewpage', $context)) {
throw new moodle_exception('cannotviewpage', 'wiki');
}
// Trigger course_module_viewed event and completion.
wiki_view($wiki, $course, $cm, $context);
$result = array();
$result['status'] = true;
$result['warnings'] = $warnings;
return $result;
}
示例10: post
function post()
{
require_once 'include/wiki.php';
// /wiki/channel/preview
// Render mardown-formatted text in HTML for preview
if (argc() > 2 && argv(2) === 'preview') {
$content = $_POST['content'];
$resource_id = $_POST['resource_id'];
require_once 'library/markdown.php';
$html = wiki_generate_toc(purify_html(Markdown($content)));
$w = wiki_get_wiki($resource_id);
$wikiURL = argv(0) . '/' . argv(1) . '/' . $w['urlName'];
$html = wiki_convert_links($html, $wikiURL);
json_return_and_die(array('html' => $html, 'success' => true));
}
// Create a new wiki
// /wiki/channel/create/wiki
if (argc() > 3 && argv(2) === 'create' && argv(3) === 'wiki') {
$nick = argv(1);
$channel = get_channel_by_nick($nick);
// Determine if observer has permission to create wiki
$observer_hash = get_observer_hash();
// Only the channel owner can create a wiki, at least until we create a
// more detail permissions framework
if (local_channel() !== intval($channel['channel_id'])) {
goaway('/' . argv(0) . '/' . $nick . '/');
}
$wiki = array();
// Generate new wiki info from input name
$wiki['postVisible'] = intval($_POST['postVisible']) === 0 ? 0 : 1;
$wiki['rawName'] = $_POST['wikiName'];
$wiki['htmlName'] = escape_tags($_POST['wikiName']);
$wiki['urlName'] = urlencode($_POST['wikiName']);
if ($wiki['urlName'] === '') {
notice('Error creating wiki. Invalid name.');
goaway('/wiki');
}
// Get ACL for permissions
$acl = new \Zotlabs\Access\AccessList($channel);
$acl->set_from_array($_POST);
$r = wiki_create_wiki($channel, $observer_hash, $wiki, $acl);
if ($r['success']) {
$homePage = wiki_create_page('Home', $r['item']['resource_id']);
if (!$homePage['success']) {
notice('Wiki created, but error creating Home page.');
goaway('/wiki/' . $nick . '/' . $wiki['urlName']);
}
goaway('/wiki/' . $nick . '/' . $wiki['urlName'] . '/' . $homePage['page']['urlName']);
} else {
notice('Error creating wiki');
goaway('/wiki');
}
}
// Delete a wiki
if (argc() > 3 && argv(2) === 'delete' && argv(3) === 'wiki') {
$nick = argv(1);
$channel = get_channel_by_nick($nick);
// Only the channel owner can delete a wiki, at least until we create a
// more detail permissions framework
if (local_channel() !== intval($channel['channel_id'])) {
logger('Wiki delete permission denied.' . EOL);
json_return_and_die(array('message' => 'Wiki delete permission denied.', 'success' => false));
}
$resource_id = $_POST['resource_id'];
$deleted = wiki_delete_wiki($resource_id);
if ($deleted['success']) {
json_return_and_die(array('message' => '', 'success' => true));
} else {
logger('Error deleting wiki: ' . $resource_id);
json_return_and_die(array('message' => 'Error deleting wiki', 'success' => false));
}
}
// Create a page
if (argc() === 4 && argv(2) === 'create' && argv(3) === 'page') {
$nick = argv(1);
$resource_id = $_POST['resource_id'];
// Determine if observer has permission to create a page
$channel = get_channel_by_nick($nick);
if (local_channel() !== intval($channel['channel_id'])) {
$observer_hash = get_observer_hash();
$perms = wiki_get_permissions($resource_id, intval($channel['channel_id']), $observer_hash);
if (!$perms['write']) {
logger('Wiki write permission denied. ' . EOL);
json_return_and_die(array('success' => false));
}
}
$name = $_POST['name'];
//Get new page name
if (urlencode(escape_tags($_POST['name'])) === '') {
json_return_and_die(array('message' => 'Error creating page. Invalid name.', 'success' => false));
}
$page = wiki_create_page($name, $resource_id);
if ($page['success']) {
json_return_and_die(array('url' => '/' . argv(0) . '/' . argv(1) . '/' . $page['wiki']['urlName'] . '/' . urlencode($page['page']['urlName']), 'success' => true));
} else {
logger('Error creating page');
json_return_and_die(array('message' => 'Error creating page.', 'success' => false));
}
}
// Fetch page list for a wiki
//.........这里部分代码省略.........
示例11: get_subwikis
/**
* Returns the list of subwikis the user can see in a specific wiki.
*
* @param int $wikiid The wiki instance ID.
* @return array Containing a list of warnings and a list of subwikis.
* @since Moodle 3.1
*/
public static function get_subwikis($wikiid)
{
global $USER;
$warnings = array();
$params = self::validate_parameters(self::get_subwikis_parameters(), array('wikiid' => $wikiid));
// Get wiki instance.
if (!($wiki = wiki_get_wiki($params['wikiid']))) {
throw new moodle_exception('incorrectwikiid', 'wiki');
}
// Validate context and capabilities.
list($course, $cm) = get_course_and_cm_from_instance($wiki, 'wiki');
$context = context_module::instance($cm->id);
self::validate_context($context);
require_capability('mod/wiki:viewpage', $context);
$returnedsubwikis = wiki_get_visible_subwikis($wiki, $cm, $context);
foreach ($returnedsubwikis as $subwiki) {
$subwiki->canedit = wiki_user_can_edit($subwiki);
}
$result = array();
$result['subwikis'] = $returnedsubwikis;
$result['warnings'] = $warnings;
return $result;
}
示例12: get_subwiki_pages
/**
* 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;
}
}
//.........这里部分代码省略.........