Replaced wiki item record object field with ActivityStreams information. Wiki git repo path is stored in iconfig instead.
This commit is contained in:
parent
8f0c3f0e9b
commit
a52cdcb241
@ -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 = '';
|
||||
|
||||
// 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
|
||||
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
|
||||
$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
|
||||
@ -91,6 +94,7 @@ class Wiki extends \Zotlabs\Web\Controller {
|
||||
// Until separate read and write permissions are implemented, only allow
|
||||
// the wiki owner to see page controls
|
||||
$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,
|
||||
|
@ -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>
|
@ -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,23 +118,16 @@ 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);
|
||||
|
||||
$w = wiki_get_wiki($resource_id);
|
||||
$item = $w['wiki'];
|
||||
if (!$item || !$w['path']) {
|
||||
return array('item' => 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);
|
||||
$drop = drop_item($item['id'], false, DROPITEM_NORMAL, true);
|
||||
$pathdel = rrmdir($w['path']);
|
||||
if ($pathdel) {
|
||||
info('Wiki deleted successfully');
|
||||
info('Wiki files deleted successfully');
|
||||
}
|
||||
return array('item' => $item, 'success' => (($drop === 1 && $pathdel) ? true : false));
|
||||
}
|
||||
@ -141,12 +142,13 @@ 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);
|
||||
}
|
||||
}
|
||||
@ -162,7 +164,6 @@ function wiki_exists_by_name($uid, $name) {
|
||||
} 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);
|
||||
$w = wiki_get_wiki($resource_id);
|
||||
if (!$w['path']) {
|
||||
return array('page' => null, 'message' => 'Wiki 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);
|
||||
}
|
||||
// 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);
|
||||
}
|
||||
|
@ -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}}
|
||||
|
Reference in New Issue
Block a user