} // Now process the [\d+] links which are numeric references $oldn = $ntokens; $tmpline = tokenize($tmpline, '\\[\\s*\\d+\\s*\\]', $replacements, $ntokens); while ($oldn < $ntokens) { $num = (int) substr($replacements[$oldn], 1); if (!empty($embedded[$num])) { $replacements[$oldn] = $embedded[$num]; } $oldn++; } // match anything else between brackets $oldn = $ntokens; $tmpline = tokenize($tmpline, '\\[.+?\\]', $replacements, $ntokens); while ($oldn < $ntokens) { $link = ParseAndLink($replacements[$oldn]); $replacements[$oldn] = $link['link']; $oldn++; } ////////////////////////////////////////////////////////// // replace all URL's with tokens, so we don't confuse them // with Wiki words later. Wiki words in URL's break things. // URLs preceeded by a '!' are not linked $tmpline = tokenize($tmpline, "!?\\b({$AllowedProtocols}):[^\\s<>\\[\\]\"'()]*[^\\s<>\\[\\]\"'(),.?]", $replacements, $ntokens); while ($oldn < $ntokens) { if ($replacements[$oldn][0] == '!') { $replacements[$oldn] = substr($replacements[$oldn], 1); } else { $replacements[$oldn] = LinkURL($replacements[$oldn]); } $oldn++;
function ExtractWikiPageLinks($content) { global $WikiNameRegexp, $AllowedProtocols; $wikilinks = array(); $numlines = count($content); for ($l = 0; $l < $numlines; $l++) { // remove escaped '[' $line = str_replace('[[', ' ', $content[$l]); // bracket links (only type wiki-* is of interest) $numBracketLinks = preg_match_all("/\\[\\s*([^\\]|]+\\|)?\\s*(.+?)\\s*\\]/", $line, $brktlinks); for ($i = 0; $i < $numBracketLinks; $i++) { $link = ParseAndLink($brktlinks[0][$i]); if (preg_match("#^wiki#", $link['type'])) { $wikilinks[$brktlinks[2][$i]] = 1; } $brktlink = preg_quote($brktlinks[0][$i]); $line = preg_replace("|{$brktlink}|", '', $line); } // Remove URLs (think about "http:a.b.com/WikiWords"). $line = preg_replace("/!?\\b({$AllowedProtocols}):[^\\s<>\\[\\]\"'()]*[^\\s<>\\[\\]\"'(),.?]/", ' ', $line); // BumpyText old-style wiki links if (preg_match_all("/!?{$WikiNameRegexp}/", $line, $link)) { for ($i = 0; isset($link[0][$i]); $i++) { if ($link[0][$i][0] != '!') { $wikilinks[$link[0][$i]] = 1; } } } } return $wikilinks; }