]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/CachedMarkup.php
Allow bold, italics or underlined for numbers
[SourceForge/phpwiki.git] / lib / CachedMarkup.php
1 <?php
2
3 /* Copyright (C) 2002 Geoffrey T. Dairiki <dairiki@dairiki.org>
4  * Copyright (C) 2004-2010 $ThePhpWikiProgrammingTeam
5  * Copyright (C) 2008-2009 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 require_once 'lib/Units.php';
25
26 class CacheableMarkup extends XmlContent
27 {
28
29     function CacheableMarkup($content, $basepage)
30     {
31         $this->_basepage = $basepage;
32         $this->_buf = '';
33         $this->_content = array();
34         $this->_append($content);
35         if ($this->_buf != '')
36             $this->_content[] = $this->_buf;
37         unset($this->_buf);
38     }
39
40     function pack()
41     {
42         // FusionForge hack
43         // This causes a strange bug when a comment containing
44         // a single quote is entered in the Summary box:
45         // - the history is wrong (user and comment missing)
46         // - the table of contents plugin no longer works
47         global $WikiTheme;
48         if (isa($WikiTheme, 'WikiTheme_fusionforge')) {
49             return serialize($this);
50         }
51
52         if (function_exists('gzcompress'))
53             return gzcompress(serialize($this), 9);
54         return serialize($this);
55
56         // FIXME: probably should implement some sort of "compression"
57         //   when no gzcompress is available.
58     }
59
60     function unpack($packed)
61     {
62         if (!$packed)
63             return false;
64
65         // ZLIB format has a five bit checksum in it's header.
66         // Lets check for sanity.
67         if (((ord($packed[0]) * 256 + ord($packed[1])) % 31 == 0)
68             and (substr($packed, 0, 2) == "\037\213")
69             or (substr($packed, 0, 2) == "x\332")
70         ) // 120, 218
71         {
72             if (function_exists('gzuncompress')) {
73                 // Looks like ZLIB.
74                 $data = gzuncompress($packed);
75                 return unserialize($data);
76             } else {
77                 // user our php lib. TESTME
78                 include_once 'ziplib.php';
79                 $zip = new ZipReader($packed);
80                 list(, $data, $attrib) = $zip->readFile();
81                 return unserialize($data);
82             }
83         }
84         if (substr($packed, 0, 2) == "O:") {
85             // Looks like a serialized object
86             return unserialize($packed);
87         }
88         if (preg_match("/^\w+$/", $packed))
89             return $packed;
90         // happened with DebugBackendInfo problem also.
91         trigger_error("Can't unpack bad cached markup. Probably php_zlib extension not loaded.",
92             E_USER_WARNING);
93         return false;
94     }
95
96     /** Get names of wikipages linked to.
97      *
98      * @return array of hashes { linkto=>pagename, relation=>pagename }
99      */
100     function getWikiPageLinks()
101     {
102         $links = array();
103         foreach ($this->_content as $item) {
104             if (!isa($item, 'Cached_DynamicContent'))
105                 continue;
106             if (!($item_links = $item->getWikiPageLinks($this->_basepage)))
107                 continue;
108             $links = array_merge($links, $item_links);
109         }
110         // array_unique has a bug with hashes!
111         // set_links checks for duplicates, array_merge does not
112         //return array_unique($links);
113         return $links;
114     }
115
116     /** Get link info.
117      *
118      * This is here to support the XML-RPC listLinks() method.
119      *
120      * @return array
121      * Returns an array of hashes.
122      */
123     function getLinkInfo()
124     {
125         foreach ($this->_content as $link) {
126             if (!isa($link, 'Cached_Link'))
127                 continue;
128             $info = $link->getLinkInfo($this->_basepage);
129             $links[$info->href] = $info;
130         }
131         return array_values($links);
132     }
133
134     function _append($item)
135     {
136         if (is_array($item)) {
137             foreach ($item as $subitem)
138                 $this->_append($subitem);
139         } elseif (!is_object($item)) {
140             $this->_buf .= $this->_quote((string)$item);
141         } elseif (isa($item, 'Cached_DynamicContent')) {
142             if ($this->_buf) {
143                 $this->_content[] = $this->_buf;
144                 $this->_buf = '';
145             }
146             $this->_content[] = $item;
147         } elseif (isa($item, 'XmlElement')) {
148             if ($item->isEmpty()) {
149                 $this->_buf .= $item->emptyTag();
150             } else {
151                 $this->_buf .= $item->startTag();
152                 foreach ($item->getContent() as $subitem)
153                     $this->_append($subitem);
154                 $this->_buf .= "</$item->_tag>";
155
156                 if (!$this->getDescription() and $item->getTag() == 'p') {
157                     // performance: when is this really needed?
158                     $this->_glean_description($item->asString());
159                 }
160             }
161             if (!$item->isInlineElement())
162                 $this->_buf .= "\n";
163         } elseif (isa($item, 'XmlContent')) {
164             foreach ($item->getContent() as $item)
165                 $this->_append($item);
166         } elseif (method_exists($item, 'asXML')) {
167             $this->_buf .= $item->asXML();
168         } elseif (method_exists($item, 'asString')) {
169             $this->_buf .= $this->_quote($item->asString());
170         } else {
171             $this->_buf .= sprintf("==Object(%s)==", get_class($item));
172         }
173     }
174
175     function _glean_description($text)
176     {
177         static $two_sentences;
178         if (!$two_sentences) {
179             $two_sentences = "[.?!][\")]*\s+[\"(]*[[:upper:])]"
180                 . ".*"
181                 . "[.?!][\")]*\s*[\"(]*([[:upper:])]|$)";
182         }
183
184         if (!isset($this->_description) and preg_match("/$two_sentences/sx", $text))
185             $this->_description = preg_replace("/\s*\n\s*/", " ", trim($text));
186     }
187
188     /**
189      * Guess a short description of the page.
190      *
191      * Algorithm:
192      *
193      * This algorithm was suggested on MeatballWiki by
194      * Alex Schroeder <kensanata@yahoo.com>.
195      *
196      * Use the first paragraph in the page which contains at least two
197      * sentences.
198      *
199      * @see http://www.usemod.com/cgi-bin/mb.pl?MeatballWikiSuggestions
200      *
201      * @return string
202      */
203     function getDescription()
204     {
205         return isset($this->_description) ? $this->_description : '';
206     }
207
208     function asXML()
209     {
210         $xml = '';
211         $basepage = $this->_basepage;
212
213         foreach ($this->_content as $item) {
214             if (is_string($item)) {
215                 $xml .= $item;
216             } elseif (is_subclass_of($item, 'Cached_DynamicContent')
217             ) {
218                 $val = $item->expand($basepage, $this);
219                 $xml .= $val->asXML();
220             } else {
221                 $xml .= $item->asXML();
222             }
223         }
224         return $xml;
225     }
226
227     function printXML()
228     {
229         $basepage = $this->_basepage;
230         // _content might be changed from a plugin (CreateToc)
231         for ($i = 0; $i < count($this->_content); $i++) {
232             $item = $this->_content[$i];
233             if (is_string($item)) {
234                 print $item;
235             } elseif (is_subclass_of($item, 'Cached_DynamicContent')
236             ) { // give the content the chance to know about itself or even
237                 // to change itself
238                 $val = $item->expand($basepage, $this);
239                 if ($val) {
240                     $val->printXML();
241                 } else {
242                     if (DEBUG) {
243                         trigger_error('empty item ' . print_r($item, true));
244                     }
245                 }
246             } else {
247                 $item->printXML();
248             }
249         }
250     }
251 }
252
253 /**
254  * The base class for all dynamic content.
255  *
256  * Dynamic content is anything that can change even when the original
257  * wiki-text from which it was parsed is unchanged.
258  */
259 class Cached_DynamicContent
260 {
261
262     function cache(&$cache)
263     {
264         $cache[] = $this;
265     }
266
267     function expand($basepage, &$obj)
268     {
269         trigger_error("Pure virtual", E_USER_ERROR);
270     }
271
272     function getWikiPageLinks($basepage)
273     {
274         return false;
275     }
276 }
277
278 class XmlRpc_LinkInfo
279 {
280     function XmlRpc_LinkInfo($page, $type, $href, $relation = '')
281     {
282         $this->page = $page;
283         $this->type = $type;
284         $this->href = $href;
285         $this->relation = $relation;
286         //$this->pageref = str_replace("/RPC2.php", "/index.php", $href);
287     }
288 }
289
290 class Cached_Link extends Cached_DynamicContent
291 {
292
293     function isInlineElement()
294     {
295         return true;
296     }
297
298     /** Get link info (for XML-RPC support)
299      *
300      * This is here to support the XML-RPC listLinks method.
301      * (See http://www.ecyrd.com/JSPWiki/Wiki.jsp?page=WikiRPCInterface)
302      */
303     function getLinkInfo($basepage)
304     {
305         return new XmlRpc_LinkInfo($this->_getName($basepage),
306             $this->_getType(),
307             $this->_getURL($basepage),
308             $this->_getRelation($basepage));
309     }
310
311     function _getURL($basepage)
312     {
313         return $this->_url;
314     }
315
316     function __getRelation($basepage)
317     {
318         return $this->_relation;
319     }
320 }
321
322 /*
323  * Defer interwiki inline links. img src=upload:xx.png
324  * LinkImage($url, $alt = false)
325  */
326 class Cached_InlinedImage extends Cached_DynamicContent
327 {
328     function isInlineElement()
329     {
330         return true;
331     }
332
333     function _getURL($basepage)
334     {
335         return $this->_url;
336     }
337
338     // TODO: fix interwiki inline links in case of static dumps
339     function expand($basepage, &$markup)
340     {
341         global $WikiTheme;
342         $this->_basepage = $basepage;
343         $label = isset($this->_label) ? $this->_label : false;
344         if ($WikiTheme->DUMP_MODE) {
345             // In case of static dumps we need to check if we should
346             // inline the image or not: external: keep link, internal: copy locally
347             return LinkImage($label);
348         } else {
349             return LinkImage($label);
350         }
351     }
352 }
353
354 class Cached_WikiLink extends Cached_Link
355 {
356
357     function Cached_WikiLink($page, $label = false, $anchor = false)
358     {
359         $this->_page = $page;
360         /* ":DontStoreLink" */
361         if (substr($this->_page, 0, 1) == ':') {
362             $this->_page = substr($this->_page, 1);
363             $this->_nolink = true;
364         }
365         if ($anchor)
366             $this->_anchor = $anchor;
367         if ($label and $label != $page)
368             $this->_label = $label;
369         $this->_basepage = false;
370     }
371
372     function _getType()
373     {
374         return 'internal';
375     }
376
377     function getPagename($basepage)
378     {
379         $page = new WikiPageName($this->_page, $basepage);
380         if ($page->isValid()) return $page->name;
381         else return false;
382     }
383
384     function getWikiPageLinks($basepage)
385     {
386         if ($basepage == '') return false;
387         if (isset($this->_nolink)) return false;
388         if ($link = $this->getPagename($basepage))
389             return array(array('linkto' => $link));
390         else
391             return false;
392     }
393
394     function _getName($basepage)
395     {
396         return $this->getPagename($basepage);
397     }
398
399     function _getURL($basepage)
400     {
401         return WikiURL($this->getPagename($basepage));
402         //return WikiURL($this->getPagename($basepage), false, 'abs_url');
403     }
404
405     function expand($basepage, &$markup)
406     {
407         global $WikiTheme;
408         $this->_basepage = $basepage;
409         $label = isset($this->_label) ? $this->_label : false;
410         $anchor = isset($this->_anchor) ? (string)$this->_anchor : '';
411         $page = new WikiPageName($this->_page, $basepage, $anchor);
412         if ($WikiTheme->DUMP_MODE and !empty($WikiTheme->VALID_LINKS)) {
413             if (!in_array($this->_page, $WikiTheme->VALID_LINKS))
414                 return HTML($label ? $label : $page->getName());
415         }
416         if ($page->isValid()) return WikiLink($page, 'auto', $label);
417         else return HTML($label);
418     }
419
420     function asXML()
421     {
422         global $WikiTheme;
423         $label = isset($this->_label) ? $this->_label : false;
424         $anchor = isset($this->_anchor) ? (string)$this->_anchor : '';
425         //TODO: need basepage for subpages like /Remove (within CreateTOC)
426         $page = new WikiPageName($this->_page, $this->_basepage, $anchor);
427         if ($WikiTheme->DUMP_MODE and $WikiTheme->VALID_LINKS) {
428             if (!in_array($this->_page, $WikiTheme->VALID_LINKS))
429                 return $label ? $label : $page->getName();
430         }
431         $link = WikiLink($page, 'auto', $label);
432         return $link->asXML();
433     }
434
435     function asString()
436     {
437         if (isset($this->_label))
438             return $this->_label;
439         return $this->_page;
440     }
441 }
442
443 class Cached_WikiLinkIfKnown extends Cached_WikiLink
444 {
445     function Cached_WikiLinkIfKnown($moniker)
446     {
447         $this->_page = $moniker;
448     }
449
450     function expand($basepage, &$markup)
451     {
452         global $WikiTheme;
453         if ($WikiTheme->DUMP_MODE and $WikiTheme->VALID_LINKS) {
454             if (!in_array($this->_page, $WikiTheme->VALID_LINKS))
455                 return HTML($label ? $label : $page->getName());
456         }
457         return WikiLink($this->_page, 'if_known');
458     }
459 }
460
461 class Cached_SpellCheck extends Cached_WikiLink
462 {
463     function Cached_SpellCheck($word, $suggs)
464     {
465         $this->_page = $word;
466         $this->suggestions = $suggs;
467     }
468
469     function expand($basepage, &$markup)
470     {
471         $link = HTML::a(array('class' => 'spell-wrong',
472                 'title' => 'SpellCheck: ' . join(', ', $this->suggestions),
473                 'name' => $this->_page),
474             $this->_page);
475         return $link;
476     }
477 }
478
479 class Cached_PhpwikiURL extends Cached_DynamicContent
480 {
481     function Cached_PhpwikiURL($url, $label)
482     {
483         $this->_url = $url;
484         if ($label)
485             $this->_label = $label;
486     }
487
488     function isInlineElement()
489     {
490         return true;
491     }
492
493     function expand($basepage, &$markup)
494     {
495         global $WikiTheme;
496         $label = isset($this->_label) ? $this->_label : false;
497         if ($WikiTheme->DUMP_MODE and $WikiTheme->VALID_LINKS) {
498             if (!in_array($this->_page, $WikiTheme->VALID_LINKS))
499                 return HTML($label ? $label : $page->getName());
500         }
501         return LinkPhpwikiURL($this->_url, $label, $basepage);
502     }
503
504     function asXML()
505     {
506         $label = isset($this->_label) ? $this->_label : false;
507         $link = LinkPhpwikiURL($this->_url, $label);
508         return $link->asXML();
509     }
510
511     function asString()
512     {
513         if (isset($this->_label))
514             return $this->_label;
515         return $this->_url;
516     }
517 }
518
519 /*
520  * Relations (::) are named links to pages.
521  * Attributes (:=) are named metadata per page, "named links to numbers with units".
522  * We don't want to exhaust the linktable with numbers,
523  * since this would create empty pages per each value,
524  * so we don't store the attributes as full relationlink.
525  * But we do store the attribute name as relation with an empty pagename
526  * to denote that this is an attribute,
527  * and to enable a fast listRelations mode=attributes
528  */
529 class Cached_SemanticLink extends Cached_WikiLink
530 {
531
532     function Cached_SemanticLink($url, $label = false)
533     {
534         $this->_url = $url;
535         if ($label && $label != $url)
536             $this->_label = $label;
537         $this->_expandurl($this->_url);
538     }
539
540     function isInlineElement()
541     {
542         return true;
543     }
544
545     function getPagename($basepage)
546     {
547         if (!isset($this->_page)) return false;
548         $page = new WikiPageName($this->_page, $basepage);
549         if ($page->isValid()) return $page->name;
550         else return false;
551     }
552
553     /* Add relation to the link table.
554      * attributes have the _relation, but not the _page set.
555      */
556     function getWikiPageLinks($basepage)
557     {
558         if ($basepage == '') return false;
559         if (!isset($this->_page) and isset($this->_attribute)) {
560             // An attribute: we store it in the basepage now, to fill the cache for page->save
561             // TODO: side-effect free query
562             $page = $GLOBALS['request']->getPage($basepage);
563             $page->setAttribute($this->_relation, $this->_attribute);
564             $this->_page = $basepage;
565             return array(array('linkto' => '', 'relation' => $this->_relation));
566         }
567         if ($link = $this->getPagename($basepage))
568             return array(array('linkto' => $link, 'relation' => $this->_relation));
569         else
570             return false;
571     }
572
573     function _expandurl($url)
574     {
575         $m = array();
576         if (!preg_match('/^ ([^:]+) (:[:=]) (.+) $/x', $url, $m)) {
577             return HTML::span(array('class' => 'error'), _("BAD semantic relation link"));
578         }
579         $this->_relation = urldecode($m[1]);
580         $is_attribute = ($m[2] == ':=');
581         if ($is_attribute) {
582             $this->_attribute = urldecode($m[3]);
583             // since this stored in the markup cache, we are extra sensible
584             // not to store false empty stuff.
585             $units = new Units();
586             if (!DISABLE_UNITS and !$units->errcode) {
587                 $this->_attribute_base = $units->Definition($this->_attribute);
588                 $this->_unit = $units->baseunit($this->_attribute);
589             }
590         } else {
591             $this->_page = urldecode($m[3]);
592         }
593         return $m;
594     }
595
596     function _expand($url, $label = false)
597     {
598         global $WikiTheme;
599         $m = $this->_expandurl($url);
600         $class = 'wiki';
601         // do not link to the attribute value, but to the attribute
602         $is_attribute = ($m[2] == ':=');
603         if ($WikiTheme->DUMP_MODE and $WikiTheme->VALID_LINKS) {
604             if (isset($this->_page) and !in_array($this->_page, $WikiTheme->VALID_LINKS))
605                 return HTML($label ? $label : ($is_attribute ? $this->_relation : $this->_page));
606         }
607         if ($is_attribute)
608             $title = isset($this->_attribute_base)
609                 ? sprintf(_("Attribute %s, base value: %s"), $this->_relation, $this->_attribute_base)
610                 : sprintf(_("Attribute %s, value: %s"), $this->_relation, $this->_attribute);
611         if ($label) {
612             return HTML::span(
613                 HTML::a(array('href' => WikiURL($is_attribute ? $this->_relation : $this->_page),
614                         'class' => "wiki " . ($is_attribute ? "attribute" : "relation"),
615                         'title' => $is_attribute
616                             ? $title
617                             : sprintf(_("Relation %s to page %s"), $this->_relation, $this->_page)),
618                     $label)
619             );
620         } elseif ($is_attribute) {
621             return HTML::span
622             (
623                 HTML::a(array('href' => WikiURL($this->_relation),
624                         'class' => "wiki attribute",
625                         'title' => $title),
626                     $url)
627             );
628         } else {
629             return HTML::span
630             (
631                 HTML::a(array('href' => WikiURL($this->_relation),
632                         'class' => "wiki relation"),
633                     $this->_relation),
634                 HTML::span(array('class' => 'relation-symbol'), $m[2]),
635                 HTML::a(array('href' => WikiURL($this->_page),
636                         'class' => "wiki"),
637                     $this->_page)
638             );
639         }
640     }
641
642     function expand($basepage, &$markup)
643     {
644         $label = isset($this->_label) ? $this->_label : false;
645         return $this->_expand($this->_url, $label);
646     }
647
648     function asXML()
649     {
650         $label = isset($this->_label) ? $this->_label : false;
651         $link = $this->_expand($this->_url, $label);
652         return $link->asXML();
653     }
654
655     function asString()
656     {
657         if (isset($this->_label))
658             return $this->_label;
659         return $this->_url;
660     }
661 }
662
663 /**
664  * Highlight found search engine terms
665  */
666 class Cached_SearchHighlight extends Cached_DynamicContent
667 {
668     function Cached_SearchHighlight($word, $engine)
669     {
670         $this->_word = $word;
671         $this->engine = $engine;
672     }
673
674     function expand($basepage, &$markup)
675     {
676         return HTML::span(array('class' => 'search-term',
677                 'title' => _("Found by ") . $this->engine),
678             $this->_word);
679     }
680 }
681
682 class Cached_ExternalLink extends Cached_Link
683 {
684
685     function Cached_ExternalLink($url, $label = false)
686     {
687         $this->_url = $url;
688         if ($label && $label != $url)
689             $this->_label = $label;
690     }
691
692     function _getType()
693     {
694         return 'external';
695     }
696
697     function _getName($basepage)
698     {
699         $label = isset($this->_label) ? $this->_label : false;
700         return ($label and is_string($label)) ? $label : $this->_url;
701     }
702
703     function expand($basepage, &$markup)
704     {
705         global $request;
706
707         $label = isset($this->_label) ? $this->_label : false;
708         $link = LinkURL($this->_url, $label);
709
710         if (GOOGLE_LINKS_NOFOLLOW) {
711             // Ignores nofollow when the user who saved the page was authenticated.
712             $page = $request->getPage($basepage);
713             $current = $page->getCurrentRevision(false);
714             if (!$current->get('author_id'))
715                 $link->setAttr('rel', 'nofollow');
716         }
717         return $link;
718     }
719
720     function asString()
721     {
722         if (isset($this->_label) and is_string($this->_label))
723             return $this->_label;
724         return $this->_url;
725     }
726 }
727
728 class Cached_InterwikiLink extends Cached_ExternalLink
729 {
730
731     function Cached_InterwikiLink($link, $label = false)
732     {
733         $this->_link = $link;
734         if ($label)
735             $this->_label = $label;
736     }
737
738     function getPagename($basepage)
739     {
740         list ($moniker, $page) = explode(":", $this->_link, 2);
741         $page = new WikiPageName($page, $basepage);
742         if ($page->isValid()) return $page->name;
743         else return false;
744     }
745
746     function getWikiPageLinks($basepage)
747     {
748         if ($basepage == '') return false;
749         /* ":DontStoreLink" */
750         if (substr($this->_link, 0, 1) == ':') return false;
751         /* store only links to valid pagenames */
752         $dbi = $GLOBALS['request']->getDbh();
753         if ($link = $this->getPagename($basepage) and $dbi->isWikiPage($link)) {
754             return array(array('linkto' => $link));
755         } else {
756             return false; // dont store external links
757         }
758     }
759
760     function _getName($basepage)
761     {
762         $label = isset($this->_label) ? $this->_label : false;
763         return ($label and is_string($label)) ? $label : $this->_link;
764     }
765
766     /* there may be internal interwiki links also */
767     function _getType()
768     {
769         return $this->getPagename(false) ? 'internal' : 'external';
770     }
771
772     function _getURL($basepage)
773     {
774         $link = $this->expand($basepage, $this);
775         return $link->getAttr('href');
776     }
777
778     function expand($basepage, &$markup)
779     {
780         global $WikiTheme;
781         $intermap = getInterwikiMap();
782         $label = isset($this->_label) ? $this->_label : false;
783         //FIXME: check Upload: inlined images
784         if ($WikiTheme->DUMP_MODE and !empty($WikiTheme->VALID_LINKS)) {
785             if (!in_array($this->_link, $WikiTheme->VALID_LINKS))
786                 return HTML($label ? $label : $this->_link);
787         }
788         return $intermap->link($this->_link, $label);
789     }
790
791     function asString()
792     {
793         if (isset($this->_label))
794             return $this->_label;
795         return $this->_link;
796     }
797 }
798
799 // Needed to put UserPages to backlinks. Special method to markup userpages with icons
800 // Thanks to PhpWiki:DanFr for finding this bug.
801 // Fixed since 1.3.8, prev. versions had no userpages in backlinks
802 class Cached_UserLink extends Cached_WikiLink
803 {
804     function expand($basepage, &$markup)
805     {
806         $label = isset($this->_label) ? $this->_label : false;
807         $anchor = isset($this->_anchor) ? (string)$this->_anchor : '';
808         $page = new WikiPageName($this->_page, $basepage, $anchor);
809         $link = WikiLink($page, 'auto', $label);
810         // $link = HTML::a(array('href' => $PageName));
811         $link->setContent(PossiblyGlueIconToText('wikiuser', $this->_page));
812         $link->setAttr('class', 'wikiuser');
813         return $link;
814     }
815 }
816
817 /**
818  * 1.3.13: Previously stored was only _pi.
819  * A fresh generated cache has now ->name and ->args also.
820  * main::isActionPage only checks the raw content.
821  */
822 class Cached_PluginInvocation extends Cached_DynamicContent
823 {
824
825     function Cached_PluginInvocation($pi)
826     {
827         $this->_pi = $pi;
828         $loader = $this->_getLoader();
829         if (is_array($plugin_cmdline = $loader->parsePI($pi)) and $plugin_cmdline[1]) {
830             $this->pi_name = $plugin_cmdline[0]; // plugin, plugin-form, plugin-list
831             $this->name = $plugin_cmdline[1]->getName();
832             $this->args = $plugin_cmdline[2];
833         }
834     }
835
836     function setTightness($top, $bottom)
837     {
838     }
839
840     function isInlineElement()
841     {
842         return false;
843     }
844
845     function expand($basepage, &$markup)
846     {
847         $loader = $this->_getLoader();
848         $xml = $loader->expandPI($this->_pi, $GLOBALS['request'], $markup, $basepage);
849         return $xml;
850     }
851
852     function asString()
853     {
854         return $this->_pi;
855     }
856
857     function getWikiPageLinks($basepage)
858     {
859         $loader = $this->_getLoader();
860
861         return $loader->getWikiPageLinks($this->_pi, $basepage);
862     }
863
864     function & _getLoader()
865     {
866         static $loader = false;
867
868         if (!$loader) {
869             include_once 'lib/WikiPlugin.php';
870             $loader = new WikiPluginLoader();
871         }
872         return $loader;
873     }
874 }
875
876 // Local Variables:
877 // mode: php
878 // tab-width: 8
879 // c-basic-offset: 4
880 // c-hanging-comment-ender-p: nil
881 // indent-tabs-mode: nil
882 // End: