]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/CachedMarkup.php
Activated Id substitution for Subversion
[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  *
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 (!$this->getDescription() and $item->getTag() == 'p') {
143                     // performance: when is this really needed?
144                     $this->_glean_description($item->asString());
145                 }
146             }
147             if (!$item->isInlineElement())
148                 $this->_buf .= "\n";
149         }
150         elseif (isa($item, 'XmlContent')) {
151             foreach ($item->getContent() as $item)
152                 $this->_append($item);
153         }
154         elseif (method_exists($item, 'asXML')) {
155             $this->_buf .= $item->asXML();
156         }
157         elseif (method_exists($item, 'asString')) {
158             $this->_buf .= $this->_quote($item->asString());
159         }
160         else {
161             $this->_buf .= sprintf("==Object(%s)==", get_class($item));
162         }
163     }
164
165     function _glean_description($text) {
166         static $two_sentences;
167         if (!$two_sentences) {
168             $two_sentences = pcre_fix_posix_classes("[.?!][\")]*\s+[\"(]*[[:upper:])]"
169                                                     . ".*"
170                                                     . "[.?!][\")]*\s*[\"(]*([[:upper:])]|$)");
171         }
172         
173         if (!isset($this->_description) and preg_match("/$two_sentences/sx", $text))
174             $this->_description = preg_replace("/\s*\n\s*/", " ", trim($text));
175     }
176
177     /**
178      * Guess a short description of the page.
179      *
180      * Algorithm:
181      *
182      * This algorithm was suggested on MeatballWiki by
183      * Alex Schroeder <kensanata@yahoo.com>.
184      *
185      * Use the first paragraph in the page which contains at least two
186      * sentences.
187      *
188      * @see http://www.usemod.com/cgi-bin/mb.pl?MeatballWikiSuggestions
189      *
190      * @return string
191      */
192     function getDescription () {
193         return isset($this->_description) ? $this->_description : '';
194     }
195     
196     function asXML () {
197         $xml = '';
198         $basepage = $this->_basepage;
199         
200         foreach ($this->_content as $item) {
201             if (is_string($item)) {
202                 $xml .= $item;
203             }
204             elseif (is_subclass_of($item, 
205                                    check_php_version(5) 
206                                      ? 'Cached_DynamicContent' 
207                                      : 'cached_dynamiccontent'))
208             {
209                 $val = $item->expand($basepage, $this);
210                 $xml .= $val->asXML();
211             }
212             else {
213                 $xml .= $item->asXML();
214             }
215         }
216         return $xml;
217     }
218
219     function printXML () {
220         $basepage = $this->_basepage;
221         // _content might be changed from a plugin (CreateToc)
222         for ($i=0; $i < count($this->_content); $i++) {
223             $item = $this->_content[$i];
224             if (is_string($item)) {
225                 print $item;
226             }
227             elseif (is_subclass_of($item, 
228                                    check_php_version(5) 
229                                      ? 'Cached_DynamicContent' 
230                                      : 'cached_dynamiccontent')) 
231             {   // give the content the chance to know about itself or even 
232                 // to change itself
233                 $val = $item->expand($basepage, $this);
234                 $val->printXML();
235             }
236             else {
237                 $item->printXML();
238             }
239         }
240     }
241 }       
242
243 /**
244  * The base class for all dynamic content.
245  *
246  * Dynamic content is anything that can change even when the original
247  * wiki-text from which it was parsed is unchanged.
248  */
249 class Cached_DynamicContent {
250
251     function cache(&$cache) {
252         $cache[] = $this;
253     }
254
255     function expand($basepage, &$obj) {
256         trigger_error("Pure virtual", E_USER_ERROR);
257     }
258
259     function getWikiPageLinks($basepage) {
260         return false;
261     }
262 }
263
264 class XmlRpc_LinkInfo {
265     function XmlRpc_LinkInfo($page, $type, $href, $relation = '') {
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 class Cached_Link extends Cached_DynamicContent {
275
276     function isInlineElement() {
277         return true;
278     }
279
280     /** Get link info (for XML-RPC support)
281      *
282      * This is here to support the XML-RPC listLinks method.
283      * (See http://www.ecyrd.com/JSPWiki/Wiki.jsp?page=WikiRPCInterface)
284      */
285     function getLinkInfo($basepage) {
286         return new XmlRpc_LinkInfo($this->_getName($basepage),
287                                    $this->_getType(),
288                                    $this->_getURL($basepage),
289                                    $this->_getRelation($basepage));
290     }
291     
292     function _getURL($basepage) {
293         return $this->_url;
294     }
295     function __getRelation($basepage) {
296         return $this->_relation;
297     }
298 }
299 /*
300  * Defer interwiki inline links. img src=upload:xx.png
301  * LinkImage($url, $alt = false)
302  */
303 class Cached_InlinedImage extends Cached_DynamicContent {
304     function isInlineElement() {
305         return true;
306     }
307     function _getURL($basepage) {
308         return $this->_url;
309     }
310     // TODO: fix interwiki inline links in case of static dumps
311     function expand($basepage, &$markup) {
312         global $WikiTheme;
313         $this->_basepage = $basepage;
314         $label = isset($this->_label) ? $this->_label : false;
315         if ($WikiTheme->DUMP_MODE) {
316             // In case of static dumps we need to check if we should
317             // inline the image or not: external: keep link, internal: copy locally
318             return LinkImage($label);
319         } else {
320             return LinkImage($label);
321         }
322     }
323 }
324
325 class Cached_WikiLink extends Cached_Link {
326
327     function Cached_WikiLink ($page, $label = false, $anchor = false) {
328         $this->_page = $page;
329         /* ":DontStoreLink" */
330         if (substr($this->_page,0,1) == ':') {
331             $this->_page = substr($this->_page,1);
332             $this->_nolink = true;
333         }    
334         if ($anchor)
335             $this->_anchor = $anchor;
336         if ($label and $label != $page)
337             $this->_label = $label;
338         $this->_basepage = false;    
339     }
340
341     function _getType() {
342         return 'internal';
343     }
344     
345     function getPagename($basepage) {
346         $page = new WikiPageName($this->_page, $basepage);
347         if ($page->isValid()) return $page->name;
348         else return false;
349     }
350
351     function getWikiPageLinks($basepage) {
352         if ($basepage == '') return false;
353         if (isset($this->_nolink)) return false;
354         if ($link = $this->getPagename($basepage)) 
355             return array(array('linkto' => $link, 'relation' => 0));
356         else 
357             return false;
358     }
359
360     function _getName($basepage) {
361         return $this->getPagename($basepage);
362     }
363
364     function _getURL($basepage) {
365         return WikiURL($this->getPagename($basepage));
366         //return WikiURL($this->getPagename($basepage), false, 'abs_url');
367     }
368
369     function expand($basepage, &$markup) {
370         global $WikiTheme;
371         $this->_basepage = $basepage;
372         $label = isset($this->_label) ? $this->_label : false;
373         $anchor = isset($this->_anchor) ? (string)$this->_anchor : '';
374         $page = new WikiPageName($this->_page, $basepage, $anchor);
375         if ($WikiTheme->DUMP_MODE and !empty($WikiTheme->VALID_LINKS)) {
376             if (!in_array($this->_page, $WikiTheme->VALID_LINKS))
377                 return HTML($label ? $label : $page->getName());
378         }
379         if ($page->isValid()) return WikiLink($page, 'auto', $label);
380         else return HTML($label);
381     }
382
383     function asXML() {
384         global $WikiTheme;
385         $label = isset($this->_label) ? $this->_label : false;
386         $anchor = isset($this->_anchor) ? (string)$this->_anchor : '';
387         //TODO: need basepage for subpages like /Remove (within CreateTOC)
388         $page = new WikiPageName($this->_page, $this->_basepage, $anchor);
389         if ($WikiTheme->DUMP_MODE and $WikiTheme->VALID_LINKS) {
390             if (!in_array($this->_page, $WikiTheme->VALID_LINKS))
391                 return $label ? $label : $page->getName();
392         }
393         $link = WikiLink($page, 'auto', $label);
394         return $link->asXML();
395     }
396
397     function asString() {
398         if (isset($this->_label))
399             return $this->_label;
400         return $this->_page;
401     }
402 }
403
404 class Cached_WikiLinkIfKnown extends Cached_WikiLink
405 {
406     function Cached_WikiLinkIfKnown ($moniker) {
407         $this->_page = $moniker;
408     }
409
410     function expand($basepage, &$markup) {
411         global $WikiTheme;
412         if ($WikiTheme->DUMP_MODE and $WikiTheme->VALID_LINKS) {
413             if (!in_array($this->_page, $WikiTheme->VALID_LINKS))
414                 return HTML($label ? $label : $page->getName());
415         }
416         return WikiLink($this->_page, 'if_known');
417     }
418 }    
419
420 class Cached_SpellCheck extends Cached_WikiLink
421 {
422     function Cached_SpellCheck ($word, $suggs) {
423         $this->_page = $word;
424         $this->suggestions = $suggs;
425     }
426
427     function expand($basepage, &$markup) {
428         $link = HTML::a(array('class' => 'spell-wrong', 
429                               'title' => 'SpellCheck: '.join(', ', $this->suggestions),
430                               'name' => $this->_page), 
431                         $this->_page);
432         return $link;
433     }
434 }    
435     
436 class Cached_PhpwikiURL extends Cached_DynamicContent
437 {
438     function Cached_PhpwikiURL ($url, $label) {
439         $this->_url = $url;
440         if ($label)
441             $this->_label = $label;
442     }
443
444     function isInlineElement() {
445         return true;
446     }
447
448     function expand($basepage, &$markup) {
449         global $WikiTheme;
450         $label = isset($this->_label) ? $this->_label : false;
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 LinkPhpwikiURL($this->_url, $label, $basepage);
456     }
457
458     function asXML() {
459         $label = isset($this->_label) ? $this->_label : false;
460         $link = LinkPhpwikiURL($this->_url, $label);
461         return $link->asXML();
462     }
463
464     function asString() {
465         if (isset($this->_label))
466             return $this->_label;
467         return $this->_url;
468     }
469 }    
470
471 /*
472  * Relations (::) are named links to pages.
473  * Attributes (:=) are named metadata per page, "named links to numbers with units". 
474  * We don't want to exhaust the linktable with numbers,
475  * since this would create empty pages per each value, 
476  * so we don't store the attributes as full relationlink. 
477  * But we do store the attribute name as relation with an empty pagename 
478  * to denote that this is an attribute, 
479  * and to enable a fast listRelations mode=attributes
480  */
481 class Cached_SemanticLink extends Cached_WikiLink {
482
483     function Cached_SemanticLink ($url, $label=false) {
484         $this->_url = $url;
485         if ($label && $label != $url)
486             $this->_label = $label;
487         $this->_expandurl($this->_url);
488     }
489
490     function isInlineElement() {
491         return true;
492     }
493
494     function getPagename($basepage) {
495         if (!isset($this->_page)) return false;
496         $page = new WikiPageName($this->_page, $basepage);
497         if ($page->isValid()) return $page->name;
498         else return false;
499     }
500
501     /* Add relation to the link table.
502      * attributes have the _relation, but not the _page set.
503      */
504     function getWikiPageLinks($basepage) {
505         if ($basepage == '') return false;
506         if (!isset($this->_page) and isset($this->_attribute)) {
507             // An attribute: we store it in the basepage now, to fill the cache for page->save
508             // TODO: side-effect free query
509             $page = $GLOBALS['request']->getPage($basepage); 
510             $page->setAttribute($this->_relation, $this->_attribute);
511             $this->_page = $basepage;
512             return array(array('linkto' => '', 'relation' => $this->_relation));
513         }
514         if ($link = $this->getPagename($basepage)) 
515             return array(array('linkto' => $link, 'relation' => $this->_relation));
516         else
517             return false;
518     }
519
520     function _expandurl($url) {
521         $m = array();
522         if (!preg_match('/^ ([^:]+) (:[:=]) (.+) $/x', $url, $m)) {
523             return HTML::strong(array('class' => 'rawurl'),
524                                 HTML::u(array('class' => 'baduri'),
525                                         _("BAD semantic relation link")));
526         }
527         $this->_relation = urldecode($m[1]);
528         $is_attribute = ($m[2] == ':=');
529         if ($is_attribute) {
530             $this->_attribute = urldecode($m[3]);
531             // since this stored in the markup cache, we are extra sensible 
532             // not to store false empty stuff.
533             $units = new Units();
534             if (!DISABLE_UNITS and !$units->errcode) 
535             {
536                 $this->_attribute_base = $units->Definition($this->_attribute);
537                 $this->_unit = $units->baseunit($this->_attribute);
538             }
539         } else {
540             $this->_page = urldecode($m[3]);
541         }
542         return $m;
543     }
544
545     function _expand($url, $label = false) {
546         global $WikiTheme;
547         $m = $this->_expandurl($url);
548         $class = 'wiki';
549         // do not link to the attribute value, but to the attribute
550         $is_attribute = ($m[2] == ':=');
551         if ($WikiTheme->DUMP_MODE and $WikiTheme->VALID_LINKS) {
552             if (isset($this->_page) and !in_array($this->_page, $WikiTheme->VALID_LINKS))
553                 return HTML($label ? $label : ($is_attribute ? $this->_relation : $this->_page));
554         }
555         if ($is_attribute)
556             $title = isset($this->_attribute_base)
557                 ? sprintf(_("Attribute %s, base value: %s"), $this->_relation, $this->_attribute_base)
558                 : sprintf(_("Attribute %s, value: %s"), $this->_relation, $this->_attribute);
559         if ($label) {
560             return HTML::span
561                 (
562                  HTML::a(array('href'  => WikiURL($is_attribute ? $this->_relation : $this->_page),
563                                'class' => "wiki ".($is_attribute ? "attribute" : "relation"),
564                                'title' => $is_attribute 
565                                ? $title 
566                                : sprintf(_("Relation %s to page %s"), $this->_relation, $this->_page)),
567                          $label)
568                  );
569         } elseif ($is_attribute) {
570             return HTML::span
571                 (
572                  HTML::a(array('href'  => WikiURL($this->_relation),
573                                'class' => "wiki attribute",
574                                'title' => $title),
575                          $url)
576                  );
577         } else {
578             return HTML::span
579                 (
580                  HTML::a(array('href'  => WikiURL($this->_relation),
581                                'class' => "wiki relation"),
582                          $this->_relation),
583                  HTML::span(array('class'=>'relation-symbol'), $m[2]),
584                  HTML::a(array('href'  => WikiURL($this->_page),
585                                'class' => "wiki"),
586                          $this->_page)
587                  );
588         }
589     }
590
591     function expand($basepage, &$markup) {
592         $label = isset($this->_label) ? $this->_label : false;
593         return $this->_expand($this->_url, $label);
594     }
595
596     function asXML() {
597         $label = isset($this->_label) ? $this->_label : false;
598         $link = $this->_expand($this->_url, $label);
599         return $link->asXML();
600     }
601
602     function asString() {
603         if (isset($this->_label))
604             return $this->_label;
605         return $this->_url;
606     }
607 }
608
609 /** 
610  * Highlight found search engine terms
611  */
612 class Cached_SearchHighlight extends Cached_DynamicContent
613 {
614     function Cached_SearchHighlight ($word, $engine) {
615         $this->_word = $word;
616         $this->engine = $engine;
617     }
618
619     function expand($basepage, &$markup) {
620         return HTML::span(array('class' => 'search-term',
621                                 'title' => _("Found by ") . $this->engine),
622                           $this->_word);
623     }
624 }    
625     
626 class Cached_ExternalLink extends Cached_Link {
627
628     function Cached_ExternalLink($url, $label=false) {
629         $this->_url = $url;
630         if ($label && $label != $url)
631             $this->_label = $label;
632     }
633
634     function _getType() {
635         return 'external';
636     }
637     
638     function _getName($basepage) {
639         $label = isset($this->_label) ? $this->_label : false;
640         return ($label and is_string($label)) ? $label : $this->_url;
641     }
642
643     function expand($basepage, &$markup) {
644         global $request;
645
646         $label = isset($this->_label) ? $this->_label : false;
647         $link = LinkURL($this->_url, $label);
648
649         if (GOOGLE_LINKS_NOFOLLOW) {
650             // Ignores nofollow when the user who saved the page was authenticated. 
651             $page = $request->getPage($basepage);
652             $current = $page->getCurrentRevision(false);
653             if (!$current->get('author_id'))
654                 $link->setAttr('rel', 'nofollow');
655         }
656         return $link;
657     }
658
659     function asString() {
660         if (isset($this->_label) and is_string($this->_label))
661             return $this->_label;
662         return $this->_url;
663     }
664 }
665
666 class Cached_InterwikiLink extends Cached_ExternalLink {
667     
668     function Cached_InterwikiLink($link, $label=false) {
669         $this->_link = $link;
670         if ($label)
671             $this->_label = $label;
672     }
673
674     function getPagename($basepage) {
675         list ($moniker, $page) = split (":", $this->_link, 2);
676         $page = new WikiPageName($page, $basepage);
677         if ($page->isValid()) return $page->name;
678         else return false;
679     }
680
681     function getWikiPageLinks($basepage) {
682         if ($basepage == '') return false;
683         /* ":DontStoreLink" */
684         if (substr($this->_link,0,1) == ':') return false;
685         /* store only links to valid pagenames */
686         if ($link = $this->getPagename($basepage)) 
687             return array(array('linkto' => $link, 'relation' => 0));
688         else return false; // dont store external links
689     }
690
691     function _getName($basepage) {
692         $label = isset($this->_label) ? $this->_label : false;
693         return ($label and is_string($label)) ? $label : $this->_link;
694     }
695     
696     /* there may be internal interwiki links also */
697     function _getType() {
698         return $this->getPagename(false) ? 'internal' : 'external';
699     }
700
701     function _getURL($basepage) {
702         $link = $this->expand($basepage, $this);
703         return $link->getAttr('href');
704     }
705
706     function expand($basepage, &$markup) {
707         global $WikiTheme;
708         $intermap = getInterwikiMap();
709         $label = isset($this->_label) ? $this->_label : false;
710         //FIXME: check Upload: inlined images
711         if ($WikiTheme->DUMP_MODE and !empty($WikiTheme->VALID_LINKS)) {
712             if (!in_array($this->_link, $WikiTheme->VALID_LINKS))
713                 return HTML($label ? $label : $this->_link);
714         }
715         return $intermap->link($this->_link, $label);
716     }
717
718     function asString() {
719         if (isset($this->_label))
720             return $this->_label;
721         return $this->_link;
722     }
723 }
724
725 // Needed to put UserPages to backlinks. Special method to markup userpages with icons
726 // Thanks to PhpWiki:DanFr for finding this bug. 
727 // Fixed since 1.3.8, prev. versions had no userpages in backlinks
728 class Cached_UserLink extends Cached_WikiLink {
729     function expand($basepage, &$markup) {
730         $label = isset($this->_label) ? $this->_label : false;
731         $anchor = isset($this->_anchor) ? (string)$this->_anchor : '';
732         $page = new WikiPageName($this->_page, $basepage, $anchor);
733         $link = WikiLink($page, 'auto', $label);
734         // $link = HTML::a(array('href' => $PageName));
735         $link->setContent(PossiblyGlueIconToText('wikiuser', $this->_page));
736         $link->setAttr('class', 'wikiuser');
737         return $link;
738     }
739 }
740
741 /**
742  * 1.3.13: Previously stored was only _pi. 
743  * A fresh generated cache has now ->name and ->args also.
744  * main::isActionPage only checks the raw content.
745  */
746 class Cached_PluginInvocation extends Cached_DynamicContent {
747
748     function Cached_PluginInvocation ($pi) {
749         $this->_pi = $pi;
750         $loader = $this->_getLoader();
751         if (is_array($plugin_cmdline = $loader->parsePI($pi)) and $plugin_cmdline[1]) {
752             $this->pi_name = $plugin_cmdline[0]; // plugin, plugin-form, plugin-list, plugin-link
753             $this->name = $plugin_cmdline[1]->getName();
754             $this->args = $plugin_cmdline[2];
755         }
756     }
757
758     function setTightness($top, $bottom) {
759         $this->_tightenable = 0;
760         if ($top) $this->_tightenable |= 1;
761         if ($bottom) $this->_tightenable |= 2;
762     }
763     
764     function isInlineElement() {
765         return false;
766     }
767
768     function expand($basepage, &$markup) {
769         $loader = $this->_getLoader();
770
771         $xml = $loader->expandPI($this->_pi, $GLOBALS['request'], $markup, $basepage);
772         $div = HTML::div(array('class' => 'plugin'));
773         if (isset($this->name))
774             $id = GenerateId($this->name . 'Plugin');
775    
776         if (isset($this->_tightenable)) {
777             if ($this->_tightenable == 3) {
778                 // We need a div here, it might contain a table
779                 $span = HTML::div(array('class' => 'plugin'), $xml);
780                 if (!empty($id))
781                     $span->setAttr('id', $id);
782                 return $span;
783             }
784             $div->setInClass('tightenable');
785             $div->setInClass('top', ($this->_tightenable & 1) != 0);
786             $div->setInClass('bottom', ($this->_tightenable & 2) != 0);
787         }
788         if (!empty($id))
789             $div->setAttr('id', $id);
790         $div->pushContent($xml);
791         return $div;
792     }
793
794     function asString() {
795         return $this->_pi;
796     }
797
798
799     function getWikiPageLinks($basepage) {
800         $loader = $this->_getLoader();
801
802         return $loader->getWikiPageLinks($this->_pi, $basepage);
803     }
804
805     function & _getLoader() {
806         static $loader = false;
807
808         if (!$loader) {
809             include_once('lib/WikiPlugin.php');
810             $loader = new WikiPluginLoader;
811         }
812         return $loader;
813     }
814 }
815
816 // $Log: not supported by cvs2svn $
817 // Revision 1.64  2008/03/21 20:35:52  rurban
818 // Improve upon embedded ImgObject, such as [ *.mp3 ], objects.
819 // Object tags now render as label correctly and param tags are also added.
820 //
821 // Revision 1.63  2008/03/17 19:03:08  rurban
822 // protect $WikiTheme->VALID_LINKS
823 //
824 // Revision 1.62  2008/02/14 18:40:32  rurban
825 // fix DUMP_MODE with LINKS
826 //
827 // Revision 1.61  2008/01/30 19:08:59  vargenau
828 // Valid HTML code: we need a div, it might contain a table
829 //
830 // Revision 1.60  2007/09/15 12:28:46  rurban
831 // Improve multi-page format handling: abstract _DumpHtmlToDir. get rid of non-external pdf, non-global VALID_LINKS
832 //
833 // Revision 1.59  2007/09/12 19:32:29  rurban
834 // link only VALID_LINKS with pagelist HTML_DUMP
835 //
836 // Revision 1.58  2007/07/14 12:30:53  rurban
837 // include => require
838 //
839 // Revision 1.57  2007/05/28 20:13:46  rurban
840 // Overwrite all attributes at once at page->save to delete dangling meta
841 //
842 // Revision 1.56  2007/04/08 16:39:40  rurban
843 // fix when DISABLE_UNITS = true (thanks to Walter Rafelsberger)
844 // simplify title calculation
845 //
846 // Revision 1.55  2007/03/18 17:35:14  rurban
847 // Fix :DontStoreLink
848 //
849 // Revision 1.54  2007/01/25 07:41:41  rurban
850 // Print attribute in title. Use CSS formatting for ::=
851 //
852 // Revision 1.53  2007/01/21 23:26:52  rurban
853 // Translate Found by
854 //
855 // Revision 1.52  2007/01/20 15:53:51  rurban
856 // Rewrite of SearchHighlight: through ActionPage and InlineParser
857 //
858 // Revision 1.51  2007/01/20 11:24:53  rurban
859 // add SpellCheck support
860 //
861 // Revision 1.50  2007/01/07 18:41:51  rurban
862 // Fix fallback ZipReader syntax error. Use label=false. Add parsed plugin names to the stored tree.
863 //
864 // Revision 1.49  2007/01/04 16:40:35  rurban
865 // Remove units object from CachedMarkup links, Store parsed linkinfo only: basevalue, baseunit.
866 //
867 // Revision 1.48  2007/01/03 21:22:08  rurban
868 // Use Units for attributes. Store the unified base value as Cached_SemanticLink->_attribute_base in the wikimarkup and display it as title.
869 //
870 // Revision 1.47  2007/01/02 13:17:57  rurban
871 // 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
872 //
873 // Revision 1.46  2006/12/22 00:11:38  rurban
874 // add seperate expandurl method, to simplify pagename parsing
875 //
876 // Revision 1.45  2006/10/12 06:33:50  rurban
877 // decide later with which class to render this link (fixes interwiki link layout)
878
879 // (c-file-style: "gnu")
880 // Local Variables:
881 // mode: php
882 // tab-width: 8
883 // c-basic-offset: 4
884 // c-hanging-comment-ender-p: nil
885 // indent-tabs-mode: nil
886 // End:   
887 ?>