Replaced wiki item record object field with ActivityStreams information. Wiki git repo path is stored in iconfig instead.

This commit is contained in:
Andrew Manning 2016-05-30 14:59:33 -04:00
parent 8f0c3f0e9b
commit a52cdcb241
4 changed files with 53 additions and 72 deletions

View File

@ -27,6 +27,7 @@ class Wiki extends \Zotlabs\Web\Controller {
require_once('include/wiki.php'); require_once('include/wiki.php');
require_once('include/acl_selectors.php'); require_once('include/acl_selectors.php');
$wiki_owner = false; $wiki_owner = false;
$showNewWikiButton = false;
if(local_channel()) { if(local_channel()) {
$channel = \App::get_channel(); $channel = \App::get_channel();
} }
@ -47,15 +48,16 @@ class Wiki extends \Zotlabs\Web\Controller {
$resource_id = ''; $resource_id = '';
$pagename = ''; $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)/... // GET https://hubzilla.hub/argv(0)/argv(1)/argv(2)/argv(3)/argv(4)/...
if(argc() > 2) { if(argc() > 2) {
// GET /wiki/channel/wiki // GET /wiki/channel/wiki
// Check if wiki exists andr redirect if it does not // 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)); $w = wiki_exists_by_name($channel['channel_id'], argv(2));
if(!$w['resource_id']) { if(!$w['resource_id']) {
notice('Wiki not found' . EOL); 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*."'; $content = '"# Wiki Sandbox\n\nContent you **edit** and **preview** here *will not be saved*."';
$hide_editor = false; $hide_editor = false;
$showPageControls = false; $showPageControls = false;
$showNewWikiButton = $wiki_owner;
} elseif (argc()<4) { } elseif (argc()<4) {
// GET /wiki/channel/wiki // GET /wiki/channel/wiki
// No page was specified, so redirect to Home.md // No page was specified, so redirect to Home.md
@ -90,7 +93,8 @@ class Wiki extends \Zotlabs\Web\Controller {
$hide_editor = true; $hide_editor = true;
// Until separate read and write permissions are implemented, only allow // Until separate read and write permissions are implemented, only allow
// the wiki owner to see page controls // the wiki owner to see page controls
$showPageControls = $wiki_owner; $showPageControls = $wiki_owner;
$showNewWikiButton = $wiki_owner;
} elseif (argc()<5) { } elseif (argc()<5) {
// GET /wiki/channel/wiki/page // GET /wiki/channel/wiki/page
$pagename = argv(3); $pagename = argv(3);
@ -102,6 +106,7 @@ class Wiki extends \Zotlabs\Web\Controller {
$content = ($p['content'] !== '' ? $p['content'] : '"# New page\n"'); $content = ($p['content'] !== '' ? $p['content'] : '"# New page\n"');
$hide_editor = false; $hide_editor = false;
$showPageControls = $wiki_owner; $showPageControls = $wiki_owner;
$showNewWikiButton = $wiki_owner;
} }
require_once('library/markdown.php'); require_once('library/markdown.php');
$renderedContent = Markdown(json_decode($content)); $renderedContent = Markdown(json_decode($content));
@ -110,6 +115,7 @@ class Wiki extends \Zotlabs\Web\Controller {
'$wikiheader' => $wikiheader, '$wikiheader' => $wikiheader,
'$hideEditor' => $hide_editor, '$hideEditor' => $hide_editor,
'$showPageControls' => $showPageControls, '$showPageControls' => $showPageControls,
'$showNewWikiButton'=> $showNewWikiButton,
'$channel' => $channel['channel_address'], '$channel' => $channel['channel_address'],
'$resource_id' => $resource_id, '$resource_id' => $resource_id,
'$page' => $pagename, '$page' => $pagename,

View File

@ -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>

View File

@ -95,9 +95,17 @@ function wiki_create_wiki($channel, $observer_hash, $name, $acl) {
$arr['item_private'] = intval($acl->is_private()); $arr['item_private'] = intval($acl->is_private());
$arr['verb'] = ACTIVITY_CREATE; $arr['verb'] = ACTIVITY_CREATE;
$arr['obj_type'] = ACTIVITY_OBJ_WIKI; $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]'; $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); $post = item_store($arr);
$item_id = $post['item_id']; $item_id = $post['item_id'];
@ -110,26 +118,19 @@ function wiki_create_wiki($channel, $observer_hash, $name, $acl) {
} }
function wiki_delete_wiki($resource_id) { 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), $w = wiki_get_wiki($resource_id);
dbesc($resource_id) $item = $w['wiki'];
); if (!$item || !$w['path']) {
if (!$item) { return array('item' => null, 'success' => false);
return array('items' => null, 'success' => false); } else {
} else { $drop = drop_item($item['id'], false, DROPITEM_NORMAL, true);
$drop = drop_item($item[0]['id'],false,DROPITEM_NORMAL,true); $pathdel = rrmdir($w['path']);
$object = json_decode($item[0]['object'], true); if ($pathdel) {
if(!realpath(__DIR__ . '/../' . $object['path'])) { info('Wiki files deleted successfully');
return array('items' => null, 'success' => false); }
} return array('item' => $item, 'success' => (($drop === 1 && $pathdel) ? true : 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));
}
} }
function wiki_get_wiki($resource_id) { function wiki_get_wiki($resource_id) {
@ -141,28 +142,28 @@ function wiki_get_wiki($resource_id) {
return array('wiki' => null, 'path' => null); return array('wiki' => null, 'path' => null);
} else { } else {
$w = $item[0]; $w = $item[0];
$object = json_decode($w['object'], true); //$object = json_decode($w['object'], true);
if (!realpath(__DIR__ . '/../' . $object['path'])) { $path = get_iconfig($w, 'wiki', 'path');
if (!realpath(__DIR__ . '/../' . $path)) {
return array('wiki' => null, 'path' => null); return array('wiki' => null, 'path' => null);
} }
// Path to wiki exists // Path to wiki exists
$abs_path = realpath(__DIR__ . '/../' . $object['path']); $abs_path = realpath(__DIR__ . '/../' . $path);
return array('wiki' => $w, 'path' => $abs_path); return array('wiki' => $w, 'path' => $abs_path);
} }
} }
function wiki_exists_by_name($uid, $name) { 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", $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(WIKI_ITEM_RESOURCE_TYPE),
dbesc($name), dbesc($name),
dbesc($uid) dbesc($uid)
); );
if (!$item) { if (!$item) {
return array('id' => null, 'resource_id' => null); return array('id' => null, 'resource_id' => null);
} else { } else {
return array('id' => $item[0]['id'], 'resource_id' => $item[0]['resource_id']); return array('id' => $item[0]['id'], 'resource_id' => $item[0]['resource_id']);
} }
} }
function wiki_get_permissions($resource_id, $owner_id, $observer_hash) { 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) { 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", $w = wiki_get_wiki($resource_id);
dbesc(WIKI_ITEM_RESOURCE_TYPE), if (!$w['path']) {
dbesc($resource_id) return array('page' => null, 'message' => 'Wiki not found.', 'success' => false);
);
if (!$item) {
return array('page' => null, 'message' => 'Wiki item not found.', 'success' => false);
} }
$object = json_decode($item[0]['object'], true); $page_path = $w['path'] . '/' . $name;
$wikiname = $item[0]['title'];
if (!realpath(__DIR__ . '/../' . $object['path'])) {
return array('page' => null, 'message' => 'Wiki directory does not exist.', 'success' => false);
}
// Path to wiki exists
$abs_path = realpath(__DIR__ . '/../' . $object['path']);
$page_path = $abs_path . '/' . $name;
if (is_file($page_path)) { if (is_file($page_path)) {
return array('page' => null, 'message' => 'Page already exists.', 'success' => false); return array('page' => null, 'message' => 'Page already exists.', 'success' => false);
} }

View File

@ -14,7 +14,7 @@
<div class="generic-content-wrapper"> <div class="generic-content-wrapper">
<div class="section-title-wrapper"> <div class="section-title-wrapper">
<div class="pull-right"> <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-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> <button class="btn btn-success btn-xs" onclick="$('#new-wiki-form-wrapper').hide(); openClose('new-page-form-wrapper');">New Page</button>
{{/if}} {{/if}}