more work on wiki mimetypes
This commit is contained in:
parent
91e97468a0
commit
d184b3fa86
@ -313,7 +313,6 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
if (local_channel() !== intval($owner['channel_id'])) {
|
if (local_channel() !== intval($owner['channel_id'])) {
|
||||||
goaway('/' . argv(0) . '/' . $nick . '/');
|
goaway('/' . argv(0) . '/' . $nick . '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
$wiki = array();
|
$wiki = array();
|
||||||
// Generate new wiki info from input name
|
// Generate new wiki info from input name
|
||||||
$wiki['postVisible'] = ((intval($_POST['postVisible']) === 0) ? 0 : 1);
|
$wiki['postVisible'] = ((intval($_POST['postVisible']) === 0) ? 0 : 1);
|
||||||
@ -321,10 +320,12 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
$wiki['htmlName'] = escape_tags($_POST['wikiName']);
|
$wiki['htmlName'] = escape_tags($_POST['wikiName']);
|
||||||
$wiki['urlName'] = urlencode($_POST['wikiName']);
|
$wiki['urlName'] = urlencode($_POST['wikiName']);
|
||||||
$wiki['mimeType'] = $_POST['mimeType'];
|
$wiki['mimeType'] = $_POST['mimeType'];
|
||||||
|
|
||||||
if($wiki['urlName'] === '') {
|
if($wiki['urlName'] === '') {
|
||||||
notice( t('Error creating wiki. Invalid name.') . EOL);
|
notice( t('Error creating wiki. Invalid name.') . EOL);
|
||||||
goaway('/wiki');
|
goaway('/wiki');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get ACL for permissions
|
// Get ACL for permissions
|
||||||
$acl = new \Zotlabs\Access\AccessList($owner);
|
$acl = new \Zotlabs\Access\AccessList($owner);
|
||||||
$acl->set_from_array($_POST);
|
$acl->set_from_array($_POST);
|
||||||
@ -386,7 +387,7 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
'commit_msg' => t('New page created'),
|
'commit_msg' => t('New page created'),
|
||||||
'resource_id' => $resource_id,
|
'resource_id' => $resource_id,
|
||||||
'observer' => $ob,
|
'observer' => $ob,
|
||||||
'files' => array($page['page']['urlName'].'.md')
|
'files' => array($page['page']['fileName'])
|
||||||
));
|
));
|
||||||
if($commit['success']) {
|
if($commit['success']) {
|
||||||
json_return_and_die(array('url' => '/'.argv(0).'/'.argv(1).'/'.$page['wiki']['urlName'].'/'.$page['page']['urlName'], 'success' => true));
|
json_return_and_die(array('url' => '/'.argv(0).'/'.argv(1).'/'.$page['wiki']['urlName'].'/'.$page['page']['urlName'], 'success' => true));
|
||||||
@ -442,7 +443,7 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
'commit_msg' => $commitMsg,
|
'commit_msg' => $commitMsg,
|
||||||
'resource_id' => $resource_id,
|
'resource_id' => $resource_id,
|
||||||
'observer' => $ob,
|
'observer' => $ob,
|
||||||
'files' => array($pageUrlName.'.md')
|
'files' => array($saved['fileName'])
|
||||||
));
|
));
|
||||||
if($commit['success']) {
|
if($commit['success']) {
|
||||||
json_return_and_die(array('message' => 'Wiki git repo commit made', 'success' => true));
|
json_return_and_die(array('message' => 'Wiki git repo commit made', 'success' => true));
|
||||||
@ -581,7 +582,7 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
'commit_msg' => 'Renamed ' . urldecode($pageUrlName) . ' to ' . $renamed['page']['htmlName'],
|
'commit_msg' => 'Renamed ' . urldecode($pageUrlName) . ' to ' . $renamed['page']['htmlName'],
|
||||||
'resource_id' => $resource_id,
|
'resource_id' => $resource_id,
|
||||||
'observer' => $ob,
|
'observer' => $ob,
|
||||||
'files' => array($pageUrlName . '.md', $renamed['page']['fileName']),
|
'files' => array($pageUrlName . substr($renamed['page']['fileName'], -3), $renamed['page']['fileName']),
|
||||||
'all' => true
|
'all' => true
|
||||||
));
|
));
|
||||||
if($commit['success']) {
|
if($commit['success']) {
|
||||||
|
@ -19,6 +19,7 @@ function wiki_list($channel, $observer_hash) {
|
|||||||
$w['htmlName'] = get_iconfig($w, 'wiki', 'htmlName');
|
$w['htmlName'] = get_iconfig($w, 'wiki', 'htmlName');
|
||||||
$w['urlName'] = get_iconfig($w, 'wiki', 'urlName');
|
$w['urlName'] = get_iconfig($w, 'wiki', 'urlName');
|
||||||
$w['path'] = get_iconfig($w, 'wiki', 'path');
|
$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
|
// 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
|
// TODO: Check that the files are all text files
|
||||||
$i = 1;
|
$i = 1;
|
||||||
foreach($files as $file) {
|
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);
|
$title = substr($file, 0, -3);
|
||||||
if(urldecode($title) !== 'Home') {
|
if(urldecode($title) !== 'Home') {
|
||||||
$pages[] = [
|
$pages[] = [
|
||||||
@ -139,7 +140,7 @@ function wiki_create_wiki($channel, $observer_hash, $wiki, $acl) {
|
|||||||
if (!set_iconfig($arr, 'wiki', 'urlName', $wiki['urlName'], true)) {
|
if (!set_iconfig($arr, 'wiki', 'urlName', $wiki['urlName'], true)) {
|
||||||
return array('item' => null, 'success' => false);
|
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);
|
return array('item' => null, 'success' => false);
|
||||||
}
|
}
|
||||||
$post = item_store($arr);
|
$post = item_store($arr);
|
||||||
@ -183,6 +184,7 @@ function wiki_get_wiki($resource_id) {
|
|||||||
$htmlName = get_iconfig($w, 'wiki', 'htmlName');
|
$htmlName = get_iconfig($w, 'wiki', 'htmlName');
|
||||||
$urlName = get_iconfig($w, 'wiki', 'urlName');
|
$urlName = get_iconfig($w, 'wiki', 'urlName');
|
||||||
$mimeType = get_iconfig($w, 'wiki', 'mimeType');
|
$mimeType = get_iconfig($w, 'wiki', 'mimeType');
|
||||||
|
|
||||||
$path = get_iconfig($w, 'wiki', 'path');
|
$path = get_iconfig($w, 'wiki', 'path');
|
||||||
if (!realpath(__DIR__ . '/../' . $path)) {
|
if (!realpath(__DIR__ . '/../' . $path)) {
|
||||||
return array('wiki' => null, 'path' => null);
|
return array('wiki' => null, 'path' => null);
|
||||||
@ -242,7 +244,8 @@ function wiki_create_page($name, $resource_id) {
|
|||||||
if (!$w['path']) {
|
if (!$w['path']) {
|
||||||
return array('page' => null, 'wiki' => null, 'message' => 'Wiki not found.', 'success' => false);
|
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'];
|
$page_path = $w['path'] . '/' . $page['fileName'];
|
||||||
if (is_file($page_path)) {
|
if (is_file($page_path)) {
|
||||||
return array('page' => null, 'wiki' => null, 'message' => 'Page already exists.', 'success' => false);
|
return array('page' => null, 'wiki' => null, 'message' => 'Page already exists.', 'success' => false);
|
||||||
@ -264,11 +267,11 @@ function wiki_rename_page($arr) {
|
|||||||
if (!$w['path']) {
|
if (!$w['path']) {
|
||||||
return array('message' => 'Wiki not found.', 'success' => false);
|
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) {
|
if (!is_readable($page_path_old) === true) {
|
||||||
return array('message' => 'Cannot read wiki page: ' . $page_path_old, 'success' => false);
|
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'] ;
|
$page_path_new = $w['path'] . '/' . $page['fileName'] ;
|
||||||
if (is_file($page_path_new)) {
|
if (is_file($page_path_new)) {
|
||||||
return array('message' => 'Page already exists.', 'success' => false);
|
return array('message' => 'Page already exists.', 'success' => false);
|
||||||
@ -289,7 +292,7 @@ function wiki_get_page_content($arr) {
|
|||||||
if (!$w['path']) {
|
if (!$w['path']) {
|
||||||
return array('content' => null, 'message' => 'Error reading wiki', 'success' => false);
|
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 (is_readable($page_path) === true) {
|
||||||
if(filesize($page_path) === 0) {
|
if(filesize($page_path) === 0) {
|
||||||
$content = '';
|
$content = '';
|
||||||
@ -311,7 +314,7 @@ function wiki_page_history($arr) {
|
|||||||
if (!$w['path']) {
|
if (!$w['path']) {
|
||||||
return array('history' => null, 'message' => 'Error reading wiki', 'success' => false);
|
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) {
|
if (!is_readable($page_path) === true) {
|
||||||
return array('history' => null, 'message' => 'Cannot read wiki page: ' . $page_path, 'success' => false);
|
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']) {
|
if (!$w['path']) {
|
||||||
return array('message' => 'Error reading wiki', 'success' => false);
|
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 (is_writable($page_path) === true) {
|
||||||
if(!file_put_contents($page_path, $content)) {
|
if(!file_put_contents($page_path, $content)) {
|
||||||
return array('message' => 'Error writing to page file', 'success' => false);
|
return array('message' => 'Error writing to page file', 'success' => false);
|
||||||
}
|
}
|
||||||
return array('message' => '', 'success' => true);
|
return array('message' => '', 'filename' => $filename, 'success' => true);
|
||||||
} else {
|
} else {
|
||||||
return array('message' => 'Page file not writable', 'success' => false);
|
return array('message' => 'Page file not writable', 'success' => false);
|
||||||
}
|
}
|
||||||
@ -354,7 +359,7 @@ function wiki_delete_page($arr) {
|
|||||||
if (!$w['path']) {
|
if (!$w['path']) {
|
||||||
return array('message' => 'Error reading wiki', 'success' => false);
|
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 (is_writable($page_path) === true) {
|
||||||
if(!unlink($page_path)) {
|
if(!unlink($page_path)) {
|
||||||
return array('message' => 'Error deleting page file', 'success' => false);
|
return array('message' => 'Error deleting page file', 'success' => false);
|
||||||
@ -376,7 +381,7 @@ function wiki_revert_page($arr) {
|
|||||||
if (!$w['path']) {
|
if (!$w['path']) {
|
||||||
return array('content' => $content, 'message' => 'Error reading wiki', 'success' => false);
|
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) {
|
if (is_writable($page_path) === true) {
|
||||||
|
|
||||||
$reponame = ((array_key_exists('title', $w['wiki'])) ? urlencode($w['wiki']['title']) : 'repo');
|
$reponame = ((array_key_exists('title', $w['wiki'])) ? urlencode($w['wiki']['title']) : 'repo');
|
||||||
@ -388,7 +393,7 @@ function wiki_revert_page($arr) {
|
|||||||
try {
|
try {
|
||||||
$git->setIdentity($observer['xchan_name'], $observer['xchan_addr']);
|
$git->setIdentity($observer['xchan_name'], $observer['xchan_addr']);
|
||||||
foreach ($git->git->tree($commitHash) as $object) {
|
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']);
|
$content = $git->git->cat->blob($object['hash']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -413,7 +418,7 @@ function wiki_compare_page($arr) {
|
|||||||
if (!$w['path']) {
|
if (!$w['path']) {
|
||||||
return array('message' => 'Error reading wiki', 'success' => false);
|
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) {
|
if (is_readable($page_path) === true) {
|
||||||
$reponame = ((array_key_exists('title', $w['wiki'])) ? urlencode($w['wiki']['title']) : 'repo');
|
$reponame = ((array_key_exists('title', $w['wiki'])) ? urlencode($w['wiki']['title']) : 'repo');
|
||||||
if($reponame === '') {
|
if($reponame === '') {
|
||||||
@ -423,12 +428,12 @@ function wiki_compare_page($arr) {
|
|||||||
$compareContent = $currentContent = '';
|
$compareContent = $currentContent = '';
|
||||||
try {
|
try {
|
||||||
foreach ($git->git->tree($currentCommit) as $object) {
|
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']);
|
$currentContent = $git->git->cat->blob($object['hash']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ($git->git->tree($compareCommit) as $object) {
|
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']);
|
$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) {
|
function wiki_convert_links($s, $wikiURL) {
|
||||||
|
|
||||||
if (strpos($s,'[[') !== false) {
|
if (strpos($s,'[[') !== false) {
|
||||||
@ -569,6 +565,13 @@ function wiki_bbcode($s) {
|
|||||||
return $s;
|
return $s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function wiki_get_mimetype($arr) {
|
||||||
|
if($arr['mimeType'] == 'text/bbcode')
|
||||||
|
return '.bb';
|
||||||
|
else
|
||||||
|
return '.md';
|
||||||
|
}
|
||||||
|
|
||||||
// This function is derived from
|
// This function is derived from
|
||||||
// http://stackoverflow.com/questions/32068537/generate-table-of-contents-from-markdown-in-php
|
// http://stackoverflow.com/questions/32068537/generate-table-of-contents-from-markdown-in-php
|
||||||
function wiki_toc($content) {
|
function wiki_toc($content) {
|
||||||
|
Reference in New Issue
Block a user