aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Manning <tamanning@zoho.com>2016-05-30 14:59:33 -0400
committerAndrew Manning <tamanning@zoho.com>2016-05-30 14:59:33 -0400
commita52cdcb2410fc67823a3dab62b413d70ec57cdec (patch)
treedb3e9309d7892644bc2055296e3bc0ef5a37fea2
parent8f0c3f0e9be676e08b886af2d872cf9d544680bd (diff)
downloadvolse-hubzilla-a52cdcb2410fc67823a3dab62b413d70ec57cdec.tar.gz
volse-hubzilla-a52cdcb2410fc67823a3dab62b413d70ec57cdec.tar.bz2
volse-hubzilla-a52cdcb2410fc67823a3dab62b413d70ec57cdec.zip
Replaced wiki item record object field with ActivityStreams information. Wiki git repo path is stored in iconfig instead.
-rw-r--r--Zotlabs/Module/Wiki.php18
-rw-r--r--doc/html/index.php16
-rw-r--r--include/wiki.php89
-rw-r--r--view/tpl/wiki.tpl2
4 files changed, 53 insertions, 72 deletions
diff --git a/Zotlabs/Module/Wiki.php b/Zotlabs/Module/Wiki.php
index 030e34cf6..d6acbf6b0 100644
--- a/Zotlabs/Module/Wiki.php
+++ b/Zotlabs/Module/Wiki.php
@@ -27,6 +27,7 @@ class Wiki extends \Zotlabs\Web\Controller {
require_once('include/wiki.php');
require_once('include/acl_selectors.php');
$wiki_owner = false;
+ $showNewWikiButton = false;
if(local_channel()) {
$channel = \App::get_channel();
}
@@ -47,15 +48,16 @@ class Wiki extends \Zotlabs\Web\Controller {
$resource_id = '';
$pagename = '';
-
+ if(argc() > 1) {
+ $channel = get_channel_by_nick(argv(1));
+ if(local_channel() === intval($channel['channel_id'])) {
+ $wiki_owner = true;
+ }
+ }
// GET https://hubzilla.hub/argv(0)/argv(1)/argv(2)/argv(3)/argv(4)/...
if(argc() > 2) {
// GET /wiki/channel/wiki
// Check if wiki exists andr redirect if it does not
- $channel = get_channel_by_nick(argv(1));
- if(local_channel() === intval($channel['channel_id'])) {
- $wiki_owner = true;
- }
$w = wiki_exists_by_name($channel['channel_id'], argv(2));
if(!$w['resource_id']) {
notice('Wiki not found' . EOL);
@@ -81,6 +83,7 @@ class Wiki extends \Zotlabs\Web\Controller {
$content = '"# Wiki Sandbox\n\nContent you **edit** and **preview** here *will not be saved*."';
$hide_editor = false;
$showPageControls = false;
+ $showNewWikiButton = $wiki_owner;
} elseif (argc()<4) {
// GET /wiki/channel/wiki
// No page was specified, so redirect to Home.md
@@ -90,7 +93,8 @@ class Wiki extends \Zotlabs\Web\Controller {
$hide_editor = true;
// Until separate read and write permissions are implemented, only allow
// the wiki owner to see page controls
- $showPageControls = $wiki_owner;
+ $showPageControls = $wiki_owner;
+ $showNewWikiButton = $wiki_owner;
} elseif (argc()<5) {
// GET /wiki/channel/wiki/page
$pagename = argv(3);
@@ -102,6 +106,7 @@ class Wiki extends \Zotlabs\Web\Controller {
$content = ($p['content'] !== '' ? $p['content'] : '"# New page\n"');
$hide_editor = false;
$showPageControls = $wiki_owner;
+ $showNewWikiButton = $wiki_owner;
}
require_once('library/markdown.php');
$renderedContent = Markdown(json_decode($content));
@@ -110,6 +115,7 @@ class Wiki extends \Zotlabs\Web\Controller {
'$wikiheader' => $wikiheader,
'$hideEditor' => $hide_editor,
'$showPageControls' => $showPageControls,
+ '$showNewWikiButton'=> $showNewWikiButton,
'$channel' => $channel['channel_address'],
'$resource_id' => $resource_id,
'$page' => $pagename,
diff --git a/doc/html/index.php b/doc/html/index.php
deleted file mode 100644
index 2e1b4277c..000000000
--- a/doc/html/index.php
+++ /dev/null
@@ -1,16 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <title>$Projectname Doxygen API Documentation</title>
-</head>
-<body>
-<h1>$Projectname Doxygen API Documentation not rendered</h1>
-
-To get the Doxygen API Documentation you must render it with the program <a href="http://www.doxygen.org">Doxygen</a> (included in most distributions).
-<pre>
-$ doxygen util/Doxyfile
-</pre>
-<br>
-<a href="javascript:history.back()">back</a>
-</body>
-</html>
diff --git a/include/wiki.php b/include/wiki.php
index 70788eed2..6a94dc111 100644
--- a/include/wiki.php
+++ b/include/wiki.php
@@ -95,9 +95,17 @@ function wiki_create_wiki($channel, $observer_hash, $name, $acl) {
$arr['item_private'] = intval($acl->is_private());
$arr['verb'] = ACTIVITY_CREATE;
$arr['obj_type'] = ACTIVITY_OBJ_WIKI;
- $arr['object'] = array('path' => $path);
+ $arr['object'] = json_encode(array(
+ 'type' => $arr['obj_type'],
+ 'title' => $arr['title'],
+ 'id' => $arr['resource_id'],
+ 'url' => $wiki_url
+ ));
$arr['body'] = '[table][tr][td][h1]New Wiki[/h1][/td][/tr][tr][td][zrl=' . $wiki_url . ']' . $name . '[/zrl][/td][/tr][/table]';
-
+ // Save the path using iconfig. The file path should not be shared with other hubs
+ if (!set_iconfig($arr, 'wiki', 'path', $path, false)) {
+ return array('item' => null, 'success' => false);
+ }
$post = item_store($arr);
$item_id = $post['item_id'];
@@ -110,26 +118,19 @@ function wiki_create_wiki($channel, $observer_hash, $name, $acl) {
}
function wiki_delete_wiki($resource_id) {
- $item = q("SELECT id, object 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('items' => null, 'success' => false);
- } else {
- $drop = drop_item($item[0]['id'],false,DROPITEM_NORMAL,true);
- $object = json_decode($item[0]['object'], true);
- if(!realpath(__DIR__ . '/../' . $object['path'])) {
- return array('items' => null, 'success' => false);
- }
- // Path to wiki exists
- $abs_path = realpath(__DIR__ . '/../' . $object['path']);
- $pathdel = rrmdir($abs_path);
- if($pathdel) {
- info('Wiki deleted successfully');
- }
- return array('item' => $item, 'success' => (($drop === 1 && $pathdel) ? true : false));
- }
+
+ $w = wiki_get_wiki($resource_id);
+ $item = $w['wiki'];
+ if (!$item || !$w['path']) {
+ return array('item' => null, 'success' => false);
+ } else {
+ $drop = drop_item($item['id'], false, DROPITEM_NORMAL, true);
+ $pathdel = rrmdir($w['path']);
+ if ($pathdel) {
+ info('Wiki files deleted successfully');
+ }
+ return array('item' => $item, 'success' => (($drop === 1 && $pathdel) ? true : false));
+ }
}
function wiki_get_wiki($resource_id) {
@@ -141,28 +142,28 @@ function wiki_get_wiki($resource_id) {
return array('wiki' => null, 'path' => null);
} else {
$w = $item[0];
- $object = json_decode($w['object'], true);
- if (!realpath(__DIR__ . '/../' . $object['path'])) {
+ //$object = json_decode($w['object'], true);
+ $path = get_iconfig($w, 'wiki', 'path');
+ if (!realpath(__DIR__ . '/../' . $path)) {
return array('wiki' => null, 'path' => null);
}
// Path to wiki exists
- $abs_path = realpath(__DIR__ . '/../' . $object['path']);
+ $abs_path = realpath(__DIR__ . '/../' . $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),
- dbesc($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),
+ dbesc($name),
dbesc($uid)
- );
- if (!$item) {
- return array('id' => null, 'resource_id' => null);
- } else {
- return array('id' => $item[0]['id'], 'resource_id' => $item[0]['resource_id']);
- }
-
+ );
+ if (!$item) {
+ return array('id' => null, 'resource_id' => null);
+ } else {
+ return array('id' => $item[0]['id'], 'resource_id' => $item[0]['resource_id']);
+ }
}
function wiki_get_permissions($resource_id, $owner_id, $observer_hash) {
@@ -180,21 +181,11 @@ function wiki_get_permissions($resource_id, $owner_id, $observer_hash) {
}
function wiki_create_page($name, $resource_id) {
- $item = q("SELECT id,title,object 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('page' => null, 'message' => 'Wiki item not found.', 'success' => false);
- }
- $object = json_decode($item[0]['object'], true);
- $wikiname = $item[0]['title'];
- if (!realpath(__DIR__ . '/../' . $object['path'])) {
- return array('page' => null, 'message' => 'Wiki directory does not exist.', 'success' => false);
+ $w = wiki_get_wiki($resource_id);
+ if (!$w['path']) {
+ return array('page' => null, 'message' => 'Wiki not found.', 'success' => false);
}
- // Path to wiki exists
- $abs_path = realpath(__DIR__ . '/../' . $object['path']);
- $page_path = $abs_path . '/' . $name;
+ $page_path = $w['path'] . '/' . $name;
if (is_file($page_path)) {
return array('page' => null, 'message' => 'Page already exists.', 'success' => false);
}
diff --git a/view/tpl/wiki.tpl b/view/tpl/wiki.tpl
index e6e8c720b..91c6e64b2 100644
--- a/view/tpl/wiki.tpl
+++ b/view/tpl/wiki.tpl
@@ -14,7 +14,7 @@
<div class="generic-content-wrapper">
<div class="section-title-wrapper">
<div class="pull-right">
- {{if $showPageControls}}
+ {{if $showNewWikiButton}}
<button class="btn btn-primary btn-xs" onclick="$('#new-page-form-wrapper').hide(); openClose('new-wiki-form-wrapper');">New Wiki</button>
<button class="btn btn-success btn-xs" onclick="$('#new-wiki-form-wrapper').hide(); openClose('new-page-form-wrapper');">New Page</button>
{{/if}}