aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Zotlabs/Module/Wiki.php20
-rw-r--r--include/widgets.php19
-rw-r--r--include/wiki.php38
-rw-r--r--view/tpl/wiki.tpl17
-rw-r--r--view/tpl/wiki_page_list.tpl2
5 files changed, 81 insertions, 15 deletions
diff --git a/Zotlabs/Module/Wiki.php b/Zotlabs/Module/Wiki.php
index 909b2c84d..9d905f561 100644
--- a/Zotlabs/Module/Wiki.php
+++ b/Zotlabs/Module/Wiki.php
@@ -92,8 +92,6 @@ class Wiki extends \Zotlabs\Web\Controller {
function post() {
require_once('include/wiki.php');
- // TODO: Implement wiki API
-
// Render mardown-formatted text in HTML
if((argc() > 2) && (argv(2) === 'preview')) {
$content = $_POST['content'];
@@ -212,8 +210,22 @@ class Wiki extends \Zotlabs\Web\Controller {
}
}
- notice('You must be authenticated.');
- goaway('/wiki');
+ // Fetch page list for a wiki
+ if ((argc() === 5) && (argv(2) === 'get') && (argv(3) === 'page') && (argv(4) === 'list')) {
+ $resource_id = $_POST['resource_id']; // resource_id for wiki in db
+ $channel = get_channel_by_nick(argv(1));
+ $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('pages' => null, 'message' => 'Permission denied.', 'success' => false));
+ }
+ $page_list_html = widget_wiki_pages(array('resource_id' => $resource_id));
+ json_return_and_die(array('pages' => $page_list_html, 'message' => '', 'success' => true));
+ }
+
+ //notice('You must be authenticated.');
+ json_return_and_die(array('message' => 'You must be authenticated.', 'success' => false));
}
}
diff --git a/include/widgets.php b/include/widgets.php
index 1cc6dfc28..0d734d6cf 100644
--- a/include/widgets.php
+++ b/include/widgets.php
@@ -877,14 +877,21 @@ function widget_wiki_list($arr) {
function widget_wiki_pages($arr) {
require_once("include/wiki.php");
- $r = wiki_pages(App::$profile['channel_hash']);
- if($r) {
- return replace_macros(get_markup_template('wiki_page_list.tpl'), array(
- '$header' => t('Wiki Pages'),
- '$pages' => $r['pages']
- ));
+ $pages = array();
+ if (!array_key_exists('resource_id', $arr)) {
+ $hide = true;
+ } else {
+ $p = wiki_page_list($arr['resource_id']);
+ if ($p['pages']) {
+ $pages = $p['pages'];
+ }
}
+ return replace_macros(get_markup_template('wiki_page_list.tpl'), array(
+ '$hide' => $hide,
+ '$header' => t('Wiki Pages'),
+ '$pages' => $pages
+ ));
}
function widget_bookmarkedchats($arr) {
diff --git a/include/wiki.php b/include/wiki.php
index 317db1239..c1779e208 100644
--- a/include/wiki.php
+++ b/include/wiki.php
@@ -20,9 +20,20 @@ function wiki_list($nick, $observer_hash) {
return array('wikis' => $wikis);
}
-function wiki_pages() {
- // TODO: scan wiki folder for pages
- return array('pages' => array('page1.md', 'page2.md'));
+function wiki_page_list($resource_id) {
+ // TODO: Create item table records for pages so that metadata like title can be applied
+ $w = wiki_get_wiki($resource_id);
+ if (!$w['path']) {
+ return array('pages' => null);
+ }
+ $pages = array();
+ if (is_dir($w['path']) === true) {
+ $files = array_diff(scandir($w['path']), array('.', '..', '.git'));
+ // TODO: Check that the files are all text files
+ $pages = $files;
+ }
+
+ return array('pages' => $pages);
}
function wiki_init_wiki($channel, $name) {
@@ -125,6 +136,25 @@ function wiki_delete_wiki($resource_id) {
}
}
+function wiki_get_wiki($resource_id) {
+ $item = q("SELECT * FROM item WHERE resource_type = '%s' AND resource_id = '%s' AND item_deleted = 0 limit 1",
+ dbesc(WIKI_ITEM_RESOURCE_TYPE),
+ dbesc($resource_id)
+ );
+ if (!$item) {
+ return array('wiki' => null, 'path' => null);
+ } else {
+ $w = $item[0];
+ $object = json_decode($w['object'], true);
+ if (!realpath(__DIR__ . '/../' . $object['path'])) {
+ return array('wiki' => null, 'path' => null);
+ }
+ // Path to wiki exists
+ $abs_path = realpath(__DIR__ . '/../' . $object['path']);
+ return array('wiki' => $w, 'path' => $abs_path);
+ }
+}
+
function wiki_exists_by_name($uid, $name) {
$item = q("SELECT id,resource_id FROM item WHERE resource_type = '%s' AND title = '%s' AND uid = '%s' AND item_deleted = 0 limit 1",
dbesc(WIKI_ITEM_RESOURCE_TYPE),
@@ -147,7 +177,7 @@ function wiki_get_permissions($resource_id, $owner_id, $observer_hash) {
dbesc($resource_id)
);
if(!$r) {
- return array('read' => false, 'write' => false, 'success' => false);
+ return array('read' => false, 'write' => false, 'success' => true);
} else {
return array('read' => true, 'write' => false, 'success' => true);
}
diff --git a/view/tpl/wiki.tpl b/view/tpl/wiki.tpl
index b0824650c..27887cc1c 100644
--- a/view/tpl/wiki.tpl
+++ b/view/tpl/wiki.tpl
@@ -78,6 +78,7 @@
<script>
window.wiki_resource_id = '{{$resource_id}}';
$(document).ready(function () {
+ wiki_refresh_page_list();
// Show Edit tab first. Otherwise the Ace editor does not load.
$("#wiki-nav-tabs li:eq(0) a").tab('show');
});
@@ -131,4 +132,20 @@ function wiki_delete_wiki(wikiName, resource_id) {
}, 'json');
ev.preventDefault();
});
+
+ function wiki_refresh_page_list() {
+ if (window.wiki_resource_id === '') {
+ return false;
+ }
+ $.post("wiki/{{$channel}}/get/page/list/", {resource_id: window.wiki_resource_id}, function (data) {
+ if (data.success) {
+ $('#wiki_page_list').html(data.pages);
+ $('#wiki_page_list').show();
+ } else {
+ alert('Error fetching page list!');
+ window.console.log('Error fetching page list!');
+ }
+ }, 'json');
+ return false;
+ }
</script>
diff --git a/view/tpl/wiki_page_list.tpl b/view/tpl/wiki_page_list.tpl
index 015ffb930..0ced893c3 100644
--- a/view/tpl/wiki_page_list.tpl
+++ b/view/tpl/wiki_page_list.tpl
@@ -1,4 +1,4 @@
-<div id="wiki_page_list" class="widget">
+<div id="wiki_page_list" class="widget" {{if $hide}} style="display: none;" {{/if}}>
<h3>{{$header}}</h3>
<ul class="nav nav-pills nav-stacked">
{{foreach $pages as $page}}