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