aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Zotlabs/Module/Wiki.php55
-rw-r--r--include/wiki.php18
-rw-r--r--view/tpl/wiki.tpl34
3 files changed, 99 insertions, 8 deletions
diff --git a/Zotlabs/Module/Wiki.php b/Zotlabs/Module/Wiki.php
index ef42c85cf..e335e8917 100644
--- a/Zotlabs/Module/Wiki.php
+++ b/Zotlabs/Module/Wiki.php
@@ -80,7 +80,8 @@ class Wiki extends \Zotlabs\Web\Controller {
break;
case 3:
// /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:
// GET /wiki/channel/wiki/page
// 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));
if(!$p['success']) {
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"');
$hide_editor = false;
@@ -116,7 +117,7 @@ class Wiki extends \Zotlabs\Web\Controller {
$pageHistory = wiki_page_history(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
break;
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
require_once('library/markdown.php');
@@ -287,7 +288,6 @@ class Wiki extends \Zotlabs\Web\Controller {
$nick = argv(1);
$resource_id = $_POST['resource_id'];
$pageUrlName = $_POST['name'];
- logger('pageURLname: ' . $pageUrlName);
$pageHtmlName = escape_tags($_POST['name']);
$content = escape_tags($_POST['content']); //Get new 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));
}
+ // 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.');
json_return_and_die(array('message' => 'You must be authenticated.', 'success' => false));
diff --git a/include/wiki.php b/include/wiki.php
index ccf47ef9a..1f90fae1e 100644
--- a/include/wiki.php
+++ b/include/wiki.php
@@ -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) {
$files = ((array_key_exists('files', $arr)) ? $arr['files'] : null);
$commit_msg = ((array_key_exists('commit_msg', $arr)) ? $arr['commit_msg'] : 'Repo updated');
diff --git a/view/tpl/wiki.tpl b/view/tpl/wiki.tpl
index 384dc796d..6cdfabdb9 100644
--- a/view/tpl/wiki.tpl
+++ b/view/tpl/wiki.tpl
@@ -5,10 +5,10 @@
height: 500px;
}
.fade.in {
- -webkit-transition: opacity 2s 1s ease;
- -moz-transition: opacity 2s 1s ease;
- -o-transition: opacity 2s 1s ease;
- transition: opacity 2s 1s ease;
+ -webkit-transition: opacity 0.5s 0.5s ease;
+ -moz-transition: opacity 0.5s 0.5s ease;
+ -o-transition: opacity 0.5s 0.5s ease;
+ transition: opacity 0.5s 0.5s ease;
}
</style>
<div class="generic-content-wrapper">
@@ -106,6 +106,9 @@
<script>
window.wiki_resource_id = '{{$resource_id}}';
window.wiki_page_name = '{{$page}}';
+ if (window.wiki_page_name === 'Home') {
+ $('#delete-page').hide();
+ }
$(document).ready(function () {
wiki_refresh_page_list();
// Show Edit tab first. Otherwise the Ace editor does not load.
@@ -206,4 +209,27 @@ function wiki_delete_wiki(wikiHtmlName, resource_id) {
}, 'json');
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>