5 * Parses for interwiki links.
11 * @author Paul M. Jones <pmjones@php.net>
15 * @version $Id: Interwiki.php,v 1.4 2005/02/23 17:38:29 pmjones Exp $
21 * Parses for interwiki links.
23 * This class implements a Text_Wiki_Parse to find source text marked as
24 * an Interwiki link. See the regex for a detailed explanation of the
25 * text matching procedure; e.g., "InterWikiName:PageName".
31 * @author Paul M. Jones <pmjones@php.net>
35 class Text_Wiki_Parse_Interwiki
extends Text_Wiki_Parse
{
37 // double-colons wont trip up now
38 var $regex = '([A-Za-z0-9_]+):((?!:)[A-Za-z0-9_\/=&~#.:;-]+)';
43 * Parser. We override the standard parser so we can
44 * find both described interwiki links and standalone links.
54 // described interwiki links
55 $tmp_regex = '/\[' . $this->regex
. ' (.+?)\]/';
56 $this->wiki
->source
= preg_replace_callback(
58 array(&$this, 'processDescr'),
62 // standalone interwiki links
63 $tmp_regex = '/' . $this->regex
. '/';
64 $this->wiki
->source
= preg_replace_callback(
66 array(&$this, 'process'),
75 * Generates a replacement for the matched standalone interwiki text.
78 * 'site' => The key name for the Text_Wiki interwiki array map,
79 * usually the name of the interwiki site.
81 * 'page' => The page on the target interwiki to link to.
83 * 'text' => The text to display as the link.
87 * @param array &$matches The array of matches from parse().
89 * @return A delimited token to be used as a placeholder in
90 * the source text, plus any text priot to the match.
94 function process(&$matches)
97 'site' => $matches[1],
98 'page' => $matches[2],
102 return $this->wiki
->addToken($this->rule
, $options);
108 * Generates a replacement for described interwiki links. Token
111 * 'site' => The key name for the Text_Wiki interwiki array map,
112 * usually the name of the interwiki site.
114 * 'page' => The page on the target interwiki to link to.
116 * 'text' => The text to display as the link.
120 * @param array &$matches The array of matches from parse().
122 * @return A delimited token to be used as a placeholder in
123 * the source text, plus any text priot to the match.
127 function processDescr(&$matches)
130 'site' => $matches[1],
131 'page' => $matches[2],
132 'text' => $matches[3]
135 return $this->wiki
->addToken($this->rule
, $options);