1 <?php rcs_id('$Id: Theme.php,v 1.86 2004-04-18 01:11:51 rurban Exp $');
2 /* Copyright (C) 2002, Geoffrey T. Dairiki <dairiki@dairiki.org>
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('lib/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 $page = $page_or_rev->getPage();
68 $pagename = $page->getName();
69 $wikipage = $pagename;
72 elseif (isa($page_or_rev, 'WikiDB_Page')) {
74 $pagename = $page->getName();
75 $wikipage = $pagename;
77 elseif (isa($page_or_rev, 'WikiPageName')) {
78 $wikipage = $page_or_rev;
79 $pagename = $wikipage->name;
82 $wikipage = new WikiPageName($page_or_rev, $request->getPage());
83 $pagename = $wikipage->name;
86 if (!is_string($wikipage) and !$wikipage->isValid('strict'))
87 return $Theme->linkBadWikiWord($wikipage, $label);
89 if ($type == 'auto' or $type == 'if_known') {
91 $current = $page->getCurrentRevision();
92 $exists = ! $current->hasDefaultContents();
95 $dbi = $request->getDbh();
96 $exists = $dbi->isWikiPage($wikipage->name);
99 elseif ($type == 'unknown') {
106 // FIXME: this should be somewhere else, if really needed.
107 // WikiLink makes A link, not a string of fancy ones.
108 // (I think that the fancy split links are just confusing.)
109 // Todo: test external ImageLinks http://some/images/next.gif
110 if (isa($wikipage, 'WikiPageName') and !$label
111 and strchr(substr($wikipage->shortName,1), SUBPAGE_SEPARATOR)) {
112 $parts = explode(SUBPAGE_SEPARATOR, $wikipage->shortName);
113 $last_part = array_pop($parts);
115 $link = HTML::span();
116 foreach ($parts as $part) {
118 $parent = join(SUBPAGE_SEPARATOR, $path);
119 if ($Theme->_autosplitWikiWords)
122 $link->pushContent($Theme->linkExistingWikiWord($parent, $sep . $part));
123 $sep = $Theme->_autosplitWikiWords ? ' ' . SUBPAGE_SEPARATOR : SUBPAGE_SEPARATOR;
126 $link->pushContent($Theme->linkExistingWikiWord($wikipage, $sep . $last_part, $version));
128 $link->pushContent($Theme->linkUnknownWikiWord($wikipage, $last_part));
133 return $Theme->linkExistingWikiWord($wikipage, $label, $version);
135 elseif ($type == 'if_known') {
136 if (!$label && isa($wikipage, 'WikiPageName'))
137 $label = $wikipage->shortName;
138 return HTML($label ? $label : $pagename);
141 return $Theme->linkUnknownWikiWord($wikipage, $label);
150 * This is a convenience function.
152 * @param $action string
154 * <dt>[action]</dt><dd>Perform action (e.g. 'edit') on the selected page.</dd>
155 * <dt>[ActionPage]</dt><dd>Run the actionpage (e.g. 'BackLinks') on the selected page.</dd>
156 * <dt>'submit:'[name]</dt><dd>Make a form submission button with the given name.
157 * ([name] can be blank for a nameless submit button.)</dd>
158 * <dt>a hash</dt><dd>Query args for the action. E.g.<pre>
159 * array('action' => 'diff', 'previous' => 'author')
163 * @param $label string
164 * A label for the button. If ommited, a suitable default (based on the valued of $action)
167 * @param $page_or_rev mixed
168 * Which page (& version) to perform the action on.
170 * <dt>A string</dt><dd>The pagename.</dd>
171 * <dt>A WikiDB_Page object</dt><dd>The page.</dd>
172 * <dt>A WikiDB_PageRevision object</dt><dd>A specific version of the page.</dd>
174 * ($Page_or_rev is ignored for submit buttons.)
176 function Button ($action, $label = false, $page_or_rev = false) {
179 if (!is_array($action) && preg_match('/submit:(.*)/A', $action, $m))
180 return $Theme->makeSubmitButton($label, $m[1], $class = $page_or_rev);
182 return $Theme->makeActionButton($action, $label, $page_or_rev);
187 var $HTML_DUMP_SUFFIX = '';
188 var $DUMP_MODE = false, $dumped_images, $dumped_css;
190 function Theme ($theme_name = 'default') {
191 $this->_name = $theme_name;
192 $themes_dir = defined('PHPWIKI_DIR') ? PHPWIKI_DIR . "/themes" : "themes";
194 $this->_path = defined('PHPWIKI_DIR') ? PHPWIKI_DIR . "/" : "";
195 $this->_theme = "themes/$theme_name";
197 if ($theme_name != 'default')
198 $this->_default_theme = new Theme;
200 $this->_css = array();
203 function file ($file) {
204 return $this->_path . "$this->_theme/$file";
207 function _findFile ($file, $missing_okay = false) {
208 if (file_exists($this->_path . "$this->_theme/$file"))
209 return "$this->_theme/$file";
211 // FIXME: this is a short-term hack. Delete this after all files
212 // get moved into themes/...
213 if (file_exists($this->_path . $file))
217 if (isset($this->_default_theme)) {
218 return $this->_default_theme->_findFile($file, $missing_okay);
220 else if (!$missing_okay) {
221 trigger_error("$file: not found", E_USER_NOTICE);
226 function _findData ($file, $missing_okay = false) {
227 $path = $this->_findFile($file, $missing_okay);
231 if (defined('DATA_PATH'))
232 return DATA_PATH . "/$path";
236 ////////////////////////////////////////////////////////////////
238 // Date and Time formatting
240 ////////////////////////////////////////////////////////////////
242 // Note: Windows' implemetation of strftime does not include certain
243 // format specifiers, such as %e (for date without leading zeros). In
245 // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_strftime.2c_.wcsftime.asp
246 // As a result, we have to use %d, and strip out leading zeros ourselves.
248 var $_dateFormat = "%B %d, %Y";
249 var $_timeFormat = "%I:%M %p";
251 var $_showModTime = true;
254 * Set format string used for dates.
256 * @param $fs string Format string for dates.
258 * @param $show_mod_time bool If true (default) then times
259 * are included in the messages generated by getLastModifiedMessage(),
260 * otherwise, only the date of last modification will be shown.
262 function setDateFormat ($fs, $show_mod_time = true) {
263 $this->_dateFormat = $fs;
264 $this->_showModTime = $show_mod_time;
268 * Set format string used for times.
270 * @param $fs string Format string for times.
272 function setTimeFormat ($fs) {
273 $this->_timeFormat = $fs;
279 * Any time zone offset specified in the users preferences is
280 * taken into account by this method.
282 * @param $time_t integer Unix-style time.
284 * @return string The date.
286 function formatDate ($time_t) {
289 $offset_time = $time_t + 3600 * $request->getPref('timeOffset');
290 // strip leading zeros from date elements (ie space followed by zero)
291 return preg_replace('/ 0/', ' ',
292 strftime($this->_dateFormat, $offset_time));
298 * Any time zone offset specified in the users preferences is
299 * taken into account by this method.
301 * @param $time_t integer Unix-style time.
303 * @return string The time.
305 function formatTime ($time_t) {
306 //FIXME: make 24-hour mode configurable?
308 $offset_time = $time_t + 3600 * $request->getPref('timeOffset');
309 return preg_replace('/^0/', ' ',
310 strtolower(strftime($this->_timeFormat, $offset_time)));
314 * Format a date and time.
316 * Any time zone offset specified in the users preferences is
317 * taken into account by this method.
319 * @param $time_t integer Unix-style time.
321 * @return string The date and time.
323 function formatDateTime ($time_t) {
324 return $this->formatDate($time_t) . ' ' . $this->formatTime($time_t);
328 * Format a (possibly relative) date.
330 * If enabled in the users preferences, this method might
331 * return a relative day (e.g. 'Today', 'Yesterday').
333 * Any time zone offset specified in the users preferences is
334 * taken into account by this method.
336 * @param $time_t integer Unix-style time.
338 * @return string The day.
340 function getDay ($time_t) {
343 if ($request->getPref('relativeDates') && ($date = $this->_relativeDay($time_t))) {
344 return ucfirst($date);
346 return $this->formatDate($time_t);
350 * Format the "last modified" message for a page revision.
352 * @param $revision object A WikiDB_PageRevision object.
354 * @param $show_version bool Should the page version number
355 * be included in the message. (If this argument is omitted,
356 * then the version number will be shown only iff the revision
357 * is not the current one.
359 * @return string The "last modified" message.
361 function getLastModifiedMessage ($revision, $show_version = 'auto') {
364 // dates >= this are considered invalid.
365 if (! defined('EPOCH'))
366 define('EPOCH', 0); // seconds since ~ January 1 1970
368 $mtime = $revision->get('mtime');
370 return fmt("Never edited.");
372 if ($show_version == 'auto')
373 $show_version = !$revision->isCurrent();
375 if ($request->getPref('relativeDates') && ($date = $this->_relativeDay($mtime))) {
376 if ($this->_showModTime)
377 $date = sprintf(_("%s at %s"),
378 $date, $this->formatTime($mtime));
381 return fmt("Version %s, saved %s.", $revision->getVersion(), $date);
383 return fmt("Last edited %s.", $date);
386 if ($this->_showModTime)
387 $date = $this->formatDateTime($mtime);
389 $date = $this->formatDate($mtime);
392 return fmt("Version %s, saved on %s.", $revision->getVersion(), $date);
394 return fmt("Last edited on %s.", $date);
397 function _relativeDay ($time_t) {
400 if (is_numeric($request->getPref('timeOffset')))
401 $offset = 3600 * $request->getPref('timeOffset');
405 $now = time() + $offset;
406 $today = localtime($now, true);
407 $time = localtime($time_t + $offset, true);
409 if ($time['tm_yday'] == $today['tm_yday'] && $time['tm_year'] == $today['tm_year'])
412 // Note that due to daylight savings chages (and leap seconds), $now minus
413 // 24 hours is not guaranteed to be yesterday.
414 $yesterday = localtime($now - (12 + $today['tm_hour']) * 3600, true);
415 if ($time['tm_yday'] == $yesterday['tm_yday'] && $time['tm_year'] == $yesterday['tm_year'])
416 return _("yesterday");
421 ////////////////////////////////////////////////////////////////
423 // Hooks for other formatting
425 ////////////////////////////////////////////////////////////////
427 //FIXME: PHP 4.1 Warnings
428 //lib/Theme.php:84: Notice[8]: The call_user_method() function is deprecated,
429 //use the call_user_func variety with the array(&$obj, "method") syntax instead
431 function getFormatter ($type, $format) {
432 $method = strtolower("get${type}Formatter");
433 if (method_exists($this, $method))
434 return $this->{$method}($format);
438 ////////////////////////////////////////////////////////////////
442 ////////////////////////////////////////////////////////////////
444 var $_autosplitWikiWords = false;
446 function setAutosplitWikiWords($autosplit=false) {
447 $this->_autosplitWikiWords = $autosplit ? true : false;
450 function maybeSplitWikiWord ($wikiword) {
451 if ($this->_autosplitWikiWords)
452 return split_pagename($wikiword);
457 var $_anonEditUnknownLinks = true;
458 function setAnonEditUnknownLinks($anonedit=true) {
459 $this->_anonEditUnknownLinks = $anonedit ? true : false;
462 function linkExistingWikiWord($wikiword, $linktext = '', $version = false) {
465 if ($version !== false)
466 $url = WikiURL($wikiword, array('version' => $version));
468 $url = WikiURL($wikiword);
470 // Extra steps for dumping page to an html file.
471 // FIXME: shouldn't this be in WikiURL?
472 if ($this->HTML_DUMP_SUFFIX) {
473 // no action or sortby links
474 $url = preg_replace("/\?.*$/","",$url);
475 // urlencode for pagenames with accented letters
476 $url = rawurlencode($url);
477 $url = preg_replace('/^\./', '%2e', $url);
478 // fix url#anchor links (looks awful)
479 if (strstr($url,'%23'))
480 $url = preg_replace("/%23/",$this->HTML_DUMP_SUFFIX."#",$url);
482 $url .= $this->HTML_DUMP_SUFFIX;
485 $link = HTML::a(array('href' => $url));
487 if (isa($wikiword, 'WikiPageName'))
488 $default_text = $wikiword->shortName;
490 $default_text = $wikiword;
492 if (!empty($linktext)) {
493 $link->pushContent($linktext);
494 $link->setAttr('class', 'named-wiki');
495 $link->setAttr('title', $this->maybeSplitWikiWord($default_text));
498 $link->pushContent($this->maybeSplitWikiWord($default_text));
499 $link->setAttr('class', 'wiki');
501 if ($request->getArg('frame'))
502 $link->setAttr('target', '_top');
506 function linkUnknownWikiWord($wikiword, $linktext = '') {
509 // Get rid of anchors on unknown wikiwords
510 if (isa($wikiword, 'WikiPageName')) {
511 $default_text = $wikiword->shortName;
512 $wikiword = $wikiword->name;
515 $default_text = $wikiword;
518 if ($this->DUMP_MODE) { // HTML, PDF or XML
519 $link = HTML::u( empty($linktext) ? $wikiword : $linktext);
520 $link->addTooltip(sprintf(_("Empty link to: %s"), $wikiword));
521 $link->setAttr('class', empty($linktext) ? 'wikiunknown' : 'named-wikiunknown');
524 // if AnonEditUnknownLinks show "?" only users which are allowed to edit this page
525 if (! $this->_anonEditUnknownLinks and ! mayAccessPage('edit',$request->getArg('pagename'))) {
526 $text = HTML::span( empty($linktext) ? $wikiword : $linktext);
527 $text->setAttr('class', empty($linktext) ? 'wikiunknown' : 'named-wikiunknown');
530 $url = WikiURL($wikiword, array('action' => 'create'));
531 $button = $this->makeButton('?', $url);
532 $button->addTooltip(sprintf(_("Create: %s"), $wikiword));
534 $link = HTML::span($button);
538 if (!empty($linktext)) {
539 $link->pushContent(HTML::u($linktext));
540 $link->setAttr('class', 'named-wikiunknown');
543 $link->pushContent(HTML::u($this->maybeSplitWikiWord($default_text)));
544 $link->setAttr('class', 'wikiunknown');
546 if ($request->getArg('frame'))
547 $link->setAttr('target', '_top');
552 function linkBadWikiWord($wikiword, $linktext = '') {
553 global $ErrorManager;
558 elseif (isa($wikiword, 'WikiPageName')) {
559 $text = $wikiword->shortName;
565 if (isa($wikiword, 'WikiPageName'))
566 $message = $wikiword->getWarnings();
568 $message = sprintf(_("'%s': Bad page name"), $wikiword);
569 $ErrorManager->warning($message);
571 return HTML::span(array('class' => 'badwikiword'), $text);
574 ////////////////////////////////////////////////////////////////
578 ////////////////////////////////////////////////////////////////
579 var $_imageAliases = array();
580 var $_imageAlt = array();
584 * (To disable an image, alias the image to <code>false</code>.
586 function addImageAlias ($alias, $image_name) {
587 // fall back to the PhpWiki-supplied image if not found
588 if ($this->_findFile("images/$image_name", true))
589 $this->_imageAliases[$alias] = $image_name;
592 function addImageAlt ($alias, $alt_text) {
593 $this->_imageAlt[$alias] = $alt_text;
595 function getImageAlt ($alias) {
596 return $this->_imageAlt[$alias];
599 function getImageURL ($image) {
600 $aliases = &$this->_imageAliases;
602 if (isset($aliases[$image])) {
603 $image = $aliases[$image];
608 // If not extension, default to .png.
609 if (!preg_match('/\.\w+$/', $image))
612 // FIXME: this should probably be made to fall back
613 // automatically to .gif, .jpg.
614 // Also try .gif before .png if browser doesn't like png.
616 $path = $this->_findData("images/$image", 'missing okay');
617 if (!$path) // search explicit images/ or button/ links also
618 $path = $this->_findData("$image", 'missing okay');
620 if ($this->DUMP_MODE) {
621 if (empty($this->dumped_images)) $this->dumped_images = array();
622 $path = "images/". basename($path);
623 if (!in_array($path,$this->dumped_images)) $this->dumped_images[] = $path;
628 function setLinkIcon($proto, $image = false) {
632 $this->_linkIcons[$proto] = $image;
635 function getLinkIconURL ($proto) {
636 $icons = &$this->_linkIcons;
637 if (!empty($icons[$proto]))
638 return $this->getImageURL($icons[$proto]);
639 elseif (!empty($icons['*']))
640 return $this->getImageURL($icons['*']);
644 function addButtonAlias ($text, $alias = false) {
645 $aliases = &$this->_buttonAliases;
648 $aliases = array_merge($aliases, $text);
649 elseif ($alias === false)
650 unset($aliases[$text]);
652 $aliases[$text] = $alias;
655 function getButtonURL ($text) {
656 $aliases = &$this->_buttonAliases;
657 if (isset($aliases[$text]))
658 $text = $aliases[$text];
660 $qtext = urlencode($text);
661 $url = $this->_findButton("$qtext.png");
662 if ($url && strstr($url, '%')) {
663 $url = preg_replace('|([^/]+)$|e', 'urlencode("\\1")', $url);
665 if (!$url) {// Jeff complained about png not supported everywhere. This is not PC
666 $url = $this->_findButton("$qtext.gif");
667 if ($url && strstr($url, '%')) {
668 $url = preg_replace('|([^/]+)$|e', 'urlencode("\\1")', $url);
674 function _findButton ($button_file) {
675 if (empty($this->_button_path))
676 $this->_button_path = $this->_getButtonPath();
678 foreach ($this->_button_path as $dir) {
679 $path = "$dir/$button_file";
680 if (file_exists($this->_path . $path))
681 return defined('DATA_PATH') ? DATA_PATH . "/$path" : $path;
686 function _getButtonPath () {
687 $button_dir = $this->_findFile("buttons");
688 $path_dir = $this->_path . $button_dir;
689 if (!file_exists($path_dir) || !is_dir($path_dir))
691 $path = array($button_dir);
692 $dir = dir($path_dir);
693 while (($subdir = $dir->read()) !== false) {
694 if ($subdir[0] == '.')
696 if ($subdir == 'CVS')
698 if (is_dir("$path_dir/$subdir"))
699 $path[] = "$button_dir/$subdir";
706 ////////////////////////////////////////////////////////////////
710 ////////////////////////////////////////////////////////////////
712 function makeButton ($text, $url, $class = false) {
713 // FIXME: don't always try for image button?
715 // Special case: URLs like 'submit:preview' generate form
716 // submission buttons.
717 if (preg_match('/^submit:(.*)$/', $url, $m))
718 return $this->makeSubmitButton($text, $m[1], $class);
720 $imgurl = $this->getButtonURL($text);
722 return new ImageButton($text, $url, $class, $imgurl);
724 return new Button($text, $url, $class);
727 function makeSubmitButton ($text, $name, $class = false) {
728 $imgurl = $this->getButtonURL($text);
731 return new SubmitImageButton($text, $name, $class, $imgurl);
733 return new SubmitButton($text, $name, $class);
737 * Make button to perform action.
739 * This constructs a button which performs an action on the
740 * currently selected version of the current page.
741 * (Or anotherpage or version, if you want...)
743 * @param $action string The action to perform (e.g. 'edit', 'lock').
744 * This can also be the name of an "action page" like 'LikePages'.
745 * Alternatively you can give a hash of query args to be applied
748 * @param $label string Textual label for the button. If left empty,
749 * a suitable name will be guessed.
751 * @param $page_or_rev mixed The page to link to. This can be
752 * given as a string (the page name), a WikiDB_Page object, or as
753 * WikiDB_PageRevision object. If given as a WikiDB_PageRevision
754 * object, the button will link to a specific version of the
755 * designated page, otherwise the button links to the most recent
756 * version of the page.
758 * @return object A Button object.
760 function makeActionButton ($action, $label = false, $page_or_rev = false) {
761 extract($this->_get_name_and_rev($page_or_rev));
763 if (is_array($action)) {
765 $action = isset($attr['action']) ? $attr['action'] : 'browse';
768 $attr['action'] = $action;
770 $class = is_safe_action($action) ? 'wikiaction' : 'wikiadmin';
772 $label = $this->_labelForAction($action);
775 $attr['version'] = $version;
777 if ($action == 'browse')
778 unset($attr['action']);
780 return $this->makeButton($label, WikiURL($pagename, $attr), $class);
784 * Make a "button" which links to a wiki-page.
786 * These are really just regular WikiLinks, possibly
787 * disguised (e.g. behind an image button) by the theme.
789 * This method should probably only be used for links
790 * which appear in page navigation bars, or similar places.
792 * Use linkExistingWikiWord, or LinkWikiWord for normal links.
794 * @param $page_or_rev mixed The page to link to. This can be
795 * given as a string (the page name), a WikiDB_Page object, or as
796 * WikiDB_PageRevision object. If given as a WikiDB_PageRevision
797 * object, the button will link to a specific version of the
798 * designated page, otherwise the button links to the most recent
799 * version of the page.
801 * @return object A Button object.
803 function makeLinkButton ($page_or_rev, $label = false) {
804 extract($this->_get_name_and_rev($page_or_rev));
806 $args = $version ? array('version' => $version) : false;
808 return $this->makeButton($label ? $label : $this->maybeSplitWikiWord($pagename),
809 WikiURL($pagename, $args), 'wiki');
812 function _get_name_and_rev ($page_or_rev) {
815 if (empty($page_or_rev)) {
817 $pagename = $request->getArg("pagename");
818 $version = $request->getArg("version");
820 elseif (is_object($page_or_rev)) {
821 if (isa($page_or_rev, 'WikiDB_PageRevision')) {
823 $page = $rev->getPage();
824 $version = $rev->getVersion();
827 $page = $page_or_rev;
829 $pagename = $page->getName();
832 $pagename = (string) $page_or_rev;
834 return compact('pagename', 'version');
837 function _labelForAction ($action) {
839 case 'edit': return _("Edit");
840 case 'diff': return _("Diff");
841 case 'logout': return _("Sign Out");
842 case 'login': return _("Sign In");
843 case 'lock': return _("Lock Page");
844 case 'unlock': return _("Unlock Page");
845 case 'remove': return _("Remove Page");
847 // I don't think the rest of these actually get used.
849 // 'upload' 'dumpserial' 'loadfile' 'zip'
851 return gettext(ucfirst($action));
855 //----------------------------------------------------------------
856 var $_buttonSeparator = "\n | ";
858 function setButtonSeparator($separator) {
859 $this->_buttonSeparator = $separator;
862 function getButtonSeparator() {
863 return $this->_buttonSeparator;
867 ////////////////////////////////////////////////////////////////
873 // Based on testing with Galeon 1.2.7 (Mozilla 1.2):
874 // Automatic media-based style selection (via <link> tags) only
875 // seems to work for the default style, not for alternate styles.
879 // <link rel="stylesheet" type="text/css" href="phpwiki.css" />
880 // <link rel="stylesheet" type="text/css" href="phpwiki-printer.css" media="print" />
882 // works to make it so that the printer style sheet get used
883 // automatically when printing (or print-previewing) a page
884 // (but when only when the default style is selected.)
888 // <link rel="alternate stylesheet" title="Modern"
889 // type="text/css" href="phpwiki-modern.css" />
890 // <link rel="alternate stylesheet" title="Modern"
891 // type="text/css" href="phpwiki-printer.css" media="print" />
893 // Result in two "Modern" choices when trying to select alternate style.
894 // If one selects the first of those choices, one gets phpwiki-modern
895 // both when browsing and printing. If one selects the second "Modern",
896 // one gets no CSS when browsing, and phpwiki-printer when printing.
901 // We should probably move to doing the media based style
902 // switching in the CSS files themselves using, e.g.:
904 // @import url(print.css) print;
906 ////////////////////////////////////////////////////////////////
908 function _CSSlink($title, $css_file, $media, $is_alt = false) {
909 // Don't set title on default style. This makes it clear to
910 // the user which is the default (i.e. most supported) style.
911 $link = HTML::link(array('rel' => $is_alt ? 'alternate stylesheet' : 'stylesheet',
912 'type' => 'text/css',
913 'charset' => $GLOBALS['charset'],
914 'href' => $this->_findData($css_file)));
916 $link->setAttr('title', $title);
919 $link->setAttr('media', $media);
920 if ($this->DUMP_MODE) {
921 if (empty($this->dumped_css)) $this->dumped_css = array();
922 if (!in_array($css_file,$this->dumped_css)) $this->dumped_css[] = $css_file;
923 $link->setAttr('href', basename($link->getAttr('href')));
929 /** Set default CSS source for this theme.
931 * To set styles to be used for different media, pass a
932 * hash for the second argument, e.g.
934 * $theme->setDefaultCSS('default', array('' => 'normal.css',
935 * 'print' => 'printer.css'));
937 * If you call this more than once, the last one called takes
938 * precedence as the default style.
940 * @param string $title Name of style (currently ignored, unless
941 * you call this more than once, in which case, some of the style
942 * will become alternate (rather than default) styles, and then their
943 * titles will be used.
945 * @param mixed $css_files Name of CSS file, or hash containing a mapping
946 * between media types and CSS file names. Use a key of '' (the empty string)
947 * to set the default CSS for non-specified media. (See above for an example.)
949 function setDefaultCSS ($title, $css_files) {
950 if (!is_array($css_files))
951 $css_files = array('' => $css_files);
952 // Add to the front of $this->_css
953 unset($this->_css[$title]);
954 $this->_css = array_merge(array($title => $css_files), $this->_css);
957 /** Set alternate CSS source for this theme.
959 * @param string $title Name of style.
960 * @param string $css_files Name of CSS file.
962 function addAlternateCSS ($title, $css_files) {
963 if (!is_array($css_files))
964 $css_files = array('' => $css_files);
965 $this->_css[$title] = $css_files;
969 * @return string HTML for CSS.
974 foreach ($this->_css as $title => $css_files) {
975 ksort($css_files); // move $css_files[''] to front.
976 foreach ($css_files as $media => $css_file) {
977 $css[] = $this->_CSSlink($title, $css_file, $media, $is_alt);
987 function findTemplate ($name) {
988 return $this->_path . $this->_findFile("templates/$name.tmpl");
991 var $_MoreHeaders = array();
992 function addMoreHeaders ($element) {
993 array_push($this->_MoreHeaders,$element);
995 function getMoreHeaders () {
996 if (empty($this->_MoreHeaders))
999 //$out = "<!-- More Headers -->\n";
1000 foreach ($this->_MoreHeaders as $h) {
1002 $out .= printXML($h);
1009 var $_MoreAttr = array();
1010 function addMoreAttr ($id,$element) {
1011 if (empty($this->_MoreAttr) or !is_array($this->_MoreAttr[$id]))
1012 $this->_MoreAttr[$id] = array($element);
1014 array_push($this->_MoreAttr[$id],$element);
1016 function getMoreAttr ($id) {
1017 if (empty($this->_MoreAttr[$id]))
1020 foreach ($this->_MoreAttr[$id] as $h) {
1022 $out .= printXML($h);
1030 * Custom UserPreferences:
1031 * A list of name => _UserPreference class pairs.
1032 * Rationale: Certain themes should be able to extend the predefined list
1033 * of preferences. Display/editing is done in the theme specific userprefs.tmpl
1034 * but storage/sanification/update/... must be extended to the Get/SetPreferences methods.
1035 * These values are just ignored if another theme is used.
1037 function customUserPreferences($array) {
1038 global $customUserPreferenceColumns; // FIXME: really a global?
1039 if (empty($customUserPreferenceColumns)) $customUserPreferenceColumns = array();
1040 //array('wikilens' => new _UserPreference_wikilens());
1041 foreach ($array as $field => $prefobj) {
1042 $customUserPreferenceColumns[$field] = $prefobj;
1046 /** addPageListColumn(array('rating' => new _PageList_Column_rating('rating', _("Rate"))))
1047 * Register custom PageList types for special themes, like
1048 * 'rating' for wikilens
1050 function addPageListColumn ($array) {
1051 global $customPageListColumns;
1052 if (empty($customPageListColumns)) $customPageListColumns = array();
1053 foreach ($array as $column => $obj) {
1054 $customPageListColumns[$column] = $obj;
1062 * A class representing a clickable "button".
1064 * In it's simplest (default) form, a "button" is just a link associated
1065 * with some sort of wiki-action.
1067 class Button extends HtmlElement {
1070 * @param $text string The text for the button.
1071 * @param $url string The url (href) for the button.
1072 * @param $class string The CSS class for the button.
1074 function Button ($text, $url, $class = false) {
1077 if (check_php_version(5)) {
1078 $this->_init('a', array('href' => $url));
1080 $this->HtmlElement('a', array('href' => $url));
1083 $this->setAttr('class', $class);
1084 if ($request->getArg('frame'))
1085 $this->setAttr('target', '_top');
1086 $this->pushContent($GLOBALS['Theme']->maybeSplitWikiWord($text));
1093 * A clickable image button.
1095 class ImageButton extends Button {
1098 * @param $text string The text for the button.
1099 * @param $url string The url (href) for the button.
1100 * @param $class string The CSS class for the button.
1101 * @param $img_url string URL for button's image.
1102 * @param $img_attr array Additional attributes for the <img> tag.
1104 function ImageButton ($text, $url, $class, $img_url, $img_attr = false) {
1105 $this->HtmlElement('a', array('href' => $url));
1107 $this->setAttr('class', $class);
1109 if (!is_array($img_attr))
1110 $img_attr = array();
1111 $img_attr['src'] = $img_url;
1112 $img_attr['alt'] = $text;
1113 $img_attr['class'] = 'wiki-button';
1114 $img_attr['border'] = 0;
1115 $this->pushContent(HTML::img($img_attr));
1120 * A class representing a form <samp>submit</samp> button.
1122 class SubmitButton extends HtmlElement {
1125 * @param $text string The text for the button.
1126 * @param $name string The name of the form field.
1127 * @param $class string The CSS class for the button.
1129 function SubmitButton ($text, $name = false, $class = false) {
1130 $this->HtmlElement('input', array('type' => 'submit',
1133 $this->setAttr('name', $name);
1135 $this->setAttr('class', $class);
1142 * A class representing an image form <samp>submit</samp> button.
1144 class SubmitImageButton extends SubmitButton {
1147 * @param $text string The text for the button.
1148 * @param $name string The name of the form field.
1149 * @param $class string The CSS class for the button.
1150 * @param $img_url string URL for button's image.
1151 * @param $img_attr array Additional attributes for the <img> tag.
1153 function SubmitImageButton ($text, $name = false, $class = false, $img_url) {
1154 $this->HtmlElement('input', array('type' => 'image',
1159 $this->setAttr('name', $name);
1161 $this->setAttr('class', $class);
1167 * A sidebar box with title and body, narrow fixed-width.
1168 * To represent abbrevated content of plugins, links or forms,
1169 * like "Getting Started", "Search", "Sarch Pagename",
1170 * "Login", "Menu", "Recent Changes", "Last comments", "Last Blogs"
1172 * ... See http://tikiwiki.org/
1176 * $menu = SidebarBox("Menu",HTML::dl(HTML::dt(...))); $menu->format();
1177 * $menu = PluginSidebarBox("RecentChanges",array('limit'=>10)); $menu->format();
1181 function SidebarBox($title, $body) {
1182 $this->title = $title;
1183 $this->body = $body;
1186 return WikiPlugin::makeBox($this->title, $this->body);
1191 * A sidebar box for plugins.
1192 * Any plugin may provide a box($args=false, $request=false, $basepage=false)
1193 * method, with the help of WikiPlugin::makeBox()
1195 class PluginSidebarBox extends SidebarBox {
1197 var $_plugin, $_args = false, $_basepage = false;
1199 function PluginSidebarBox($name, $args = false, $basepage = false) {
1200 $loader = new WikiPluginLoader();
1201 $plugin = $loader->getPlugin($name);
1202 if (!method_exists($plugin,'box')) {
1203 return $loader->error(sprintf(_("%s: has no box method"),
1204 get_class($plugin)));
1206 $this->_plugin =& $plugin;
1207 $this->_args = $args ? $args : array();
1208 $this->_basepage = $basepage;
1211 function format($args = false) {
1212 return $this->_plugin->box($args ? array_merge($this->_args,$args) : $this->_args,
1213 $GLOBALS['request'],
1218 // Various boxes which are no plugins
1219 class RelatedLinksBox extends SidebarBox {
1220 function RelatedLinksBox($title = false, $body = '', $limit = 20) {
1222 $this->title = $title ? $title : _("Related Links");
1223 $this->body = HTML($body);
1224 $page = $request->getPage($request->getArg('pagename'));
1225 $revision = $page->getCurrentRevision();
1226 $page_content = $revision->getTransformedContent();
1227 //$cache = &$page->_wikidb->_cache;
1229 $sp = HTML::Raw('· ');
1230 foreach ($page_content->getWikiPageLinks() as $link) {
1231 if (!$request->_dbi->isWikiPage($link)) continue;
1232 $this->body->pushContent($sp, WikiLink($link), HTML::br());
1234 if ($limit and $counter > $limit) continue;
1239 class RelatedExternalLinksBox extends SidebarBox {
1240 function RelatedExternalLinksBox($title = false, $body = '', $limit = 20) {
1242 $this->title = $title ? $title : _("External Links");
1243 $this->body = HTML($body);
1244 $page = $request->getPage($request->getArg('pagename'));
1245 $cache = &$page->_wikidb->_cache;
1247 $sp = HTML::Raw('· ');
1248 foreach ($cache->getWikiPageLinks() as $link) {
1250 $this->body->pushContent($sp, WikiLink($link), HTML::br());
1252 if ($limit and $counter > $limit) continue;
1260 // $Log: not supported by cvs2svn $
1261 // Revision 1.85 2004/04/12 13:04:50 rurban
1262 // added auth_create: self-registering Db users
1264 // removed rating recommendations
1265 // ziplib reformatting
1267 // Revision 1.84 2004/04/10 02:30:49 rurban
1268 // Fixed gettext problem with VIRTUAL_PATH scripts (Windows only probably)
1269 // Fixed "cannot setlocale..." (sf.net problem)
1271 // Revision 1.83 2004/04/09 17:49:03 rurban
1272 // Added PhpWiki RssFeed to Sidebar
1273 // sidebar formatting
1274 // some browser dependant fixes (old-browser support)
1276 // Revision 1.82 2004/04/06 20:00:10 rurban
1277 // Cleanup of special PageList column types
1278 // Added support of plugin and theme specific Pagelist Types
1279 // Added support for theme specific UserPreferences
1280 // Added session support for ip-based throttling
1281 // sql table schema change: ALTER TABLE session ADD sess_ip CHAR(15);
1282 // Enhanced postgres schema
1283 // Added DB_Session_dba support
1285 // Revision 1.81 2004/04/01 15:57:10 rurban
1286 // simplified Sidebar theme: table, not absolute css positioning
1287 // added the new box methods.
1288 // remaining problems: large left margin, how to override _autosplitWikiWords in Template only
1290 // Revision 1.80 2004/03/30 02:14:03 rurban
1291 // fixed yet another Prefs bug
1292 // added generic PearDb_iter
1293 // $request->appendValidators no so strict as before
1294 // added some box plugin methods
1295 // PageList commalist for condensed output
1297 // Revision 1.79 2004/03/24 19:39:02 rurban
1298 // php5 workaround code (plus some interim debugging code in XmlElement)
1299 // php5 doesn't work yet with the current XmlElement class constructors,
1300 // WikiUserNew does work better than php4.
1301 // rewrote WikiUserNew user upgrading to ease php5 update
1302 // fixed pref handling in WikiUserNew
1303 // added Email Notification
1304 // added simple Email verification
1305 // removed emailVerify userpref subclass: just a email property
1306 // changed pref binary storage layout: numarray => hash of non default values
1307 // print optimize message only if really done.
1308 // forced new cookie policy: delete pref cookies, use only WIKI_ID as plain string.
1309 // prefs should be stored in db or homepage, besides the current session.
1311 // Revision 1.78 2004/03/18 22:32:33 rurban
1312 // work to make it php5 compatible
1314 // Revision 1.77 2004/03/08 19:30:01 rurban
1315 // fixed Theme->getButtonURL
1316 // AllUsers uses now WikiGroup (also DB User and DB Pref users)
1317 // PageList fix for empty pagenames
1319 // Revision 1.76 2004/03/08 18:17:09 rurban
1320 // added more WikiGroup::getMembersOf methods, esp. for special groups
1321 // fixed $LDAP_SET_OPTIONS
1322 // fixed _AuthInfo group methods
1324 // Revision 1.75 2004/03/01 09:34:37 rurban
1325 // fixed button path logic: now fallback to default also
1327 // Revision 1.74 2004/02/28 21:14:08 rurban
1328 // generally more PHPDOC docs
1329 // see http://xarch.tu-graz.ac.at/home/rurban/phpwiki/xref/
1330 // fxied WikiUserNew pref handling: empty theme not stored, save only
1331 // changed prefs, sql prefs improved, fixed password update,
1332 // removed REPLACE sql (dangerous)
1333 // moved gettext init after the locale was guessed
1334 // + some minor changes
1336 // Revision 1.73 2004/02/26 03:22:05 rurban
1337 // also copy css and images with XHTML Dump
1339 // Revision 1.72 2004/02/26 02:25:53 rurban
1340 // fix empty and #-anchored links in XHTML Dumps
1342 // Revision 1.71 2004/02/15 21:34:37 rurban
1343 // PageList enhanced and improved.
1344 // fixed new WikiAdmin... plugins
1345 // editpage, Theme with exp. htmlarea framework
1346 // (htmlarea yet committed, this is really questionable)
1347 // WikiUser... code with better session handling for prefs
1348 // enhanced UserPreferences (again)
1349 // RecentChanges for show_deleted: how should pages be deleted then?
1351 // Revision 1.70 2004/01/26 09:17:48 rurban
1352 // * changed stored pref representation as before.
1353 // the array of objects is 1) bigger and 2)
1354 // less portable. If we would import packed pref
1355 // objects and the object definition was changed, PHP would fail.
1356 // This doesn't happen with an simple array of non-default values.
1357 // * use $prefs->retrieve and $prefs->store methods, where retrieve
1358 // understands the interim format of array of objects also.
1359 // * simplified $prefs->get() and fixed $prefs->set()
1360 // * added $user->_userid and class '_WikiUser' portability functions
1361 // * fixed $user object ->_level upgrading, mostly using sessions.
1362 // this fixes yesterdays problems with loosing authorization level.
1363 // * fixed WikiUserNew::checkPass to return the _level
1364 // * fixed WikiUserNew::isSignedIn
1365 // * added explodePageList to class PageList, support sortby arg
1366 // * fixed UserPreferences for WikiUserNew
1367 // * fixed WikiPlugin for empty defaults array
1368 // * UnfoldSubpages: added pagename arg, renamed pages arg,
1369 // removed sort arg, support sortby arg
1371 // Revision 1.69 2003/12/05 01:32:28 carstenklapp
1372 // New feature: Easier to run multiple wiks off of one set of code. Name
1373 // your logo and signature image files "YourWikiNameLogo.png" and
1374 // "YourWikiNameSignature.png" and put them all into
1375 // themes/default/images. YourWikiName should match what is defined as
1376 // WIKI_NAME in index.php. In case the image is not found, the default
1377 // shipped with PhpWiki will be used.
1379 // Revision 1.68 2003/03/04 01:53:30 dairiki
1380 // Inconsequential decrufting.
1382 // Revision 1.67 2003/02/26 03:40:22 dairiki
1383 // New action=create. Essentially the same as action=edit, except that if the
1384 // page already exists, it falls back to action=browse.
1386 // This is for use in the "question mark" links for unknown wiki words
1387 // to avoid problems and confusion when following links from stale pages.
1388 // (If the "unknown page" has been created in the interim, the user probably
1389 // wants to view the page before editing it.)
1391 // Revision 1.66 2003/02/26 00:10:26 dairiki
1392 // More/better/different checks for bad page names.
1394 // Revision 1.65 2003/02/24 22:41:57 dairiki
1397 // Revision 1.64 2003/02/24 22:06:14 dairiki
1398 // Attempts to fix auto-selection of printer CSS when printing.
1399 // See new comments lib/Theme.php for more details.
1400 // Also see SF patch #669563.
1402 // Revision 1.63 2003/02/23 03:37:05 dairiki
1403 // Stupid typo/bug fix.
1405 // Revision 1.62 2003/02/21 04:14:52 dairiki
1406 // New WikiLink type 'if_known'. This gives linkified name if page
1407 // exists, otherwise, just plain text.
1409 // Revision 1.61 2003/02/18 21:52:05 dairiki
1410 // Fix so that one can still link to wiki pages with # in their names.
1411 // (This was made difficult by the introduction of named tags, since
1412 // '[Page #1]' is now a link to anchor '1' in page 'Page'.
1414 // Now the ~ escape for page names should work: [Page ~#1].
1416 // Revision 1.60 2003/02/15 01:59:47 dairiki
1417 // Theme::getCSS(): Add Default-Style HTTP(-eqiv) header in attempt
1418 // to fix default stylesheet selection on some browsers.
1419 // For details on the Default-Style header, see:
1420 // http://home.dairiki.org/docs/html4/present/styles.html#h-14.3.2
1422 // Revision 1.59 2003/01/04 22:30:16 carstenklapp
1423 // New: display a "Never edited." message instead of an invalid epoch date.
1426 // (c-file-style: "gnu")
1430 // c-basic-offset: 4
1431 // c-hanging-comment-ender-p: nil
1432 // indent-tabs-mode: nil