1 <?php rcs_id('$Id: Theme.php,v 1.64 2003-02-24 22:06:14 dairiki Exp $');
3 require_once('lib/HtmlElement.php');
7 * Make a link to a wiki page (in this wiki).
9 * This is a convenience function.
11 * @param mixed $page_or_rev
13 * <dt>A string</dt><dd>The page to link to.</dd>
14 * <dt>A WikiDB_Page object</dt><dd>The page to link to.</dd>
15 * <dt>A WikiDB_PageRevision object</dt><dd>A specific version of the page to link to.</dd>
20 * <dt>'unknown'</dt><dd>Make link appropriate for a non-existant page.</dd>
21 * <dt>'known'</dt><dd>Make link appropriate for an existing page.</dd>
22 * <dt>'auto'</dt><dd>Either 'unknown' or 'known' as appropriate.</dd>
23 * <dt>'button'</dt><dd>Make a button-style link.</dd>
24 * <dt>'if_known'</dt><dd>Only linkify if page exists.</dd>
26 * Unless $type of of the latter form, the link will be of class 'wiki', 'wikiunknown',
27 * 'named-wiki', or 'named-wikiunknown', as appropriate.
29 * @param mixed $label (string or XmlContent object)
30 * Label for the link. If not given, defaults to the page name.
32 * @return XmlContent The link
34 function WikiLink ($page_or_rev, $type = 'known', $label = false) {
35 global $Theme, $request;
37 if ($type == 'button') {
38 return $Theme->makeLinkButton($page_or_rev, $label);
43 if (isa($page_or_rev, 'WikiDB_PageRevision')) {
44 $version = $page_or_rev->getVersion();
45 $page = $page_or_rev->getPage();
46 $pagename = $page->getName();
47 $wikipage = $pagename;
50 elseif (isa($page_or_rev, 'WikiDB_Page')) {
52 $pagename = $page->getName();
53 $wikipage = $pagename;
55 elseif (isa($page_or_rev, 'WikiPageName')) {
56 $wikipage = $page_or_rev;
57 $pagename = $wikipage->name;
60 $wikipage = new WikiPageName($page_or_rev, $request->getPage());
61 $pagename = $wikipage->name;
65 if ($type == 'auto' or $type == 'if_known') {
67 $current = $page->getCurrentRevision();
68 $exists = ! $current->hasDefaultContents();
71 $dbi = $request->getDbh();
72 $exists = $dbi->isWikiPage($wikipage->name);
75 elseif ($type == 'unknown') {
82 // FIXME: this should be somewhere else, if really needed.
83 // WikiLink makes A link, not a string of fancy ones.
84 // (I think that the fancy split links are just confusing.)
85 // Todo: test external ImageLinks http://some/images/next.gif
86 if (isa($wikipage, 'WikiPageName') and !$label
87 and strchr(substr($wikipage->shortName,1), SUBPAGE_SEPARATOR)) {
88 $parts = explode(SUBPAGE_SEPARATOR, $wikipage->shortName);
89 $last_part = array_pop($parts);
92 foreach ($parts as $part) {
94 $parent = join(SUBPAGE_SEPARATOR, $path);
96 $link->pushContent($Theme->linkExistingWikiWord($parent, $sep . $part));
97 $sep = SUBPAGE_SEPARATOR;
100 $link->pushContent($Theme->linkExistingWikiWord($wikipage, $sep . $last_part, $version));
102 $link->pushContent($Theme->linkUnknownWikiWord($wikipage, $last_part));
107 return $Theme->linkExistingWikiWord($wikipage, $label, $version);
109 elseif ($type == 'if_known') {
110 if (!$label && isa($wikipage, 'WikiPageName'))
111 $label = $wikipage->shortName;
112 return HTML($label ? $label : $pagename);
115 return $Theme->linkUnknownWikiWord($wikipage, $label);
124 * This is a convenience function.
126 * @param $action string
128 * <dt>[action]</dt><dd>Perform action (e.g. 'edit') on the selected page.</dd>
129 * <dt>[ActionPage]</dt><dd>Run the actionpage (e.g. 'BackLinks') on the selected page.</dd>
130 * <dt>'submit:'[name]</dt><dd>Make a form submission button with the given name.
131 * ([name] can be blank for a nameless submit button.)</dd>
132 * <dt>a hash</dt><dd>Query args for the action. E.g.<pre>
133 * array('action' => 'diff', 'previous' => 'author')
137 * @param $label string
138 * A label for the button. If ommited, a suitable default (based on the valued of $action)
141 * @param $page_or_rev mixed
142 * Which page (& version) to perform the action on.
144 * <dt>A string</dt><dd>The pagename.</dd>
145 * <dt>A WikiDB_Page object</dt><dd>The page.</dd>
146 * <dt>A WikiDB_PageRevision object</dt><dd>A specific version of the page.</dd>
148 * ($Page_or_rev is ignored for submit buttons.)
150 function Button ($action, $label = false, $page_or_rev = false) {
153 if (!is_array($action) && preg_match('/submit:(.*)/A', $action, $m))
154 return $Theme->makeSubmitButton($label, $m[1], $class = $page_or_rev);
156 return $Theme->makeActionButton($action, $label, $page_or_rev);
161 var $HTML_DUMP_SUFFIX = '';
162 function Theme ($theme_name = 'default') {
163 $this->_name = $theme_name;
164 $themes_dir = defined('PHPWIKI_DIR') ? PHPWIKI_DIR . "/themes" : "themes";
166 $this->_path = defined('PHPWIKI_DIR') ? PHPWIKI_DIR . "/" : "";
167 $this->_theme = "themes/$theme_name";
169 if ($theme_name != 'default')
170 $this->_default_theme = new Theme;
172 $this->_css = array();
175 function file ($file) {
176 return $this->_path . "$this->_theme/$file";
179 function _findFile ($file, $missing_okay = false) {
180 if (file_exists($this->_path . "$this->_theme/$file"))
181 return "$this->_theme/$file";
183 // FIXME: this is a short-term hack. Delete this after all files
184 // get moved into themes/...
185 if (file_exists($this->_path . $file))
189 if (isset($this->_default_theme)) {
190 return $this->_default_theme->_findFile($file, $missing_okay);
192 else if (!$missing_okay) {
193 trigger_error("$file: not found", E_USER_NOTICE);
198 function _findData ($file, $missing_okay = false) {
199 $path = $this->_findFile($file, $missing_okay);
203 if (defined('DATA_PATH'))
204 return DATA_PATH . "/$path";
208 ////////////////////////////////////////////////////////////////
210 // Date and Time formatting
212 ////////////////////////////////////////////////////////////////
214 // Note: Windows' implemetation of strftime does not include certain
215 // format specifiers, such as %e (for date without leading zeros). In
217 // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_strftime.2c_.wcsftime.asp
218 // As a result, we have to use %d, and strip out leading zeros ourselves.
220 var $_dateFormat = "%B %d, %Y";
221 var $_timeFormat = "%I:%M %p";
223 var $_showModTime = true;
226 * Set format string used for dates.
228 * @param $fs string Format string for dates.
230 * @param $show_mod_time bool If true (default) then times
231 * are included in the messages generated by getLastModifiedMessage(),
232 * otherwise, only the date of last modification will be shown.
234 function setDateFormat ($fs, $show_mod_time = true) {
235 $this->_dateFormat = $fs;
236 $this->_showModTime = $show_mod_time;
240 * Set format string used for times.
242 * @param $fs string Format string for times.
244 function setTimeFormat ($fs) {
245 $this->_timeFormat = $fs;
251 * Any time zone offset specified in the users preferences is
252 * taken into account by this method.
254 * @param $time_t integer Unix-style time.
256 * @return string The date.
258 function formatDate ($time_t) {
261 $offset_time = $time_t + 3600 * $request->getPref('timeOffset');
262 // strip leading zeros from date elements (ie space followed by zero)
263 return preg_replace('/ 0/', ' ',
264 strftime($this->_dateFormat, $offset_time));
270 * Any time zone offset specified in the users preferences is
271 * taken into account by this method.
273 * @param $time_t integer Unix-style time.
275 * @return string The time.
277 function formatTime ($time_t) {
278 //FIXME: make 24-hour mode configurable?
280 $offset_time = $time_t + 3600 * $request->getPref('timeOffset');
281 return preg_replace('/^0/', ' ',
282 strtolower(strftime($this->_timeFormat, $offset_time)));
286 * Format a date and time.
288 * Any time zone offset specified in the users preferences is
289 * taken into account by this method.
291 * @param $time_t integer Unix-style time.
293 * @return string The date and time.
295 function formatDateTime ($time_t) {
296 return $this->formatDate($time_t) . ' ' . $this->formatTime($time_t);
300 * Format a (possibly relative) date.
302 * If enabled in the users preferences, this method might
303 * return a relative day (e.g. 'Today', 'Yesterday').
305 * Any time zone offset specified in the users preferences is
306 * taken into account by this method.
308 * @param $time_t integer Unix-style time.
310 * @return string The day.
312 function getDay ($time_t) {
315 if ($request->getPref('relativeDates') && ($date = $this->_relativeDay($time_t))) {
316 return ucfirst($date);
318 return $this->formatDate($time_t);
322 * Format the "last modified" message for a page revision.
324 * @param $revision object A WikiDB_PageRevision object.
326 * @param $show_version bool Should the page version number
327 * be included in the message. (If this argument is omitted,
328 * then the version number will be shown only iff the revision
329 * is not the current one.
331 * @return string The "last modified" message.
333 function getLastModifiedMessage ($revision, $show_version = 'auto') {
336 // dates >= this are considered invalid.
337 if (! defined('EPOCH'))
338 define('EPOCH', 0); // seconds since ~ January 1 1970
340 $mtime = $revision->get('mtime');
342 return fmt("Never edited.");
344 if ($show_version == 'auto')
345 $show_version = !$revision->isCurrent();
347 if ($request->getPref('relativeDates') && ($date = $this->_relativeDay($mtime))) {
348 if ($this->_showModTime)
349 $date = sprintf(_("%s at %s"),
350 $date, $this->formatTime($mtime));
353 return fmt("Version %s, saved %s.", $revision->getVersion(), $date);
355 return fmt("Last edited %s.", $date);
358 if ($this->_showModTime)
359 $date = $this->formatDateTime($mtime);
361 $date = $this->formatDate($mtime);
364 return fmt("Version %s, saved on %s.", $revision->getVersion(), $date);
366 return fmt("Last edited on %s.", $date);
369 function _relativeDay ($time_t) {
371 $offset = 3600 * $request->getPref('timeOffset');
373 $now = time() + $offset;
374 $today = localtime($now, true);
375 $time = localtime($time_t + $offset, true);
377 if ($time['tm_yday'] == $today['tm_yday'] && $time['tm_year'] == $today['tm_year'])
380 // Note that due to daylight savings chages (and leap seconds), $now minus
381 // 24 hours is not guaranteed to be yesterday.
382 $yesterday = localtime($now - (12 + $today['tm_hour']) * 3600, true);
383 if ($time['tm_yday'] == $yesterday['tm_yday'] && $time['tm_year'] == $yesterday['tm_year'])
384 return _("yesterday");
389 ////////////////////////////////////////////////////////////////
391 // Hooks for other formatting
393 ////////////////////////////////////////////////////////////////
395 //FIXME: PHP 4.1 Warnings
396 //lib/Theme.php:84: Notice[8]: The call_user_method() function is deprecated,
397 //use the call_user_func variety with the array(&$obj, "method") syntax instead
399 function getFormatter ($type, $format) {
400 $method = strtolower("get${type}Formatter");
401 if (method_exists($this, $method))
402 return $this->{$method}($format);
406 ////////////////////////////////////////////////////////////////
410 ////////////////////////////////////////////////////////////////
412 var $_autosplitWikiWords = false;
414 function setAutosplitWikiWords($autosplit=false) {
415 $this->_autosplitWikiWords = $autosplit ? true : false;
418 function maybeSplitWikiWord ($wikiword) {
419 if ($this->_autosplitWikiWords)
420 return split_pagename($wikiword);
425 function linkExistingWikiWord($wikiword, $linktext = '', $version = false) {
428 if ($version !== false)
429 $url = WikiURL($wikiword, array('version' => $version));
431 $url = WikiURL($wikiword);
433 // Extra steps for dumping page to an html file.
434 // FIXME: shouldn't this be in WikiURL?
435 if ($this->HTML_DUMP_SUFFIX) {
436 // urlencode for pagenames with accented letters
437 $url = rawurlencode($url);
438 $url = preg_replace('/^\./', '%2e', $url);
439 $url .= $this->HTML_DUMP_SUFFIX;
442 $link = HTML::a(array('href' => $url));
444 if (isa($wikiword, 'WikiPageName'))
445 $default_text = $wikiword->shortName;
447 $default_text = $wikiword;
449 if (!empty($linktext)) {
450 $link->pushContent($linktext);
451 $link->setAttr('class', 'named-wiki');
452 $link->setAttr('title', $this->maybeSplitWikiWord($default_text));
455 $link->pushContent($this->maybeSplitWikiWord($default_text));
456 $link->setAttr('class', 'wiki');
458 if ($request->getArg('frame'))
459 $link->setAttr('target', '_top');
463 function linkUnknownWikiWord($wikiword, $linktext = '') {
466 // Get rid of anchors on unknown wikiwords
467 if (isa($wikiword, 'WikiPageName')) {
468 $default_text = $wikiword->shortName;
469 $wikiword = $wikiword->name;
472 $default_text = $wikiword;
475 $url = WikiURL($wikiword, array('action' => 'edit'));
476 //$link = HTML::span(HTML::a(array('href' => $url), '?'));
477 $button = $this->makeButton('?', $url);
478 $button->addTooltip(sprintf(_("Edit: %s"), $wikiword));
479 $link = HTML::span($button);
482 if (!empty($linktext)) {
483 $link->pushContent(HTML::u($linktext));
484 $link->setAttr('class', 'named-wikiunknown');
487 $link->pushContent(HTML::u($this->maybeSplitWikiWord($default_text)));
488 $link->setAttr('class', 'wikiunknown');
490 if ($request->getArg('frame'))
491 $link->setAttr('target', '_top');
496 ////////////////////////////////////////////////////////////////
500 ////////////////////////////////////////////////////////////////
501 var $_imageAliases = array();
502 var $_imageAlt = array();
506 * (To disable an image, alias the image to <code>false</code>.
508 function addImageAlias ($alias, $image_name) {
509 $this->_imageAliases[$alias] = $image_name;
512 function addImageAlt ($alias, $alt_text) {
513 $this->_imageAlt[$alias] = $alt_text;
515 function getImageAlt ($alias) {
516 return $this->_imageAlt[$alias];
519 function getImageURL ($image) {
520 $aliases = &$this->_imageAliases;
522 if (isset($aliases[$image])) {
523 $image = $aliases[$image];
528 // If not extension, default to .png.
529 if (!preg_match('/\.\w+$/', $image))
532 // FIXME: this should probably be made to fall back
533 // automatically to .gif, .jpg.
534 // Also try .gif before .png if browser doesn't like png.
536 $path = $this->_findData("images/$image", 'missing okay');
537 if (!$path) // search explicit images/ or button/ links also
538 return $this->_findData("$image", 'missing okay');
543 function setLinkIcon($proto, $image = false) {
547 $this->_linkIcons[$proto] = $image;
550 function getLinkIconURL ($proto) {
551 $icons = &$this->_linkIcons;
552 if (!empty($icons[$proto]))
553 return $this->getImageURL($icons[$proto]);
554 elseif (!empty($icons['*']))
555 return $this->getImageURL($icons['*']);
559 function addButtonAlias ($text, $alias = false) {
560 $aliases = &$this->_buttonAliases;
563 $aliases = array_merge($aliases, $text);
564 elseif ($alias === false)
565 unset($aliases[$text]);
567 $aliases[$text] = $alias;
570 function getButtonURL ($text) {
571 $aliases = &$this->_buttonAliases;
572 if (isset($aliases[$text]))
573 $text = $aliases[$text];
575 $qtext = urlencode($text);
576 $url = $this->_findButton("$qtext.png");
577 if ($url && strstr($url, '%')) {
578 $url = preg_replace('|([^/]+)$|e', 'urlencode("\\1")', $url);
580 if (!$url) {// Jeff complained about png not supported everywhere. This is not PC
581 $url = $this->_findButton("$qtext.gif");
582 if ($url && strstr($url, '%')) {
583 $url = preg_replace('|([^/]+)$|e', 'urlencode("\\1")', $url);
589 function _findButton ($button_file) {
590 if (!isset($this->_button_path))
591 $this->_button_path = $this->_getButtonPath();
593 foreach ($this->_button_path as $dir) {
594 $path = "$this->_theme/$dir/$button_file";
595 if (file_exists($this->_path . $path))
596 return defined('DATA_PATH') ? DATA_PATH . "/$path" : $path;
601 function _getButtonPath () {
602 $button_dir = $this->file("buttons");
603 if (!file_exists($button_dir) || !is_dir($button_dir))
606 $path = array('buttons');
608 $dir = dir($button_dir);
609 while (($subdir = $dir->read()) !== false) {
610 if ($subdir[0] == '.')
612 if (is_dir("$button_dir/$subdir"))
613 $path[] = "buttons/$subdir";
620 ////////////////////////////////////////////////////////////////
624 ////////////////////////////////////////////////////////////////
626 function makeButton ($text, $url, $class = false) {
627 // FIXME: don't always try for image button?
629 // Special case: URLs like 'submit:preview' generate form
630 // submission buttons.
631 if (preg_match('/^submit:(.*)$/', $url, $m))
632 return $this->makeSubmitButton($text, $m[1], $class);
634 $imgurl = $this->getButtonURL($text);
636 return new ImageButton($text, $url, $class, $imgurl);
638 return new Button($text, $url, $class);
641 function makeSubmitButton ($text, $name, $class = false) {
642 $imgurl = $this->getButtonURL($text);
645 return new SubmitImageButton($text, $name, $class, $imgurl);
647 return new SubmitButton($text, $name, $class);
651 * Make button to perform action.
653 * This constructs a button which performs an action on the
654 * currently selected version of the current page.
655 * (Or anotherpage or version, if you want...)
657 * @param $action string The action to perform (e.g. 'edit', 'lock').
658 * This can also be the name of an "action page" like 'LikePages'.
659 * Alternatively you can give a hash of query args to be applied
662 * @param $label string Textual label for the button. If left empty,
663 * a suitable name will be guessed.
665 * @param $page_or_rev mixed The page to link to. This can be
666 * given as a string (the page name), a WikiDB_Page object, or as
667 * WikiDB_PageRevision object. If given as a WikiDB_PageRevision
668 * object, the button will link to a specific version of the
669 * designated page, otherwise the button links to the most recent
670 * version of the page.
672 * @return object A Button object.
674 function makeActionButton ($action, $label = false, $page_or_rev = false) {
675 extract($this->_get_name_and_rev($page_or_rev));
677 if (is_array($action)) {
679 $action = isset($attr['action']) ? $attr['action'] : 'browse';
682 $attr['action'] = $action;
684 $class = is_safe_action($action) ? 'wikiaction' : 'wikiadmin';
686 $label = $this->_labelForAction($action);
689 $attr['version'] = $version;
691 if ($action == 'browse')
692 unset($attr['action']);
694 return $this->makeButton($label, WikiURL($pagename, $attr), $class);
698 * Make a "button" which links to a wiki-page.
700 * These are really just regular WikiLinks, possibly
701 * disguised (e.g. behind an image button) by the theme.
703 * This method should probably only be used for links
704 * which appear in page navigation bars, or similar places.
706 * Use linkExistingWikiWord, or LinkWikiWord for normal links.
708 * @param $page_or_rev mixed The page to link to. This can be
709 * given as a string (the page name), a WikiDB_Page object, or as
710 * WikiDB_PageRevision object. If given as a WikiDB_PageRevision
711 * object, the button will link to a specific version of the
712 * designated page, otherwise the button links to the most recent
713 * version of the page.
715 * @return object A Button object.
717 function makeLinkButton ($page_or_rev, $label = false) {
718 extract($this->_get_name_and_rev($page_or_rev));
720 $args = $version ? array('version' => $version) : false;
722 return $this->makeButton($label ? $label : $this->maybeSplitWikiWord($pagename),
723 WikiURL($pagename, $args), 'wiki');
726 function _get_name_and_rev ($page_or_rev) {
729 if (empty($page_or_rev)) {
731 $pagename = $request->getArg("pagename");
732 $version = $request->getArg("version");
734 elseif (is_object($page_or_rev)) {
735 if (isa($page_or_rev, 'WikiDB_PageRevision')) {
737 $page = $rev->getPage();
738 $version = $rev->getVersion();
741 $page = $page_or_rev;
743 $pagename = $page->getName();
746 $pagename = (string) $page_or_rev;
748 return compact('pagename', 'version');
751 function _labelForAction ($action) {
753 case 'edit': return _("Edit");
754 case 'diff': return _("Diff");
755 case 'logout': return _("Sign Out");
756 case 'login': return _("Sign In");
757 case 'lock': return _("Lock Page");
758 case 'unlock': return _("Unlock Page");
759 case 'remove': return _("Remove Page");
761 // I don't think the rest of these actually get used.
763 // 'upload' 'dumpserial' 'loadfile' 'zip'
765 return gettext(ucfirst($action));
769 //----------------------------------------------------------------
770 var $_buttonSeparator = "\n | ";
772 function setButtonSeparator($separator) {
773 $this->_buttonSeparator = $separator;
776 function getButtonSeparator() {
777 return $this->_buttonSeparator;
781 ////////////////////////////////////////////////////////////////
787 // Based on testing with Galeon 1.2.7 (Mozilla 1.2):
788 // Automatic media-based style selection (via <link> tags) only
789 // seems to work for the default style, not for alternate styles.
793 // <link rel="stylesheet" type="text/css" href="phpwiki.css" />
794 // <link rel="stylesheet" type="text/css" href="phpwiki-printer.css" media="print" />
796 // works to make it so that the printer style sheet get used
797 // automatically when printing (or print-previewing) a page
798 // (but when only when the default style is selected.)
802 // <link rel="alternate stylesheet" title="Modern"
803 // type="text/css" href="phpwiki-modern.css" />
804 // <link rel="alternate stylesheet" title="Modern"
805 // type="text/css" href="phpwiki-printer.css" media="print" />
807 // Result in two "Modern" choices when trying to select alternate style.
808 // If one selects the first of those choices, one gets phpwiki-modern
809 // both when browsing and printing. If one selects the second "Modern",
810 // one gets no CSS when browsing, and phpwiki-printer when printing.
815 // We should probably move to doing the media based style
816 // switching in the CSS files themselves using, e.g.:
818 // @import url(print.css) print;
820 ////////////////////////////////////////////////////////////////
822 function _CSSlink($title, $css_file, $media, $is_alt = false) {
823 // Don't set title on default style. This makes it clear to
824 // the user which is the default (i.e. most supported) style.
825 $link = HTML::link(array('rel' => $is_alt ? 'alternate stylesheet' : 'stylesheet',
826 'type' => 'text/css',
827 'charset' => CHARSET,
828 'href' => $this->_findData($css_file)));
830 $link->setAttr('title', $title);
833 $link->setAttr('media', $media);
838 /** Set default CSS source for this theme.
840 * To set styles to be used for different media, pass a
841 * hash for the second argument, e.g.
843 * $theme->setDefaultCSS('default', array('' => 'normal.css',
844 * 'print' => 'printer.css'));
846 * If you call this more than once, the last one called takes
847 * precedence as the default style.
849 * @param string $title Name of style (currently ignored, unless
850 * you call this more than once, in which case, some of the style
851 * will become alternate (rather than default) styles, and then their
852 * titles will be used.
854 * @param mixed $css_files Name of CSS file, or hash containing a mapping
855 * between media types and CSS file names. Use a key of '' (the empty string)
856 * to set the default CSS for non-specified media. (See above for an example.)
858 function setDefaultCSS ($title, $css_files) {
859 if (!is_array($css_files))
860 $css_files = array('' => $css_files);
861 // Add to the front of $this->_css
862 unset($this->_css[$title]);
863 $this->_css = array_merge(array($title => $css_files), $this->_css);
866 /** Set alternate CSS source for this theme.
868 * @param string $title Name of style.
869 * @param string $css_files Name of CSS file.
871 function addAlternateCSS ($title, $css_files) {
872 if (!is_array($css_files))
873 $css_files = array('' => $css_files);
874 $this->_css[$title] = $css_files;
878 * @return string HTML for CSS.
883 foreach ($this->_css as $title => $css_files) {
884 aksort($css_files); // move $css_files[''] to front.
885 foreach ($css_files as $media => $css_file) {
886 $css[] = $this->_CSSlink($title, $css_file, $media, $is_alt);
896 function findTemplate ($name) {
897 return $this->_path . $this->_findFile("templates/$name.tmpl");
903 * A class representing a clickable "button".
905 * In it's simplest (default) form, a "button" is just a link associated
906 * with some sort of wiki-action.
908 class Button extends HtmlElement {
911 * @param $text string The text for the button.
912 * @param $url string The url (href) for the button.
913 * @param $class string The CSS class for the button.
915 function Button ($text, $url, $class = false) {
917 $this->HtmlElement('a', array('href' => $url));
919 $this->setAttr('class', $class);
920 if ($request->getArg('frame'))
921 $this->setAttr('target', '_top');
922 $this->pushContent($GLOBALS['Theme']->maybeSplitWikiWord($text));
929 * A clickable image button.
931 class ImageButton extends Button {
934 * @param $text string The text for the button.
935 * @param $url string The url (href) for the button.
936 * @param $class string The CSS class for the button.
937 * @param $img_url string URL for button's image.
938 * @param $img_attr array Additional attributes for the <img> tag.
940 function ImageButton ($text, $url, $class, $img_url, $img_attr = false) {
941 $this->HtmlElement('a', array('href' => $url));
943 $this->setAttr('class', $class);
945 if (!is_array($img_attr))
947 $img_attr['src'] = $img_url;
948 $img_attr['alt'] = $text;
949 $img_attr['class'] = 'wiki-button';
950 $img_attr['border'] = 0;
951 $this->pushContent(HTML::img($img_attr));
956 * A class representing a form <samp>submit</samp> button.
958 class SubmitButton extends HtmlElement {
961 * @param $text string The text for the button.
962 * @param $name string The name of the form field.
963 * @param $class string The CSS class for the button.
965 function SubmitButton ($text, $name = false, $class = false) {
966 $this->HtmlElement('input', array('type' => 'submit',
969 $this->setAttr('name', $name);
971 $this->setAttr('class', $class);
978 * A class representing an image form <samp>submit</samp> button.
980 class SubmitImageButton extends SubmitButton {
983 * @param $text string The text for the button.
984 * @param $name string The name of the form field.
985 * @param $class string The CSS class for the button.
986 * @param $img_url string URL for button's image.
987 * @param $img_attr array Additional attributes for the <img> tag.
989 function SubmitImageButton ($text, $name = false, $class = false, $img_url) {
990 $this->HtmlElement('input', array('type' => 'image',
995 $this->setAttr('name', $name);
997 $this->setAttr('class', $class);
1002 // $Log: not supported by cvs2svn $
1003 // Revision 1.63 2003/02/23 03:37:05 dairiki
1004 // Stupid typo/bug fix.
1006 // Revision 1.62 2003/02/21 04:14:52 dairiki
1007 // New WikiLink type 'if_known'. This gives linkified name if page
1008 // exists, otherwise, just plain text.
1010 // Revision 1.61 2003/02/18 21:52:05 dairiki
1011 // Fix so that one can still link to wiki pages with # in their names.
1012 // (This was made difficult by the introduction of named tags, since
1013 // '[Page #1]' is now a link to anchor '1' in page 'Page'.
1015 // Now the ~ escape for page names should work: [Page ~#1].
1017 // Revision 1.60 2003/02/15 01:59:47 dairiki
1018 // Theme::getCSS(): Add Default-Style HTTP(-eqiv) header in attempt
1019 // to fix default stylesheet selection on some browsers.
1020 // For details on the Default-Style header, see:
1021 // http://home.dairiki.org/docs/html4/present/styles.html#h-14.3.2
1023 // Revision 1.59 2003/01/04 22:30:16 carstenklapp
1024 // New: display a "Never edited." message instead of an invalid epoch date.
1027 // (c-file-style: "gnu")
1031 // c-basic-offset: 4
1032 // c-hanging-comment-ender-p: nil
1033 // indent-tabs-mode: nil