1 <?php rcs_id('$Id: Theme.php,v 1.142 2007-07-01 09:36:09 rurban Exp $');
2 /* Copyright (C) 2002,2004,2005,2006 $ThePhpWikiProgrammingTeam
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 $WikiTheme, $request;
59 if ($type == 'button') {
60 return $WikiTheme->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;
82 if (!$wikipage->isValid('strict'))
83 return $WikiTheme->linkBadWikiWord($wikipage, $label);
86 $wikipage = new WikiPageName($page_or_rev, $request->getPage());
87 $pagename = $wikipage->name;
88 if (!$wikipage->isValid('strict'))
89 return $WikiTheme->linkBadWikiWord($wikipage, $label);
92 if ($type == 'auto' or $type == 'if_known') {
94 $exists = $page->exists();
97 $dbi =& $request->_dbi;
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 ($WikiTheme->_autosplitWikiWords)
126 $link->pushContent($WikiTheme->linkExistingWikiWord($parent, $sep . $part));
127 $sep = $WikiTheme->_autosplitWikiWords
128 ? ' ' . SUBPAGE_SEPARATOR : SUBPAGE_SEPARATOR;
131 $link->pushContent($WikiTheme->linkExistingWikiWord($wikipage, $sep . $last_part,
134 $link->pushContent($WikiTheme->linkUnknownWikiWord($wikipage, $sep . $last_part));
139 return $WikiTheme->linkExistingWikiWord($wikipage, $label, $version);
141 elseif ($type == 'if_known') {
142 if (!$label && isa($wikipage, 'WikiPageName'))
143 $label = $wikipage->shortName;
144 return HTML($label ? $label : $pagename);
147 return $WikiTheme->linkUnknownWikiWord($wikipage, $label);
156 * This is a convenience function.
158 * @param $action string
160 * <dt>[action]</dt><dd>Perform action (e.g. 'edit') on the selected page.</dd>
161 * <dt>[ActionPage]</dt><dd>Run the actionpage (e.g. 'BackLinks') on the selected page.</dd>
162 * <dt>'submit:'[name]</dt><dd>Make a form submission button with the given name.
163 * ([name] can be blank for a nameless submit button.)</dd>
164 * <dt>a hash</dt><dd>Query args for the action. E.g.<pre>
165 * array('action' => 'diff', 'previous' => 'author')
169 * @param $label string
170 * A label for the button. If ommited, a suitable default (based on the valued of $action)
173 * @param $page_or_rev mixed
174 * Which page (& version) to perform the action on.
176 * <dt>A string</dt><dd>The pagename.</dd>
177 * <dt>A WikiDB_Page object</dt><dd>The page.</dd>
178 * <dt>A WikiDB_PageRevision object</dt><dd>A specific version of the page.</dd>
180 * ($Page_or_rev is ignored for submit buttons.)
182 function Button ($action, $label = false, $page_or_rev = false, $options = false) {
185 if (!is_array($action) && preg_match('/^submit:(.*)/', $action, $m))
186 return $WikiTheme->makeSubmitButton($label, $m[1], $page_or_rev, $options);
188 return $WikiTheme->makeActionButton($action, $label, $page_or_rev, $options);
192 var $HTML_DUMP_SUFFIX = '';
193 var $DUMP_MODE = false, $dumped_images, $dumped_css;
196 * noinit: Do not initialize unnecessary items in default_theme fallback twice.
198 function Theme ($theme_name = 'default', $noinit = false) {
199 $this->_name = $theme_name;
200 $this->_themes_dir = NormalizeLocalFileName("themes");
201 $this->_path = defined('PHPWIKI_DIR') ? NormalizeLocalFileName("") : "";
202 $this->_theme = "themes/$theme_name";
204 if ($theme_name != 'default')
205 $this->_default_theme = new Theme('default',true);
208 $this->addMoreHeaders(JavaScript("var data_path = '". DATA_PATH ."'\n"
209 ."var pagename = '". $GLOBALS['request']->getArg('pagename') ."'\n"
210 ."var stylepath = '". DATA_PATH . '/'.$this->_theme."/'\n"));
212 if ((is_object($GLOBALS['request']) // guard against unittests
213 and $GLOBALS['request']->getPref('doubleClickEdit'))
214 or ENABLE_DOUBLECLICKEDIT)
215 $this->initDoubleClickEdit();
217 // will be replaced by acDropDown
218 if (ENABLE_LIVESEARCH) { // by bitflux.ch
219 $this->initLiveSearch();
221 // replaces external LiveSearch
222 if (defined("ENABLE_ACDROPDOWN") and ENABLE_ACDROPDOWN) {
223 $this->initMoAcDropDown();
225 $this->_css = array();
228 function file ($file) {
229 return $this->_path . "$this->_theme/$file";
232 function _findFile ($file, $missing_okay = false) {
233 if (file_exists($this->file($file)))
234 return "$this->_theme/$file";
236 // FIXME: this is a short-term hack. Delete this after all files
237 // get moved into themes/...
238 if (file_exists($this->_path . $file))
241 if (isset($this->_default_theme)) {
242 return $this->_default_theme->_findFile($file, $missing_okay);
244 else if (!$missing_okay) {
245 if (DEBUG & function_exists('debug_backtrace')) { // >= 4.3.0
246 echo "<pre>", printSimpleTrace(debug_backtrace()), "</pre>\n";
248 trigger_error("$this->_theme/$file: not found", E_USER_NOTICE);
253 function _findData ($file, $missing_okay = false) {
254 $path = $this->_findFile($file, $missing_okay);
258 if (defined('DATA_PATH'))
259 return DATA_PATH . "/$path";
263 ////////////////////////////////////////////////////////////////
265 // Date and Time formatting
267 ////////////////////////////////////////////////////////////////
269 // Note: Windows' implemetation of strftime does not include certain
270 // format specifiers, such as %e (for date without leading zeros). In
272 // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_strftime.2c_.wcsftime.asp
273 // As a result, we have to use %d, and strip out leading zeros ourselves.
275 var $_dateFormat = "%B %d, %Y";
276 var $_timeFormat = "%I:%M %p";
278 var $_showModTime = true;
281 * Set format string used for dates.
283 * @param $fs string Format string for dates.
285 * @param $show_mod_time bool If true (default) then times
286 * are included in the messages generated by getLastModifiedMessage(),
287 * otherwise, only the date of last modification will be shown.
289 function setDateFormat ($fs, $show_mod_time = true) {
290 $this->_dateFormat = $fs;
291 $this->_showModTime = $show_mod_time;
295 * Set format string used for times.
297 * @param $fs string Format string for times.
299 function setTimeFormat ($fs) {
300 $this->_timeFormat = $fs;
306 * Any time zone offset specified in the users preferences is
307 * taken into account by this method.
309 * @param $time_t integer Unix-style time.
311 * @return string The date.
313 function formatDate ($time_t) {
316 $offset_time = $time_t + 3600 * $request->getPref('timeOffset');
317 // strip leading zeros from date elements (ie space followed by zero)
318 return preg_replace('/ 0/', ' ',
319 strftime($this->_dateFormat, $offset_time));
325 * Any time zone offset specified in the users preferences is
326 * taken into account by this method.
328 * @param $time_t integer Unix-style time.
330 * @return string The time.
332 function formatTime ($time_t) {
333 //FIXME: make 24-hour mode configurable?
335 $offset_time = $time_t + 3600 * $request->getPref('timeOffset');
336 return preg_replace('/^0/', ' ',
337 strtolower(strftime($this->_timeFormat, $offset_time)));
341 * Format a date and time.
343 * Any time zone offset specified in the users preferences is
344 * taken into account by this method.
346 * @param $time_t integer Unix-style time.
348 * @return string The date and time.
350 function formatDateTime ($time_t) {
351 return $this->formatDate($time_t) . ' ' . $this->formatTime($time_t);
355 * Format a (possibly relative) date.
357 * If enabled in the users preferences, this method might
358 * return a relative day (e.g. 'Today', 'Yesterday').
360 * Any time zone offset specified in the users preferences is
361 * taken into account by this method.
363 * @param $time_t integer Unix-style time.
365 * @return string The day.
367 function getDay ($time_t) {
370 if ($request->getPref('relativeDates') && ($date = $this->_relativeDay($time_t))) {
371 return ucfirst($date);
373 return $this->formatDate($time_t);
377 * Format the "last modified" message for a page revision.
379 * @param $revision object A WikiDB_PageRevision object.
381 * @param $show_version bool Should the page version number
382 * be included in the message. (If this argument is omitted,
383 * then the version number will be shown only iff the revision
384 * is not the current one.
386 * @return string The "last modified" message.
388 function getLastModifiedMessage ($revision, $show_version = 'auto') {
390 if (!$revision) return '';
392 // dates >= this are considered invalid.
393 if (! defined('EPOCH'))
394 define('EPOCH', 0); // seconds since ~ January 1 1970
396 $mtime = $revision->get('mtime');
398 return fmt("Never edited");
400 if ($show_version == 'auto')
401 $show_version = !$revision->isCurrent();
403 if ($request->getPref('relativeDates') && ($date = $this->_relativeDay($mtime))) {
404 if ($this->_showModTime)
405 $date = sprintf(_("%s at %s"),
406 $date, $this->formatTime($mtime));
409 return fmt("Version %s, saved %s", $revision->getVersion(), $date);
411 return fmt("Last edited %s", $date);
414 if ($this->_showModTime)
415 $date = $this->formatDateTime($mtime);
417 $date = $this->formatDate($mtime);
420 return fmt("Version %s, saved on %s", $revision->getVersion(), $date);
422 return fmt("Last edited on %s", $date);
425 function _relativeDay ($time_t) {
428 if (is_numeric($request->getPref('timeOffset')))
429 $offset = 3600 * $request->getPref('timeOffset');
433 $now = time() + $offset;
434 $today = localtime($now, true);
435 $time = localtime($time_t + $offset, true);
437 if ($time['tm_yday'] == $today['tm_yday'] && $time['tm_year'] == $today['tm_year'])
440 // Note that due to daylight savings chages (and leap seconds), $now minus
441 // 24 hours is not guaranteed to be yesterday.
442 $yesterday = localtime($now - (12 + $today['tm_hour']) * 3600, true);
443 if ($time['tm_yday'] == $yesterday['tm_yday']
444 and $time['tm_year'] == $yesterday['tm_year'])
445 return _("yesterday");
451 * Format the "Author" and "Owner" messages for a page revision.
453 function getOwnerMessage ($page) {
454 if (!ENABLE_PAGEPERM or !class_exists("PagePermission"))
456 $dbi =& $GLOBALS['request']->_dbi;
457 $owner = $page->getOwner();
460 if ( mayAccessPage('change',$page->getName()) )
461 return fmt("Owner: %s", $this->makeActionButton(array('action'=>_("chown"),
462 's' => $page->getName()),
465 if ( $dbi->isWikiPage($owner) )
466 return fmt("Owner: %s", WikiLink($owner));
468 return fmt("Owner: %s", '"'.$owner.'"');
472 /* New behaviour: (by Matt Brown)
473 Prefer author (name) over internal author_id (IP) */
474 function getAuthorMessage ($revision) {
475 if (!$revision) return '';
476 $dbi =& $GLOBALS['request']->_dbi;
477 $author = $revision->get('author');
478 if (!$author) $author = $revision->get('author_id');
479 if (!$author) return '';
480 if ( $dbi->isWikiPage($author) ) {
481 return fmt("by %s", WikiLink($author));
483 return fmt("by %s", '"'.$author.'"');
487 ////////////////////////////////////////////////////////////////
489 // Hooks for other formatting
491 ////////////////////////////////////////////////////////////////
493 //FIXME: PHP 4.1 Warnings
494 //lib/Theme.php:84: Notice[8]: The call_user_method() function is deprecated,
495 //use the call_user_func variety with the array(&$obj, "method") syntax instead
497 function getFormatter ($type, $format) {
498 $method = strtolower("get${type}Formatter");
499 if (method_exists($this, $method))
500 return $this->{$method}($format);
504 ////////////////////////////////////////////////////////////////
508 ////////////////////////////////////////////////////////////////
510 var $_autosplitWikiWords = false;
511 function setAutosplitWikiWords($autosplit=true) {
512 $this->_autosplitWikiWords = $autosplit ? true : false;
515 function maybeSplitWikiWord ($wikiword) {
516 if ($this->_autosplitWikiWords)
517 return SplitPagename($wikiword);
522 var $_anonEditUnknownLinks = true;
523 function setAnonEditUnknownLinks($anonedit=true) {
524 $this->_anonEditUnknownLinks = $anonedit ? true : false;
527 function linkExistingWikiWord($wikiword, $linktext = '', $version = false) {
530 if ($version !== false and !$this->HTML_DUMP_SUFFIX)
531 $url = WikiURL($wikiword, array('version' => $version));
533 $url = WikiURL($wikiword);
535 // Extra steps for dumping page to an html file.
536 if ($this->HTML_DUMP_SUFFIX) {
537 $url = preg_replace('/^\./', '%2e', $url); // dot pages
540 $link = HTML::a(array('href' => $url));
542 if (isa($wikiword, 'WikiPageName'))
543 $default_text = $wikiword->shortName;
545 $default_text = $wikiword;
547 if (!empty($linktext)) {
548 $link->pushContent($linktext);
549 $link->setAttr('class', 'named-wiki');
550 $link->setAttr('title', $this->maybeSplitWikiWord($default_text));
553 $link->pushContent($this->maybeSplitWikiWord($default_text));
554 $link->setAttr('class', 'wiki');
556 if ($request->getArg('frame'))
557 $link->setAttr('target', '_top');
561 function linkUnknownWikiWord($wikiword, $linktext = '') {
564 // Get rid of anchors on unknown wikiwords
565 if (isa($wikiword, 'WikiPageName')) {
566 $default_text = $wikiword->shortName;
567 $wikiword = $wikiword->name;
570 $default_text = $wikiword;
573 if ($this->DUMP_MODE) { // HTML, PDF or XML
574 $link = HTML::u( empty($linktext) ? $wikiword : $linktext);
575 $link->addTooltip(sprintf(_("Empty link to: %s"), $wikiword));
576 $link->setAttr('class', empty($linktext) ? 'wikiunknown' : 'named-wikiunknown');
579 // if AnonEditUnknownLinks show "?" only users which are allowed to edit this page
580 if (! $this->_anonEditUnknownLinks and
581 ( ! $request->_user->isSignedIn()
582 or ! mayAccessPage('edit', $request->getArg('pagename'))))
584 $text = HTML::span( empty($linktext) ? $wikiword : $linktext);
585 $text->setAttr('class', empty($linktext) ? 'wikiunknown' : 'named-wikiunknown');
588 $url = WikiURL($wikiword, array('action' => 'create'));
589 $button = $this->makeButton('?', $url);
590 $button->addTooltip(sprintf(_("Create: %s"), $wikiword));
594 $link = HTML::span();
595 if (!empty($linktext)) {
596 $link->pushContent(HTML::u($linktext));
597 $link->setAttr('class', 'named-wikiunknown');
600 $link->pushContent(HTML::u($this->maybeSplitWikiWord($default_text)));
601 $link->setAttr('class', 'wikiunknown');
603 if (!isa($button, "ImageButton"))
604 $button->setAttr('rel', 'nofollow');
605 $link->pushContent($button);
606 if ($request->getPref('googleLink')) {
607 $gbutton = $this->makeButton('G', "http://www.google.com/search?q="
608 . urlencode($wikiword));
609 $gbutton->addTooltip(sprintf(_("Google:%s"), $wikiword));
610 $link->pushContent($gbutton);
612 if ($request->getArg('frame'))
613 $link->setAttr('target', '_top');
618 function linkBadWikiWord($wikiword, $linktext = '') {
619 global $ErrorManager;
624 elseif (isa($wikiword, 'WikiPageName')) {
625 $text = $wikiword->shortName;
631 if (isa($wikiword, 'WikiPageName'))
632 $message = $wikiword->getWarnings();
634 $message = sprintf(_("'%s': Bad page name"), $wikiword);
635 $ErrorManager->warning($message);
637 return HTML::span(array('class' => 'badwikiword'), $text);
640 ////////////////////////////////////////////////////////////////
644 ////////////////////////////////////////////////////////////////
645 var $_imageAliases = array();
646 var $_imageAlt = array();
650 * (To disable an image, alias the image to <code>false</code>.
652 function addImageAlias ($alias, $image_name) {
653 // fall back to the PhpWiki-supplied image if not found
654 if ((empty($this->_imageAliases[$alias])
655 and $this->_findFile("images/$image_name", true))
656 or $image_name === false)
657 $this->_imageAliases[$alias] = $image_name;
660 function addImageAlt ($alias, $alt_text) {
661 $this->_imageAlt[$alias] = $alt_text;
663 function getImageAlt ($alias) {
664 return $this->_imageAlt[$alias];
667 function getImageURL ($image) {
668 $aliases = &$this->_imageAliases;
670 if (isset($aliases[$image])) {
671 $image = $aliases[$image];
676 // If not extension, default to .png.
677 if (!preg_match('/\.\w+$/', $image))
680 // FIXME: this should probably be made to fall back
681 // automatically to .gif, .jpg.
682 // Also try .gif before .png if browser doesn't like png.
684 $path = $this->_findData("images/$image", 'missing okay');
685 if (!$path) // search explicit images/ or button/ links also
686 $path = $this->_findData("$image", 'missing okay');
688 if ($this->DUMP_MODE) {
689 if (empty($this->dumped_images)) $this->dumped_images = array();
690 $path = "images/". basename($path);
691 if (!in_array($path,$this->dumped_images))
692 $this->dumped_images[] = $path;
697 function setLinkIcon($proto, $image = false) {
701 $this->_linkIcons[$proto] = $image;
704 function getLinkIconURL ($proto) {
705 $icons = &$this->_linkIcons;
706 if (!empty($icons[$proto]))
707 return $this->getImageURL($icons[$proto]);
708 elseif (!empty($icons['*']))
709 return $this->getImageURL($icons['*']);
713 var $_linkIcon = 'front'; // or 'after' or 'no'.
714 // maybe also 'spanall': there is a scheme currently in effect with front, which
715 // spans the icon only to the first, to let the next words wrap on line breaks
716 // see stdlib.php:PossiblyGlueIconToText()
717 function getLinkIconAttr () {
718 return $this->_linkIcon;
720 function setLinkIconAttr ($where) {
721 $this->_linkIcon = $where;
724 function addButtonAlias ($text, $alias = false) {
725 $aliases = &$this->_buttonAliases;
728 $aliases = array_merge($aliases, $text);
729 elseif ($alias === false)
730 unset($aliases[$text]);
732 $aliases[$text] = $alias;
735 function getButtonURL ($text) {
736 $aliases = &$this->_buttonAliases;
737 if (isset($aliases[$text]))
738 $text = $aliases[$text];
740 $qtext = urlencode($text);
741 $url = $this->_findButton("$qtext.png");
742 if ($url && strstr($url, '%')) {
743 $url = preg_replace('|([^/]+)$|e', 'urlencode("\\1")', $url);
745 if (!$url) {// Jeff complained about png not supported everywhere.
746 // This was not PC until 2005.
747 $url = $this->_findButton("$qtext.gif");
748 if ($url && strstr($url, '%')) {
749 $url = preg_replace('|([^/]+)$|e', 'urlencode("\\1")', $url);
752 if ($url and $this->DUMP_MODE) {
753 if (empty($this->dumped_buttons)) $this->dumped_buttons = array();
755 if (defined('DATA_PATH'))
756 $file = substr($url,strlen(DATA_PATH)+1);
757 $url = "images/buttons/".basename($file);
758 if (!array_key_exists($text, $this->dumped_buttons))
759 $this->dumped_buttons[$text] = $file;
764 function _findButton ($button_file) {
765 if (empty($this->_button_path))
766 $this->_button_path = $this->_getButtonPath();
768 foreach ($this->_button_path as $dir) {
769 if ($path = $this->_findData("$dir/$button_file", 1))
775 function _getButtonPath () {
776 $button_dir = $this->_findFile("buttons");
777 $path_dir = $this->_path . $button_dir;
778 if (!file_exists($path_dir) || !is_dir($path_dir))
780 $path = array($button_dir);
782 $dir = dir($path_dir);
783 while (($subdir = $dir->read()) !== false) {
784 if ($subdir[0] == '.')
786 if ($subdir == 'CVS')
788 if (is_dir("$path_dir/$subdir"))
789 $path[] = "$button_dir/$subdir";
792 // add default buttons
793 $path[] = "themes/default/buttons";
794 $path_dir = $this->_path . "themes/default/buttons";
795 $dir = dir($path_dir);
796 while (($subdir = $dir->read()) !== false) {
797 if ($subdir[0] == '.')
799 if ($subdir == 'CVS')
801 if (is_dir("$path_dir/$subdir"))
802 $path[] = "themes/default/buttons/$subdir";
809 ////////////////////////////////////////////////////////////////
813 ////////////////////////////////////////////////////////////////
815 function makeButton ($text, $url, $class = false, $options = false) {
816 // FIXME: don't always try for image button?
818 // Special case: URLs like 'submit:preview' generate form
819 // submission buttons.
820 if (preg_match('/^submit:(.*)$/', $url, $m))
821 return $this->makeSubmitButton($text, $m[1], $class, $options);
823 $imgurl = $this->getButtonURL($text);
825 return new ImageButton($text, $url, $class, $imgurl, $options);
827 return new Button($this->maybeSplitWikiWord($text), $url,
831 function makeSubmitButton ($text, $name, $class = false, $options = false) {
832 $imgurl = $this->getButtonURL($text);
835 return new SubmitImageButton($text, $name, $class, $imgurl, $options);
837 return new SubmitButton($text, $name, $class, $options);
841 * Make button to perform action.
843 * This constructs a button which performs an action on the
844 * currently selected version of the current page.
845 * (Or anotherpage or version, if you want...)
847 * @param $action string The action to perform (e.g. 'edit', 'lock').
848 * This can also be the name of an "action page" like 'LikePages'.
849 * Alternatively you can give a hash of query args to be applied
852 * @param $label string Textual label for the button. If left empty,
853 * a suitable name will be guessed.
855 * @param $page_or_rev mixed The page to link to. This can be
856 * given as a string (the page name), a WikiDB_Page object, or as
857 * WikiDB_PageRevision object. If given as a WikiDB_PageRevision
858 * object, the button will link to a specific version of the
859 * designated page, otherwise the button links to the most recent
860 * version of the page.
862 * @return object A Button object.
864 function makeActionButton ($action, $label = false, $page_or_rev = false, $options = false) {
865 extract($this->_get_name_and_rev($page_or_rev));
867 if (is_array($action)) {
869 $action = isset($attr['action']) ? $attr['action'] : 'browse';
872 $attr['action'] = $action;
874 $class = is_safe_action($action) ? 'wikiaction' : 'wikiadmin';
876 $label = $this->_labelForAction($action);
879 $attr['version'] = $version;
881 if ($action == 'browse')
882 unset($attr['action']);
884 $options = $this->fixAccesskey($options);
886 return $this->makeButton($label, WikiURL($pagename, $attr), $class, $options);
889 function tooltipAccessKeyPrefix() {
890 static $tooltipAccessKeyPrefix = null;
891 if ($tooltipAccessKeyPrefix) return $tooltipAccessKeyPrefix;
893 $tooltipAccessKeyPrefix = 'alt';
894 if (isBrowserOpera()) $tooltipAccessKeyPrefix = 'shift-esc';
895 elseif (isBrowserSafari() or browserDetect("Mac") or isBrowserKonqueror())
896 $tooltipAccessKeyPrefix = 'ctrl';
897 // ff2 win and x11 only
898 elseif ((browserDetect("firefox/2") or browserDetect("minefield/3") or browserDetect("SeaMonkey/1.1"))
899 and ((browserDetect("windows") or browserDetect("x11"))))
900 $tooltipAccessKeyPrefix = 'alt-shift';
901 return $tooltipAccessKeyPrefix;
904 /** Define the accesskey in the title only, with ending [p] or [alt-p].
905 * This fixes the prefix in the title and sets the accesskey.
907 function fixAccesskey($attrs) {
908 if (!empty($attrs['title']) and preg_match("/\[(alt-)?(.)\]$/", $attrs['title'], $m))
910 if (empty($attrs['accesskey'])) $attrs['accesskey'] = $m[2];
911 // firefox 'alt-shift', MSIE: 'alt', ... see wikibits.js
912 $attrs['title'] = preg_replace("/\[(alt-)?(.)\]$/", "[".$this->tooltipAccessKeyPrefix()."-\\2]", $attrs['title']);
918 * Make a "button" which links to a wiki-page.
920 * These are really just regular WikiLinks, possibly
921 * disguised (e.g. behind an image button) by the theme.
923 * This method should probably only be used for links
924 * which appear in page navigation bars, or similar places.
926 * Use linkExistingWikiWord, or LinkWikiWord for normal links.
928 * @param $page_or_rev mixed The page to link to. This can be
929 * given as a string (the page name), a WikiDB_Page object, or as
930 * WikiDB_PageRevision object. If given as a WikiDB_PageRevision
931 * object, the button will link to a specific version of the
932 * designated page, otherwise the button links to the most recent
933 * version of the page.
935 * @return object A Button object.
937 function makeLinkButton ($page_or_rev, $label = false, $action = false) {
938 extract($this->_get_name_and_rev($page_or_rev));
940 $args = $version ? array('version' => $version) : false;
941 if ($action) $args['action'] = $action;
943 return $this->makeButton($label ? $label : $pagename,
944 WikiURL($pagename, $args), 'wiki');
947 function _get_name_and_rev ($page_or_rev) {
950 if (empty($page_or_rev)) {
952 $pagename = $request->getArg("pagename");
953 $version = $request->getArg("version");
955 elseif (is_object($page_or_rev)) {
956 if (isa($page_or_rev, 'WikiDB_PageRevision')) {
958 $page = $rev->getPage();
959 if (!$rev->isCurrent()) $version = $rev->getVersion();
962 $page = $page_or_rev;
964 $pagename = $page->getName();
966 elseif (is_numeric($page_or_rev)) {
967 $version = $page_or_rev;
970 $pagename = (string) $page_or_rev;
972 return compact('pagename', 'version');
975 function _labelForAction ($action) {
977 case 'edit': return _("Edit");
978 case 'diff': return _("Diff");
979 case 'logout': return _("Sign Out");
980 case 'login': return _("Sign In");
981 case 'lock': return _("Lock Page");
982 case 'unlock': return _("Unlock Page");
983 case 'remove': return _("Remove Page");
985 // I don't think the rest of these actually get used.
987 // 'upload' 'dumpserial' 'loadfile' 'zip'
989 return gettext(ucfirst($action));
993 //----------------------------------------------------------------
994 var $_buttonSeparator = "\n | ";
996 function setButtonSeparator($separator) {
997 $this->_buttonSeparator = $separator;
1000 function getButtonSeparator() {
1001 return $this->_buttonSeparator;
1005 ////////////////////////////////////////////////////////////////
1011 // Based on testing with Galeon 1.2.7 (Mozilla 1.2):
1012 // Automatic media-based style selection (via <link> tags) only
1013 // seems to work for the default style, not for alternate styles.
1017 // <link rel="stylesheet" type="text/css" href="phpwiki.css" />
1018 // <link rel="stylesheet" type="text/css" href="phpwiki-printer.css" media="print" />
1020 // works to make it so that the printer style sheet get used
1021 // automatically when printing (or print-previewing) a page
1022 // (but when only when the default style is selected.)
1026 // <link rel="alternate stylesheet" title="Modern"
1027 // type="text/css" href="phpwiki-modern.css" />
1028 // <link rel="alternate stylesheet" title="Modern"
1029 // type="text/css" href="phpwiki-printer.css" media="print" />
1031 // Result in two "Modern" choices when trying to select alternate style.
1032 // If one selects the first of those choices, one gets phpwiki-modern
1033 // both when browsing and printing. If one selects the second "Modern",
1034 // one gets no CSS when browsing, and phpwiki-printer when printing.
1039 // We should probably move to doing the media based style
1040 // switching in the CSS files themselves using, e.g.:
1042 // @import url(print.css) print;
1044 ////////////////////////////////////////////////////////////////
1046 function _CSSlink($title, $css_file, $media, $is_alt = false) {
1047 // Don't set title on default style. This makes it clear to
1048 // the user which is the default (i.e. most supported) style.
1049 if ($is_alt and isBrowserKonqueror())
1051 $link = HTML::link(array('rel' => $is_alt ? 'alternate stylesheet' : 'stylesheet',
1052 'type' => 'text/css',
1053 'charset' => $GLOBALS['charset'],
1054 'href' => $this->_findData($css_file)));
1056 $link->setAttr('title', $title);
1059 $link->setAttr('media', $media);
1060 if ($this->DUMP_MODE) {
1061 if (empty($this->dumped_css)) $this->dumped_css = array();
1062 if (!in_array($css_file,$this->dumped_css)) $this->dumped_css[] = $css_file;
1063 $link->setAttr('href', basename($link->getAttr('href')));
1069 /** Set default CSS source for this theme.
1071 * To set styles to be used for different media, pass a
1072 * hash for the second argument, e.g.
1074 * $theme->setDefaultCSS('default', array('' => 'normal.css',
1075 * 'print' => 'printer.css'));
1077 * If you call this more than once, the last one called takes
1078 * precedence as the default style.
1080 * @param string $title Name of style (currently ignored, unless
1081 * you call this more than once, in which case, some of the style
1082 * will become alternate (rather than default) styles, and then their
1083 * titles will be used.
1085 * @param mixed $css_files Name of CSS file, or hash containing a mapping
1086 * between media types and CSS file names. Use a key of '' (the empty string)
1087 * to set the default CSS for non-specified media. (See above for an example.)
1089 function setDefaultCSS ($title, $css_files) {
1090 if (!is_array($css_files))
1091 $css_files = array('' => $css_files);
1092 // Add to the front of $this->_css
1093 unset($this->_css[$title]);
1094 $this->_css = array_merge(array($title => $css_files), $this->_css);
1097 /** Set alternate CSS source for this theme.
1099 * @param string $title Name of style.
1100 * @param string $css_files Name of CSS file.
1102 function addAlternateCSS ($title, $css_files) {
1103 if (!is_array($css_files))
1104 $css_files = array('' => $css_files);
1105 $this->_css[$title] = $css_files;
1109 * @return string HTML for CSS.
1111 function getCSS () {
1114 foreach ($this->_css as $title => $css_files) {
1115 ksort($css_files); // move $css_files[''] to front.
1116 foreach ($css_files as $media => $css_file) {
1117 if (!empty($this->DUMP_MODE)) {
1118 if ($media == 'print')
1119 $css[] = $this->_CSSlink($title, $css_file, '', $is_alt);
1121 $css[] = $this->_CSSlink($title, $css_file, $media, $is_alt);
1130 function findTemplate ($name) {
1131 if ($tmp = $this->_findFile("templates/$name.tmpl", 1))
1132 return $this->_path . $tmp;
1134 $f1 = $this->file("templates/$name.tmpl");
1135 //trigger_error("findTemplate($name) pwd: ".getcwd(), E_USER_ERROR);
1136 if (isset($this->_default_theme)) {
1137 $f2 = $this->_default_theme->file("templates/$name.tmpl");
1138 //trigger_error("$f1 nor $f2 found", E_USER_ERROR);
1140 trigger_error("$f1 not found", E_USER_ERROR);
1145 var $_MoreHeaders = array();
1146 function addMoreHeaders ($element) {
1147 $this->_MoreHeaders[] = $element;
1148 if (!empty($this->_headers_printed) and $this->_headers_printed) {
1149 trigger_error(_("Some action(page) wanted to add more headers, but they were already printed.")
1150 ."\n". $element->asXML(),
1156 * Singleton. Only called once, by the head template. See the warning above.
1158 function getMoreHeaders () {
1159 // actionpages cannot add headers, because recursive template expansion
1160 // already expanded the head template before.
1161 $this->_headers_printed = 1;
1162 if (empty($this->_MoreHeaders))
1165 //$out = "<!-- More Headers -->\n";
1166 foreach ($this->_MoreHeaders as $h) {
1168 $out .= printXML($h);
1175 var $_MoreAttr = array();
1176 // new arg: named elements to be able to remove them. such as DoubleClickEdit for htmldumps
1177 function addMoreAttr ($tag, $name, $element) {
1178 // protect from duplicate attr (body jscript: themes, prefs, ...)
1179 static $_attr_cache = array();
1180 $hash = md5($tag."/".$element);
1181 if (!empty($_attr_cache[$hash])) return;
1182 $_attr_cache[$hash] = 1;
1184 if (empty($this->_MoreAttr) or !is_array($this->_MoreAttr[$tag]))
1185 $this->_MoreAttr[$tag] = array($name => $element);
1187 $this->_MoreAttr[$tag][$name] = $element;
1190 function getMoreAttr ($tag) {
1191 if (empty($this->_MoreAttr[$tag]))
1194 foreach ($this->_MoreAttr[$tag] as $name => $element) {
1195 if (is_object($element))
1196 $out .= printXML($element);
1204 * Common Initialisations
1208 * The ->load() method replaces the formerly global code in themeinfo.php.
1209 * Without this you would not be able to derive from other themes.
1213 // CSS file defines fonts, colors and background images for this
1214 // style. The companion '*-heavy.css' file isn't defined, it's just
1215 // expected to be in the same directory that the base style is in.
1217 // This should result in phpwiki-printer.css being used when
1218 // printing or print-previewing with style "PhpWiki" or "MacOSX" selected.
1219 $this->setDefaultCSS('PhpWiki',
1220 array('' => 'phpwiki.css',
1221 'print' => 'phpwiki-printer.css'));
1223 // This allows one to manually select "Printer" style (when browsing page)
1224 // to see what the printer style looks like.
1225 $this->addAlternateCSS(_("Printer"), 'phpwiki-printer.css', 'print, screen');
1226 $this->addAlternateCSS(_("Top & bottom toolbars"), 'phpwiki-topbottombars.css');
1227 $this->addAlternateCSS(_("Modern"), 'phpwiki-modern.css');
1229 if (isBrowserIE()) {
1230 $this->addMoreHeaders($this->_CSSlink(0,
1231 $this->_findFile('IEFixes.css'),'all'));
1232 $this->addMoreHeaders("\n");
1236 * The logo image appears on every page and links to the HomePage.
1238 $this->addImageAlias('logo', WIKI_NAME . 'Logo.png');
1240 $this->addImageAlias('search', 'search.png');
1243 * The Signature image is shown after saving an edited page. If this
1244 * is set to false then the "Thank you for editing..." screen will
1248 $this->addImageAlias('signature', WIKI_NAME . "Signature.png");
1249 // Uncomment this next line to disable the signature.
1250 //$this->addImageAlias('signature', false);
1255 $this->setLinkIcon('http');
1256 $this->setLinkIcon('https');
1257 $this->setLinkIcon('ftp');
1258 $this->setLinkIcon('mailto');
1259 $this->setLinkIcon('interwiki');
1260 $this->setLinkIcon('wikiuser');
1261 $this->setLinkIcon('*', 'url');
1263 $this->setButtonSeparator("\n | ");
1266 * WikiWords can automatically be split by inserting spaces between
1267 * the words. The default is to leave WordsSmashedTogetherLikeSo.
1269 $this->setAutosplitWikiWords(false);
1272 * Layout improvement with dangling links for mostly closed wiki's:
1273 * If false, only users with edit permissions will be presented the
1274 * special wikiunknown class with "?" and Tooltip.
1275 * If true (default), any user will see the ?, but will be presented
1276 * the PrintLoginForm on a click.
1278 //$this->setAnonEditUnknownLinks(false);
1281 * You may adjust the formats used for formatting dates and times
1282 * below. (These examples give the default formats.)
1283 * Formats are given as format strings to PHP strftime() function See
1284 * http://www.php.net/manual/en/function.strftime.php for details.
1285 * Do not include the server's zone (%Z), times are converted to the
1288 * Suggestion for french:
1289 * $this->setDateFormat("%A %e %B %Y");
1290 * $this->setTimeFormat("%H:%M:%S");
1291 * Suggestion for capable php versions, using the server locale:
1292 * $this->setDateFormat("%x");
1293 * $this->setTimeFormat("%X");
1295 //$this->setDateFormat("%B %d, %Y");
1296 //$this->setTimeFormat("%I:%M %p");
1299 * To suppress times in the "Last edited on" messages, give a
1300 * give a second argument of false:
1302 //$this->setDateFormat("%B %d, %Y", false);
1306 * Custom UserPreferences:
1307 * A list of name => _UserPreference class pairs.
1308 * Rationale: Certain themes should be able to extend the predefined list
1309 * of preferences. Display/editing is done in the theme specific userprefs.tmpl
1310 * but storage/sanification/update/... must be extended to the Get/SetPreferences methods.
1311 * See themes/wikilens/themeinfo.php
1313 //$this->customUserPreference();
1316 * Register custom PageList type and define custom PageList classes.
1317 * Rationale: Certain themes should be able to extend the predefined list
1318 * of pagelist types. E.g. certain plugins, like MostPopular might use
1319 * info=pagename,hits,rating
1320 * which displays the rating column whenever the wikilens theme is active.
1321 * See themes/wikilens/themeinfo.php
1323 //$this->addPageListColumn();
1328 * Custom UserPreferences:
1329 * A list of name => _UserPreference class pairs.
1330 * Rationale: Certain themes should be able to extend the predefined list
1331 * of preferences. Display/editing is done in the theme specific userprefs.tmpl
1332 * but storage/sanification/update/... must be extended to the Get/SetPreferences methods.
1333 * These values are just ignored if another theme is used.
1335 function customUserPreferences($array) {
1336 global $customUserPreferenceColumns; // FIXME: really a global?
1337 if (empty($customUserPreferenceColumns)) $customUserPreferenceColumns = array();
1338 //array('wikilens' => new _UserPreference_wikilens());
1339 foreach ($array as $field => $prefobj) {
1340 $customUserPreferenceColumns[$field] = $prefobj;
1344 /** addPageListColumn(array('rating' => new _PageList_Column_rating('rating', _("Rate"))))
1345 * Register custom PageList types for special themes, like
1346 * 'rating' for wikilens
1348 function addPageListColumn ($array) {
1349 global $customPageListColumns;
1350 if (empty($customPageListColumns)) $customPageListColumns = array();
1351 foreach ($array as $column => $obj) {
1352 $customPageListColumns[$column] = $obj;
1356 // Works only on action=browse. Patch #970004 by pixels
1357 // Usage: call $WikiTheme->initDoubleClickEdit() from theme init or
1358 // define ENABLE_DOUBLECLICKEDIT
1359 function initDoubleClickEdit() {
1360 if (!$this->HTML_DUMP_SUFFIX)
1361 $this->addMoreAttr('body', 'DoubleClickEdit', HTML::Raw(" ondblclick=\"url = document.URL; url2 = url; if (url.indexOf('?') != -1) url2 = url.slice(0, url.indexOf('?')); if ((url.indexOf('action') == -1) || (url.indexOf('action=browse') != -1)) document.location = url2 + '?action=edit';\""));
1364 // Immediate title search results via XMLHTML(HttpRequest)
1365 // by Bitflux GmbH, bitflux.ch. You need to install the livesearch.js seperately.
1366 // Google's or acdropdown is better.
1367 function initLiveSearch() {
1368 //subclasses of Sidebar will init this twice
1369 static $already = 0;
1370 if (!$this->HTML_DUMP_SUFFIX and !$already) {
1371 $this->addMoreAttr('body', 'LiveSearch',
1372 HTML::Raw(" onload=\"liveSearchInit()"));
1373 $this->addMoreHeaders(JavaScript('var liveSearchURI="'
1374 .WikiURL(_("TitleSearch"),false,true).'";'));
1375 $this->addMoreHeaders(JavaScript('', array
1376 ('src' => $this->_findData('livesearch.js'))));
1381 // Immediate title search results via XMLHttpRequest
1382 // using the shipped moacdropdown js-lib
1383 function initMoAcDropDown() {
1384 //subclasses of Sidebar will init this twice
1385 static $already = 0;
1386 if (!$this->HTML_DUMP_SUFFIX and !$already) {
1387 $dir = $this->_findData('moacdropdown');
1388 // if autocomplete_remote is used: (getobject2 also for calc. the showlist width)
1390 foreach (array("mobrowser.js","modomevent3.js","modomt.js",
1391 "modomext.js","getobject2.js","xmlextras.js") as $js)
1393 $this->addMoreHeaders(JavaScript('', array('src' => "$dir/js/$js")));
1395 $this->addMoreHeaders(JavaScript('', array('src' => "$dir/js/acdropdown.js")));
1397 $this->addMoreHeaders(JavaScript('', array('src' => DATA_PATH . "/themes/default/moacdropdown.js")));
1399 //$this->addMoreHeaders($this->_CSSlink(0,
1400 // $this->_findFile('moacdropdown/css/dropdown.css'), 'all'));
1401 $this->addMoreHeaders(HTML::style(" @import url( $dir/css/dropdown.css );\n"));
1403 // for local xmlrpc requests
1404 $xmlrpc_url = deduce_script_name();
1405 //if (1 or DATABASE_TYPE == 'dba')
1406 $xmlrpc_url = DATA_PATH . "/RPC2.php";
1407 if ((DEBUG & _DEBUG_REMOTE) and isset($_GET['start_debug']))
1408 $xmlrpc_url .= ("?start_debug=".$_GET['start_debug']);
1409 $this->addMoreHeaders(JavaScript("var xmlrpc_url = '$xmlrpc_url'"));
1415 function calendarLink($date = false) {
1416 return $this->calendarBase() . SUBPAGE_SEPARATOR .
1417 strftime("%Y-%m-%d", $date ? $date : time());
1420 function calendarBase() {
1421 static $UserCalPageTitle = false;
1424 if (!$UserCalPageTitle)
1425 $UserCalPageTitle = $request->_user->getId() .
1426 SUBPAGE_SEPARATOR . _("Calendar");
1427 if (!$UserCalPageTitle)
1428 $UserCalPageTitle = (BLOG_EMPTY_DEFAULT_PREFIX ? ''
1429 : ($request->_user->getId() . SUBPAGE_SEPARATOR)) . "Blog";
1430 return $UserCalPageTitle;
1433 function calendarInit($force = false) {
1434 $dbi = $GLOBALS['request']->getDbh();
1435 // display flat calender dhtml in the sidebar
1436 if ($force or $dbi->isWikiPage($this->calendarBase())) {
1437 $jslang = @$GLOBALS['LANG'];
1438 $this->addMoreHeaders
1441 $this->_findFile('jscalendar/calendar-phpwiki.css'), 'all'));
1442 $this->addMoreHeaders
1444 array('src' => $this->_findData('jscalendar/calendar'.(DEBUG?'':'_stripped').'.js'))));
1445 if (!($langfile = $this->_findData("jscalendar/lang/calendar-$jslang.js")))
1446 $langfile = $this->_findData("jscalendar/lang/calendar-en.js");
1447 $this->addMoreHeaders(JavaScript('',array('src' => $langfile)));
1448 $this->addMoreHeaders
1451 $this->_findData('jscalendar/calendar-setup'.(DEBUG?'':'_stripped').'.js'))));
1453 // Get existing date entries for the current user
1454 require_once("lib/TextSearchQuery.php");
1455 $iter = $dbi->titleSearch(new TextSearchQuery("^".$this->calendarBase().SUBPAGE_SEPARATOR, true, "auto"));
1456 $existing = array();
1457 while ($page = $iter->next()) {
1458 if ($page->exists())
1459 $existing[] = basename($page->_pagename);
1461 if (!empty($existing)) {
1462 $js_exist = '{"'.join('":1,"',$existing).'":1}';
1463 //var SPECIAL_DAYS = {"2004-05-11":1,"2004-05-12":1,"2004-06-01":1}
1464 $this->addMoreHeaders(JavaScript('
1465 // This table holds the existing calender entries for the current user
1466 // calculated from the database
1467 var SPECIAL_DAYS = '.$js_exist.';
1468 // This function returns true if the date exists in SPECIAL_DAYS
1469 function dateExists(date, y, m, d) {
1470 var year = date.getFullYear();
1472 m = m < 10 ? "0" + m : m; // integer, 0..11
1473 d = d < 10 ? "0" + d : d; // integer, 1..31
1474 var date = year+"-"+m+"-"+d;
1475 var exists = SPECIAL_DAYS[date];
1476 if (!exists) return false;
1479 // This is the actual date status handler.
1480 // Note that it receives the date object as well as separate
1481 // values of year, month and date.
1482 function dateStatusFunc(date, y, m, d) {
1483 if (dateExists(date, y, m, d)) return "existing";
1488 $this->addMoreHeaders(JavaScript('
1489 function dateStatusFunc(date, y, m, d) { return false;}'));
1494 ////////////////////////////////////////////////////////////////
1498 ////////////////////////////////////////////////////////////////
1500 /* Callback when a new user creates or edits a page */
1501 function CbNewUserEdit (&$request, $userid) {
1502 ; // i.e. create homepage with Template/UserPage
1505 /* Callback when a new user logs in.
1506 What is new? We only record changes, not logins.
1507 Should we track user actions?
1508 Let's say user without homepage.
1510 function CbNewUserLogin (&$request, $userid) {
1514 /* Callback when a user logs out
1516 function CbUserLogout (&$request, $userid) {
1524 * A class representing a clickable "button".
1526 * In it's simplest (default) form, a "button" is just a link associated
1527 * with some sort of wiki-action.
1529 class Button extends HtmlElement {
1532 * @param $text string The text for the button.
1533 * @param $url string The url (href) for the button.
1534 * @param $class string The CSS class for the button.
1535 * @param $options array Additional attributes for the <input> tag.
1537 function Button ($text, $url, $class=false, $options=false) {
1540 if (check_php_version(5)) {
1541 $this->_init('a', array('href' => $url));
1543 $this->__construct('a', array('href' => $url));
1546 $this->setAttr('class', $class);
1547 if ($request->getArg('frame'))
1548 $this->setAttr('target', '_top');
1549 if (!empty($options)) {
1550 foreach ($options as $key => $val)
1551 $this->setAttr($key, $val);
1553 // Google honors this
1554 if (in_array(strtolower($text), array('edit','create','diff','pdf'))
1555 and !$request->_user->isAuthenticated())
1556 $this->setAttr('rel', 'nofollow');
1557 $this->pushContent($GLOBALS['WikiTheme']->maybeSplitWikiWord($text));
1564 * A clickable image button.
1566 class ImageButton extends Button {
1569 * @param $text string The text for the button.
1570 * @param $url string The url (href) for the button.
1571 * @param $class string The CSS class for the button.
1572 * @param $img_url string URL for button's image.
1573 * @param $img_attr array Additional attributes for the <img> tag.
1575 function ImageButton ($text, $url, $class, $img_url, $img_attr=false) {
1576 $this->__construct('a', array('href' => $url));
1578 $this->setAttr('class', $class);
1579 // Google honors this
1580 if (in_array(strtolower($text), array('edit','create','diff','pdf'))
1581 and !$GLOBALS['request']->_user->isAuthenticated())
1582 $this->setAttr('rel', 'nofollow');
1584 if (!is_array($img_attr))
1585 $img_attr = array();
1586 $img_attr['src'] = $img_url;
1587 $img_attr['alt'] = $text;
1588 $img_attr['class'] = 'wiki-button';
1589 $img_attr['border'] = 0;
1590 $this->pushContent(HTML::img($img_attr));
1595 * A class representing a form <samp>submit</samp> button.
1597 class SubmitButton extends HtmlElement {
1600 * @param $text string The text for the button.
1601 * @param $name string The name of the form field.
1602 * @param $class string The CSS class for the button.
1603 * @param $options array Additional attributes for the <input> tag.
1605 function SubmitButton ($text, $name=false, $class=false, $options=false) {
1606 $this->__construct('input', array('type' => 'submit',
1609 $this->setAttr('name', $name);
1611 $this->setAttr('class', $class);
1612 if (!empty($options)) {
1613 foreach ($options as $key => $val)
1614 $this->setAttr($key, $val);
1622 * A class representing an image form <samp>submit</samp> button.
1624 class SubmitImageButton extends SubmitButton {
1627 * @param $text string The text for the button.
1628 * @param $name string The name of the form field.
1629 * @param $class string The CSS class for the button.
1630 * @param $img_url string URL for button's image.
1631 * @param $img_attr array Additional attributes for the <img> tag.
1633 function SubmitImageButton ($text, $name=false, $class=false, $img_url, $img_attr=false) {
1634 $this->__construct('input', array('type' => 'image',
1639 $this->setAttr('name', $name);
1641 $this->setAttr('class', $class);
1642 if (!empty($img_attr)) {
1643 foreach ($img_attr as $key => $val)
1644 $this->setAttr($key, $val);
1651 * A sidebar box with title and body, narrow fixed-width.
1652 * To represent abbrevated content of plugins, links or forms,
1653 * like "Getting Started", "Search", "Sarch Pagename",
1654 * "Login", "Menu", "Recent Changes", "Last comments", "Last Blogs"
1656 * ... See http://tikiwiki.org/
1660 * $menu = SidebarBox("Menu",HTML::dl(HTML::dt(...))); $menu->format();
1661 * $menu = PluginSidebarBox("RecentChanges",array('limit'=>10)); $menu->format();
1665 function SidebarBox($title, $body) {
1666 require_once('lib/WikiPlugin.php');
1667 $this->title = $title;
1668 $this->body = $body;
1671 return WikiPlugin::makeBox($this->title, $this->body);
1676 * A sidebar box for plugins.
1677 * Any plugin may provide a box($args=false, $request=false, $basepage=false)
1678 * method, with the help of WikiPlugin::makeBox()
1680 class PluginSidebarBox extends SidebarBox {
1682 var $_plugin, $_args = false, $_basepage = false;
1684 function PluginSidebarBox($name, $args = false, $basepage = false) {
1685 require_once("lib/WikiPlugin.php");
1687 $loader = new WikiPluginLoader();
1688 $plugin = $loader->getPlugin($name);
1690 return $loader->_error(sprintf(_("Plugin %s: undefined"),
1693 if (!method_exists($plugin, 'box')) {
1694 return $loader->_error(sprintf(_("%s: has no box method"),
1695 get_class($plugin)));
1697 $this->_plugin =& $plugin;
1698 $this->_args = $args ? $args : array();
1699 $this->_basepage = $basepage;
1702 function format($args = false) {
1703 return $this->_plugin->box($args ? array_merge($this->_args, $args) : $this->_args,
1704 $GLOBALS['request'],
1709 // Various boxes which are no plugins
1710 class RelatedLinksBox extends SidebarBox {
1711 function RelatedLinksBox($title = false, $body = '', $limit = 20) {
1713 $this->title = $title ? $title : _("Related Links");
1714 $this->body = HTML($body);
1715 $page = $request->getPage($request->getArg('pagename'));
1716 $revision = $page->getCurrentRevision();
1717 $page_content = $revision->getTransformedContent();
1718 //$cache = &$page->_wikidb->_cache;
1720 $sp = HTML::Raw('· ');
1721 foreach ($page_content->getWikiPageLinks() as $link) {
1722 $linkto = $link['linkto'];
1723 if (!$request->_dbi->isWikiPage($linkto)) continue;
1724 $this->body->pushContent($sp, WikiLink($linkto), HTML::br());
1726 if ($limit and $counter > $limit) continue;
1731 class RelatedExternalLinksBox extends SidebarBox {
1732 function RelatedExternalLinksBox($title = false, $body = '', $limit = 20) {
1734 $this->title = $title ? $title : _("External Links");
1735 $this->body = HTML($body);
1736 $page = $request->getPage($request->getArg('pagename'));
1737 $cache = &$page->_wikidb->_cache;
1739 $sp = HTML::Raw('· ');
1740 foreach ($cache->getWikiPageLinks() as $link) {
1741 $linkto = $link['linkto'];
1743 $this->body->pushContent($sp, WikiLink($linkto), HTML::br());
1745 if ($limit and $counter > $limit) continue;
1751 function listAvailableThemes() {
1752 $available_themes = array();
1753 $dir_root = 'themes';
1754 if (defined('PHPWIKI_DIR'))
1755 $dir_root = PHPWIKI_DIR . "/$dir_root";
1756 $dir = dir($dir_root);
1758 while($entry = $dir->read()) {
1759 if (is_dir($dir_root.'/'.$entry)
1760 and file_exists($dir_root.'/'.$entry.'/themeinfo.php'))
1762 array_push($available_themes, $entry);
1767 return $available_themes;
1770 function listAvailableLanguages() {
1771 $available_languages = array('en');
1772 $dir_root = 'locale';
1773 if (defined('PHPWIKI_DIR'))
1774 $dir_root = PHPWIKI_DIR . "/$dir_root";
1775 if ($dir = dir($dir_root)) {
1776 while($entry = $dir->read()) {
1777 if (is_dir($dir_root."/".$entry) and is_dir($dir_root.'/'.$entry.'/LC_MESSAGES'))
1779 array_push($available_languages, $entry);
1784 return $available_languages;
1787 // $Log: not supported by cvs2svn $
1788 // Revision 1.141 2007/06/02 18:24:30 rurban
1789 // Added accesskeys. Added js stylepath
1791 // Revision 1.140 2007/03/10 18:27:20 rurban
1792 // Patch 1677965 by Erwann Penet
1794 // Revision 1.138 2007/01/07 18:43:37 rurban
1795 // Remove fatals when no intermediate template was found. Deprecate subclasses of subthemes (blog of Sidebar). Warn about lost _MoreHeaders. $noinit: Do not initialize unnecessary items in default_theme fallback twice. Move over calendarInit from themes/Sidebar/themeinfo.php.
1797 // Revision 1.137 2007/01/02 13:19:23 rurban
1798 // add getobject2.js to acdropdown to calculate the sizes. add global xmlrpc_url for local xml requests (interface simplification). stabilize theme and language detection: require magic files there
1800 // Revision 1.136 2006/12/06 22:07:31 rurban
1801 // Add new Button argument to override any option.
1803 // Revision 1.135 2006/04/17 17:28:21 rurban
1804 // honor getWikiPageLinks change linkto=>relation
1806 // Revision 1.134 2006/03/19 16:24:38 rurban
1807 // fix syntax error with patch #1377650
1809 // Revision 1.133 2006/03/19 14:24:38 rurban
1810 // sf.net patch #1377650 by Matt Brown: Always prefer legible author name over author_id property
1812 // Revision 1.132 2005/07/24 09:51:22 rurban
1813 // guard doubleClickEdit for unittests, add AcDropDown support
1815 // Revision 1.131 2005/06/10 06:09:06 rurban
1816 // enable getPref('doubleClickEdit')
1818 // Revision 1.130 2005/05/06 16:43:35 rurban
1821 // Revision 1.129 2005/05/05 08:57:26 rurban
1822 // support action=revert
1824 // Revision 1.128 2005/04/23 11:23:49 rurban
1825 // improve semantics in the setAutosplitWikiWords method: switch to true if no args
1827 // Revision 1.127 2005/02/11 14:45:44 rurban
1828 // support ENABLE_LIVESEARCH, enable PDO sessions
1830 // Revision 1.126 2005/02/04 11:43:18 rurban
1833 // Revision 1.125 2005/02/03 05:09:56 rurban
1834 // livesearch.js support
1836 // Revision 1.124 2005/01/27 16:28:15 rurban
1837 // especially for Google: nofollow on unauthenticated edit,diff,create,pdf
1839 // Revision 1.123 2005/01/25 07:03:02 rurban
1840 // change addMoreAttr() to support named attr, to remove DoubleClickEdit for htmldumps
1842 // Revision 1.122 2005/01/21 11:51:22 rurban
1845 // Revision 1.121 2005/01/20 10:14:37 rurban
1846 // rel=nofollow on edit/create page links
1848 // Revision 1.120 2004/12/20 13:20:23 rurban
1849 // fix problem described in patch #1088131. SidebarBox may be used before lib/WikiPlugin.php
1852 // Revision 1.119 2004/12/14 21:38:12 rurban
1855 // Revision 1.118 2004/12/13 14:34:46 rurban
1856 // box parent method exists
1858 // Revision 1.117 2004/11/30 17:44:54 rurban
1859 // revisison neutral
1861 // Revision 1.116 2004/11/21 11:59:16 rurban
1862 // remove final \n to be ob_cache independent
1864 // Revision 1.115 2004/11/17 17:24:02 rurban
1865 // more verbose on fatal template not found
1867 // Revision 1.114 2004/11/11 18:31:26 rurban
1868 // add simple backtrace on such general failures to get at least an idea where
1870 // Revision 1.113 2004/11/09 17:11:04 rurban
1871 // * revert to the wikidb ref passing. there's no memory abuse there.
1872 // * use new wikidb->_cache->_id_cache[] instead of wikidb->_iwpcache, to effectively
1873 // store page ids with getPageLinks (GleanDescription) of all existing pages, which
1874 // are also needed at the rendering for linkExistingWikiWord().
1875 // pass options to pageiterator.
1876 // use this cache also for _get_pageid()
1877 // This saves about 8 SELECT count per page (num all pagelinks).
1878 // * fix passing of all page fields to the pageiterator.
1879 // * fix overlarge session data which got broken with the latest ACCESS_LOG_SQL changes
1881 // Revision 1.112 2004/11/03 16:50:31 rurban
1882 // some new defaults and constants, renamed USE_DOUBLECLICKEDIT to ENABLE_DOUBLECLICKEDIT
1884 // Revision 1.111 2004/10/21 20:20:53 rurban
1885 // From patch #970004 "Double clic to edit" by pixels.
1887 // Revision 1.110 2004/10/15 11:05:10 rurban
1888 // fix yesterdays premature dumphtml fix for $default_text (thanks John Shen)
1890 // Revision 1.109 2004/10/14 21:06:02 rurban
1891 // fix dumphtml with USE_PATH_INFO (again). fix some PageList refs
1893 // Revision 1.108 2004/09/26 12:24:02 rurban
1894 // no anchor (PCRE memory), explicit ^ instead
1896 // Revision 1.107 2004/06/21 16:22:29 rurban
1897 // add DEFAULT_DUMP_DIR and HTML_DUMP_DIR constants, for easier cmdline dumps,
1898 // fixed dumping buttons locally (images/buttons/),
1899 // support pages arg for dumphtml,
1900 // optional directory arg for dumpserial + dumphtml,
1901 // fix a AllPages warning,
1902 // show dump warnings/errors on DEBUG,
1903 // don't warn just ignore on wikilens pagelist columns, if not loaded.
1904 // RateIt pagelist column is called "rating", not "ratingwidget" (Dan?)
1906 // Revision 1.106 2004/06/20 14:42:54 rurban
1907 // various php5 fixes (still broken at blockparser)
1909 // Revision 1.105 2004/06/14 11:31:36 rurban
1910 // renamed global $Theme to $WikiTheme (gforge nameclash)
1911 // inherit PageList default options from PageList
1912 // default sortby=pagename
1913 // use options in PageList_Selectable (limit, sortby, ...)
1914 // added action revert, with button at action=diff
1915 // added option regex to WikiAdminSearchReplace
1917 // Revision 1.104 2004/06/11 09:07:30 rurban
1918 // support theme-specific LinkIconAttr: front or after or none
1920 // Revision 1.103 2004/06/07 22:44:14 rurban
1921 // added simplified chown, setacl actions
1923 // Revision 1.102 2004/06/07 18:59:28 rurban
1924 // added Chown link to Owner in statusbar
1926 // Revision 1.101 2004/06/03 12:59:40 rurban
1927 // simplify translation
1928 // NS4 wrap=virtual only
1930 // Revision 1.100 2004/06/03 10:18:19 rurban
1931 // fix FileUser locking issues, new config ENABLE_PAGEPERM
1933 // Revision 1.99 2004/06/01 15:27:59 rurban
1934 // AdminUser only ADMIN_USER not member of Administrators
1935 // some RateIt improvements by dfrankow
1936 // edit_toolbar buttons
1938 // Revision 1.98 2004/05/27 17:49:05 rurban
1939 // renamed DB_Session to DbSession (in CVS also)
1940 // added WikiDB->getParam and WikiDB->getAuthParam method to get rid of globals
1941 // remove leading slash in error message
1942 // added force_unlock parameter to File_Passwd (no return on stale locks)
1943 // fixed adodb session AffectedRows
1944 // added FileFinder helpers to unify local filenames and DATA_PATH names
1945 // editpage.php: new edit toolbar javascript on ENABLE_EDIT_TOOLBAR
1947 // Revision 1.97 2004/05/18 16:23:39 rurban
1948 // rename split_pagename to SplitPagename
1950 // Revision 1.96 2004/05/13 13:48:34 rurban
1951 // doc update for the new 1.3.10 release
1953 // Revision 1.94 2004/05/13 11:52:34 rurban
1954 // search also default buttons
1956 // Revision 1.93 2004/05/12 10:49:55 rurban
1957 // require_once fix for those libs which are loaded before FileFinder and
1958 // its automatic include_path fix, and where require_once doesn't grok
1959 // dirname(__FILE__) != './lib'
1960 // upgrade fix with PearDB
1961 // navbar.tmpl: remove spaces for IE button alignment
1963 // Revision 1.92 2004/05/03 21:57:47 rurban
1964 // locale updates: we previously lost some words because of wrong strings in
1965 // PhotoAlbum, german rewording.
1966 // fixed $_SESSION registering (lost session vars, esp. prefs)
1967 // fixed ending slash in listAvailableLanguages/Themes
1969 // Revision 1.91 2004/05/03 11:40:42 rurban
1970 // put listAvailableLanguages() and listAvailableThemes() from SystemInfo and
1971 // UserPreferences into Themes.php
1973 // Revision 1.90 2004/05/02 19:12:14 rurban
1974 // fix sf.net bug #945154 Konqueror alt css
1976 // Revision 1.89 2004/04/29 21:25:45 rurban
1977 // default theme navbar consistency: linkButtons instead of action buttons
1978 // 3rd makeLinkButtin arg for action support
1980 // Revision 1.88 2004/04/19 18:27:45 rurban
1981 // Prevent from some PHP5 warnings (ref args, no :: object init)
1982 // php5 runs now through, just one wrong XmlElement object init missing
1983 // Removed unneccesary UpgradeUser lines
1984 // Changed WikiLink to omit version if current (RecentChanges)
1986 // Revision 1.87 2004/04/19 09:13:23 rurban
1987 // new pref: googleLink
1989 // Revision 1.86 2004/04/18 01:11:51 rurban
1990 // more numeric pagename fixes.
1991 // fixed action=upload with merge conflict warnings.
1992 // charset changed from constant to global (dynamic utf-8 switching)
1994 // Revision 1.85 2004/04/12 13:04:50 rurban
1995 // added auth_create: self-registering Db users
1997 // removed rating recommendations
1998 // ziplib reformatting
2000 // Revision 1.84 2004/04/10 02:30:49 rurban
2001 // Fixed gettext problem with VIRTUAL_PATH scripts (Windows only probably)
2002 // Fixed "cannot setlocale..." (sf.net problem)
2004 // Revision 1.83 2004/04/09 17:49:03 rurban
2005 // Added PhpWiki RssFeed to Sidebar
2006 // sidebar formatting
2007 // some browser dependant fixes (old-browser support)
2009 // Revision 1.82 2004/04/06 20:00:10 rurban
2010 // Cleanup of special PageList column types
2011 // Added support of plugin and theme specific Pagelist Types
2012 // Added support for theme specific UserPreferences
2013 // Added session support for ip-based throttling
2014 // sql table schema change: ALTER TABLE session ADD sess_ip CHAR(15);
2015 // Enhanced postgres schema
2016 // Added DB_Session_dba support
2018 // Revision 1.81 2004/04/01 15:57:10 rurban
2019 // simplified Sidebar theme: table, not absolute css positioning
2020 // added the new box methods.
2021 // remaining problems: large left margin, how to override _autosplitWikiWords in Template only
2023 // Revision 1.80 2004/03/30 02:14:03 rurban
2024 // fixed yet another Prefs bug
2025 // added generic PearDb_iter
2026 // $request->appendValidators no so strict as before
2027 // added some box plugin methods
2028 // PageList commalist for condensed output
2030 // Revision 1.79 2004/03/24 19:39:02 rurban
2031 // php5 workaround code (plus some interim debugging code in XmlElement)
2032 // php5 doesn't work yet with the current XmlElement class constructors,
2033 // WikiUserNew does work better than php4.
2034 // rewrote WikiUserNew user upgrading to ease php5 update
2035 // fixed pref handling in WikiUserNew
2036 // added Email Notification
2037 // added simple Email verification
2038 // removed emailVerify userpref subclass: just a email property
2039 // changed pref binary storage layout: numarray => hash of non default values
2040 // print optimize message only if really done.
2041 // forced new cookie policy: delete pref cookies, use only WIKI_ID as plain string.
2042 // prefs should be stored in db or homepage, besides the current session.
2044 // Revision 1.78 2004/03/18 22:32:33 rurban
2045 // work to make it php5 compatible
2047 // Revision 1.77 2004/03/08 19:30:01 rurban
2048 // fixed Theme->getButtonURL
2049 // AllUsers uses now WikiGroup (also DB User and DB Pref users)
2050 // PageList fix for empty pagenames
2052 // Revision 1.76 2004/03/08 18:17:09 rurban
2053 // added more WikiGroup::getMembersOf methods, esp. for special groups
2054 // fixed $LDAP_SET_OPTIONS
2055 // fixed _AuthInfo group methods
2057 // Revision 1.75 2004/03/01 09:34:37 rurban
2058 // fixed button path logic: now fallback to default also
2060 // Revision 1.74 2004/02/28 21:14:08 rurban
2061 // generally more PHPDOC docs
2062 // see http://xarch.tu-graz.ac.at/home/rurban/phpwiki/xref/
2063 // fxied WikiUserNew pref handling: empty theme not stored, save only
2064 // changed prefs, sql prefs improved, fixed password update,
2065 // removed REPLACE sql (dangerous)
2066 // moved gettext init after the locale was guessed
2067 // + some minor changes
2069 // Revision 1.73 2004/02/26 03:22:05 rurban
2070 // also copy css and images with XHTML Dump
2072 // Revision 1.72 2004/02/26 02:25:53 rurban
2073 // fix empty and #-anchored links in XHTML Dumps
2075 // Revision 1.71 2004/02/15 21:34:37 rurban
2076 // PageList enhanced and improved.
2077 // fixed new WikiAdmin... plugins
2078 // editpage, Theme with exp. htmlarea framework
2079 // (htmlarea yet committed, this is really questionable)
2080 // WikiUser... code with better session handling for prefs
2081 // enhanced UserPreferences (again)
2082 // RecentChanges for show_deleted: how should pages be deleted then?
2084 // Revision 1.70 2004/01/26 09:17:48 rurban
2085 // * changed stored pref representation as before.
2086 // the array of objects is 1) bigger and 2)
2087 // less portable. If we would import packed pref
2088 // objects and the object definition was changed, PHP would fail.
2089 // This doesn't happen with an simple array of non-default values.
2090 // * use $prefs->retrieve and $prefs->store methods, where retrieve
2091 // understands the interim format of array of objects also.
2092 // * simplified $prefs->get() and fixed $prefs->set()
2093 // * added $user->_userid and class '_WikiUser' portability functions
2094 // * fixed $user object ->_level upgrading, mostly using sessions.
2095 // this fixes yesterdays problems with loosing authorization level.
2096 // * fixed WikiUserNew::checkPass to return the _level
2097 // * fixed WikiUserNew::isSignedIn
2098 // * added explodePageList to class PageList, support sortby arg
2099 // * fixed UserPreferences for WikiUserNew
2100 // * fixed WikiPlugin for empty defaults array
2101 // * UnfoldSubpages: added pagename arg, renamed pages arg,
2102 // removed sort arg, support sortby arg
2104 // Revision 1.69 2003/12/05 01:32:28 carstenklapp
2105 // New feature: Easier to run multiple wiks off of one set of code. Name
2106 // your logo and signature image files "YourWikiNameLogo.png" and
2107 // "YourWikiNameSignature.png" and put them all into
2108 // themes/default/images. YourWikiName should match what is defined as
2109 // WIKI_NAME in index.php. In case the image is not found, the default
2110 // shipped with PhpWiki will be used.
2112 // Revision 1.68 2003/03/04 01:53:30 dairiki
2113 // Inconsequential decrufting.
2115 // Revision 1.67 2003/02/26 03:40:22 dairiki
2116 // New action=create. Essentially the same as action=edit, except that if the
2117 // page already exists, it falls back to action=browse.
2119 // This is for use in the "question mark" links for unknown wiki words
2120 // to avoid problems and confusion when following links from stale pages.
2121 // (If the "unknown page" has been created in the interim, the user probably
2122 // wants to view the page before editing it.)
2124 // Revision 1.66 2003/02/26 00:10:26 dairiki
2125 // More/better/different checks for bad page names.
2127 // Revision 1.65 2003/02/24 22:41:57 dairiki
2130 // Revision 1.64 2003/02/24 22:06:14 dairiki
2131 // Attempts to fix auto-selection of printer CSS when printing.
2132 // See new comments lib/Theme.php for more details.
2133 // Also see SF patch #669563.
2135 // Revision 1.63 2003/02/23 03:37:05 dairiki
2136 // Stupid typo/bug fix.
2138 // Revision 1.62 2003/02/21 04:14:52 dairiki
2139 // New WikiLink type 'if_known'. This gives linkified name if page
2140 // exists, otherwise, just plain text.
2142 // Revision 1.61 2003/02/18 21:52:05 dairiki
2143 // Fix so that one can still link to wiki pages with # in their names.
2144 // (This was made difficult by the introduction of named tags, since
2145 // '[Page #1]' is now a link to anchor '1' in page 'Page'.
2147 // Now the ~ escape for page names should work: [Page ~#1].
2149 // Revision 1.60 2003/02/15 01:59:47 dairiki
2150 // Theme::getCSS(): Add Default-Style HTTP(-eqiv) header in attempt
2151 // to fix default stylesheet selection on some browsers.
2152 // For details on the Default-Style header, see:
2153 // http://home.dairiki.org/docs/html4/present/styles.html#h-14.3.2
2155 // Revision 1.59 2003/01/04 22:30:16 carstenklapp
2156 // New: display a "Never edited." message instead of an invalid epoch date.
2159 // (c-file-style: "gnu")
2163 // c-basic-offset: 4
2164 // c-hanging-comment-ender-p: nil
2165 // indent-tabs-mode: nil