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