]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/InlineParser.php
phpdoc_params
[SourceForge/phpwiki.git] / lib / InlineParser.php
1 <?php
2 // $Id$
3 /* Copyright (C) 2002 Geoffrey T. Dairiki <dairiki@dairiki.org>
4  * Copyright (C) 2004-2010 Reini Urban
5  * Copyright (C) 2008-2010 Marc-Etienne Vargenau, Alcatel-Lucent
6  *
7  * This file is part of PhpWiki.
8  *
9  * PhpWiki is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * PhpWiki is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23 /**
24  * This is the code which deals with the inline part of the (new-style)
25  * wiki-markup.
26  *
27  * @package Markup
28  * @author Geoffrey T. Dairiki, Reini Urban
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/CachedMarkup.php');
38 require_once(dirname(__FILE__).'/stdlib.php');
39
40
41 function WikiEscape($text) {
42     return str_replace('#', ESCAPE_CHAR . '#', $text);
43 }
44
45 function UnWikiEscape($text) {
46     return preg_replace('/' . ESCAPE_CHAR . '(.)/', '\1', $text);
47 }
48
49 /**
50  * Return type from RegexpSet::match and RegexpSet::nextMatch.
51  *
52  * @see RegexpSet
53  */
54 class RegexpSet_match {
55     /**
56      * The text leading up the the next match.
57      */
58     var $prematch;
59     /**
60      * The matched text.
61      */
62     var $match;
63     /**
64      * The text following the matched text.
65      */
66     var $postmatch;
67     /**
68      * Index of the regular expression which matched.
69      */
70     var $regexp_ind;
71 }
72
73 /**
74  * A set of regular expressions.
75  *
76  * This class is probably only useful for InlineTransformer.
77  */
78 class RegexpSet
79 {
80     /** Constructor
81      *
82      * @param array $regexps A list of regular expressions.  The
83      * regular expressions should not include any sub-pattern groups
84      * "(...)".  (Anonymous groups, like "(?:...)", as well as
85      * look-ahead and look-behind assertions are okay.)
86      */
87     function RegexpSet ($regexps) {
88         assert($regexps);
89         $this->_regexps = array_unique($regexps);
90         if (!defined('_INLINE_OPTIMIZATION')) define('_INLINE_OPTIMIZATION',0);
91     }
92
93     /**
94      * Search text for the next matching regexp from the Regexp Set.
95      *
96      * @param string $text The text to search.
97      *
98      * @return RegexpSet_match A RegexpSet_match object, or false if no match.
99      */
100     function match ($text) {
101         return $this->_match($text, $this->_regexps, '*?');
102     }
103
104     /**
105      * Search for next matching regexp.
106      *
107      * Here, 'next' has two meanings:
108      *
109      * Match the next regexp(s) in the set, at the same position as the last match.
110      *
111      * If that fails, match the whole RegexpSet, starting after the position of the
112      * previous match.
113      *
114      * @param string $text Text to search.
115      *
116      * @param RegexpSet_match $prevMatch A RegexpSet_match object.
117      * $prevMatch should be a match object obtained by a previous
118      * match upon the same value of $text.
119      *
120      * @return RegexpSet_match A RegexpSet_match object, or false if no match.
121      */
122     function nextMatch ($text, $prevMatch) {
123         // Try to find match at same position.
124         $pos = strlen($prevMatch->prematch);
125         $regexps = array_slice($this->_regexps, $prevMatch->regexp_ind + 1);
126         if ($regexps) {
127             $repeat = sprintf('{%d}', $pos);
128             if ( ($match = $this->_match($text, $regexps, $repeat)) ) {
129                 $match->regexp_ind += $prevMatch->regexp_ind + 1;
130                 return $match;
131             }
132
133         }
134
135         // Failed.  Look for match after current position.
136         $repeat = sprintf('{%d,}?', $pos + 1);
137         return $this->_match($text, $this->_regexps, $repeat);
138     }
139
140     // Syntax: http://www.pcre.org/pcre.txt
141     //   x - EXTENDED, ignore whitespace
142     //   s - DOTALL
143     //   A - ANCHORED
144     //   S - STUDY
145     function _match ($text, $regexps, $repeat) {
146         // If one of the regexps is an empty string, php will crash here:
147         // sf.net: Fatal error: Allowed memory size of 8388608 bytes exhausted
148         //         (tried to allocate 634 bytes)
149         if (_INLINE_OPTIMIZATION) { // disabled, wrong
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(); $matched_ind = array();
155         for ($i=0; $i<count($regexps); $i++) {
156         if (!trim($regexps[$i])) {
157             trigger_error("empty regexp $i", E_USER_WARNING);
158             continue;
159         }
160         $pat= "/ ( . $repeat ) ( " . $regexps[$i] . " ) /x";
161         if (preg_match($pat, $text, $_m)) {
162             $m = $_m; // FIXME: prematch, postmatch is wrong
163             $matched[] = $regexps[$i];
164             $matched_ind[] = $i;
165             $regexp_ind = $i;
166         }
167         }
168         // To overcome ANCHORED:
169         // We could sort by longest match and iterate over these.
170         if (empty($matched)) return false;
171         }
172         $match = new RegexpSet_match;
173
174         // Optimization: if the matches are only "$" and another, then omit "$"
175         if (! _INLINE_OPTIMIZATION or count($matched) > 2) {
176             assert(!empty($repeat));
177             assert(!empty($regexps));
178             // We could do much better, if we would know the matching markup for the
179             // longest regexp match:
180             $hugepat= "/ ( . $repeat ) ( (" . join(')|(', $regexps) . ") ) /Asx";
181             // Proposed premature optimization 1:
182             //$hugepat= "/ ( . $repeat ) ( (" . join(')|(', array_values($matched)) . ") ) /Asx";
183             if (! preg_match($hugepat, $text, $m)) {
184                 return false;
185             }
186             // Proposed premature optimization 1:
187             //$match->regexp_ind = $matched_ind[count($m) - 4];
188             $match->regexp_ind = count($m) - 4;
189         } else {
190             $match->regexp_ind = $regexp_ind;
191         }
192
193         $match->postmatch = substr($text, strlen($m[0]));
194         $match->prematch = $m[1];
195         $match->match = $m[2];
196
197         /* DEBUGGING */
198         if (DEBUG & _DEBUG_PARSER) {
199           static $_already_dumped = 0;
200           if (!$_already_dumped) {
201             var_dump($regexps);
202             if (_INLINE_OPTIMIZATION)
203                 var_dump($matched);
204             var_dump($matched_ind);
205           }
206           $_already_dumped = 1;
207           PrintXML(HTML::dl(HTML::dt("input"),
208                           HTML::dd(HTML::pre($text)),
209                           HTML::dt("regexp"),
210                           HTML::dd(HTML::pre($match->regexp_ind, ":", $regexps[$match->regexp_ind])),
211                           HTML::dt("prematch"),
212                           HTML::dd(HTML::pre($match->prematch)),
213                           HTML::dt("match"),
214                           HTML::dd(HTML::pre($match->match)),
215                           HTML::dt("postmatch"),
216                           HTML::dd(HTML::pre($match->postmatch))
217                           ));
218         }
219         return $match;
220     }
221 }
222
223
224
225 /**
226  * A simple markup rule (i.e. terminal token).
227  *
228  * These are defined by a regexp.
229  *
230  * When a match is found for the regexp, the matching text is replaced.
231  * The replacement content is obtained by calling the SimpleMarkup::markup method.
232  */
233 class SimpleMarkup
234 {
235     var $_match_regexp;
236
237     /** Get regexp.
238      *
239      * @return string Regexp which matches this token.
240      */
241     function getMatchRegexp () {
242         return $this->_match_regexp;
243     }
244
245     /** Markup matching text.
246      *
247      * @param string $match The text which matched the regexp
248      * (obtained from getMatchRegexp).
249      *
250      * @return mixed The expansion of the matched text.
251      */
252     function markup ($match /*, $body */) {
253         trigger_error("pure virtual", E_USER_ERROR);
254     }
255 }
256
257 /**
258  * A balanced markup rule.
259  *
260  * These are defined by a start regexp, and an end regexp.
261  */
262 class BalancedMarkup
263 {
264     var $_start_regexp;
265
266     /** Get the starting regexp for this rule.
267      *
268      * @return string The starting regexp.
269      */
270     function getStartRegexp () {
271         return $this->_start_regexp;
272     }
273
274     /** Get the ending regexp for this rule.
275      *
276      * @param string $match The text which matched the starting regexp.
277      *
278      * @return string The ending regexp.
279      */
280     function getEndRegexp ($match) {
281         return $this->_end_regexp;
282     }
283
284     /** Get expansion for matching input.
285      *
286      * @param string $match The text which matched the starting regexp.
287      *
288      * @param mixed $body Transformed text found between the starting
289      * and ending regexps.
290      *
291      * @return mixed The expansion of the matched text.
292      */
293     function markup ($match, $body) {
294         trigger_error("pure virtual", E_USER_ERROR);
295     }
296 }
297
298 class Markup_escape  extends SimpleMarkup
299 {
300     function getMatchRegexp () {
301         return ESCAPE_CHAR . '(?: [[:alnum:]]+ | .)';
302     }
303
304     function markup ($match) {
305         assert(strlen($match) >= 2);
306         return substr($match, 1);
307     }
308 }
309
310 /**
311  * [image.jpg size=50% border=5], [image.jpg size=50x30]
312  * Support for the following attributes: see stdlib.php:LinkImage()
313  *   size=<percent>%, size=<width>x<height>
314  *   border=n, align=\w+, hspace=n, vspace=n
315  *   width=n, height=n
316  *   title, lang, id, alt
317  */
318 function isImageLink($link) {
319     if (!$link) return false;
320     assert(defined('INLINE_IMAGES'));
321     return preg_match("/\\.(" . INLINE_IMAGES . ")$/i", $link)
322         or preg_match("/\\.(" . INLINE_IMAGES . ")\s+(size|border|align|hspace|vspace|type|data|width|height|title|lang|id|alt)=/i", $link);
323 }
324
325 function LinkBracketLink($bracketlink) {
326
327     // $bracketlink will start and end with brackets; in between will
328     // be either a page name, a URL or both separated by a pipe.
329
330    $wikicreolesyntax = false;
331
332    if (string_starts_with($bracketlink, "[[") or string_starts_with($bracketlink, "#[[")) {
333        $wikicreolesyntax = true;
334        $bracketlink = str_replace("[[", "[", $bracketlink);
335        $bracketlink = str_replace("]]", "]", $bracketlink);
336    }
337
338     // Strip brackets and leading space
339     // bug#1904088  Some brackets links on 2 lines cause the parser to crash
340     preg_match('/(\#?) \[\s* (?: (.*?) \s* (?<!' . ESCAPE_CHAR . ')(\|) )? \s* (.+?) \s*\]/x',
341            str_replace("\n", " ", $bracketlink), $matches);
342     if (count($matches) < 4) {
343         // "[ personal\ninformation manager | PhpWiki:PersonalWiki ]"
344         trigger_error(_("Invalid [] syntax ignored")._(": ").$bracketlink, E_USER_WARNING);
345         return new Cached_Link;
346     }
347     list (, $hash, $label, $bar, $rawlink) = $matches;
348
349     if ($wikicreolesyntax and $label) {
350         $temp = $label;
351         $label = $rawlink;
352         $rawlink = $temp;
353     }
354
355     // Mediawiki compatibility: allow "Image:" and "File:"
356     // as synonyms of "Upload:"
357     // Allow "upload:", "image:" and "file:" also
358     // Remove spaces before and after ":", if any
359     if (string_starts_with($rawlink, "Upload")) {
360         $rawlink = preg_replace("/^Upload\\s*:\\s*/", "Upload:", $rawlink);
361     } else if (string_starts_with($rawlink, "upload")) {
362         $rawlink = preg_replace("/^upload\\s*:\\s*/", "Upload:", $rawlink);
363     } else if (string_starts_with($rawlink, "Image")) {
364         $rawlink = preg_replace("/^Image\\s*:\\s*/", "Upload:", $rawlink);
365     } else if (string_starts_with($rawlink, "image")) {
366         $rawlink = preg_replace("/^image\\s*:\\s*/", "Upload:", $rawlink);
367     } else if (string_starts_with($rawlink, "File")) {
368         $rawlink = preg_replace("/^File\\s*:\\s*/", "Upload:", $rawlink);
369     } else if (string_starts_with($rawlink, "file")) {
370         $rawlink = preg_replace("/^file\\s*:\\s*/", "Upload:", $rawlink);
371     }
372
373     $label = UnWikiEscape($label);
374     /*
375      * Check if the user has typed a explicit URL. This solves the
376      * problem where the URLs have a ~ character, which would be stripped away.
377      *   "[http:/server/~name/]" will work as expected
378      *   "http:/server/~name/"   will NOT work as expected, will remove the ~
379      */
380     if (   string_starts_with ($rawlink, "http://")
381         or string_starts_with ($rawlink, "https://") )
382     {
383         $link = $rawlink;
384         // Mozilla Browser URI Obfuscation Weakness 2004-06-14
385         //   http://www.securityfocus.com/bid/10532/
386         //   goodurl+"%2F%20%20%20."+badurl
387         if (preg_match("/%2F(%20)+\./i", $rawlink)) {
388             $rawlink = preg_replace("/%2F(%20)+\./i","%2F.",$rawlink);
389         }
390     } else {
391         // Check page name lenght
392         if (!string_starts_with($rawlink, "Upload:")) {
393             if (strlen($rawlink) > MAX_PAGENAME_LENGTH) {
394                 return HTML::span(array('class' => 'error'),
395                                         _('Page name too long'));
396             }
397         }
398         // Check illegal characters in page names: <>[]{}|"
399         if (preg_match("/[<\[\{\|\"\}\]>]/", $rawlink, $matches) > 0) {
400             return HTML::span(array('class' => 'error'),
401                          sprintf(_("Illegal character '%s' in page name."),
402                                  $matches[0]));
403         }
404         $link  = UnWikiEscape($rawlink);
405     }
406
407     /* Relatives links by Joel Schaubert.
408      * Recognize [../bla] or [/bla] as relative links, without needing http://
409      * but [ /link ] only if SUBPAGE_SEPERATOR is not "/".
410      * Normally /Page links to the subpage /Page.
411      */
412     if (SUBPAGE_SEPARATOR == '/') {
413         if (preg_match('/^\.\.\//', $link)) {
414             return new Cached_ExternalLink($link, $label);
415         }
416     } else if (preg_match('/^(\.\.\/|\/)/', $link)) {
417         return new Cached_ExternalLink($link, $label);
418     }
419
420     // Handle "[[SandBox|{{image.jpg}}]]" and "[[SandBox|{{image.jpg|alt text}}]]"
421     if (string_starts_with($label, "{{")) {
422         $imgurl = substr($label, 2, -2); // Remove "{{" and "}}"
423         $pipe = strpos($imgurl, '|');
424         if ($pipe === false) {
425             $label = LinkImage(getUploadDataPath() . $imgurl, $link);
426         } else {
427             list($img, $alt) = explode("|", $imgurl);
428             $label = LinkImage(getUploadDataPath() . $img, $alt);
429         }
430     } else
431
432     // [label|link]
433     // If label looks like a url to an image or object, we want an image link.
434     if (isImageLink($label)) {
435         $imgurl = $label;
436         $intermap = getInterwikiMap();
437         if (preg_match("/^" . $intermap->getRegexp() . ":/", $label)) {
438             $imgurl = $intermap->link($label);
439             $imgurl = $imgurl->getAttr('href');
440         } elseif (! preg_match("#^(" . ALLOWED_PROTOCOLS . "):#", $imgurl)) {
441             // local theme linkname like 'images/next.gif'.
442             global $WikiTheme;
443             $imgurl = $WikiTheme->getImageURL($imgurl);
444         }
445         // for objects (non-images) the link is taken as alt tag,
446         // which is in return taken as alternative img
447         $label = LinkImage($imgurl, $link);
448     }
449
450     if ($hash) {
451         // It's an anchor, not a link...
452         $id = MangleXmlIdentifier($link);
453         return HTML::a(array('name' => $id, 'id' => $id),
454                        $bar ? $label : $link);
455     }
456
457     if (preg_match("#^(" . ALLOWED_PROTOCOLS . "):#", $link)) {
458         // if it's an image, embed it; otherwise, it's a regular link
459         if (isImageLink($link) and empty($label)) // patch #1348996 by Robert Litwiniec
460             return LinkImage($link, $label);
461         else
462             return new Cached_ExternalLink($link, $label);
463     }
464     elseif (substr($link,0,8) == 'phpwiki:')
465         return new Cached_PhpwikiURL($link, $label);
466
467     /* Semantic relations and attributes.
468      * Relation and attribute names must be word chars only, no space.
469      * Links and Attributes may contain everything. word, nums, units, space, groupsep, numsep, ...
470      */
471     elseif (preg_match("/^ (\w+) (:[:=]) (.*) $/x", $link) and !isImageLink($link))
472         return new Cached_SemanticLink($link, $label);
473
474     /* Do not store the link */
475     elseif (substr($link,0,1) == ':')
476         return new Cached_WikiLink($link, $label);
477
478     /*
479      * Inline images in Interwiki urls's:
480      * [File:my_image.gif] inlines the image,
481      * File:my_image.gif shows a plain inter-wiki link,
482      * [what a pic|File:my_image.gif] shows a named inter-wiki link to the gif
483      * [File:my_image.gif|what a pic] shows an inlined image linked to the page "what a pic"
484      *
485      * Note that for simplicity we will accept embedded object tags (non-images)
486      * here also, and seperate them later in LinkImage()
487      */
488     elseif (strstr($link,':')
489             and ($intermap = getInterwikiMap())
490             and preg_match("/^" . $intermap->getRegexp() . ":/", $link))
491     {
492         // trigger_error("label: $label link: $link", E_USER_WARNING);
493         if (empty($label) and isImageLink($link)) {
494             // if without label => inlined image [File:xx.gif]
495             $imgurl = $intermap->link($link);
496             return LinkImage($imgurl->getAttr('href'));
497         }
498         return new Cached_InterwikiLink($link, $label);
499     } else {
500         // Split anchor off end of pagename.
501         if (preg_match('/\A(.*)(?<!'.ESCAPE_CHAR.')#(.*?)\Z/', $rawlink, $m)) {
502             list(,$rawlink,$anchor) = $m;
503             $pagename = UnWikiEscape($rawlink);
504             $anchor = UnWikiEscape($anchor);
505             if (!$label)
506                 $label = $link;
507         }
508         else {
509             $pagename = $link;
510             $anchor = false;
511         }
512         return new Cached_WikiLink($pagename, $label, $anchor);
513     }
514 }
515
516 class Markup_wikicreolebracketlink  extends SimpleMarkup
517 {
518     var $_match_regexp = "\\#? \\[\\[ .*? [^]\\s] .*? \\]\\]";
519
520     function markup ($match) {
521         $link = LinkBracketLink($match);
522         assert($link->isInlineElement());
523         return $link;
524     }
525 }
526
527 class Markup_bracketlink  extends SimpleMarkup
528 {
529     var $_match_regexp = "\\#? \\[ .*? [^]\\s] .*? \\]";
530
531     function markup ($match) {
532         $link = LinkBracketLink($match);
533         assert($link->isInlineElement());
534         return $link;
535     }
536 }
537
538 class Markup_spellcheck extends SimpleMarkup
539 {
540     function Markup_spellcheck () {
541     $this->suggestions = $GLOBALS['request']->getArg('suggestions');
542     }
543     function getMatchRegexp () {
544         if (empty($this->suggestions))
545             return "(?# false )";
546     $words = array_keys($this->suggestions);
547         return "(?<= \W ) (?:" . join('|', $words) . ") (?= \W )";
548     }
549
550     function markup ($match) {
551         if (empty($this->suggestions) or empty($this->suggestions[$match]))
552             return $match;
553         return new Cached_SpellCheck(UnWikiEscape($match), $this->suggestions[$match]);
554     }
555 }
556
557 class Markup_searchhighlight extends SimpleMarkup
558 {
559     function Markup_searchhighlight () {
560         $result = $GLOBALS['request']->_searchhighlight;
561         require_once("lib/TextSearchQuery.php");
562         $query = new TextSearchQuery($result['query']);
563         $this->hilight_re = $query->getHighlightRegexp();
564         $this->engine = $result['engine'];
565     }
566     function getMatchRegexp () {
567         return $this->hilight_re;
568     }
569     function markup ($match) {
570         return new Cached_SearchHighlight(UnWikiEscape($match), $this->engine);
571     }
572 }
573
574 class Markup_url extends SimpleMarkup
575 {
576     function getMatchRegexp () {
577         return "(?<![[:alnum:]]) (?:" . ALLOWED_PROTOCOLS . ") : [^\s<>\"']+ (?<![ ,.?; \] \) ])";
578     }
579
580     function markup ($match) {
581         return new Cached_ExternalLink(UnWikiEscape($match));
582     }
583 }
584
585 class Markup_interwiki extends SimpleMarkup
586 {
587     function getMatchRegexp () {
588         $map = getInterwikiMap();
589         return "(?<! [[:alnum:]])" . $map->getRegexp(). ": [^:=]\S+ (?<![ ,.?;! \] \) \" \' ])";
590     }
591
592     function markup ($match) {
593         return new Cached_InterwikiLink(UnWikiEscape($match));
594     }
595 }
596
597 class Markup_semanticlink extends SimpleMarkup
598 {
599     // No units seperated by space allowed here
600     // For :: (relations) only words, no comma,
601     // but for := (attributes) comma and dots are allowed. Units with groupsep.
602     // Ending dots or comma are not part of the link.
603     var $_match_regexp = "(?: \w+:=\S+(?<![\.,]))|(?: \w+::[\w\.]+(?<!\.))";
604
605     function markup ($match) {
606         return new Cached_SemanticLink(UnWikiEscape($match));
607     }
608 }
609
610 class Markup_wikiword extends SimpleMarkup
611 {
612     function getMatchRegexp () {
613         global $WikiNameRegexp;
614         if (!trim($WikiNameRegexp)) return " " . WIKI_NAME_REGEXP;
615         return " $WikiNameRegexp";
616     }
617
618     function markup ($match) {
619         if (!$match) return false;
620         if ($this->_isWikiUserPage($match))
621             return new Cached_UserLink($match); //$this->_UserLink($match);
622         else
623             return new Cached_WikiLink($match);
624     }
625
626     // FIXME: there's probably a more useful place to put these two functions
627     function _isWikiUserPage ($page) {
628         global $request;
629         $dbi = $request->getDbh();
630         $page_handle = $dbi->getPage($page);
631         if ($page_handle and $page_handle->get('pref'))
632             return true;
633         else
634             return false;
635     }
636
637     function _UserLink($PageName) {
638         $link = HTML::a(array('href' => $PageName));
639         $link->pushContent(PossiblyGlueIconToText('wikiuser', $PageName));
640         $link->setAttr('class', 'wikiuser');
641         return $link;
642     }
643 }
644
645 class Markup_linebreak extends SimpleMarkup
646 {
647     var $_match_regexp = "(?: (?<! %) %%% (?! %) | \\\\\\\\ | <\s*(?:br|BR)\s*> | <\s*(?:br|BR)\s*\/\s*> )";
648
649     function markup ($match) {
650         return HTML::br();
651     }
652 }
653
654 class Markup_wikicreole_italics extends BalancedMarkup
655 {
656     var $_start_regexp = "\\/\\/";
657
658     function getEndRegexp ($match) {
659         return "\\/\\/";
660     }
661
662     function markup ($match, $body) {
663         $tag = 'em';
664         return new HtmlElement($tag, $body);
665     }
666 }
667
668 class Markup_wikicreole_bold extends BalancedMarkup
669 {
670     var $_start_regexp = "\\*\\*";
671
672     function getEndRegexp ($match) {
673         return "\\*\\*";
674     }
675
676     function markup ($match, $body) {
677         $tag = 'strong';
678         return new HtmlElement($tag, $body);
679     }
680 }
681
682 class Markup_wikicreole_monospace extends BalancedMarkup
683 {
684     var $_start_regexp = "\\#\\#";
685
686     function getEndRegexp ($match) {
687         return "\\#\\#";
688     }
689
690     function markup ($match, $body) {
691         return new HtmlElement('span', array('class' => 'tt'), $body);
692     }
693 }
694
695 class Markup_wikicreole_underline extends BalancedMarkup
696 {
697     var $_start_regexp = "\\_\\_";
698
699     function getEndRegexp ($match) {
700         return "\\_\\_";
701     }
702
703     function markup ($match, $body) {
704         $tag = 'u';
705         return new HtmlElement($tag, $body);
706     }
707 }
708
709 class Markup_wikicreole_superscript extends BalancedMarkup
710 {
711     var $_start_regexp = "\\^\\^";
712
713     function getEndRegexp ($match) {
714         return "\\^\\^";
715     }
716
717     function markup ($match, $body) {
718         $tag = 'sup';
719         return new HtmlElement($tag, $body);
720     }
721 }
722
723 class Markup_wikicreole_subscript extends BalancedMarkup
724 {
725     var $_start_regexp = ",,";
726
727     function getEndRegexp ($match) {
728         return $match;
729     }
730
731     function markup ($match, $body) {
732         $tag = 'sub';
733         return new HtmlElement($tag, $body);
734     }
735 }
736
737 class Markup_old_emphasis  extends BalancedMarkup
738 {
739     var $_start_regexp = "''";
740
741     function getEndRegexp ($match) {
742         return $match;
743     }
744
745     function markup ($match, $body) {
746         $tag = 'em';
747         return new HtmlElement($tag, $body);
748     }
749 }
750
751 class Markup_nestled_emphasis extends BalancedMarkup
752 {
753     function getStartRegexp() {
754     static $start_regexp = false;
755
756     if (!$start_regexp) {
757         // The three possible delimiters
758             // (none of which can be followed by itself.)
759         $i = "_ (?! _)";
760         $b = "\\* (?! \\*)";
761         $tt = "= (?! =)";
762
763         $any = "(?: ${i}|${b}|${tt})"; // any of the three.
764
765         // Any of [_*=] is okay if preceded by space or one of [-"'/:]
766         $start[] = "(?<= \\s|^|[-\"'\\/:]) ${any}";
767
768         // _ or * is okay after = as long as not immediately followed by =
769         $start[] = "(?<= =) (?: ${i}|${b}) (?! =)";
770         // etc...
771         $start[] = "(?<= _) (?: ${b}|${tt}) (?! _)";
772         $start[] = "(?<= \\*) (?: ${i}|${tt}) (?! \\*)";
773
774
775         // any delimiter okay after an opening brace ( [{<(] )
776         // as long as it's not immediately followed by the matching closing
777         // brace.
778         $start[] = "(?<= { ) ${any} (?! } )";
779         $start[] = "(?<= < ) ${any} (?! > )";
780         $start[] = "(?<= \\( ) ${any} (?! \\) )";
781
782         $start = "(?:" . join('|', $start) . ")";
783
784         // Any of the above must be immediately followed by non-whitespace.
785         $start_regexp = $start . "(?= \S)";
786     }
787
788     return $start_regexp;
789     }
790
791     function getEndRegexp ($match) {
792         $chr = preg_quote($match);
793         return "(?<= \S | ^ ) (?<! $chr) $chr (?! $chr) (?= \s | [-)}>\"'\\/:.,;!? _*=] | $)";
794     }
795
796     function markup ($match, $body) {
797         switch ($match) {
798         case '*': return new HtmlElement('b', $body);
799         case '=': return new HtmlElement('span', array('class' => 'tt'), $body);
800         case '_': return new HtmlElement('i', $body);
801         }
802     }
803 }
804
805 class Markup_html_emphasis extends BalancedMarkup
806 {
807     var $_start_regexp =
808         "<(?: b|big|i|small|tt|em|strong|cite|code|dfn|kbd|samp|s|strike|del|var|sup|sub )>";
809
810     function getEndRegexp ($match) {
811         return "<\\/" . substr($match, 1);
812     }
813
814     function markup ($match, $body) {
815         $tag = substr($match, 1, -1);
816         return new HtmlElement($tag, $body);
817     }
818 }
819
820 class Markup_html_divspan extends BalancedMarkup
821 {
822     var $_start_regexp =
823         "<(?: div|span )(?: \s[^>]*)?>";
824
825     function getEndRegexp ($match) {
826         if (substr($match,1,4) == 'span')
827             $tag = 'span';
828         else
829             $tag = 'div';
830         return "<\\/" . $tag . '>';
831     }
832
833     function markup ($match, $body) {
834         if (substr($match,1,4) == 'span')
835             $tag = 'span';
836         else
837             $tag = 'div';
838         $rest = substr($match,1+strlen($tag),-1);
839         if (!empty($rest)) {
840             $args = parse_attributes($rest);
841         } else {
842             $args = array();
843         }
844         return new HtmlElement($tag, $args, $body);
845     }
846 }
847
848
849 class Markup_html_abbr extends BalancedMarkup
850 {
851     //rurban: abbr|acronym need an optional title tag.
852     //sf.net bug #728595
853     var $_start_regexp = "<(?: abbr|acronym )(?: [^>]*)?>";
854
855     function getEndRegexp ($match) {
856         if (substr($match,1,4) == 'abbr')
857             $tag = 'abbr';
858         else
859             $tag = 'acronym';
860         return "<\\/" . $tag . '>';
861     }
862
863     function markup ($match, $body) {
864         if (substr($match,1,4) == 'abbr')
865             $tag = 'abbr';
866         else
867             $tag = 'acronym';
868         $rest = substr($match,1+strlen($tag),-1);
869         $attrs = parse_attributes($rest);
870         // Remove attributes other than title and lang
871         $allowedargs = array();
872         foreach ($attrs as $key => $value) {
873             if (in_array ($key, array("title", "lang"))) {
874                 $allowedargs[$key] = $value;
875             }
876         }
877         return new HtmlElement($tag, $allowedargs, $body);
878     }
879 }
880
881 /** ENABLE_MARKUP_COLOR
882  *  See http://www.pmwiki.org/wiki/PmWiki/WikiStyles and
883  *      http://www.flexwiki.com/default.aspx/FlexWiki/FormattingRules.html
884  */
885 class Markup_color extends BalancedMarkup {
886     // %color=blue% blue text %% and back to normal
887     var $_start_regexp = "%color=(?: [^%]*)%";
888     var $_end_regexp = "%%";
889
890     function markup ($match, $body) {
891         $color = strtolower(substr($match, 7, -1));
892
893         $morecolors = array('beige' => '#f5f5dc',
894                             'brown' => '#a52a2a',
895                             'chocolate' => '#d2691e',
896                             'cyan' => '#00ffff',
897                             'gold' => '#ffd700',
898                             'ivory' => '#fffff0',
899                             'indigo' => '#4b0082',
900                             'magenta' => '#ff00ff',
901                             'orange' => '#ffa500',
902                             'pink' => '#ffc0cb',
903                             'salmon' => '#fa8072',
904                             'snow' => '#fffafa',
905                             'turquoise' => '#40e0d0',
906                             'violet' => '#ee82ee',
907                            );
908
909         if (isset($morecolors[$color])) {
910             $color = $morecolors[$color];
911         }
912
913         // HTML 4 defines the following 16 colors
914         if (in_array($color, array('aqua', 'black', 'blue', 'fuchsia',
915                                    'gray', 'green', 'lime', 'maroon',
916                                    'navy', 'olive', 'purple', 'red',
917                                    'silver', 'teal', 'white', 'yellow'))
918               or ((substr($color,0,1) == '#')
919                   and ((strlen($color) == 4) or (strlen($color) == 7))
920                   and (strspn(substr($color,1),'0123456789abcdef') == strlen($color)-1))) {
921             return new HtmlElement('span', array('style' => "color: $color"), $body);
922         } else {
923             return new HtmlElement('span', array('class' => 'error'),
924                                    sprintf(_("unknown color %s ignored"), substr($match, 7, -1)));
925         }
926     }
927 }
928
929 // Wikicreole placeholder
930 // <<<placeholder>>>
931 class Markup_placeholder extends SimpleMarkup
932 {
933     var $_match_regexp = '<<<.*?>>>';
934
935     function markup ($match) {
936         return HTML::span($match);
937     }
938 }
939
940 // Single-line HTML comment
941 // <!-- This is a comment -->
942 class Markup_html_comment extends SimpleMarkup
943 {
944     var $_match_regexp = '<!--.*?-->';
945
946     function markup ($match) {
947         return HTML::raw('');
948     }
949 }
950
951 // Special version for single-line plugins formatting,
952 //  like: '<small>< ?plugin PopularNearby ? ></small>'
953 class Markup_plugin extends SimpleMarkup
954 {
955     var $_match_regexp = '<\?plugin(?:-form)?\s[^\n]+?\?>';
956
957     function markup ($match) {
958     return new Cached_PluginInvocation($match);
959     }
960 }
961
962 // Special version for single-line Wikicreole plugins formatting.
963 class Markup_plugin_wikicreole extends SimpleMarkup
964 {
965     var $_match_regexp = '<<[^\n]+?>>';
966
967     function markup ($match) {
968         $pi = str_replace("<<", "<?plugin ", $match);
969         $pi = str_replace(">>", " ?>", $pi);
970     return new Cached_PluginInvocation($pi);
971     }
972 }
973
974 // Special version for plugins in xml syntax, mediawiki-style
975 // <name arg=value>body</name> or <name /> => < ? plugin pluginname arg=value body ? >
976 // PLUGIN_MARKUP_MAP = "html:RawHtml dot:GraphViz toc:CreateToc amath:AsciiMath richtable:RichTable include:IncludePage tex:TexToPng"
977 class Markup_xml_plugin extends BalancedMarkup
978 {
979     //var $_start_regexp = "<(?: ".join('|',PLUGIN_MARKUP_MAP)." )(?: \s[^>]*)>";
980
981     function getStartRegexp () {
982     global $PLUGIN_MARKUP_MAP;
983         static $_start_regexp;
984         if ($_start_regexp) return $_start_regexp;
985         if (empty($PLUGIN_MARKUP_MAP)) return '';
986         //"<(?: html|search|extsearch|dot|toc|math|richtable|include|tex )(?: \s[^>]*)>"
987     $_start_regexp = "<(?: ".join('|',array_keys($PLUGIN_MARKUP_MAP))." )(?: \s[^>]*|\\/ )>";
988         return $_start_regexp;
989     }
990     function getEndRegexp ($match) {
991         return "<\\/" . $match . '>';
992     }
993     function markup ($match, $body) {
994     global $PLUGIN_MARKUP_MAP;
995         $name = substr($match,2,-2);
996     $vars = '';
997         if (preg_match('/^(\S+)\|(.*)$/', $name, $_m)) {
998             $name = $_m[1];
999             $vars = $_m[2]; //str_replace(' ', '&', $_m[2]);
1000         }
1001         if (!isset($PLUGIN_MARKUP_MAP[$name])) {
1002             trigger_error("No plugin for $name $vars defined.", E_USER_WARNING);
1003             return "";
1004         }
1005         $plugin = $PLUGIN_MARKUP_MAP[$name];
1006     return new Cached_PluginInvocation("<"."?plugin $plugin $vars $body ?".">");
1007     }
1008 }
1009
1010 /**
1011  *  Mediawiki <nowiki>
1012  *  <nowiki>...</nowiki>
1013  */
1014 class Markup_nowiki extends SimpleMarkup
1015 {
1016     var $_match_regexp = '<nowiki>.*?<\/nowiki>';
1017
1018     function markup ($match) {
1019         // Remove <nowiki> and </nowiki>
1020         return HTML::raw(substr($match, 8, -9));
1021     }
1022 }
1023
1024 /**
1025  *  Wikicreole preformatted
1026  *  {{{
1027  *  }}}
1028  */
1029 class Markup_wikicreole_preformatted extends SimpleMarkup
1030 {
1031     var $_match_regexp = '\{\{\{.*?\}\}\}';
1032
1033     function markup ($match) {
1034         // Remove {{{ and }}}
1035         return new HtmlElement('span', array('class' => 'tt'), substr($match, 3, -3));
1036     }
1037 }
1038
1039 /** ENABLE_MARKUP_TEMPLATE
1040  *  Template syntax similar to Mediawiki
1041  *  {{template}}
1042  * => < ? plugin Template page=template ? >
1043  *  {{template|var1=value1|var2=value|...}}
1044  * => < ? plugin Template page=template var=value ... ? >
1045  *
1046  * The {{...}} syntax is also used for:
1047  *  - Wikicreole images
1048  *  - videos
1049  *  - predefined icons
1050  */
1051 class Markup_template_plugin  extends SimpleMarkup
1052 {
1053     // patch #1732793: allow \n, mult. {{ }} in one line, and single letters
1054     var $_match_regexp = '\{\{.*?\}\}';
1055
1056     function markup ($match) {
1057
1058         $page = substr($match,2,-2);
1059         $page = trim($page);
1060
1061         // Check for predefined icons.
1062         $predefinedicons = array(":)" => "ic_smile.png",
1063                                  ":(" => "ic_sad.png",
1064                                  ":P" => "ic_tongue.png",
1065                                  ":D" => "ic_biggrin.png",
1066                                  ";)" => "ic_wink.png",
1067                                  "(y)" => "ic_handyes.png",
1068                                  "(n)" => "ic_handno.png",
1069                                  "(i)" => "ic_info.png",
1070                                  "(/)" => "ic_check.png",
1071                                  "(x)" => "ic_cross.png",
1072                                  "(!)" => "ic_danger.png",
1073                                  "(+)" => "ic_plus.png",
1074                                  "(-)" => "ic_minus.png",
1075                                  "(?)" => "ic_help.png",
1076                                  "(on)" => "ic_lighton.png",
1077                                  "(off)" => "ic_lightoff.png",
1078                                  "(*)" => "ic_yellowstar.png",
1079                                  "(*r)" => "ic_redstar.png",
1080                                  "(*g)" => "ic_greenstar.png",
1081                                  "(*b)" => "ic_bluestar.png",
1082                                  "(*y)" => "ic_yellowstar.png",
1083                                 );
1084         foreach ($predefinedicons as $ascii => $icon) {
1085             if ($page == $ascii) {
1086                 return LinkImage(DATA_PATH . "/themes/default/images/$icon", $page);
1087             }
1088         }
1089
1090         if (strpos($page, "|") === false) {
1091             $imagename = $page;
1092             $alt = "";
1093         } else {
1094             $imagename = substr($page, 0, strpos($page, "|"));
1095             $alt = ltrim(strstr($page, "|"), "|");
1096         }
1097
1098         // It's not a Mediawiki template, it's a Wikicreole image
1099         if (is_image($imagename)) {
1100             if ((strpos($imagename, "http://") === 0) || (strpos($imagename, "https://") === 0)) {
1101                 return LinkImage($imagename, $alt);
1102             } else if ($imagename[0] == '/') {
1103                 return LinkImage(DATA_PATH . '/' . $imagename, $alt);
1104             } else {
1105                 return LinkImage(getUploadDataPath() . $imagename, $alt);
1106             }
1107         }
1108
1109         // It's a video
1110         if (is_video($imagename)) {
1111             $s = '<'.'?plugin Video file="' . $imagename . '" ?'.'>';
1112         return new Cached_PluginInvocation($s);
1113         }
1114
1115         $page = str_replace("\n", "", $page);
1116
1117         // The argument value might contain a double quote (")
1118         // We have to encode that.
1119         $page = htmlspecialchars($page);
1120
1121         $vars = '';
1122
1123         if (preg_match('/^(\S+?)\|(.*)$/', $page, $_m)) {
1124             $page = $_m[1];
1125             $vars = '"' . preg_replace('/\|/', '" "', $_m[2]) . '"';
1126             $vars = preg_replace('/"(\S+)=([^"]*)"/', '\\1="\\2"', $vars);
1127         }
1128
1129         // page may contain a version number
1130         // {{foo?version=5}}
1131         // in that case, output is "page=foo rev=5"
1132         if (strstr($page, "?")) {
1133             $page = str_replace("?version=", "\" rev=\"", $page);
1134         }
1135
1136         if ($vars)
1137             $s = '<'.'?plugin Template page="'.$page.'" '.$vars.' ?'.'>';
1138         else
1139             $s = '<'.'?plugin Template page="' . $page . '" ?'.'>';
1140     return new Cached_PluginInvocation($s);
1141     }
1142 }
1143
1144 // "..." => "&#133;"  browser specific display (not cached?)
1145 // Support some HTML::Entities: (C) for copy, --- for mdash, -- for ndash
1146 // TODO: "--" => "&emdash;" browser specific display (not cached?)
1147
1148 class Markup_html_entities  extends SimpleMarkup {
1149     //var $_match_regexp = '(: \.\.\.|\-\-|\-\-\-|\(C\) )';
1150
1151     function Markup_html_entities() {
1152         $this->_entities = array('...'  => '&#133;',
1153                                  '--'   => '&ndash;',
1154                                  '---'  => '&mdash;',
1155                                  '(C)'  => '&copy;',
1156                                  '&copy;' => '&copy;',
1157                                  '&trade;'  => '&trade;',
1158                                  );
1159         $this->_match_regexp =
1160             '(: ' .
1161             join('|', array_map('preg_quote', array_keys($this->_entities))) .
1162             ' )';
1163     }
1164
1165     function markup ($match) {
1166         return HTML::Raw($this->_entities[$match]);
1167     }
1168 }
1169
1170 class Markup_isonumchars  extends SimpleMarkup {
1171     var $_match_regexp = '\&\#\d{2,5};';
1172
1173     function markup ($match) {
1174         return HTML::Raw($match);
1175     }
1176 }
1177
1178 class Markup_isohexchars extends SimpleMarkup {
1179     // hexnums, like &#x00A4; <=> &curren;
1180     var $_match_regexp = '\&\#x[0-9a-fA-F]{2,4};';
1181
1182     function markup ($match) {
1183         return HTML::Raw($match);
1184     }
1185 }
1186
1187 // FIXME: Do away with magic phpwiki forms.  (Maybe phpwiki: links too?)
1188
1189 class InlineTransformer
1190 {
1191     var $_regexps = array();
1192     var $_markup = array();
1193
1194     function InlineTransformer ($markup_types = false) {
1195         global $request;
1196     // We need to extend the inline parsers by certain actions, like SearchHighlight,
1197     // SpellCheck and maybe CreateToc.
1198         if (!$markup_types) {
1199             $non_default = false;
1200             $markup_types = array
1201                 ('escape', 'wikicreolebracketlink', 'bracketlink', 'url',
1202                  'html_comment', 'placeholder',
1203                  'interwiki',  'semanticlink', 'wikiword', 'linebreak',
1204                  'wikicreole_superscript',
1205                  'wikicreole_subscript',
1206                  'wikicreole_italics', 'wikicreole_bold',
1207                  'wikicreole_monospace',
1208                  'wikicreole_underline',
1209                  'old_emphasis', 'nestled_emphasis',
1210                  'html_emphasis', 'html_abbr', 'plugin', 'plugin_wikicreole',
1211                  'isonumchars', 'isohexchars', /*'html_entities'*/
1212                  );
1213         if (DISABLE_MARKUP_WIKIWORD)
1214                 $markup_types = array_remove($markup_types, 'wikiword');
1215
1216         $action = $request->getArg('action');
1217         if ($action == 'SpellCheck' and $request->getArg('suggestions'))
1218         {   // insert it after url
1219         array_splice($markup_types, 2, 1, array('url','spellcheck'));
1220         }
1221         if (isset($request->_searchhighlight))
1222         {   // insert it after url
1223         array_splice($markup_types, 2, 1, array('url','searchhighlight'));
1224                 //$request->setArg('searchhighlight', false);
1225         }
1226         } else {
1227             $non_default = true;
1228     }
1229         foreach ($markup_types as $mtype) {
1230             $class = "Markup_$mtype";
1231             $this->_addMarkup(new $class);
1232         }
1233         $this->_addMarkup(new Markup_nowiki);
1234         if (ENABLE_MARKUP_DIVSPAN and !$non_default)
1235             $this->_addMarkup(new Markup_html_divspan);
1236         if (ENABLE_MARKUP_COLOR and !$non_default)
1237             $this->_addMarkup(new Markup_color);
1238         // Markup_wikicreole_preformatted must be before Markup_template_plugin
1239         $this->_addMarkup(new Markup_wikicreole_preformatted);
1240         if (ENABLE_MARKUP_TEMPLATE and !$non_default)
1241             $this->_addMarkup(new Markup_template_plugin);
1242         // This does not work yet
1243         if (PLUGIN_MARKUP_MAP and !$non_default)
1244             $this->_addMarkup(new Markup_xml_plugin);
1245     }
1246
1247     function _addMarkup ($markup) {
1248         if (isa($markup, 'SimpleMarkup'))
1249             $regexp = $markup->getMatchRegexp();
1250         else
1251             $regexp = $markup->getStartRegexp();
1252
1253         assert( !isset($this->_markup[$regexp]) );
1254         assert( strlen(trim($regexp)) > 0 );
1255         $this->_regexps[] = $regexp;
1256         $this->_markup[] = $markup;
1257     }
1258
1259     function parse (&$text, $end_regexps = array('$')) {
1260         $regexps = $this->_regexps;
1261
1262         // $end_re takes precedence: "favor reduce over shift"
1263         array_unshift($regexps, $end_regexps[0]);
1264         //array_push($regexps, $end_regexps[0]);
1265         $regexps = new RegexpSet($regexps);
1266
1267         $input = $text;
1268         $output = new XmlContent;
1269
1270         $match = $regexps->match($input);
1271
1272         while ($match) {
1273             if ($match->regexp_ind == 0) {
1274                 // No start pattern found before end pattern.
1275                 // We're all done!
1276                 if (isset($markup) and is_object($markup)
1277                     and isa($markup,'Markup_plugin'))
1278                 {
1279                     $current =& $output->_content[count($output->_content)-1];
1280                     $current->setTightness(true,true);
1281                 }
1282                 $output->pushContent($match->prematch);
1283                 $text = $match->postmatch;
1284                 return $output;
1285             }
1286
1287             $markup = $this->_markup[$match->regexp_ind - 1];
1288             $body = $this->_parse_markup_body($markup, $match->match,
1289                                               $match->postmatch, $end_regexps);
1290             if (!$body) {
1291                 // Couldn't match balanced expression.
1292                 // Ignore and look for next matching start regexp.
1293                 $match = $regexps->nextMatch($input, $match);
1294                 continue;
1295             }
1296
1297             // Matched markup.  Eat input, push output.
1298             // FIXME: combine adjacent strings.
1299             if (isa($markup, 'SimpleMarkup'))
1300                 $current = $markup->markup($match->match);
1301             else
1302                 $current = $markup->markup($match->match, $body);
1303             $input = $match->postmatch;
1304             if (isset($markup) and is_object($markup)
1305                 and isa($markup,'Markup_plugin'))
1306             {
1307                 $current->setTightness(true,true);
1308             }
1309             $output->pushContent($match->prematch, $current);
1310
1311             $match = $regexps->match($input);
1312         }
1313
1314         // No pattern matched, not even the end pattern.
1315         // Parse fails.
1316         return false;
1317     }
1318
1319     function _parse_markup_body ($markup, $match, &$text, $end_regexps) {
1320         if (isa($markup, 'SimpleMarkup'))
1321             return true;        // Done. SimpleMarkup is simple.
1322
1323         if (!is_object($markup)) return false; // Some error: Should assert
1324         array_unshift($end_regexps, $markup->getEndRegexp($match));
1325
1326         // Optimization: if no end pattern in text, we know the
1327         // parse will fail.  This is an important optimization,
1328         // e.g. when text is "*lots *of *start *delims *with
1329         // *no *matching *end *delims".
1330         $ends_pat = "/(?:" . join(").*(?:", $end_regexps) . ")/xs";
1331         if (!preg_match($ends_pat, $text))
1332             return false;
1333         return $this->parse($text, $end_regexps);
1334     }
1335 }
1336
1337 class LinkTransformer extends InlineTransformer
1338 {
1339     function LinkTransformer () {
1340         $this->InlineTransformer(array('escape', 'wikicreolebracketlink', 'bracketlink', 'url',
1341                                        'semanticlink', 'interwiki', 'wikiword',
1342                                        ));
1343     }
1344 }
1345
1346 class NowikiTransformer extends InlineTransformer
1347 {
1348     function NowikiTransformer () {
1349         $this->InlineTransformer
1350             (array('linebreak',
1351                    'html_emphasis', 'html_abbr', 'plugin', 'plugin_wikicreole',
1352                    'isonumchars', 'isohexchars', /*'html_entities',*/
1353                    ));
1354     }
1355 }
1356
1357 function TransformInline($text, $markup = 2.0, $basepage=false) {
1358     static $trfm;
1359     $action = $GLOBALS['request']->getArg('action');
1360     if (empty($trfm) or $action == 'SpellCheck') {
1361         $trfm = new InlineTransformer;
1362     }
1363
1364     if ($markup < 2.0) {
1365         $text = ConvertOldMarkup($text, 'inline');
1366     }
1367
1368     if ($basepage) {
1369         return new CacheableMarkup($trfm->parse($text), $basepage);
1370     }
1371     return $trfm->parse($text);
1372 }
1373
1374 function TransformLinks($text, $markup = 2.0, $basepage = false) {
1375     static $trfm;
1376
1377     if (empty($trfm)) {
1378         $trfm = new LinkTransformer;
1379     }
1380
1381     if ($markup < 2.0) {
1382         $text = ConvertOldMarkup($text, 'links');
1383     }
1384
1385     if ($basepage) {
1386         return new CacheableMarkup($trfm->parse($text), $basepage);
1387     }
1388     return $trfm->parse($text);
1389 }
1390
1391 /**
1392  * Transform only html markup and entities.
1393  */
1394 function TransformInlineNowiki($text, $markup = 2.0, $basepage=false) {
1395     static $trfm;
1396
1397     if (empty($trfm)) {
1398         $trfm = new NowikiTransformer;
1399     }
1400     if ($basepage) {
1401         return new CacheableMarkup($trfm->parse($text), $basepage);
1402     }
1403     return $trfm->parse($text);
1404 }
1405
1406 // Local Variables:
1407 // mode: php
1408 // tab-width: 8
1409 // c-basic-offset: 4
1410 // c-hanging-comment-ender-p: nil
1411 // indent-tabs-mode: nil
1412 // End:
1413 ?>