本文整理汇总了PHP中wiki_create_page函数的典型用法代码示例。如果您正苦于以下问题:PHP wiki_create_page函数的具体用法?PHP wiki_create_page怎么用?PHP wiki_create_page使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wiki_create_page函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_tag_removed
/**
* Test the tag removed event.
*/
public function test_tag_removed()
{
global $DB;
$this->setAdminUser();
// Create a course to tag.
$course = $this->getDataGenerator()->create_course();
// Create a wiki page to tag.
$wikigenerator = $this->getDataGenerator()->get_plugin_generator('mod_wiki');
$wiki = $wikigenerator->create_instance(array('course' => $course->id));
$subwikiid = wiki_add_subwiki($wiki->id, 0);
$wikipageid = wiki_create_page($subwikiid, 'Title', FORMAT_HTML, '2');
// Create the tag.
$tag = $this->getDataGenerator()->create_tag();
// Assign a tag to a course.
tag_assign('course', $course->id, $tag->id, 1, 2, 'core', context_course::instance($course->id)->id);
// Trigger and capture the event for untagging a course.
$sink = $this->redirectEvents();
coursetag_delete_keyword($tag->id, 2, $course->id);
$events = $sink->get_events();
$event = reset($events);
// Check that the tag was removed from the course and the event data is valid.
$this->assertEquals(0, $DB->count_records('tag_instance'));
$this->assertInstanceOf('\\core\\event\\tag_removed', $event);
$this->assertEquals(context_course::instance($course->id), $event->get_context());
// Create the tag.
$tag = $this->getDataGenerator()->create_tag();
// Assign a tag to a wiki this time.
tag_assign('wiki_pages', $wikipageid, $tag->id, 1, 2, 'mod_wiki', context_module::instance($wiki->cmid)->id);
// Trigger and capture the event for deleting this tag instance.
$sink = $this->redirectEvents();
tag_delete_instance('wiki_pages', $wikipageid, $tag->id);
$events = $sink->get_events();
$event = reset($events);
// Check that tag was removed from the wiki page and the event data is valid.
$this->assertEquals(0, $DB->count_records('tag_instance'));
$this->assertInstanceOf('\\core\\event\\tag_removed', $event);
$this->assertEquals(context_module::instance($wiki->cmid), $event->get_context());
// Create a tag again - the other would have been deleted since there were no more instances associated with it.
$tag = $this->getDataGenerator()->create_tag();
// Assign a tag to the wiki again.
tag_assign('wiki_pages', $wikipageid, $tag->id, 1, 2, 'mod_wiki', context_module::instance($wiki->cmid)->id);
// Now we want to delete this tag, and because there is only one tag instance
// associated with it, it should get deleted as well.
$sink = $this->redirectEvents();
tag_delete($tag->id);
$events = $sink->get_events();
$event = reset($events);
// Check that tag was removed from the wiki page and the event data is valid.
$this->assertEquals(0, $DB->count_records('tag_instance'));
$this->assertInstanceOf('\\core\\event\\tag_removed', $event);
$this->assertEquals(context_module::instance($wiki->cmid), $event->get_context());
// Create a tag again - the other would have been deleted since there were no more instances associated with it.
$tag = $this->getDataGenerator()->create_tag();
// Assign a tag to the wiki again.
tag_assign('wiki_pages', $wikipageid, $tag->id, 1, 2, 'mod_wiki', context_module::instance($wiki->cmid)->id);
// Delete all tag instances for this wiki instance.
$sink = $this->redirectEvents();
tag_delete_instances('mod_wiki', context_module::instance($wiki->cmid)->id);
$events = $sink->get_events();
$event = reset($events);
// Check that tag was removed from the wiki page and the event data is valid.
$this->assertEquals(0, $DB->count_records('tag_instance'));
$this->assertInstanceOf('\\core\\event\\tag_removed', $event);
$this->assertEquals(context_module::instance($wiki->cmid), $event->get_context());
// Create another wiki.
$wiki2 = $wikigenerator->create_instance(array('course' => $course->id));
$subwikiid2 = wiki_add_subwiki($wiki2->id, 0);
$wikipageid2 = wiki_create_page($subwikiid2, 'Title', FORMAT_HTML, '2');
// Assign a tag to both wiki pages.
tag_assign('wiki_pages', $wikipageid, $tag->id, 1, 2, 'mod_wiki', context_module::instance($wiki->cmid)->id);
tag_assign('wiki_pages', $wikipageid2, $tag->id, 1, 2, 'mod_wiki', context_module::instance($wiki2->cmid)->id);
// Now remove all tag_instances associated with all wikis.
$sink = $this->redirectEvents();
tag_delete_instances('mod_wiki');
$events = $sink->get_events();
// There will be two events - one for each wiki instance removed.
$event1 = reset($events);
$event2 = $events[1];
// Check that the tags were removed from the wiki pages.
$this->assertEquals(0, $DB->count_records('tag_instance'));
// Check the first event data is valid.
$this->assertInstanceOf('\\core\\event\\tag_removed', $event1);
$this->assertEquals(context_module::instance($wiki->cmid), $event1->get_context());
// Check that the second event data is valid.
$this->assertInstanceOf('\\core\\event\\tag_removed', $event2);
$this->assertEquals(context_module::instance($wiki2->cmid), $event2->get_context());
}
示例2: create_page
function create_page($pagetitle) {
global $USER, $PAGE;
$data = $this->mform->get_data();
if (isset($data->groupinfo)) {
$groupid = $data->groupinfo;
} else if (!empty($this->gid)) {
$groupid = $this->gid;
} else {
$groupid = '0';
}
if (empty($this->subwiki)) {
// If subwiki is not set then try find one and set else create one.
if (!$this->subwiki = wiki_get_subwiki_by_group($this->wid, $groupid, $this->uid)) {
$swid = wiki_add_subwiki($PAGE->activityrecord->id, $groupid, $this->uid);
$this->subwiki = wiki_get_subwiki($swid);
}
}
if ($data) {
$this->set_title($data->pagetitle);
$id = wiki_create_page($this->subwiki->id, $data->pagetitle, $data->pageformat, $USER->id);
} else {
$this->set_title($pagetitle);
$id = wiki_create_page($this->subwiki->id, $pagetitle, $PAGE->activityrecord->defaultformat, $USER->id);
}
$this->page = $id;
return $id;
}
示例3: create_page
function create_page($pagetitle)
{
global $USER, $PAGE;
$data = $this->mform->get_data();
if (isset($data->groupinfo)) {
$groupid = $data->groupinfo;
} else {
$groupid = '0';
}
if (!($this->subwiki = wiki_get_subwiki_by_group($this->wid, $groupid))) {
$swid = wiki_add_subwiki($PAGE->activityrecord->id, $groupid, $this->uid);
$this->subwiki = wiki_get_subwiki($swid);
}
if ($data) {
$this->set_title($data->pagetitle);
$id = wiki_create_page($this->subwiki->id, $data->pagetitle, $data->pageformat, $USER->id);
} else {
$this->set_title($pagetitle);
$id = wiki_create_page($this->subwiki->id, $pagetitle, $PAGE->activityrecord->defaultformat, $USER->id);
}
$this->page = $id;
return $id;
}
示例4: create_page
function create_page($pagetitle)
{
global $USER, $CFG, $PAGE;
$data = $this->mform->get_data();
if (empty($this->subwiki)) {
$swid = wiki_add_subwiki($PAGE->activityrecord->id, $this->gid, $this->uid);
$this->subwiki = wiki_get_subwiki($swid);
}
if ($data) {
$id = wiki_create_page($this->subwiki->id, $data->pagetitle, $data->pageformat, $USER->id);
} else {
$id = wiki_create_page($this->subwiki->id, $pagetitle, $PAGE->activityrecord->defaultformat, $USER->id);
}
redirect($CFG->wwwroot . '/mod/wiki/edit.php?pageid=' . $id);
}
示例5: 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;
}
示例6: create_page
function create_page($pagetitle) {
global $USER, $CFG, $PAGE;
$data = $this->mform->get_data();
if (empty($this->subwiki)) {
$swid = wiki_add_subwiki($PAGE->activityrecord->id, $this->gid, $this->uid);
$this->subwiki = wiki_get_subwiki($swid);
}
if ($data) {
$this->set_title($data->pagetitle);
$id = wiki_create_page($this->subwiki->id, $data->pagetitle, $data->pageformat, $USER->id);
} else {
$this->set_title($pagetitle);
$id = wiki_create_page($this->subwiki->id, $pagetitle, $PAGE->activityrecord->defaultformat, $USER->id);
}
$this->page = $id;
return $id;
}
示例7: create_page
/**
* 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'];
}
示例8: create_page
/**
* 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'];
}
示例9: 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
//.........这里部分代码省略.........