From 0f5a166cceef6dcfb5f29077122eabd09ef290be Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 15 Nov 2016 02:12:30 -0800 Subject: still a bit of wiki permission weirdness, this should catch the major ones --- include/wiki.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'include/wiki.php') diff --git a/include/wiki.php b/include/wiki.php index d52308b08..1d1e20e27 100644 --- a/include/wiki.php +++ b/include/wiki.php @@ -192,8 +192,9 @@ function wiki_exists_by_name($uid, $urlName) { function wiki_get_permissions($resource_id, $owner_id, $observer_hash) { // TODO: For now, only the owner can edit $sql_extra = item_permissions_sql($owner_id, $observer_hash); - $r = q("SELECT * FROM item WHERE resource_type = '%s' AND resource_id = '%s' $sql_extra LIMIT 1", - dbesc(WIKI_ITEM_RESOURCE_TYPE), + $r = q("SELECT * FROM item WHERE uid = %d and resource_type = '%s' AND resource_id = '%s' $sql_extra LIMIT 1", + intval($owner_id), + dbesc(WIKI_ITEM_RESOURCE_TYPE), dbesc($resource_id) ); -- cgit v1.2.3 From 501bd814c3a057684b102bc4c6cb8e0b7403debd Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 15 Nov 2016 18:43:26 -0800 Subject: wiki: simplify permission model, reduce duplicate calls to get the same channel info and permissions, return the owner permissions with the normal permission check (keeping all permission fetching in one place), rename the 'channel' variable to 'owner' in several places to identify this channel role more clearly as to the way it is being used in this module, update the deprecated call to proc_run (include/notifier) and make several notice messages translatable. --- include/wiki.php | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'include/wiki.php') diff --git a/include/wiki.php b/include/wiki.php index 1d1e20e27..ffa8b66d3 100644 --- a/include/wiki.php +++ b/include/wiki.php @@ -13,11 +13,13 @@ function wiki_list($channel, $observer_hash) { dbesc(WIKI_ITEM_RESOURCE_TYPE), intval($channel['channel_id']) ); - foreach($wikis as &$w) { - $w['rawName'] = get_iconfig($w, 'wiki', 'rawName'); - $w['htmlName'] = get_iconfig($w, 'wiki', 'htmlName'); - $w['urlName'] = get_iconfig($w, 'wiki', 'urlName'); - $w['path'] = get_iconfig($w, 'wiki', 'path'); + if($wikis) { + foreach($wikis as &$w) { + $w['rawName'] = get_iconfig($w, 'wiki', 'rawName'); + $w['htmlName'] = get_iconfig($w, 'wiki', 'htmlName'); + $w['urlName'] = get_iconfig($w, 'wiki', 'urlName'); + $w['path'] = get_iconfig($w, 'wiki', 'path'); + } } // TODO: query db for wikis the observer can access. Return with two lists, for read and write access return array('wikis' => $wikis); @@ -125,7 +127,7 @@ function wiki_create_wiki($channel, $observer_hash, $wiki, $acl) { $item_id = $post['item_id']; if ($item_id) { - proc_run('php', "include/notifier.php", "activity", $item_id); + \Zotlabs\Daemon\Master::Summon(array('Notifier', 'activity', $item_id)); return array('item' => $arr, 'success' => true); } else { return array('item' => null, 'success' => false); @@ -192,23 +194,23 @@ function wiki_exists_by_name($uid, $urlName) { function wiki_get_permissions($resource_id, $owner_id, $observer_hash) { // TODO: For now, only the owner can edit $sql_extra = item_permissions_sql($owner_id, $observer_hash); + + if(local_channel() && local_channel == $owner_id) { + return [ 'read' => true, 'write' => true, 'success' => true ]; + } + $r = q("SELECT * FROM item WHERE uid = %d and resource_type = '%s' AND resource_id = '%s' $sql_extra LIMIT 1", intval($owner_id), dbesc(WIKI_ITEM_RESOURCE_TYPE), dbesc($resource_id) ); - + if (!$r) { return array('read' => false, 'write' => false, 'success' => true); } else { - $perms = get_all_perms($owner_id, $observer_hash); // TODO: Create a new permission setting for wiki analogous to webpages. Until // then, use webpage permissions - if (!$perms['write_pages']) { - $write = false; - } else { - $write = true; - } + $write = perm_is_allowed($owner_id, $observer_hash,'write_pages'); return array('read' => true, 'write' => $write, 'success' => true); } } -- cgit v1.2.3 From 91c803ff65314ff50621556da102ea37223cc64c Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 16 Nov 2016 14:13:10 -0800 Subject: use item from DB for return value --- include/wiki.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/wiki.php') diff --git a/include/wiki.php b/include/wiki.php index ffa8b66d3..bcdf9d7d8 100644 --- a/include/wiki.php +++ b/include/wiki.php @@ -128,7 +128,7 @@ function wiki_create_wiki($channel, $observer_hash, $wiki, $acl) { if ($item_id) { \Zotlabs\Daemon\Master::Summon(array('Notifier', 'activity', $item_id)); - return array('item' => $arr, 'success' => true); + return array('item' => $post['item'], 'success' => true); } else { return array('item' => null, 'success' => false); } -- cgit v1.2.3 From d5c14a513d435aade7d16d792a7e7a22ff9b01ff Mon Sep 17 00:00:00 2001 From: Andrew Manning Date: Fri, 18 Nov 2016 21:25:40 -0500 Subject: Wiki pages display in tab to the left of the edit pane tab. Home is always first in the list. --- include/wiki.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'include/wiki.php') diff --git a/include/wiki.php b/include/wiki.php index bcdf9d7d8..d2cb51bd3 100644 --- a/include/wiki.php +++ b/include/wiki.php @@ -32,13 +32,16 @@ function wiki_page_list($resource_id) { return array('pages' => null, 'wiki' => null); } $pages = array(); + $pages[] = array('title' => 'Home', 'url' => 'Home'); if (is_dir($w['path']) === true) { $files = array_diff(scandir($w['path']), array('.', '..', '.git')); // TODO: Check that the files are all text files foreach($files as $file) { // strip the .md file extension and unwrap URL encoding to leave HTML encoded name - $pages[] = array('title' => urldecode(substr($file, 0, -3)), 'url' => urlencode(substr($file, 0, -3))); + if( urldecode(substr($file, 0, -3)) !== 'Home') { + $pages[] = array('title' => urldecode(substr($file, 0, -3)), 'url' => urlencode(substr($file, 0, -3))); + } } } -- cgit v1.2.3 From 1ce4eda0b92e13615991ec22d3b789c640991431 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Mon, 28 Nov 2016 11:29:10 +0100 Subject: wiki: move delete page functionality to the widget --- include/wiki.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'include/wiki.php') diff --git a/include/wiki.php b/include/wiki.php index d2cb51bd3..eb87840f6 100644 --- a/include/wiki.php +++ b/include/wiki.php @@ -31,16 +31,29 @@ function wiki_page_list($resource_id) { if (!$w['path']) { return array('pages' => null, 'wiki' => null); } - $pages = array(); - $pages[] = array('title' => 'Home', 'url' => 'Home'); + + $pages[] = [ + 'resource_id' => '', + 'title' => 'Home', + 'url' => 'Home', + 'link_id' => 'id_wiki_home_0' + ]; + if (is_dir($w['path']) === true) { $files = array_diff(scandir($w['path']), array('.', '..', '.git')); // TODO: Check that the files are all text files - + $i = 1; foreach($files as $file) { // strip the .md file extension and unwrap URL encoding to leave HTML encoded name - if( urldecode(substr($file, 0, -3)) !== 'Home') { - $pages[] = array('title' => urldecode(substr($file, 0, -3)), 'url' => urlencode(substr($file, 0, -3))); + $title = substr($file, 0, -3); + if(urldecode($title) !== 'Home') { + $pages[] = [ + 'resource_id' => $resource_id, + 'title' => urldecode($title), + 'url' => $title, + 'link_id' => 'id_' . substr($resource_id, 0, 10) . '_' . $i + ]; + $i++; } } } -- cgit v1.2.3 From f9b732482d1776ba0c8cad593157589189f6bedd Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Mon, 28 Nov 2016 15:24:49 +0100 Subject: some basic work for implementing mimetypes for wikis --- include/wiki.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'include/wiki.php') diff --git a/include/wiki.php b/include/wiki.php index eb87840f6..c6ef7fe59 100644 --- a/include/wiki.php +++ b/include/wiki.php @@ -139,6 +139,9 @@ function wiki_create_wiki($channel, $observer_hash, $wiki, $acl) { if (!set_iconfig($arr, 'wiki', 'urlName', $wiki['urlName'], true)) { return array('item' => null, 'success' => false); } + if (!set_iconfig($arr, 'wiki', 'mimteType', $wiki['mimeType'], true)) { + return array('item' => null, 'success' => false); + } $post = item_store($arr); $item_id = $post['item_id']; @@ -179,17 +182,20 @@ function wiki_get_wiki($resource_id) { $rawName = get_iconfig($w, 'wiki', 'rawName'); $htmlName = get_iconfig($w, 'wiki', 'htmlName'); $urlName = get_iconfig($w, 'wiki', 'urlName'); + $mimeType = get_iconfig($w, 'wiki', 'mimeType'); $path = get_iconfig($w, 'wiki', 'path'); if (!realpath(__DIR__ . '/../' . $path)) { return array('wiki' => null, 'path' => null); } // Path to wiki exists $abs_path = realpath(__DIR__ . '/../' . $path); - return array( 'wiki' => $w, - 'path' => $abs_path, - 'rawName' => $rawName, - 'htmlName' => $htmlName, - 'urlName' => $urlName + return array( + 'wiki' => $w, + 'path' => $abs_path, + 'rawName' => $rawName, + 'htmlName' => $htmlName, + 'urlName' => $urlName, + 'mimeType' => $mimeType ); } } -- cgit v1.2.3 From d184b3fa8674a349b274b69655b8e8c38dab064b Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Tue, 29 Nov 2016 10:33:46 +0100 Subject: more work on wiki mimetypes --- include/wiki.php | 57 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 27 deletions(-) (limited to 'include/wiki.php') diff --git a/include/wiki.php b/include/wiki.php index c6ef7fe59..8fbabcbef 100644 --- a/include/wiki.php +++ b/include/wiki.php @@ -19,6 +19,7 @@ function wiki_list($channel, $observer_hash) { $w['htmlName'] = get_iconfig($w, 'wiki', 'htmlName'); $w['urlName'] = get_iconfig($w, 'wiki', 'urlName'); $w['path'] = get_iconfig($w, 'wiki', 'path'); + $w['path'] = get_iconfig($w, 'wiki', 'mimeType'); } } // TODO: query db for wikis the observer can access. Return with two lists, for read and write access @@ -44,7 +45,7 @@ function wiki_page_list($resource_id) { // TODO: Check that the files are all text files $i = 1; foreach($files as $file) { - // strip the .md file extension and unwrap URL encoding to leave HTML encoded name + // strip the file extension and unwrap URL encoding to leave HTML encoded name $title = substr($file, 0, -3); if(urldecode($title) !== 'Home') { $pages[] = [ @@ -91,7 +92,7 @@ function wiki_create_wiki($channel, $observer_hash, $wiki, $acl) { $resource_id = random_string(); $r = q("SELECT mid FROM item WHERE resource_id = '%s' AND resource_type = '%s' AND uid = %d LIMIT 1", dbesc($resource_id), - dbesc(WIKI_ITEM_RESOURCE_TYPE), + dbesc(WIKI_ITEM_RESOURCE_TYPE), intval($channel['channel_id']) ); if (count($r)) @@ -139,7 +140,7 @@ function wiki_create_wiki($channel, $observer_hash, $wiki, $acl) { if (!set_iconfig($arr, 'wiki', 'urlName', $wiki['urlName'], true)) { return array('item' => null, 'success' => false); } - if (!set_iconfig($arr, 'wiki', 'mimteType', $wiki['mimeType'], true)) { + if (!set_iconfig($arr, 'wiki', 'mimeType', $wiki['mimeType'], true)) { return array('item' => null, 'success' => false); } $post = item_store($arr); @@ -171,8 +172,8 @@ function wiki_delete_wiki($resource_id) { function wiki_get_wiki($resource_id) { $item = q("SELECT * FROM item WHERE resource_type = '%s' AND resource_id = '%s' AND item_deleted = 0 limit 1", - dbesc(WIKI_ITEM_RESOURCE_TYPE), - dbesc($resource_id) + dbesc(WIKI_ITEM_RESOURCE_TYPE), + dbesc($resource_id) ); if (!$item) { return array('wiki' => null, 'path' => null); @@ -183,6 +184,7 @@ function wiki_get_wiki($resource_id) { $htmlName = get_iconfig($w, 'wiki', 'htmlName'); $urlName = get_iconfig($w, 'wiki', 'urlName'); $mimeType = get_iconfig($w, 'wiki', 'mimeType'); + $path = get_iconfig($w, 'wiki', 'path'); if (!realpath(__DIR__ . '/../' . $path)) { return array('wiki' => null, 'path' => null); @@ -242,7 +244,8 @@ function wiki_create_page($name, $resource_id) { if (!$w['path']) { return array('page' => null, 'wiki' => null, 'message' => 'Wiki not found.', 'success' => false); } - $page = array('rawName' => $name, 'htmlName' => escape_tags($name), 'urlName' => urlencode(escape_tags($name)), 'fileName' => urlencode(escape_tags($name)).'.md'); + + $page = array('rawName' => $name, 'htmlName' => escape_tags($name), 'urlName' => urlencode(escape_tags($name)), 'fileName' => urlencode(escape_tags($name)) . wiki_get_mimetype($w)); $page_path = $w['path'] . '/' . $page['fileName']; if (is_file($page_path)) { return array('page' => null, 'wiki' => null, 'message' => 'Page already exists.', 'success' => false); @@ -264,11 +267,11 @@ function wiki_rename_page($arr) { if (!$w['path']) { return array('message' => 'Wiki not found.', 'success' => false); } - $page_path_old = $w['path'].'/'.$pageUrlName.'.md'; + $page_path_old = $w['path'] . '/' . $pageUrlName . wiki_get_mimetype($w); if (!is_readable($page_path_old) === true) { return array('message' => 'Cannot read wiki page: ' . $page_path_old, 'success' => false); } - $page = array('rawName' => $pageNewName, 'htmlName' => escape_tags($pageNewName), 'urlName' => urlencode(escape_tags($pageNewName)), 'fileName' => urlencode(escape_tags($pageNewName)).'.md'); + $page = array('rawName' => $pageNewName, 'htmlName' => escape_tags($pageNewName), 'urlName' => urlencode(escape_tags($pageNewName)), 'fileName' => urlencode(escape_tags($pageNewName)) . wiki_get_mimetype($w)); $page_path_new = $w['path'] . '/' . $page['fileName'] ; if (is_file($page_path_new)) { return array('message' => 'Page already exists.', 'success' => false); @@ -289,7 +292,7 @@ function wiki_get_page_content($arr) { if (!$w['path']) { return array('content' => null, 'message' => 'Error reading wiki', 'success' => false); } - $page_path = $w['path'].'/'.$pageUrlName.'.md'; + $page_path = $w['path'] . '/' . $pageUrlName . wiki_get_mimetype($w); if (is_readable($page_path) === true) { if(filesize($page_path) === 0) { $content = ''; @@ -311,7 +314,7 @@ function wiki_page_history($arr) { if (!$w['path']) { return array('history' => null, 'message' => 'Error reading wiki', 'success' => false); } - $page_path = $w['path'].'/'.$pageUrlName.'.md'; + $page_path = $w['path'] . '/' . $pageUrlName . wiki_get_mimetype($w); if (!is_readable($page_path) === true) { return array('history' => null, 'message' => 'Cannot read wiki page: ' . $page_path, 'success' => false); } @@ -336,12 +339,14 @@ function wiki_save_page($arr) { if (!$w['path']) { return array('message' => 'Error reading wiki', 'success' => false); } - $page_path = $w['path'].'/'.$pageUrlName.'.md'; + + $fileName = $pageUrlName . wiki_get_mimetype($w); + $page_path = $w['path'] . '/' . $fileName; if (is_writable($page_path) === true) { if(!file_put_contents($page_path, $content)) { return array('message' => 'Error writing to page file', 'success' => false); } - return array('message' => '', 'success' => true); + return array('message' => '', 'filename' => $filename, 'success' => true); } else { return array('message' => 'Page file not writable', 'success' => false); } @@ -354,7 +359,7 @@ function wiki_delete_page($arr) { if (!$w['path']) { return array('message' => 'Error reading wiki', 'success' => false); } - $page_path = $w['path'].'/'.$pageUrlName.'.md'; + $page_path = $w['path'] . '/' . $pageUrlName . wiki_get_mimetype($w); if (is_writable($page_path) === true) { if(!unlink($page_path)) { return array('message' => 'Error deleting page file', 'success' => false); @@ -376,7 +381,7 @@ function wiki_revert_page($arr) { if (!$w['path']) { return array('content' => $content, 'message' => 'Error reading wiki', 'success' => false); } - $page_path = $w['path'].'/'.$pageUrlName.'.md'; + $page_path = $w['path'] . '/' . $pageUrlName . wiki_get_mimetype($w); if (is_writable($page_path) === true) { $reponame = ((array_key_exists('title', $w['wiki'])) ? urlencode($w['wiki']['title']) : 'repo'); @@ -388,7 +393,7 @@ function wiki_revert_page($arr) { try { $git->setIdentity($observer['xchan_name'], $observer['xchan_addr']); foreach ($git->git->tree($commitHash) as $object) { - if ($object['type'] == 'blob' && $object['file'] === $pageUrlName.'.md' ) { + if ($object['type'] == 'blob' && $object['file'] === $pageUrlName . wiki_get_mimetype($w)) { $content = $git->git->cat->blob($object['hash']); } } @@ -413,7 +418,7 @@ function wiki_compare_page($arr) { if (!$w['path']) { return array('message' => 'Error reading wiki', 'success' => false); } - $page_path = $w['path'].'/'.$pageUrlName.'.md'; + $page_path = $w['path'] . '/' . $pageUrlName . wiki_get_mimetype($w); if (is_readable($page_path) === true) { $reponame = ((array_key_exists('title', $w['wiki'])) ? urlencode($w['wiki']['title']) : 'repo'); if($reponame === '') { @@ -423,12 +428,12 @@ function wiki_compare_page($arr) { $compareContent = $currentContent = ''; try { foreach ($git->git->tree($currentCommit) as $object) { - if ($object['type'] == 'blob' && $object['file'] === $pageUrlName.'.md' ) { + if ($object['type'] == 'blob' && $object['file'] === $pageUrlName . wiki_get_mimetype($w)) { $currentContent = $git->git->cat->blob($object['hash']); } } foreach ($git->git->tree($compareCommit) as $object) { - if ($object['type'] == 'blob' && $object['file'] === $pageUrlName.'.md' ) { + if ($object['type'] == 'blob' && $object['file'] === $pageUrlName . wiki_get_mimetype($w)) { $compareContent = $git->git->cat->blob($object['hash']); } } @@ -491,15 +496,6 @@ function wiki_git_commit($arr) { } } -function wiki_generate_page_filename($name) { - $file = urlencode(escape_tags($name)); - if( $file === '') { - return null; - } else { - return $file . '.md'; - } -} - function wiki_convert_links($s, $wikiURL) { if (strpos($s,'[[') !== false) { @@ -569,6 +565,13 @@ function wiki_bbcode($s) { return $s; } +function wiki_get_mimetype($arr) { + if($arr['mimeType'] == 'text/bbcode') + return '.bb'; + else + return '.md'; +} + // This function is derived from // http://stackoverflow.com/questions/32068537/generate-table-of-contents-from-markdown-in-php function wiki_toc($content) { -- cgit v1.2.3 From 6a786342f98bcf96b30eaa09a76bd5e2f228522d Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Tue, 29 Nov 2016 10:46:04 +0100 Subject: rename function --- include/wiki.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'include/wiki.php') diff --git a/include/wiki.php b/include/wiki.php index 8fbabcbef..ac35c8546 100644 --- a/include/wiki.php +++ b/include/wiki.php @@ -245,7 +245,7 @@ function wiki_create_page($name, $resource_id) { return array('page' => null, 'wiki' => null, 'message' => 'Wiki not found.', 'success' => false); } - $page = array('rawName' => $name, 'htmlName' => escape_tags($name), 'urlName' => urlencode(escape_tags($name)), 'fileName' => urlencode(escape_tags($name)) . wiki_get_mimetype($w)); + $page = array('rawName' => $name, 'htmlName' => escape_tags($name), 'urlName' => urlencode(escape_tags($name)), 'fileName' => urlencode(escape_tags($name)) . wiki_get_file_ext($w)); $page_path = $w['path'] . '/' . $page['fileName']; if (is_file($page_path)) { return array('page' => null, 'wiki' => null, 'message' => 'Page already exists.', 'success' => false); @@ -267,11 +267,11 @@ function wiki_rename_page($arr) { if (!$w['path']) { return array('message' => 'Wiki not found.', 'success' => false); } - $page_path_old = $w['path'] . '/' . $pageUrlName . wiki_get_mimetype($w); + $page_path_old = $w['path'] . '/' . $pageUrlName . wiki_get_file_ext($w); if (!is_readable($page_path_old) === true) { return array('message' => 'Cannot read wiki page: ' . $page_path_old, 'success' => false); } - $page = array('rawName' => $pageNewName, 'htmlName' => escape_tags($pageNewName), 'urlName' => urlencode(escape_tags($pageNewName)), 'fileName' => urlencode(escape_tags($pageNewName)) . wiki_get_mimetype($w)); + $page = array('rawName' => $pageNewName, 'htmlName' => escape_tags($pageNewName), 'urlName' => urlencode(escape_tags($pageNewName)), 'fileName' => urlencode(escape_tags($pageNewName)) . wiki_get_file_ext($w)); $page_path_new = $w['path'] . '/' . $page['fileName'] ; if (is_file($page_path_new)) { return array('message' => 'Page already exists.', 'success' => false); @@ -292,7 +292,7 @@ function wiki_get_page_content($arr) { if (!$w['path']) { return array('content' => null, 'message' => 'Error reading wiki', 'success' => false); } - $page_path = $w['path'] . '/' . $pageUrlName . wiki_get_mimetype($w); + $page_path = $w['path'] . '/' . $pageUrlName . wiki_get_file_ext($w); if (is_readable($page_path) === true) { if(filesize($page_path) === 0) { $content = ''; @@ -314,7 +314,7 @@ function wiki_page_history($arr) { if (!$w['path']) { return array('history' => null, 'message' => 'Error reading wiki', 'success' => false); } - $page_path = $w['path'] . '/' . $pageUrlName . wiki_get_mimetype($w); + $page_path = $w['path'] . '/' . $pageUrlName . wiki_get_file_ext($w); if (!is_readable($page_path) === true) { return array('history' => null, 'message' => 'Cannot read wiki page: ' . $page_path, 'success' => false); } @@ -340,7 +340,7 @@ function wiki_save_page($arr) { return array('message' => 'Error reading wiki', 'success' => false); } - $fileName = $pageUrlName . wiki_get_mimetype($w); + $fileName = $pageUrlName . wiki_get_file_ext($w); $page_path = $w['path'] . '/' . $fileName; if (is_writable($page_path) === true) { if(!file_put_contents($page_path, $content)) { @@ -359,7 +359,7 @@ function wiki_delete_page($arr) { if (!$w['path']) { return array('message' => 'Error reading wiki', 'success' => false); } - $page_path = $w['path'] . '/' . $pageUrlName . wiki_get_mimetype($w); + $page_path = $w['path'] . '/' . $pageUrlName . wiki_get_file_ext($w); if (is_writable($page_path) === true) { if(!unlink($page_path)) { return array('message' => 'Error deleting page file', 'success' => false); @@ -381,7 +381,7 @@ function wiki_revert_page($arr) { if (!$w['path']) { return array('content' => $content, 'message' => 'Error reading wiki', 'success' => false); } - $page_path = $w['path'] . '/' . $pageUrlName . wiki_get_mimetype($w); + $page_path = $w['path'] . '/' . $pageUrlName . wiki_get_file_ext($w); if (is_writable($page_path) === true) { $reponame = ((array_key_exists('title', $w['wiki'])) ? urlencode($w['wiki']['title']) : 'repo'); @@ -393,7 +393,7 @@ function wiki_revert_page($arr) { try { $git->setIdentity($observer['xchan_name'], $observer['xchan_addr']); foreach ($git->git->tree($commitHash) as $object) { - if ($object['type'] == 'blob' && $object['file'] === $pageUrlName . wiki_get_mimetype($w)) { + if ($object['type'] == 'blob' && $object['file'] === $pageUrlName . wiki_get_file_ext($w)) { $content = $git->git->cat->blob($object['hash']); } } @@ -418,7 +418,7 @@ function wiki_compare_page($arr) { if (!$w['path']) { return array('message' => 'Error reading wiki', 'success' => false); } - $page_path = $w['path'] . '/' . $pageUrlName . wiki_get_mimetype($w); + $page_path = $w['path'] . '/' . $pageUrlName . wiki_get_file_ext($w); if (is_readable($page_path) === true) { $reponame = ((array_key_exists('title', $w['wiki'])) ? urlencode($w['wiki']['title']) : 'repo'); if($reponame === '') { @@ -428,12 +428,12 @@ function wiki_compare_page($arr) { $compareContent = $currentContent = ''; try { foreach ($git->git->tree($currentCommit) as $object) { - if ($object['type'] == 'blob' && $object['file'] === $pageUrlName . wiki_get_mimetype($w)) { + 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_mimetype($w)) { + if ($object['type'] == 'blob' && $object['file'] === $pageUrlName . wiki_get_file_ext($w)) { $compareContent = $git->git->cat->blob($object['hash']); } } @@ -565,7 +565,7 @@ function wiki_bbcode($s) { return $s; } -function wiki_get_mimetype($arr) { +function wiki_get_file_ext($arr) { if($arr['mimeType'] == 'text/bbcode') return '.bb'; else -- cgit v1.2.3 From afffbb6487d8dc1806767ed2b2728ab56bf06669 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 30 Nov 2016 13:30:50 +0100 Subject: go live with wiki mimetypes - you can now choose if a wiki will contain markdown or bb-code markup --- include/wiki.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'include/wiki.php') diff --git a/include/wiki.php b/include/wiki.php index ac35c8546..dd5dbbe11 100644 --- a/include/wiki.php +++ b/include/wiki.php @@ -303,7 +303,7 @@ function wiki_get_page_content($arr) { } } // TODO: Check that the files are all text files - return array('content' => json_encode($content), 'message' => '', 'success' => true); + return array('content' => json_encode($content), 'mimeType' => $w['mimeType'], 'message' => '', 'success' => true); } } @@ -523,7 +523,6 @@ function wiki_convert_links($s, $wikiURL) { * @return string */ function wiki_generate_toc($s) { - if (strpos($s,'[toc]') !== false) { //$toc_md = wiki_toc($s); // Generate Markdown-formatted list prior to HTML render $toc_md = '
    '; // use the available jQuery plugin http://ndabas.github.io/toc/ -- cgit v1.2.3 From bb7680dc51723d3166bac005fd8f8510be8cfd01 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Sun, 4 Dec 2016 15:07:03 +0100 Subject: implement content type in wiki list --- include/wiki.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/wiki.php') diff --git a/include/wiki.php b/include/wiki.php index dd5dbbe11..542d617b9 100644 --- a/include/wiki.php +++ b/include/wiki.php @@ -19,7 +19,7 @@ function wiki_list($channel, $observer_hash) { $w['htmlName'] = get_iconfig($w, 'wiki', 'htmlName'); $w['urlName'] = get_iconfig($w, 'wiki', 'urlName'); $w['path'] = get_iconfig($w, 'wiki', 'path'); - $w['path'] = get_iconfig($w, 'wiki', 'mimeType'); + $w['mimeType'] = get_iconfig($w, 'wiki', 'mimeType'); } } // TODO: query db for wikis the observer can access. Return with two lists, for read and write access -- cgit v1.2.3 From 9e27559bdb2ba2177128deb014ecaef21f1eaaba Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 11 Dec 2016 14:39:06 -0800 Subject: clone sync missing for some item delete operations --- include/wiki.php | 56 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'include/wiki.php') diff --git a/include/wiki.php b/include/wiki.php index 542d617b9..30685a0bf 100644 --- a/include/wiki.php +++ b/include/wiki.php @@ -46,7 +46,7 @@ function wiki_page_list($resource_id) { $i = 1; foreach($files as $file) { // strip the file extension and unwrap URL encoding to leave HTML encoded name - $title = substr($file, 0, -3); + $title = substr($file, 0, strrpos($file,'.')); if(urldecode($title) !== 'Home') { $pages[] = [ 'resource_id' => $resource_id, @@ -147,7 +147,7 @@ function wiki_create_wiki($channel, $observer_hash, $wiki, $acl) { $item_id = $post['item_id']; if ($item_id) { - \Zotlabs\Daemon\Master::Summon(array('Notifier', 'activity', $item_id)); + \Zotlabs\Daemon\Master::Summon(array('Notifier', 'activity', $item_id)); return array('item' => $post['item'], 'success' => true); } else { return array('item' => null, 'success' => false); @@ -226,8 +226,8 @@ function wiki_get_permissions($resource_id, $owner_id, $observer_hash) { $r = q("SELECT * FROM item WHERE uid = %d and resource_type = '%s' AND resource_id = '%s' $sql_extra LIMIT 1", intval($owner_id), dbesc(WIKI_ITEM_RESOURCE_TYPE), - dbesc($resource_id) - ); + dbesc($resource_id) + ); if (!$r) { return array('read' => false, 'write' => false, 'success' => true); @@ -579,36 +579,36 @@ function wiki_toc($content) { // look for markdown TOC items preg_match_all( - '/^(?:=|-|#).*$/m', - $source, - $matches, - PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE + '/^(?:=|-|#).*$/m', + $source, + $matches, + PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE ); // preprocess: iterate matched lines to create an array of items // where each item is an array(level, text) $file_size = strlen($source); foreach ($matches[0] as $item) { - $found_mark = substr($item[0], 0, 1); - if ($found_mark == '#') { - // text is the found item - $item_text = $item[0]; - $item_level = strrpos($item_text, '#') + 1; - $item_text = substr($item_text, $item_level); - } else { - // text is the previous line (empty if
    ) - $item_offset = $item[1]; - $prev_line_offset = strrpos($source, "\n", -($file_size - $item_offset + 2)); - $item_text = - substr($source, $prev_line_offset, $item_offset - $prev_line_offset - 1); - $item_text = trim($item_text); - $item_level = $found_mark == '=' ? 1 : 2; - } - if (!trim($item_text) OR strpos($item_text, '|') !== FALSE) { - // item is an horizontal separator or a table header, don't mind - continue; - } - $raw_toc[] = ['level' => $item_level, 'text' => trim($item_text)]; + $found_mark = substr($item[0], 0, 1); + if ($found_mark == '#') { + // text is the found item + $item_text = $item[0]; + $item_level = strrpos($item_text, '#') + 1; + $item_text = substr($item_text, $item_level); + } else { + // text is the previous line (empty if
    ) + $item_offset = $item[1]; + $prev_line_offset = strrpos($source, "\n", -($file_size - $item_offset + 2)); + $item_text = + substr($source, $prev_line_offset, $item_offset - $prev_line_offset - 1); + $item_text = trim($item_text); + $item_level = $found_mark == '=' ? 1 : 2; + } + if (!trim($item_text) OR strpos($item_text, '|') !== FALSE) { + // item is an horizontal separator or a table header, don't mind + continue; + } + $raw_toc[] = ['level' => $item_level, 'text' => trim($item_text)]; } $o = ''; foreach($raw_toc as $t) { -- cgit v1.2.3 From 29bf6e5d3275925e57f9aa8d71910b7038d91191 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Tue, 13 Dec 2016 11:14:22 +0100 Subject: bring lockview to wikilist --- include/wiki.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include/wiki.php') diff --git a/include/wiki.php b/include/wiki.php index 30685a0bf..332d4efe0 100644 --- a/include/wiki.php +++ b/include/wiki.php @@ -14,12 +14,13 @@ function wiki_list($channel, $observer_hash) { intval($channel['channel_id']) ); if($wikis) { - foreach($wikis as &$w) { + foreach($wikis as &$w) { $w['rawName'] = get_iconfig($w, 'wiki', 'rawName'); $w['htmlName'] = get_iconfig($w, 'wiki', 'htmlName'); $w['urlName'] = get_iconfig($w, 'wiki', 'urlName'); $w['path'] = get_iconfig($w, 'wiki', 'path'); $w['mimeType'] = get_iconfig($w, 'wiki', 'mimeType'); + $w['lock'] = (($w['allow_cid'] || $w['allow_gid'] || $w['deny_cid'] || $w['deny_gid']) ? true : false); } } // TODO: query db for wikis the observer can access. Return with two lists, for read and write access -- cgit v1.2.3