Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
170 jpm 1
<?php
2
// $Id: Interwiki.php,v 1.1 2004-11-24 18:34:35 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
    * Parser.  We override the standard parser so we can
25
    * find both described interwiki links and standalone links.
26
    *
27
    * @access public
28
    *
29
    * @return void
30
    *
31
    */
32
 
33
    function parse()
34
    {
35
        // described interwiki links
36
        $tmp_regex = '/\[\[' . $this->regex . ' (.+?)\]\]/';
37
        $this->wiki->source = preg_replace_callback(
38
            $tmp_regex,
39
            array(&$this, 'processDescr'),
40
            $this->wiki->source);
41
 
42
        // standalone interwiki links
43
        $tmp_regex = '/\[\[' . $this->regex . '\]\]/';
44
        $this->wiki->source = preg_replace_callback(
45
            $tmp_regex,
46
            array(&$this, 'process'),
47
            $this->wiki->source);
48
    }
49
 
50
 
51
    /**
52
    *
53
    * Generates a replacement for the matched standalone interwiki text.
54
    * Token options are:
55
    *
56
    * 'site' => The key name for the Text_Wiki interwiki array map,
57
    * usually the name of the interwiki site.
58
    *
59
    * 'page' => The page on the target interwiki to link to.
60
    *
61
    * 'text' => The text to display as the link.
62
    *
63
    * @access public
64
    *
65
    * @param array &$matches The array of matches from parse().
66
    *
67
    * @return A delimited token to be used as a placeholder in
68
    * the source text, plus any text priot to the match.
69
    *
70
    */
71
 
72
    function process(&$matches)
73
    {
74
        $options = array(
75
            'site' => $matches[1],
76
            'page' => $matches[2],
77
            'text' => $matches[1].':'.$matches[2]
78
        );
79
 
80
        return $this->wiki->addToken($this->rule, $options);
81
    }
82
 
83
 
84
    /**
85
    *
86
    * Generates a replacement for described interwiki links. Token
87
    * options are:
88
    *
89
    * 'site' => The key name for the Text_Wiki interwiki array map,
90
    * usually the name of the interwiki site.
91
    *
92
    * 'page' => The page on the target interwiki to link to.
93
    *
94
    * 'text' => The text to display as the link.
95
    *
96
    * @access public
97
    *
98
    * @param array &$matches The array of matches from parse().
99
    *
100
    * @return A delimited token to be used as a placeholder in
101
    * the source text, plus any text priot to the match.
102
    *
103
    */
104
 
105
    function processDescr(&$matches)
106
    {
107
        $options = array(
108
            'site' => $matches[1],
109
            'page' => $matches[2],
110
            'text' => $matches[3]
111
        );
112
 
113
        return $this->wiki->addToken($this->rule, $options);
114
    }
115
}
116
?>