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