aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Module/Wiki.php
diff options
context:
space:
mode:
authorAndrew Manning <tamanning@zoho.com>2016-06-17 06:33:39 -0400
committerAndrew Manning <tamanning@zoho.com>2016-06-17 06:33:39 -0400
commit961539258be90f5b7c989299db0e8c551d0d6c72 (patch)
tree8c1e37dd56e06ed157feb9288fba7867f18e0034 /Zotlabs/Module/Wiki.php
parentaa77b04860a68370d829f1081418e69777d0e1f9 (diff)
downloadvolse-hubzilla-961539258be90f5b7c989299db0e8c551d0d6c72.tar.gz
volse-hubzilla-961539258be90f5b7c989299db0e8c551d0d6c72.tar.bz2
volse-hubzilla-961539258be90f5b7c989299db0e8c551d0d6c72.zip
Wiki page revision comparison tool with diff displayed in modal dialog. Leverages Diff class from http://code.stephenmorley.org/php/diff-implementation with license CC0 1.0 universal http://creativecommons.org/publicdomain/zero/1.0/legalcode
Diffstat (limited to 'Zotlabs/Module/Wiki.php')
-rw-r--r--Zotlabs/Module/Wiki.php42
1 files changed, 40 insertions, 2 deletions
diff --git a/Zotlabs/Module/Wiki.php b/Zotlabs/Module/Wiki.php
index 9e7d151b5..83fa0e337 100644
--- a/Zotlabs/Module/Wiki.php
+++ b/Zotlabs/Module/Wiki.php
@@ -136,6 +136,16 @@ class Wiki extends \Zotlabs\Web\Controller {
// Render the Markdown-formatted page content in HTML
require_once('library/markdown.php');
+ $wikiModalID = random_string(3);
+ $wikiModal = replace_macros(
+ get_markup_template('generic_modal.tpl'), array(
+ '$id' => $wikiModalID,
+ '$title' => t('Revision Comparison'),
+ '$ok' => t('Revert'),
+ '$cancel' => t('Cancel')
+ )
+ );
+
$o .= replace_macros(get_markup_template('wiki.tpl'),array(
'$wikiheaderName' => $wikiheaderName,
'$wikiheaderPage' => $wikiheaderPage,
@@ -157,7 +167,10 @@ class Wiki extends \Zotlabs\Web\Controller {
'$pageName' => array('pageName', t('Enter the name of the new page:'), '', ''),
'$pageRename' => array('pageRename', t('Enter the new name:'), '', ''),
'$commitMsg' => array('commitMsg', '', '', '', '', 'placeholder="(optional) Enter a custom message when saving the page..."'),
- '$pageHistory' => $pageHistory['history']
+ '$pageHistory' => $pageHistory['history'],
+ '$wikiModal' => $wikiModal,
+ '$wikiModalID' => $wikiModalID,
+ '$commit' => 'HEAD'
));
head_add_js('library/ace/ace.js'); // Ace Code Editor
return $o;
@@ -412,7 +425,7 @@ class Wiki extends \Zotlabs\Web\Controller {
json_return_and_die(array('success' => false));
}
}
- $reverted = wiki_revert_page(array('commitHash' => $commitHash, 'observer' => \App::get_observer(), 'resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
+ $reverted = wiki_revert_page(array('commitHash' => $commitHash, 'resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
if($reverted['success']) {
json_return_and_die(array('content' => $reverted['content'], 'message' => '', 'success' => true));
} else {
@@ -420,6 +433,31 @@ class Wiki extends \Zotlabs\Web\Controller {
}
}
+ // Compare page revisions
+ if ((argc() === 4) && (argv(2) === 'compare') && (argv(3) === 'page')) {
+ $resource_id = $_POST['resource_id'];
+ $pageUrlName = $_POST['name'];
+ $compareCommit = $_POST['compareCommit'];
+ $currentCommit = $_POST['currentCommit'];
+ // Determine if observer has permission to revert pages
+ $nick = argv(1);
+ $channel = get_channel_by_nick($nick);
+ if (local_channel() !== intval($channel['channel_id'])) {
+ $observer_hash = get_observer_hash();
+ $perms = wiki_get_permissions($resource_id, intval($channel['channel_id']), $observer_hash);
+ if(!$perms['read']) {
+ logger('Wiki read permission denied.' . EOL);
+ json_return_and_die(array('success' => false));
+ }
+ }
+ $compare = wiki_compare_page(array('currentCommit' => $currentCommit, 'compareCommit' => $compareCommit, 'resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
+ if($compare['success']) {
+ json_return_and_die(array('diff' => $compare['diff'], 'message' => '', 'success' => true));
+ } else {
+ json_return_and_die(array('diff' => '', 'message' => 'Error comparing page', 'success' => false));
+ }
+ }
+
// Rename a page
if ((argc() === 4) && (argv(2) === 'rename') && (argv(3) === 'page')) {
$resource_id = $_POST['resource_id'];