1 <?php rcs_id('$Id: Theme.php,v 1.96 2004-05-13 13:48:34 rurban Exp $');
2 /* Copyright (C) 2002,2004 $ThePhpWikiProgrammingTeam
4 * This file is part of PhpWiki.
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.
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.
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
22 * Customize output by themes: templates, css, special links functions,
23 * and more formatting.
26 require_once(dirname(__FILE__).'/HtmlElement.php');
29 * Make a link to a wiki page (in this wiki).
31 * This is a convenience function.
33 * @param mixed $page_or_rev
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>
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>
48 * Unless $type of of the latter form, the link will be of class 'wiki', 'wikiunknown',
49 * 'named-wiki', or 'named-wikiunknown', as appropriate.
51 * @param mixed $label (string or XmlContent object)
52 * Label for the link. If not given, defaults to the page name.
54 * @return XmlContent The link
56 function WikiLink ($page_or_rev, $type = 'known', $label = false) {
57 global $Theme, $request;
59 if ($type == 'button') {
60 return $Theme->makeLinkButton($page_or_rev, $label);
65 if (isa($page_or_rev, 'WikiDB_PageRevision')) {
66 $version = $page_or_rev->getVersion();
67 if ($page_or_rev->isCurrent())
69 $page = $page_or_rev->getPage();
70 $pagename = $page->getName();
71 $wikipage = $pagename;
74 elseif (isa($page_or_rev, 'WikiDB_Page')) {
76 $pagename = $page->getName();
77 $wikipage = $pagename;
79 elseif (isa($page_or_rev, 'WikiPageName')) {
80 $wikipage = $page_or_rev;
81 $pagename = $wikipage->name;
84 $wikipage = new WikiPageName($page_or_rev, $request->getPage());
85 $pagename = $wikipage->name;
88 if (!is_string($wikipage) and !$wikipage->isValid('strict'))
89 return $Theme->linkBadWikiWord($wikipage, $label);
91 if ($type == 'auto' or $type == 'if_known') {
93 $current = $page->getCurrentRevision();
94 $exists = ! $current->hasDefaultContents();
97 $dbi = $request->getDbh();
98 $exists = $dbi->isWikiPage($wikipage->name);
101 elseif ($type == 'unknown') {
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
114 strchr(substr($wikipage->shortName,1), SUBPAGE_SEPARATOR))
116 $parts = explode(SUBPAGE_SEPARATOR, $wikipage->shortName);
117 $last_part = array_pop($parts);
119 $link = HTML::span();
120 foreach ($parts as $part) {
122 $parent = join(SUBPAGE_SEPARATOR, $path);
123 if ($Theme->_autosplitWikiWords)
126 $link->pushContent($Theme->linkExistingWikiWord($parent, $sep . $part));
127 $sep = $Theme->_autosplitWikiWords ? ' ' . SUBPAGE_SEPARATOR : SUBPAGE_SEPARATOR;
130 $link->pushContent($Theme->linkExistingWikiWord($wikipage, $sep . $last_part, $version));
132 $link->pushContent($Theme->linkUnknownWikiWord($wikipage, $sep . $last_part));
137 return $Theme->linkExistingWikiWord($wikipage, $label, $version);
139 elseif ($type == 'if_known') {
140 if (!$label && isa($wikipage, 'WikiPageName'))
141 $label = $wikipage->shortName;
142 return HTML($label ? $label : $pagename);
145 return $Theme->linkUnknownWikiWord($wikipage, $label);
154 * This is a convenience function.
156 * @param $action string
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')
167 * @param $label string
168 * A label for the button. If ommited, a suitable default (based on the valued of $action)
171 * @param $page_or_rev mixed
172 * Which page (& version) to perform the action on.
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>
178 * ($Page_or_rev is ignored for submit buttons.)
180 function Button ($action, $label = false, $page_or_rev = false) {
183 if (!is_array($action) && preg_match('/submit:(.*)/A', $action, $m))
184 return $Theme->makeSubmitButton($label, $m[1], $class = $page_or_rev);
186 return $Theme->makeActionButton($action, $label, $page_or_rev);
191 var $HTML_DUMP_SUFFIX = '';
192 var $DUMP_MODE = false, $dumped_images, $dumped_css;
194 function Theme ($theme_name = 'default') {
195 $this->_name = $theme_name;
196 $themes_dir = defined('PHPWIKI_DIR') ? PHPWIKI_DIR . "/themes" : "themes";
198 $this->_path = defined('PHPWIKI_DIR') ? PHPWIKI_DIR . "/" : "";
199 $this->_theme = "themes/$theme_name";
201 if ($theme_name != 'default')
202 $this->_default_theme = new Theme;
204 $this->_css = array();
207 function file ($file) {
208 return $this->_path . "$this->_theme/$file";
211 function _findFile ($file, $missing_okay = false) {
212 if (file_exists($this->_path . "$this->_theme/$file"))
213 return "$this->_theme/$file";
215 // FIXME: this is a short-term hack. Delete this after all files
216 // get moved into themes/...
217 if (file_exists($this->_path . $file))
221 if (isset($this->_default_theme)) {
222 return $this->_default_theme->_findFile($file, $missing_okay);
224 else if (!$missing_okay) {
225 trigger_error("$file: not found", E_USER_NOTICE);
230 function _findData ($file, $missing_okay = false) {
231 $path = $this->_findFile($file, $missing_okay);
235 if (defined('DATA_PATH'))
236 return DATA_PATH . "/$path";
240 ////////////////////////////////////////////////////////////////
242 // Date and Time formatting
244 ////////////////////////////////////////////////////////////////
246 // Note: Windows' implemetation of strftime does not include certain
247 // format specifiers, such as %e (for date without leading zeros). In
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.
252 var $_dateFormat = "%B %d, %Y";
253 var $_timeFormat = "%I:%M %p";
255 var $_showModTime = true;
258 * Set format string used for dates.
260 * @param $fs string Format string for dates.
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.
266 function setDateFormat ($fs, $show_mod_time = true) {
267 $this->_dateFormat = $fs;
268 $this->_showModTime = $show_mod_time;
272 * Set format string used for times.
274 * @param $fs string Format string for times.
276 function setTimeFormat ($fs) {
277 $this->_timeFormat = $fs;
283 * Any time zone offset specified in the users preferences is
284 * taken into account by this method.
286 * @param $time_t integer Unix-style time.
288 * @return string The date.
290 function formatDate ($time_t) {
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));
302 * Any time zone offset specified in the users preferences is
303 * taken into account by this method.
305 * @param $time_t integer Unix-style time.
307 * @return string The time.
309 function formatTime ($time_t) {
310 //FIXME: make 24-hour mode configurable?
312 $offset_time = $time_t + 3600 * $request->getPref('timeOffset');
313 return preg_replace('/^0/', ' ',
314 strtolower(strftime($this->_timeFormat, $offset_time)));
318 * Format a date and time.
320 * Any time zone offset specified in the users preferences is
321 * taken into account by this method.
323 * @param $time_t integer Unix-style time.
325 * @return string The date and time.
327 function formatDateTime ($time_t) {
328 return $this->formatDate($time_t) . ' ' . $this->formatTime($time_t);
332 * Format a (possibly relative) date.
334 * If enabled in the users preferences, this method might
335 * return a relative day (e.g. 'Today', 'Yesterday').
337 * Any time zone offset specified in the users preferences is
338 * taken into account by this method.
340 * @param $time_t integer Unix-style time.
342 * @return string The day.
344 function getDay ($time_t) {
347 if ($request->getPref('relativeDates') && ($date = $this->_relativeDay($time_t))) {
348 return ucfirst($date);
350 return $this->formatDate($time_t);
354 * Format the "last modified" message for a page revision.
356 * @param $revision object A WikiDB_PageRevision object.
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.
363 * @return string The "last modified" message.
365 function getLastModifiedMessage ($revision, $show_version = 'auto') {
368 // dates >= this are considered invalid.
369 if (! defined('EPOCH'))
370 define('EPOCH', 0); // seconds since ~ January 1 1970
372 $mtime = $revision->get('mtime');
374 return fmt("Never edited.");
376 if ($show_version == 'auto')
377 $show_version = !$revision->isCurrent();
379 if ($request->getPref('relativeDates') && ($date = $this->_relativeDay($mtime))) {
380 if ($this->_showModTime)
381 $date = sprintf(_("%s at %s"),
382 $date, $this->formatTime($mtime));
385 return fmt("Version %s, saved %s.", $revision->getVersion(), $date);
387 return fmt("Last edited %s.", $date);
390 if ($this->_showModTime)
391 $date = $this->formatDateTime($mtime);
393 $date = $this->formatDate($mtime);
396 return fmt("Version %s, saved on %s.", $revision->getVersion(), $date);
398 return fmt("Last edited on %s.", $date);
401 function _relativeDay ($time_t) {
404 if (is_numeric($request->getPref('timeOffset')))
405 $offset = 3600 * $request->getPref('timeOffset');
409 $now = time() + $offset;
410 $today = localtime($now, true);
411 $time = localtime($time_t + $offset, true);
413 if ($time['tm_yday'] == $today['tm_yday'] && $time['tm_year'] == $today['tm_year'])
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");
425 ////////////////////////////////////////////////////////////////
427 // Hooks for other formatting
429 ////////////////////////////////////////////////////////////////
431 //FIXME: PHP 4.1 Warnings
432 //lib/Theme.php:84: Notice[8]: The call_user_method() function is deprecated,
433 //use the call_user_func variety with the array(&$obj, "method") syntax instead
435 function getFormatter ($type, $format) {
436 $method = strtolower("get${type}Formatter");
437 if (method_exists($this, $method))
438 return $this->{$method}($format);
442 ////////////////////////////////////////////////////////////////
446 ////////////////////////////////////////////////////////////////
448 var $_autosplitWikiWords = false;
450 function setAutosplitWikiWords($autosplit=false) {
451 $this->_autosplitWikiWords = $autosplit ? true : false;
454 function maybeSplitWikiWord ($wikiword) {
455 if ($this->_autosplitWikiWords)
456 return split_pagename($wikiword);
461 var $_anonEditUnknownLinks = true;
462 function setAnonEditUnknownLinks($anonedit=true) {
463 $this->_anonEditUnknownLinks = $anonedit ? true : false;
466 function linkExistingWikiWord($wikiword, $linktext = '', $version = false) {
469 if ($version !== false)
470 $url = WikiURL($wikiword, array('version' => $version));
472 $url = WikiURL($wikiword);
474 // Extra steps for dumping page to an html file.
475 // FIXME: shouldn't this be in WikiURL?
476 if ($this->HTML_DUMP_SUFFIX) {
477 // no action or sortby links
478 $url = preg_replace("/\?.*$/","",$url);
479 // urlencode for pagenames with accented letters
480 $url = rawurlencode($url);
481 $url = preg_replace('/^\./', '%2e', $url);
482 // fix url#anchor links (looks awful)
483 if (strstr($url,'%23'))
484 $url = preg_replace("/%23/",$this->HTML_DUMP_SUFFIX."#",$url);
486 $url .= $this->HTML_DUMP_SUFFIX;
489 $link = HTML::a(array('href' => $url));
491 if (isa($wikiword, 'WikiPageName'))
492 $default_text = $wikiword->shortName;
494 $default_text = $wikiword;
496 if (!empty($linktext)) {
497 $link->pushContent($linktext);
498 $link->setAttr('class', 'named-wiki');
499 $link->setAttr('title', $this->maybeSplitWikiWord($default_text));
502 $link->pushContent($this->maybeSplitWikiWord($default_text));
503 $link->setAttr('class', 'wiki');
505 if ($request->getArg('frame'))
506 $link->setAttr('target', '_top');
510 function linkUnknownWikiWord($wikiword, $linktext = '') {
513 // Get rid of anchors on unknown wikiwords
514 if (isa($wikiword, 'WikiPageName')) {
515 $default_text = $wikiword->shortName;
516 $wikiword = $wikiword->name;
519 $default_text = $wikiword;
522 if ($this->DUMP_MODE) { // HTML, PDF or XML
523 $link = HTML::u( empty($linktext) ? $wikiword : $linktext);
524 $link->addTooltip(sprintf(_("Empty link to: %s"), $wikiword));
525 $link->setAttr('class', empty($linktext) ? 'wikiunknown' : 'named-wikiunknown');
528 // if AnonEditUnknownLinks show "?" only users which are allowed to edit this page
529 if (! $this->_anonEditUnknownLinks and ! mayAccessPage('edit', $request->getArg('pagename'))) {
530 $text = HTML::span( empty($linktext) ? $wikiword : $linktext);
531 $text->setAttr('class', empty($linktext) ? 'wikiunknown' : 'named-wikiunknown');
534 $url = WikiURL($wikiword, array('action' => 'create'));
535 $button = $this->makeButton('?', $url);
536 $button->addTooltip(sprintf(_("Create: %s"), $wikiword));
540 $link = HTML::span();
541 if (!empty($linktext)) {
542 $link->pushContent(HTML::u($linktext));
543 $link->setAttr('class', 'named-wikiunknown');
546 $link->pushContent(HTML::u($this->maybeSplitWikiWord($default_text)));
547 $link->setAttr('class', 'wikiunknown');
549 $link->pushContent($button);
550 if ($request->getPref('googleLink')) {
551 $gbutton = $this->makeButton('G', "http://www.google.com/search?q=$wikiword");
552 $gbutton->addTooltip(sprintf(_("Google:%s"), $wikiword));
553 $link->pushContent($gbutton);
555 if ($request->getArg('frame'))
556 $link->setAttr('target', '_top');
560 function linkBadWikiWord($wikiword, $linktext = '') {
561 global $ErrorManager;
566 elseif (isa($wikiword, 'WikiPageName')) {
567 $text = $wikiword->shortName;
573 if (isa($wikiword, 'WikiPageName'))
574 $message = $wikiword->getWarnings();
576 $message = sprintf(_("'%s': Bad page name"), $wikiword);
577 $ErrorManager->warning($message);
579 return HTML::span(array('class' => 'badwikiword'), $text);
582 ////////////////////////////////////////////////////////////////
586 ////////////////////////////////////////////////////////////////
587 var $_imageAliases = array();
588 var $_imageAlt = array();
592 * (To disable an image, alias the image to <code>false</code>.
594 function addImageAlias ($alias, $image_name) {
595 // fall back to the PhpWiki-supplied image if not found
596 if ($this->_findFile("images/$image_name", true))
597 $this->_imageAliases[$alias] = $image_name;
600 function addImageAlt ($alias, $alt_text) {
601 $this->_imageAlt[$alias] = $alt_text;
603 function getImageAlt ($alias) {
604 return $this->_imageAlt[$alias];
607 function getImageURL ($image) {
608 $aliases = &$this->_imageAliases;
610 if (isset($aliases[$image])) {
611 $image = $aliases[$image];
616 // If not extension, default to .png.
617 if (!preg_match('/\.\w+$/', $image))
620 // FIXME: this should probably be made to fall back
621 // automatically to .gif, .jpg.
622 // Also try .gif before .png if browser doesn't like png.
624 $path = $this->_findData("images/$image", 'missing okay');
625 if (!$path) // search explicit images/ or button/ links also
626 $path = $this->_findData("$image", 'missing okay');
628 if ($this->DUMP_MODE) {
629 if (empty($this->dumped_images)) $this->dumped_images = array();
630 $path = "images/". basename($path);
631 if (!in_array($path,$this->dumped_images)) $this->dumped_images[] = $path;
636 function setLinkIcon($proto, $image = false) {
640 $this->_linkIcons[$proto] = $image;
643 function getLinkIconURL ($proto) {
644 $icons = &$this->_linkIcons;
645 if (!empty($icons[$proto]))
646 return $this->getImageURL($icons[$proto]);
647 elseif (!empty($icons['*']))
648 return $this->getImageURL($icons['*']);
652 function addButtonAlias ($text, $alias = false) {
653 $aliases = &$this->_buttonAliases;
656 $aliases = array_merge($aliases, $text);
657 elseif ($alias === false)
658 unset($aliases[$text]);
660 $aliases[$text] = $alias;
663 function getButtonURL ($text) {
664 $aliases = &$this->_buttonAliases;
665 if (isset($aliases[$text]))
666 $text = $aliases[$text];
668 $qtext = urlencode($text);
669 $url = $this->_findButton("$qtext.png");
670 if ($url && strstr($url, '%')) {
671 $url = preg_replace('|([^/]+)$|e', 'urlencode("\\1")', $url);
673 if (!$url) {// Jeff complained about png not supported everywhere. This is not PC
674 $url = $this->_findButton("$qtext.gif");
675 if ($url && strstr($url, '%')) {
676 $url = preg_replace('|([^/]+)$|e', 'urlencode("\\1")', $url);
682 function _findButton ($button_file) {
683 if (empty($this->_button_path))
684 $this->_button_path = $this->_getButtonPath();
686 foreach ($this->_button_path as $dir) {
687 if ($path = $this->_findData("$dir/$button_file", 1))
693 function _getButtonPath () {
694 $button_dir = $this->_findFile("buttons");
695 $path_dir = $this->_path . $button_dir;
696 if (!file_exists($path_dir) || !is_dir($path_dir))
698 $path = array($button_dir);
700 $dir = dir($path_dir);
701 while (($subdir = $dir->read()) !== false) {
702 if ($subdir[0] == '.')
704 if ($subdir == 'CVS')
706 if (is_dir("$path_dir/$subdir"))
707 $path[] = "$button_dir/$subdir";
710 // add default buttons
711 $path[] = "themes/default/buttons";
712 $path_dir = $this->_path . "themes/default/buttons";
713 $dir = dir($path_dir);
714 while (($subdir = $dir->read()) !== false) {
715 if ($subdir[0] == '.')
717 if ($subdir == 'CVS')
719 if (is_dir("$path_dir/$subdir"))
720 $path[] = "themes/default/buttons/$subdir";
727 ////////////////////////////////////////////////////////////////
731 ////////////////////////////////////////////////////////////////
733 function makeButton ($text, $url, $class = false) {
734 // FIXME: don't always try for image button?
736 // Special case: URLs like 'submit:preview' generate form
737 // submission buttons.
738 if (preg_match('/^submit:(.*)$/', $url, $m))
739 return $this->makeSubmitButton($text, $m[1], $class);
741 $imgurl = $this->getButtonURL($text);
743 return new ImageButton($text, $url, $class, $imgurl);
745 return new Button($this->maybeSplitWikiWord($text), $url, $class);
748 function makeSubmitButton ($text, $name, $class = false) {
749 $imgurl = $this->getButtonURL($text);
752 return new SubmitImageButton($text, $name, $class, $imgurl);
754 return new SubmitButton($text, $name, $class);
758 * Make button to perform action.
760 * This constructs a button which performs an action on the
761 * currently selected version of the current page.
762 * (Or anotherpage or version, if you want...)
764 * @param $action string The action to perform (e.g. 'edit', 'lock').
765 * This can also be the name of an "action page" like 'LikePages'.
766 * Alternatively you can give a hash of query args to be applied
769 * @param $label string Textual label for the button. If left empty,
770 * a suitable name will be guessed.
772 * @param $page_or_rev mixed The page to link to. This can be
773 * given as a string (the page name), a WikiDB_Page object, or as
774 * WikiDB_PageRevision object. If given as a WikiDB_PageRevision
775 * object, the button will link to a specific version of the
776 * designated page, otherwise the button links to the most recent
777 * version of the page.
779 * @return object A Button object.
781 function makeActionButton ($action, $label = false, $page_or_rev = false) {
782 extract($this->_get_name_and_rev($page_or_rev));
784 if (is_array($action)) {
786 $action = isset($attr['action']) ? $attr['action'] : 'browse';
789 $attr['action'] = $action;
791 $class = is_safe_action($action) ? 'wikiaction' : 'wikiadmin';
793 $label = $this->_labelForAction($action);
796 $attr['version'] = $version;
798 if ($action == 'browse')
799 unset($attr['action']);
801 return $this->makeButton($label, WikiURL($pagename, $attr), $class);
805 * Make a "button" which links to a wiki-page.
807 * These are really just regular WikiLinks, possibly
808 * disguised (e.g. behind an image button) by the theme.
810 * This method should probably only be used for links
811 * which appear in page navigation bars, or similar places.
813 * Use linkExistingWikiWord, or LinkWikiWord for normal links.
815 * @param $page_or_rev mixed The page to link to. This can be
816 * given as a string (the page name), a WikiDB_Page object, or as
817 * WikiDB_PageRevision object. If given as a WikiDB_PageRevision
818 * object, the button will link to a specific version of the
819 * designated page, otherwise the button links to the most recent
820 * version of the page.
822 * @return object A Button object.
824 function makeLinkButton ($page_or_rev, $label = false, $action = false) {
825 extract($this->_get_name_and_rev($page_or_rev));
827 $args = $version ? array('version' => $version) : false;
828 if ($action) $args['action'] = $action;
830 return $this->makeButton($label ? $label : $pagename,
831 WikiURL($pagename, $args), 'wiki');
834 function _get_name_and_rev ($page_or_rev) {
837 if (empty($page_or_rev)) {
839 $pagename = $request->getArg("pagename");
840 $version = $request->getArg("version");
842 elseif (is_object($page_or_rev)) {
843 if (isa($page_or_rev, 'WikiDB_PageRevision')) {
845 $page = $rev->getPage();
846 if (!$rev->isCurrent()) $version = $rev->getVersion();
849 $page = $page_or_rev;
851 $pagename = $page->getName();
854 $pagename = (string) $page_or_rev;
856 return compact('pagename', 'version');
859 function _labelForAction ($action) {
861 case 'edit': return _("Edit");
862 case 'diff': return _("Diff");
863 case 'logout': return _("Sign Out");
864 case 'login': return _("Sign In");
865 case 'lock': return _("Lock Page");
866 case 'unlock': return _("Unlock Page");
867 case 'remove': return _("Remove Page");
869 // I don't think the rest of these actually get used.
871 // 'upload' 'dumpserial' 'loadfile' 'zip'
873 return gettext(ucfirst($action));
877 //----------------------------------------------------------------
878 var $_buttonSeparator = "\n | ";
880 function setButtonSeparator($separator) {
881 $this->_buttonSeparator = $separator;
884 function getButtonSeparator() {
885 return $this->_buttonSeparator;
889 ////////////////////////////////////////////////////////////////
895 // Based on testing with Galeon 1.2.7 (Mozilla 1.2):
896 // Automatic media-based style selection (via <link> tags) only
897 // seems to work for the default style, not for alternate styles.
901 // <link rel="stylesheet" type="text/css" href="phpwiki.css" />
902 // <link rel="stylesheet" type="text/css" href="phpwiki-printer.css" media="print" />
904 // works to make it so that the printer style sheet get used
905 // automatically when printing (or print-previewing) a page
906 // (but when only when the default style is selected.)
910 // <link rel="alternate stylesheet" title="Modern"
911 // type="text/css" href="phpwiki-modern.css" />
912 // <link rel="alternate stylesheet" title="Modern"
913 // type="text/css" href="phpwiki-printer.css" media="print" />
915 // Result in two "Modern" choices when trying to select alternate style.
916 // If one selects the first of those choices, one gets phpwiki-modern
917 // both when browsing and printing. If one selects the second "Modern",
918 // one gets no CSS when browsing, and phpwiki-printer when printing.
923 // We should probably move to doing the media based style
924 // switching in the CSS files themselves using, e.g.:
926 // @import url(print.css) print;
928 ////////////////////////////////////////////////////////////////
930 function _CSSlink($title, $css_file, $media, $is_alt = false) {
931 // Don't set title on default style. This makes it clear to
932 // the user which is the default (i.e. most supported) style.
933 if ($is_alt and isBrowserKonqueror())
935 $link = HTML::link(array('rel' => $is_alt ? 'alternate stylesheet' : 'stylesheet',
936 'type' => 'text/css',
937 'charset' => $GLOBALS['charset'],
938 'href' => $this->_findData($css_file)));
940 $link->setAttr('title', $title);
943 $link->setAttr('media', $media);
944 if ($this->DUMP_MODE) {
945 if (empty($this->dumped_css)) $this->dumped_css = array();
946 if (!in_array($css_file,$this->dumped_css)) $this->dumped_css[] = $css_file;
947 $link->setAttr('href', basename($link->getAttr('href')));
953 /** Set default CSS source for this theme.
955 * To set styles to be used for different media, pass a
956 * hash for the second argument, e.g.
958 * $theme->setDefaultCSS('default', array('' => 'normal.css',
959 * 'print' => 'printer.css'));
961 * If you call this more than once, the last one called takes
962 * precedence as the default style.
964 * @param string $title Name of style (currently ignored, unless
965 * you call this more than once, in which case, some of the style
966 * will become alternate (rather than default) styles, and then their
967 * titles will be used.
969 * @param mixed $css_files Name of CSS file, or hash containing a mapping
970 * between media types and CSS file names. Use a key of '' (the empty string)
971 * to set the default CSS for non-specified media. (See above for an example.)
973 function setDefaultCSS ($title, $css_files) {
974 if (!is_array($css_files))
975 $css_files = array('' => $css_files);
976 // Add to the front of $this->_css
977 unset($this->_css[$title]);
978 $this->_css = array_merge(array($title => $css_files), $this->_css);
981 /** Set alternate CSS source for this theme.
983 * @param string $title Name of style.
984 * @param string $css_files Name of CSS file.
986 function addAlternateCSS ($title, $css_files) {
987 if (!is_array($css_files))
988 $css_files = array('' => $css_files);
989 $this->_css[$title] = $css_files;
993 * @return string HTML for CSS.
998 foreach ($this->_css as $title => $css_files) {
999 ksort($css_files); // move $css_files[''] to front.
1000 foreach ($css_files as $media => $css_file) {
1001 $css[] = $this->_CSSlink($title, $css_file, $media, $is_alt);
1011 function findTemplate ($name) {
1012 return $this->_path . $this->_findFile("templates/$name.tmpl");
1015 var $_MoreHeaders = array();
1016 function addMoreHeaders ($element) {
1017 array_push($this->_MoreHeaders,$element);
1019 function getMoreHeaders () {
1020 if (empty($this->_MoreHeaders))
1023 //$out = "<!-- More Headers -->\n";
1024 foreach ($this->_MoreHeaders as $h) {
1026 $out .= printXML($h);
1033 var $_MoreAttr = array();
1034 function addMoreAttr ($id,$element) {
1035 if (empty($this->_MoreAttr) or !is_array($this->_MoreAttr[$id]))
1036 $this->_MoreAttr[$id] = array($element);
1038 array_push($this->_MoreAttr[$id],$element);
1040 function getMoreAttr ($id) {
1041 if (empty($this->_MoreAttr[$id]))
1044 foreach ($this->_MoreAttr[$id] as $h) {
1046 $out .= printXML($h);
1054 * Custom UserPreferences:
1055 * A list of name => _UserPreference class pairs.
1056 * Rationale: Certain themes should be able to extend the predefined list
1057 * of preferences. Display/editing is done in the theme specific userprefs.tmpl
1058 * but storage/sanification/update/... must be extended to the Get/SetPreferences methods.
1059 * These values are just ignored if another theme is used.
1061 function customUserPreferences($array) {
1062 global $customUserPreferenceColumns; // FIXME: really a global?
1063 if (empty($customUserPreferenceColumns)) $customUserPreferenceColumns = array();
1064 //array('wikilens' => new _UserPreference_wikilens());
1065 foreach ($array as $field => $prefobj) {
1066 $customUserPreferenceColumns[$field] = $prefobj;
1070 /** addPageListColumn(array('rating' => new _PageList_Column_rating('rating', _("Rate"))))
1071 * Register custom PageList types for special themes, like
1072 * 'rating' for wikilens
1074 function addPageListColumn ($array) {
1075 global $customPageListColumns;
1076 if (empty($customPageListColumns)) $customPageListColumns = array();
1077 foreach ($array as $column => $obj) {
1078 $customPageListColumns[$column] = $obj;
1086 * A class representing a clickable "button".
1088 * In it's simplest (default) form, a "button" is just a link associated
1089 * with some sort of wiki-action.
1091 class Button extends HtmlElement {
1094 * @param $text string The text for the button.
1095 * @param $url string The url (href) for the button.
1096 * @param $class string The CSS class for the button.
1098 function Button ($text, $url, $class = false) {
1101 if (check_php_version(5)) {
1102 $this->_init('a', array('href' => $url));
1104 $this->HtmlElement('a', array('href' => $url));
1107 $this->setAttr('class', $class);
1108 if ($request->getArg('frame'))
1109 $this->setAttr('target', '_top');
1110 $this->pushContent($GLOBALS['Theme']->maybeSplitWikiWord($text));
1117 * A clickable image button.
1119 class ImageButton extends Button {
1122 * @param $text string The text for the button.
1123 * @param $url string The url (href) for the button.
1124 * @param $class string The CSS class for the button.
1125 * @param $img_url string URL for button's image.
1126 * @param $img_attr array Additional attributes for the <img> tag.
1128 function ImageButton ($text, $url, $class, $img_url, $img_attr = false) {
1129 $this->HtmlElement('a', array('href' => $url));
1131 $this->setAttr('class', $class);
1133 if (!is_array($img_attr))
1134 $img_attr = array();
1135 $img_attr['src'] = $img_url;
1136 $img_attr['alt'] = $text;
1137 $img_attr['class'] = 'wiki-button';
1138 $img_attr['border'] = 0;
1139 $this->pushContent(HTML::img($img_attr));
1144 * A class representing a form <samp>submit</samp> button.
1146 class SubmitButton extends HtmlElement {
1149 * @param $text string The text for the button.
1150 * @param $name string The name of the form field.
1151 * @param $class string The CSS class for the button.
1153 function SubmitButton ($text, $name = false, $class = false) {
1154 $this->HtmlElement('input', array('type' => 'submit',
1157 $this->setAttr('name', $name);
1159 $this->setAttr('class', $class);
1166 * A class representing an image form <samp>submit</samp> button.
1168 class SubmitImageButton extends SubmitButton {
1171 * @param $text string The text for the button.
1172 * @param $name string The name of the form field.
1173 * @param $class string The CSS class for the button.
1174 * @param $img_url string URL for button's image.
1175 * @param $img_attr array Additional attributes for the <img> tag.
1177 function SubmitImageButton ($text, $name = false, $class = false, $img_url) {
1178 $this->HtmlElement('input', array('type' => 'image',
1183 $this->setAttr('name', $name);
1185 $this->setAttr('class', $class);
1191 * A sidebar box with title and body, narrow fixed-width.
1192 * To represent abbrevated content of plugins, links or forms,
1193 * like "Getting Started", "Search", "Sarch Pagename",
1194 * "Login", "Menu", "Recent Changes", "Last comments", "Last Blogs"
1196 * ... See http://tikiwiki.org/
1200 * $menu = SidebarBox("Menu",HTML::dl(HTML::dt(...))); $menu->format();
1201 * $menu = PluginSidebarBox("RecentChanges",array('limit'=>10)); $menu->format();
1205 function SidebarBox($title, $body) {
1206 $this->title = $title;
1207 $this->body = $body;
1210 return WikiPlugin::makeBox($this->title, $this->body);
1215 * A sidebar box for plugins.
1216 * Any plugin may provide a box($args=false, $request=false, $basepage=false)
1217 * method, with the help of WikiPlugin::makeBox()
1219 class PluginSidebarBox extends SidebarBox {
1221 var $_plugin, $_args = false, $_basepage = false;
1223 function PluginSidebarBox($name, $args = false, $basepage = false) {
1224 $loader = new WikiPluginLoader();
1225 $plugin = $loader->getPlugin($name);
1226 if (!method_exists($plugin,'box')) {
1227 return $loader->error(sprintf(_("%s: has no box method"),
1228 get_class($plugin)));
1230 $this->_plugin =& $plugin;
1231 $this->_args = $args ? $args : array();
1232 $this->_basepage = $basepage;
1235 function format($args = false) {
1236 return $this->_plugin->box($args ? array_merge($this->_args,$args) : $this->_args,
1237 $GLOBALS['request'],
1242 // Various boxes which are no plugins
1243 class RelatedLinksBox extends SidebarBox {
1244 function RelatedLinksBox($title = false, $body = '', $limit = 20) {
1246 $this->title = $title ? $title : _("Related Links");
1247 $this->body = HTML($body);
1248 $page = $request->getPage($request->getArg('pagename'));
1249 $revision = $page->getCurrentRevision();
1250 $page_content = $revision->getTransformedContent();
1251 //$cache = &$page->_wikidb->_cache;
1253 $sp = HTML::Raw('· ');
1254 foreach ($page_content->getWikiPageLinks() as $link) {
1255 if (!$request->_dbi->isWikiPage($link)) continue;
1256 $this->body->pushContent($sp, WikiLink($link), HTML::br());
1258 if ($limit and $counter > $limit) continue;
1263 class RelatedExternalLinksBox extends SidebarBox {
1264 function RelatedExternalLinksBox($title = false, $body = '', $limit = 20) {
1266 $this->title = $title ? $title : _("External Links");
1267 $this->body = HTML($body);
1268 $page = $request->getPage($request->getArg('pagename'));
1269 $cache = &$page->_wikidb->_cache;
1271 $sp = HTML::Raw('· ');
1272 foreach ($cache->getWikiPageLinks() as $link) {
1274 $this->body->pushContent($sp, WikiLink($link), HTML::br());
1276 if ($limit and $counter > $limit) continue;
1282 function listAvailableThemes() {
1283 $available_themes = array();
1284 $dir_root = 'themes';
1285 if (defined('PHPWIKI_DIR'))
1286 $dir_root = PHPWIKI_DIR . "/$dir_root";
1287 $dir = dir($dir_root);
1289 while($entry = $dir->read()) {
1290 if (is_dir($dir_root.'/'.$entry)
1291 && (substr($entry,0,1) != '.')
1292 && $entry != 'CVS') {
1293 array_push($available_themes, $entry);
1298 return $available_themes;
1301 function listAvailableLanguages() {
1302 $available_languages = array('en');
1303 $dir_root = 'locale';
1304 if (defined('PHPWIKI_DIR'))
1305 $dir_root = PHPWIKI_DIR . "/$dir_root";
1306 if ($dir = dir($dir_root)) {
1307 while($entry = $dir->read()) {
1308 if (is_dir($dir_root."/".$entry)
1309 && (substr($entry,0,1) != '.')
1313 array_push($available_languages, $entry);
1318 return $available_languages;
1321 // $Log: not supported by cvs2svn $
1322 // Revision 1.94 2004/05/13 11:52:34 rurban
1323 // search also default buttons
1325 // Revision 1.93 2004/05/12 10:49:55 rurban
1326 // require_once fix for those libs which are loaded before FileFinder and
1327 // its automatic include_path fix, and where require_once doesn't grok
1328 // dirname(__FILE__) != './lib'
1329 // upgrade fix with PearDB
1330 // navbar.tmpl: remove spaces for IE button alignment
1332 // Revision 1.92 2004/05/03 21:57:47 rurban
1333 // locale updates: we previously lost some words because of wrong strings in
1334 // PhotoAlbum, german rewording.
1335 // fixed $_SESSION registering (lost session vars, esp. prefs)
1336 // fixed ending slash in listAvailableLanguages/Themes
1338 // Revision 1.91 2004/05/03 11:40:42 rurban
1339 // put listAvailableLanguages() and listAvailableThemes() from SystemInfo and
1340 // UserPreferences into Themes.php
1342 // Revision 1.90 2004/05/02 19:12:14 rurban
1343 // fix sf.net bug #945154 Konqueror alt css
1345 // Revision 1.89 2004/04/29 21:25:45 rurban
1346 // default theme navbar consistency: linkButtons instead of action buttons
1347 // 3rd makeLinkButtin arg for action support
1349 // Revision 1.88 2004/04/19 18:27:45 rurban
1350 // Prevent from some PHP5 warnings (ref args, no :: object init)
1351 // php5 runs now through, just one wrong XmlElement object init missing
1352 // Removed unneccesary UpgradeUser lines
1353 // Changed WikiLink to omit version if current (RecentChanges)
1355 // Revision 1.87 2004/04/19 09:13:23 rurban
1356 // new pref: googleLink
1358 // Revision 1.86 2004/04/18 01:11:51 rurban
1359 // more numeric pagename fixes.
1360 // fixed action=upload with merge conflict warnings.
1361 // charset changed from constant to global (dynamic utf-8 switching)
1363 // Revision 1.85 2004/04/12 13:04:50 rurban
1364 // added auth_create: self-registering Db users
1366 // removed rating recommendations
1367 // ziplib reformatting
1369 // Revision 1.84 2004/04/10 02:30:49 rurban
1370 // Fixed gettext problem with VIRTUAL_PATH scripts (Windows only probably)
1371 // Fixed "cannot setlocale..." (sf.net problem)
1373 // Revision 1.83 2004/04/09 17:49:03 rurban
1374 // Added PhpWiki RssFeed to Sidebar
1375 // sidebar formatting
1376 // some browser dependant fixes (old-browser support)
1378 // Revision 1.82 2004/04/06 20:00:10 rurban
1379 // Cleanup of special PageList column types
1380 // Added support of plugin and theme specific Pagelist Types
1381 // Added support for theme specific UserPreferences
1382 // Added session support for ip-based throttling
1383 // sql table schema change: ALTER TABLE session ADD sess_ip CHAR(15);
1384 // Enhanced postgres schema
1385 // Added DB_Session_dba support
1387 // Revision 1.81 2004/04/01 15:57:10 rurban
1388 // simplified Sidebar theme: table, not absolute css positioning
1389 // added the new box methods.
1390 // remaining problems: large left margin, how to override _autosplitWikiWords in Template only
1392 // Revision 1.80 2004/03/30 02:14:03 rurban
1393 // fixed yet another Prefs bug
1394 // added generic PearDb_iter
1395 // $request->appendValidators no so strict as before
1396 // added some box plugin methods
1397 // PageList commalist for condensed output
1399 // Revision 1.79 2004/03/24 19:39:02 rurban
1400 // php5 workaround code (plus some interim debugging code in XmlElement)
1401 // php5 doesn't work yet with the current XmlElement class constructors,
1402 // WikiUserNew does work better than php4.
1403 // rewrote WikiUserNew user upgrading to ease php5 update
1404 // fixed pref handling in WikiUserNew
1405 // added Email Notification
1406 // added simple Email verification
1407 // removed emailVerify userpref subclass: just a email property
1408 // changed pref binary storage layout: numarray => hash of non default values
1409 // print optimize message only if really done.
1410 // forced new cookie policy: delete pref cookies, use only WIKI_ID as plain string.
1411 // prefs should be stored in db or homepage, besides the current session.
1413 // Revision 1.78 2004/03/18 22:32:33 rurban
1414 // work to make it php5 compatible
1416 // Revision 1.77 2004/03/08 19:30:01 rurban
1417 // fixed Theme->getButtonURL
1418 // AllUsers uses now WikiGroup (also DB User and DB Pref users)
1419 // PageList fix for empty pagenames
1421 // Revision 1.76 2004/03/08 18:17:09 rurban
1422 // added more WikiGroup::getMembersOf methods, esp. for special groups
1423 // fixed $LDAP_SET_OPTIONS
1424 // fixed _AuthInfo group methods
1426 // Revision 1.75 2004/03/01 09:34:37 rurban
1427 // fixed button path logic: now fallback to default also
1429 // Revision 1.74 2004/02/28 21:14:08 rurban
1430 // generally more PHPDOC docs
1431 // see http://xarch.tu-graz.ac.at/home/rurban/phpwiki/xref/
1432 // fxied WikiUserNew pref handling: empty theme not stored, save only
1433 // changed prefs, sql prefs improved, fixed password update,
1434 // removed REPLACE sql (dangerous)
1435 // moved gettext init after the locale was guessed
1436 // + some minor changes
1438 // Revision 1.73 2004/02/26 03:22:05 rurban
1439 // also copy css and images with XHTML Dump
1441 // Revision 1.72 2004/02/26 02:25:53 rurban
1442 // fix empty and #-anchored links in XHTML Dumps
1444 // Revision 1.71 2004/02/15 21:34:37 rurban
1445 // PageList enhanced and improved.
1446 // fixed new WikiAdmin... plugins
1447 // editpage, Theme with exp. htmlarea framework
1448 // (htmlarea yet committed, this is really questionable)
1449 // WikiUser... code with better session handling for prefs
1450 // enhanced UserPreferences (again)
1451 // RecentChanges for show_deleted: how should pages be deleted then?
1453 // Revision 1.70 2004/01/26 09:17:48 rurban
1454 // * changed stored pref representation as before.
1455 // the array of objects is 1) bigger and 2)
1456 // less portable. If we would import packed pref
1457 // objects and the object definition was changed, PHP would fail.
1458 // This doesn't happen with an simple array of non-default values.
1459 // * use $prefs->retrieve and $prefs->store methods, where retrieve
1460 // understands the interim format of array of objects also.
1461 // * simplified $prefs->get() and fixed $prefs->set()
1462 // * added $user->_userid and class '_WikiUser' portability functions
1463 // * fixed $user object ->_level upgrading, mostly using sessions.
1464 // this fixes yesterdays problems with loosing authorization level.
1465 // * fixed WikiUserNew::checkPass to return the _level
1466 // * fixed WikiUserNew::isSignedIn
1467 // * added explodePageList to class PageList, support sortby arg
1468 // * fixed UserPreferences for WikiUserNew
1469 // * fixed WikiPlugin for empty defaults array
1470 // * UnfoldSubpages: added pagename arg, renamed pages arg,
1471 // removed sort arg, support sortby arg
1473 // Revision 1.69 2003/12/05 01:32:28 carstenklapp
1474 // New feature: Easier to run multiple wiks off of one set of code. Name
1475 // your logo and signature image files "YourWikiNameLogo.png" and
1476 // "YourWikiNameSignature.png" and put them all into
1477 // themes/default/images. YourWikiName should match what is defined as
1478 // WIKI_NAME in index.php. In case the image is not found, the default
1479 // shipped with PhpWiki will be used.
1481 // Revision 1.68 2003/03/04 01:53:30 dairiki
1482 // Inconsequential decrufting.
1484 // Revision 1.67 2003/02/26 03:40:22 dairiki
1485 // New action=create. Essentially the same as action=edit, except that if the
1486 // page already exists, it falls back to action=browse.
1488 // This is for use in the "question mark" links for unknown wiki words
1489 // to avoid problems and confusion when following links from stale pages.
1490 // (If the "unknown page" has been created in the interim, the user probably
1491 // wants to view the page before editing it.)
1493 // Revision 1.66 2003/02/26 00:10:26 dairiki
1494 // More/better/different checks for bad page names.
1496 // Revision 1.65 2003/02/24 22:41:57 dairiki
1499 // Revision 1.64 2003/02/24 22:06:14 dairiki
1500 // Attempts to fix auto-selection of printer CSS when printing.
1501 // See new comments lib/Theme.php for more details.
1502 // Also see SF patch #669563.
1504 // Revision 1.63 2003/02/23 03:37:05 dairiki
1505 // Stupid typo/bug fix.
1507 // Revision 1.62 2003/02/21 04:14:52 dairiki
1508 // New WikiLink type 'if_known'. This gives linkified name if page
1509 // exists, otherwise, just plain text.
1511 // Revision 1.61 2003/02/18 21:52:05 dairiki
1512 // Fix so that one can still link to wiki pages with # in their names.
1513 // (This was made difficult by the introduction of named tags, since
1514 // '[Page #1]' is now a link to anchor '1' in page 'Page'.
1516 // Now the ~ escape for page names should work: [Page ~#1].
1518 // Revision 1.60 2003/02/15 01:59:47 dairiki
1519 // Theme::getCSS(): Add Default-Style HTTP(-eqiv) header in attempt
1520 // to fix default stylesheet selection on some browsers.
1521 // For details on the Default-Style header, see:
1522 // http://home.dairiki.org/docs/html4/present/styles.html#h-14.3.2
1524 // Revision 1.59 2003/01/04 22:30:16 carstenklapp
1525 // New: display a "Never edited." message instead of an invalid epoch date.
1528 // (c-file-style: "gnu")
1532 // c-basic-offset: 4
1533 // c-hanging-comment-ender-p: nil
1534 // indent-tabs-mode: nil