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