]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/InlineParser.php
require_once fix for those libs which are loaded before FileFinder and
[SourceForge/phpwiki.git] / lib / InlineParser.php
1 <?php 
2 rcs_id('$Id: InlineParser.php,v 1.50 2004-05-12 10:49:54 rurban Exp $');
3 /* Copyright (C) 2002 Geoffrey T. Dairiki <dairiki@dairiki.org>
4  * Copyright (C) 2004 Reini Urban
5  *
6  * This file is part of PhpWiki.
7  * 
8  * PhpWiki is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  * 
13  * PhpWiki is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  * 
18  * You should have received a copy of the GNU General Public License
19  * along with PhpWiki; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22 /**
23  * This is the code which deals with the inline part of the (new-style)
24  * wiki-markup.
25  *
26  * @package Markup
27  * @author Geoffrey T. Dairiki
28  */
29 /**
30  */
31
32 /**
33  * This is the character used in wiki markup to escape characters with
34  * special meaning.
35  */
36 define('ESCAPE_CHAR', '~');
37
38 require_once(dirname(__FILE__).'/HtmlElement.php');
39 require_once('lib/CachedMarkup.php');
40 require_once(dirname(__FILE__).'/stdlib.php');
41
42
43 function WikiEscape($text) {
44     return str_replace('#', ESCAPE_CHAR . '#', $text);
45 }
46
47 function UnWikiEscape($text) {
48     return preg_replace('/' . ESCAPE_CHAR . '(.)/', '\1', $text);
49 }
50
51 /**
52  * Return type from RegexpSet::match and RegexpSet::nextMatch.
53  *
54  * @see RegexpSet
55  */
56 class RegexpSet_match {
57     /**
58      * The text leading up the the next match.
59      */
60     var $prematch;
61     /**
62      * The matched text.
63      */
64     var $match;
65     /**
66      * The text following the matched text.
67      */
68     var $postmatch;
69     /**
70      * Index of the regular expression which matched.
71      */
72     var $regexp_ind;
73 }
74
75 /**
76  * A set of regular expressions.
77  *
78  * This class is probably only useful for InlineTransformer.
79  */
80 class RegexpSet
81 {
82     /** Constructor
83      *
84      * @param array $regexps A list of regular expressions.  The
85      * regular expressions should not include any sub-pattern groups
86      * "(...)".  (Anonymous groups, like "(?:...)", as well as
87      * look-ahead and look-behind assertions are okay.)
88      */
89     function RegexpSet ($regexps) {
90         assert($regexps);
91         $this->_regexps = array_unique($regexps);
92     }
93
94     /**
95      * Search text for the next matching regexp from the Regexp Set.
96      *
97      * @param string $text The text to search.
98      *
99      * @return RegexpSet_match  A RegexpSet_match object, or false if no match.
100      */
101     function match ($text) {
102         return $this->_match($text, $this->_regexps, '*?');
103     }
104
105     /**
106      * Search for next matching regexp.
107      *
108      * Here, 'next' has two meanings:
109      *
110      * Match the next regexp(s) in the set, at the same position as the last match.
111      *
112      * If that fails, match the whole RegexpSet, starting after the position of the
113      * previous match.
114      *
115      * @param string $text Text to search.
116      *
117      * @param RegexpSet_match $prevMatch A RegexpSet_match object.
118      * $prevMatch should be a match object obtained by a previous
119      * match upon the same value of $text.
120      *
121      * @return RegexpSet_match A RegexpSet_match object, or false if no match.
122      */
123     function nextMatch ($text, $prevMatch) {
124         // Try to find match at same position.
125         $pos = strlen($prevMatch->prematch);
126         $regexps = array_slice($this->_regexps, $prevMatch->regexp_ind + 1);
127         if ($regexps) {
128             $repeat = sprintf('{%d}', $pos);
129             if ( ($match = $this->_match($text, $regexps, $repeat)) ) {
130                 $match->regexp_ind += $prevMatch->regexp_ind + 1;
131                 return $match;
132             }
133             
134         }
135         
136         // Failed.  Look for match after current position.
137         $repeat = sprintf('{%d,}?', $pos + 1);
138         return $this->_match($text, $this->_regexps, $repeat);
139     }
140     
141
142     function _match ($text, $regexps, $repeat) {
143         // If one of the regexps is an empty string, php will crash here: 
144         // sf.net: Fatal error: Allowed memory size of 8388608 bytes exhausted 
145         //         (tried to allocate 634 bytes)
146
147         // So we try to minize memory usage, by looping explicitly,
148         // and storing only those regexp which actually match. 
149         // There may be more than one, so we have to find the longest, 
150         // and match inside until the shortest is empty.
151         $matched = array(); $matched_ind = array();
152         for ($i=0; $i<count($regexps); $i++) {
153             if (!trim($regexps[$i])) {
154                 trigger_error("empty regexp $i",E_USER_WARNING);
155                 continue;
156             }
157             $pat= "/ ( . $repeat ) ( " . $regexps[$i] . " ) /x";
158             if (preg_match($pat, $text, $_m)) {
159                 $m = $_m;
160                 $matched[] = $regexps[$i];
161                 $matched_ind[] = $i;
162                 $regexp_ind = $i;
163             }
164         }
165         // To overcome ANCHORED:
166         // We could sort by longest match and iterate over these.
167         if (empty($matched)) return false;
168         $match = new RegexpSet_match;
169         
170         // Optimization: if the matches are only "$" and another, then omit "$"
171         // Syntax: http://www.pcre.org/pcre.txt
172         //   x - EXTENDED, ignore whitespace
173         //   s - DOTALL
174         //   A - ANCHORED
175         //   S - STUDY
176         if (count($matched) > 2) {
177             // We could do much better, if we would know the matching markup for the 
178             // longest regexp match:
179             $hugepat= "/ ( . $repeat ) ( (" . join(')|(', $regexps) . ") ) /Asx";
180             // Proposed premature optimization 1:
181             //$hugepat= "/ ( . $repeat ) ( (" . join(')|(', array_values($matched)) . ") ) /Asx";
182             if (! preg_match($hugepat, $text, $m)) {
183                 return false;
184             }
185             // Proposed premature optimization 1:
186             //$match->regexp_ind = $matched_ind[count($m) - 4];
187             $match->regexp_ind = count($m) - 4;
188         } else {
189             $match->regexp_ind = $regexp_ind;
190         }
191         
192         $match->postmatch = substr($text, strlen($m[0]));
193         $match->prematch = $m[1];
194         $match->match = $m[2];
195
196         /* DEBUGGING */
197         /*
198         if (DEBUG == 4) {
199           var_dump($regexps); var_dump($matched); var_dump($matched_inc); 
200         PrintXML(HTML::dl(HTML::dt("input"),
201                           HTML::dd(HTML::pre($text)),
202                           HTML::dt("regexp"),
203                           HTML::dd(HTML::pre($match->regexp_ind, ":", $regexps[$match->regexp_ind])),
204                           HTML::dt("prematch"),
205                           HTML::dd(HTML::pre($match->prematch)),
206                           HTML::dt("match"),
207                           HTML::dd(HTML::pre($match->match)),
208                           HTML::dt("postmatch"),
209                           HTML::dd(HTML::pre($match->postmatch))
210                           ));
211         }
212         */
213         return $match;
214     }
215 }
216
217
218
219 /**
220  * A simple markup rule (i.e. terminal token).
221  *
222  * These are defined by a regexp.
223  *
224  * When a match is found for the regexp, the matching text is replaced.
225  * The replacement content is obtained by calling the SimpleMarkup::markup method.
226  */ 
227 class SimpleMarkup
228 {
229     var $_match_regexp;
230
231     /** Get regexp.
232      *
233      * @return string Regexp which matches this token.
234      */
235     function getMatchRegexp () {
236         return $this->_match_regexp;
237     }
238
239     /** Markup matching text.
240      *
241      * @param string $match The text which matched the regexp
242      * (obtained from getMatchRegexp).
243      *
244      * @return mixed The expansion of the matched text.
245      */
246     function markup ($match /*, $body */) {
247         trigger_error("pure virtual", E_USER_ERROR);
248     }
249 }
250
251 /**
252  * A balanced markup rule.
253  *
254  * These are defined by a start regexp, and an end regexp.
255  */ 
256 class BalancedMarkup
257 {
258     var $_start_regexp;
259
260     /** Get the starting regexp for this rule.
261      *
262      * @return string The starting regexp.
263      */
264     function getStartRegexp () {
265         return $this->_start_regexp;
266     }
267     
268     /** Get the ending regexp for this rule.
269      *
270      * @param string $match The text which matched the starting regexp.
271      *
272      * @return string The ending regexp.
273      */
274     function getEndRegexp ($match) {
275         return $this->_end_regexp;
276     }
277
278     /** Get expansion for matching input.
279      *
280      * @param string $match The text which matched the starting regexp.
281      *
282      * @param mixed $body Transformed text found between the starting
283      * and ending regexps.
284      *
285      * @return mixed The expansion of the matched text.
286      */
287     function markup ($match, $body) {
288         trigger_error("pure virtual", E_USER_ERROR);
289     }
290 }
291
292 class Markup_escape  extends SimpleMarkup
293 {
294     function getMatchRegexp () {
295         return ESCAPE_CHAR . '(?: [[:alnum:]]+ | .)';
296     }
297     
298     function markup ($match) {
299         assert(strlen($match) >= 2);
300         return substr($match, 1);
301     }
302 }
303
304 /**
305  * [image.jpg size=50% border=5], [image.jpg size=50x30]
306  * Support for the following attributes: see stdlib.php:LinkImage()
307  *   size=<precent>%, size=<width>x<height>
308  *   border=n, align=\w+, hspace=n, vspace=n
309  */
310 function isImageLink($link) {
311     if (!$link) return false;
312     return preg_match("/\\.(" . INLINE_IMAGES . ")$/i", $link)
313         or preg_match("/\\.(" . INLINE_IMAGES . ")\s+(size|border|align|hspace|vspace)=/i", $link);
314 }
315
316 function LinkBracketLink($bracketlink) {
317
318     // $bracketlink will start and end with brackets; in between will
319     // be either a page name, a URL or both separated by a pipe.
320     
321     // strip brackets and leading space
322     preg_match('/(\#?) \[\s* (?: (.*?) \s* (?<!' . ESCAPE_CHAR . ')(\|) )? \s* (.+?) \s*\]/x',
323                $bracketlink, $matches);
324     list (, $hash, $label, $bar, $rawlink) = $matches;
325
326     $label = UnWikiEscape($label);
327     /*
328      * Check if the user has typed a explicit URL. This solves the
329      * problem where the URLs have a ~ character, which would be stripped away.
330      *   "[http:/server/~name/]" will work as expected
331      *   "http:/server/~name/"   will NOT work as expected, will remove the ~
332      */
333     if (strstr($rawlink, "http://") or strstr($rawlink, "https://"))
334         $link = $rawlink;
335     else
336         $link  = UnWikiEscape($rawlink);
337
338     // [label|link]
339     // if label looks like a url to an image, we want an image link.
340     if (isImageLink($label)) {
341         $imgurl = $label;
342         if (preg_match("/^" . $intermap->getRegexp() . ":/", $label)) {
343             $imgurl = $intermap->link($label);
344             $imgurl = $imgurl->getAttr('href');
345         } elseif (! preg_match("#^(" . ALLOWED_PROTOCOLS . "):#", $imgurl)) {
346             // local theme linkname like 'images/next.gif'.
347             global $Theme;
348             $imgurl = $Theme->getImageURL($imgurl);
349         }
350         $label = LinkImage($imgurl, $link);
351     }
352
353     if ($hash) {
354         // It's an anchor, not a link...
355         $id = MangleXmlIdentifier($link);
356         return HTML::a(array('name' => $id, 'id' => $id),
357                        $bar ? $label : $link);
358     }
359
360     if (preg_match("#^(" . ALLOWED_PROTOCOLS . "):#", $link)) {
361         // if it's an image, embed it; otherwise, it's a regular link
362         if (isImageLink($link))
363             return LinkImage($link, $label);
364         else
365             return new Cached_ExternalLink($link, $label);
366     }
367     elseif (preg_match("/^phpwiki:/", $link))
368         return new Cached_PhpwikiURL($link, $label);
369     /*
370      * Inline images in Interwiki urls's:
371      * [File:my_image.gif] inlines the image,
372      * File:my_image.gif shows a plain inter-wiki link,
373      * [what a pic|File:my_image.gif] shows a named inter-wiki link to the gif
374      * [File:my_image.gif|what a pic] shows a inlimed image linked to the page "what a pic"
375      */
376     elseif (strstr($link,':') and 
377             ($intermap = getInterwikiMap()) and 
378             preg_match("/^" . $intermap->getRegexp() . ":/", $link)) {
379         if (empty($label) && isImageLink($link)) {
380             // if without label => inlined image [File:xx.gif]
381             $imgurl = $intermap->link($link);
382             return LinkImage($imgurl->getAttr('href'), $label);
383         }
384         return new Cached_InterwikiLink($link, $label);
385     } else {
386         // Split anchor off end of pagename.
387         if (preg_match('/\A(.*)(?<!'.ESCAPE_CHAR.')#(.*?)\Z/', $rawlink, $m)) {
388             list(,$rawlink,$anchor) = $m;
389             $pagename = UnWikiEscape($rawlink);
390             $anchor = UnWikiEscape($anchor);
391             if (!$label)
392                 $label = $link;
393         }
394         else {
395             $pagename = $link;
396             $anchor = false;
397         }
398         return new Cached_WikiLink($pagename, $label, $anchor);
399     }
400 }
401
402 class Markup_bracketlink  extends SimpleMarkup
403 {
404     var $_match_regexp = "\\#? \\[ .*? [^]\\s] .*? \\]";
405     
406     function markup ($match) {
407         $link = LinkBracketLink($match);
408         assert($link->isInlineElement());
409         return $link;
410     }
411 }
412
413 class Markup_url extends SimpleMarkup
414 {
415     function getMatchRegexp () {
416         return "(?<![[:alnum:]]) (?:" . ALLOWED_PROTOCOLS . ") : [^\s<>\"']+ (?<![ ,.?; \] \) ])";
417     }
418     
419     function markup ($match) {
420         return new Cached_ExternalLink(UnWikiEscape($match));
421     }
422 }
423
424
425 class Markup_interwiki extends SimpleMarkup
426 {
427     function getMatchRegexp () {
428         global $request;
429         $map = getInterwikiMap();
430         return "(?<! [[:alnum:]])" . $map->getRegexp(). ": \S+ (?<![ ,.?;! \] \) \" \' ])";
431     }
432
433     function markup ($match) {
434         //$map = getInterwikiMap();
435         return new Cached_InterwikiLink(UnWikiEscape($match));
436     }
437 }
438
439 class Markup_wikiword extends SimpleMarkup
440 {
441     function getMatchRegexp () {
442         global $WikiNameRegexp;
443         if (!trim($WikiNameRegexp)) return " " . WIKI_NAME_REGEXP;
444         return " $WikiNameRegexp";
445     }
446
447     function markup ($match) {
448         if (!$match) return false;
449         if ($this->_isWikiUserPage($match))
450             return new Cached_UserLink($match); //$this->_UserLink($match);
451         else
452             return new Cached_WikiLink($match);
453     }
454
455     // FIXME: there's probably a more useful place to put these two functions    
456     function _isWikiUserPage ($page) {
457         global $request;
458         $dbi = $request->getDbh();
459         $page_handle = $dbi->getPage($page);
460         if ($page_handle and $page_handle->get('pref'))
461             return true;
462         else
463             return false;
464     }
465
466     function _UserLink($PageName) {
467         $link = HTML::a(array('href' => $PageName));
468         $link->pushContent(PossiblyGlueIconToText('wikiuser', $PageName));
469         $link->setAttr('class', 'wikiuser');
470         return $link;
471     }
472 }
473
474 class Markup_linebreak extends SimpleMarkup
475 {
476     //var $_match_regexp = "(?: (?<! %) %%% (?! %) | <(?:br|BR)> | <(?:br|BR) \/> )";
477     var $_match_regexp = "(?: (?<! %) %%% (?! %) | <(?:br|BR)> )";
478
479     function markup ($match) {
480         return HTML::br();
481     }
482 }
483
484 class Markup_old_emphasis  extends BalancedMarkup
485 {
486     var $_start_regexp = "''|__";
487
488     function getEndRegexp ($match) {
489         return $match;
490     }
491     
492     function markup ($match, $body) {
493         $tag = $match == "''" ? 'em' : 'strong';
494         return new HtmlElement($tag, $body);
495     }
496 }
497
498 class Markup_nestled_emphasis extends BalancedMarkup
499 {
500     function getStartRegexp() {
501         static $start_regexp = false;
502
503         if (!$start_regexp) {
504             // The three possible delimiters
505             // (none of which can be followed by itself.)
506             $i = "_ (?! _)";
507             $b = "\\* (?! \\*)";
508             $tt = "= (?! =)";
509
510             $any = "(?: ${i}|${b}|${tt})"; // any of the three.
511
512             // Any of [_*=] is okay if preceded by space or one of [-"'/:]
513             $start[] = "(?<= \\s|^|[-\"'\\/:]) ${any}";
514
515             // _ or * is okay after = as long as not immediately followed by =
516             $start[] = "(?<= =) (?: ${i}|${b}) (?! =)";
517             // etc...
518             $start[] = "(?<= _) (?: ${b}|${tt}) (?! _)";
519             $start[] = "(?<= \\*) (?: ${i}|${tt}) (?! \\*)";
520
521
522             // any delimiter okay after an opening brace ( [{<(] )
523             // as long as it's not immediately followed by the matching closing
524             // brace.
525             $start[] = "(?<= { ) ${any} (?! } )";
526             $start[] = "(?<= < ) ${any} (?! > )";
527             $start[] = "(?<= \\( ) ${any} (?! \\) )";
528             
529             $start = "(?:" . join('|', $start) . ")";
530             
531             // Any of the above must be immediately followed by non-whitespace.
532             $start_regexp = $start . "(?= \S)";
533         }
534
535         return $start_regexp;
536     }
537
538     function getEndRegexp ($match) {
539         $chr = preg_quote($match);
540         return "(?<= \S | ^ ) (?<! $chr) $chr (?! $chr) (?= \s | [-)}>\"'\\/:.,;!? _*=] | $)";
541     }
542     
543     function markup ($match, $body) {
544         switch ($match) {
545         case '*': return new HtmlElement('b', $body);
546         case '=': return new HtmlElement('tt', $body);
547         case '_': return new HtmlElement('i', $body);
548         }
549     }
550 }
551
552 class Markup_html_emphasis extends BalancedMarkup
553 {
554     var $_start_regexp = 
555         "<(?: b|big|i|small|tt|em|strong|cite|code|dfn|kbd|samp|var|sup|sub )>";
556
557     function getEndRegexp ($match) {
558         return "<\\/" . substr($match, 1);
559     }
560     
561     function markup ($match, $body) {
562         $tag = substr($match, 1, -1);
563         return new HtmlElement($tag, $body);
564     }
565 }
566
567 class Markup_html_abbr extends BalancedMarkup
568 {
569     //rurban: abbr|acronym need an optional title tag.
570     //sf.net bug #728595
571     var $_start_regexp = "<(?: abbr|acronym )(?: \stitle=[^>]*)?>";
572
573     function getEndRegexp ($match) {
574         if (substr($match,1,4) == 'abbr')
575             $tag = 'abbr';
576         else
577             $tag = 'acronym';
578         return "<\\/" . $tag . '>';
579     }
580     
581     function markup ($match, $body) {
582         if (substr($match,1,4) == 'abbr')
583             $tag = 'abbr';
584         else
585             $tag = 'acronym';
586         $rest = substr($match,1+strlen($tag),-1);
587         if (!empty($rest)) {
588             list($key,$val) = explode("=",$rest);
589             $args = array($key => $val);
590         } else $args = array();
591         return new HtmlElement($tag, $args, $body);
592     }
593 }
594
595 // Special version for single-line plugins formatting, 
596 //  like: '<small>< ?plugin PopularNearby ? ></small>'
597 class Markup_plugin extends SimpleMarkup
598 {
599     var $_match_regexp = '<\?plugin(?:-form)?\s[^\n]+?\?>';
600
601     function markup ($match) {
602         //$xml = new Cached_PluginInvocation($match);
603         //$xml->setTightness(true,true);
604         return new Cached_PluginInvocation($match);
605     }
606 }
607
608
609 // TODO: "..." => "&#133;"  browser specific display (not cached?)
610 // TODO: "--" => "&emdash;" browser specific display (not cached?)
611
612 // FIXME: Do away with magic phpwiki forms.  (Maybe phpwiki: links too?)
613 // FIXME: Do away with plugin-links.  They seem not to be used.
614 //Plugin link
615
616
617 class InlineTransformer
618 {
619     var $_regexps = array();
620     var $_markup = array();
621     
622     function InlineTransformer ($markup_types = false) {
623         if (!$markup_types)
624             $markup_types = array('escape', 'bracketlink', 'url',
625                                   'interwiki', 'wikiword', 'linebreak',
626                                   'old_emphasis', 'nestled_emphasis',
627                                   'html_emphasis', 'html_abbr', 'plugin');
628         foreach ($markup_types as $mtype) {
629             $class = "Markup_$mtype";
630             $this->_addMarkup(new $class);
631         }
632     }
633
634     function _addMarkup ($markup) {
635         if (isa($markup, 'SimpleMarkup'))
636             $regexp = $markup->getMatchRegexp();
637         else
638             $regexp = $markup->getStartRegexp();
639
640         assert(!isset($this->_markup[$regexp]));
641         $this->_regexps[] = $regexp;
642         $this->_markup[] = $markup;
643     }
644         
645     function parse (&$text, $end_regexps = array('$')) {
646         $regexps = $this->_regexps;
647
648         // $end_re takes precedence: "favor reduce over shift"
649         array_unshift($regexps, $end_regexps[0]);
650         //array_push($regexps, $end_regexps[0]);
651         $regexps = new RegexpSet($regexps);
652         
653         $input = $text;
654         $output = new XmlContent;
655
656         $match = $regexps->match($input);
657         
658         while ($match) {
659             if ($match->regexp_ind == 0) {
660                 // No start pattern found before end pattern.
661                 // We're all done!
662                 if (isset($markup) and is_object($markup) and isa($markup,'Markup_plugin')) {
663                     $current =& $output->_content[count($output->_content)-1];
664                     $current->setTightness(true,true);
665                 }
666                 $output->pushContent($match->prematch);
667                 $text = $match->postmatch;
668                 return $output;
669             }
670
671             $markup = $this->_markup[$match->regexp_ind - 1];
672             $body = $this->_parse_markup_body($markup, $match->match, $match->postmatch, $end_regexps);
673             if (!$body) {
674                 // Couldn't match balanced expression.
675                 // Ignore and look for next matching start regexp.
676                 $match = $regexps->nextMatch($input, $match);
677                 continue;
678             }
679
680             // Matched markup.  Eat input, push output.
681             // FIXME: combine adjacent strings.
682             $current = $markup->markup($match->match, $body);
683             $input = $match->postmatch;
684             if (isset($markup) and is_object($markup) and isa($markup,'Markup_plugin')) {
685                 $current->setTightness(true,true);
686             }
687             $output->pushContent($match->prematch, $current);
688
689             $match = $regexps->match($input);
690         }
691
692         // No pattern matched, not even the end pattern.
693         // Parse fails.
694         return false;
695     }
696
697     function _parse_markup_body ($markup, $match, &$text, $end_regexps) {
698         if (isa($markup, 'SimpleMarkup'))
699             return true;        // Done. SimpleMarkup is simple.
700
701         if (!is_object($markup)) return false; // Some error: Should assert
702         array_unshift($end_regexps, $markup->getEndRegexp($match));
703
704         // Optimization: if no end pattern in text, we know the
705         // parse will fail.  This is an important optimization,
706         // e.g. when text is "*lots *of *start *delims *with
707         // *no *matching *end *delims".
708         $ends_pat = "/(?:" . join(").*(?:", $end_regexps) . ")/xs";
709         if (!preg_match($ends_pat, $text))
710             return false;
711         return $this->parse($text, $end_regexps);
712     }
713 }
714
715 class LinkTransformer extends InlineTransformer
716 {
717     function LinkTransformer () {
718         $this->InlineTransformer(array('escape', 'bracketlink', 'url',
719                                        'interwiki', 'wikiword'));
720     }
721 }
722
723 function TransformInline($text, $markup = 2.0, $basepage=false) {
724     static $trfm;
725     
726     if (empty($trfm)) {
727         $trfm = new InlineTransformer;
728     }
729     
730     if ($markup < 2.0) {
731         $text = ConvertOldMarkup($text, 'inline');
732     }
733
734     if ($basepage) {
735         return new CacheableMarkup($trfm->parse($text), $basepage);
736     }
737     return $trfm->parse($text);
738 }
739
740 function TransformLinks($text, $markup = 2.0, $basepage = false) {
741     static $trfm;
742     
743     if (empty($trfm)) {
744         $trfm = new LinkTransformer;
745     }
746
747     if ($markup < 2.0) {
748         $text = ConvertOldMarkup($text, 'links');
749     }
750     
751     if ($basepage) {
752         return new CacheableMarkup($trfm->parse($text), $basepage);
753     }
754     return $trfm->parse($text);
755 }
756
757 // (c-file-style: "gnu")
758 // Local Variables:
759 // mode: php
760 // tab-width: 8
761 // c-basic-offset: 4
762 // c-hanging-comment-ender-p: nil
763 // indent-tabs-mode: nil
764 // End:   
765 ?>