aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Manning <tamanning@zoho.com>2016-06-25 14:29:52 -0500
committerAndrew Manning <tamanning@zoho.com>2016-06-25 14:29:52 -0500
commit0df3978cc5891f1383dd0dbcdc1c6b4c0010e645 (patch)
tree26549c9d00b9af36faa5c452cbe0ac95379451e9
parent241b257556826e172707689b89e6f07687f8f556 (diff)
downloadvolse-hubzilla-0df3978cc5891f1383dd0dbcdc1c6b4c0010e645.tar.gz
volse-hubzilla-0df3978cc5891f1383dd0dbcdc1c6b4c0010e645.tar.bz2
volse-hubzilla-0df3978cc5891f1383dd0dbcdc1c6b4c0010e645.zip
A page name wrapped in double brackets is converted into a link to another page in the current wiki
-rw-r--r--Zotlabs/Module/Wiki.php15
-rw-r--r--include/wiki.php20
-rw-r--r--view/tpl/wiki.tpl2
3 files changed, 32 insertions, 5 deletions
diff --git a/Zotlabs/Module/Wiki.php b/Zotlabs/Module/Wiki.php
index 1c3add38f..de5863d2e 100644
--- a/Zotlabs/Module/Wiki.php
+++ b/Zotlabs/Module/Wiki.php
@@ -74,7 +74,9 @@ class Wiki extends \Zotlabs\Web\Controller {
// Configure page template
$wikiheaderName = t('Wiki');
$wikiheaderPage = t('Sandbox');
- $content = '"# Wiki Sandbox\n\nContent you **edit** and **preview** here *will not be saved*."';
+ require_once('library/markdown.php');
+ $content = t('"# Wiki Sandbox\n\nContent you **edit** and **preview** here *will not be saved*."');
+ $renderedContent = Markdown(json_decode($content));
$hide_editor = false;
$showPageControls = false;
$showNewWikiButton = $wiki_owner;
@@ -122,6 +124,9 @@ class Wiki extends \Zotlabs\Web\Controller {
goaway('/'.argv(0).'/'.argv(1).'/'.$wikiUrlName);
}
$content = ($p['content'] !== '' ? $p['content'] : '"# New page\n"');
+ // Render the Markdown-formatted page content in HTML
+ require_once('library/markdown.php');
+ $renderedContent = wiki_convert_links(Markdown(json_decode($content)),argv(0).'/'.argv(1).'/'.$wikiUrlName);
$hide_editor = false;
$showPageControls = $wiki_editor;
$showNewWikiButton = $wiki_owner;
@@ -133,8 +138,6 @@ class Wiki extends \Zotlabs\Web\Controller {
default: // Strip the extraneous URL components
goaway('/'.argv(0).'/'.argv(1).'/'.$wikiUrlName.'/'.$pageUrlName);
}
- // Render the Markdown-formatted page content in HTML
- require_once('library/markdown.php');
$wikiModalID = random_string(3);
$wikiModal = replace_macros(
@@ -162,7 +165,7 @@ class Wiki extends \Zotlabs\Web\Controller {
'$acl' => $x['acl'],
'$bang' => $x['bang'],
'$content' => $content,
- '$renderedContent' => Markdown(json_decode($content)),
+ '$renderedContent' => $renderedContent,
'$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:'), '', ''),
@@ -193,8 +196,12 @@ class Wiki extends \Zotlabs\Web\Controller {
// Render mardown-formatted text in HTML for preview
if((argc() > 2) && (argv(2) === 'preview')) {
$content = $_POST['content'];
+ $resource_id = $_POST['resource_id'];
require_once('library/markdown.php');
$html = purify_html(Markdown($content));
+ $w = wiki_get_wiki($resource_id);
+ $wikiURL = argv(0).'/'.argv(1).'/'.$w['urlName'];
+ $html = wiki_convert_links($html,$wikiURL);
json_return_and_die(array('html' => $html, 'success' => true));
}
diff --git a/include/wiki.php b/include/wiki.php
index fdbc704dc..63cf70f3c 100644
--- a/include/wiki.php
+++ b/include/wiki.php
@@ -473,4 +473,24 @@ function wiki_generate_page_filename($name) {
} else {
return $file . '.md';
}
+}
+
+function wiki_convert_links($s, $wikiURL) {
+
+ if (strpos($s,'[[') !== false) {
+ preg_match_all("/\[\[(.*?)\]\]/", $s, $match);
+ $pages = $pageURLs = array();
+ foreach ($match[1] as $m) {
+ // TODO: Why do we need to double urlencode for this to work?
+ $pageURLs[] = urlencode(urlencode(escape_tags($m)));
+ $pages[] = $m;
+ }
+ $idx = 0;
+ while(strpos($s,'[[') !== false) {
+ $replace = '<a href="'.$wikiURL.'/'.$pageURLs[$idx].'">'.$pages[$idx].'</a>';
+ $s = preg_replace("/\[\[(.*?)\]\]/", $replace, $s, 1);
+ $idx++;
+ }
+ }
+ return $s;
} \ No newline at end of file
diff --git a/view/tpl/wiki.tpl b/view/tpl/wiki.tpl
index d0744009d..1d8570828 100644
--- a/view/tpl/wiki.tpl
+++ b/view/tpl/wiki.tpl
@@ -200,7 +200,7 @@
editor.getSession().setValue(window.wiki_page_content);
$('#wiki-get-preview').click(function (ev) {
- $.post("wiki/{{$channel}}/preview", {content: editor.getValue()}, function (data) {
+ $.post("wiki/{{$channel}}/preview", {content: editor.getValue(), resource_id: window.wiki_resource_id}, function (data) {
if (data.success) {
$('#wiki-preview').html(data.html);
} else {