]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/CachedMarkup.php
Rename private functions without underscores
[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 __construct($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 (is_a($WikiTheme, 'WikiTheme_fusionforge')) {
49             return serialize($this);
50         }
51
52         return gzcompress(serialize($this), 9);
53     }
54
55     static function unpack($packed)
56     {
57         if (!$packed)
58             return false;
59
60         // ZLIB format has a five bit checksum in its header.
61         // Lets check for sanity.
62         if (((ord($packed[0]) * 256 + ord($packed[1])) % 31 == 0)
63             and (substr($packed, 0, 2) == "\037\213")
64             or (substr($packed, 0, 2) == "x\332")
65         ) // 120, 218
66         {
67             // Looks like ZLIB.
68             $data = gzuncompress($packed);
69             return unserialize($data);
70         }
71         if (substr($packed, 0, 2) == "O:") {
72             // Looks like a serialized object
73             return unserialize($packed);
74         }
75         if (preg_match("/^\w+$/", $packed))
76             return $packed;
77         // happened with DebugBackendInfo problem also.
78         trigger_error("Can't unpack bad cached markup. Probably php_zlib extension not loaded.",
79             E_USER_WARNING);
80         return false;
81     }
82
83     /** Get names of wikipages linked to.
84      *
85      * @return array of hashes { linkto=>pagename, relation=>pagename }
86      */
87     function getWikiPageLinks()
88     {
89         $links = array();
90         foreach ($this->_content as $item) {
91             if (!is_a($item, 'Cached_DynamicContent'))
92                 continue;
93             if (!($item_links = $item->getWikiPageLinks($this->_basepage)))
94                 continue;
95             $links = array_merge($links, $item_links);
96         }
97         // array_unique has a bug with hashes!
98         // set_links checks for duplicates, array_merge does not
99         //return array_unique($links);
100         return $links;
101     }
102
103     /** Get link info.
104      *
105      * This is here to support the XML-RPC listLinks() method.
106      *
107      * @return array
108      * Returns an array of hashes.
109      */
110     function getLinkInfo()
111     {
112         $links = array();
113         foreach ($this->_content as $link) {
114             if (!is_a($link, 'Cached_Link'))
115                 continue;
116             $info = $link->getLinkInfo($this->_basepage);
117             $links[$info->href] = $info;
118         }
119         return array_values($links);
120     }
121
122     function _append($item)
123     {
124         if (is_array($item)) {
125             foreach ($item as $subitem)
126                 $this->_append($subitem);
127         } elseif (!is_object($item)) {
128             $this->_buf .= $this->_quote((string)$item);
129         } elseif (is_a($item, 'Cached_DynamicContent')) {
130             if ($this->_buf) {
131                 $this->_content[] = $this->_buf;
132                 $this->_buf = '';
133             }
134             $this->_content[] = $item;
135         } elseif (is_a($item, 'XmlElement')) {
136             if ($item->isEmpty()) {
137                 $this->_buf .= $item->emptyTag();
138             } else {
139                 $this->_buf .= $item->startTag();
140                 foreach ($item->getContent() as $subitem)
141                     $this->_append($subitem);
142                 $this->_buf .= "</$item->_tag>";
143
144                 if (!$this->getDescription() and $item->getTag() == 'p') {
145                     // performance: when is this really needed?
146                     $this->_glean_description($item->asString());
147                 }
148             }
149             if (!$item->isInlineElement())
150                 $this->_buf .= "\n";
151         } elseif (is_a($item, 'XmlContent')) {
152             foreach ($item->getContent() as $item)
153                 $this->_append($item);
154         } elseif (method_exists($item, 'asXML')) {
155             $this->_buf .= $item->asXML();
156         } elseif (method_exists($item, 'asString')) {
157             $this->_buf .= $this->_quote($item->asString());
158         } else {
159             $this->_buf .= sprintf("==Object(%s)==", get_class($item));
160         }
161     }
162
163     function _glean_description($text)
164     {
165         static $two_sentences;
166         if (!$two_sentences) {
167             $two_sentences = "[.?!][\")]*\s+[\"(]*[[:upper:])]"
168                 . ".*"
169                 . "[.?!][\")]*\s*[\"(]*([[:upper:])]|$)";
170         }
171
172         if (!isset($this->_description) and preg_match("/$two_sentences/sx", $text))
173             $this->_description = preg_replace("/\s*\n\s*/", " ", trim($text));
174     }
175
176     /**
177      * Guess a short description of the page.
178      *
179      * Algorithm:
180      *
181      * This algorithm was suggested on MeatballWiki by
182      * Alex Schroeder <kensanata@yahoo.com>.
183      *
184      * Use the first paragraph in the page which contains at least two
185      * sentences.
186      *
187      * @see http://www.usemod.com/cgi-bin/mb.pl?MeatballWikiSuggestions
188      *
189      * @return string
190      */
191     function getDescription()
192     {
193         return isset($this->_description) ? $this->_description : '';
194     }
195
196     function asXML()
197     {
198         $xml = '';
199         $basepage = $this->_basepage;
200
201         foreach ($this->_content as $item) {
202             if (is_string($item)) {
203                 $xml .= $item;
204             } elseif (is_subclass_of($item, 'Cached_DynamicContent')
205             ) {
206                 $val = $item->expand($basepage, $this);
207                 $xml .= $val->asXML();
208             } else {
209                 $xml .= $item->asXML();
210             }
211         }
212         return $xml;
213     }
214
215     function printXML()
216     {
217         $basepage = $this->_basepage;
218         // _content might be changed from a plugin (CreateToc)
219         for ($i = 0; $i < count($this->_content); $i++) {
220             $item = $this->_content[$i];
221             if (is_string($item)) {
222                 print $item;
223             } elseif (is_subclass_of($item, 'Cached_DynamicContent')
224             ) { // give the content the chance to know about itself or even
225                 // to change itself
226                 $val = $item->expand($basepage, $this);
227                 if ($val) {
228                     $val->printXML();
229                 } else {
230                     if (DEBUG) {
231                         trigger_error('empty item ' . print_r($item, true));
232                     }
233                 }
234             } else {
235                 $item->printXML();
236             }
237         }
238     }
239 }
240
241 /**
242  * The base class for all dynamic content.
243  *
244  * Dynamic content is anything that can change even when the original
245  * wiki-text from which it was parsed is unchanged.
246  */
247 abstract class Cached_DynamicContent
248 {
249     function cache(&$cache)
250     {
251         $cache[] = $this;
252     }
253
254     abstract protected function expand($basepage, &$obj);
255
256     function getWikiPageLinks($basepage)
257     {
258         return false;
259     }
260 }
261
262 class XmlRpc_LinkInfo
263 {
264     function XmlRpc_LinkInfo($page, $type, $href, $relation = '')
265     {
266         $this->page = $page;
267         $this->type = $type;
268         $this->href = $href;
269         $this->relation = $relation;
270         //$this->pageref = str_replace("/RPC2.php", "/index.php", $href);
271     }
272 }
273
274 abstract class Cached_Link extends Cached_DynamicContent
275 {
276     public $_url;
277     public $_relation;
278
279     function isInlineElement()
280     {
281         return true;
282     }
283
284     /** Get link info (for XML-RPC support)
285      *
286      * This is here to support the XML-RPC listLinks method.
287      * (See http://www.ecyrd.com/JSPWiki/Wiki.jsp?page=WikiRPCInterface)
288      */
289     function getLinkInfo($basepage)
290     {
291         return new XmlRpc_LinkInfo($this->_getName($basepage),
292             $this->_getType(),
293             $this->_getURL($basepage),
294             $this->_getRelation($basepage));
295     }
296
297     function _getURL($basepage)
298     {
299         return $this->_url;
300     }
301
302     function __getRelation($basepage)
303     {
304         return $this->_relation;
305     }
306 }
307
308 /*
309  * Defer interwiki inline links. img src=upload:xx.png
310  * LinkImage($url, $alt = false)
311  */
312 class Cached_InlinedImage extends Cached_DynamicContent
313 {
314     public $_url;
315     public $_basepage;
316
317     function isInlineElement()
318     {
319         return true;
320     }
321
322     function _getURL($basepage)
323     {
324         return $this->_url;
325     }
326
327     // TODO: fix interwiki inline links in case of static dumps
328     function expand($basepage, &$markup)
329     {
330         global $WikiTheme;
331         $this->_basepage = $basepage;
332         $label = isset($this->_label) ? $this->_label : false;
333         if ($WikiTheme->DUMP_MODE) {
334             // In case of static dumps we need to check if we should
335             // inline the image or not: external: keep link, internal: copy locally
336             return LinkImage($label);
337         } else {
338             return LinkImage($label);
339         }
340     }
341 }
342
343 class Cached_WikiLink extends Cached_Link
344 {
345
346     /**
347      * @param string $page
348      * @param string $label
349      * @param string $anchor
350      */
351     function __construct($page, $label = '', $anchor = '')
352     {
353         $this->_page = $page;
354         /* ":DontStoreLink" */
355         if (substr($this->_page, 0, 1) == ':') {
356             $this->_page = substr($this->_page, 1);
357             $this->_nolink = true;
358         }
359         if ($anchor)
360             $this->_anchor = $anchor;
361         if ($label and $label != $page)
362             $this->_label = $label;
363         $this->_basepage = false;
364     }
365
366     function _getType()
367     {
368         return 'internal';
369     }
370
371     function getPagename($basepage)
372     {
373         $page = new WikiPageName($this->_page, $basepage);
374         if ($page->isValid())
375             return $page->name;
376         else
377             return false;
378     }
379
380     function getWikiPageLinks($basepage)
381     {
382         if ($basepage == '')
383             return false;
384         if (isset($this->_nolink))
385             return false;
386         if ($link = $this->getPagename($basepage))
387             return array(array('linkto' => $link));
388         else
389             return false;
390     }
391
392     function _getName($basepage)
393     {
394         return $this->getPagename($basepage);
395     }
396
397     function _getURL($basepage)
398     {
399         return WikiURL($this->getPagename($basepage));
400         //return WikiURL($this->getPagename($basepage), false, 'abs_url');
401     }
402
403     function expand($basepage, &$markup)
404     {
405         global $WikiTheme;
406         $this->_basepage = $basepage;
407         $label = isset($this->_label) ? $this->_label : false;
408         $anchor = isset($this->_anchor) ? (string)$this->_anchor : '';
409         $page = new WikiPageName($this->_page, $basepage, $anchor);
410         if ($WikiTheme->DUMP_MODE and !empty($WikiTheme->VALID_LINKS)) {
411             if (!in_array($this->_page, $WikiTheme->VALID_LINKS))
412                 return HTML($label ? $label : $page->getName());
413         }
414         if ($page->isValid()) return WikiLink($page, 'auto', $label);
415         else return HTML($label);
416     }
417
418     function asXML()
419     {
420         global $WikiTheme;
421         $label = isset($this->_label) ? $this->_label : false;
422         $anchor = isset($this->_anchor) ? (string)$this->_anchor : '';
423         //TODO: need basepage for subpages like /Remove (within CreateTOC)
424         $page = new WikiPageName($this->_page, $this->_basepage, $anchor);
425         if ($WikiTheme->DUMP_MODE and $WikiTheme->VALID_LINKS) {
426             if (!in_array($this->_page, $WikiTheme->VALID_LINKS))
427                 return $label ? $label : $page->getName();
428         }
429         $link = WikiLink($page, 'auto', $label);
430         return $link->asXML();
431     }
432
433     function asString()
434     {
435         if (isset($this->_label))
436             return $this->_label;
437         return $this->_page;
438     }
439 }
440
441 class Cached_WikiLinkIfKnown extends Cached_WikiLink
442 {
443     function __construct($moniker)
444     {
445         $this->_page = $moniker;
446     }
447
448     function expand($basepage, &$markup)
449     {
450         global $WikiTheme;
451         if ($WikiTheme->DUMP_MODE and $WikiTheme->VALID_LINKS) {
452             if (!in_array($this->_page, $WikiTheme->VALID_LINKS))
453                 return HTML($label ? $label : $page->getName());
454         }
455         return WikiLink($this->_page, 'if_known');
456     }
457 }
458
459 class Cached_SpellCheck extends Cached_WikiLink
460 {
461     function __construct($word, $suggs)
462     {
463         $this->_page = $word;
464         $this->suggestions = $suggs;
465     }
466
467     function expand($basepage, &$markup)
468     {
469         $link = HTML::a(array('class' => 'spell-wrong',
470                 'title' => 'SpellCheck: ' . join(', ', $this->suggestions),
471                 'name' => $this->_page),
472             $this->_page);
473         return $link;
474     }
475 }
476
477 class Cached_PhpwikiURL extends Cached_DynamicContent
478 {
479     public $_page;
480
481     function __construct($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     public $_attribute;
532     public $_attribute_base;
533     public $_unit;
534
535     function __construct($url, $label = false)
536     {
537         $this->_url = $url;
538         if ($label && $label != $url)
539             $this->_label = $label;
540         $this->_expandurl($this->_url);
541     }
542
543     function isInlineElement()
544     {
545         return true;
546     }
547
548     function getPagename($basepage)
549     {
550         if (!isset($this->_page)) return false;
551         $page = new WikiPageName($this->_page, $basepage);
552         if ($page->isValid()) return $page->name;
553         else return false;
554     }
555
556     /* Add relation to the link table.
557      * attributes have the _relation, but not the _page set.
558      */
559     function getWikiPageLinks($basepage)
560     {
561         if ($basepage == '') return false;
562         if (!isset($this->_page) and isset($this->_attribute)) {
563             // An attribute: we store it in the basepage now, to fill the cache for page->save
564             // TODO: side-effect free query
565             $page = $GLOBALS['request']->getPage($basepage);
566             $page->setAttribute($this->_relation, $this->_attribute);
567             $this->_page = $basepage;
568             return array(array('linkto' => '', 'relation' => $this->_relation));
569         }
570         if ($link = $this->getPagename($basepage))
571             return array(array('linkto' => $link, 'relation' => $this->_relation));
572         else
573             return false;
574     }
575
576     function _expandurl($url)
577     {
578         $m = array();
579         if (!preg_match('/^ ([^:]+) (:[:=]) (.+) $/x', $url, $m)) {
580             return HTML::span(array('class' => 'error'), _("BAD semantic relation link"));
581         }
582         $this->_relation = urldecode($m[1]);
583         $is_attribute = ($m[2] == ':=');
584         if ($is_attribute) {
585             $this->_attribute = urldecode($m[3]);
586             // since this stored in the markup cache, we are extra sensible
587             // not to store false empty stuff.
588             $units = new Units();
589             if (!DISABLE_UNITS and !$units->errcode) {
590                 $this->_attribute_base = $units->Definition($this->_attribute);
591                 $this->_unit = $units->baseunit($this->_attribute);
592             }
593         } else {
594             $this->_page = urldecode($m[3]);
595         }
596         return $m;
597     }
598
599     function _expand($url, $label = false)
600     {
601         global $WikiTheme;
602         $m = $this->_expandurl($url);
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 __construct($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 __construct($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 __construct($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()) {
745             return $page->name;
746         } else {
747             return false;
748         }
749     }
750
751     function getWikiPageLinks($basepage)
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 = $GLOBALS['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 setTightness($top, $bottom)
842     {
843     }
844
845     function isInlineElement()
846     {
847         return false;
848     }
849
850     function expand($basepage, &$markup)
851     {
852         $loader = $this->_getLoader();
853         $xml = $loader->expandPI($this->_pi, $GLOBALS['request'], $markup, $basepage);
854         return $xml;
855     }
856
857     function asString()
858     {
859         return $this->_pi;
860     }
861
862     function getWikiPageLinks($basepage)
863     {
864         $loader = $this->_getLoader();
865
866         return $loader->getWikiPageLinks($this->_pi, $basepage);
867     }
868
869     function & _getLoader()
870     {
871         static $loader = false;
872
873         if (!$loader) {
874             include_once 'lib/WikiPlugin.php';
875             $loader = new WikiPluginLoader();
876         }
877         return $loader;
878     }
879 }
880
881 // Local Variables:
882 // mode: php
883 // tab-width: 8
884 // c-basic-offset: 4
885 // c-hanging-comment-ender-p: nil
886 // indent-tabs-mode: nil
887 // End: