A page name wrapped in double brackets is converted into a link to another page in the current wiki
This commit is contained in:
parent
241b257556
commit
0df3978cc5
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
@ -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 {
|
||||
|
Reference in New Issue
Block a user