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