11<?php
22
33/**
4- *
4+ *
55* Parses for interwiki links.
6- *
6+ *
77* @category Text
8- *
8+ *
99* @package Text_Wiki
10- *
10+ *
1111* @author Paul M. Jones <pmjones@php.net>
12- *
12+ *
1313* @license LGPL
14- *
14+ *
1515* @version $Id$
16- *
16+ *
1717*/
1818
1919/**
20- *
20+ *
2121* Parses for interwiki links.
22- *
22+ *
2323* This class implements a Text_Wiki_Parse_Default to find source text marked as
2424* an Interwiki link. See the regex for a detailed explanation of the
2525* text matching procedure; e.g., "InterWikiName:PageName".
2626*
2727* @category Text
28- *
28+ *
2929* @package Text_Wiki
30- *
30+ *
3131* @author Paul M. Jones <pmjones@php.net>
32- *
32+ *
3333*/
3434
3535class Text_Wiki_Parse_Default_Interwiki extends Text_Wiki_Parse {
36-
36+
3737 // double-colons wont trip up now
3838 var $ regex = '([A-Za-z0-9_]+):((?!:)[A-Za-z0-9_\/=&~#.:;-]+) ' ;
39-
40-
39+
40+
4141 /**
42- *
42+ *
4343 * Parser. We override the standard parser so we can
4444 * find both described interwiki links and standalone links.
45- *
45+ *
4646 * @access public
47- *
47+ *
4848 * @return void
49- *
49+ *
5050 */
51-
51+
5252 function parse ()
5353 {
5454 // described interwiki links
5555 $ tmp_regex = '/\[ ' . $ this ->regex . ' (.+?)\]/ ' ;
5656 $ this ->wiki ->source = preg_replace_callback (
5757 $ tmp_regex ,
58- array (&$ this , 'processDescr ' ),
58+ function ($ matches ) {
59+ return $ this ->processDescr ($ matches );
60+ },
5961 $ this ->wiki ->source
6062 );
61-
63+
6264 // standalone interwiki links
6365 $ tmp_regex = '/ ' . $ this ->regex . '/ ' ;
6466 $ this ->wiki ->source = preg_replace_callback (
6567 $ tmp_regex ,
66- array (&$ this , 'process ' ),
68+ function ($ matches ) {
69+ return $ this ->process ($ matches );
70+ },
6771 $ this ->wiki ->source
6872 );
69-
73+
7074 }
71-
72-
75+
76+
7377 /**
74- *
78+ *
7579 * Generates a replacement for the matched standalone interwiki text.
7680 * Token options are:
77- *
81+ *
7882 * 'site' => The key name for the Text_Wiki interwiki array map,
7983 * usually the name of the interwiki site.
80- *
84+ *
8185 * 'page' => The page on the target interwiki to link to.
82- *
86+ *
8387 * 'text' => The text to display as the link.
84- *
88+ *
8589 * @access public
8690 *
8791 * @param array &$matches The array of matches from parse().
@@ -90,31 +94,31 @@ function parse()
9094 * the source text, plus any text priot to the match.
9195 *
9296 */
93-
97+
9498 function process (&$ matches )
9599 {
96100 $ options = array (
97101 'site ' => $ matches [1 ],
98102 'page ' => $ matches [2 ],
99103 'text ' => $ matches [0 ]
100104 );
101-
105+
102106 return $ this ->wiki ->addToken ($ this ->rule , $ options );
103107 }
104-
105-
108+
109+
106110 /**
107- *
111+ *
108112 * Generates a replacement for described interwiki links. Token
109113 * options are:
110- *
114+ *
111115 * 'site' => The key name for the Text_Wiki interwiki array map,
112116 * usually the name of the interwiki site.
113- *
117+ *
114118 * 'page' => The page on the target interwiki to link to.
115- *
119+ *
116120 * 'text' => The text to display as the link.
117- *
121+ *
118122 * @access public
119123 *
120124 * @param array &$matches The array of matches from parse().
@@ -123,15 +127,15 @@ function process(&$matches)
123127 * the source text, plus any text priot to the match.
124128 *
125129 */
126-
130+
127131 function processDescr (&$ matches )
128132 {
129133 $ options = array (
130134 'site ' => $ matches [1 ],
131135 'page ' => $ matches [2 ],
132136 'text ' => $ matches [3 ]
133137 );
134-
138+
135139 return $ this ->wiki ->addToken ($ this ->rule , $ options );
136140 }
137141}
0 commit comments