Delete wiki (in progress)
This commit is contained in:
parent
a36bef7979
commit
e00b8a7082
@ -21,7 +21,7 @@ class Wiki extends \Zotlabs\Web\Controller {
|
||||
}
|
||||
if(! $which) {
|
||||
notice( t('You must be logged in to see this page.') . EOL );
|
||||
return;
|
||||
goaway('/login');
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,6 +91,12 @@ class Wiki extends \Zotlabs\Web\Controller {
|
||||
json_return_and_die(array('html' => $html, 'success' => true));
|
||||
}
|
||||
|
||||
// Check if specified wiki exists and redirect if not
|
||||
if((argc() > 2)) {
|
||||
$wikiname = argv(2);
|
||||
// TODO: Check if specified wiki exists and redirect if not
|
||||
}
|
||||
|
||||
// Create a new wiki
|
||||
if ((argc() > 3) && (argv(2) === 'create') && (argv(3) === 'wiki')) {
|
||||
$which = argv(1);
|
||||
@ -102,20 +108,23 @@ class Wiki extends \Zotlabs\Web\Controller {
|
||||
$observer_hash = get_observer_hash();
|
||||
// Figure out who the page owner is.
|
||||
$perms = get_all_perms(intval($channel['channel_id']), $observer_hash);
|
||||
|
||||
if (!$perms['write_wiki']) {
|
||||
// TODO: Create a new permission setting for wiki analogous to webpages. Until
|
||||
// then, use webpage permissions
|
||||
if (!$perms['write_pages']) {
|
||||
notice(t('Permission denied.') . EOL);
|
||||
json_return_and_die(array('success' => false));
|
||||
goaway(argv(0).'/'.argv(1).'/'.argv(2));
|
||||
}
|
||||
}
|
||||
$name = escape_tags(urlencode($_REQUEST['wikiName'])); //Get new wiki name
|
||||
$name = escape_tags(urlencode($_POST['wikiName'])); //Get new wiki name
|
||||
if($name === '') {
|
||||
notice('Error creating wiki. Invalid name.');
|
||||
goaway('/wiki');
|
||||
}
|
||||
// Get ACL for permissions
|
||||
$acl = new \Zotlabs\Access\AccessList($channel);
|
||||
$acl->set_from_array($_REQUEST);
|
||||
logger('POST: ' . json_encode($_POST));
|
||||
$acl->set_from_array($_POST);
|
||||
logger('acl: ' . json_encode($acl));
|
||||
$r = wiki_create_wiki($channel, $observer_hash, $name, $acl);
|
||||
if ($r['success']) {
|
||||
goaway('/wiki/'.$which.'/'.$name);
|
||||
@ -125,7 +134,36 @@ class Wiki extends \Zotlabs\Web\Controller {
|
||||
}
|
||||
}
|
||||
|
||||
json_return_and_die(array('success' => false));
|
||||
// Delete a wiki
|
||||
if ((argc() > 3) && (argv(2) === 'delete') && (argv(3) === 'wiki')) {
|
||||
$which = argv(1);
|
||||
// Determine if observer has permission to create wiki
|
||||
if (local_channel()) {
|
||||
$channel = \App::get_channel();
|
||||
} else {
|
||||
$channel = get_channel_by_nick($which);
|
||||
$observer_hash = get_observer_hash();
|
||||
// Figure out who the page owner is.
|
||||
$perms = get_all_perms(intval($channel['channel_id']), $observer_hash);
|
||||
// TODO: Create a new permission setting for wiki analogous to webpages. Until
|
||||
// then, use webpage permissions
|
||||
if (!$perms['write_pages']) {
|
||||
logger('Wiki delete permission denied.' . EOL);
|
||||
json_return_and_die(array('success' => false));
|
||||
}
|
||||
}
|
||||
$resource_id = $_POST['resource_id'];
|
||||
$deleted = wiki_delete_wiki($resource_id);
|
||||
if ($deleted['success']) {
|
||||
json_return_and_die(array('success' => true));
|
||||
} else {
|
||||
logger('Error deleting wiki: ' . $resource_id);
|
||||
json_return_and_die(array('success' => false));
|
||||
}
|
||||
}
|
||||
|
||||
notice('You must be authenticated.');
|
||||
goaway('/wiki');
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -7,14 +7,6 @@
|
||||
use \Zotlabs\Storage\GitRepo as GitRepo;
|
||||
define ( 'WIKI_ITEM_RESOURCE_TYPE', 'wiki' );
|
||||
|
||||
function wiki_create() {
|
||||
|
||||
}
|
||||
|
||||
function wiki_delete() {
|
||||
|
||||
}
|
||||
|
||||
function wiki_list($nick, $observer_hash) {
|
||||
if (local_channel() || remote_channel()) {
|
||||
$sql_extra = item_permissions_sql(get_channel_by_nick($nick)['channel_id'], $observer_hash);
|
||||
@ -36,7 +28,7 @@ function wiki_pages() {
|
||||
function wiki_init_wiki($channel, $name) {
|
||||
// Store the path as a relative path, but pass absolute path to mkdir
|
||||
$path = 'store/[data]/git/'.$channel['channel_address'].'/wiki/'.$name;
|
||||
if (!mkdir(__DIR__ . '/../' . $path, 0770, true)) {
|
||||
if (!os_mkdir(__DIR__ . '/../' . $path, 0770, true)) {
|
||||
logger('Error creating wiki path: ' . $name);
|
||||
return null;
|
||||
}
|
||||
@ -109,3 +101,22 @@ function wiki_create_wiki($channel, $observer_hash, $name, $acl) {
|
||||
return array('item' => null, 'success' => false);
|
||||
}
|
||||
}
|
||||
|
||||
function wiki_delete_wiki($resource_id) {
|
||||
$item = q("SELECT id 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);
|
||||
$abs_path = __DIR__ . '/../' . $object['path'];
|
||||
logger('path to delete: ' . $abs_path);
|
||||
$pathdel = true;
|
||||
//$pathdel = rrmdir($abs_path);
|
||||
|
||||
return array('item' => $item, 'success' => (($drop === 1 && $pathdel) ? true : false));
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,7 @@
|
||||
</div>
|
||||
<button id="new-wiki-submit" class="btn btn-primary" type="submit" name="submit" >Create Wiki</button>
|
||||
</div>
|
||||
<div>{{$acl}}</div>
|
||||
</form>
|
||||
<div class="clear"></div>
|
||||
<hr>
|
||||
@ -74,8 +75,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>{{$acl}}</div>
|
||||
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
// Show Edit tab first. Otherwise the Ace editor does not load.
|
||||
@ -98,4 +97,17 @@
|
||||
ev.preventDefault();
|
||||
});
|
||||
|
||||
function wiki_delete_wiki(wikiName, resource_id) {
|
||||
if(!confirm('Are you sure you want to delete the entire wiki: ' + JSON.stringify(wikiName))) {
|
||||
return;
|
||||
}
|
||||
$.post("wiki/{{$channel}}/delete/wiki", {resource_id: resource_id}, function (data) {
|
||||
if (data.success) {
|
||||
window.console.log('Wiki deleted');
|
||||
// Refresh list and redirect page as necessary
|
||||
} else {
|
||||
window.console.log('Error deleting wiki.');
|
||||
}
|
||||
}, 'json');
|
||||
}
|
||||
</script>
|
||||
|
@ -2,7 +2,16 @@
|
||||
<h3>{{$header}}</h3>
|
||||
<ul class="nav nav-pills nav-stacked">
|
||||
{{foreach $wikis as $wiki}}
|
||||
<li><a href="/wiki/{{$channel}}/{{$wiki.title}}">{{$wiki.title}}</a></li>
|
||||
<li class="dropdown" id="wiki-{{$wiki.resource_id}}">
|
||||
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
|
||||
<b>{{$wiki.title}}</b><b class="fa fa-caret-down pull-right"></b>
|
||||
</a>
|
||||
<ul class="dropdown-menu pull-right">
|
||||
<li><a href="/wiki/{{$channel}}/{{$wiki.title}}" title="View {{$wiki.title}}">View</a></li>
|
||||
<li class="divider"></li>
|
||||
<li><a href="#" onclick="wiki_delete_wiki('{{$wiki.title}}','{{$wiki.resource_id}}'); return false;" title="Delete {{$wiki.title}}">Delete wiki</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
{{/foreach}}
|
||||
</ul>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user