diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/wiki.php | 20 |
1 files changed, 20 insertions, 0 deletions
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 |