]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/CachedMarkup.php
protect $WikiTheme->VALID_LINKS
[SourceForge/phpwiki.git] / lib / CachedMarkup.php
1 <?php 
2 rcs_id('$Id: CachedMarkup.php,v 1.63 2008-03-17 19:03:08 rurban Exp $');
3 /* Copyright (C) 2002 Geoffrey T. Dairiki <dairiki@dairiki.org>
4  * Copyright (C) 2004,2005,2006,2007 $ThePhpWikiProgrammingTeam
5  *
6  * This file is part of PhpWiki.
7  * 
8  * PhpWiki is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  * 
13  * PhpWiki is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  * 
18  * You should have received a copy of the GNU General Public License
19  * along with PhpWiki; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 require_once("lib/Units.php");
24
25 class CacheableMarkup extends XmlContent {
26
27     function CacheableMarkup($content, $basepage) {
28         $this->_basepage = $basepage;
29         $this->_buf = '';
30         $this->_content = array();
31         $this->_append($content);
32         if ($this->_buf != '')
33             $this->_content[] = $this->_buf;
34         unset($this->_buf);
35     }
36
37     function pack() {
38         if (function_exists('gzcompress'))
39             return gzcompress(serialize($this), 9);
40         return serialize($this);
41
42         // FIXME: probably should implement some sort of "compression"
43         //   when no gzcompress is available.
44     }
45
46     function unpack($packed) {
47         if (!$packed)
48             return false;
49
50         // ZLIB format has a five bit checksum in it's header.
51         // Lets check for sanity.
52         if (((ord($packed[0]) * 256 + ord($packed[1])) % 31 == 0)
53              and (substr($packed,0,2) == "\037\213") 
54                   or (substr($packed,0,2) == "x\332"))   // 120, 218
55         {
56             if (function_exists('gzuncompress')) {
57                 // Looks like ZLIB.
58                 $data = gzuncompress($packed);
59                 return unserialize($data);
60             } else {
61                 // user our php lib. TESTME
62                 include_once("ziplib.php");
63                 $zip = new ZipReader($packed);
64                 list(,$data,$attrib) = $zip->readFile();
65                 return unserialize($data);
66             }
67         }
68         if (substr($packed,0,2) == "O:") {
69             // Looks like a serialized object
70             return unserialize($packed);
71         }
72         if (preg_match("/^\w+$/", $packed))
73             return $packed;
74         // happened with _BackendInfo problem also.
75         trigger_error("Can't unpack bad cached markup. Probably php_zlib extension not loaded.", 
76                       E_USER_WARNING);
77         return false;
78     }
79     
80     /** Get names of wikipages linked to.
81      *
82      * @return array of hashes { linkto=>pagename, relation=>pagename }
83      */
84     function getWikiPageLinks() {
85         $links = array();
86         foreach ($this->_content as $item) {
87             if (!isa($item, 'Cached_DynamicContent'))
88                 continue;
89             if (!($item_links = $item->getWikiPageLinks($this->_basepage)))
90                 continue;
91             $links = array_merge($links, $item_links);
92         }
93         // array_unique has a bug with hashes! 
94         // set_links checks for duplicates, array_merge does not
95         //return array_unique($links);
96         return $links;
97     }
98
99     /** Get link info.
100      *
101      * This is here to support the XML-RPC listLinks() method.
102      *
103      * @return array
104      * Returns an array of hashes.
105      */
106     function getLinkInfo() {
107         $link = array();
108         foreach ($this->_content as $link) {
109             if (! isa($link, 'Cached_Link'))
110                 continue;
111             $info = $link->getLinkInfo($this->_basepage);
112             $links[$info->href] = $info;
113         }
114         return array_values($links);
115     }
116
117     function _append($item) {
118         if (is_array($item)) {
119             foreach ($item as $subitem)
120                 $this->_append($subitem);
121         }
122         elseif (!is_object($item)) {
123             $this->_buf .= $this->_quote((string) $item);
124         }
125         elseif (isa($item, 'Cached_DynamicContent')) {
126             if ($this->_buf) {
127                 $this->_content[] = $this->_buf;
128                 $this->_buf = '';
129             }
130             $this->_content[] = $item;
131         }
132         elseif (isa($item, 'XmlElement')) {
133             if ($item->isEmpty()) {
134                 $this->_buf .= $item->emptyTag();
135             }
136             else {
137                 $this->_buf .= $item->startTag();
138                 foreach ($item->getContent() as $subitem)
139                     $this->_append($subitem);
140                 $this->_buf .= "</$item->_tag>";
141
142                 if (!isset($this->_description) and $item->getTag() == 'p')
143                     $this->_glean_description($item->asString());
144             }
145             if (!$item->isInlineElement())
146                 $this->_buf .= "\n";
147         }
148         elseif (isa($item, 'XmlContent')) {
149             foreach ($item->getContent() as $item)
150                 $this->_append($item);
151         }
152         elseif (method_exists($item, 'asXML')) {
153             $this->_buf .= $item->asXML();
154         }
155         elseif (method_exists($item, 'asString')) {
156             $this->_buf .= $this->_quote($item->asString());
157         }
158         else {
159             $this->_buf .= sprintf("==Object(%s)==", get_class($item));
160         }
161     }
162
163     function _glean_description($text) {
164         static $two_sentences;
165         if (!$two_sentences) {
166             $two_sentences = pcre_fix_posix_classes("[.?!][\")]*\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         return isset($this->_description) ? $this->_description : '';
192     }
193     
194     function asXML () {
195         $xml = '';
196         $basepage = $this->_basepage;
197         
198         foreach ($this->_content as $item) {
199             if (is_string($item)) {
200                 $xml .= $item;
201             }
202             elseif (is_subclass_of($item, 
203                                    check_php_version(5) 
204                                      ? 'Cached_DynamicContent' 
205                                      : 'cached_dynamiccontent'))
206             {
207                 $val = $item->expand($basepage, $this);
208                 $xml .= $val->asXML();
209             }
210             else {
211                 $xml .= $item->asXML();
212             }
213         }
214         return $xml;
215     }
216
217     function printXML () {
218         $basepage = $this->_basepage;
219         // _content might be changed from a plugin (CreateToc)
220         for ($i=0; $i < count($this->_content); $i++) {
221             $item = $this->_content[$i];
222             if (is_string($item)) {
223                 print $item;
224             }
225             elseif (is_subclass_of($item, 
226                                    check_php_version(5) 
227                                      ? 'Cached_DynamicContent' 
228                                      : 'cached_dynamiccontent')) 
229             {   // give the content the chance to know about itself or even 
230                 // to change itself
231                 $val = $item->expand($basepage, $this);
232                 $val->printXML();
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 class Cached_DynamicContent {
248
249     function cache(&$cache) {
250         $cache[] = $this;
251     }
252
253     function expand($basepage, &$obj) {
254         trigger_error("Pure virtual", E_USER_ERROR);
255     }
256
257     function getWikiPageLinks($basepage) {
258         return false;
259     }
260 }
261
262 class XmlRpc_LinkInfo {
263     function XmlRpc_LinkInfo($page, $type, $href, $relation = '') {
264         $this->page = $page;
265         $this->type = $type;
266         $this->href = $href;
267         $this->relation = $relation;
268         //$this->pageref = str_replace("/RPC2.php", "/index.php", $href);
269     }
270 }
271
272 class Cached_Link extends Cached_DynamicContent {
273
274     function isInlineElement() {
275         return true;
276     }
277
278     /** Get link info (for XML-RPC support)
279      *
280      * This is here to support the XML-RPC listLinks method.
281      * (See http://www.ecyrd.com/JSPWiki/Wiki.jsp?page=WikiRPCInterface)
282      */
283     function getLinkInfo($basepage) {
284         return new XmlRpc_LinkInfo($this->_getName($basepage),
285                                    $this->_getType(),
286                                    $this->_getURL($basepage),
287                                    $this->_getRelation($basepage));
288     }
289     
290     function _getURL($basepage) {
291         return $this->_url;
292     }
293     function __getRelation($basepage) {
294         return $this->_relation;
295     }
296 }
297 /*
298  * Defer interwiki inline links. img src=upload:xx.png
299  * LinkImage($url, $alt = false)
300  */
301 class Cached_InlinedImage extends Cached_DynamicContent {
302     function isInlineElement() {
303         return true;
304     }
305     function _getURL($basepage) {
306         return $this->_url;
307     }
308     // TODO: fix interwiki inline links in case of static dumps
309     function expand($basepage, &$markup) {
310         global $WikiTheme;
311         // In case of static dumps we need to check if we should
312         // inline the image or not: external: keep link, internal: copy locally
313         $this->_basepage = $basepage;
314         $label = isset($this->_label) ? $this->_label : false;
315         if ($WikiTheme->DUMP_MODE) {
316             return LinkImage($label);
317         } else {
318             return LinkImage($label);
319         }
320     }
321 }
322
323 class Cached_WikiLink extends Cached_Link {
324
325     function Cached_WikiLink ($page, $label = false, $anchor = false) {
326         $this->_page = $page;
327         /* ":DontStoreLink" */
328         if (substr($this->_page,0,1) == ':') {
329             $this->_page = substr($this->_page,1);
330             $this->_nolink = true;
331         }    
332         if ($anchor)
333             $this->_anchor = $anchor;
334         if ($label and $label != $page)
335             $this->_label = $label;
336         $this->_basepage = false;    
337     }
338
339     function _getType() {
340         return 'internal';
341     }
342     
343     function getPagename($basepage) {
344         $page = new WikiPageName($this->_page, $basepage);
345         if ($page->isValid()) return $page->name;
346         else return false;
347     }
348
349     function getWikiPageLinks($basepage) {
350         if ($basepage == '') return false;
351         if (isset($this->_nolink)) return false;
352         if ($link = $this->getPagename($basepage)) 
353             return array(array('linkto' => $link, 'relation' => 0));
354         else 
355             return false;
356     }
357
358     function _getName($basepage) {
359         return $this->getPagename($basepage);
360     }
361
362     function _getURL($basepage) {
363         return WikiURL($this->getPagename($basepage));
364         //return WikiURL($this->getPagename($basepage), false, 'abs_url');
365     }
366
367     function expand($basepage, &$markup) {
368         global $WikiTheme;
369         $this->_basepage = $basepage;
370         $label = isset($this->_label) ? $this->_label : false;
371         $anchor = isset($this->_anchor) ? (string)$this->_anchor : '';
372         $page = new WikiPageName($this->_page, $basepage, $anchor);
373         if ($WikiTheme->DUMP_MODE and !empty($WikiTheme->VALID_LINKS)) {
374             if (!in_array($this->_page, $WikiTheme->VALID_LINKS))
375                 return HTML($label ? $label : $page->getName());
376         }
377         if ($page->isValid()) return WikiLink($page, 'auto', $label);
378         else return HTML($label);
379     }
380
381     function asXML() {
382         global $WikiTheme;
383         $label = isset($this->_label) ? $this->_label : false;
384         $anchor = isset($this->_anchor) ? (string)$this->_anchor : '';
385         //TODO: need basepage for subpages like /Remove (within CreateTOC)
386         $page = new WikiPageName($this->_page, $this->_basepage, $anchor);
387         if ($WikiTheme->DUMP_MODE and $WikiTheme->VALID_LINKS) {
388             if (!in_array($this->_page, $WikiTheme->VALID_LINKS))
389                 return $label ? $label : $page->getName();
390         }
391         $link = WikiLink($page, 'auto', $label);
392         return $link->asXML();
393     }
394
395     function asString() {
396         if (isset($this->_label))
397             return $this->_label;
398         return $this->_page;
399     }
400 }
401
402 class Cached_WikiLinkIfKnown extends Cached_WikiLink
403 {
404     function Cached_WikiLinkIfKnown ($moniker) {
405         $this->_page = $moniker;
406     }
407
408     function expand($basepage, &$markup) {
409         global $WikiTheme;
410         if ($WikiTheme->DUMP_MODE and $WikiTheme->VALID_LINKS) {
411             if (!in_array($this->_page, $WikiTheme->VALID_LINKS))
412                 return HTML($label ? $label : $page->getName());
413         }
414         return WikiLink($this->_page, 'if_known');
415     }
416 }    
417
418 class Cached_SpellCheck extends Cached_WikiLink
419 {
420     function Cached_SpellCheck ($word, $suggs) {
421         $this->_page = $word;
422         $this->suggestions = $suggs;
423     }
424
425     function expand($basepage, &$markup) {
426         $link = HTML::a(array('class' => 'spell-wrong', 
427                               'title' => 'SpellCheck: '.join(', ', $this->suggestions),
428                               'name' => $this->_page), 
429                         $this->_page);
430         return $link;
431     }
432 }    
433     
434 class Cached_PhpwikiURL extends Cached_DynamicContent
435 {
436     function Cached_PhpwikiURL ($url, $label) {
437         $this->_url = $url;
438         if ($label)
439             $this->_label = $label;
440     }
441
442     function isInlineElement() {
443         return true;
444     }
445
446     function expand($basepage, &$markup) {
447         global $WikiTheme;
448         $label = isset($this->_label) ? $this->_label : false;
449         if ($WikiTheme->DUMP_MODE and $WikiTheme->VALID_LINKS) {
450             if (!in_array($this->_page, $WikiTheme->VALID_LINKS))
451                 return HTML($label ? $label : $page->getName());
452         }
453         return LinkPhpwikiURL($this->_url, $label, $basepage);
454     }
455
456     function asXML() {
457         $label = isset($this->_label) ? $this->_label : false;
458         $link = LinkPhpwikiURL($this->_url, $label);
459         return $link->asXML();
460     }
461
462     function asString() {
463         if (isset($this->_label))
464             return $this->_label;
465         return $this->_url;
466     }
467 }    
468
469 /*
470  * Relations (::) are named links to pages.
471  * Attributes (:=) are named metadata per page, "named links to numbers with units". 
472  * We don't want to exhaust the linktable with numbers,
473  * since this would create empty pages per each value, 
474  * so we don't store the attributes as full relationlink. 
475  * But we do store the attribute name as relation with an empty pagename 
476  * to denote that this is an attribute, 
477  * and to enable a fast listRelations mode=attributes
478  */
479 class Cached_SemanticLink extends Cached_WikiLink {
480
481     function Cached_SemanticLink ($url, $label=false) {
482         $this->_url = $url;
483         if ($label && $label != $url)
484             $this->_label = $label;
485         $this->_expandurl($this->_url);
486     }
487
488     function isInlineElement() {
489         return true;
490     }
491
492     function getPagename($basepage) {
493         if (!isset($this->_page)) return false;
494         $page = new WikiPageName($this->_page, $basepage);
495         if ($page->isValid()) return $page->name;
496         else return false;
497     }
498
499     /* Add relation to the link table.
500      * attributes have the _relation, but not the _page set.
501      */
502     function getWikiPageLinks($basepage) {
503         if ($basepage == '') return false;
504         if (!isset($this->_page) and isset($this->_attribute)) {
505             // An attribute: we store it in the basepage now, to fill the cache for page->save
506             // TODO: side-effect free query
507             $page = $GLOBALS['request']->getPage($basepage); 
508             $page->setAttribute($this->_relation, $this->_attribute);
509             $this->_page = $basepage;
510             return array(array('linkto' => '', 'relation' => $this->_relation));
511         }
512         if ($link = $this->getPagename($basepage)) 
513             return array(array('linkto' => $link, 'relation' => $this->_relation));
514         else
515             return false;
516     }
517
518     function _expandurl($url) {
519         $m = array();
520         if (!preg_match('/^ ([^:]+) (:[:=]) (.+) $/x', $url, $m)) {
521             return HTML::strong(array('class' => 'rawurl'),
522                                 HTML::u(array('class' => 'baduri'),
523                                         _("BAD semantic relation link")));
524         }
525         $this->_relation = urldecode($m[1]);
526         $is_attribute = ($m[2] == ':=');
527         if ($is_attribute) {
528             $this->_attribute = urldecode($m[3]);
529             // since this stored in the markup cache, we are extra sensible 
530             // not to store false empty stuff.
531             $units = new Units();
532             if (!DISABLE_UNITS and !$units->errcode) 
533             {
534                 $this->_attribute_base = $units->Definition($this->_attribute);
535                 $this->_unit = $units->baseunit($this->_attribute);
536             }
537         } else {
538             $this->_page = urldecode($m[3]);
539         }
540         return $m;
541     }
542
543     function _expand($url, $label = false) {
544         global $WikiTheme;
545         $m = $this->_expandurl($url);
546         $class = 'wiki';
547         // do not link to the attribute value, but to the attribute
548         $is_attribute = ($m[2] == ':=');
549         if ($WikiTheme->DUMP_MODE and $WikiTheme->VALID_LINKS) {
550             if (isset($this->_page) and !in_array($this->_page, $WikiTheme->VALID_LINKS))
551                 return HTML($label ? $label : ($is_attribute ? $this->_relation : $this->_page));
552         }
553         if ($is_attribute)
554             $title = isset($this->_attribute_base)
555                 ? sprintf(_("Attribute %s, base value: %s"), $this->_relation, $this->_attribute_base)
556                 : sprintf(_("Attribute %s, value: %s"), $this->_relation, $this->_attribute);
557         if ($label) {
558             return HTML::span
559                 (
560                  HTML::a(array('href'  => WikiURL($is_attribute ? $this->_relation : $this->_page),
561                                'class' => "wiki ".($is_attribute ? "attribute" : "relation"),
562                                'title' => $is_attribute 
563                                ? $title 
564                                : sprintf(_("Relation %s to page %s"), $this->_relation, $this->_page)),
565                          $label)
566                  );
567         } elseif ($is_attribute) {
568             return HTML::span
569                 (
570                  HTML::a(array('href'  => WikiURL($this->_relation),
571                                'class' => "wiki attribute",
572                                'title' => $title),
573                          $url)
574                  );
575         } else {
576             return HTML::span
577                 (
578                  HTML::a(array('href'  => WikiURL($this->_relation),
579                                'class' => "wiki relation"),
580                          $this->_relation),
581                  HTML::span(array('class'=>'relation-symbol'), $m[2]),
582                  HTML::a(array('href'  => WikiURL($this->_page),
583                                'class' => "wiki"),
584                          $this->_page)
585                  );
586         }
587     }
588
589     function expand($basepage, &$markup) {
590         $label = isset($this->_label) ? $this->_label : false;
591         return $this->_expand($this->_url, $label);
592     }
593
594     function asXML() {
595         $label = isset($this->_label) ? $this->_label : false;
596         $link = $this->_expand($this->_url, $label);
597         return $link->asXML();
598     }
599
600     function asString() {
601         if (isset($this->_label))
602             return $this->_label;
603         return $this->_url;
604     }
605 }
606
607 /** 
608  * Highlight found search engine terms
609  */
610 class Cached_SearchHighlight extends Cached_DynamicContent
611 {
612     function Cached_SearchHighlight ($word, $engine) {
613         $this->_word = $word;
614         $this->engine = $engine;
615     }
616
617     function expand($basepage, &$markup) {
618         return HTML::span(array('class' => 'search-term',
619                                 'title' => _("Found by ") . $this->engine),
620                           $this->_word);
621     }
622 }    
623     
624 class Cached_ExternalLink extends Cached_Link {
625
626     function Cached_ExternalLink($url, $label=false) {
627         $this->_url = $url;
628         if ($label && $label != $url)
629             $this->_label = $label;
630     }
631
632     function _getType() {
633         return 'external';
634     }
635     
636     function _getName($basepage) {
637         $label = isset($this->_label) ? $this->_label : false;
638         return ($label and is_string($label)) ? $label : $this->_url;
639     }
640
641     function expand($basepage, &$markup) {
642         global $request;
643
644         $label = isset($this->_label) ? $this->_label : false;
645         $link = LinkURL($this->_url, $label);
646
647         if (GOOGLE_LINKS_NOFOLLOW) {
648             // Ignores nofollow when the user who saved the page was authenticated. 
649             $page = $request->getPage($basepage);
650             $current = $page->getCurrentRevision(false);
651             if (!$current->get('author_id'))
652                 $link->setAttr('rel', 'nofollow');
653         }
654         return $link;
655     }
656
657     function asString() {
658         if (isset($this->_label))
659             return $this->_label;
660         return $this->_url;
661     }
662 }
663
664 class Cached_InterwikiLink extends Cached_ExternalLink {
665     
666     function Cached_InterwikiLink($link, $label=false) {
667         $this->_link = $link;
668         if ($label)
669             $this->_label = $label;
670     }
671
672     function getPagename($basepage) {
673         list ($moniker, $page) = split (":", $this->_link, 2);
674         $page = new WikiPageName($page, $basepage);
675         if ($page->isValid()) return $page->name;
676         else return false;
677     }
678
679     function getWikiPageLinks($basepage) {
680         if ($basepage == '') return false;
681         /* ":DontStoreLink" */
682         if (substr($this->_link,0,1) == ':') return false;
683         /* store only links to valid pagenames */
684         if ($link = $this->getPagename($basepage)) 
685             return array(array('linkto' => $link, 'relation' => 0));
686         else return false; // dont store external links
687     }
688
689     function _getName($basepage) {
690         $label = isset($this->_label) ? $this->_label : false;
691         return ($label and is_string($label)) ? $label : $this->_link;
692     }
693     
694     /* there may be internal interwiki links also */
695     function _getType() {
696         return $this->getPagename(false) ? 'internal' : 'external';
697     }
698
699     function _getURL($basepage) {
700         $link = $this->expand($basepage, $this);
701         return $link->getAttr('href');
702     }
703
704     function expand($basepage, &$markup) {
705         global $WikiTheme;
706         $intermap = getInterwikiMap();
707         $label = isset($this->_label) ? $this->_label : false;
708         //FIXME: check Upload: inlined images
709         if ($WikiTheme->DUMP_MODE and !empty($WikiTheme->VALID_LINKS)) {
710             if (!in_array($this->_link, $WikiTheme->VALID_LINKS))
711                 return HTML($label ? $label : $this->_link);
712         }
713         return $intermap->link($this->_link, $label);
714     }
715
716     function asString() {
717         if (isset($this->_label))
718             return $this->_label;
719         return $this->_link;
720     }
721 }
722
723 // Needed to put UserPages to backlinks. Special method to markup userpages with icons
724 // Thanks to PhpWiki:DanFr for finding this bug. 
725 // Fixed since 1.3.8, prev. versions had no userpages in backlinks
726 class Cached_UserLink extends Cached_WikiLink {
727     function expand($basepage, &$markup) {
728         $label = isset($this->_label) ? $this->_label : false;
729         $anchor = isset($this->_anchor) ? (string)$this->_anchor : '';
730         $page = new WikiPageName($this->_page, $basepage, $anchor);
731         $link = WikiLink($page, 'auto', $label);
732         // $link = HTML::a(array('href' => $PageName));
733         $link->setContent(PossiblyGlueIconToText('wikiuser', $this->_page));
734         $link->setAttr('class', 'wikiuser');
735         return $link;
736     }
737 }
738
739 /**
740  * 1.3.13: Previously stored was only _pi. 
741  * A fresh generated cache has now ->name and ->args also.
742  * main::isActionPage only checks the raw content.
743  */
744 class Cached_PluginInvocation extends Cached_DynamicContent {
745
746     function Cached_PluginInvocation ($pi) {
747         $this->_pi = $pi;
748         $loader = $this->_getLoader();
749         if (is_array($plugin_cmdline = $loader->parsePI($pi)) and $plugin_cmdline[1]) {
750             $this->pi_name = $plugin_cmdline[0]; // plugin, plugin-form, plugin-list, plugin-link
751             $this->name = $plugin_cmdline[1]->getName();
752             $this->args = $plugin_cmdline[2];
753         }
754     }
755
756     function setTightness($top, $bottom) {
757         $this->_tightenable = 0;
758         if ($top) $this->_tightenable |= 1;
759         if ($bottom) $this->_tightenable |= 2;
760     }
761     
762     function isInlineElement() {
763         return false;
764     }
765
766     function expand($basepage, &$markup) {
767         $loader = $this->_getLoader();
768
769         $xml = $loader->expandPI($this->_pi, $GLOBALS['request'], $markup, $basepage);
770         $div = HTML::div(array('class' => 'plugin'));
771         if (isset($this->name))
772             $id = GenerateId($this->name . 'Plugin');
773    
774         if (isset($this->_tightenable)) {
775             if ($this->_tightenable == 3) {
776                 // We need a div here, it might contain a table
777                 $span = HTML::div(array('class' => 'plugin'), $xml);
778                 if (!empty($id))
779                     $span->setAttr('id', $id);
780                 return $span;
781             }
782             $div->setInClass('tightenable');
783             $div->setInClass('top', ($this->_tightenable & 1) != 0);
784             $div->setInClass('bottom', ($this->_tightenable & 2) != 0);
785         }
786         if (!empty($id))
787             $div->setAttr('id', $id);
788         $div->pushContent($xml);
789         return $div;
790     }
791
792     function asString() {
793         return $this->_pi;
794     }
795
796
797     function getWikiPageLinks($basepage) {
798         $loader = $this->_getLoader();
799
800         return $loader->getWikiPageLinks($this->_pi, $basepage);
801     }
802
803     function & _getLoader() {
804         static $loader = false;
805
806         if (!$loader) {
807             include_once('lib/WikiPlugin.php');
808             $loader = new WikiPluginLoader;
809         }
810         return $loader;
811     }
812 }
813
814 // $Log: not supported by cvs2svn $
815 // Revision 1.62  2008/02/14 18:40:32  rurban
816 // fix DUMP_MODE with LINKS
817 //
818 // Revision 1.61  2008/01/30 19:08:59  vargenau
819 // Valid HTML code: we need a div, it might contain a table
820 //
821 // Revision 1.60  2007/09/15 12:28:46  rurban
822 // Improve multi-page format handling: abstract _DumpHtmlToDir. get rid of non-external pdf, non-global VALID_LINKS
823 //
824 // Revision 1.59  2007/09/12 19:32:29  rurban
825 // link only VALID_LINKS with pagelist HTML_DUMP
826 //
827 // Revision 1.58  2007/07/14 12:30:53  rurban
828 // include => require
829 //
830 // Revision 1.57  2007/05/28 20:13:46  rurban
831 // Overwrite all attributes at once at page->save to delete dangling meta
832 //
833 // Revision 1.56  2007/04/08 16:39:40  rurban
834 // fix when DISABLE_UNITS = true (thanks to Walter Rafelsberger)
835 // simplify title calculation
836 //
837 // Revision 1.55  2007/03/18 17:35:14  rurban
838 // Fix :DontStoreLink
839 //
840 // Revision 1.54  2007/01/25 07:41:41  rurban
841 // Print attribute in title. Use CSS formatting for ::=
842 //
843 // Revision 1.53  2007/01/21 23:26:52  rurban
844 // Translate Found by
845 //
846 // Revision 1.52  2007/01/20 15:53:51  rurban
847 // Rewrite of SearchHighlight: through ActionPage and InlineParser
848 //
849 // Revision 1.51  2007/01/20 11:24:53  rurban
850 // add SpellCheck support
851 //
852 // Revision 1.50  2007/01/07 18:41:51  rurban
853 // Fix fallback ZipReader syntax error. Use label=false. Add parsed plugin names to the stored tree.
854 //
855 // Revision 1.49  2007/01/04 16:40:35  rurban
856 // Remove units object from CachedMarkup links, Store parsed linkinfo only: basevalue, baseunit.
857 //
858 // Revision 1.48  2007/01/03 21:22:08  rurban
859 // Use Units for attributes. Store the unified base value as Cached_SemanticLink->_attribute_base in the wikimarkup and display it as title.
860 //
861 // Revision 1.47  2007/01/02 13:17:57  rurban
862 // fix semantic page links and attributes, esp. attributes. they get stored as link to empty page also. tighten semantic url expander regex, omit want_content if not necessary
863 //
864 // Revision 1.46  2006/12/22 00:11:38  rurban
865 // add seperate expandurl method, to simplify pagename parsing
866 //
867 // Revision 1.45  2006/10/12 06:33:50  rurban
868 // decide later with which class to render this link (fixes interwiki link layout)
869
870 // (c-file-style: "gnu")
871 // Local Variables:
872 // mode: php
873 // tab-width: 8
874 // c-basic-offset: 4
875 // c-hanging-comment-ender-p: nil
876 // indent-tabs-mode: nil
877 // End:   
878 ?>