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