Subversion Repositories Applications.papyrus

Rev

Rev 248 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
248 jpm 1
<?php
2
// $Id: Interwiki.php,v 1.1 2005-01-20 19:43:20 jpm Exp $
3
 
4
 
5
/**
6
*
7
* This class implements a Text_Wiki_Parse to find source text marked as
8
* an Interwiki link.  See the regex for a detailed explanation of the
9
* text matching procedure; e.g., "InterWikiName:PageName".
10
*
11
* @author Paul M. Jones <pmjones@ciaweb.net>
12
*
13
* @package Text_Wiki
14
*
15
*/
16
 
17
class Text_Wiki_Parse_Interwiki extends Text_Wiki_Parse {
18
 
19
 
20
    var $regex = '([A-Za-z0-9_]+):([\/=&~#A-Za-z0-9_]+)';
21
 
22
 
23
    /**
24
    *
25
    * Parser.  We override the standard parser so we can
26
    * find both described interwiki links and standalone links.
27
    *
28
    * @access public
29
    *
30
    * @return void
31
    *
32
    */
33
 
34
    function parse()
35
    {
36
        // described interwiki links
37
        $tmp_regex = '/\[' . $this->regex . ' (.+?)\]/';
38
        $this->wiki->source = preg_replace_callback(
39
            $tmp_regex,
40
            array(&$this, 'processDescr'),
41
            $this->wiki->source
42
        );
43
 
44
        // standalone interwiki links
45
        $tmp_regex = '/' . $this->regex . '/';
46
        $this->wiki->source = preg_replace_callback(
47
            $tmp_regex,
48
            array(&$this, 'process'),
49
            $this->wiki->source
50
        );
51
 
52
    }
53
 
54
 
55
    /**
56
    *
57
    * Generates a replacement for the matched standalone interwiki text.
58
    * Token options are:
59
    *
60
    * 'site' => The key name for the Text_Wiki interwiki array map,
61
    * usually the name of the interwiki site.
62
    *
63
    * 'page' => The page on the target interwiki to link to.
64
    *
65
    * 'text' => The text to display as the link.
66
    *
67
    * @access public
68
    *
69
    * @param array &$matches The array of matches from parse().
70
    *
71
    * @return A delimited token to be used as a placeholder in
72
    * the source text, plus any text priot to the match.
73
    *
74
    */
75
 
76
    function process(&$matches)
77
    {
78
        $options = array(
79
            'site' => $matches[1],
80
            'page' => $matches[2],
81
            'text' => $matches[0]
82
        );
83
 
84
        return $this->wiki->addToken($this->rule, $options);
85
    }
86
 
87
 
88
    /**
89
    *
90
    * Generates a replacement for described interwiki links. Token
91
    * options are:
92
    *
93
    * 'site' => The key name for the Text_Wiki interwiki array map,
94
    * usually the name of the interwiki site.
95
    *
96
    * 'page' => The page on the target interwiki to link to.
97
    *
98
    * 'text' => The text to display as the link.
99
    *
100
    * @access public
101
    *
102
    * @param array &$matches The array of matches from parse().
103
    *
104
    * @return A delimited token to be used as a placeholder in
105
    * the source text, plus any text priot to the match.
106
    *
107
    */
108
 
109
    function processDescr(&$matches)
110
    {
111
        $options = array(
112
            'site' => $matches[1],
113
            'page' => $matches[2],
114
            'text' => $matches[3]
115
        );
116
 
117
        return $this->wiki->addToken($this->rule, $options);
118
    }
119
}
120
?>