summaryrefslogtreecommitdiff
path: root/includes/pear/Text/Wiki/Parse/Creole
diff options
context:
space:
mode:
Diffstat (limited to 'includes/pear/Text/Wiki/Parse/Creole')
-rw-r--r--includes/pear/Text/Wiki/Parse/Creole/Address.php67
-rw-r--r--includes/pear/Text/Wiki/Parse/Creole/Blockquote.php176
-rw-r--r--includes/pear/Text/Wiki/Parse/Creole/Box.php81
-rw-r--r--includes/pear/Text/Wiki/Parse/Creole/Break.php73
-rw-r--r--includes/pear/Text/Wiki/Parse/Creole/Center.php78
-rw-r--r--includes/pear/Text/Wiki/Parse/Creole/Delimiter.php68
-rw-r--r--includes/pear/Text/Wiki/Parse/Creole/Emphasis.php83
-rw-r--r--includes/pear/Text/Wiki/Parse/Creole/Footnote.php83
-rw-r--r--includes/pear/Text/Wiki/Parse/Creole/Heading.php97
-rw-r--r--includes/pear/Text/Wiki/Parse/Creole/Horiz.php58
-rw-r--r--includes/pear/Text/Wiki/Parse/Creole/Image.php69
-rw-r--r--includes/pear/Text/Wiki/Parse/Creole/List.php244
-rw-r--r--includes/pear/Text/Wiki/Parse/Creole/Newline.php60
-rw-r--r--includes/pear/Text/Wiki/Parse/Creole/Paragraph.php139
-rw-r--r--includes/pear/Text/Wiki/Parse/Creole/Prefilter.php54
-rw-r--r--includes/pear/Text/Wiki/Parse/Creole/Preformatted.php68
-rw-r--r--includes/pear/Text/Wiki/Parse/Creole/Raw.php61
-rw-r--r--includes/pear/Text/Wiki/Parse/Creole/Strong.php84
-rw-r--r--includes/pear/Text/Wiki/Parse/Creole/Subscript.php75
-rw-r--r--includes/pear/Text/Wiki/Parse/Creole/Superscript.php75
-rw-r--r--includes/pear/Text/Wiki/Parse/Creole/Table.php207
-rw-r--r--includes/pear/Text/Wiki/Parse/Creole/Tighten.php37
-rw-r--r--includes/pear/Text/Wiki/Parse/Creole/Trim.php75
-rw-r--r--includes/pear/Text/Wiki/Parse/Creole/Tt.php78
-rw-r--r--includes/pear/Text/Wiki/Parse/Creole/Underline.php83
-rw-r--r--includes/pear/Text/Wiki/Parse/Creole/Url.php109
-rw-r--r--includes/pear/Text/Wiki/Parse/Creole/Wikilink.php322
27 files changed, 2704 insertions, 0 deletions
diff --git a/includes/pear/Text/Wiki/Parse/Creole/Address.php b/includes/pear/Text/Wiki/Parse/Creole/Address.php
new file mode 100644
index 0000000..5e1eca1
--- /dev/null
+++ b/includes/pear/Text/Wiki/Parse/Creole/Address.php
@@ -0,0 +1,67 @@
+<?php
+
+/**
+ *
+ * Parses for signatures.
+ * This class implements a Text_Wiki rule to find sections of the source
+ * text that are signatures. A signature is any line starting with exactly
+ * two - signs.
+ *
+ * @category Text
+ *
+ * @package Text_Wiki
+ *
+ * @author Michele Tomaiuolo <tomamic@yahoo.it>
+ *
+ * @license LGPL
+ *
+ * @version $Id: Address.php 222265 2006-10-23 13:11:27Z mic $
+ *
+ */
+
+class Text_Wiki_Parse_Address extends Text_Wiki_Parse {
+
+ /**
+ *
+ * The regular expression used to find source text matching this
+ * rule.
+ *
+ * @access public
+ *
+ * @var string
+ *
+ */
+
+ var $regex = '/^--([^-].*)$/m';
+
+ /**
+ *
+ * Generates a token entry for the matched text. Token options are:
+ *
+ * 'start' => The starting point of the signature.
+ *
+ * 'end' => The ending point of the signature.
+ *
+ * @access public
+ *
+ * @param array &$matches The array of matches from parse().
+ *
+ * @return A delimited token number to be used as a placeholder in
+ * the source text.
+ *
+ */
+
+ function process(&$matches)
+ {
+ $start = $this->wiki->addToken(
+ $this->rule, array('type' => 'start')
+ );
+
+ $end = $this->wiki->addToken(
+ $this->rule, array('type' => 'end')
+ );
+
+ return "\n" . $start . trim($matches[1]) . $end;
+ }
+}
+?> \ No newline at end of file
diff --git a/includes/pear/Text/Wiki/Parse/Creole/Blockquote.php b/includes/pear/Text/Wiki/Parse/Creole/Blockquote.php
new file mode 100644
index 0000000..2ab6c14
--- /dev/null
+++ b/includes/pear/Text/Wiki/Parse/Creole/Blockquote.php
@@ -0,0 +1,176 @@
+<?php
+
+/**
+ *
+ * Parse for block-quoted text.
+ *
+ * Find source text marked as a blockquote, identified by any number of
+ * greater-than signs '>' at the start of the line, followed by an
+ * optional space, and then the quote text; each '>' indicates an
+ * additional level of quoting.
+ *
+ * @category Text
+ *
+ * @package Text_Wiki
+ *
+ * @author Paul M. Jones <pmjones@php.net>
+ * @author Michele Tomaiuolo <tomamic@yahoo.it>
+ *
+ * @license LGPL
+ *
+ * @version $Id: Blockquote.php 230214 2007-02-19 08:57:14Z mic $
+ *
+ */
+
+class Text_Wiki_Parse_Blockquote extends Text_Wiki_Parse {
+
+
+ /**
+ *
+ * Regex for parsing the source text.
+ *
+ * @access public
+ *
+ * @var string
+ *
+ * @see parse()
+ *
+ */
+
+ var $regex = '/\n(([>:]).*\n)(?!([>:]))/Us';
+
+
+ /**
+ *
+ * Generates a replacement for the matched text.
+ *
+ * Token options are:
+ *
+ * 'type' =>
+ * 'start' : the start of a blockquote
+ * 'end' : the end of a blockquote
+ *
+ * 'level' => the indent level (0 for the first level, 1 for the
+ * second, etc)
+ *
+ * @access public
+ *
+ * @param array &$matches The array of matches from parse().
+ *
+ * @return A series of text and delimited tokens marking the different
+ * list text and list elements.
+ *
+ */
+
+ function process(&$matches)
+ {
+ // the replacement text we will return to parse()
+ $return = '';
+
+ // the list of post-processing matches
+ $list = array();
+
+ // $matches[1] is the text matched as a list set by parse();
+ // create an array called $list that contains a new set of
+ // matches for the various list-item elements.
+ preg_match_all(
+ '=^([>:]+)(.*?\n)=ms',
+ $matches[1],
+ $list,
+ PREG_SET_ORDER
+ );
+
+ // a stack of starts and ends; we keep this so that we know what
+ // indent level we're at.
+ $stack = array();
+
+ // loop through each list-item element.
+ foreach ($list as $key => $val) {
+
+ // $val[0] is the full matched list-item line
+ // $val[1] is the number of initial '>' chars (indent level)
+ // $val[2] is the quote text
+
+ // we number levels starting at 1, not zero
+ $level = strlen($val[1]);
+
+ // get the text of the line
+ $text = trim($val[2]);
+
+ // add a level to the list?
+ while ($level > count($stack)) {
+
+ $css = ($val[1][count($stack)] == ':') ? 'remark' : '';
+
+ // the current indent level is greater than the number
+ // of stack elements, so we must be starting a new
+ // level. push the new level onto the stack with a
+ // dummy value (boolean true)...
+ array_push($stack, true);
+
+ $return .= "\n\n";
+
+ // ...and add a start token to the return.
+ $return .= $this->wiki->addToken(
+ $this->rule,
+ array(
+ 'type' => 'start',
+ 'level' => $level - 1,
+ 'css' => $css
+ )
+ );
+
+ $return .= "\n\n";
+ }
+
+ // remove a level?
+ while (count($stack) > $level) {
+
+ // as long as the stack count is greater than the
+ // current indent level, we need to end list types.
+ // continue adding end-list tokens until the stack count
+ // and the indent level are the same.
+ array_pop($stack);
+
+ $return .= "\n\n";
+
+ $return .= $this->wiki->addToken(
+ $this->rule,
+ array (
+ 'type' => 'end',
+ 'level' => count($stack)
+ )
+ );
+
+ $return .= "\n\n";
+ }
+
+ // add the line text.
+ $return .= $text . "\n";
+ }
+
+ // the last line may have been indented. go through the stack
+ // and create end-tokens until the stack is empty.
+ $return .= "\n\n";
+
+ while (count($stack) > 0) {
+ array_pop($stack);
+
+ $return .= "\n\n";
+
+ $return .= $this->wiki->addToken(
+ $this->rule,
+ array (
+ 'type' => 'end',
+ 'level' => count($stack)
+ )
+ );
+
+ $return .= "\n\n";
+ }
+
+ // we're done! send back the replacement text.
+ return "\n\n$return\n\n";
+ }
+}
+?> \ No newline at end of file
diff --git a/includes/pear/Text/Wiki/Parse/Creole/Box.php b/includes/pear/Text/Wiki/Parse/Creole/Box.php
new file mode 100644
index 0000000..4660a3d
--- /dev/null
+++ b/includes/pear/Text/Wiki/Parse/Creole/Box.php
@@ -0,0 +1,81 @@
+<?php
+
+/**
+*
+* Parses for bold text.
+*
+* @category Text
+*
+* @package Text_Wiki
+*
+* @author Justin Patrin <papercrane@reversefold.com>
+* @author Paul M. Jones <pmjones@php.net>
+*
+* @license LGPL
+*
+* @version $Id: Box.php 240481 2007-07-30 19:11:32Z mic $
+*
+*/
+
+/**
+*
+* Parses for bold text.
+*
+* This class implements a Text_Wiki_Rule to find source text marked for
+* strong emphasis (bold) as defined by text surrounded by three
+* single-quotes. On parsing, the text itself is left in place, but the
+* starting and ending instances of three single-quotes are replaced with
+* tokens.
+*
+* @category Text
+*
+* @package Text_Wiki
+*
+* @author Justin Patrin <papercrane@reversefold.com>
+* @author Paul M. Jones <pmjones@php.net>
+*
+*/
+
+class Text_Wiki_Parse_Box extends Text_Wiki_Parse {
+
+
+ /**
+ *
+ * The regular expression used to parse the source text and find
+ * matches conforming to this rule. Used by the parse() method.
+ *
+ * @access public
+ *
+ * @var string
+ *
+ * @see parse()
+ *
+ */
+
+ var $regex = '/\n\[\d+\].*/s';
+
+
+ /**
+ *
+ * Generates a replacement for the matched text. Token options are:
+ *
+ * 'type' => ['start'|'end'] The starting or ending point of the
+ * emphasized text. The text itself is left in the source.
+ *
+ * @access public
+ *
+ * @param array &$matches The array of matches from parse().
+ *
+ * @return A pair of delimited tokens to be used as a placeholder in
+ * the source text surrounding the text to be emphasized.
+ *
+ */
+
+ function process(&$matches)
+ {
+ $start = $this->wiki->addToken($this->rule, array('type' => 'start', 'css' => 'footnotes'));
+ $end = $this->wiki->addToken($this->rule, array('type' => 'end'));
+ return $start . $matches[0] . "\n" . $end . "\n\n";
+ }
+}
+?> \ No newline at end of file
diff --git a/includes/pear/Text/Wiki/Parse/Creole/Break.php b/includes/pear/Text/Wiki/Parse/Creole/Break.php
new file mode 100644
index 0000000..47d12d9
--- /dev/null
+++ b/includes/pear/Text/Wiki/Parse/Creole/Break.php
@@ -0,0 +1,73 @@
+<?php
+
+/**
+*
+* Parses for explicit line breaks.
+*
+* @category Text
+*
+* @package Text_Wiki
+*
+* @author Paul M. Jones <pmjones@php.net>
+*
+* @license LGPL
+*
+* @version $Id: Break.php 230561 2007-02-23 14:19:19Z mic $
+*
+*/
+
+/**
+*
+* Parses for explicit line breaks.
+*
+* This class implements a Text_Wiki_Parse to mark forced line breaks in the
+* source text.
+*
+* @category Text
+*
+* @package Text_Wiki
+*
+* @author Paul M. Jones <pmjones@php.net>
+*
+*/
+
+class Text_Wiki_Parse_Break extends Text_Wiki_Parse {
+
+
+ /**
+ *
+ * The regular expression used to parse the source text and find
+ * matches conforming to this rule. Used by the parse() method.
+ *
+ * @access public
+ *
+ * @var string
+ *
+ * @see parse()
+ *
+ */
+
+ //var $regex = "/[ \n]*([\\\][\\\]|\%\%\%)[ \n]*/";
+ var $regex = "/ *([\\\][\\\]|\%\%\%)\n?/";
+
+
+ /**
+ *
+ * Generates a replacement token for the matched text.
+ *
+ * @access public
+ *
+ * @param array &$matches The array of matches from parse().
+ *
+ * @return string A delimited token to be used as a placeholder in
+ * the source text.
+ *
+ */
+
+ function process(&$matches)
+ {
+ return $this->wiki->addToken($this->rule);
+ }
+}
+
+?> \ No newline at end of file
diff --git a/includes/pear/Text/Wiki/Parse/Creole/Center.php b/includes/pear/Text/Wiki/Parse/Creole/Center.php
new file mode 100644
index 0000000..3753aca
--- /dev/null
+++ b/includes/pear/Text/Wiki/Parse/Creole/Center.php
@@ -0,0 +1,78 @@
+<?php
+
+/**
+ *
+ * Parses for centered text.
+ *
+ * This class implements a Text_Wiki_Parse to find source text marked to
+ * be a center element, as defined by text on a line by itself prefixed
+ * with an exclamation mark (!).
+ * The centered text itself is left in the source, but is prefixed and
+ * suffixed with delimited tokens marking its start and end.
+ *
+ * @category Text
+ *
+ * @package Text_Wiki
+ *
+ * @author Tomaiuolo Michele <tomamic@yahoo.it>
+ *
+ * @license LGPL
+ *
+ * @version $Id: Center.php 240476 2007-07-30 14:22:34Z mic $
+ *
+ */
+
+class Text_Wiki_Parse_Center extends Text_Wiki_Parse {
+
+
+ /**
+ *
+ * The regular expression used to parse the source text and find
+ * matches conforming to this rule. Used by the parse() method.
+ *
+ * @access public
+ *
+ * @var string
+ *
+ * @see parse()
+ *
+ */
+
+ var $regex = '/^! *(.*?)$/m';
+
+ /**
+ *
+ * Generates a replacement for the matched text. Token options are:
+ *
+ * 'type' => ['start'|'end'] The starting or ending point of the
+ * centered text. The text itself is left in the source.
+ *
+ * @access public
+ *
+ * @param array &$matches The array of matches from parse().
+ *
+ * @return string A pair of delimited tokens to be used as a
+ * placeholder in the source text surrounding the centered text.
+ *
+ */
+
+ function process(&$matches)
+ {
+ $start = $this->wiki->addToken(
+ $this->rule,
+ array(
+ 'type' => 'start'
+ )
+ );
+
+ $end = $this->wiki->addToken(
+ $this->rule,
+ array(
+ 'type' => 'end'
+ )
+ );
+
+ return $start . trim($matches[1]) . $end . "\n\n";
+ }
+}
+?>
diff --git a/includes/pear/Text/Wiki/Parse/Creole/Delimiter.php b/includes/pear/Text/Wiki/Parse/Creole/Delimiter.php
new file mode 100644
index 0000000..c53b78a
--- /dev/null
+++ b/includes/pear/Text/Wiki/Parse/Creole/Delimiter.php
@@ -0,0 +1,68 @@
+<?php
+
+/**
+ *
+ * Parses for Text_Wiki delimiter characters already in the source text.
+ *
+ * This class implements a Text_Wiki_Parse to find instances of the delimiter
+ * character already embedded in the source text; it extracts them and replaces
+ * them with a delimited token, then renders them as the delimiter itself
+ * when the target format is XHTML.
+ *
+ * @category Text
+ *
+ * @package Text_Wiki
+ *
+ * @author Paul M. Jones <pmjones@php.net>
+ *
+ * @license LGPL
+ *
+ * @version $Id: Delimiter.php 222265 2006-10-23 13:11:27Z mic $
+ *
+ */
+
+class Text_Wiki_Parse_Delimiter extends Text_Wiki_Parse {
+
+ /**
+ *
+ * Constructor. Overrides the Text_Wiki_Parse constructor so that we
+ * can set the $regex property dynamically (we need to include the
+ * Text_Wiki $delim character.
+ *
+ * @param object &$obj The calling "parent" Text_Wiki object.
+ *
+ * @param string $name The token name to use for this rule.
+ *
+ */
+
+ function Text_Wiki_Parse_Delimiter(&$obj)
+ {
+ parent::Text_Wiki_Parse($obj);
+ $this->regex = '/' . $this->wiki->delim . '/';
+ }
+
+
+ /**
+ *
+ * Generates a token entry for the matched text. Token options are:
+ *
+ * 'text' => The full matched text.
+ *
+ * @access public
+ *
+ * @param array &$matches The array of matches from parse().
+ *
+ * @return A delimited token number to be used as a placeholder in
+ * the source text.
+ *
+ */
+
+ function process(&$matches)
+ {
+ return $this->wiki->addToken(
+ $this->rule,
+ array('text' => $this->wiki->delim)
+ );
+ }
+}
+?> \ No newline at end of file
diff --git a/includes/pear/Text/Wiki/Parse/Creole/Emphasis.php b/includes/pear/Text/Wiki/Parse/Creole/Emphasis.php
new file mode 100644
index 0000000..979f89e
--- /dev/null
+++ b/includes/pear/Text/Wiki/Parse/Creole/Emphasis.php
@@ -0,0 +1,83 @@
+<?php
+
+/**
+ *
+ * Parses for italic text.
+ *
+ * This class implements a Text_Wiki_Parse to find source text marked for
+ * emphasis (italics) as defined by text surrounded by two slashes.
+ * On parsing, the text itself is left in place, but the starting and ending
+ * instances of two single-quotes are replaced with tokens.
+ *
+ * @category Text
+ *
+ * @package Text_Wiki
+ *
+ * @author Paul M. Jones <pmjones@php.net>
+ * @author Michele Tomaiuolo <tomamic@yahoo.it>
+ *
+ * @license LGPL
+ *
+ * @version $Id: Emphasis.php 242125 2007-09-03 21:16:10Z mic $
+ *
+ */
+
+class Text_Wiki_Parse_Emphasis extends Text_Wiki_Parse {
+
+
+ /**
+ *
+ * The regular expression used to parse the source text and find
+ * matches conforming to this rule. Used by the parse() method.
+ *
+ * @access public
+ *
+ * @var string
+ *
+ * @see parse()
+ *
+ */
+
+ var $regex = "/\/\/(.+?)\/\//";
+ //var $regex = "/(?:\/\/(.+?)\/\/|(?:(?<=[\W_\xFF])\/(?![ \/]))(.+?)(?:(?<![ \/])\/(?=[\W_\xFF])))/";
+
+ /**
+ *
+ * Generates a replacement for the matched text. Token options are:
+ *
+ * 'type' => ['start'|'end'] The starting or ending point of the
+ * emphasized text. The text itself is left in the source.
+ *
+ * @access public
+ *
+ * @param array &$matches The array of matches from parse().
+ *
+ * @return string A pair of delimited tokens to be used as a
+ * placeholder in the source text surrounding the text to be
+ * emphasized.
+ *
+ */
+
+ function process(&$matches)
+ {
+ $text = $matches[1];
+ //$text = $matches[1]/* ? $matches[1] : $matches[2]*/;
+
+ if (! $this->wiki->checkInnerTags($text)) {
+ return $matches[0];
+ }
+
+ $start = $this->wiki->addToken(
+ $this->rule,
+ array('type' => 'start')
+ );
+
+ $end = $this->wiki->addToken(
+ $this->rule,
+ array('type' => 'end')
+ );
+
+ return $start . $text . $end;
+ }
+}
+?> \ No newline at end of file
diff --git a/includes/pear/Text/Wiki/Parse/Creole/Footnote.php b/includes/pear/Text/Wiki/Parse/Creole/Footnote.php
new file mode 100644
index 0000000..00e4178
--- /dev/null
+++ b/includes/pear/Text/Wiki/Parse/Creole/Footnote.php
@@ -0,0 +1,83 @@
+<?php
+
+/**
+ *
+ * Parses for bold text.
+ *
+ * This class implements a Text_Wiki_Rule to find source text marked for
+ * strong emphasis (bold) as defined by text surrounded by two
+ * stars. On parsing, the text itself is left in place, but the
+ * starting and ending instances of two stars are replaced with
+ * tokens.
+ *
+ * @category Text
+ *
+ * @package Text_Wiki
+ *
+ * @author Paul M. Jones <pmjones@php.net>
+ * @author Michele Tomaiuolo <tomamic@yahoo.it>
+ *
+ * @license LGPL
+ *
+ * @version $Id: Footnote.php 236407 2007-05-26 17:47:24Z mic $
+ *
+ */
+
+class Text_Wiki_Parse_Footnote extends Text_Wiki_Parse {
+
+
+ /**
+ *
+ * The regular expression used to parse the source text and find
+ * matches conforming to this rule. Used by the parse() method.
+ *
+ * @access public
+ *
+ * @var string
+ *
+ * @see parse()
+ *
+ */
+
+ var $regex = "/(\n)*\[([0-9]+)\]/";
+
+
+ /**
+ *
+ * Generates a replacement for the matched text. Token options are:
+ *
+ * 'type' => ['start'|'end'] The starting or ending point of the
+ * emphasized text. The text itself is left in the source.
+ *
+ * @access public
+ *
+ * @param array &$matches The array of matches from parse().
+ *
+ * @return A pair of delimited tokens to be used as a placeholder in
+ * the source text surrounding the text to be emphasized.
+ *
+ */
+
+ function process(&$matches)
+ {
+ $id = $matches[2];
+
+ if ($matches[1] == "\n") {
+ $matches[1] = "\n\n";
+ $name = "fn$id";
+ $href = "#ref$id";
+ }
+ else {
+ $name = "ref$id";
+ $href = "#fn$id";
+ }
+
+ $token = $this->wiki->addToken(
+ 'Url',
+ array('text' => "[$id]", 'href' => $href, 'name' => $name, 'type' => 'inline')
+ );
+
+ return $matches[1] . $token;
+ }
+}
+?> \ No newline at end of file
diff --git a/includes/pear/Text/Wiki/Parse/Creole/Heading.php b/includes/pear/Text/Wiki/Parse/Creole/Heading.php
new file mode 100644
index 0000000..eb213c9
--- /dev/null
+++ b/includes/pear/Text/Wiki/Parse/Creole/Heading.php
@@ -0,0 +1,97 @@
+<?php
+
+/**
+ *
+ * Parses for heading text.
+ *
+ * This class implements a Text_Wiki_Parse to find source text marked to
+ * be a heading element, as defined by text on a line by itself prefixed
+ * with a number of equasl signs (=), determining the heading level.
+ * Equal signs at the end of the line are silently removed.
+ * The heading text itself is left in the source, but is prefixed and
+ * suffixed with delimited tokens marking the start and end of the heading.
+ *
+ * @category Text
+ *
+ * @package Text_Wiki
+ *
+ * @author Paul M. Jones <pmjones@php.net>
+ * @author Tomaiuolo Michele <tomamic@yahoo.it>
+ *
+ * @license LGPL
+ *
+ * @version $Id: Heading.php 228641 2007-02-01 09:57:36Z mic $
+ *
+ */
+
+class Text_Wiki_Parse_Heading extends Text_Wiki_Parse {
+
+
+ /**
+ *
+ * The regular expression used to parse the source text and find
+ * matches conforming to this rule. Used by the parse() method.
+ *
+ * @access public
+ *
+ * @var string
+ *
+ * @see parse()
+ *
+ */
+
+ var $regex = '/^(={1,6}) *(.*?) *=*$/m';
+
+ var $conf = array(
+ 'id_prefix' => 'toc'
+ );
+
+ /**
+ *
+ * Generates a replacement for the matched text. Token options are:
+ *
+ * 'type' => ['start'|'end'] The starting or ending point of the
+ * heading text. The text itself is left in the source.
+ *
+ * @access public
+ *
+ * @param array &$matches The array of matches from parse().
+ *
+ * @return string A pair of delimited tokens to be used as a
+ * placeholder in the source text surrounding the heading text.
+ *
+ */
+
+ function process(&$matches)
+ {
+ // keep a running count for header IDs. we use this later
+ // when constructing TOC entries, etc.
+ static $id;
+ if (! isset($id)) {
+ $id = 0;
+ }
+
+ $prefix = htmlspecialchars($this->getConf('id_prefix'));
+
+ $start = $this->wiki->addToken(
+ $this->rule,
+ array(
+ 'type' => 'start',
+ 'level' => strlen($matches[1]),
+ 'text' => trim($matches[2]),
+ 'id' => $prefix . $id ++
+ )
+ );
+
+ $end = $this->wiki->addToken(
+ $this->rule,
+ array(
+ 'type' => 'end',
+ 'level' => strlen($matches[1])
+ )
+ );
+
+ return $start . trim($matches[2]) . $end . "\n\n";
+ }
+}
+?>
diff --git a/includes/pear/Text/Wiki/Parse/Creole/Horiz.php b/includes/pear/Text/Wiki/Parse/Creole/Horiz.php
new file mode 100644
index 0000000..60c6160
--- /dev/null
+++ b/includes/pear/Text/Wiki/Parse/Creole/Horiz.php
@@ -0,0 +1,58 @@
+<?php
+
+/**
+ *
+ * Parses for horizontal ruling lines.
+ *
+ * This class implements a Text_Wiki_Parse to find source text marked to
+ * be a horizontal rule, as defined by four dashed on their own line.
+ *
+ * @category Text
+ *
+ * @package Text_Wiki
+ *
+ * @author Paul M. Jones <pmjones@php.net>
+ *
+ * @license LGPL
+ *
+ * @version $Id: Horiz.php 228654 2007-02-01 11:35:53Z mic $
+ *
+ */
+
+class Text_Wiki_Parse_Horiz extends Text_Wiki_Parse {
+
+
+ /**
+ *
+ * The regular expression used to parse the source text and find
+ * matches conforming to this rule. Used by the parse() method.
+ *
+ * @access public
+ *
+ * @var string
+ *
+ * @see parse()
+ *
+ */
+
+ var $regex = '/^([-]{4,})$/m';
+
+
+ /**
+ *
+ * Generates a replacement token for the matched text.
+ *
+ * @access public
+ *
+ * @param array &$matches The array of matches from parse().
+ *
+ * @return string A token marking the horizontal rule.
+ *
+ */
+
+ function process(&$matches)
+ {
+ return "\n" . $this->wiki->addToken($this->rule) . "\n";
+ }
+}
+?> \ No newline at end of file
diff --git a/includes/pear/Text/Wiki/Parse/Creole/Image.php b/includes/pear/Text/Wiki/Parse/Creole/Image.php
new file mode 100644
index 0000000..09ddb8b
--- /dev/null
+++ b/includes/pear/Text/Wiki/Parse/Creole/Image.php
@@ -0,0 +1,69 @@
+<?php
+
+/**
+ *
+ * Parse for images in the source text.
+ *
+ * @category Text
+ *
+ * @package Text_Wiki
+ *
+ * @author Tomaiuolo Michele <tomamic@yahoo.it>
+ *
+ * @license LGPL
+ *
+ * @version $Id: Image.php 243106 2007-09-28 22:02:50Z mic $
+ *
+ */
+
+
+class Text_Wiki_Parse_Image extends Text_Wiki_Parse {
+
+ /**
+ *
+ * Constructor. Overrides the Text_Wiki_Parse constructor so that we
+ * can set the $regex property dynamically (we need to include the
+ * Text_Wiki $delim character).
+ *
+ * @param object &$obj The calling "parent" Text_Wiki object.
+ *
+ * @param string $name The token name to use for this rule.
+ *
+ */
+
+ function Text_Wiki_Parse_Image(&$obj)
+ {
+ parent::Text_Wiki_Parse($obj);
+ $this->regex = '/{{([^' . $this->wiki->delim . ']*)(\|([^' . $this->wiki->delim . ']*))?}}/U';
+ }
+
+
+ /**
+ *
+ * Generates a replacement token for the matched text.
+ *
+ * @access public
+ *
+ * @param array &$matches The array of matches from parse().
+ *
+ * @return string A token marking the horizontal rule.
+ *
+ */
+
+ function process(&$matches)
+ {
+ $src = trim($matches[1]);
+ $src = ltrim($src, '/');
+ $alt = isset($matches[3]) ? trim($matches[3]) : $src;
+
+ return $this->wiki->addToken(
+ $this->rule,
+ array(
+ 'src' => $src,
+ 'attr' => array('alt' => $alt, 'title' => $alt)
+ )
+ );
+ }
+
+}
+?> \ No newline at end of file
diff --git a/includes/pear/Text/Wiki/Parse/Creole/List.php b/includes/pear/Text/Wiki/Parse/Creole/List.php
new file mode 100644
index 0000000..36ab590
--- /dev/null
+++ b/includes/pear/Text/Wiki/Parse/Creole/List.php
@@ -0,0 +1,244 @@
+<?php
+
+/**
+ *
+ * Parses for bulleted and numbered lists.
+ *
+ * This class implements a Text_Wiki_Parse to find source text marked as
+ * a bulleted or numbered list. In short, if a line starts with '*' then
+ * it is a bullet list item; if a line starts with '#' then it is a
+ * number list item. Multiple * or # indicate an indented sub-list.
+ * The list items must be on sequential lines, and are ended by blank lines.
+ * Using a non-* non-# character at the beginning of a line ends the list.
+ * Note that single newline characters may be eaten beforehand by other rules.
+ *
+ * @category Text
+ *
+ * @package Text_Wiki
+ *
+ * @author Justin Patrin <papercrane@reversefold.com>
+ * @author Paul M. Jones <pmjones@php.net>
+ * @author Michele Tomaiuolo <tomamic@yahoo.it>
+ *
+ * @license LGPL
+ *
+ * @version $Id: List.php 240550 2007-08-01 07:57:34Z mic $
+ *
+ */
+
+class Text_Wiki_Parse_List extends Text_Wiki_Parse {
+
+
+ /**
+ *
+ * The regular expression used to parse the source text and find
+ * matches conforming to this rule. Used by the parse() method.
+ *
+ * @access public
+ *
+ * @var string
+ *
+ * @see parse()
+ *
+ */
+
+ var $regex = '/\n((\*[^\#\-\*]|\-[^\-\d\*\#]|\#[^\#\-\*]).*?)\n(?![\*\-#])/s';
+
+ /**
+ *
+ * Generates a replacement for the matched text. Token options are:
+ *
+ * 'type' =>
+ * 'bullet_start' : the start of a bullet list
+ * 'bullet_end' : the end of a bullet list
+ * 'number_start' : the start of a number list
+ * 'number_end' : the end of a number list
+ * 'item_start' : the start of item text (bullet or number)
+ * 'item_end' : the end of item text (bullet or number)
+ * 'unknown' : unknown type of list or item
+ *
+ * 'level' => the indent level (0 for the first level, 1 for the
+ * second, etc)
+ *
+ * 'count' => the list item number at this level. not needed for
+ * xhtml, but very useful for PDF and RTF.
+ *
+ * @access public
+ *
+ * @param array &$matches The array of matches from parse().
+ *
+ * @return A series of text and delimited tokens marking the different
+ * list text and list elements.
+ *
+ */
+
+ function process(&$matches)
+ {
+ // the replacement text we will return
+ $return = '';
+
+ // the list of post-processing matches
+ $list = array();
+
+ // a stack of list-start and list-end types; we keep this
+ // so that we know what kind of list we're working with
+ // (bullet or number) and what indent level we're at.
+ $stack = array();
+
+ // the item count is the number of list items for any
+ // given list-type on the stack
+ $itemcount = array();
+
+ // have we processed the very first list item?
+ $pastFirst = false;
+
+ // populate $list with this set of matches. $matches[1] is the
+ // text matched as a list set by parse().
+ preg_match_all(
+ '/^((\*|\-|#)+) *(.*?)$/ms',
+ $matches[1],
+ $list,
+ PREG_SET_ORDER
+ );
+
+ if (count($list) === 1 && $matches[0][0] === '*' && $matches[0][1] !== ' ' && strpos($matches[0], '*', 1)) {
+ return $matches[0];
+ }
+
+ // loop through each list-item element.
+ foreach ($list as $key => $val) {
+ // $val[0] is the full matched list-item line
+ // $val[1] is the level (number)
+ // $val[2] is the type (* or #)
+ // $val[3] is the list item text
+
+ // how many levels are we indented? (1 means the "root"
+ // list level, no indenting.)
+ $stars = $val[1];
+ $level = strlen($stars);
+ $last = $stars[strlen($stars) - 1];
+
+ // get the list item type
+ if ($last == '*' || $last == '-') {
+ $type = 'bullet';
+ } elseif ($last == '#') {
+ $type = 'number';
+ } else {
+ $type = 'unknown';
+ }
+
+ // get the text of the list item
+ $text = $val[3];
+
+ // remove a level from the list?
+ while (count($stack) > $level || (count($stack) == $level && $type != $stack[$level - 1])) {
+
+ // so we don't keep counting the stack, we set up a temp
+ // var for the count. -1 becuase we're going to pop the
+ // stack in the next command. $tmp will then equal the
+ // current level of indent.
+ $tmp = count($stack) - 1;
+
+ // as long as the stack count is greater than the
+ // current indent level, we need to end list types.
+ // continue adding end-list tokens until the stack count
+ // and the indent level are the same.
+ $return .= $this->wiki->addToken(
+ $this->rule,
+ array (
+ 'type' => array_pop($stack) . '_list_end',
+ 'level' => $tmp
+ )
+ );
+
+ // reset to the current (previous) list type so that
+ // the new list item matches the proper list type.
+ if ($tmp) {
+ $oldtype = $stack[$tmp - 1];
+ }
+
+ // reset the item count for the popped indent level
+ unset($itemcount[$tmp + 1]);
+ }
+
+ // add a level to the list?
+ if ($level > count($stack)) {
+
+ // the current indent level is greater than the
+ // number of stack elements, so we must be starting
+ // a new list. push the new list type onto the
+ // stack...
+ array_push($stack, $type);
+
+ // ...and add a list-start token to the return.
+ $return .= $this->wiki->addToken(
+ $this->rule,
+ array(
+ 'type' => $type . '_list_start',
+ 'level' => $level - 1
+ )
+ );
+ }
+
+ // add to the item count for this list (taking into account
+ // which level we are at).
+ if (! isset($itemcount[$level])) {
+ // first count
+ $itemcount[$level] = 0;
+ } else {
+ // increment count
+ $itemcount[$level]++;
+ }
+
+ // is this the very first item in the list?
+ if (! $pastFirst) {
+ $first = true;
+ $pastFirst = true;
+ } else {
+ $first = false;
+ }
+
+ // create a list-item starting token.
+ $start = $this->wiki->addToken(
+ $this->rule,
+ array(
+ 'type' => $type . '_item_start',
+ 'level' => $level,
+ 'count' => $itemcount[$level],
+ 'first' => $first
+ )
+ );
+
+ // create a list-item ending token.
+ $end = $this->wiki->addToken(
+ $this->rule,
+ array(
+ 'type' => $type . '_item_end',
+ 'level' => $level,
+ 'count' => $itemcount[$level]
+ )
+ );
+
+ // add the starting token, list-item text, and ending token
+ // to the return.
+ $return .= "\n" . $start . $text . $end;
+ }
+
+ // the last list-item may have been indented. go through the
+ // list-type stack and create end-list tokens until the stack
+ // is empty.
+ while (count($stack) > 0) {
+ $return .= $this->wiki->addToken(
+ $this->rule,
+ array (
+ 'type' => array_pop($stack) . '_list_end',
+ 'level' => count($stack)
+ )
+ );
+ }
+
+ // we're done! send back the replacement text.
+ return "\n\n" . $return . "\n\n";
+ }
+}
+?> \ No newline at end of file
diff --git a/includes/pear/Text/Wiki/Parse/Creole/Newline.php b/includes/pear/Text/Wiki/Parse/Creole/Newline.php
new file mode 100644
index 0000000..92554ed
--- /dev/null
+++ b/includes/pear/Text/Wiki/Parse/Creole/Newline.php
@@ -0,0 +1,60 @@
+<?php
+
+/**
+ *
+ * Parses for implied line breaks indicated by newlines.
+ * Newlines are not considered if followed by another newline
+ * or by one of these chars: * | - # = {
+ *
+ * @category Text
+ *
+ * @package Text_Wiki
+ *
+ * @author Michele Tomaiuolo <tomamic@yahoo.it>
+ *
+ * @license LGPL
+ *
+ * @version $Id: Newline.php 240560 2007-08-01 11:00:11Z mic $
+ *
+ */
+
+class Text_Wiki_Parse_Newline extends Text_Wiki_Parse {
+
+
+ /**
+ *
+ * The regular expression used to parse the source text and find
+ * matches conforming to this rule. Used by the parse() method.
+ *
+ * @access public
+ *
+ * @var string
+ *
+ * @see parse()
+ *
+ */
+
+ //var $regex = '/(?<!\n)\n(?![\n\#\=\|\-\>\:]|\*[^\*\#]|\*+ )/m';
+ var $regex = '/(?<!\n)\n(?!\n|\#|\*|\=|\||\>|\:|\;|\!|\-\D)/m';
+
+
+ /**
+ *
+ * Generates a replacement token for the matched text.
+ *
+ * @access public
+ *
+ * @param array &$matches The array of matches from parse().
+ *
+ * @return string A delimited token to be used as a placeholder in
+ * the source text.
+ *
+ */
+
+ function process(&$matches)
+ {
+ return ' '; // $this->wiki->addToken($this->rule);
+ }
+}
+
+?> \ No newline at end of file
diff --git a/includes/pear/Text/Wiki/Parse/Creole/Paragraph.php b/includes/pear/Text/Wiki/Parse/Creole/Paragraph.php
new file mode 100644
index 0000000..d23ed33
--- /dev/null
+++ b/includes/pear/Text/Wiki/Parse/Creole/Paragraph.php
@@ -0,0 +1,139 @@
+<?php
+
+/**
+ *
+ * Parses for paragraph blocks.
+ * This class implements a Text_Wiki rule to find sections of the source
+ * text that are paragraphs. A paragraph is any line not starting with a
+ * token delimiter, followed by two newlines.
+ *
+ * @category Text
+ *
+ * @package Text_Wiki
+ *
+ * @author Paul M. Jones <pmjones@php.net>
+ * @author Michele Tomaiuolo <tomamic@yahoo.it>
+ *
+ * @license LGPL
+ *
+ * @version $Id: Paragraph.php 230214 2007-02-19 08:57:14Z mic $
+ *
+ */
+
+class Text_Wiki_Parse_Paragraph extends Text_Wiki_Parse {
+
+ /**
+ *
+ * The regular expression used to find source text matching this
+ * rule.
+ *
+ * @access public
+ *
+ * @var string
+ *
+ */
+
+ var $regex = "/^.+?\n/m"; // (?=[\n\-\|#{=])
+
+ var $conf = array(
+ 'skip' => array(
+ 'address',
+ 'box',
+ 'blockquote',
+ 'code',
+ 'heading',
+ 'center',
+ 'horiz',
+ 'deflist',
+ 'table',
+ 'list',
+ 'paragraph',
+ 'preformatted',
+ 'toc'
+ )
+ );
+
+
+ /**
+ *
+ * Generates a token entry for the matched text. Token options are:
+ *
+ * 'start' => The starting point of the paragraph.
+ *
+ * 'end' => The ending point of the paragraph.
+ *
+ * @access public
+ *
+ * @param array &$matches The array of matches from parse().
+ *
+ * @return A delimited token number to be used as a placeholder in
+ * the source text.
+ *
+ */
+
+ function process(&$matches)
+ {
+ $delim = $this->wiki->delim;
+
+ // was anything there?
+ if (trim($matches[0]) == '') {
+ return '';
+ }
+
+ // does the match start with a delimiter?
+ if (substr($matches[0], 0, 1) != $delim) {
+ // no.
+
+ $start = $this->wiki->addToken(
+ $this->rule, array('type' => 'start')
+ );
+
+ $end = $this->wiki->addToken(
+ $this->rule, array('type' => 'end')
+ );
+
+ return $start . trim($matches[0]) . $end;
+ }
+
+ // the line starts with a delimiter. read in the delimited
+ // token number, check the token, and see if we should
+ // skip it.
+
+ // loop starting at the second character (we already know
+ // the first is a delimiter) until we find another
+ // delimiter; the text between them is a token key number.
+ $key = '';
+ $len = strlen($matches[0]);
+ for ($i = 1; $i < $len; $i++) {
+ $char = $matches[0]{$i};
+ if ($char == $delim) {
+ break;
+ } else {
+ $key .= $char;
+ }
+ }
+
+ // look at the token and see if it's skippable (if we skip,
+ // it will not be marked as a paragraph)
+ $token_type = strtolower($this->wiki->tokens[$key][0]);
+ $skip = $this->getConf('skip', array());
+
+ if (in_array($token_type, $skip)) {
+ // this type of token should not have paragraphs applied to it.
+ // return the entire matched text.
+ return $matches[0];
+ } else {
+
+ $start = $this->wiki->addToken(
+ $this->rule, array('type' => 'start')
+ );
+
+ $end = $this->wiki->addToken(
+ $this->rule, array('type' => 'end')
+ );
+
+ return $start . trim($matches[0]) . $end;
+ }
+ }
+}
+?> \ No newline at end of file
diff --git a/includes/pear/Text/Wiki/Parse/Creole/Prefilter.php b/includes/pear/Text/Wiki/Parse/Creole/Prefilter.php
new file mode 100644
index 0000000..ced69b3
--- /dev/null
+++ b/includes/pear/Text/Wiki/Parse/Creole/Prefilter.php
@@ -0,0 +1,54 @@
+<?php
+
+/**
+ *
+ * "Pre-filter" the source text.
+ *
+ * Convert DOS and Mac line endings to Unix, convert tabs to 4-spaces,
+ * add newlines to the top and end of the source text.
+ *
+ * @category Text
+ *
+ * @package Text_Wiki
+ *
+ * @author Paul M. Jones <pmjones@php.net>
+ * @author Michele Tomaiuolo <tomamic@yahoo.it>
+ *
+ * @license LGPL
+ *
+ * @version $Id: Prefilter.php 222265 2006-10-23 13:11:27Z mic $
+ *
+ */
+
+class Text_Wiki_Parse_Prefilter extends Text_Wiki_Parse {
+
+
+ /**
+ *
+ * Simple parsing method.
+ *
+ * @access public
+ *
+ */
+
+ function parse()
+ {
+ // convert DOS line endings
+ $this->wiki->source = str_replace("\r\n", "\n",
+ $this->wiki->source);
+
+ // convert Macintosh line endings
+ $this->wiki->source = str_replace("\r", "\n",
+ $this->wiki->source);
+
+ // convert tabs to four-spaces
+ $this->wiki->source = str_replace("\t", " ",
+ $this->wiki->source);
+
+ // add extra newlines at the top and end; this
+ // seems to help many rules.
+ $this->wiki->source = "\n\n" . $this->wiki->source . "\n\n";
+ }
+
+}
+?> \ No newline at end of file
diff --git a/includes/pear/Text/Wiki/Parse/Creole/Preformatted.php b/includes/pear/Text/Wiki/Parse/Creole/Preformatted.php
new file mode 100644
index 0000000..ac164fb
--- /dev/null
+++ b/includes/pear/Text/Wiki/Parse/Creole/Preformatted.php
@@ -0,0 +1,68 @@
+<?php
+
+/**
+ *
+ * Parses for preformatted text.
+ *
+ * @category Text
+ *
+ * @package Text_Wiki
+ *
+ * @author Tomaiuolo Michele <tomamic@yahoo.it>
+ *
+ * @license LGPL
+ *
+ * @version $Id: Preformatted.php 240474 2007-07-30 13:14:41Z mic $
+ *
+ */
+
+class Text_Wiki_Parse_Preformatted extends Text_Wiki_Parse {
+
+
+ /**
+ *
+ * The regular expression used to parse the source text and find
+ * matches conforming to this rule. Used by the parse() method.
+ *
+ * @access public
+ *
+ * @var string
+ *
+ * @see parse()
+ *
+ */
+
+ var $regex = '/\n{{{\n(.*)\n}}}\n/Us';
+
+ /**
+ *
+ * Generates a replacement for the matched text. Token options are:
+ *
+ * 'text' => The preformatted text.
+ *
+ * @access public
+ *
+ * @param array &$matches The array of matches from parse().
+ *
+ * @return string A token to be used as a placeholder
+ * in the source text for the preformatted text.
+ *
+ */
+
+ function process(&$matches)
+ {
+ // > any line consisting of only indented three closing curly braces
+ // > will have one space removed from the indentation
+ // > -- http://www.wikicreole.org/wiki/AddNoWikiEscapeProposal
+ $find = "/\n( *) }}}/";
+ $replace = "\n$1}}}";
+ $matches[1] = preg_replace($find, $replace, $matches[1]);
+
+ $token = $this->wiki->addToken(
+ $this->rule,
+ array('text' => $matches[1])
+ );
+ return "\n\n" . $token . "\n\n";
+ }
+}
+?>
diff --git a/includes/pear/Text/Wiki/Parse/Creole/Raw.php b/includes/pear/Text/Wiki/Parse/Creole/Raw.php
new file mode 100644
index 0000000..6679267
--- /dev/null
+++ b/includes/pear/Text/Wiki/Parse/Creole/Raw.php
@@ -0,0 +1,61 @@
+<?php
+
+/**
+ *
+ * Parses for monospaced inline text.
+ *
+ * @category Text
+ *
+ * @package Text_Wiki
+ *
+ * @author Tomaiuolo Michele <tomamic@yahoo.it>
+ *
+ * @license LGPL
+ *
+ * @version $Id: Raw.php 242165 2007-09-04 19:43:07Z mic $
+ *
+ */
+
+class Text_Wiki_Parse_Raw extends Text_Wiki_Parse {
+
+
+ /**
+ *
+ * The regular expression used to parse the source text and find
+ * matches conforming to this rule. Used by the parse() method.
+ *
+ * @access public
+ *
+ * @var string
+ *
+ * @see parse()
+ *
+ */
+
+ var $regex = '/~(_|[^ \w\n])/';
+
+ /**
+ *
+ * Generates a replacement for the matched text. Token options are:
+ *
+ * 'type' => ['start'|'end'] The starting or ending point of the
+ * monospaced text. The text itself is encapsulated into a Raw token.
+ *
+ * @access public
+ *
+ * @param array &$matches The array of matches from parse().
+ *
+ * @return string A token to be used as a placeholder
+ * in the source text for the preformatted text.
+ *
+ */
+
+ function process(&$matches)
+ {
+ return $this->wiki->addToken(
+ $this->rule,
+ array('text' => $matches[1], 'type' => 'escape')
+ );
+ }
+}
+?>
diff --git a/includes/pear/Text/Wiki/Parse/Creole/Strong.php b/includes/pear/Text/Wiki/Parse/Creole/Strong.php
new file mode 100644
index 0000000..1d07d15
--- /dev/null
+++ b/includes/pear/Text/Wiki/Parse/Creole/Strong.php
@@ -0,0 +1,84 @@
+<?php
+
+/**
+ *
+ * Parses for bold text.
+ *
+ * This class implements a Text_Wiki_Rule to find source text marked for
+ * strong emphasis (bold) as defined by text surrounded by two
+ * stars. On parsing, the text itself is left in place, but the
+ * starting and ending instances of two stars are replaced with
+ * tokens.
+ *
+ * @category Text
+ *
+ * @package Text_Wiki
+ *
+ * @author Paul M. Jones <pmjones@php.net>
+ * @author Michele Tomaiuolo <tomamic@yahoo.it>
+ *
+ * @license LGPL
+ *
+ * @version $Id: Strong.php 242126 2007-09-03 21:17:00Z mic $
+ *
+ */
+
+class Text_Wiki_Parse_Strong extends Text_Wiki_Parse {
+
+
+ /**
+ *
+ * The regular expression used to parse the source text and find
+ * matches conforming to this rule. Used by the parse() method.
+ *
+ * @access public
+ *
+ * @var string
+ *
+ * @see parse()
+ *
+ */
+
+ var $regex = "/\*\*(.+?)\*\*/";
+ //var $regex = "/(?:\*\*(.+?)\*\*|(?:(?<=[\W_\xFF])\*(?![ \*]))(.+?)(?:(?<![ \*])\*(?=[\W_\xFF])))/";
+
+
+ /**
+ *
+ * Generates a replacement for the matched text. Token options are:
+ *
+ * 'type' => ['start'|'end'] The starting or ending point of the
+ * emphasized text. The text itself is left in the source.
+ *
+ * @access public
+ *
+ * @param array &$matches The array of matches from parse().
+ *
+ * @return A pair of delimited tokens to be used as a placeholder in
+ * the source text surrounding the text to be emphasized.
+ *
+ */
+
+ function process(&$matches)
+ {
+ $text = $matches[1];
+ //$text = $matches[1] ? $matches[1] : $matches[2];
+
+ if (! $this->wiki->checkInnerTags($text)) {
+ return $matches[0];
+ }
+
+ $start = $this->wiki->addToken(
+ $this->rule,
+ array('type' => 'start')
+ );
+
+ $end = $this->wiki->addToken(
+ $this->rule,
+ array('type' => 'end')
+ );
+
+ return $start . $text . $end;
+ }
+}
+?> \ No newline at end of file
diff --git a/includes/pear/Text/Wiki/Parse/Creole/Subscript.php b/includes/pear/Text/Wiki/Parse/Creole/Subscript.php
new file mode 100644
index 0000000..596f652
--- /dev/null
+++ b/includes/pear/Text/Wiki/Parse/Creole/Subscript.php
@@ -0,0 +1,75 @@
+<?php
+
+/**
+ *
+ * Parses for italic text.
+ *
+ * This class implements a Text_Wiki_Parse to find source text marked for
+ * superscript as defined by text surrounded by two '^'.
+ * On parsing, the text itself is left in place, but the starting and ending
+ * instances of two '^' are replaced with tokens.
+ *
+ * @category Text
+ *
+ * @package Text_Wiki
+ *
+ * @author Paul M. Jones <pmjones@php.net>
+ * @author Michele Tomaiuolo <tomamic@yahoo.it>
+ *
+ */
+
+class Text_Wiki_Parse_Subscript extends Text_Wiki_Parse {
+
+
+ /**
+ *
+ * The regular expression used to parse the source text and find
+ * matches conforming to this rule. Used by the parse() method.
+ *
+ * @access public
+ *
+ * @var string
+ *
+ * @see parse()
+ *
+ */
+
+ var $regex = "/\,\,(.*?)\,\,/";
+
+ /**
+ *
+ * Generates a replacement for the matched text. Token options are:
+ *
+ * 'type' => ['start'|'end'] The starting or ending point of the
+ * superscript text. The text itself is left in the source.
+ *
+ * @access public
+ *
+ * @param array &$matches The array of matches from parse().
+ *
+ * @return string A pair of delimited tokens to be used as a
+ * placeholder in the source text surrounding the text to be
+ * superscripted.
+ *
+ */
+
+ function process(&$matches)
+ {
+ if (! $this->wiki->checkInnerTags($matches[1])) {
+ return $matches[0];
+ }
+
+ $start = $this->wiki->addToken(
+ $this->rule,
+ array('type' => 'start')
+ );
+
+ $end = $this->wiki->addToken(
+ $this->rule,
+ array('type' => 'end')
+ );
+
+ return $start . $matches[1] . $end;
+ }
+}
+?> \ No newline at end of file
diff --git a/includes/pear/Text/Wiki/Parse/Creole/Superscript.php b/includes/pear/Text/Wiki/Parse/Creole/Superscript.php
new file mode 100644
index 0000000..0f5e38c
--- /dev/null
+++ b/includes/pear/Text/Wiki/Parse/Creole/Superscript.php
@@ -0,0 +1,75 @@
+<?php
+
+/**
+ *
+ * Parses for italic text.
+ *
+ * This class implements a Text_Wiki_Parse to find source text marked for
+ * superscript as defined by text surrounded by two '^'.
+ * On parsing, the text itself is left in place, but the starting and ending
+ * instances of two '^' are replaced with tokens.
+ *
+ * @category Text
+ *
+ * @package Text_Wiki
+ *
+ * @author Paul M. Jones <pmjones@php.net>
+ * @author Michele Tomaiuolo <tomamic@yahoo.it>
+ *
+ */
+
+class Text_Wiki_Parse_Superscript extends Text_Wiki_Parse {
+
+
+ /**
+ *
+ * The regular expression used to parse the source text and find
+ * matches conforming to this rule. Used by the parse() method.
+ *
+ * @access public
+ *
+ * @var string
+ *
+ * @see parse()
+ *
+ */
+
+ var $regex = "/(\^\^(.*?)\^\^|(?<=\d)(st|nd|rd|th|er|e|re|ers|res|nds|de|des|ère|ème|ères|èmes|o|a)(?!\w))/";
+
+ /**
+ *
+ * Generates a replacement for the matched text. Token options are:
+ *
+ * 'type' => ['start'|'end'] The starting or ending point of the
+ * superscript text. The text itself is left in the source.
+ *
+ * @access public
+ *
+ * @param array &$matches The array of matches from parse().
+ *
+ * @return string A pair of delimited tokens to be used as a
+ * placeholder in the source text surrounding the text to be
+ * superscripted.
+ *
+ */
+
+ function process(&$matches)
+ {
+ if (! $this->wiki->checkInnerTags($matches[0])) {
+ return $matches[0];
+ }
+
+ $start = $this->wiki->addToken(
+ $this->rule,
+ array('type' => 'start')
+ );
+
+ $end = $this->wiki->addToken(
+ $this->rule,
+ array('type' => 'end')
+ );
+
+ return $start . trim($matches[0], '^') . $end;
+ }
+}
+?> \ No newline at end of file
diff --git a/includes/pear/Text/Wiki/Parse/Creole/Table.php b/includes/pear/Text/Wiki/Parse/Creole/Table.php
new file mode 100644
index 0000000..2ab3284
--- /dev/null
+++ b/includes/pear/Text/Wiki/Parse/Creole/Table.php
@@ -0,0 +1,207 @@
+<?php
+
+/**
+ *
+ * Parses for table markup.
+ *
+ * This class implements a Text_Wiki_Parse to find source text marked as
+ * a set of table rows, where a line start (and optionally ends) with a
+ * single-pipe (|) and uses single-pipes to separate table cells.
+ * The rows must be on sequential lines (no blank lines between them).
+ * A blank line indicates the beginning of other text or another table.
+ *
+ * @category Text
+ *
+ * @package Text_Wiki
+ *
+ * @author Michele Tomaiuolo <tomamic@yahoo.it>
+ * @author Paul M. Jones <pmjones@php.net>
+ *
+ * @license LGPL
+ *
+ * @version $Id: Table.php 243077 2007-09-28 17:14:58Z mic $
+ *
+ */
+
+
+class Text_Wiki_Parse_Table extends Text_Wiki_Parse {
+
+
+ /**
+ *
+ * The regular expression used to parse the source text and find
+ * matches conforming to this rule. Used by the parse() method.
+ *
+ * @access public
+ *
+ * @var string
+ *
+ * @see parse()
+ *
+ */
+
+ var $regex = '/\n((\|).*)(\n)(?!(\|))/Us';
+
+
+ /**
+ *
+ * Generates a replacement for the matched text.
+ *
+ * Token options are:
+ *
+ * 'type' =>
+ * 'table_start' : the start of a bullet list
+ * 'table_end' : the end of a bullet list
+ * 'row_start' : the start of a number list
+ * 'row_end' : the end of a number list
+ * 'cell_start' : the start of item text (bullet or number)
+ * 'cell_end' : the end of item text (bullet or number)
+ *
+ * 'cols' => the number of columns in the table (for 'table_start')
+ *
+ * 'rows' => the number of rows in the table (for 'table_start')
+ *
+ * 'span' => column span (for 'cell_start')
+ *
+ * 'attr' => column attribute flag (for 'cell_start')
+ *
+ * @access public
+ *
+ * @param array &$matches The array of matches from parse().
+ *
+ * @return A series of text and delimited tokens marking the different
+ * table elements and cell text.
+ *
+ */
+
+ function process(&$matches)
+ {
+ // our eventual return value
+ $return = '';
+
+ // the number of columns in the table
+ $num_cols = 0;
+
+ // the number of rows in the table
+ $num_rows = 0;
+
+ // rows are separated by newlines in the matched text
+ $rows = explode("\n", $matches[1]);
+
+ // loop through each row
+ foreach ($rows as $row) {
+
+ // increase the row count
+ $num_rows ++;
+
+ // remove first and last (optional) pipe
+ $row = substr($row, 1);
+ if ($row[strlen($row) - 1] == '|') {
+ $row = substr($row, 0, -1);
+ }
+
+ // cells are separated by pipes
+ $cells = explode("|", $row);
+
+ if (count($cells) == 1 && $cells[0][0] == '=' && ($num_rows == 1 || $num_rows == count($rows)) && ! isset($caption)) {
+ $caption = trim(trim($cells[0], '='));
+
+ // start the caption...
+ $return .= $this->wiki->addToken(
+ $this->rule,
+ array ('type' => 'caption_start')
+ );
+
+ // ...add the content...
+ $return .= $caption;
+
+ // ...and end the caption.
+ $return .= $this->wiki->addToken(
+ $this->rule,
+ array ('type' => 'caption_end')
+ );
+ }
+ else {
+
+ // update the column count
+ if (count($cells) > $num_cols) {
+ $num_cols = count($cells);
+ }
+
+ // start a new row
+ $return .= $this->wiki->addToken(
+ $this->rule,
+ array('type' => 'row_start')
+ );
+
+ for ($i = 0; $i < count($cells); $i++) {
+ $cell = $cells[$i];
+
+ // by default, cells span only one column (their own)
+ $span = 1;
+ $attr = '';
+
+ while ($i + 1 < count($cells) && ! strlen($cells[$i + 1])) {
+ $i++;
+ $span++;
+ }
+
+ if (strlen($cell) > 0 && $cell[0] == '=') {
+ $attr = 'header';
+ $cell = trim($cell, '=');
+ }
+
+ // start a new cell...
+ $return .= $this->wiki->addToken(
+ $this->rule,
+ array (
+ 'type' => 'cell_start',
+ 'attr' => $attr,
+ 'span' => $span
+ )
+ );
+
+ // ...add the content...
+ $return .= trim($cell);
+
+ // ...and end the cell.
+ $return .= $this->wiki->addToken(
+ $this->rule,
+ array (
+ 'type' => 'cell_end',
+ 'attr' => $attr,
+ 'span' => $span
+ )
+ );
+ }
+
+ // end the row
+ $return .= $this->wiki->addToken(
+ $this->rule,
+ array('type' => 'row_end')
+ );
+ }
+ }
+
+ // we're done!
+ return
+ "\n\n".
+ $this->wiki->addToken(
+ $this->rule,
+ array(
+ 'type' => 'table_start',
+ 'rows' => $num_rows,
+ 'cols' => $num_cols
+ )
+ ).
+ $return.
+ $this->wiki->addToken(
+ $this->rule,
+ array(
+ 'type' => 'table_end'
+ )
+ ).
+ "\n\n";
+ }
+}
+?> \ No newline at end of file
diff --git a/includes/pear/Text/Wiki/Parse/Creole/Tighten.php b/includes/pear/Text/Wiki/Parse/Creole/Tighten.php
new file mode 100644
index 0000000..8ef1b45
--- /dev/null
+++ b/includes/pear/Text/Wiki/Parse/Creole/Tighten.php
@@ -0,0 +1,37 @@
+<?php
+
+/**
+ *
+ * The rule removes all remaining newlines.
+ *
+ * @category Text
+ *
+ * @package Text_Wiki
+ *
+ * @author Paul M. Jones <pmjones@php.net>
+ *
+ * @license LGPL
+ *
+ * @version $Id: Tighten.php 222265 2006-10-23 13:11:27Z mic $
+ *
+ */
+
+
+class Text_Wiki_Parse_Tighten extends Text_Wiki_Parse {
+
+
+ /**
+ *
+ * Apply tightening directly to the source text.
+ *
+ * @access public
+ *
+ */
+
+ function parse()
+ {
+ $this->wiki->source = str_replace("\n", '',
+ $this->wiki->source);
+ }
+}
+?> \ No newline at end of file
diff --git a/includes/pear/Text/Wiki/Parse/Creole/Trim.php b/includes/pear/Text/Wiki/Parse/Creole/Trim.php
new file mode 100644
index 0000000..f10c9a2
--- /dev/null
+++ b/includes/pear/Text/Wiki/Parse/Creole/Trim.php
@@ -0,0 +1,75 @@
+<?php
+
+/**
+ *
+ * Trim lines in the source text and compress 3 or more newlines to
+ * 2 newlines.
+ *
+ * @category Text
+ *
+ * @package Text_Wiki
+ *
+ * @author Paul M. Jones <pmjones@php.net>
+ * @author Michele Tomaiuolo <tomamic@yahoo.it>
+ *
+ */
+
+class Text_Wiki_Parse_Trim extends Text_Wiki_Parse {
+
+
+ /**
+ *
+ * Simple parsing method.
+ *
+ * @access public
+ *
+ */
+
+ function parse()
+ {
+ // trim lines
+ $find = "/ *\n */";
+ $replace = "\n";
+ $this->wiki->source = preg_replace($find, $replace, $this->wiki->source);
+
+ // trim lines with only one dash or star
+ $find = "/\n[\-\*]\n/";
+ $replace = "\n\n";
+ $this->wiki->source = preg_replace($find, $replace, $this->wiki->source);
+
+ // finally, compress all instances of 3 or more newlines
+ // down to two newlines.
+ $find = "/\n{3,}/m";
+ $replace = "\n\n";
+ $this->wiki->source = preg_replace($find, $replace, $this->wiki->source);
+
+ // numbered lists
+ $find = "/(\n[\*\#]*)([\d]+[\.\)]|[\w]\)) /s";
+ $replace = "$1# ";
+ $this->wiki->source = preg_replace($find, $replace, $this->wiki->source);
+
+ // numbers in parentesis are footnotes and references
+ $find = "/\(([\d][\d]?)\)/";
+ $replace = "[$1]";
+ $this->wiki->source = preg_replace($find, $replace, $this->wiki->source);
+
+ // add hr before footnotes
+ $find = "/(\n+\-\-\-\-+\n*)?(\n\[[\d]+\].*)/s";
+ $replace = "\n\n----\n\n$2";
+ $this->wiki->source = preg_replace($find, $replace, $this->wiki->source);
+
+ /*
+ // wrap images in tables
+ $find = "/(?<=\n\n){{([^\|}]*)\|([^}]*)}}(?=\n\n)/";
+ $replace = "| {{ $1 | $2 }}\n|= $2";
+ $this->wiki->source = preg_replace($find, $replace, $this->wiki->source);
+
+ // wrap images in tables
+ $find = "/(?<=\n\n){{([^\|}]*)}}(?=\n\n)/";
+ $replace = "| {{ $1 }}";
+ $this->wiki->source = preg_replace($find, $replace, $this->wiki->source);
+ */
+ }
+
+}
+?> \ No newline at end of file
diff --git a/includes/pear/Text/Wiki/Parse/Creole/Tt.php b/includes/pear/Text/Wiki/Parse/Creole/Tt.php
new file mode 100644
index 0000000..31072bc
--- /dev/null
+++ b/includes/pear/Text/Wiki/Parse/Creole/Tt.php
@@ -0,0 +1,78 @@
+<?php
+
+/**
+ *
+ * Parses for monospaced inline text.
+ *
+ * @category Text
+ *
+ * @package Text_Wiki
+ *
+ * @author Tomaiuolo Michele <tomamic@yahoo.it>
+ *
+ * @license LGPL
+ *
+ * @version $Id: Tt.php 240474 2007-07-30 13:14:41Z mic $
+ *
+ */
+
+class Text_Wiki_Parse_Tt extends Text_Wiki_Parse {
+
+
+ /**
+ *
+ * The regular expression used to parse the source text and find
+ * matches conforming to this rule. Used by the parse() method.
+ *
+ * @access public
+ *
+ * @var string
+ *
+ * @see parse()
+ *
+ */
+
+ var $regex = '/{{{(.*?)}}}(?!}|{{{)/';
+
+ /**
+ *
+ * Generates a replacement for the matched text. Token options are:
+ *
+ * 'type' => ['start'|'end'] The starting or ending point of the
+ * monospaced text. The text itself is encapsulated into a Raw token.
+ *
+ * @access public
+ *
+ * @param array &$matches The array of matches from parse().
+ *
+ * @return string A token to be used as a placeholder
+ * in the source text for the preformatted text.
+ *
+ */
+
+ function process(&$matches)
+ {
+ // remove the sequence }}}{{{
+ $find = "/}}}{{{/";
+ $replace = "";
+ $matches[1] = preg_replace($find, $replace, $matches[1]);
+
+ $start = $this->wiki->addToken(
+ $this->rule,
+ array('type' => 'start')
+ );
+
+ $raw = $this->wiki->addToken(
+ 'Raw',
+ array('text' => $matches[1])
+ );
+
+ $end = $this->wiki->addToken(
+ $this->rule,
+ array('type' => 'end')
+ );
+
+ return $start . $raw . $end;
+ }
+}
+?>
diff --git a/includes/pear/Text/Wiki/Parse/Creole/Underline.php b/includes/pear/Text/Wiki/Parse/Creole/Underline.php
new file mode 100644
index 0000000..c3d5b14
--- /dev/null
+++ b/includes/pear/Text/Wiki/Parse/Creole/Underline.php
@@ -0,0 +1,83 @@
+<?php
+
+/**
+ *
+ * Parses for italic text.
+ *
+ * This class implements a Text_Wiki_Parse to find source text marked for
+ * underlined as defined by text surrounded by two '_'.
+ * On parsing, the text itself is left in place, but the starting and ending
+ * instances of two '^' are replaced with tokens.
+ *
+ * @category Text
+ *
+ * @package Text_Wiki
+ *
+ * @author Paul M. Jones <pmjones@php.net>
+ * @author Michele Tomaiuolo <tomamic@yahoo.it>
+ *
+ * @license LGPL
+ *
+ * @version $Id: Underline.php 242127 2007-09-03 21:29:36Z mic $
+ *
+ */
+
+class Text_Wiki_Parse_Underline extends Text_Wiki_Parse {
+
+
+ /**
+ *
+ * The regular expression used to parse the source text and find
+ * matches conforming to this rule. Used by the parse() method.
+ *
+ * @access public
+ *
+ * @var string
+ *
+ * @see parse()
+ *
+ */
+
+ var $regex = "/__(.+?)__/";
+ //var $regex = "/(?:\_\_(.+?)\_\_|(?:(?<=[\W_\xFF])\_(?![ \_]))(.+?)(?:(?<![ \_])\_(?=[\W_\xFF])))/";
+
+ /**
+ *
+ * Generates a replacement for the matched text. Token options are:
+ *
+ * 'type' => ['start'|'end'] The starting or ending point of the
+ * superscript text. The text itself is left in the source.
+ *
+ * @access public
+ *
+ * @param array &$matches The array of matches from parse().
+ *
+ * @return string A pair of delimited tokens to be used as a
+ * placeholder in the source text surrounding the text to be
+ * superscripted.
+ *
+ */
+
+ function process(&$matches)
+ {
+ $text = $matches[1];
+ //$text = $matches[1] ? $matches[1] : $matches[2];
+
+ if (! $this->wiki->checkInnerTags($text)) {
+ return $matches[0];
+ }
+
+ $start = $this->wiki->addToken(
+ $this->rule,
+ array('type' => 'start')
+ );
+
+ $end = $this->wiki->addToken(
+ $this->rule,
+ array('type' => 'end')
+ );
+
+ return $start . $text . $end;
+ }
+}
+?> \ No newline at end of file
diff --git a/includes/pear/Text/Wiki/Parse/Creole/Url.php b/includes/pear/Text/Wiki/Parse/Creole/Url.php
new file mode 100644
index 0000000..4422a31
--- /dev/null
+++ b/includes/pear/Text/Wiki/Parse/Creole/Url.php
@@ -0,0 +1,109 @@
+<?php
+
+/**
+ *
+ * Parse for URLS in the source text.
+ *
+ * raw -- http://example.com
+ * no descr. -- [[http://example.com]]
+ * described -- [[http://example.com|Example Description]]
+ *
+ * When rendering a URL token, this will convert URLs pointing to a .gif,
+ * .jpg, or .png image into an inline <img /> tag (for the 'xhtml'
+ * format).
+ *
+ * @category Text
+ *
+ * @package Text_Wiki
+ *
+ * @author Michele Tomaiuolo <tomamic@yahoo.it>
+ *
+ * @license LGPL
+ *
+ * @version $Id: Url.php 293784 2010-01-20 18:48:09Z justinpatrin $
+ *
+ */
+
+class Text_Wiki_Parse_Url extends Text_Wiki_Parse {
+
+ /**
+ *
+ * Constructor. Overrides the Text_Wiki_Parse constructor so that we
+ * can set the $regex property dynamically (we need to include the
+ * Text_Wiki $delim character).
+ *
+ * @param object &$obj The calling "parent" Text_Wiki object.
+ *
+ * @param string $name The token name to use for this rule.
+ *
+ */
+
+ function Text_Wiki_Parse_Url(&$obj)
+ {
+ parent::Text_Wiki_Parse($obj);
+ $this->regex = '/((?:\[\[ *((?:\w+:\/\/|mailto:|\/)[^\|\]\n ]*)( *\| *([^\]\n]*))? *\]\])|((?<=[^\~\w])(https?:\/\/|ftps?:\/\/|mailto:)[^\'\"\n ' . $this->wiki->delim . ']*[A-Za-z0-9\/\?\=\&\~\_#]))/';
+ }
+
+
+ /**
+ *
+ * Generates a replacement for the matched text.
+ *
+ * Token options are:
+ *
+ * 'href' => the URL link href portion
+ *
+ * 'text' => the displayed text of the URL link
+ *
+ * @access public
+ *
+ * @param array &$matches The array of matches from parse().
+ *
+ * @return string A token to be used as a placeholder
+ * in the source text for the preformatted text.
+ *
+ */
+
+ function process(&$matches)
+ {
+ if (isset($matches[2])) $href = trim($matches[2]);
+ if (isset($matches[4])) $text = trim($matches[4]);
+ if (isset($matches[5])) $rawurl = $matches[5];
+ if (empty($href)) $href = $rawurl;
+
+ if (empty($text)) {
+ $text = $href;
+ if (strpos($text, '/') === FALSE) {
+ $text = str_replace('http://', '', $text);
+ $text = str_replace('mailto:', '', $text);
+ }
+ return $this->wiki->addToken(
+ $this->rule,
+ array(
+ 'type' => 'inline',
+ 'href' => $href,
+ 'text' => $text
+ )
+ );
+ } else {
+ return $this->wiki->addToken(
+ $this->rule,
+ array(
+ 'type' => 'start',
+ 'href' => $href,
+ 'text' => $text
+ )
+ ) . $text .
+ $this->wiki->addToken(
+ $this->rule,
+ array(
+ 'type' => 'end',
+ 'href' => $href,
+ 'text' => $text
+ )
+ );
+ }
+ }
+
+}
+?> \ No newline at end of file
diff --git a/includes/pear/Text/Wiki/Parse/Creole/Wikilink.php b/includes/pear/Text/Wiki/Parse/Creole/Wikilink.php
new file mode 100644
index 0000000..19cafc1
--- /dev/null
+++ b/includes/pear/Text/Wiki/Parse/Creole/Wikilink.php
@@ -0,0 +1,322 @@
+<?php
+
+/**
+ * Mediawiki: Parses for links to (inter)wiki pages or images.
+ *
+ * Text_Wiki rule parser to find links, it groups the 3 rules:
+ * # Wikilink: links to internal Wiki pages
+ * # Interwiki: links to external Wiki pages (sister projects, interlangage)
+ * # Image: Images
+ * as defined by text surrounded by double brackets [[]]
+ * Translated are the link itself, the section (anchor) and alternate text
+ *
+ * PHP versions 4 and 5
+ *
+ * @category Text
+ * @package Text_Wiki
+ * @author Bertrand Gugger <bertrand@toggg.com>
+ * @author Paul M. Jones <pmjones@php.net>
+ * @copyright 2005 bertrand Gugger
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version CVS: $Id: Wikilink.php 240474 2007-07-30 13:14:41Z mic $
+ * @link http://pear.php.net/package/Text_Wiki
+ */
+
+/**
+ * Wikilink, Interwiki and Image rules parser class for Mediawiki.
+ * This class implements a Text_Wiki_Parse to find links marked
+ * in source by text surrounded by 2 opening/closing brackets as
+ * [[Wiki page name#Section|Alternate text]]
+ * On parsing, the link is replaced with a token.
+ *
+ * @category Text
+ * @package Text_Wiki
+ * @author Bertrand Gugger <bertrand@toggg.com>
+ * @copyright 2005 bertrand Gugger
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: @package_version@
+ * @link http://pear.php.net/package/Text_Wiki
+ * @see Text_Wiki_Parse::Text_Wiki_Parse()
+ */
+
+class Text_Wiki_Parse_Wikilink extends Text_Wiki_Parse {
+
+ /**
+ * Configuration for this rule (Wikilink)
+ *
+ * @access public
+ * @var array
+ */
+
+ var $conf = array(
+ 'spaceUnderscore' => true,
+ 'project' => array('demo', 'd'),
+ 'url' => 'http://example.com/en/page=%s',
+ 'langage' => 'en'
+ );
+
+ /**
+ * Configuration for the Image rule
+ *
+ * @access public
+ * @var array
+ */
+
+ var $imageConf = array(
+ 'prefix' => array('Image', 'image')
+ );
+
+ /**
+ * Configuration for the Interwiki rule
+ *
+ * @access public
+ * @var array
+ */
+
+ var $interwikiConf = array(
+ 'sites' => array(
+ 'manual' => 'http://www.php.net/manual/en/%s',
+ 'pear' => 'http://pear.php.net/package/%s',
+ 'bugs' => 'http://pear.php.net/package/%s/bugs'
+ ),
+ 'interlangage' => array('en', 'de', 'fr')
+ );
+
+ /**
+ * The regular expression used to parse the source text and find
+ * matches conforming to this rule. Used by the parse() method.
+ *
+ * @access public
+ * @var string
+ * @see Text_Wiki_Parse::parse()
+ */
+
+ var $regex = '/(?<!\[)\[\[(?!\[) *(:?)((?:[^:\n]+:)+)?([^:\n]+)(#(?:[^\n]*))?(?: *\| *(((?R))|[^\n]*))? *]]/msU';
+
+ /**
+ * Constructor.
+ * We override the constructor to get Image and Interwiki config
+ *
+ * @param object &$obj the base conversion handler
+ * @return The parser object
+ * @access public
+ */
+
+ function Text_Wiki_Parse_Wikilink(&$obj)
+ {
+ $default = $this->conf;
+ parent::Text_Wiki_Parse($obj);
+
+ // override config options for image if specified
+ if (in_array('Image', $this->wiki->disable)) {
+ $this->imageConf['prefix'] = array();
+ } else {
+ if (isset($this->wiki->parseConf['Image']) &&
+ is_array($this->wiki->parseConf['Image'])) {
+ $this->imageConf = array_merge(
+ $this->imageConf,
+ $this->wiki->parseConf['Image']
+ );
+ }
+ }
+
+ // override config options for interwiki if specified
+ if (in_array('Interwiki', $this->wiki->disable)) {
+ $this->interwikiConf['sites'] = array();
+ $this->interwikiConf['interlangage'] = array();
+ } else {
+ if (isset($this->wiki->parseConf['Interwiki']) &&
+ is_array($this->wiki->parseConf['Interwiki'])) {
+ $this->interwikiConf = array_merge(
+ $this->interwikiConf,
+ $this->wiki->parseConf['Interwiki']
+ );
+ }
+ if (empty($this->conf['langage'])) {
+ $this->interwikiConf['interlangage'] = array();
+ }
+ }
+ //$this->regex = str_replace('DELIM', $this->wiki->delim, $this->regex);
+ // convert the list of recognized schemes to a regex OR,
+/* $schemes = $this->getConf('schemes', $default['schemes']);
+ $this->url = str_replace( '#delim#', $this->wiki->delim,
+ '#(?:' . (is_array($schemes) ? implode('|', $schemes) : $schemes) . ')://'
+ . $this->getConf('host_regexp', $default['host_regexp'])
+ . $this->getConf('path_regexp', $default['path_regexp']) .'#'); */
+ }
+
+ /**
+ * Generates a replacement for the matched text. Token options are:
+ * - 'page' => the name of the target wiki page
+ * -'anchor' => the optional section in it
+ * - 'text' => the optional alternate link text
+ *
+ * @access public
+ * @param array &$matches The array of matches from parse().
+ * @return string token to be used as replacement
+ */
+
+ function process(&$matches)
+ {
+ $matches[3] = $this->wiki->restoreRaw($matches[3]);
+
+ // Starting colon ?
+ $colon = !empty($matches[1]);
+ $auto = $interlang = $interwiki = $image = $site = '';
+ // Prefix ?
+ if (!empty($matches[2])) {
+ $prefix = explode(':', substr($matches[2], 0, -1));
+ $count = count($prefix);
+ $i = -1;
+ // Autolink
+ if (isset($this->conf['project']) &&
+ in_array(trim($prefix[0]), $this->conf['project'])) {
+ $auto = trim($prefix[0]);
+ unset($prefix[0]);
+ $i = 0;
+ }
+ while (++$i < $count) {
+ $prefix[$i] = trim($prefix[$i]);
+ // interlangage
+ if (!$interlang &&
+ in_array($prefix[$i], $this->interwikiConf['interlangage'])) {
+ $interlang = $prefix[$i];
+ unset($prefix[$i]);
+ continue;
+ }
+ // image
+ if (!$image && in_array($prefix[$i], $this->imageConf['prefix'])) {
+ $image = $prefix[$i];
+ unset($prefix[$i]);
+ break;
+ }
+ // interwiki
+ if (isset($this->interwikiConf['sites'][$prefix[$i]])) {
+ $interwiki = $this->interwikiConf['sites'][$prefix[$i]];
+ $site = $prefix[$i];
+ unset($prefix[$i]);
+ }
+ break;
+ }
+ if ($prefix) {
+ $matches[3] = implode(':', $prefix) . ':' . $matches[3];
+ }
+ }
+ $text = empty($matches[5]) ? $matches[3] : $matches[5];
+ $matches[3] = trim($matches[3]);
+ $matches[4] = empty($matches[4]) ? '' : trim($matches[4]);
+ if ($this->conf['spaceUnderscore']) {
+ $matches[3] = preg_replace('/\s+/', '_', $matches[3]);
+ $matches[4] = preg_replace('/\s+/', '_', $matches[4]);
+ }
+ if ($image) {
+ return $this->image($matches[3] . (empty($matches[4]) ? '' : '#' . $matches[4]),
+ $text, $interlang, $colon);
+ }
+ if (!$interwiki && $interlang && isset($this->conf['url'])) {
+ if ($interlang == $this->conf['langage']) {
+ $interlang = '';
+ } else {
+ $interwiki = $this->conf['url'];
+ $site = isset($this->conf['project']) ? $this->conf['project'][0] : '';
+ }
+ }
+ if ($interwiki) {
+ return $this->interwiki($site, $interwiki,
+ $matches[3] . (empty($matches[4]) ? '' : '#' . $matches[4]),
+ $text, $interlang, $colon);
+ }
+ if ($interlang) {
+ $matches[3] = $interlang . ':' . $matches[3];
+ $text = (empty($matches[5]) ? $interlang . ':' : '') . $text;
+ }
+
+ $start = $this->wiki->addToken($this->rule, array(
+ 'type' => 'start',
+ 'page' => $matches[3],
+ 'anchor' => (empty($matches[4]) ? '' : $matches[4]),
+ 'text' => $text
+ ));
+
+ $end = $this->wiki->addToken($this->rule, array(
+ 'type' => 'end',
+ 'page' => $matches[3],
+ 'anchor' => (empty($matches[4]) ? '' : $matches[4]),
+ 'text' => $text
+ ));
+
+ // create and return the replacement token
+ return $start . $text . $end;
+ }
+
+ /**
+ * Generates an image token. Token options are:
+ * - 'src' => the name of the image file
+ * - 'attr' => an array of attributes for the image:
+ * | - 'alt' => the optional alternate image text
+ * | - 'align => 'left', 'center' or 'right'
+ *
+ * @access public
+ * @param array &$matches The array of matches from parse().
+ * @return string token to be used as replacement
+ */
+
+ function image($name, $text, $interlang, $colon)
+ {
+ $attr = array('alt' => '');
+ // scan text for supplementary attibutes
+ if (strpos($text, '|') !== false) {
+ $splits = explode('|', $text);
+ $sep = '';
+ foreach ($splits as $split) {
+ switch (strtolower($split)) {
+ case 'left': case 'center': case 'right':
+ $attr['align'] = strtolower($split);
+ break;
+ default:
+ $attr['alt'] .= $sep . $split;
+ $sep = '|';
+ }
+ }
+ } else {
+ $attr['alt'] = $text;
+ }
+ $options = array(
+ 'src' => ($interlang ? $interlang . ':' : '') . $name,
+ 'attr' => $attr);
+
+ // create and return the replacement token
+ return $this->wiki->addToken('Image', $options);
+ }
+
+ /**
+ * Generates an interwiki token. Token options are:
+ * - 'page' => the name of the target wiki page
+ * - 'site' => the key for external site
+ * - 'url' => the full target url
+ * - 'text' => the optional alternate link text
+ *
+ * @access public
+ * @param array &$matches The array of matches from parse().
+ * @return string token to be used as replacement
+ */
+
+ function interwiki($site, $interwiki, $page, $text, $interlang, $colon)
+ {
+ if ($interlang) {
+ $interwiki = preg_replace('/\b' . $this->conf['langage'] . '\b/i',
+ $interlang, $interwiki);
+ }
+ // set the options
+ $options = array(
+ 'page' => $page,
+ 'site' => $site,
+ 'url' => sprintf($interwiki, $page),
+ 'text' => $text
+ );
+
+ // create and return the replacement token
+ return $this->wiki->addToken('Interwiki', $options);
+ }
+}
+?>