aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Module
diff options
context:
space:
mode:
authorAndrew Manning <tamanning@zoho.com>2016-06-15 06:25:31 -0400
committerAndrew Manning <tamanning@zoho.com>2016-06-15 06:25:31 -0400
commit688171d016412f30a3ed60d4dc70feb64a19621b (patch)
treef664ba56a4b2df71db208b848db72b1ce1396b99 /Zotlabs/Module
parente5a919c32eae5c04d44e1e60ddadf95a63f9deb3 (diff)
downloadvolse-hubzilla-688171d016412f30a3ed60d4dc70feb64a19621b.tar.gz
volse-hubzilla-688171d016412f30a3ed60d4dc70feb64a19621b.tar.bz2
volse-hubzilla-688171d016412f30a3ed60d4dc70feb64a19621b.zip
Rename page feature added. Fixed bug in git commit function and other minor fixes.
Diffstat (limited to 'Zotlabs/Module')
-rw-r--r--Zotlabs/Module/Wiki.php54
1 files changed, 50 insertions, 4 deletions
diff --git a/Zotlabs/Module/Wiki.php b/Zotlabs/Module/Wiki.php
index f1f7b87b2..9e7d151b5 100644
--- a/Zotlabs/Module/Wiki.php
+++ b/Zotlabs/Module/Wiki.php
@@ -72,7 +72,8 @@ class Wiki extends \Zotlabs\Web\Controller {
switch (argc()) {
case 2:
// Configure page template
- $wikiheader = t('Wiki Sandbox');
+ $wikiheaderName = t('Wiki');
+ $wikiheaderPage = t('Sandbox');
$content = '"# Wiki Sandbox\n\nContent you **edit** and **preview** here *will not be saved*."';
$hide_editor = false;
$showPageControls = false;
@@ -113,7 +114,8 @@ class Wiki extends \Zotlabs\Web\Controller {
} else {
$wiki_editor = true;
}
- $wikiheader = urldecode($wikiUrlName) . ': ' . urldecode($pageUrlName); // show wiki name and page
+ $wikiheaderName = urldecode($wikiUrlName);
+ $wikiheaderPage = urldecode($pageUrlName);
$p = wiki_get_page_content(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
if(!$p['success']) {
notice('Error retrieving page content' . EOL);
@@ -135,7 +137,8 @@ class Wiki extends \Zotlabs\Web\Controller {
require_once('library/markdown.php');
$o .= replace_macros(get_markup_template('wiki.tpl'),array(
- '$wikiheader' => $wikiheader,
+ '$wikiheaderName' => $wikiheaderName,
+ '$wikiheaderPage' => $wikiheaderPage,
'$hideEditor' => $hide_editor,
'$showPageControls' => $showPageControls,
'$showNewWikiButton'=> $showNewWikiButton,
@@ -152,6 +155,7 @@ class Wiki extends \Zotlabs\Web\Controller {
'$renderedContent' => Markdown(json_decode($content)),
'$wikiName' => array('wikiName', t('Enter the name of your new wiki:'), '', ''),
'$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']
));
@@ -377,7 +381,7 @@ class Wiki extends \Zotlabs\Web\Controller {
if($deleted['success']) {
$ob = \App::get_observer();
$commit = wiki_git_commit(array(
- 'commit_msg' => 'Deleted ' . $pageHtmlName,
+ 'commit_msg' => 'Deleted ' . $pageUrlName,
'resource_id' => $resource_id,
'observer' => $ob,
'files' => null
@@ -416,6 +420,48 @@ class Wiki extends \Zotlabs\Web\Controller {
}
}
+ // Rename a page
+ if ((argc() === 4) && (argv(2) === 'rename') && (argv(3) === 'page')) {
+ $resource_id = $_POST['resource_id'];
+ $pageUrlName = $_POST['oldName'];
+ $pageNewName = $_POST['newName'];
+ if ($pageUrlName === 'Home') {
+ json_return_and_die(array('message' => 'Cannot rename Home','success' => false));
+ }
+ if(urlencode(escape_tags($pageNewName)) === '') {
+ json_return_and_die(array('message' => 'Error renaming page. Invalid name.', 'success' => false));
+ }
+ // Determine if observer has permission to rename 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['write']) {
+ logger('Wiki write permission denied. ' . EOL);
+ json_return_and_die(array('success' => false));
+ }
+ }
+ $renamed = wiki_rename_page(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName, 'pageNewName' => $pageNewName));
+ logger('$renamed: ' . json_encode($renamed));
+ if($renamed['success']) {
+ $ob = \App::get_observer();
+ $commit = wiki_git_commit(array(
+ 'commit_msg' => 'Renamed ' . urldecode($pageUrlName) . ' to ' . $renamed['page']['htmlName'],
+ 'resource_id' => $resource_id,
+ 'observer' => $ob,
+ 'files' => array($pageUrlName . '.md', $renamed['page']['fileName']),
+ 'all' => true
+ ));
+ if($commit['success']) {
+ json_return_and_die(array('name' => $renamed['page'], '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 renaming page', 'success' => false));
+ }
+ }
//notice('You must be authenticated.');
json_return_and_die(array('message' => 'You must be authenticated.', 'success' => false));