Skip to content

Commit

Permalink
now supports an optional extended character set for wiki page names; …
Browse files Browse the repository at this point in the history
…umlauts and

so on should be legal if you call setParseConf('Wikilink', 'ext_chars', true).


git-svn-id: https://svn.php.net/repository/pear/packages/Text_Wiki/trunk@179737 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
Paul M Jones committed Feb 14, 2005
1 parent 167d1ba commit 4c73d3f
Showing 1 changed file with 39 additions and 16 deletions.
55 changes: 39 additions & 16 deletions Text/Wiki/Parse/Default/Wikilink.php
Expand Up @@ -28,6 +28,9 @@

class Text_Wiki_Parse_Wikilink extends Text_Wiki_Parse {

var $conf = array (
'ext_chars' => false
);

/**
*
Expand All @@ -46,22 +49,36 @@ function Text_Wiki_Parse_Wikilink(&$obj)
{
parent::Text_Wiki_Parse($obj);

// allows numbers as "lowercase letters" in the regex
if ($this->getConf('ext_chars')) {
// use an extended character set; this should
// allow for umlauts and so on. taken from the
// Tavi project defaults.php file.
$upper = "A-Z\xc0-\xde";
$lower = "a-z0-9\xdf-\xfe";
$either = "A-Za-z0-9\xc0-\xfe";
} else {
// the default character set, should be fine
// for most purposes.
$upper = "A-Z";
$lower = "a-z0-9";
$either = "A-Za-z0-9";
}

// build the regular expression for finding WikiPage names.
$this->regex =
"(!?" . // START WikiPage pattern (1)
"[A-Z]" . // 1 upper
"[A-Za-z0-9]*" . // 0+ alpha or digit
"[a-z0-9]+" . // 1+ lower or digit
"[A-Z]" . // 1 upper
"[A-Za-z0-9]*" . // 0+ or more alpha or digit
")" . // END WikiPage pattern (/1)
"((\#" . // START Anchor pattern (2)(3)
"[A-Za-z]" . // 1 alpha
"(" . // start sub pattern (4)
"[-A-Za-z0-9_:.]*" . // 0+ dash, alpha, digit, underscore, colon, dot
"[-A-Za-z0-9_]" . // 1 dash, alpha, digit, or underscore
")?)?)"; // end subpatterns (/4)(/3)(/2)

"(!?" . // START WikiPage pattern (1)
"[$upper]" . // 1 upper
"[$either]*" . // 0+ alpha or digit
"[$lower]+" . // 1+ lower or digit
"[$upper]" . // 1 upper
"[$either]*" . // 0+ or more alpha or digit
")" . // END WikiPage pattern (/1)
"((\#" . // START Anchor pattern (2)(3)
"[$either]" . // 1 alpha
"(" . // start sub pattern (4)
"[-_$either:.]*" . // 0+ dash, alpha, digit, underscore, colon, dot
"[-_$either]" . // 1 dash, alpha, digit, or underscore
")?)?)"; // end subpatterns (/4)(/3)(/2)
}


Expand All @@ -86,7 +103,13 @@ function parse()
);

// standalone wiki links
$tmp_regex = '/(^|[^A-Za-z0-9\-_])' . $this->regex . '/';
if ($this->getConf('ext_chars')) {
$either = "A-Za-z0-9\xc0-\xfe";
} else {
$either = "A-Za-z0-9";
}

$tmp_regex = '/(^|[^$either\-_])' . $this->regex . '/';
$this->wiki->source = preg_replace_callback(
$tmp_regex,
array(&$this, 'process'),
Expand Down

0 comments on commit 4c73d3f

Please sign in to comment.