本文整理汇总了PHP中wiki_save_page函数的典型用法代码示例。如果您正苦于以下问题:PHP wiki_save_page函数的具体用法?PHP wiki_save_page怎么用?PHP wiki_save_page使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wiki_save_page函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wiki_restore_page
/**
* Restore a page
*/
function wiki_restore_page($wikipage, $newcontent, $userid)
{
$return = wiki_save_page($wikipage, $newcontent, $userid);
return $return['page'];
}
示例2: wiki_restore_page
/**
* Restore a page with specified version.
*
* @param stdClass $wikipage wiki page record
* @param stdClass $version wiki page version to restore
* @param context_module $context context of wiki module
* @return stdClass restored page
*/
function wiki_restore_page($wikipage, $version, $context)
{
$return = wiki_save_page($wikipage, $version->content, $version->userid);
$event = \mod_wiki\event\page_version_restored::create(array('context' => $context, 'objectid' => $version->id, 'other' => array('pageid' => $wikipage->id)));
$event->add_record_snapshot('wiki_versions', $version);
$event->trigger();
return $return['page'];
}
示例3: print_save
protected function print_save() {
global $CFG, $USER, $OUTPUT, $PAGE;
$url = $CFG->wwwroot . '/mod/wiki/edit.php?pageid=' . $this->page->id;
if (!empty($this->section)) {
$url .= "§ion=" . urlencode($this->section);
}
$params = array(
'attachmentoptions' => page_wiki_edit::$attachmentoptions,
'format' => $this->format,
'version' => $this->versionnumber,
'contextid' => $this->modcontext->id
);
if ($this->format != 'html') {
$params['fileitemid'] = $this->page->id;
$params['component'] = 'mod_wiki';
$params['filearea'] = 'attachments';
}
$form = new mod_wiki_edit_form($url, $params);
$save = false;
$data = false;
if ($data = $form->get_data()) {
if ($this->format == 'html') {
$data = file_postupdate_standard_editor($data, 'newcontent', page_wiki_edit::$attachmentoptions, $this->modcontext, 'mod_wiki', 'attachments', $this->subwiki->id);
}
if (isset($this->section)) {
$save = wiki_save_section($this->page, $this->section, $data->newcontent, $USER->id);
} else {
$save = wiki_save_page($this->page, $data->newcontent, $USER->id);
}
}
if ($save && $data) {
if (!empty($CFG->usetags)) {
tag_set('wiki_pages', $this->page->id, $data->tags);
}
$message = '<p>' . get_string('saving', 'wiki') . '</p>';
if (!empty($save['sections'])) {
foreach ($save['sections'] as $s) {
$message .= '<p>' . get_string('repeatedsection', 'wiki', $s) . '</p>';
}
}
if ($this->versionnumber + 1 != $save['version']) {
$message .= '<p>' . get_string('wrongversionsave', 'wiki') . '</p>';
}
if (isset($errors) && !empty($errors)) {
foreach ($errors as $e) {
$message .= "<p>" . get_string('filenotuploadederror', 'wiki', $e->get_filename()) . "</p>";
}
}
//deleting old locks
wiki_delete_locks($this->page->id, $USER->id, $this->section);
$url = new moodle_url('view.php', array('pageid' => $this->page->id, 'group' => $this->subwiki->groupid));
redirect($url);
} else {
print_error('savingerror', 'wiki');
}
}
示例4: edit_page
/**
* 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;
}
示例5: test_page_updated
/**
* Test page_updated event.
*/
public function test_page_updated()
{
global $USER;
$this->setUp();
$page = $this->wikigenerator->create_first_page($this->wiki);
$context = context_module::instance($this->wiki->cmid);
// Triggering and capturing the event.
$sink = $this->redirectEvents();
wiki_save_page($page, 'New content', $USER->id);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
// Checking that the event contains the expected values.
$this->assertInstanceOf('\\mod_wiki\\event\\page_updated', $event);
$this->assertEquals($context, $event->get_context());
$this->assertEquals($page->id, $event->objectid);
$expected = array($this->course->id, 'wiki', 'edit', 'view.php?pageid=' . $page->id, $page->id, $this->wiki->cmid);
$this->assertEventLegacyLogData($expected, $event);
$this->assertEventContextNotUsed($event);
}
示例6: wiki_blacklist
if (substr_count($logmessage, 'http:') > 0 and !trim($data)) {
wiki_blacklist($_SERVER['REMOTE_ADDR'], 'blanked page and spammed log');
}
foreach ($badtext as $badline) {
$badline = trim($badline);
if (preg_match("#{$badline}#", $data)) {
wiki_blacklist($_SERVER['REMOTE_ADDR'], "matched {$badline}");
}
}
/*
if(!($t = recode('UTF-7..UTF-8', recode('UTF-8..UTF-7', $data))) == $data) {
print("Invalid data: $t</body></html>");
exit();
}
*/
if (wiki_save_page($pagename, $data, $logmessage, $headers, $noindex)) {
http_302($_SERVER['SCRIPT_NAME'] . preg_replace('/(;.*$|$)/', '', pqurlencode($PATH_INFO)) . ";" . rcs_version_inc($Current));
ob_exit();
// } else {
// print("Somebody saved the page before you. You should
// probably make sure you didn't cover over what they wrote.
// ($srcversion < {$revisions[2]}). Your stuff is saved,
// though, and theirs isn't lost.");
// }
} else {
while (ob_get_level()) {
ob_end_clean();
}
die("An error occurred whilst saving the page: " . errmsg());
}
} elseif ($action == 'tag') {
示例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
//.........这里部分代码省略.........
$observer_hash = get_observer_hash();
if (local_channel() !== intval($channel['channel_id'])) {
$perms = wiki_get_permissions($resource_id, intval($channel['channel_id']), $observer_hash);
if (!$perms['read']) {
logger('Wiki read permission denied.' . EOL);
json_return_and_die(array('pages' => null, 'message' => 'Permission denied.', 'success' => false));
}
}
$page_list_html = widget_wiki_pages(array('resource_id' => $resource_id, 'refresh' => true, 'channel' => argv(1)));
json_return_and_die(array('pages' => $page_list_html, 'message' => '', 'success' => true));
}
// Save a page
if (argc() === 4 && argv(2) === 'save' && argv(3) === 'page') {
$resource_id = $_POST['resource_id'];
$pageUrlName = $_POST['name'];
$pageHtmlName = escape_tags($_POST['name']);
$content = $_POST['content'];
//Get new content
$commitMsg = $_POST['commitMsg'];
if ($commitMsg === '') {
$commitMsg = 'Updated ' . $pageHtmlName;
}
$nick = argv(1);
$channel = get_channel_by_nick($nick);
// Determine if observer has permission to save content
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));
}
}
$saved = wiki_save_page(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName, 'content' => $content));
if ($saved['success']) {
$ob = \App::get_observer();
$commit = wiki_git_commit(array('commit_msg' => $commitMsg, 'resource_id' => $resource_id, 'observer' => $ob, 'files' => array($pageUrlName . '.md')));
if ($commit['success']) {
json_return_and_die(array('message' => 'Wiki git repo commit made', 'success' => true));
} else {
json_return_and_die(array('message' => 'Error making git commit', 'success' => false));
}
} else {
json_return_and_die(array('message' => 'Error saving page', 'success' => false));
}
}
// Update page history
// /wiki/channel/history/page
if (argc() === 4 && argv(2) === 'history' && argv(3) === 'page') {
$resource_id = $_POST['resource_id'];
$pageUrlName = $_POST['name'];
$nick = argv(1);
$channel = get_channel_by_nick($nick);
// Determine if observer has permission to read content
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['read']) {
logger('Wiki read permission denied.' . EOL);
json_return_and_die(array('historyHTML' => '', 'message' => 'Permission denied.', 'success' => false));
}
}
$historyHTML = widget_wiki_page_history(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
json_return_and_die(array('historyHTML' => $historyHTML, 'message' => '', 'success' => true));
}
// Delete a page
示例10: while
//LOAD PLUGINS
if ($handle = opendir($GLOBALS['dir']['plugins'])) {
while ($plugin = readdir($handle)) {
if ($plugin[0] != '.' && $plugin[0] != '_' && !is_dir($plugin = $GLOBALS['dir']['plugins'] . $plugin)) {
if (!(include_once $plugin)) {
wiki_perror("Failed to load plugin: {$plugin}");
}
}
}
closedir($handle);
}
//do nothing if included...
if (!isset($wiki_include)) {
//Handle POSTs (edit)
if (isset($_POST['content']) && $_POST['content'] != '') {
if (@wiki_check_pass($_POST['passwd'])) {
wiki_save_page($page, $_POST['content']);
}
}
//Handle GETs (render)
$template_file = $dir['templates'] . $template . $template_ext;
if (@($_GET['template'] === 'plaintext')) {
die(wiki_page_plain());
}
if (@($_GET['template'] === 'html') || !@(include $template_file)) {
/*echo("<!-- IT'S STRANGE, BUT THIS PAGE WAS RENDERED WITHOUT USE OF TEMPLATES\n".
"IF YOU HAVEN'T DISABLED TEMPLATES INTENTIONALY, PLEASE CHECK CONFIGURATION. -->\n"
);*/
wiki_page_content();
}
}