import of Diogenes 0.9.18
[diogenes.git] / include / Text / Wiki / Parse / Default / Interwiki.php
1 <?php
2
3 /**
4 *
5 * Parses for interwiki links.
6 *
7 * @category Text
8 *
9 * @package Text_Wiki
10 *
11 * @author Paul M. Jones <pmjones@php.net>
12 *
13 * @license LGPL
14 *
15 * @version $Id: Interwiki.php,v 1.4 2005/02/23 17:38:29 pmjones Exp $
16 *
17 */
18
19 /**
20 *
21 * Parses for interwiki links.
22 *
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".
26 *
27 * @category Text
28 *
29 * @package Text_Wiki
30 *
31 * @author Paul M. Jones <pmjones@php.net>
32 *
33 */
34
35 class Text_Wiki_Parse_Interwiki extends Text_Wiki_Parse {
36
37 // double-colons wont trip up now
38 var $regex = '([A-Za-z0-9_]+):((?!:)[A-Za-z0-9_\/=&~#.:;-]+)';
39
40
41 /**
42 *
43 * Parser. We override the standard parser so we can
44 * find both described interwiki links and standalone links.
45 *
46 * @access public
47 *
48 * @return void
49 *
50 */
51
52 function parse()
53 {
54 // described interwiki links
55 $tmp_regex = '/\[' . $this->regex . ' (.+?)\]/';
56 $this->wiki->source = preg_replace_callback(
57 $tmp_regex,
58 array(&$this, 'processDescr'),
59 $this->wiki->source
60 );
61
62 // standalone interwiki links
63 $tmp_regex = '/' . $this->regex . '/';
64 $this->wiki->source = preg_replace_callback(
65 $tmp_regex,
66 array(&$this, 'process'),
67 $this->wiki->source
68 );
69
70 }
71
72
73 /**
74 *
75 * Generates a replacement for the matched standalone interwiki text.
76 * Token options are:
77 *
78 * 'site' => The key name for the Text_Wiki interwiki array map,
79 * usually the name of the interwiki site.
80 *
81 * 'page' => The page on the target interwiki to link to.
82 *
83 * 'text' => The text to display as the link.
84 *
85 * @access public
86 *
87 * @param array &$matches The array of matches from parse().
88 *
89 * @return A delimited token to be used as a placeholder in
90 * the source text, plus any text priot to the match.
91 *
92 */
93
94 function process(&$matches)
95 {
96 $options = array(
97 'site' => $matches[1],
98 'page' => $matches[2],
99 'text' => $matches[0]
100 );
101
102 return $this->wiki->addToken($this->rule, $options);
103 }
104
105
106 /**
107 *
108 * Generates a replacement for described interwiki links. Token
109 * options are:
110 *
111 * 'site' => The key name for the Text_Wiki interwiki array map,
112 * usually the name of the interwiki site.
113 *
114 * 'page' => The page on the target interwiki to link to.
115 *
116 * 'text' => The text to display as the link.
117 *
118 * @access public
119 *
120 * @param array &$matches The array of matches from parse().
121 *
122 * @return A delimited token to be used as a placeholder in
123 * the source text, plus any text priot to the match.
124 *
125 */
126
127 function processDescr(&$matches)
128 {
129 $options = array(
130 'site' => $matches[1],
131 'page' => $matches[2],
132 'text' => $matches[3]
133 );
134
135 return $this->wiki->addToken($this->rule, $options);
136 }
137 }
138 ?>