diff -r 9d29f7e101d6 -r 8079b0288e8e includes/render.php --- a/includes/render.php Sun Aug 12 14:56:52 2007 -0400 +++ b/includes/render.php Tue Aug 14 15:13:40 2007 -0400 @@ -408,7 +408,7 @@ function sanitize_html($text) { $text = htmlspecialchars($text); - $allowed_tags = Array('b', 'i', 'u', 'pre', 'code', 'tt', 'br', 'p', 'nowiki', '!--([^.]+)--'); + $allowed_tags = Array('b', 'i', 'u', 'pre', 'code', 'tt', 'br', 'p', 'nowiki', '!--([\w\W]+)--'); foreach($allowed_tags as $t) { $text = preg_replace('#<'.$t.'>(.*?)</'.$t.'>#is', '<'.$t.'>\\1', $text); @@ -418,6 +418,52 @@ return $text; } + /** + * Parses internal links (wikilinks) in a block of text. + * @param string Text to process + * @return string + */ + + function parse_internal_links($text) + { + + // stage 1 - links with alternate text + preg_match_all('/\[\[([^\[\]<>\{\}\|]+)\|(.+?)\]\]/', $text, $matches); + foreach ( $matches[0] as $i => $match ) + { + list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]); + $pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id); + + $url = makeUrl($pid_clean, false, true); + $inner_text = $matches[2][$i]; + $quot = '"'; + $exists = ( isPage($pid_clean) ) ? '' : ' class="wikilink-nonexistent"'; + + $link = "{$inner_text}"; + + $text = str_replace($match, $link, $text); + } + + // stage 2 - links with no alternate text + preg_match_all('/\[\[([^\[\]<>\{\}\|]+)\]\]/', $text, $matches); + foreach ( $matches[0] as $i => $match ) + { + list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]); + $pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id); + + $url = makeUrl($matches[1][$i], false, true); + $inner_text = htmlspecialchars(get_page_title($pid_clean)); + $quot = '"'; + $exists = ( isPage($pid_clean) ) ? '' : ' class="wikilink-nonexistent"'; + + $link = "{$inner_text}"; + + $text = str_replace($match, $link, $text); + } + + return $text; + } + /* * * Replaces template inclusions with the templates * @param string $message The text to format