aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Zotlabs/Module/Wiki.php44
-rw-r--r--include/wiki.php22
-rw-r--r--view/tpl/wiki.tpl23
3 files changed, 83 insertions, 6 deletions
diff --git a/Zotlabs/Module/Wiki.php b/Zotlabs/Module/Wiki.php
index a53cb3f6a..5d293e6f0 100644
--- a/Zotlabs/Module/Wiki.php
+++ b/Zotlabs/Module/Wiki.php
@@ -51,6 +51,7 @@ class Wiki extends \Zotlabs\Web\Controller {
);
$resource_id = '';
+ $pagename = '';
if(argc()>2) {
// Check if wiki exists andr redirect if it does not
$channel = get_channel_by_nick(argv(1));
@@ -68,12 +69,13 @@ class Wiki extends \Zotlabs\Web\Controller {
$showPageControls = false;
} elseif (argc()<4) {
$wikiheader = rawurldecode(argv(2)); // show wiki name
- $content = '';
+ $content = '""';
$hide_editor = true;
$showPageControls = true;
} elseif (argc()<5) {
- $wikiheader = rawurldecode(argv(2)) . ': ' . rawurldecode(argv(3)); // show wiki name and page
- $p = wiki_get_page_content(array('wiki_resource_id' => $resource_id, 'page' => argv(3)));
+ $pagename = argv(3);
+ $wikiheader = rawurldecode(argv(2)) . ': ' . rawurldecode($pagename); // show wiki name and page
+ $p = wiki_get_page_content(array('wiki_resource_id' => $resource_id, 'page' => $pagename));
if(!$p['success']) {
logger('Error getting page content');
$content = 'Error retrieving page content. Try again.';
@@ -82,7 +84,6 @@ class Wiki extends \Zotlabs\Web\Controller {
$hide_editor = false;
$showPageControls = true;
}
-
$parsedown = new Parsedown();
$renderedContent = $parsedown->text(json_decode($content));
@@ -92,6 +93,7 @@ class Wiki extends \Zotlabs\Web\Controller {
'$showPageControls' => $showPageControls,
'$channel' => $channel['channel_address'],
'$resource_id' => $resource_id,
+ '$page' => $pagename,
'$lockstate' => $x['lockstate'],
'$acl' => $x['acl'],
'$bang' => $x['bang'],
@@ -238,6 +240,40 @@ class Wiki extends \Zotlabs\Web\Controller {
json_return_and_die(array('pages' => $page_list_html, 'message' => '', 'success' => true));
}
+ // Save a page
+ if ((argc() === 4) && (argv(2) === 'save') && (argv(3) === 'page')) {
+ $which = argv(1);
+ $resource_id = $_POST['resource_id'];
+ $pagename = escape_tags(urlencode($_POST['name']));
+ $content = escape_tags($_POST['content']); //Get new content
+ // Determine if observer has permission to create wiki
+ if (local_channel()) {
+ $channel = \App::get_channel();
+ } else {
+ $channel = get_channel_by_nick($which);
+ $observer_hash = get_observer_hash();
+ // Figure out who the page owner is.
+ $perms = get_all_perms(intval($channel['channel_id']), $observer_hash);
+ // TODO: Create a new permission setting for wiki analogous to webpages. Until
+ // then, use webpage permissions
+ if (!$perms['write_pages']) {
+ logger('Wiki editing permission denied.' . EOL);
+ json_return_and_die(array('success' => false));
+ }
+ $perms = wiki_get_permissions($resource_id, intval($channel['channel_id']), $observer_hash);
+ if(!$perms['write']) {
+ logger('Wiki write permission denied. Read only.' . EOL);
+ json_return_and_die(array('success' => false));
+ }
+ }
+ $saved = wiki_save_page(array('resource_id' => $resource_id, 'name' => $pagename, 'content' => $content));
+ if($saved['success']) {
+ json_return_and_die(array('success' => true));
+ } else {
+ json_return_and_die(array('success' => false));
+ }
+ }
+
//notice('You must be authenticated.');
json_return_and_die(array('message' => 'You must be authenticated.', 'success' => false));
diff --git a/include/wiki.php b/include/wiki.php
index f97036c29..e01cc12c3 100644
--- a/include/wiki.php
+++ b/include/wiki.php
@@ -232,4 +232,26 @@ function wiki_get_page_content($arr) {
// TODO: Check that the files are all text files
return array('content' => json_encode($content), 'message' => '', 'success' => true);
}
+}
+
+
+function wiki_save_page($arr) {
+ $pagename = ((array_key_exists('name',$arr)) ? $arr['name'] : '');
+ $content = ((array_key_exists('content',$arr)) ? $arr['content'] : '');
+ $resource_id = ((array_key_exists('resource_id',$arr)) ? $arr['resource_id'] : '');
+ $w = wiki_get_wiki($resource_id);
+ if (!$w['path']) {
+ return array('message' => 'Error reading wiki', 'success' => false);
+ }
+ $page_path = $w['path'].'/'.$pagename;
+ if (is_writable($page_path) === true) {
+ if(!file_put_contents($page_path, $content)) {
+ return array('message' => 'Error writing to page file', 'success' => false);
+ }
+ return array('message' => '', 'success' => true);
+ } else {
+ return array('message' => 'Page file not writable', 'success' => false);
+ }
+
+
} \ No newline at end of file
diff --git a/view/tpl/wiki.tpl b/view/tpl/wiki.tpl
index 9610eea63..e931cd6e6 100644
--- a/view/tpl/wiki.tpl
+++ b/view/tpl/wiki.tpl
@@ -55,8 +55,8 @@
<li class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle" href="#">Page <b class="caret"></b></a>
<ul class="dropdown-menu">
- <li><a data-toggle="tab" href="#save">Save</a></li>
- <li><a data-toggle="tab" href="#delete">Delete</a></li>
+ <li><a id="save-page" data-toggle="tab" href="#">Save</a></li>
+ <li><a id="delete-page" data-toggle="tab" href="#">Delete</a></li>
</ul>
</li>
{{/if}}
@@ -79,6 +79,7 @@
<script>
window.wiki_resource_id = '{{$resource_id}}';
+ window.wiki_page_name = '{{$page}}';
$(document).ready(function () {
wiki_refresh_page_list();
// Show Edit tab first. Otherwise the Ace editor does not load.
@@ -150,4 +151,22 @@ function wiki_delete_wiki(wikiName, resource_id) {
}, 'json');
return false;
}
+
+ $('#save-page').click(function (ev) {
+ if (window.wiki_resource_id === '' || window.wiki_page_name === '') {
+ window.console.log('You must have a wiki page open in order to edit pages.');
+ ev.preventDefault();
+ return false;
+ }
+ $.post("wiki/{{$channel}}/save/page", {content: editor.getValue(), name: window.wiki_page_name, resource_id: window.wiki_resource_id},
+ function (data) {
+ if (data.success) {
+ window.console.log('Page saved successfully.');
+ } else {
+ alert('Error saving page.'); // TODO: Replace alerts with auto-timeout popups
+ window.console.log('Error saving page.');
+ }
+ }, 'json');
+ ev.preventDefault();
+ });
</script>