]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/Theme.php
make TextSearchQuery->_stoplist localizable and overridable within config.ini
[SourceForge/phpwiki.git] / lib / Theme.php
1 <?php rcs_id('$Id: Theme.php,v 1.134 2006-03-19 16:24:38 rurban Exp $');
2 /* Copyright (C) 2002,2004,2005 $ThePhpWikiProgrammingTeam
3  *
4  * This file is part of PhpWiki.
5  * 
6  * PhpWiki is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * 
11  * PhpWiki is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License
17  * along with PhpWiki; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 /**
22  * Customize output by themes: templates, css, special links functions, 
23  * and more formatting.
24  */
25
26 require_once(dirname(__FILE__).'/HtmlElement.php');
27
28 /**
29  * Make a link to a wiki page (in this wiki).
30  *
31  * This is a convenience function.
32  *
33  * @param mixed $page_or_rev
34  * Can be:<dl>
35  * <dt>A string</dt><dd>The page to link to.</dd>
36  * <dt>A WikiDB_Page object</dt><dd>The page to link to.</dd>
37  * <dt>A WikiDB_PageRevision object</dt><dd>A specific version of the page to link to.</dd>
38  * </dl>
39  *
40  * @param string $type
41  * One of:<dl>
42  * <dt>'unknown'</dt><dd>Make link appropriate for a non-existant page.</dd>
43  * <dt>'known'</dt><dd>Make link appropriate for an existing page.</dd>
44  * <dt>'auto'</dt><dd>Either 'unknown' or 'known' as appropriate.</dd>
45  * <dt>'button'</dt><dd>Make a button-style link.</dd>
46  * <dt>'if_known'</dt><dd>Only linkify if page exists.</dd>
47  * </dl>
48  * Unless $type of of the latter form, the link will be of class 'wiki', 'wikiunknown',
49  * 'named-wiki', or 'named-wikiunknown', as appropriate.
50  *
51  * @param mixed $label (string or XmlContent object)
52  * Label for the link.  If not given, defaults to the page name.
53  *
54  * @return XmlContent The link
55  */
56 function WikiLink ($page_or_rev, $type = 'known', $label = false) {
57     global $WikiTheme, $request;
58
59     if ($type == 'button') {
60         return $WikiTheme->makeLinkButton($page_or_rev, $label);
61     }
62
63     $version = false;
64     
65     if (isa($page_or_rev, 'WikiDB_PageRevision')) {
66         $version = $page_or_rev->getVersion();
67         if ($page_or_rev->isCurrent())
68             $version = false;
69         $page = $page_or_rev->getPage();
70         $pagename = $page->getName();
71         $wikipage = $pagename;
72         $exists = true;
73     }
74     elseif (isa($page_or_rev, 'WikiDB_Page')) {
75         $page = $page_or_rev;
76         $pagename = $page->getName();
77         $wikipage = $pagename;
78     }
79     elseif (isa($page_or_rev, 'WikiPageName')) {
80         $wikipage = $page_or_rev;
81         $pagename = $wikipage->name;
82         if (!$wikipage->isValid('strict'))
83             return $WikiTheme->linkBadWikiWord($wikipage, $label);
84     }
85     else {
86         $wikipage = new WikiPageName($page_or_rev, $request->getPage());
87         $pagename = $wikipage->name;
88         if (!$wikipage->isValid('strict'))
89             return $WikiTheme->linkBadWikiWord($wikipage, $label);
90     }
91     
92     if ($type == 'auto' or $type == 'if_known') {
93         if (isset($page)) {
94             $exists = $page->exists();
95         }
96         else {
97             $dbi =& $request->_dbi;
98             $exists = $dbi->isWikiPage($wikipage->name);
99         }
100     }
101     elseif ($type == 'unknown') {
102         $exists = false;
103     }
104     else {
105         $exists = true;
106     }
107
108     // FIXME: this should be somewhere else, if really needed.
109     // WikiLink makes A link, not a string of fancy ones.
110     // (I think that the fancy split links are just confusing.)
111     // Todo: test external ImageLinks http://some/images/next.gif
112     if (isa($wikipage, 'WikiPageName') and 
113         ! $label and 
114         strchr(substr($wikipage->shortName,1), SUBPAGE_SEPARATOR))
115     {
116         $parts = explode(SUBPAGE_SEPARATOR, $wikipage->shortName);
117         $last_part = array_pop($parts);
118         $sep = '';
119         $link = HTML::span();
120         foreach ($parts as $part) {
121             $path[] = $part;
122             $parent = join(SUBPAGE_SEPARATOR, $path);
123             if ($WikiTheme->_autosplitWikiWords)
124                 $part = " " . $part;
125             if ($part)
126                 $link->pushContent($WikiTheme->linkExistingWikiWord($parent, $sep . $part));
127             $sep = $WikiTheme->_autosplitWikiWords 
128                    ? ' ' . SUBPAGE_SEPARATOR : SUBPAGE_SEPARATOR;
129         }
130         if ($exists)
131             $link->pushContent($WikiTheme->linkExistingWikiWord($wikipage, $sep . $last_part, 
132                                                                 $version));
133         else
134             $link->pushContent($WikiTheme->linkUnknownWikiWord($wikipage, $sep . $last_part));
135         return $link;
136     }
137
138     if ($exists) {
139         return $WikiTheme->linkExistingWikiWord($wikipage, $label, $version);
140     }
141     elseif ($type == 'if_known') {
142         if (!$label && isa($wikipage, 'WikiPageName'))
143             $label = $wikipage->shortName;
144         return HTML($label ? $label : $pagename);
145     }
146     else {
147         return $WikiTheme->linkUnknownWikiWord($wikipage, $label);
148     }
149 }
150
151
152
153 /**
154  * Make a button.
155  *
156  * This is a convenience function.
157  *
158  * @param $action string
159  * One of <dl>
160  * <dt>[action]</dt><dd>Perform action (e.g. 'edit') on the selected page.</dd>
161  * <dt>[ActionPage]</dt><dd>Run the actionpage (e.g. 'BackLinks') on the selected page.</dd>
162  * <dt>'submit:'[name]</dt><dd>Make a form submission button with the given name.
163  *      ([name] can be blank for a nameless submit button.)</dd>
164  * <dt>a hash</dt><dd>Query args for the action. E.g.<pre>
165  *      array('action' => 'diff', 'previous' => 'author')
166  * </pre></dd>
167  * </dl>
168  *
169  * @param $label string
170  * A label for the button.  If ommited, a suitable default (based on the valued of $action)
171  * will be picked.
172  *
173  * @param $page_or_rev mixed
174  * Which page (& version) to perform the action on.
175  * Can be one of:<dl>
176  * <dt>A string</dt><dd>The pagename.</dd>
177  * <dt>A WikiDB_Page object</dt><dd>The page.</dd>
178  * <dt>A WikiDB_PageRevision object</dt><dd>A specific version of the page.</dd>
179  * </dl>
180  * ($Page_or_rev is ignored for submit buttons.)
181  */
182 function Button ($action, $label = false, $page_or_rev = false) {
183     global $WikiTheme;
184
185     if (!is_array($action) && preg_match('/^submit:(.*)/', $action, $m))
186         return $WikiTheme->makeSubmitButton($label, $m[1], $page_or_rev);
187     else
188         return $WikiTheme->makeActionButton($action, $label, $page_or_rev);
189 }
190
191
192 class Theme {
193     var $HTML_DUMP_SUFFIX = '';
194     var $DUMP_MODE = false, $dumped_images, $dumped_css; 
195
196     function Theme ($theme_name = 'default') {
197         $this->_name = $theme_name;
198         $this->_themes_dir = NormalizeLocalFileName("themes");
199         $this->_path  = defined('PHPWIKI_DIR') ? NormalizeLocalFileName("") : "";
200         $this->_theme = "themes/$theme_name";
201
202         if ($theme_name != 'default')
203             $this->_default_theme = new Theme;
204
205         // by pixels
206         if ((is_object($GLOBALS['request']) // guard against unittests
207              and $GLOBALS['request']->getPref('doubleClickEdit'))
208             or ENABLE_DOUBLECLICKEDIT)
209             $this->initDoubleClickEdit();
210
211         // will be replaced by acDropDown
212         if (ENABLE_LIVESEARCH) { // by bitflux.ch
213             $this->initLiveSearch();
214         }
215         // replaces external LiveSearch
216         if (defined("ENABLE_ACDROPDOWN") and ENABLE_ACDROPDOWN) { 
217             $this->initMoAcDropDown();
218         }
219         $this->_css = array();
220     }
221
222     function file ($file) {
223         return $this->_path . "$this->_theme/$file";
224    } 
225
226     function _findFile ($file, $missing_okay = false) {
227         if (file_exists($this->file($file)))
228             return "$this->_theme/$file";
229
230         // FIXME: this is a short-term hack.  Delete this after all files
231         // get moved into themes/...
232         if (file_exists($this->_path . $file))
233             return $file;
234
235         if (isset($this->_default_theme)) {
236             return $this->_default_theme->_findFile($file, $missing_okay);
237         }
238         else if (!$missing_okay) {
239             if (DEBUG & function_exists('debug_backtrace')) { // >= 4.3.0
240                 echo "<pre>", printSimpleTrace(debug_backtrace()), "</pre>\n";
241             }
242             trigger_error("$this->_theme/$file: not found", E_USER_NOTICE);
243         }
244         return false;
245     }
246
247     function _findData ($file, $missing_okay = false) {
248         $path = $this->_findFile($file, $missing_okay);
249         if (!$path)
250             return false;
251
252         if (defined('DATA_PATH'))
253             return DATA_PATH . "/$path";
254         return $path;
255     }
256
257     ////////////////////////////////////////////////////////////////
258     //
259     // Date and Time formatting
260     //
261     ////////////////////////////////////////////////////////////////
262
263     // Note:  Windows' implemetation of strftime does not include certain
264         // format specifiers, such as %e (for date without leading zeros).  In
265         // general, see:
266         // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_strftime.2c_.wcsftime.asp
267         // As a result, we have to use %d, and strip out leading zeros ourselves.
268
269     var $_dateFormat = "%B %d, %Y";
270     var $_timeFormat = "%I:%M %p";
271
272     var $_showModTime = true;
273
274     /**
275      * Set format string used for dates.
276      *
277      * @param $fs string Format string for dates.
278      *
279      * @param $show_mod_time bool If true (default) then times
280      * are included in the messages generated by getLastModifiedMessage(),
281      * otherwise, only the date of last modification will be shown.
282      */
283     function setDateFormat ($fs, $show_mod_time = true) {
284         $this->_dateFormat = $fs;
285         $this->_showModTime = $show_mod_time;
286     }
287
288     /**
289      * Set format string used for times.
290      *
291      * @param $fs string Format string for times.
292      */
293     function setTimeFormat ($fs) {
294         $this->_timeFormat = $fs;
295     }
296
297     /**
298      * Format a date.
299      *
300      * Any time zone offset specified in the users preferences is
301      * taken into account by this method.
302      *
303      * @param $time_t integer Unix-style time.
304      *
305      * @return string The date.
306      */
307     function formatDate ($time_t) {
308         global $request;
309         
310         $offset_time = $time_t + 3600 * $request->getPref('timeOffset');
311         // strip leading zeros from date elements (ie space followed by zero)
312         return preg_replace('/ 0/', ' ', 
313                             strftime($this->_dateFormat, $offset_time));
314     }
315
316     /**
317      * Format a date.
318      *
319      * Any time zone offset specified in the users preferences is
320      * taken into account by this method.
321      *
322      * @param $time_t integer Unix-style time.
323      *
324      * @return string The time.
325      */
326     function formatTime ($time_t) {
327         //FIXME: make 24-hour mode configurable?
328         global $request;
329         $offset_time = $time_t + 3600 * $request->getPref('timeOffset');
330         return preg_replace('/^0/', ' ',
331                             strtolower(strftime($this->_timeFormat, $offset_time)));
332     }
333
334     /**
335      * Format a date and time.
336      *
337      * Any time zone offset specified in the users preferences is
338      * taken into account by this method.
339      *
340      * @param $time_t integer Unix-style time.
341      *
342      * @return string The date and time.
343      */
344     function formatDateTime ($time_t) {
345         return $this->formatDate($time_t) . ' ' . $this->formatTime($time_t);
346     }
347
348     /**
349      * Format a (possibly relative) date.
350      *
351      * If enabled in the users preferences, this method might
352      * return a relative day (e.g. 'Today', 'Yesterday').
353      *
354      * Any time zone offset specified in the users preferences is
355      * taken into account by this method.
356      *
357      * @param $time_t integer Unix-style time.
358      *
359      * @return string The day.
360      */
361     function getDay ($time_t) {
362         global $request;
363         
364         if ($request->getPref('relativeDates') && ($date = $this->_relativeDay($time_t))) {
365             return ucfirst($date);
366         }
367         return $this->formatDate($time_t);
368     }
369     
370     /**
371      * Format the "last modified" message for a page revision.
372      *
373      * @param $revision object A WikiDB_PageRevision object.
374      *
375      * @param $show_version bool Should the page version number
376      * be included in the message.  (If this argument is omitted,
377      * then the version number will be shown only iff the revision
378      * is not the current one.
379      *
380      * @return string The "last modified" message.
381      */
382     function getLastModifiedMessage ($revision, $show_version = 'auto') {
383         global $request;
384         if (!$revision) return '';
385         
386         // dates >= this are considered invalid.
387         if (! defined('EPOCH'))
388             define('EPOCH', 0); // seconds since ~ January 1 1970
389         
390         $mtime = $revision->get('mtime');
391         if ($mtime <= EPOCH)
392             return fmt("Never edited");
393
394         if ($show_version == 'auto')
395             $show_version = !$revision->isCurrent();
396
397         if ($request->getPref('relativeDates') && ($date = $this->_relativeDay($mtime))) {
398             if ($this->_showModTime)
399                 $date =  sprintf(_("%s at %s"),
400                                  $date, $this->formatTime($mtime));
401             
402             if ($show_version)
403                 return fmt("Version %s, saved %s", $revision->getVersion(), $date);
404             else
405                 return fmt("Last edited %s", $date);
406         }
407
408         if ($this->_showModTime)
409             $date = $this->formatDateTime($mtime);
410         else
411             $date = $this->formatDate($mtime);
412         
413         if ($show_version)
414             return fmt("Version %s, saved on %s", $revision->getVersion(), $date);
415         else
416             return fmt("Last edited on %s", $date);
417     }
418     
419     function _relativeDay ($time_t) {
420         global $request;
421         
422         if (is_numeric($request->getPref('timeOffset')))
423           $offset = 3600 * $request->getPref('timeOffset');
424         else 
425           $offset = 0;          
426
427         $now = time() + $offset;
428         $today = localtime($now, true);
429         $time = localtime($time_t + $offset, true);
430
431         if ($time['tm_yday'] == $today['tm_yday'] && $time['tm_year'] == $today['tm_year'])
432             return _("today");
433         
434         // Note that due to daylight savings chages (and leap seconds), $now minus
435         // 24 hours is not guaranteed to be yesterday.
436         $yesterday = localtime($now - (12 + $today['tm_hour']) * 3600, true);
437         if ($time['tm_yday'] == $yesterday['tm_yday'] 
438             and $time['tm_year'] == $yesterday['tm_year'])
439             return _("yesterday");
440
441         return false;
442     }
443
444     /**
445      * Format the "Author" and "Owner" messages for a page revision.
446      */
447     function getOwnerMessage ($page) {
448         if (!ENABLE_PAGEPERM or !class_exists("PagePermission"))
449             return '';
450         $dbi =& $GLOBALS['request']->_dbi;
451         $owner = $page->getOwner();
452         if ($owner) {
453             /*
454             if ( mayAccessPage('change',$page->getName()) )
455                 return fmt("Owner: %s", $this->makeActionButton(array('action'=>_("chown"),
456                                                                       's' => $page->getName()),
457                                                                 $owner, $page));
458             */
459             if ( $dbi->isWikiPage($owner) )
460                 return fmt("Owner: %s", WikiLink($owner));
461             else
462                 return fmt("Owner: %s", '"'.$owner.'"');
463         }
464     }
465
466     /* New behaviour: (by Matt Brown)
467        Prefer author (name) over internal author_id (IP) */
468     function getAuthorMessage ($revision) {
469         if (!$revision) return '';
470         $dbi =& $GLOBALS['request']->_dbi;
471         $author = $revision->get('author');
472         if (!$author) $author = $revision->get('author_id');
473             if (!$author) return '';
474         if ( $dbi->isWikiPage($author) ) {
475                 return fmt("by %s", WikiLink($author));
476         } else {
477                 return fmt("by %s", '"'.$author.'"');
478         }
479     }
480
481     ////////////////////////////////////////////////////////////////
482     //
483     // Hooks for other formatting
484     //
485     ////////////////////////////////////////////////////////////////
486
487     //FIXME: PHP 4.1 Warnings
488     //lib/Theme.php:84: Notice[8]: The call_user_method() function is deprecated,
489     //use the call_user_func variety with the array(&$obj, "method") syntax instead
490
491     function getFormatter ($type, $format) {
492         $method = strtolower("get${type}Formatter");
493         if (method_exists($this, $method))
494             return $this->{$method}($format);
495         return false;
496     }
497
498     ////////////////////////////////////////////////////////////////
499     //
500     // Links
501     //
502     ////////////////////////////////////////////////////////////////
503
504     var $_autosplitWikiWords = false;
505     function setAutosplitWikiWords($autosplit=true) {
506         $this->_autosplitWikiWords = $autosplit ? true : false;
507     }
508
509     function maybeSplitWikiWord ($wikiword) {
510         if ($this->_autosplitWikiWords)
511             return SplitPagename($wikiword);
512         else
513             return $wikiword;
514     }
515
516     var $_anonEditUnknownLinks = true;
517     function setAnonEditUnknownLinks($anonedit=true) {
518         $this->_anonEditUnknownLinks = $anonedit ? true : false;
519     }
520
521     function linkExistingWikiWord($wikiword, $linktext = '', $version = false) {
522         global $request;
523
524         if ($version !== false and !$this->HTML_DUMP_SUFFIX)
525             $url = WikiURL($wikiword, array('version' => $version));
526         else
527             $url = WikiURL($wikiword);
528
529         // Extra steps for dumping page to an html file.
530         if ($this->HTML_DUMP_SUFFIX) {
531             $url = preg_replace('/^\./', '%2e', $url); // dot pages
532         }
533
534         $link = HTML::a(array('href' => $url));
535
536         if (isa($wikiword, 'WikiPageName'))
537              $default_text = $wikiword->shortName;
538          else
539              $default_text = $wikiword;
540          
541         if (!empty($linktext)) {
542             $link->pushContent($linktext);
543             $link->setAttr('class', 'named-wiki');
544             $link->setAttr('title', $this->maybeSplitWikiWord($default_text));
545         }
546         else {
547             $link->pushContent($this->maybeSplitWikiWord($default_text));
548             $link->setAttr('class', 'wiki');
549         }
550         if ($request->getArg('frame'))
551             $link->setAttr('target', '_top');
552         return $link;
553     }
554
555     function linkUnknownWikiWord($wikiword, $linktext = '') {
556         global $request;
557
558         // Get rid of anchors on unknown wikiwords
559         if (isa($wikiword, 'WikiPageName')) {
560             $default_text = $wikiword->shortName;
561             $wikiword = $wikiword->name;
562         }
563         else {
564             $default_text = $wikiword;
565         }
566         
567         if ($this->DUMP_MODE) { // HTML, PDF or XML
568             $link = HTML::u( empty($linktext) ? $wikiword : $linktext);
569             $link->addTooltip(sprintf(_("Empty link to: %s"), $wikiword));
570             $link->setAttr('class', empty($linktext) ? 'wikiunknown' : 'named-wikiunknown');
571             return $link;
572         } else {
573             // if AnonEditUnknownLinks show "?" only users which are allowed to edit this page
574             if (! $this->_anonEditUnknownLinks and 
575                 ( ! $request->_user->isSignedIn() 
576                   or ! mayAccessPage('edit', $request->getArg('pagename')))) 
577             {
578                 $text = HTML::span( empty($linktext) ? $wikiword : $linktext);
579                 $text->setAttr('class', empty($linktext) ? 'wikiunknown' : 'named-wikiunknown');
580                 return $text;
581             } else {
582                 $url = WikiURL($wikiword, array('action' => 'create'));
583                 $button = $this->makeButton('?', $url);
584                 $button->addTooltip(sprintf(_("Create: %s"), $wikiword));
585             }
586         }
587
588         $link = HTML::span();
589         if (!empty($linktext)) {
590             $link->pushContent(HTML::u($linktext));
591             $link->setAttr('class', 'named-wikiunknown');
592         }
593         else {
594             $link->pushContent(HTML::u($this->maybeSplitWikiWord($default_text)));
595             $link->setAttr('class', 'wikiunknown');
596         }
597         if (!isa($button, "ImageButton"))
598             $button->setAttr('rel', 'nofollow');
599         $link->pushContent($button);
600         if ($request->getPref('googleLink')) {
601             $gbutton = $this->makeButton('G', "http://www.google.com/search?q="
602                                          . urlencode($wikiword));
603             $gbutton->addTooltip(sprintf(_("Google:%s"), $wikiword));
604             $link->pushContent($gbutton);
605         }
606         if ($request->getArg('frame'))
607             $link->setAttr('target', '_top');
608
609         return $link;
610     }
611
612     function linkBadWikiWord($wikiword, $linktext = '') {
613         global $ErrorManager;
614         
615         if ($linktext) {
616             $text = $linktext;
617         }
618         elseif (isa($wikiword, 'WikiPageName')) {
619             $text = $wikiword->shortName;
620         }
621         else {
622             $text = $wikiword;
623         }
624
625         if (isa($wikiword, 'WikiPageName'))
626             $message = $wikiword->getWarnings();
627         else
628             $message = sprintf(_("'%s': Bad page name"), $wikiword);
629         $ErrorManager->warning($message);
630         
631         return HTML::span(array('class' => 'badwikiword'), $text);
632     }
633     
634     ////////////////////////////////////////////////////////////////
635     //
636     // Images and Icons
637     //
638     ////////////////////////////////////////////////////////////////
639     var $_imageAliases = array();
640     var $_imageAlt = array();
641
642     /**
643      *
644      * (To disable an image, alias the image to <code>false</code>.
645      */
646     function addImageAlias ($alias, $image_name) {
647         // fall back to the PhpWiki-supplied image if not found
648         if ($this->_findFile("images/$image_name", true))
649             $this->_imageAliases[$alias] = $image_name;
650     }
651
652     function addImageAlt ($alias, $alt_text) {
653         $this->_imageAlt[$alias] = $alt_text;
654     }
655     function getImageAlt ($alias) {
656         return $this->_imageAlt[$alias];
657     }
658
659     function getImageURL ($image) {
660         $aliases = &$this->_imageAliases;
661
662         if (isset($aliases[$image])) {
663             $image = $aliases[$image];
664             if (!$image)
665                 return false;
666         }
667
668         // If not extension, default to .png.
669         if (!preg_match('/\.\w+$/', $image))
670             $image .= '.png';
671
672         // FIXME: this should probably be made to fall back
673         //        automatically to .gif, .jpg.
674         //        Also try .gif before .png if browser doesn't like png.
675
676         $path = $this->_findData("images/$image", 'missing okay');
677         if (!$path) // search explicit images/ or button/ links also
678             $path = $this->_findData("$image", 'missing okay');
679
680         if ($this->DUMP_MODE) {
681             if (empty($this->dumped_images)) $this->dumped_images = array();
682             $path = "images/". basename($path);
683             if (!in_array($path,$this->dumped_images)) 
684                 $this->dumped_images[] = $path;
685         }
686         return $path;   
687     }
688
689     function setLinkIcon($proto, $image = false) {
690         if (!$image)
691             $image = $proto;
692
693         $this->_linkIcons[$proto] = $image;
694     }
695
696     function getLinkIconURL ($proto) {
697         $icons = &$this->_linkIcons;
698         if (!empty($icons[$proto]))
699             return $this->getImageURL($icons[$proto]);
700         elseif (!empty($icons['*']))
701             return $this->getImageURL($icons['*']);
702         return false;
703     }
704
705     var $_linkIcon = 'front'; // or 'after' or 'no'. 
706     // maybe also 'spanall': there is a scheme currently in effect with front, which 
707     // spans the icon only to the first, to let the next words wrap on line breaks
708     // see stdlib.php:PossiblyGlueIconToText()
709     function getLinkIconAttr () {
710         return $this->_linkIcon;
711     }
712     function setLinkIconAttr ($where) {
713         $this->_linkIcon = $where;
714     }
715
716     function addButtonAlias ($text, $alias = false) {
717         $aliases = &$this->_buttonAliases;
718
719         if (is_array($text))
720             $aliases = array_merge($aliases, $text);
721         elseif ($alias === false)
722             unset($aliases[$text]);
723         else
724             $aliases[$text] = $alias;
725     }
726
727     function getButtonURL ($text) {
728         $aliases = &$this->_buttonAliases;
729         if (isset($aliases[$text]))
730             $text = $aliases[$text];
731
732         $qtext = urlencode($text);
733         $url = $this->_findButton("$qtext.png");
734         if ($url && strstr($url, '%')) {
735             $url = preg_replace('|([^/]+)$|e', 'urlencode("\\1")', $url);
736         }
737         if (!$url) {// Jeff complained about png not supported everywhere. 
738                     // This was not PC until 2005.
739             $url = $this->_findButton("$qtext.gif");
740             if ($url && strstr($url, '%')) {
741                 $url = preg_replace('|([^/]+)$|e', 'urlencode("\\1")', $url);
742             }
743         }
744         if ($url and $this->DUMP_MODE) {
745             if (empty($this->dumped_buttons)) $this->dumped_buttons = array();
746             $file = $url;
747             if (defined('DATA_PATH'))
748                 $file = substr($url,strlen(DATA_PATH)+1);
749             $url = "images/buttons/".basename($file);
750             if (!array_key_exists($text, $this->dumped_buttons))
751                 $this->dumped_buttons[$text] = $file;
752         }
753         return $url;
754     }
755
756     function _findButton ($button_file) {
757         if (empty($this->_button_path))
758             $this->_button_path = $this->_getButtonPath();
759
760         foreach ($this->_button_path as $dir) {
761             if ($path = $this->_findData("$dir/$button_file", 1))
762                 return $path; 
763         }
764         return false;
765     }
766
767     function _getButtonPath () {
768         $button_dir = $this->_findFile("buttons");
769         $path_dir = $this->_path . $button_dir;
770         if (!file_exists($path_dir) || !is_dir($path_dir))
771             return array();
772         $path = array($button_dir);
773         
774         $dir = dir($path_dir);
775         while (($subdir = $dir->read()) !== false) {
776             if ($subdir[0] == '.')
777                 continue;
778             if ($subdir == 'CVS')
779                 continue;
780             if (is_dir("$path_dir/$subdir"))
781                 $path[] = "$button_dir/$subdir";
782         }
783         $dir->close();
784         // add default buttons
785         $path[] = "themes/default/buttons";
786         $path_dir = $this->_path . "themes/default/buttons";
787         $dir = dir($path_dir);
788         while (($subdir = $dir->read()) !== false) {
789             if ($subdir[0] == '.')
790                 continue;
791             if ($subdir == 'CVS')
792                 continue;
793             if (is_dir("$path_dir/$subdir"))
794                 $path[] = "themes/default/buttons/$subdir";
795         }
796         $dir->close();
797
798         return $path;
799     }
800
801     ////////////////////////////////////////////////////////////////
802     //
803     // Button style
804     //
805     ////////////////////////////////////////////////////////////////
806
807     function makeButton ($text, $url, $class = false) {
808         // FIXME: don't always try for image button?
809
810         // Special case: URLs like 'submit:preview' generate form
811         // submission buttons.
812         if (preg_match('/^submit:(.*)$/', $url, $m))
813             return $this->makeSubmitButton($text, $m[1], $class);
814
815         $imgurl = $this->getButtonURL($text);
816         if ($imgurl)
817             return new ImageButton($text, $url, $class, $imgurl);
818         else
819             return new Button($this->maybeSplitWikiWord($text), $url, $class);
820     }
821
822     function makeSubmitButton ($text, $name, $class = false) {
823         $imgurl = $this->getButtonURL($text);
824
825         if ($imgurl)
826             return new SubmitImageButton($text, $name, $class, $imgurl);
827         else
828             return new SubmitButton($text, $name, $class);
829     }
830
831     /**
832      * Make button to perform action.
833      *
834      * This constructs a button which performs an action on the
835      * currently selected version of the current page.
836      * (Or anotherpage or version, if you want...)
837      *
838      * @param $action string The action to perform (e.g. 'edit', 'lock').
839      * This can also be the name of an "action page" like 'LikePages'.
840      * Alternatively you can give a hash of query args to be applied
841      * to the page.
842      *
843      * @param $label string Textual label for the button.  If left empty,
844      * a suitable name will be guessed.
845      *
846      * @param $page_or_rev mixed  The page to link to.  This can be
847      * given as a string (the page name), a WikiDB_Page object, or as
848      * WikiDB_PageRevision object.  If given as a WikiDB_PageRevision
849      * object, the button will link to a specific version of the
850      * designated page, otherwise the button links to the most recent
851      * version of the page.
852      *
853      * @return object A Button object.
854      */
855     function makeActionButton ($action, $label = false, $page_or_rev = false) {
856         extract($this->_get_name_and_rev($page_or_rev));
857
858         if (is_array($action)) {
859             $attr = $action;
860             $action = isset($attr['action']) ? $attr['action'] : 'browse';
861         }
862         else
863             $attr['action'] = $action;
864
865         $class = is_safe_action($action) ? 'wikiaction' : 'wikiadmin';
866         if ( !$label )
867             $label = $this->_labelForAction($action);
868
869         if ($version)
870             $attr['version'] = $version;
871
872         if ($action == 'browse')
873             unset($attr['action']);
874
875         return $this->makeButton($label, WikiURL($pagename, $attr), $class);
876     }
877
878     /**
879      * Make a "button" which links to a wiki-page.
880      *
881      * These are really just regular WikiLinks, possibly
882      * disguised (e.g. behind an image button) by the theme.
883      *
884      * This method should probably only be used for links
885      * which appear in page navigation bars, or similar places.
886      *
887      * Use linkExistingWikiWord, or LinkWikiWord for normal links.
888      *
889      * @param $page_or_rev mixed The page to link to.  This can be
890      * given as a string (the page name), a WikiDB_Page object, or as
891      * WikiDB_PageRevision object.  If given as a WikiDB_PageRevision
892      * object, the button will link to a specific version of the
893      * designated page, otherwise the button links to the most recent
894      * version of the page.
895      *
896      * @return object A Button object.
897      */
898     function makeLinkButton ($page_or_rev, $label = false, $action = false) {
899         extract($this->_get_name_and_rev($page_or_rev));
900
901         $args = $version ? array('version' => $version) : false;
902         if ($action) $args['action'] = $action;
903
904         return $this->makeButton($label ? $label : $pagename, 
905                                  WikiURL($pagename, $args), 'wiki');
906     }
907
908     function _get_name_and_rev ($page_or_rev) {
909         $version = false;
910
911         if (empty($page_or_rev)) {
912             global $request;
913             $pagename = $request->getArg("pagename");
914             $version = $request->getArg("version");
915         }
916         elseif (is_object($page_or_rev)) {
917             if (isa($page_or_rev, 'WikiDB_PageRevision')) {
918                 $rev = $page_or_rev;
919                 $page = $rev->getPage();
920                 if (!$rev->isCurrent()) $version = $rev->getVersion();
921             }
922             else {
923                 $page = $page_or_rev;
924             }
925             $pagename = $page->getName();
926         }
927         elseif (is_numeric($page_or_rev)) {
928             $version = $page_or_rev;
929         }
930         else {
931             $pagename = (string) $page_or_rev;
932         }
933         return compact('pagename', 'version');
934     }
935
936     function _labelForAction ($action) {
937         switch ($action) {
938             case 'edit':   return _("Edit");
939             case 'diff':   return _("Diff");
940             case 'logout': return _("Sign Out");
941             case 'login':  return _("Sign In");
942             case 'lock':   return _("Lock Page");
943             case 'unlock': return _("Unlock Page");
944             case 'remove': return _("Remove Page");
945             default:
946                 // I don't think the rest of these actually get used.
947                 // 'setprefs'
948                 // 'upload' 'dumpserial' 'loadfile' 'zip'
949                 // 'save' 'browse'
950                 return gettext(ucfirst($action));
951         }
952     }
953
954     //----------------------------------------------------------------
955     var $_buttonSeparator = "\n | ";
956
957     function setButtonSeparator($separator) {
958         $this->_buttonSeparator = $separator;
959     }
960
961     function getButtonSeparator() {
962         return $this->_buttonSeparator;
963     }
964
965
966     ////////////////////////////////////////////////////////////////
967     //
968     // CSS
969     //
970     // Notes:
971     //
972     // Based on testing with Galeon 1.2.7 (Mozilla 1.2):
973     // Automatic media-based style selection (via <link> tags) only
974     // seems to work for the default style, not for alternate styles.
975     //
976     // Doing
977     //
978     //  <link rel="stylesheet" type="text/css" href="phpwiki.css" />
979     //  <link rel="stylesheet" type="text/css" href="phpwiki-printer.css" media="print" />
980     //
981     // works to make it so that the printer style sheet get used
982     // automatically when printing (or print-previewing) a page
983     // (but when only when the default style is selected.)
984     //
985     // Attempts like:
986     //
987     //  <link rel="alternate stylesheet" title="Modern"
988     //        type="text/css" href="phpwiki-modern.css" />
989     //  <link rel="alternate stylesheet" title="Modern"
990     //        type="text/css" href="phpwiki-printer.css" media="print" />
991     //
992     // Result in two "Modern" choices when trying to select alternate style.
993     // If one selects the first of those choices, one gets phpwiki-modern
994     // both when browsing and printing.  If one selects the second "Modern",
995     // one gets no CSS when browsing, and phpwiki-printer when printing.
996     //
997     // The Real Fix?
998     // =============
999     //
1000     // We should probably move to doing the media based style
1001     // switching in the CSS files themselves using, e.g.:
1002     //
1003     //  @import url(print.css) print;
1004     //
1005     ////////////////////////////////////////////////////////////////
1006
1007     function _CSSlink($title, $css_file, $media, $is_alt = false) {
1008         // Don't set title on default style.  This makes it clear to
1009         // the user which is the default (i.e. most supported) style.
1010         if ($is_alt and isBrowserKonqueror())
1011             return HTML();
1012         $link = HTML::link(array('rel'     => $is_alt ? 'alternate stylesheet' : 'stylesheet',
1013                                  'type'    => 'text/css',
1014                                  'charset' => $GLOBALS['charset'],
1015                                  'href'    => $this->_findData($css_file)));
1016         if ($is_alt)
1017             $link->setAttr('title', $title);
1018
1019         if ($media) 
1020             $link->setAttr('media', $media);
1021         if ($this->DUMP_MODE) {
1022             if (empty($this->dumped_css)) $this->dumped_css = array();
1023             if (!in_array($css_file,$this->dumped_css)) $this->dumped_css[] = $css_file;
1024             $link->setAttr('href', basename($link->getAttr('href')));
1025         }
1026         
1027         return $link;
1028     }
1029
1030     /** Set default CSS source for this theme.
1031      *
1032      * To set styles to be used for different media, pass a
1033      * hash for the second argument, e.g.
1034      *
1035      * $theme->setDefaultCSS('default', array('' => 'normal.css',
1036      *                                        'print' => 'printer.css'));
1037      *
1038      * If you call this more than once, the last one called takes
1039      * precedence as the default style.
1040      *
1041      * @param string $title Name of style (currently ignored, unless
1042      * you call this more than once, in which case, some of the style
1043      * will become alternate (rather than default) styles, and then their
1044      * titles will be used.
1045      *
1046      * @param mixed $css_files Name of CSS file, or hash containing a mapping
1047      * between media types and CSS file names.  Use a key of '' (the empty string)
1048      * to set the default CSS for non-specified media.  (See above for an example.)
1049      */
1050     function setDefaultCSS ($title, $css_files) {
1051         if (!is_array($css_files))
1052             $css_files = array('' => $css_files);
1053         // Add to the front of $this->_css
1054         unset($this->_css[$title]);
1055         $this->_css = array_merge(array($title => $css_files), $this->_css);
1056     }
1057
1058     /** Set alternate CSS source for this theme.
1059      *
1060      * @param string $title Name of style.
1061      * @param string $css_files Name of CSS file.
1062      */
1063     function addAlternateCSS ($title, $css_files) {
1064         if (!is_array($css_files))
1065             $css_files = array('' => $css_files);
1066         $this->_css[$title] = $css_files;
1067     }
1068
1069     /**
1070      * @return string HTML for CSS.
1071      */
1072     function getCSS () {
1073         $css = array();
1074         $is_alt = false;
1075         foreach ($this->_css as $title => $css_files) {
1076             ksort($css_files); // move $css_files[''] to front.
1077             foreach ($css_files as $media => $css_file) {
1078                 $css[] = $this->_CSSlink($title, $css_file, $media, $is_alt);
1079                 if ($is_alt) break;
1080                 
1081             }
1082             $is_alt = true;
1083         }
1084         return HTML($css);
1085     }
1086
1087     function findTemplate ($name) {
1088         if ($tmp = $this->_findFile("templates/$name.tmpl", 1))
1089             return $this->_path . $tmp;
1090         else {
1091             $f1 = $this->file("templates/$name.tmpl");
1092             trigger_error("pwd: ".getcwd(), E_USER_ERROR);
1093             if (isset($this->_default_theme)) {
1094                $f2 = $this->_default_theme->file("templates/$name.tmpl");
1095                trigger_error("$f1 nor $f2 found", E_USER_ERROR);
1096             } else 
1097                trigger_error("$f1 not found", E_USER_ERROR);
1098             return false;
1099         }
1100     }
1101
1102     var $_MoreHeaders = array();
1103     function addMoreHeaders ($element) {
1104         array_push($this->_MoreHeaders, $element);
1105     }
1106     function getMoreHeaders () {
1107         if (empty($this->_MoreHeaders))
1108             return '';
1109         $out = '';
1110         //$out = "<!-- More Headers -->\n";
1111         foreach ($this->_MoreHeaders as $h) {
1112             if (is_object($h))
1113                 $out .= printXML($h);
1114             else
1115                 $out .= "$h\n";
1116         }
1117         return $out;
1118     }
1119
1120     var $_MoreAttr = array();
1121     // new arg: named elements to be able to remove them. such as DoubleClickEdit for htmldumps
1122     function addMoreAttr ($tag, $name, $element) {
1123         // protect from duplicate attr (body jscript: themes, prefs, ...)
1124         static $_attr_cache = array();
1125         $hash = md5($tag."/".$element);
1126         if (!empty($_attr_cache[$hash])) return;
1127         $_attr_cache[$hash] = 1;
1128
1129         if (empty($this->_MoreAttr) or !is_array($this->_MoreAttr[$tag]))
1130             $this->_MoreAttr[$tag] = array($name => $element);
1131         else
1132             $this->_MoreAttr[$tag][$name] = $element;
1133     }
1134
1135     function getMoreAttr ($tag) {
1136         if (empty($this->_MoreAttr[$tag]))
1137             return '';
1138         $out = '';
1139         foreach ($this->_MoreAttr[$tag] as $name => $element) {
1140             if (is_object($element))
1141                 $out .= printXML($element);
1142             else
1143                 $out .= "$element";
1144         }
1145         return $out;
1146     }
1147
1148     /**
1149      * Custom UserPreferences:
1150      * A list of name => _UserPreference class pairs.
1151      * Rationale: Certain themes should be able to extend the predefined list 
1152      * of preferences. Display/editing is done in the theme specific userprefs.tmpl
1153      * but storage/sanification/update/... must be extended to the Get/SetPreferences methods.
1154      * These values are just ignored if another theme is used.
1155      */
1156     function customUserPreferences($array) {
1157         global $customUserPreferenceColumns; // FIXME: really a global?
1158         if (empty($customUserPreferenceColumns)) $customUserPreferenceColumns = array();
1159         //array('wikilens' => new _UserPreference_wikilens());
1160         foreach ($array as $field => $prefobj) {
1161             $customUserPreferenceColumns[$field] = $prefobj;
1162         }
1163     }
1164
1165     /** addPageListColumn(array('rating' => new _PageList_Column_rating('rating', _("Rate"))))
1166      *  Register custom PageList types for special themes, like 
1167      *  'rating' for wikilens
1168      */
1169     function addPageListColumn ($array) {
1170         global $customPageListColumns;
1171         if (empty($customPageListColumns)) $customPageListColumns = array();
1172         foreach ($array as $column => $obj) {
1173             $customPageListColumns[$column] = $obj;
1174         }
1175     }
1176
1177     // Works only on action=browse. Patch #970004 by pixels
1178     // Usage: call $WikiTheme->initDoubleClickEdit() from theme init or 
1179     // define ENABLE_DOUBLECLICKEDIT
1180     function initDoubleClickEdit() {
1181         if (!$this->HTML_DUMP_SUFFIX)
1182             $this->addMoreAttr('body', 'DoubleClickEdit', HTML::Raw(" ondblclick=\"url = document.URL; url2 = url; if (url.indexOf('?') != -1) url2 = url.slice(0, url.indexOf('?')); if ((url.indexOf('action') == -1) || (url.indexOf('action=browse') != -1)) document.location = url2 + '?action=edit';\""));
1183     }
1184
1185     // Immediate title search results via XMLHTML(HttpRequest
1186     // by Bitflux GmbH, bitflux.ch. You need to install the livesearch.js seperately.
1187     // Google's or acdropdown is better.
1188     function initLiveSearch() {
1189         if (!$this->HTML_DUMP_SUFFIX) {
1190             $this->addMoreAttr('body', 'LiveSearch', 
1191                                HTML::Raw(" onload=\"liveSearchInit()"));
1192             $this->addMoreHeaders(JavaScript('var liveSearchURI="'
1193                                              .WikiURL(_("TitleSearch"),false,true).'";'));
1194             $this->addMoreHeaders(JavaScript('', array
1195                                              ('src' => $this->_findData('livesearch.js'))));
1196         }
1197     }
1198
1199     // Immediate title search results via XMLHttpRequest
1200     // using the shipped moacdropdown js-lib
1201     function initMoAcDropDown() {
1202         if (!$this->HTML_DUMP_SUFFIX) {
1203             $dir = $this->_findData('moacdropdown');
1204             // if autocomplete_remote is used:
1205             foreach (array("mobrowser.js","modomevent.js","modomt.js",
1206                            "modomext.js","xmlextras.js") as $js) 
1207             {
1208                 $this->addMoreHeaders(JavaScript('', array('src' => "$dir/js/$js")));
1209             }
1210             $this->addMoreHeaders(JavaScript('', array('src' => "$dir/js/acdropdown.js")));
1211             //$this->addMoreHeaders($this->_CSSlink(0, 
1212             //                      $this->_findFile('moacdropdown/css/dropdown.css'), 'all'));
1213             $this->addMoreHeaders(HTML::style("  @import url( $dir/css/dropdown.css );\n"));
1214         }
1215     }
1216 };
1217
1218
1219 /**
1220  * A class representing a clickable "button".
1221  *
1222  * In it's simplest (default) form, a "button" is just a link associated
1223  * with some sort of wiki-action.
1224  */
1225 class Button extends HtmlElement {
1226     /** Constructor
1227      *
1228      * @param $text string The text for the button.
1229      * @param $url string The url (href) for the button.
1230      * @param $class string The CSS class for the button.
1231      */
1232     function Button ($text, $url, $class = false) {
1233         global $request;
1234         //php5 workaround
1235         if (check_php_version(5)) {
1236             $this->_init('a', array('href' => $url));
1237         } else {
1238             $this->__construct('a', array('href' => $url));
1239         }
1240         if ($class)
1241             $this->setAttr('class', $class);
1242         if ($request->getArg('frame'))
1243             $this->setAttr('target', '_top');
1244         // Google honors this
1245         if (in_array(strtolower($text), array('edit','create','diff','pdf'))
1246             and !$request->_user->isAuthenticated())
1247             $this->setAttr('rel', 'nofollow');
1248         $this->pushContent($GLOBALS['WikiTheme']->maybeSplitWikiWord($text));
1249     }
1250
1251 };
1252
1253
1254 /**
1255  * A clickable image button.
1256  */
1257 class ImageButton extends Button {
1258     /** Constructor
1259      *
1260      * @param $text string The text for the button.
1261      * @param $url string The url (href) for the button.
1262      * @param $class string The CSS class for the button.
1263      * @param $img_url string URL for button's image.
1264      * @param $img_attr array Additional attributes for the &lt;img&gt; tag.
1265      */
1266     function ImageButton ($text, $url, $class, $img_url, $img_attr = false) {
1267         $this->__construct('a', array('href' => $url));
1268         if ($class)
1269             $this->setAttr('class', $class);
1270         // Google honors this
1271         if (in_array(strtolower($text), array('edit','create','diff','pdf'))
1272             and !$GLOBALS['request']->_user->isAuthenticated())
1273             $this->setAttr('rel', 'nofollow');
1274
1275         if (!is_array($img_attr))
1276             $img_attr = array();
1277         $img_attr['src'] = $img_url;
1278         $img_attr['alt'] = $text;
1279         $img_attr['class'] = 'wiki-button';
1280         $img_attr['border'] = 0;
1281         $this->pushContent(HTML::img($img_attr));
1282     }
1283 };
1284
1285 /**
1286  * A class representing a form <samp>submit</samp> button.
1287  */
1288 class SubmitButton extends HtmlElement {
1289     /** Constructor
1290      *
1291      * @param $text string The text for the button.
1292      * @param $name string The name of the form field.
1293      * @param $class string The CSS class for the button.
1294      */
1295     function SubmitButton ($text, $name = false, $class = false) {
1296         $this->__construct('input', array('type' => 'submit',
1297                                           'value' => $text));
1298         if ($name)
1299             $this->setAttr('name', $name);
1300         if ($class)
1301             $this->setAttr('class', $class);
1302     }
1303
1304 };
1305
1306
1307 /**
1308  * A class representing an image form <samp>submit</samp> button.
1309  */
1310 class SubmitImageButton extends SubmitButton {
1311     /** Constructor
1312      *
1313      * @param $text string The text for the button.
1314      * @param $name string The name of the form field.
1315      * @param $class string The CSS class for the button.
1316      * @param $img_url string URL for button's image.
1317      * @param $img_attr array Additional attributes for the &lt;img&gt; tag.
1318      */
1319     function SubmitImageButton ($text, $name = false, $class = false, $img_url) {
1320         $this->__construct('input', array('type'  => 'image',
1321                                           'src'   => $img_url,
1322                                           'value' => $text,
1323                                           'alt'   => $text));
1324         if ($name)
1325             $this->setAttr('name', $name);
1326         if ($class)
1327             $this->setAttr('class', $class);
1328     }
1329
1330 };
1331
1332 /** 
1333  * A sidebar box with title and body, narrow fixed-width.
1334  * To represent abbrevated content of plugins, links or forms,
1335  * like "Getting Started", "Search", "Sarch Pagename", 
1336  * "Login", "Menu", "Recent Changes", "Last comments", "Last Blogs"
1337  * "Calendar"
1338  * ... See http://tikiwiki.org/
1339  *
1340  * Usage:
1341  * sidebar.tmpl:
1342  *   $menu = SidebarBox("Menu",HTML::dl(HTML::dt(...))); $menu->format();
1343  *   $menu = PluginSidebarBox("RecentChanges",array('limit'=>10)); $menu->format();
1344  */
1345 class SidebarBox {
1346
1347     function SidebarBox($title, $body) {
1348         require_once('lib/WikiPlugin.php');
1349         $this->title = $title;
1350         $this->body = $body;
1351     }
1352     function format() {
1353         return WikiPlugin::makeBox($this->title, $this->body);
1354     }
1355 }
1356
1357 /** 
1358  * A sidebar box for plugins.
1359  * Any plugin may provide a box($args=false, $request=false, $basepage=false)
1360  * method, with the help of WikiPlugin::makeBox()
1361  */
1362 class PluginSidebarBox extends SidebarBox {
1363
1364     var $_plugin, $_args = false, $_basepage = false;
1365
1366     function PluginSidebarBox($name, $args = false, $basepage = false) {
1367         $loader = new WikiPluginLoader();
1368         $plugin = $loader->getPlugin($name);
1369         if (!$plugin) {
1370             return $loader->_error(sprintf(_("Plugin %s: undefined"),
1371                                           $name));
1372         }/*
1373         if (!method_exists($plugin, 'box')) {
1374             return $loader->_error(sprintf(_("%s: has no box method"),
1375                                            get_class($plugin)));
1376         }*/
1377         $this->_plugin   =& $plugin;
1378         $this->_args     = $args ? $args : array();
1379         $this->_basepage = $basepage;
1380     }
1381
1382     function format($args = false) {
1383         return $this->_plugin->box($args ? array_merge($this->_args, $args) : $this->_args,
1384                                    $GLOBALS['request'], 
1385                                    $this->_basepage);
1386     }
1387 }
1388
1389 // Various boxes which are no plugins
1390 class RelatedLinksBox extends SidebarBox {
1391     function RelatedLinksBox($title = false, $body = '', $limit = 20) {
1392         global $request;
1393         $this->title = $title ? $title : _("Related Links");
1394         $this->body = HTML($body);
1395         $page = $request->getPage($request->getArg('pagename'));
1396         $revision = $page->getCurrentRevision();
1397         $page_content = $revision->getTransformedContent();
1398         //$cache = &$page->_wikidb->_cache;
1399         $counter = 0;
1400         $sp = HTML::Raw('&middot; ');
1401         foreach ($page_content->getWikiPageLinks() as $link) {
1402             if (!$request->_dbi->isWikiPage($link)) continue;
1403             $this->body->pushContent($sp, WikiLink($link), HTML::br());
1404             $counter++;
1405             if ($limit and $counter > $limit) continue;
1406         }
1407     }
1408 }
1409
1410 class RelatedExternalLinksBox extends SidebarBox {
1411     function RelatedExternalLinksBox($title = false, $body = '', $limit = 20) {
1412         global $request;
1413         $this->title = $title ? $title : _("External Links");
1414         $this->body = HTML($body);
1415         $page = $request->getPage($request->getArg('pagename'));
1416         $cache = &$page->_wikidb->_cache;
1417         $counter = 0;
1418         $sp = HTML::Raw('&middot; ');
1419         foreach ($cache->getWikiPageLinks() as $link) {
1420             if ($link) {
1421                 $this->body->pushContent($sp, WikiLink($link), HTML::br());
1422                 $counter++;
1423                 if ($limit and $counter > $limit) continue;
1424             }
1425         }
1426     }
1427 }
1428
1429 function listAvailableThemes() {
1430     $available_themes = array(); 
1431     $dir_root = 'themes';
1432     if (defined('PHPWIKI_DIR'))
1433         $dir_root = PHPWIKI_DIR . "/$dir_root";
1434     $dir = dir($dir_root);
1435     if ($dir) {
1436         while($entry = $dir->read()) {
1437             if (is_dir($dir_root.'/'.$entry)
1438                 && (substr($entry,0,1) != '.')
1439                 && $entry != 'CVS') {
1440                 array_push($available_themes, $entry);
1441             }
1442         }
1443         $dir->close();
1444     }
1445     return $available_themes;
1446 }
1447
1448 function listAvailableLanguages() {
1449     $available_languages = array('en');
1450     $dir_root = 'locale';
1451     if (defined('PHPWIKI_DIR'))
1452         $dir_root = PHPWIKI_DIR . "/$dir_root";
1453     if ($dir = dir($dir_root)) {
1454         while($entry = $dir->read()) {
1455             if (is_dir($dir_root."/".$entry)
1456                 && (substr($entry,0,1) != '.')
1457                 && $entry != 'po'
1458                 && $entry != 'CVS') 
1459             {
1460                 array_push($available_languages, $entry);
1461             }
1462         }
1463         $dir->close();
1464     }
1465     return $available_languages;
1466 }
1467
1468 // $Log: not supported by cvs2svn $
1469 // Revision 1.133  2006/03/19 14:24:38  rurban
1470 // sf.net patch #1377650 by Matt Brown:  Always prefer legible author name over author_id property
1471 //
1472 // Revision 1.132  2005/07/24 09:51:22  rurban
1473 // guard doubleClickEdit for unittests, add AcDropDown support
1474 //
1475 // Revision 1.131  2005/06/10 06:09:06  rurban
1476 // enable getPref('doubleClickEdit')
1477 //
1478 // Revision 1.130  2005/05/06 16:43:35  rurban
1479 // split long lines
1480 //
1481 // Revision 1.129  2005/05/05 08:57:26  rurban
1482 // support action=revert
1483 //
1484 // Revision 1.128  2005/04/23 11:23:49  rurban
1485 // improve semantics in the setAutosplitWikiWords method: switch to true if no args
1486 //
1487 // Revision 1.127  2005/02/11 14:45:44  rurban
1488 // support ENABLE_LIVESEARCH, enable PDO sessions
1489 //
1490 // Revision 1.126  2005/02/04 11:43:18  rurban
1491 // update comments
1492 //
1493 // Revision 1.125  2005/02/03 05:09:56  rurban
1494 // livesearch.js support
1495 //
1496 // Revision 1.124  2005/01/27 16:28:15  rurban
1497 // especially for Google: nofollow on unauthenticated edit,diff,create,pdf
1498 //
1499 // Revision 1.123  2005/01/25 07:03:02  rurban
1500 // change addMoreAttr() to support named attr, to remove DoubleClickEdit for htmldumps
1501 //
1502 // Revision 1.122  2005/01/21 11:51:22  rurban
1503 // changed (c)
1504 //
1505 // Revision 1.121  2005/01/20 10:14:37  rurban
1506 // rel=nofollow on edit/create page links
1507 //
1508 // Revision 1.120  2004/12/20 13:20:23  rurban
1509 // fix problem described in patch #1088131. SidebarBox may be used before lib/WikiPlugin.php
1510 // is loaded.
1511 //
1512 // Revision 1.119  2004/12/14 21:38:12  rurban
1513 // just aesthetics
1514 //
1515 // Revision 1.118  2004/12/13 14:34:46  rurban
1516 // box parent method exists
1517 //
1518 // Revision 1.117  2004/11/30 17:44:54  rurban
1519 // revisison neutral
1520 //
1521 // Revision 1.116  2004/11/21 11:59:16  rurban
1522 // remove final \n to be ob_cache independent
1523 //
1524 // Revision 1.115  2004/11/17 17:24:02  rurban
1525 // more verbose on fatal template not found
1526 //
1527 // Revision 1.114  2004/11/11 18:31:26  rurban
1528 // add simple backtrace on such general failures to get at least an idea where
1529 //
1530 // Revision 1.113  2004/11/09 17:11:04  rurban
1531 // * revert to the wikidb ref passing. there's no memory abuse there.
1532 // * use new wikidb->_cache->_id_cache[] instead of wikidb->_iwpcache, to effectively
1533 //   store page ids with getPageLinks (GleanDescription) of all existing pages, which
1534 //   are also needed at the rendering for linkExistingWikiWord().
1535 //   pass options to pageiterator.
1536 //   use this cache also for _get_pageid()
1537 //   This saves about 8 SELECT count per page (num all pagelinks).
1538 // * fix passing of all page fields to the pageiterator.
1539 // * fix overlarge session data which got broken with the latest ACCESS_LOG_SQL changes
1540 //
1541 // Revision 1.112  2004/11/03 16:50:31  rurban
1542 // some new defaults and constants, renamed USE_DOUBLECLICKEDIT to ENABLE_DOUBLECLICKEDIT
1543 //
1544 // Revision 1.111  2004/10/21 20:20:53  rurban
1545 // From patch #970004 "Double clic to edit" by pixels.
1546 //
1547 // Revision 1.110  2004/10/15 11:05:10  rurban
1548 // fix yesterdays premature dumphtml fix for $default_text (thanks John Shen)
1549 //
1550 // Revision 1.109  2004/10/14 21:06:02  rurban
1551 // fix dumphtml with USE_PATH_INFO (again). fix some PageList refs
1552 //
1553 // Revision 1.108  2004/09/26 12:24:02  rurban
1554 // no anchor (PCRE memory), explicit ^ instead
1555 //
1556 // Revision 1.107  2004/06/21 16:22:29  rurban
1557 // add DEFAULT_DUMP_DIR and HTML_DUMP_DIR constants, for easier cmdline dumps,
1558 // fixed dumping buttons locally (images/buttons/),
1559 // support pages arg for dumphtml,
1560 // optional directory arg for dumpserial + dumphtml,
1561 // fix a AllPages warning,
1562 // show dump warnings/errors on DEBUG,
1563 // don't warn just ignore on wikilens pagelist columns, if not loaded.
1564 // RateIt pagelist column is called "rating", not "ratingwidget" (Dan?)
1565 //
1566 // Revision 1.106  2004/06/20 14:42:54  rurban
1567 // various php5 fixes (still broken at blockparser)
1568 //
1569 // Revision 1.105  2004/06/14 11:31:36  rurban
1570 // renamed global $Theme to $WikiTheme (gforge nameclash)
1571 // inherit PageList default options from PageList
1572 //   default sortby=pagename
1573 // use options in PageList_Selectable (limit, sortby, ...)
1574 // added action revert, with button at action=diff
1575 // added option regex to WikiAdminSearchReplace
1576 //
1577 // Revision 1.104  2004/06/11 09:07:30  rurban
1578 // support theme-specific LinkIconAttr: front or after or none
1579 //
1580 // Revision 1.103  2004/06/07 22:44:14  rurban
1581 // added simplified chown, setacl actions
1582 //
1583 // Revision 1.102  2004/06/07 18:59:28  rurban
1584 // added Chown link to Owner in statusbar
1585 //
1586 // Revision 1.101  2004/06/03 12:59:40  rurban
1587 // simplify translation
1588 // NS4 wrap=virtual only
1589 //
1590 // Revision 1.100  2004/06/03 10:18:19  rurban
1591 // fix FileUser locking issues, new config ENABLE_PAGEPERM
1592 //
1593 // Revision 1.99  2004/06/01 15:27:59  rurban
1594 // AdminUser only ADMIN_USER not member of Administrators
1595 // some RateIt improvements by dfrankow
1596 // edit_toolbar buttons
1597 //
1598 // Revision 1.98  2004/05/27 17:49:05  rurban
1599 // renamed DB_Session to DbSession (in CVS also)
1600 // added WikiDB->getParam and WikiDB->getAuthParam method to get rid of globals
1601 // remove leading slash in error message
1602 // added force_unlock parameter to File_Passwd (no return on stale locks)
1603 // fixed adodb session AffectedRows
1604 // added FileFinder helpers to unify local filenames and DATA_PATH names
1605 // editpage.php: new edit toolbar javascript on ENABLE_EDIT_TOOLBAR
1606 //
1607 // Revision 1.97  2004/05/18 16:23:39  rurban
1608 // rename split_pagename to SplitPagename
1609 //
1610 // Revision 1.96  2004/05/13 13:48:34  rurban
1611 // doc update for the new 1.3.10 release
1612 //
1613 // Revision 1.94  2004/05/13 11:52:34  rurban
1614 // search also default buttons
1615 //
1616 // Revision 1.93  2004/05/12 10:49:55  rurban
1617 // require_once fix for those libs which are loaded before FileFinder and
1618 //   its automatic include_path fix, and where require_once doesn't grok
1619 //   dirname(__FILE__) != './lib'
1620 // upgrade fix with PearDB
1621 // navbar.tmpl: remove spaces for IE &nbsp; button alignment
1622 //
1623 // Revision 1.92  2004/05/03 21:57:47  rurban
1624 // locale updates: we previously lost some words because of wrong strings in
1625 //   PhotoAlbum, german rewording.
1626 // fixed $_SESSION registering (lost session vars, esp. prefs)
1627 // fixed ending slash in listAvailableLanguages/Themes
1628 //
1629 // Revision 1.91  2004/05/03 11:40:42  rurban
1630 // put listAvailableLanguages() and listAvailableThemes() from SystemInfo and
1631 // UserPreferences into Themes.php
1632 //
1633 // Revision 1.90  2004/05/02 19:12:14  rurban
1634 // fix sf.net bug #945154 Konqueror alt css
1635 //
1636 // Revision 1.89  2004/04/29 21:25:45  rurban
1637 // default theme navbar consistency: linkButtons instead of action buttons
1638 //   3rd makeLinkButtin arg for action support
1639 //
1640 // Revision 1.88  2004/04/19 18:27:45  rurban
1641 // Prevent from some PHP5 warnings (ref args, no :: object init)
1642 //   php5 runs now through, just one wrong XmlElement object init missing
1643 // Removed unneccesary UpgradeUser lines
1644 // Changed WikiLink to omit version if current (RecentChanges)
1645 //
1646 // Revision 1.87  2004/04/19 09:13:23  rurban
1647 // new pref: googleLink
1648 //
1649 // Revision 1.86  2004/04/18 01:11:51  rurban
1650 // more numeric pagename fixes.
1651 // fixed action=upload with merge conflict warnings.
1652 // charset changed from constant to global (dynamic utf-8 switching)
1653 //
1654 // Revision 1.85  2004/04/12 13:04:50  rurban
1655 // added auth_create: self-registering Db users
1656 // fixed IMAP auth
1657 // removed rating recommendations
1658 // ziplib reformatting
1659 //
1660 // Revision 1.84  2004/04/10 02:30:49  rurban
1661 // Fixed gettext problem with VIRTUAL_PATH scripts (Windows only probably)
1662 // Fixed "cannot setlocale..." (sf.net problem)
1663 //
1664 // Revision 1.83  2004/04/09 17:49:03  rurban
1665 // Added PhpWiki RssFeed to Sidebar
1666 // sidebar formatting
1667 // some browser dependant fixes (old-browser support)
1668 //
1669 // Revision 1.82  2004/04/06 20:00:10  rurban
1670 // Cleanup of special PageList column types
1671 // Added support of plugin and theme specific Pagelist Types
1672 // Added support for theme specific UserPreferences
1673 // Added session support for ip-based throttling
1674 //   sql table schema change: ALTER TABLE session ADD sess_ip CHAR(15);
1675 // Enhanced postgres schema
1676 // Added DB_Session_dba support
1677 //
1678 // Revision 1.81  2004/04/01 15:57:10  rurban
1679 // simplified Sidebar theme: table, not absolute css positioning
1680 // added the new box methods.
1681 // remaining problems: large left margin, how to override _autosplitWikiWords in Template only
1682 //
1683 // Revision 1.80  2004/03/30 02:14:03  rurban
1684 // fixed yet another Prefs bug
1685 // added generic PearDb_iter
1686 // $request->appendValidators no so strict as before
1687 // added some box plugin methods
1688 // PageList commalist for condensed output
1689 //
1690 // Revision 1.79  2004/03/24 19:39:02  rurban
1691 // php5 workaround code (plus some interim debugging code in XmlElement)
1692 //   php5 doesn't work yet with the current XmlElement class constructors,
1693 //   WikiUserNew does work better than php4.
1694 // rewrote WikiUserNew user upgrading to ease php5 update
1695 // fixed pref handling in WikiUserNew
1696 // added Email Notification
1697 // added simple Email verification
1698 // removed emailVerify userpref subclass: just a email property
1699 // changed pref binary storage layout: numarray => hash of non default values
1700 // print optimize message only if really done.
1701 // forced new cookie policy: delete pref cookies, use only WIKI_ID as plain string.
1702 //   prefs should be stored in db or homepage, besides the current session.
1703 //
1704 // Revision 1.78  2004/03/18 22:32:33  rurban
1705 // work to make it php5 compatible
1706 //
1707 // Revision 1.77  2004/03/08 19:30:01  rurban
1708 // fixed Theme->getButtonURL
1709 // AllUsers uses now WikiGroup (also DB User and DB Pref users)
1710 // PageList fix for empty pagenames
1711 //
1712 // Revision 1.76  2004/03/08 18:17:09  rurban
1713 // added more WikiGroup::getMembersOf methods, esp. for special groups
1714 // fixed $LDAP_SET_OPTIONS
1715 // fixed _AuthInfo group methods
1716 //
1717 // Revision 1.75  2004/03/01 09:34:37  rurban
1718 // fixed button path logic: now fallback to default also
1719 //
1720 // Revision 1.74  2004/02/28 21:14:08  rurban
1721 // generally more PHPDOC docs
1722 //   see http://xarch.tu-graz.ac.at/home/rurban/phpwiki/xref/
1723 // fxied WikiUserNew pref handling: empty theme not stored, save only
1724 //   changed prefs, sql prefs improved, fixed password update,
1725 //   removed REPLACE sql (dangerous)
1726 // moved gettext init after the locale was guessed
1727 // + some minor changes
1728 //
1729 // Revision 1.73  2004/02/26 03:22:05  rurban
1730 // also copy css and images with XHTML Dump
1731 //
1732 // Revision 1.72  2004/02/26 02:25:53  rurban
1733 // fix empty and #-anchored links in XHTML Dumps
1734 //
1735 // Revision 1.71  2004/02/15 21:34:37  rurban
1736 // PageList enhanced and improved.
1737 // fixed new WikiAdmin... plugins
1738 // editpage, Theme with exp. htmlarea framework
1739 //   (htmlarea yet committed, this is really questionable)
1740 // WikiUser... code with better session handling for prefs
1741 // enhanced UserPreferences (again)
1742 // RecentChanges for show_deleted: how should pages be deleted then?
1743 //
1744 // Revision 1.70  2004/01/26 09:17:48  rurban
1745 // * changed stored pref representation as before.
1746 //   the array of objects is 1) bigger and 2)
1747 //   less portable. If we would import packed pref
1748 //   objects and the object definition was changed, PHP would fail.
1749 //   This doesn't happen with an simple array of non-default values.
1750 // * use $prefs->retrieve and $prefs->store methods, where retrieve
1751 //   understands the interim format of array of objects also.
1752 // * simplified $prefs->get() and fixed $prefs->set()
1753 // * added $user->_userid and class '_WikiUser' portability functions
1754 // * fixed $user object ->_level upgrading, mostly using sessions.
1755 //   this fixes yesterdays problems with loosing authorization level.
1756 // * fixed WikiUserNew::checkPass to return the _level
1757 // * fixed WikiUserNew::isSignedIn
1758 // * added explodePageList to class PageList, support sortby arg
1759 // * fixed UserPreferences for WikiUserNew
1760 // * fixed WikiPlugin for empty defaults array
1761 // * UnfoldSubpages: added pagename arg, renamed pages arg,
1762 //   removed sort arg, support sortby arg
1763 //
1764 // Revision 1.69  2003/12/05 01:32:28  carstenklapp
1765 // New feature: Easier to run multiple wiks off of one set of code. Name
1766 // your logo and signature image files "YourWikiNameLogo.png" and
1767 // "YourWikiNameSignature.png" and put them all into
1768 // themes/default/images. YourWikiName should match what is defined as
1769 // WIKI_NAME in index.php. In case the image is not found, the default
1770 // shipped with PhpWiki will be used.
1771 //
1772 // Revision 1.68  2003/03/04 01:53:30  dairiki
1773 // Inconsequential decrufting.
1774 //
1775 // Revision 1.67  2003/02/26 03:40:22  dairiki
1776 // New action=create.  Essentially the same as action=edit, except that if the
1777 // page already exists, it falls back to action=browse.
1778 //
1779 // This is for use in the "question mark" links for unknown wiki words
1780 // to avoid problems and confusion when following links from stale pages.
1781 // (If the "unknown page" has been created in the interim, the user probably
1782 // wants to view the page before editing it.)
1783 //
1784 // Revision 1.66  2003/02/26 00:10:26  dairiki
1785 // More/better/different checks for bad page names.
1786 //
1787 // Revision 1.65  2003/02/24 22:41:57  dairiki
1788 // Fix stupid typo.
1789 //
1790 // Revision 1.64  2003/02/24 22:06:14  dairiki
1791 // Attempts to fix auto-selection of printer CSS when printing.
1792 // See new comments lib/Theme.php for more details.
1793 // Also see SF patch #669563.
1794 //
1795 // Revision 1.63  2003/02/23 03:37:05  dairiki
1796 // Stupid typo/bug fix.
1797 //
1798 // Revision 1.62  2003/02/21 04:14:52  dairiki
1799 // New WikiLink type 'if_known'.  This gives linkified name if page
1800 // exists, otherwise, just plain text.
1801 //
1802 // Revision 1.61  2003/02/18 21:52:05  dairiki
1803 // Fix so that one can still link to wiki pages with # in their names.
1804 // (This was made difficult by the introduction of named tags, since
1805 // '[Page #1]' is now a link to anchor '1' in page 'Page'.
1806 //
1807 // Now the ~ escape for page names should work: [Page ~#1].
1808 //
1809 // Revision 1.60  2003/02/15 01:59:47  dairiki
1810 // Theme::getCSS():  Add Default-Style HTTP(-eqiv) header in attempt
1811 // to fix default stylesheet selection on some browsers.
1812 // For details on the Default-Style header, see:
1813 //  http://home.dairiki.org/docs/html4/present/styles.html#h-14.3.2
1814 //
1815 // Revision 1.59  2003/01/04 22:30:16  carstenklapp
1816 // New: display a "Never edited." message instead of an invalid epoch date.
1817 //
1818
1819 // (c-file-style: "gnu")
1820 // Local Variables:
1821 // mode: php
1822 // tab-width: 8
1823 // c-basic-offset: 4
1824 // c-hanging-comment-ender-p: nil
1825 // indent-tabs-mode: nil
1826 // End:
1827 ?>