Page deletion implemented. Hide the delete button and disallow for Home page.
This commit is contained in:
parent
a92241d3cf
commit
4bc4fd5b7e
@ -80,7 +80,8 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
// /wiki/channel/wiki -> No page was specified, so redirect to Home.md
|
// /wiki/channel/wiki -> No page was specified, so redirect to Home.md
|
||||||
goaway('/'.argv(0).'/'.argv(1).'/'.argv(2).'/Home');
|
$wikiUrlName = urlencode(argv(2));
|
||||||
|
goaway('/'.argv(0).'/'.argv(1).'/'.$wikiUrlName.'/Home');
|
||||||
case 4:
|
case 4:
|
||||||
// GET /wiki/channel/wiki/page
|
// GET /wiki/channel/wiki/page
|
||||||
// Fetch the wiki info and determine observer permissions
|
// Fetch the wiki info and determine observer permissions
|
||||||
@ -106,7 +107,7 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
$p = wiki_get_page_content(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
|
$p = wiki_get_page_content(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
|
||||||
if(!$p['success']) {
|
if(!$p['success']) {
|
||||||
notice('Error retrieving page content' . EOL);
|
notice('Error retrieving page content' . EOL);
|
||||||
goaway('/'.argv(0).'/'.argv(1).'/'.argv(2));
|
goaway('/'.argv(0).'/'.argv(1).'/'.$wikiUrlName);
|
||||||
}
|
}
|
||||||
$content = ($p['content'] !== '' ? $p['content'] : '"# New page\n"');
|
$content = ($p['content'] !== '' ? $p['content'] : '"# New page\n"');
|
||||||
$hide_editor = false;
|
$hide_editor = false;
|
||||||
@ -116,7 +117,7 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
$pageHistory = wiki_page_history(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
|
$pageHistory = wiki_page_history(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
|
||||||
break;
|
break;
|
||||||
default: // Strip the extraneous URL components
|
default: // Strip the extraneous URL components
|
||||||
goaway('/'.argv(0).'/'.argv(1).'/'.argv(2).'/'.argv(3));
|
goaway('/'.argv(0).'/'.argv(1).'/'.$wikiUrlName.'/'.$pageUrlName);
|
||||||
}
|
}
|
||||||
// Render the Markdown-formatted page content in HTML
|
// Render the Markdown-formatted page content in HTML
|
||||||
require_once('library/markdown.php');
|
require_once('library/markdown.php');
|
||||||
@ -287,7 +288,6 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
$nick = argv(1);
|
$nick = argv(1);
|
||||||
$resource_id = $_POST['resource_id'];
|
$resource_id = $_POST['resource_id'];
|
||||||
$pageUrlName = $_POST['name'];
|
$pageUrlName = $_POST['name'];
|
||||||
logger('pageURLname: ' . $pageUrlName);
|
|
||||||
$pageHtmlName = escape_tags($_POST['name']);
|
$pageHtmlName = escape_tags($_POST['name']);
|
||||||
$content = escape_tags($_POST['content']); //Get new content
|
$content = escape_tags($_POST['content']); //Get new content
|
||||||
// Determine if observer has permission to save content
|
// Determine if observer has permission to save content
|
||||||
@ -354,6 +354,53 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
json_return_and_die(array('historyHTML' => $historyHTML, 'message' => '', 'success' => true));
|
json_return_and_die(array('historyHTML' => $historyHTML, 'message' => '', 'success' => true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete a page
|
||||||
|
if ((argc() === 4) && (argv(2) === 'delete') && (argv(3) === 'page')) {
|
||||||
|
$nick = argv(1);
|
||||||
|
$resource_id = $_POST['resource_id'];
|
||||||
|
$pageUrlName = $_POST['name'];
|
||||||
|
if ($pageUrlName === 'Home') {
|
||||||
|
json_return_and_die(array('message' => 'Cannot delete Home','success' => false));
|
||||||
|
}
|
||||||
|
// Determine if observer has permission to delete pages
|
||||||
|
if (local_channel()) {
|
||||||
|
$channel = \App::get_channel();
|
||||||
|
} else {
|
||||||
|
$channel = get_channel_by_nick($nick);
|
||||||
|
$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 editing permission denied.' . EOL);
|
||||||
|
json_return_and_die(array('success' => false));
|
||||||
|
}
|
||||||
|
$perms = wiki_get_permissions($resource_id, intval($channel['channel_id']), $observer_hash);
|
||||||
|
if(!$perms['write']) {
|
||||||
|
logger('Wiki write permission denied. Read only.' . EOL);
|
||||||
|
json_return_and_die(array('success' => false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$deleted = wiki_delete_page(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
|
||||||
|
if($deleted['success']) {
|
||||||
|
$ob = \App::get_observer();
|
||||||
|
$commit = wiki_git_commit(array(
|
||||||
|
'commit_msg' => 'Deleted ' . $pageHtmlName,
|
||||||
|
'resource_id' => $resource_id,
|
||||||
|
'observer' => $ob,
|
||||||
|
'files' => null
|
||||||
|
));
|
||||||
|
if($commit['success']) {
|
||||||
|
json_return_and_die(array('message' => 'Wiki git repo commit made', 'success' => true));
|
||||||
|
} else {
|
||||||
|
json_return_and_die(array('message' => 'Error making git commit','success' => false));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
json_return_and_die(array('message' => 'Error deleting page', 'success' => false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//notice('You must be authenticated.');
|
//notice('You must be authenticated.');
|
||||||
json_return_and_die(array('message' => 'You must be authenticated.', 'success' => false));
|
json_return_and_die(array('message' => 'You must be authenticated.', 'success' => false));
|
||||||
|
|
||||||
|
@ -289,6 +289,24 @@ function wiki_save_page($arr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function wiki_delete_page($arr) {
|
||||||
|
$pageUrlName = ((array_key_exists('pageUrlName',$arr)) ? $arr['pageUrlName'] : '');
|
||||||
|
$resource_id = ((array_key_exists('resource_id',$arr)) ? $arr['resource_id'] : '');
|
||||||
|
$w = wiki_get_wiki($resource_id);
|
||||||
|
if (!$w['path']) {
|
||||||
|
return array('message' => 'Error reading wiki', 'success' => false);
|
||||||
|
}
|
||||||
|
$page_path = $w['path'].'/'.$pageUrlName.'.md';
|
||||||
|
if (is_writable($page_path) === true) {
|
||||||
|
if(!unlink($page_path)) {
|
||||||
|
return array('message' => 'Error deleting page file', 'success' => false);
|
||||||
|
}
|
||||||
|
return array('message' => '', 'success' => true);
|
||||||
|
} else {
|
||||||
|
return array('message' => 'Page file not writable', 'success' => false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function wiki_git_commit($arr) {
|
function wiki_git_commit($arr) {
|
||||||
$files = ((array_key_exists('files', $arr)) ? $arr['files'] : null);
|
$files = ((array_key_exists('files', $arr)) ? $arr['files'] : null);
|
||||||
$commit_msg = ((array_key_exists('commit_msg', $arr)) ? $arr['commit_msg'] : 'Repo updated');
|
$commit_msg = ((array_key_exists('commit_msg', $arr)) ? $arr['commit_msg'] : 'Repo updated');
|
||||||
|
@ -5,10 +5,10 @@
|
|||||||
height: 500px;
|
height: 500px;
|
||||||
}
|
}
|
||||||
.fade.in {
|
.fade.in {
|
||||||
-webkit-transition: opacity 2s 1s ease;
|
-webkit-transition: opacity 0.5s 0.5s ease;
|
||||||
-moz-transition: opacity 2s 1s ease;
|
-moz-transition: opacity 0.5s 0.5s ease;
|
||||||
-o-transition: opacity 2s 1s ease;
|
-o-transition: opacity 0.5s 0.5s ease;
|
||||||
transition: opacity 2s 1s ease;
|
transition: opacity 0.5s 0.5s ease;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<div class="generic-content-wrapper">
|
<div class="generic-content-wrapper">
|
||||||
@ -106,6 +106,9 @@
|
|||||||
<script>
|
<script>
|
||||||
window.wiki_resource_id = '{{$resource_id}}';
|
window.wiki_resource_id = '{{$resource_id}}';
|
||||||
window.wiki_page_name = '{{$page}}';
|
window.wiki_page_name = '{{$page}}';
|
||||||
|
if (window.wiki_page_name === 'Home') {
|
||||||
|
$('#delete-page').hide();
|
||||||
|
}
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
wiki_refresh_page_list();
|
wiki_refresh_page_list();
|
||||||
// Show Edit tab first. Otherwise the Ace editor does not load.
|
// Show Edit tab first. Otherwise the Ace editor does not load.
|
||||||
@ -206,4 +209,27 @@ function wiki_delete_wiki(wikiHtmlName, resource_id) {
|
|||||||
}, 'json');
|
}, 'json');
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#delete-page').click(function (ev) {
|
||||||
|
if (window.wiki_resource_id === '' || window.wiki_page_name === '' || window.wiki_page_name === 'Home') {
|
||||||
|
window.console.log('You must have a wiki page open in order to delete pages.');
|
||||||
|
ev.preventDefault();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$.post("wiki/{{$channel}}/delete/page", {name: window.wiki_page_name, resource_id: window.wiki_resource_id},
|
||||||
|
function (data) {
|
||||||
|
if (data.success) {
|
||||||
|
window.console.log('Page deleted successfully.');
|
||||||
|
var url = window.location.href;
|
||||||
|
if (url.substr(-1) == '/') url = url.substr(0, url.length - 2);
|
||||||
|
url = url.split('/');
|
||||||
|
url.pop();
|
||||||
|
window.location = url.join('/');
|
||||||
|
} else {
|
||||||
|
alert('Error deleting page.'); // TODO: Replace alerts with auto-timeout popups
|
||||||
|
window.console.log('Error deleting page.');
|
||||||
|
}
|
||||||
|
}, 'json');
|
||||||
|
ev.preventDefault();
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
Reference in New Issue
Block a user