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