aboutsummaryrefslogtreecommitdiffstats
path: root/include/wiki.php
diff options
context:
space:
mode:
authorAndrew Manning <tamanning@zoho.com>2016-06-05 16:32:03 -0400
committerAndrew Manning <tamanning@zoho.com>2016-06-05 16:32:03 -0400
commit0a3fbdd128dd3b80868c93cb93901b501edf576c (patch)
treefeff8120476bcc96f5c4c327ac66d0724fcfa2ac /include/wiki.php
parent4bc4fd5b7ebd7c5f25cfc9acfbda5b14a38dedb8 (diff)
downloadvolse-hubzilla-0a3fbdd128dd3b80868c93cb93901b501edf576c.tar.gz
volse-hubzilla-0a3fbdd128dd3b80868c93cb93901b501edf576c.tar.bz2
volse-hubzilla-0a3fbdd128dd3b80868c93cb93901b501edf576c.zip
Basic page reversion implemented. The revert button on the history view replaces the editor text but does not save the page.
Diffstat (limited to 'include/wiki.php')
-rw-r--r--include/wiki.php39
1 files changed, 38 insertions, 1 deletions
diff --git a/include/wiki.php b/include/wiki.php
index 1f90fae1e..cc948dee2 100644
--- a/include/wiki.php
+++ b/include/wiki.php
@@ -263,7 +263,6 @@ function wiki_page_history($arr) {
$git = new GitRepo('', null, false, $w['wiki']['title'], $w['path']);
try {
$gitlog = $git->git->log('', $page_path , array('limit' => 500));
- logger('gitlog: ' . json_encode($gitlog));
return array('history' => $gitlog, 'message' => '', 'success' => true);
} catch (\PHPGit\Exception\GitException $e) {
return array('history' => null, 'message' => 'GitRepo error thrown', 'success' => false);
@@ -307,6 +306,44 @@ function wiki_delete_page($arr) {
}
}
+function wiki_revert_page($arr) {
+ $pageUrlName = ((array_key_exists('pageUrlName',$arr)) ? $arr['pageUrlName'] : '');
+ $resource_id = ((array_key_exists('resource_id',$arr)) ? $arr['resource_id'] : '');
+ $commitHash = ((array_key_exists('commitHash',$arr)) ? $arr['commitHash'] : null);
+ if (! $commitHash) {
+ return array('content' => $content, 'message' => 'No commit has provided', 'success' => false);
+ }
+ $w = wiki_get_wiki($resource_id);
+ if (!$w['path']) {
+ return array('content' => $content, 'message' => 'Error reading wiki', 'success' => false);
+ }
+ $page_path = $w['path'].'/'.$pageUrlName.'.md';
+ if (is_writable($page_path) === true) {
+
+ $reponame = ((array_key_exists('title', $w['wiki'])) ? urlencode($w['wiki']['title']) : 'repo');
+ if($reponame === '') {
+ $reponame = 'repo';
+ }
+ $git = new GitRepo($observer['xchan_addr'], null, false, $w['wiki']['title'], $w['path']);
+ $content = null;
+ try {
+ $git->setIdentity($observer['xchan_name'], $observer['xchan_addr']);
+ foreach ($git->git->tree($commitHash) as $object) {
+ logger('tree object: ' . json_encode($object));
+ if ($object['type'] == 'blob' && $object['file'] === $pageUrlName.'.md' ) {
+ $content = $git->git->cat->blob($object['hash']);
+ logger('content: ' . json_encode($content));
+ }
+ }
+ } catch (\PHPGit\Exception\GitException $e) {
+ json_return_and_die(array('content' => $content, 'message' => 'GitRepo error thrown', 'success' => false));
+ }
+ return array('content' => $content, 'message' => '', 'success' => true);
+ } else {
+ return array('content' => $content, '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');