aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Zotlabs/Module/Wiki.php14
-rw-r--r--include/wiki.php23
-rw-r--r--view/tpl/wiki.tpl2
3 files changed, 35 insertions, 4 deletions
diff --git a/Zotlabs/Module/Wiki.php b/Zotlabs/Module/Wiki.php
index 54511fc91..76c07f2bc 100644
--- a/Zotlabs/Module/Wiki.php
+++ b/Zotlabs/Module/Wiki.php
@@ -63,12 +63,20 @@ class Wiki extends \Zotlabs\Web\Controller {
}
if(argc()<3) {
$wikiheader = t('Wiki Sandbox');
+ $content = '# Wiki Sandbox\nContent you **edit** and **preview** here *will not be saved*.';
$hide_editor = false;
} elseif (argc()<4) {
- $wikiheader = 'Empty wiki: ' . rawurldecode(argv(2)); // show wiki name
+ $wikiheader = rawurldecode(argv(2)); // show wiki name
+ $content = '';
$hide_editor = true;
} elseif (argc()<5) {
- $wikiheader = rawurldecode(argv(2)) . ': ' . rawurldecode(argv(3)); // show wiki name and page
+ $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)));
+ if(!$p['success']) {
+ logger('Error getting page content');
+ $content = 'Error retrieving page content. Try again.';
+ }
+ $content = $p['content'];
$hide_editor = false;
}
@@ -80,7 +88,7 @@ class Wiki extends \Zotlabs\Web\Controller {
'$lockstate' => $x['lockstate'],
'$acl' => $x['acl'],
'$bang' => $x['bang'],
- '$content' => '# Start your wiki',
+ '$content' => $content,
'$wikiName' => array('wikiName', t('Enter the name of your new wiki:'), '', ''),
'$pageName' => array('pageName', t('Enter the name of the new page:'), '', '')
));
diff --git a/include/wiki.php b/include/wiki.php
index c1779e208..f97036c29 100644
--- a/include/wiki.php
+++ b/include/wiki.php
@@ -210,3 +210,26 @@ function wiki_create_page($name, $resource_id) {
}
}
+
+function wiki_get_page_content($arr) {
+ $page = ((array_key_exists('page',$arr)) ? $arr['page'] : '');
+ // TODO: look for page resource_id and retrieve that way alternatively
+ $wiki_resource_id = ((array_key_exists('wiki_resource_id',$arr)) ? $arr['wiki_resource_id'] : '');
+ $w = wiki_get_wiki($wiki_resource_id);
+ if (!$w['path']) {
+ return array('content' => null, 'message' => 'Error reading wiki', 'success' => false);
+ }
+ $page_path = $w['path'].'/'.$page;
+ if (is_readable($page_path) === true) {
+ if(filesize($page_path) === 0) {
+ $content = '';
+ } else {
+ $content = file_get_contents($page_path);
+ if(!$content) {
+ return array('content' => null, 'message' => 'Error reading page content', 'success' => false);
+ }
+ }
+ // TODO: Check that the files are all text files
+ return array('content' => json_encode($content), 'message' => '', 'success' => true);
+ }
+} \ No newline at end of file
diff --git a/view/tpl/wiki.tpl b/view/tpl/wiki.tpl
index a18831aa5..26258e7c2 100644
--- a/view/tpl/wiki.tpl
+++ b/view/tpl/wiki.tpl
@@ -86,7 +86,7 @@
var editor = ace.edit("ace-editor");
editor.setTheme("ace/theme/github");
editor.getSession().setMode("ace/mode/markdown");
- editor.getSession().setValue('{{$content}}');
+ editor.getSession().setValue({{$content}});
$('#wiki-get-preview').click(function (ev) {
$.post("wiki/{{$channel}}/preview", {content: editor.getValue()}, function (data) {