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