A page name wrapped in double brackets is converted into a link to another page in the current wiki

This commit is contained in:
Andrew Manning
2016-06-25 14:29:52 -05:00
parent 241b257556
commit 0df3978cc5
3 changed files with 32 additions and 5 deletions

View File

@@ -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;
}