860a2f9a2260a729d3ce4337164e0cb29f12d9c5
5 * Parses for wiki freelink text.
11 * @author Paul M. Jones <pmjones@php.net>
15 * @version $Id: Freelink.php,v 1.3 2005/02/23 17:38:29 pmjones Exp $
21 * Parses for freelinked page links.
23 * This class implements a Text_Wiki_Parse to find source text marked as a
24 * wiki freelink, and automatically create a link to that page.
26 * A freelink is any page name not conforming to the standard
27 * StudlyCapsStyle for a wiki page name. For example, a page normally
28 * named MyHomePage can be renamed and referred to as ((My Home Page)) --
29 * note the spaces in the page name. You can also make a "nice-looking"
30 * link without renaming the target page; e.g., ((MyHomePage|My Home
31 * Page)). Finally, you can use named anchors on the target page:
32 * ((MyHomePage|My Home Page#Section1)).
38 * @author Paul M. Jones <pmjones@php.net>
42 class Text_Wiki_Parse_Freelink
extends Text_Wiki_Parse
{
47 * Constructor. We override the Text_Wiki_Parse constructor so we can
48 * explicitly comment each part of the $regex property.
52 * @param object &$obj The calling "parent" Text_Wiki object.
56 function Text_Wiki_Parse_Freelink(&$obj)
58 parent
::Text_Wiki_Parse($obj);
62 "\\(\\(" . // double open-parens
63 "(" . // START freelink page patter
64 "[-A-Za-z0-9 _+\\/.,;:!?'\"\\[\\]\\{\\}&\xc0-\xff]+" . // 1 or more of just about any character
65 ")" . // END freelink page pattern
66 "(" . // START display-name
67 "\|" . // a pipe to start the display name
68 "[-A-Za-z0-9 _+\\/.,;:!?'\"\\[\\]\\{\\}&\xc0-\xff]+" . // 1 or more of just about any character
69 ")?" . // END display-name pattern 0 or 1
70 "(" . // START pattern for named anchors
72 "[A-Za-z]" . // 1 alpha
73 "[-A-Za-z0-9_:.]*" . // 0 or more alpha, digit, underscore
74 ")?" . // END named anchors pattern 0 or 1
75 "()\\)\\)" . // double close-parens
82 * Generates a replacement for the matched text. Token options are:
84 * 'page' => the wiki page name (e.g., HomePage).
86 * 'text' => alternative text to be displayed in place of the wiki
89 * 'anchor' => a named anchor on the target wiki page
93 * @param array &$matches The array of matches from parse().
95 * @return A delimited token to be used as a placeholder in
96 * the source text, plus any text priot to the match.
100 function process(&$matches)
102 // use nice variable names
106 // get rid of the leading # from the anchor, if any
107 $anchor = substr($matches[3], 1);
109 // is the page given a new text appearance?
110 if (trim($text) == '') {
114 // yes, strip the leading | character
115 $text = substr($text, 1);
125 // return a token placeholder
126 return $this->wiki
->addToken($this->rule
, $options);