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