From 0df3978cc5891f1383dd0dbcdc1c6b4c0010e645 Mon Sep 17 00:00:00 2001 From: Andrew Manning Date: Sat, 25 Jun 2016 14:29:52 -0500 Subject: A page name wrapped in double brackets is converted into a link to another page in the current wiki --- include/wiki.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'include') 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 = ''.$pages[$idx].''; + $s = preg_replace("/\[\[(.*?)\]\]/", $replace, $s, 1); + $idx++; + } + } + return $s; } \ No newline at end of file -- cgit v1.2.3