aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs
diff options
context:
space:
mode:
authorHubzilla <hubzilla@hz.macgirvin.com>2017-01-18 17:45:27 -0800
committerHubzilla <hubzilla@hz.macgirvin.com>2017-01-18 17:45:27 -0800
commit6e504b7bc992bebabedfc22f4e9b80dd29761800 (patch)
treee4b30ba9d96803e18a47e95cb1a71e648db84d0b /Zotlabs
parent7f944515dedd5c7a7d36fe5ed3b6bd884eb9be40 (diff)
downloadvolse-hubzilla-6e504b7bc992bebabedfc22f4e9b80dd29761800.tar.gz
volse-hubzilla-6e504b7bc992bebabedfc22f4e9b80dd29761800.tar.bz2
volse-hubzilla-6e504b7bc992bebabedfc22f4e9b80dd29761800.zip
nwiki updates
Diffstat (limited to 'Zotlabs')
-rw-r--r--Zotlabs/Lib/NativeWikiPage.php173
-rw-r--r--Zotlabs/Module/Wiki.php296
2 files changed, 266 insertions, 203 deletions
diff --git a/Zotlabs/Lib/NativeWikiPage.php b/Zotlabs/Lib/NativeWikiPage.php
index c78661654..aa9365993 100644
--- a/Zotlabs/Lib/NativeWikiPage.php
+++ b/Zotlabs/Lib/NativeWikiPage.php
@@ -20,7 +20,8 @@ class NativeWikiPage {
$sql_extra = item_permissions_sql($channel_id,$observer_hash);
- $r = q("select * from item where resource_type = 'nwikipage' and resource_id = '%s' and uid = %d $sql_extra group by mid",
+ $r = q("select * from item where resource_type = 'nwikipage' and resource_id = '%s' and uid = %d
+ $sql_extra group by mid",
dbesc($resource_id),
intval($channel_id)
);
@@ -55,6 +56,9 @@ class NativeWikiPage {
$arr['resource_type'] = 'nwikipage';
$arr['resource_id'] = $resource_id;
+ // We may wish to change this some day.
+ $arr['item_unpublished'] = 1;
+
set_iconfig($arr,'nwikipage','pagetitle',urlencode(($name) ? $name : t('(No Title)')),true);
post_activity_item($arr, false, false);
@@ -77,36 +81,45 @@ class NativeWikiPage {
$channel_id = ((array_key_exists('channel_id',$arr)) ? $arr['channel_id'] : 0);
$w = Zlib\NativeWiki::get_wiki($channel_id, $observer_hash, $resource_id);
- if(! $w['path']) {
+ if(! $w['wiki']) {
return array('message' => t('Wiki not found.'), 'success' => false);
}
- $page_path_old = $w['path'] . '/' . $pageUrlName . \Zlib\NativeWikiPage::get_file_ext($w);
- if(! is_readable($page_path_old) === true) {
- return array('message' => 'Cannot read wiki page: ' . $page_path_old, 'success' => false);
+ $ic = q("select * from iconfig left join item on iconfig.iid = item.id
+ where uid = %d and cat = 'nwikipage' and k = 'pagetitle' and v = '%s'",
+ intval($channel_id),
+ dbesc($pageNewName)
+ );
+
+ if($ic) {
+ return [ 'success' => false, 'message' => t('Destination name already exists') ];
}
- $page = [
- 'rawName' => $pageNewName,
- 'htmlName' => escape_tags($pageNewName),
- 'urlName' => urlencode(escape_tags($pageNewName)),
- 'fileName' => urlencode(escape_tags($pageNewName)) . \Zlib\NativeWikiPage::get_file_ext($w)
- ];
- $page_path_new = $w['path'] . '/' . $page['fileName'] ;
+ $ids = [];
- if(is_file($page_path_new)) {
- return array('message' => 'Page already exists.', 'success' => false);
- }
+ $ic = q("select *, item.id as item_id from iconfig left join item on iconfig.iid = item.id
+ where uid = %d and cat = 'nwikipage' and k = 'pagetitle' and v = '%s'",
+ intval($channel_id),
+ dbesc($pageUrlName)
+ );
+
+ if($ic) {
+ foreach($ic as $c) {
+ set_iconfig($c['item_id'],'nwikipage','pagetitle',$pageNewName);
+ }
- // Rename the page file in the wiki repo
- if(! rename($page_path_old, $page_path_new)) {
- return array('message' => 'Error renaming page file.', 'success' => false);
- }
- else {
- return array('page' => $page, 'message' => '', 'success' => true);
+ $page = [
+ 'rawName' => $pageNewName,
+ 'htmlName' => escape_tags($pageNewName),
+ 'urlName' => urlencode(escape_tags($pageNewName))
+ ];
+
+ return [ 'success' => true, 'page' => $page ];
}
+
+ return [ 'success' => false, 'message' => t('Page not found') ];
}
@@ -178,7 +191,7 @@ class NativeWikiPage {
static public function load_page($arr) {
-logger('arr: ' . print_r($arr,true));
+
$pageUrlName = ((array_key_exists('pageUrlName',$arr)) ? $arr['pageUrlName'] : '');
$resource_id = ((array_key_exists('resource_id',$arr)) ? $arr['resource_id'] : '');
$observer_hash = ((array_key_exists('observer_hash',$arr)) ? $arr['observer_hash'] : '');
@@ -191,7 +204,7 @@ logger('arr: ' . print_r($arr,true));
}
$ids = '';
-dbg(0);
+
$ic = q("select * from iconfig left join item on iconfig.iid = item.id where uid = %d and cat = 'nwikipage' and k = 'pagetitle' and v = '%s'",
intval($channel_id),
dbesc($pageUrlName)
@@ -217,13 +230,13 @@ dbg(0);
dbesc($resource_id),
intval($channel_id)
);
-dbg(0);
+
if($r) {
$items = fetch_post_tags($r,true);
return $items[0];
}
}
-dbg(0);
+
return null;
}
@@ -317,17 +330,23 @@ dbg(0);
return array('message' => t('Error reading wiki'), 'success' => false);
}
+ // fetch the most recently saved revision.
+
$item = self::load_page($arr);
if(! $item) {
return array('message' => t('Page not found'), 'success' => false);
}
+
+ // change just the fields we need to change to create a revision;
+
unset($item['id']);
unset($item['author']);
- $item['parent'] = 0;
- $item['body'] = $content;
+ $item['parent'] = 0;
+ $item['body'] = $content;
$item['author_xchan'] = $observer_hash;
- $item['revision'] = (($arr['revision']) ? intval($arr['revision']) + 1 : intval($item['revision']) + 1);
+ $item['revision'] = (($arr['revision']) ? intval($arr['revision']) + 1 : intval($item['revision']) + 1);
+ $item['edited'] = datetime_convert();
if($item['iconfig'] && is_array($item['iconfig']) && count($item['iconfig'])) {
for($x = 0; $x < count($item['iconfig']); $x ++) {
@@ -352,19 +371,32 @@ dbg(0);
$w = Zlib\NativeWiki::get_wiki($channel_id, $observer_hash, $resource_id);
- if (!$w['path']) {
- return array('message' => t('Error reading wiki'), 'success' => false);
+ if(! $w['wiki']) {
+ return [ 'success' => false, 'message' => t('Error reading wiki') ];
}
- $page_path = $w['path'] . '/' . $pageUrlName . wiki_get_file_ext($w);
- if (is_writable($page_path) === true) {
- if(!unlink($page_path)) {
- return array('message' => t('Error deleting page file'), 'success' => false);
+
+ $ids = [];
+
+ $ic = q("select * from iconfig left join item on iconfig.iid = item.id
+ where uid = %d and cat = 'nwikipage' and k = 'pagetitle' and v = '%s'",
+ intval($channel_id),
+ dbesc($pageUrlName)
+ );
+
+ if($ic) {
+ foreach($ic as $c) {
+ $ids[] = intval($c['iid']);
}
- return array('message' => '', 'success' => true);
- }
- else {
- return array('message' => t('Page file not writable'), 'success' => false);
- }
+ }
+
+ if($ids) {
+ foreach($ids as $id) {
+ drop_item($id,false);
+ }
+ return [ 'success' => true ];
+ }
+
+ return [ 'success' => false, 'message' => t('Nothing deleted') ];
}
static public function revert_page($arr) {
@@ -401,54 +433,41 @@ dbg(0);
static public function compare_page($arr) {
$pageUrlName = ((array_key_exists('pageUrlName',$arr)) ? $arr['pageUrlName'] : '');
$resource_id = ((array_key_exists('resource_id',$arr)) ? $arr['resource_id'] : '');
- $currentCommit = ((array_key_exists('currentCommit',$arr)) ? $arr['currentCommit'] : 'HEAD');
- $compareCommit = ((array_key_exists('compareCommit',$arr)) ? $arr['compareCommit'] : null);
+ $currentCommit = ((array_key_exists('currentCommit',$arr)) ? $arr['currentCommit'] : (-1));
+ $compareCommit = ((array_key_exists('compareCommit',$arr)) ? $arr['compareCommit'] : 0);
$observer_hash = ((array_key_exists('observer_hash',$arr)) ? $arr['observer_hash'] : '');
$channel_id = ((array_key_exists('channel_id',$arr)) ? $arr['channel_id'] : 0);
- if (! $compareCommit) {
- return array('message' => t('No compare commit was provided'), 'success' => false);
- }
-
$w = Zlib\NativeWiki::get_wiki($channel_id, $observer_hash, $resource_id);
- if (!$w['path']) {
+ if (!$w['wiki']) {
return array('message' => t('Error reading wiki'), 'success' => false);
}
- $page_path = $w['path'] . '/' . $pageUrlName . \Zlib\NativeWikiPage::get_file_ext($w);
- if (is_readable($page_path) === true) {
- $reponame = ((array_key_exists('title', $w['wiki'])) ? urlencode($w['wiki']['title']) : 'repo');
- if($reponame === '') {
- $reponame = 'repo';
- }
- $git = new GitRepo('', null, false, $w['wiki']['title'], $w['path']);
- $compareContent = $currentContent = '';
- try {
- foreach ($git->git->tree($currentCommit) as $object) {
- if ($object['type'] == 'blob' && $object['file'] === $pageUrlName . wiki_get_file_ext($w)) {
- $currentContent = $git->git->cat->blob($object['hash']);
- }
- }
- foreach ($git->git->tree($compareCommit) as $object) {
- if ($object['type'] == 'blob' && $object['file'] === $pageUrlName . wiki_get_file_ext($w)) {
- $compareContent = $git->git->cat->blob($object['hash']);
- }
- }
- require_once('library/class.Diff.php');
- $diff = Diff::toTable(Diff::compare($currentContent, $compareContent));
- }
- catch (\PHPGit\Exception\GitException $e) {
- return array('message' => t('GitRepo error thrown'), 'success' => false);
- }
- return array('diff' => $diff, 'message' => '', 'success' => true);
- }
- else {
- return array('message' => t('Page file not writable'), 'success' => false);
+
+ $x = $arr;
+ $x['revision'] = (-1);
+
+ $currpage = self::load_page($x);
+ if($currpage)
+ $currentContent = $currpage['body'];
+
+ $x['revision'] = $compareCommit;
+ $comppage = self::load_page($x);
+ if($comppage)
+ $compareContent = $comppage['body'];
+
+ if($currpage && $comppage) {
+ require_once('library/class.Diff.php');
+ $diff = \Diff::toTable(\Diff::compare($currentContent, $compareContent));
+
+ return [ 'success' => true, 'diff' => $diff ];
}
+ return [ 'success' => false, 'message' => t('Compare: object not found.') ];
+
}
static public function commit($arr) {
-logger('committing');
+
$commit_msg = ((array_key_exists('commit_msg', $arr)) ? $arr['commit_msg'] : t('Page updated'));
$observer_hash = ((array_key_exists('observer_hash',$arr)) ? $arr['observer_hash'] : '');
$channel_id = ((array_key_exists('channel_id',$arr)) ? $arr['channel_id'] : 0);
@@ -468,7 +487,7 @@ logger('committing');
}
$page = self::load_page($arr);
-logger('commit: page: ' . print_r($page,true));
+
if($page) {
set_iconfig($page['id'],'nwikipage','commit_msg',escape_tags($commit_msg),true);
return [ 'success' => true, 'page' => $page ];
diff --git a/Zotlabs/Module/Wiki.php b/Zotlabs/Module/Wiki.php
index 95f7c8704..60a1fb665 100644
--- a/Zotlabs/Module/Wiki.php
+++ b/Zotlabs/Module/Wiki.php
@@ -2,26 +2,30 @@
namespace Zotlabs\Module;
+use \Zotlabs\Lib as Zlib;
+
class Wiki extends \Zotlabs\Web\Controller {
+ private $wiki = null;
+
function init() {
// Determine which channel's wikis to display to the observer
$nick = null;
if (argc() > 1)
$nick = argv(1); // if the channel name is in the URL, use that
- if (!$nick && local_channel()) { // if no channel name was provided, assume the current logged in channel
+ if (! $nick && local_channel()) { // if no channel name was provided, assume the current logged in channel
$channel = \App::get_channel();
if ($channel && $channel['channel_address']) {
$nick = $channel['channel_address'];
goaway(z_root() . '/wiki/' . $nick);
}
}
- if (!$nick) {
- notice(t('You must be logged in to see this page.') . EOL);
- goaway('/login');
+ if (! $nick) {
+ notice( t('Profile Unavailable.') . EOL);
+ goaway(z_root());
}
- profile_load($nick);
+ profile_load($nick);
}
function get() {
@@ -42,6 +46,7 @@ class Wiki extends \Zotlabs\Web\Controller {
// TODO: Combine the interface configuration into a unified object
// Something like $interface = array('new_page_button' => false, 'new_wiki_button' => false, ...)
+
$wiki_owner = false;
$showNewWikiButton = false;
$pageHistory = array();
@@ -49,12 +54,16 @@ class Wiki extends \Zotlabs\Web\Controller {
$resource_id = '';
// init() should have forced the URL to redirect to /wiki/channel so assume argc() > 1
+
$nick = argv(1);
$owner = channelx_by_nick($nick); // The channel who owns the wikis being viewed
if(! $owner) {
notice( t('Invalid channel') . EOL);
goaway('/' . argv(0));
}
+
+ $observer_hash = get_observer_hash();
+
// Determine if the observer is the channel owner so the ACL dialog can be populated
if (local_channel() === intval($owner['channel_id'])) {
@@ -62,12 +71,14 @@ class Wiki extends \Zotlabs\Web\Controller {
// Obtain the default permission settings of the channel
$owner_acl = array(
- 'allow_cid' => $owner['channel_allow_cid'],
- 'allow_gid' => $owner['channel_allow_gid'],
- 'deny_cid' => $owner['channel_deny_cid'],
- 'deny_gid' => $owner['channel_deny_gid']
+ 'allow_cid' => $owner['channel_allow_cid'],
+ 'allow_gid' => $owner['channel_allow_gid'],
+ 'deny_cid' => $owner['channel_deny_cid'],
+ 'deny_gid' => $owner['channel_deny_gid']
);
+
// Initialize the ACL to the channel default permissions
+
$x = array(
'lockstate' => (( $owner['channel_allow_cid'] ||
$owner['channel_allow_gid'] ||
@@ -78,11 +89,12 @@ class Wiki extends \Zotlabs\Web\Controller {
'acl' => populate_acl($owner_acl),
'allow_cid' => acl2json($owner_acl['allow_cid']),
'allow_gid' => acl2json($owner_acl['allow_gid']),
- 'deny_cid' => acl2json($owner_acl['deny_cid']),
- 'deny_gid' => acl2json($owner_acl['deny_gid']),
+ 'deny_cid' => acl2json($owner_acl['deny_cid']),
+ 'deny_gid' => acl2json($owner_acl['deny_gid']),
'bang' => ''
);
- } else {
+ }
+ else {
// Not the channel owner
$owner_acl = $x = array();
}
@@ -91,12 +103,13 @@ class Wiki extends \Zotlabs\Web\Controller {
$o = profile_tabs($a, $is_owner, \App::$profile['channel_address']);
// Download a wiki
+
if((argc() > 3) && (argv(2) === 'download') && (argv(3) === 'wiki')) {
$resource_id = argv(4);
- $w = wiki_get_wiki($resource_id);
- if(!$w['path']) {
+ $w = Zlib\NativeWiki::get_wiki($owner,$observer_hash,$resource_id);
+ if(! $w['htmlName']) {
notice(t('Error retrieving wiki') . EOL);
}
@@ -111,7 +124,7 @@ class Wiki extends \Zotlabs\Web\Controller {
$zip_filepath = '/tmp/' . $zip_folder_name . '/' . $zip_filename;
// Generate the zip file
- \Zotlabs\Lib\ExtendedZip::zipTree($w['path'], $zip_filepath, \ZipArchive::CREATE);
+ ZLib\ExtendedZip::zipTree($w['path'], $zip_filepath, \ZipArchive::CREATE);
// Output the file for download
@@ -131,10 +144,10 @@ class Wiki extends \Zotlabs\Web\Controller {
}
- switch (argc()) {
+ switch(argc()) {
case 2:
- $wikis = wiki_list($owner, get_observer_hash());
- if ($wikis) {
+ $wikis = Zlib\NativeWiki::listwikis($owner, get_observer_hash());
+ if($wikis) {
$o .= replace_macros(get_markup_template('wikilist.tpl'), array(
'$header' => t('Wikis'),
'$channel' => $owner['channel_address'],
@@ -161,72 +174,78 @@ class Wiki extends \Zotlabs\Web\Controller {
return $o;
}
-
break;
+
case 3:
+
// /wiki/channel/wiki -> No page was specified, so redirect to Home.md
+
$wikiUrlName = urlencode(argv(2));
- goaway('/'.argv(0).'/'.argv(1).'/'.$wikiUrlName.'/Home');
+ goaway(z_root() . '/' . argv(0) . '/' . argv(1) . '/' . $wikiUrlName . '/Home');
+
case 4:
+
// GET /wiki/channel/wiki/page
// Fetch the wiki info and determine observer permissions
+
$wikiUrlName = urlencode(argv(2));
$pageUrlName = urlencode(argv(3));
- $w = wiki_exists_by_name($owner['channel_id'], $wikiUrlName);
- if(!$w['resource_id']) {
+ $w = Zlib\NativeWiki::exists_by_name($owner['channel_id'], $wikiUrlName);
+
+ if(! $w['resource_id']) {
notice(t('Wiki not found') . EOL);
- goaway('/'.argv(0).'/'.argv(1));
- return; //not reached
+ goaway(z_root() . '/' . argv(0) . '/' . argv(1));
}
+
$resource_id = $w['resource_id'];
- if (!$wiki_owner) {
+ if(! $wiki_owner) {
// Check for observer permissions
$observer_hash = get_observer_hash();
- $perms = wiki_get_permissions($resource_id, intval($owner['channel_id']), $observer_hash);
- if(!$perms['read']) {
+ $perms = Zlib\NativeWiki::get_permissions($resource_id, intval($owner['channel_id']), $observer_hash);
+ if(! $perms['read']) {
notice(t('Permission denied.') . EOL);
- goaway('/'.argv(0).'/'.argv(1));
+ goaway(z_root() . '/' . argv(0) . '/' . argv(1));
return; //not reached
}
- if($perms['write']) {
- $wiki_editor = true;
- } else {
- $wiki_editor = false;
- }
- } else {
+ $wiki_editor = (($perms['write']) ? true : false);
+ }
+ else {
$wiki_editor = true;
}
+
$wikiheaderName = urldecode($wikiUrlName);
$wikiheaderPage = urldecode($pageUrlName);
+
$renamePage = (($wikiheaderPage === 'Home') ? '' : t('Rename page'));
- $p = wiki_get_page_content(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
- if(!$p['success']) {
- notice(t('Error retrieving page content') . EOL);
- goaway('/'.argv(0).'/'.argv(1).'/'.$wikiUrlName);
- return; //not reached
+ $p = Zlib\NativeWikiPage::get_page_content(array('channel_id' => $owner['channel_id'], 'observer_hash' => $observer_hash, 'resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
+ if(! $p['success']) {
+ notice( t('Error retrieving page content') . EOL);
+ goaway(z_root() . '/' . argv(0) . '/' . argv(1) );
}
$mimeType = $p['mimeType'];
- $rawContent = (($p['mimeType'] == 'text/bbcode') ? htmlspecialchars_decode(json_decode($p['content']),ENT_COMPAT) : htmlspecialchars_decode($p['content'],ENT_COMPAT));
+ $rawContent = (($p['mimeType'] == 'text/bbcode')
+ ? htmlspecialchars_decode(json_decode($p['content']),ENT_COMPAT)
+ : htmlspecialchars_decode($p['content'],ENT_COMPAT)
+ );
$content = ($p['content'] !== '' ? $rawContent : '"# New page\n"');
// Render the Markdown-formatted page content in HTML
if($mimeType == 'text/bbcode') {
- $renderedContent = wiki_convert_links(zidify_links(smilies(bbcode($content))),argv(0).'/'.argv(1).'/'.$wikiUrlName);
+ $renderedContent = Zlib\NativeWikiPage::convert_links(zidify_links(smilies(bbcode($content))), argv(0) . '/' . argv(1) . '/' . $wikiUrlName);
}
else {
require_once('library/markdown.php');
$html = wiki_generate_toc(zidify_text(purify_html(Markdown(wiki_bbcode(json_decode($content))))));
- $renderedContent = wiki_convert_links($html,argv(0).'/'.argv(1).'/'.$wikiUrlName);
+ $renderedContent = wiki_convert_links($html, argv(0) . '/' . argv(1) . '/' . $wikiUrlName);
}
$showPageControls = $wiki_editor;
break;
default: // Strip the extraneous URL components
goaway('/' . argv(0) . '/' . argv(1) . '/' . $wikiUrlName . '/' . $pageUrlName);
- return; //not reached
}
$wikiModalID = random_string(3);
@@ -237,6 +256,8 @@ class Wiki extends \Zotlabs\Web\Controller {
'$ok' => (($showPageControls) ? t('Revert') : ''),
'$cancel' => t('Cancel')
));
+
+ $placeholder = t('Short description of your changes (optional)');
$o .= replace_macros(get_markup_template('wiki.tpl'),array(
'$wikiheaderName' => $wikiheaderName,
@@ -252,7 +273,7 @@ class Wiki extends \Zotlabs\Web\Controller {
'$content' => $content,
'$renderedContent' => $renderedContent,
'$pageRename' => array('pageRename', t('New page name'), '', ''),
- '$commitMsg' => array('commitMsg', '', '', '', '', 'placeholder="Short description of your changes (optional)"'),
+ '$commitMsg' => array('commitMsg', '', '', '', '', 'placeholder="' . $placeholder . '"'),
'$wikiModal' => $wikiModal,
'$wikiModalID' => $wikiModalID,
'$commit' => 'HEAD',
@@ -293,19 +314,20 @@ class Wiki extends \Zotlabs\Web\Controller {
if((argc() > 2) && (argv(2) === 'preview')) {
$content = $_POST['content'];
$resource_id = $_POST['resource_id'];
- $w = wiki_get_wiki($resource_id);
- $wikiURL = argv(0).'/'.argv(1).'/'.$w['urlName'];
+ $w = Zlib\NativeWiki::get_wiki($owner,$observer_hash,$resource_id);
+
+ $wikiURL = argv(0) . '/' . argv(1) . '/' . $w['urlName'];
$mimeType = $w['mimeType'];
if($mimeType == 'text/bbcode') {
- $html = wiki_convert_links(zidify_links(smilies(bbcode($content))),$wikiURL);
+ $html = Zlib\NativeWikiPage::convert_links(zidify_links(smilies(bbcode($content))),$wikiURL);
}
else {
require_once('library/markdown.php');
- $content = wiki_bbcode($content);
- $html = wiki_generate_toc(zidify_text(purify_html(Markdown($content))));
- $html = wiki_convert_links($html,$wikiURL);
+ $content = Zlib\NativeWikiPage::bbcode($content);
+ $html = Zlib\NativeWikiPage::generate_toc(zidify_text(purify_html(Markdown($content))));
+ $html = Zlib\NativeWikiPage::convert_links($html,$wikiURL);
}
json_return_and_die(array('html' => $html, 'success' => true));
}
@@ -336,17 +358,18 @@ class Wiki extends \Zotlabs\Web\Controller {
// Get ACL for permissions
$acl = new \Zotlabs\Access\AccessList($owner);
$acl->set_from_array($_POST);
- $r = wiki_create_wiki($owner, $observer_hash, $wiki, $acl);
- if ($r['success']) {
- $homePage = wiki_create_page('Home', $r['item']['resource_id']);
- if(!$homePage['success']) {
+ $r = Zlib\NativeWiki::create_wiki($owner, $observer_hash, $wiki, $acl);
+ if($r['success']) {
+ $homePage = Zlib\NativeWikiPage::create_page($owner['channel_id'],$observer_hash,'Home', $r['item']['resource_id']);
+ if(! $homePage['success']) {
notice( t('Wiki created, but error creating Home page.'));
- goaway('/wiki/'.$nick.'/'.$wiki['urlName']);
+ goaway(z_root() . '/wiki/' . $nick . '/' . $wiki['urlName']);
}
- goaway('/wiki/'.$nick.'/'.$wiki['urlName'].'/'.$homePage['page']['urlName']);
- } else {
- notice(t('Error creating wiki'));
- goaway('/wiki');
+ goaway(z_root() . '/wiki/' . $nick . '/' . $wiki['urlName'] . '/' . $homePage['page']['urlName']);
+ }
+ else {
+ notice( t('Error creating wiki'));
+ goaway(z_root() . '/wiki');
}
}
@@ -357,15 +380,16 @@ class Wiki extends \Zotlabs\Web\Controller {
// more detail permissions framework
if (local_channel() !== intval($owner['channel_id'])) {
logger('Wiki delete permission denied.');
- json_return_and_die(array('message' => 'Wiki delete permission denied.', 'success' => false));
+ json_return_and_die(array('message' => t('Wiki delete permission denied.'), 'success' => false));
}
$resource_id = $_POST['resource_id'];
- $deleted = wiki_delete_wiki($resource_id);
+ $deleted = Zlib\NativeWiki::delete_wiki($owner['channel_id'],$observer_hash,$resource_id);
if ($deleted['success']) {
json_return_and_die(array('message' => '', 'success' => true));
- } else {
- logger('Error deleting wiki: ' . $resource_id);
- json_return_and_die(array('message' => 'Error deleting wiki', 'success' => false));
+ }
+ else {
+ logger('Error deleting wiki: ' . $resource_id . ' ' . $deleted['message']);
+ json_return_and_die(array('message' => t('Error deleting wiki'), 'success' => false));
}
}
@@ -377,41 +401,46 @@ class Wiki extends \Zotlabs\Web\Controller {
// Determine if observer has permission to create a page
- $perms = wiki_get_permissions($resource_id, intval($owner['channel_id']), $observer_hash);
- if(!$perms['write']) {
+ $perms = Zlib\NativeWiki::get_permissions($resource_id, intval($owner['channel_id']), $observer_hash);
+ if(! $perms['write']) {
logger('Wiki write permission denied. ' . EOL);
json_return_and_die(array('success' => false));
}
- $name = $_POST['name']; //Get new page name
- if(urlencode(escape_tags($_POST['name'])) === '') {
+ $name = $_POST['pageName']; //Get new page name
+ if(urlencode(escape_tags($_POST['pageName'])) === '') {
json_return_and_die(array('message' => 'Error creating page. Invalid name.', 'success' => false));
}
- $page = wiki_create_page($name, $resource_id);
- if ($page['success']) {
+ $page = Zlib\NativeWikiPage::create_page($owner['channel_id'],$observer_hash, $name, $resource_id);
+
+ if($page['success']) {
$ob = \App::get_observer();
- $commit = wiki_git_commit(array(
- 'commit_msg' => t('New page created'),
- 'resource_id' => $resource_id,
- 'observer' => $ob,
- 'files' => array($page['page']['fileName'])
- ));
+ $commit = Zlib\NativeWikiPage::commit(array(
+ 'commit_msg' => t('New page created'),
+ 'resource_id' => $resource_id,
+ 'channel_id' => $owner['channel_id'],
+ 'observer_hash' => $observer_hash,
+ 'pageUrlName' => $name
+ ));
+
if($commit['success']) {
- json_return_and_die(array('url' => '/'.argv(0).'/'.argv(1).'/'.$page['wiki']['urlName'].'/'.$page['page']['urlName'], 'success' => true));
- } else {
- json_return_and_die(array('message' => 'Error making git commit','url' => '/'.argv(0).'/'.argv(1).'/'.$page['wiki']['urlName'].'/'.urlencode($page['page']['urlName']),'success' => false));
+ json_return_and_die(array('url' => '/' . argv(0) . '/' . argv(1) . '/' . $page['wiki']['urlName'] . '/' . $page['page']['urlName'], 'success' => true));
+ }
+ else {
+ json_return_and_die(array('message' => 'Error making git commit','url' => '/' . argv(0) . '/' . argv(1) . '/' . $page['wiki']['urlName'] . '/' . urlencode($page['page']['urlName']),'success' => false));
}
- } else {
+ }
+ else {
logger('Error creating page');
json_return_and_die(array('message' => 'Error creating page.', 'success' => false));
}
}
// Fetch page list for a wiki
- if ((argc() === 5) && (argv(2) === 'get') && (argv(3) === 'page') && (argv(4) === 'list')) {
+ if((argc() === 5) && (argv(2) === 'get') && (argv(3) === 'page') && (argv(4) === 'list')) {
$resource_id = $_POST['resource_id']; // resource_id for wiki in db
- $perms = wiki_get_permissions($resource_id, intval($owner['channel_id']), $observer_hash);
+ $perms = Zlib\NativeWiki::get_permissions($resource_id, intval($owner['channel_id']), $observer_hash);
if(!$perms['read']) {
logger('Wiki read permission denied.' . EOL);
json_return_and_die(array('pages' => null, 'message' => 'Permission denied.', 'success' => false));
@@ -437,27 +466,33 @@ class Wiki extends \Zotlabs\Web\Controller {
}
// Determine if observer has permission to save content
- $perms = wiki_get_permissions($resource_id, intval($owner['channel_id']), $observer_hash);
- if(!$perms['write']) {
+ $perms = Zlib\NativeWiki::get_permissions($resource_id, intval($owner['channel_id']), $observer_hash);
+ if(! $perms['write']) {
logger('Wiki write permission denied. ' . EOL);
json_return_and_die(array('success' => false));
}
- $saved = wiki_save_page(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName, 'content' => $content));
+ $saved = Zlib\NativeWikiPage::save_page(array('channel_id' => $owner['channel_id'], 'observer_hash' => $observer_hash, 'resource_id' => $resource_id, 'pageUrlName' => $pageUrlName, 'content' => $content));
+
if($saved['success']) {
$ob = \App::get_observer();
- $commit = wiki_git_commit(array(
- 'commit_msg' => $commitMsg,
- 'resource_id' => $resource_id,
- 'observer' => $ob,
- 'files' => array($saved['fileName'])
- ));
+ $commit = Zlib\NativeWikiPage::commit(array(
+ 'commit_msg' => $commitMsg,
+ 'pageUrlName' => $pageUrlName,
+ 'resource_id' => $resource_id,
+ 'channel_id' => $owner['channel_id'],
+ 'observer_hash' => $observer_hash,
+ 'revision' => (-1)
+ ));
+
if($commit['success']) {
json_return_and_die(array('message' => 'Wiki git repo commit made', 'success' => true));
- } else {
+ }
+ else {
json_return_and_die(array('message' => 'Error making git commit','success' => false));
}
- } else {
+ }
+ else {
json_return_and_die(array('message' => 'Error saving page', 'success' => false));
}
}
@@ -472,8 +507,8 @@ class Wiki extends \Zotlabs\Web\Controller {
// Determine if observer has permission to read content
- $perms = wiki_get_permissions($resource_id, intval($owner['channel_id']), $observer_hash);
- if(!$perms['read']) {
+ $perms = Zlib\NativeWiki::get_permissions($resource_id, intval($owner['channel_id']), $observer_hash);
+ if(! $perms['read']) {
logger('Wiki read permission denied.' . EOL);
json_return_and_die(array('historyHTML' => '', 'message' => 'Permission denied.', 'success' => false));
}
@@ -481,59 +516,65 @@ class Wiki extends \Zotlabs\Web\Controller {
$historyHTML = widget_wiki_page_history(array(
'resource_id' => $resource_id,
'pageUrlName' => $pageUrlName,
- 'permsWrite' => $perms['write']
+ 'permsWrite' => $perms['write']
));
json_return_and_die(array('historyHTML' => $historyHTML, 'message' => '', 'success' => true));
}
// Delete a page
if ((argc() === 4) && (argv(2) === 'delete') && (argv(3) === 'page')) {
+
$resource_id = $_POST['resource_id'];
$pageUrlName = $_POST['name'];
+
if ($pageUrlName === 'Home') {
- json_return_and_die(array('message' => 'Cannot delete Home','success' => false));
+ json_return_and_die(array('message' => t('Cannot delete Home'),'success' => false));
}
// Determine if observer has permission to delete pages
- $perms = wiki_get_permissions($resource_id, intval($owner['channel_id']), $observer_hash);
- if(!$perms['write']) {
+ $perms = Zlib\NativeWiki::get_permissions($resource_id, intval($owner['channel_id']), $observer_hash);
+ if(! $perms['write']) {
logger('Wiki write permission denied. ' . EOL);
json_return_and_die(array('success' => false));
}
- $deleted = wiki_delete_page(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
+ $deleted = Zlib\NativeWikiPage::delete_page(array('channel_id' => $owner['channel_id'], 'observer_hash' => $observer_hash, 'resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
if($deleted['success']) {
$ob = \App::get_observer();
- $commit = wiki_git_commit(array(
- 'commit_msg' => 'Deleted ' . $pageUrlName,
- 'resource_id' => $resource_id,
- 'observer' => $ob,
- 'files' => null
- ));
+ $commit = Zlib\NativeWikiPage::git_commit(array(
+ 'commit_msg' => 'Deleted ' . $pageUrlName,
+ '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 {
+ }
+ else {
json_return_and_die(array('message' => 'Error making git commit','success' => false));
}
- } else {
+ }
+ else {
json_return_and_die(array('message' => 'Error deleting page', 'success' => false));
}
}
// Revert a page
if ((argc() === 4) && (argv(2) === 'revert') && (argv(3) === 'page')) {
+
+logger('revert was called: ' . print_r($_POST,true));
$resource_id = $_POST['resource_id'];
$pageUrlName = $_POST['name'];
$commitHash = $_POST['commitHash'];
// Determine if observer has permission to revert pages
- $perms = wiki_get_permissions($resource_id, intval($owner['channel_id']), $observer_hash);
- if(!$perms['write']) {
+ $perms = Zlib\NativeWiki::get_permissions($resource_id, intval($owner['channel_id']), $observer_hash);
+ if(! $perms['write']) {
logger('Wiki write permission denied.' . EOL);
json_return_and_die(array('success' => false));
}
- $reverted = wiki_revert_page(array('commitHash' => $commitHash, 'resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
+ $reverted = Zlib\NativeWikiPage::revert_page(array('channel_id' => $owner['channel_id'], 'observer_hash' => $observer_hash, 'commitHash' => $commitHash, 'resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
if($reverted['success']) {
json_return_and_die(array('content' => $reverted['content'], 'message' => '', 'success' => true));
} else {
@@ -549,15 +590,15 @@ class Wiki extends \Zotlabs\Web\Controller {
$currentCommit = $_POST['currentCommit'];
// Determine if observer has permission to revert pages
- $perms = wiki_get_permissions($resource_id, intval($owner['channel_id']), $observer_hash);
+ $perms = Zlib\NativeWiki::get_permissions($resource_id, intval($owner['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));
+ $compare = Zlib\NativeWikiPage::compare_page(array('channel_id' => $owner['channel_id'], 'observer_hash' => $observer_hash, 'currentCommit' => $currentCommit, 'compareCommit' => $compareCommit, 'resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
if($compare['success']) {
- $diffHTML = '<table class="text-center" width="100%"><tr><td class="lead" width="50%">Current Revision</td><td class="lead" width="50%">Selected Revision</td></tr></table>' . $compare['diff'];
+ $diffHTML = '<table class="text-center" width="100%"><tr><td class="lead" width="50%">' . t('Current Revision') . '</td><td class="lead" width="50%">' . t('Selected Revision') . '</td></tr></table>' . $compare['diff'];
json_return_and_die(array('diff' => $diffHTML, 'message' => '', 'success' => true));
} else {
json_return_and_die(array('diff' => '', 'message' => 'Error comparing page', 'success' => false));
@@ -577,34 +618,37 @@ class Wiki extends \Zotlabs\Web\Controller {
}
// Determine if observer has permission to rename pages
- $perms = wiki_get_permissions($resource_id, intval($owner['channel_id']), $observer_hash);
- if(!$perms['write']) {
+ $perms = Zlib\NativeWikiPage::get_permissions($resource_id, intval($owner['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));
+ $renamed = Zlib\NativeWikiPage::rename_page(array('channel_id' => $owner['channel_id'], 'observer_hash' => $observer_hash, 'resource_id' => $resource_id, 'pageUrlName' => $pageUrlName, 'pageNewName' => $pageNewName));
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 . substr($renamed['page']['fileName'], -3), $renamed['page']['fileName']),
- 'all' => true
- ));
+ 'commit_msg' => 'Renamed ' . urldecode($pageUrlName) . ' to ' . $renamed['page']['htmlName'],
+ 'resource_id' => $resource_id,
+ 'observer' => $ob,
+ 'files' => array($pageUrlName . substr($renamed['page']['fileName'], -3), $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 {
+ }
+ else {
json_return_and_die(array('message' => 'Error making git commit','success' => false));
}
- } else {
+ }
+ else {
json_return_and_die(array('message' => 'Error renaming page', 'success' => false));
}
}
//notice( t('You must be authenticated.'));
- json_return_and_die(array('message' => 'You must be authenticated.', 'success' => false));
+ json_return_and_die(array('message' => t('You must be authenticated.'), 'success' => false));
}
}