2 /* Copyright (C) 2002,2004,2005,2006,2008,2009,2010 $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 along
17 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 * Customize output by themes: templates, css, special links functions,
23 * and more formatting.
27 * Make a link to a wiki page (in this wiki).
29 * This is a convenience function.
31 * @param mixed $page_or_rev
33 * <dt>A string</dt><dd>The page to link to.</dd>
34 * <dt>A WikiDB_Page object</dt><dd>The page to link to.</dd>
35 * <dt>A WikiDB_PageRevision object</dt><dd>A specific version of the page to link to.</dd>
40 * <dt>'unknown'</dt><dd>Make link appropriate for a non-existant page.</dd>
41 * <dt>'known'</dt><dd>Make link appropriate for an existing page.</dd>
42 * <dt>'auto'</dt><dd>Either 'unknown' or 'known' as appropriate.</dd>
43 * <dt>'button'</dt><dd>Make a button-style link.</dd>
44 * <dt>'if_known'</dt><dd>Only linkify if page exists.</dd>
46 * Unless $type of of the latter form, the link will be of class 'wiki', 'wikiunknown',
47 * 'named-wiki', or 'named-wikiunknown', as appropriate.
49 * @param mixed $label (string or XmlContent object)
50 * Label for the link. If not given, defaults to the page name.
52 * @return XmlContent The link
54 function WikiLink($page_or_rev, $type = 'known', $label = false)
56 global $WikiTheme, $request;
58 if ($type == 'button') {
59 return $WikiTheme->makeLinkButton($page_or_rev, $label);
64 if (isa($page_or_rev, 'WikiDB_PageRevision')) {
65 $version = $page_or_rev->getVersion();
66 if ($page_or_rev->isCurrent())
68 $page = $page_or_rev->getPage();
69 $pagename = $page->getName();
70 $wikipage = $pagename;
71 } elseif (isa($page_or_rev, 'WikiDB_Page')) {
73 $pagename = $page->getName();
74 $wikipage = $pagename;
75 } elseif (isa($page_or_rev, 'WikiPageName')) {
76 $wikipage = $page_or_rev;
77 $pagename = $wikipage->name;
78 if (!$wikipage->isValid('strict'))
79 return $WikiTheme->linkBadWikiWord($wikipage, $label);
81 $wikipage = new WikiPageName($page_or_rev, $request->getPage());
82 $pagename = $wikipage->name;
83 if (!$wikipage->isValid('strict'))
84 return $WikiTheme->linkBadWikiWord($wikipage, $label);
87 if ($type == 'auto' or $type == 'if_known') {
89 $exists = $page->exists();
91 $dbi =& $request->_dbi;
92 $exists = $dbi->isWikiPage($wikipage->name);
94 } elseif ($type == 'unknown') {
100 // FIXME: this should be somewhere else, if really needed.
101 // WikiLink makes A link, not a string of fancy ones.
102 // (I think that the fancy split links are just confusing.)
103 // Todo: test external ImageLinks http://some/images/next.gif
104 if (isa($wikipage, 'WikiPageName') and
106 strchr(substr($wikipage->shortName, 1), SUBPAGE_SEPARATOR)
108 $parts = explode(SUBPAGE_SEPARATOR, $wikipage->shortName);
109 $last_part = array_pop($parts);
111 $link = HTML::span();
112 foreach ($parts as $part) {
114 $parent = join(SUBPAGE_SEPARATOR, $path);
115 if ($WikiTheme->_autosplitWikiWords)
118 $link->pushContent($WikiTheme->linkExistingWikiWord($parent, $sep . $part));
119 $sep = $WikiTheme->_autosplitWikiWords
120 ? ' ' . SUBPAGE_SEPARATOR : SUBPAGE_SEPARATOR;
123 $link->pushContent($WikiTheme->linkExistingWikiWord($wikipage, $sep . $last_part,
126 $link->pushContent($WikiTheme->linkUnknownWikiWord($wikipage, $sep . $last_part));
131 return $WikiTheme->linkExistingWikiWord($wikipage, $label, $version);
132 } elseif ($type == 'if_known') {
133 if (!$label && isa($wikipage, 'WikiPageName'))
134 $label = $wikipage->shortName;
135 return HTML($label ? $label : $pagename);
137 return $WikiTheme->linkUnknownWikiWord($wikipage, $label);
144 * This is a convenience function.
146 * @param $action string
148 * <dt>[action]</dt><dd>Perform action (e.g. 'edit') on the selected page.</dd>
149 * <dt>[ActionPage]</dt><dd>Run the actionpage (e.g. 'BackLinks') on the selected page.</dd>
150 * <dt>'submit:'[name]</dt><dd>Make a form submission button with the given name.
151 * ([name] can be blank for a nameless submit button.)</dd>
152 * <dt>a hash</dt><dd>Query args for the action. E.g.<pre>
153 * array('action' => 'diff', 'previous' => 'author')
157 * @param $label string
158 * A label for the button. If ommited, a suitable default (based on the valued of $action)
161 * @param $page_or_rev mixed
162 * Which page (& version) to perform the action on.
164 * <dt>A string</dt><dd>The pagename.</dd>
165 * <dt>A WikiDB_Page object</dt><dd>The page.</dd>
166 * <dt>A WikiDB_PageRevision object</dt><dd>A specific version of the page.</dd>
168 * ($Page_or_rev is ignored for submit buttons.)
170 function Button($action, $label = false, $page_or_rev = false, $options = false)
174 if (!is_array($action) && preg_match('/^submit:(.*)/', $action, $m))
175 return $WikiTheme->makeSubmitButton($label, $m[1], $page_or_rev, $options);
177 return $WikiTheme->makeActionButton($action, $label, $page_or_rev, $options);
182 var $HTML_DUMP_SUFFIX = '';
183 var $DUMP_MODE = false, $dumped_images, $dumped_css;
186 * noinit: Do not initialize unnecessary items in default_theme fallback twice.
188 function WikiTheme($theme_name = 'default', $noinit = false)
190 $this->_name = $theme_name;
191 $this->_themes_dir = NormalizeLocalFileName("themes");
192 $this->_path = defined('PHPWIKI_DIR') ? NormalizeLocalFileName("") : "";
193 $this->_theme = "themes/$theme_name";
194 $this->_parents = array();
196 if ($theme_name != 'default') {
198 /* derived classes should search all parent classes */
199 while ($parent = get_parent_class($parent)) {
200 if (strtolower($parent) == 'wikitheme') {
201 $this->_default_theme = new WikiTheme('default', true);
202 $this->_parents[] = $this->_default_theme;
204 $this->_parents[] = new WikiTheme
205 (preg_replace("/^WikiTheme_/i", "", $parent), true);
210 $this->_css = array();
212 // on derived classes do not add headers twice
213 if (count($this->_parents) > 1) {
216 $this->addMoreHeaders(JavaScript('', array('src' => $this->_findData("wikicommon.js"))));
217 if (!(defined('FUSIONFORGE') and FUSIONFORGE)) {
218 // FusionForge already loads this
219 $this->addMoreHeaders(JavaScript('', array('src' => $this->_findData("sortable.js"))));
222 if ((is_object($GLOBALS['request']) // guard against unittests
223 and $GLOBALS['request']->getPref('doubleClickEdit'))
224 or ENABLE_DOUBLECLICKEDIT
226 $this->initDoubleClickEdit();
228 // will be replaced by acDropDown
229 if (ENABLE_LIVESEARCH) { // by bitflux.ch
230 $this->initLiveSearch();
232 // replaces external LiveSearch
233 // enable ENABLE_AJAX for DynamicIncludePage
234 if (ENABLE_ACDROPDOWN or ENABLE_AJAX) {
235 $this->initMoAcDropDown();
236 if (ENABLE_AJAX and DEBUG) // minified all together
237 $this->addMoreHeaders(JavaScript('', array('src' => $this->_findData("ajax.js"))));
243 return $this->_path . "$this->_theme/$file";
246 function _findFile($file, $missing_okay = false)
248 if (file_exists($this->file($file)))
249 return "$this->_theme/$file";
251 // FIXME: this is a short-term hack. Delete this after all files
252 // get moved into themes/...
253 // Needed for button paths in parent themes
254 if (file_exists($this->_path . $file))
257 /* Derived classes should search all parent classes */
258 foreach ($this->_parents as $parent) {
259 $path = $parent->_findFile($file, 1);
262 } elseif (0 and DEBUG & (_DEBUG_VERBOSE + _DEBUG_REMOTE)) {
263 trigger_error("$parent->_theme/$file: not found", E_USER_NOTICE);
266 if (isset($this->_default_theme)) {
267 return $this->_default_theme->_findFile($file, $missing_okay);
268 } elseif (!$missing_okay) {
269 trigger_error("$this->_theme/$file: not found", E_USER_NOTICE);
270 if (DEBUG & _DEBUG_TRACE) {
272 printSimpleTrace(debug_backtrace());
279 function _findData($file, $missing_okay = false)
281 if (!string_starts_with($file, "themes")) { // common case
282 $path = $this->_findFile($file, $missing_okay);
285 if (file_exists($file)) {
287 } elseif (defined('DATA_PATH')
288 and file_exists(DATA_PATH . "/$file")
291 } else { // fallback for buttons in parent themes
292 $path = $this->_findFile($file, $missing_okay);
298 $min = preg_replace("/\.(css|js)$/", "-min.\\1", $file);
299 if ($min and ($x = $this->_findFile($min, true))) $path = $x;
302 if (defined('DATA_PATH'))
303 return DATA_PATH . "/$path";
307 ////////////////////////////////////////////////////////////////
309 // Date and Time formatting
311 ////////////////////////////////////////////////////////////////
313 // Note: Windows' implementation of strftime does not include certain
314 // format specifiers, such as %e (for date without leading zeros). In
316 // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_strftime.2c_.wcsftime.asp
317 // As a result, we have to use %d, and strip out leading zeros ourselves.
319 var $_dateFormat = "%B %d, %Y";
320 var $_timeFormat = "%I:%M %p";
322 var $_showModTime = true;
325 * Set format string used for dates.
327 * @param $fs string Format string for dates.
329 * @param $show_mod_time bool If true (default) then times
330 * are included in the messages generated by getLastModifiedMessage(),
331 * otherwise, only the date of last modification will be shown.
333 function setDateFormat($fs, $show_mod_time = true)
335 $this->_dateFormat = $fs;
336 $this->_showModTime = $show_mod_time;
340 * Set format string used for times.
342 * @param $fs string Format string for times.
344 function setTimeFormat($fs)
346 $this->_timeFormat = $fs;
352 * Any time zone offset specified in the users preferences is
353 * taken into account by this method.
355 * @param $time_t integer Unix-style time.
357 * @return string The date.
359 function formatDate($time_t)
363 $offset_time = $time_t + 3600 * $request->getPref('timeOffset');
364 // strip leading zeros from date elements (ie space followed by zero
365 // or leading 0 as in French "09 mai 2009")
366 return preg_replace('/ 0/', ' ', preg_replace('/^0/', ' ',
367 strftime($this->_dateFormat, $offset_time)));
373 * Any time zone offset specified in the users preferences is
374 * taken into account by this method.
376 * @param $time_t integer Unix-style time.
378 * @return string The time.
380 function formatTime($time_t)
382 //FIXME: make 24-hour mode configurable?
384 $offset_time = $time_t + 3600 * $request->getPref('timeOffset');
385 return preg_replace('/^0/', ' ',
386 strtolower(strftime($this->_timeFormat, $offset_time)));
390 * Format a date and time.
392 * Any time zone offset specified in the users preferences is
393 * taken into account by this method.
395 * @param $time_t integer Unix-style time.
397 * @return string The date and time.
399 function formatDateTime($time_t)
402 // Do not display "01 January 1970 1:00" for nonexistent pages
405 return $this->formatDate($time_t) . ' ' . $this->formatTime($time_t);
410 * Format a (possibly relative) date.
412 * If enabled in the users preferences, this method might
413 * return a relative day (e.g. 'Today', 'Yesterday').
415 * Any time zone offset specified in the users preferences is
416 * taken into account by this method.
418 * @param $time_t integer Unix-style time.
420 * @return string The day.
422 function getDay($time_t)
426 if ($request->getPref('relativeDates') && ($date = $this->_relativeDay($time_t))) {
427 return ucfirst($date);
429 return $this->formatDate($time_t);
433 * Format the "last modified" message for a page revision.
435 * @param $revision object A WikiDB_PageRevision object.
437 * @param $show_version bool Should the page version number
438 * be included in the message. (If this argument is omitted,
439 * then the version number will be shown only iff the revision
440 * is not the current one.
442 * @return string The "last modified" message.
444 function getLastModifiedMessage($revision, $show_version = 'auto')
447 if (!$revision) return '';
449 // dates >= this are considered invalid.
450 if (!defined('EPOCH'))
451 define('EPOCH', 0); // seconds since ~ January 1 1970
453 $mtime = $revision->get('mtime');
455 return _("Never edited");
457 if ($show_version == 'auto')
458 $show_version = !$revision->isCurrent();
460 if ($request->getPref('relativeDates') && ($date = $this->_relativeDay($mtime))) {
461 if ($this->_showModTime)
462 $date = sprintf(_("%s at %s"),
463 $date, $this->formatTime($mtime));
466 return fmt("Version %s, saved on %s", $revision->getVersion(), $date);
468 return fmt("Last edited on %s", $date);
471 if ($this->_showModTime)
472 $date = $this->formatDateTime($mtime);
474 $date = $this->formatDate($mtime);
477 return fmt("Version %s, saved on %s", $revision->getVersion(), $date);
479 return fmt("Last edited on %s", $date);
482 function _relativeDay($time_t)
486 if (is_numeric($request->getPref('timeOffset')))
487 $offset = 3600 * $request->getPref('timeOffset');
491 $now = time() + $offset;
492 $today = localtime($now, true);
493 $time = localtime($time_t + $offset, true);
495 if ($time['tm_yday'] == $today['tm_yday'] && $time['tm_year'] == $today['tm_year'])
498 // Note that due to daylight savings chages (and leap seconds), $now minus
499 // 24 hours is not guaranteed to be yesterday.
500 $yesterday = localtime($now - (12 + $today['tm_hour']) * 3600, true);
501 if ($time['tm_yday'] == $yesterday['tm_yday']
502 and $time['tm_year'] == $yesterday['tm_year']
504 return _("yesterday");
510 * Format the "Author" and "Owner" messages for a page revision.
512 function getOwnerMessage($page)
514 if (!ENABLE_PAGEPERM or !class_exists("PagePermission"))
516 $dbi =& $GLOBALS['request']->_dbi;
517 $owner = $page->getOwner();
520 if ( mayAccessPage('change',$page->getName()) )
521 return fmt("Owner: %s", $this->makeActionButton(array('action'=>_("chown"),
522 's' => $page->getName()),
525 if ($dbi->isWikiPage($owner))
526 return fmt("Owner: %s", WikiLink($owner));
528 return fmt("Owner: %s", '"' . $owner . '"');
533 /* New behaviour: (by Matt Brown)
534 Prefer author (name) over internal author_id (IP) */
535 function getAuthorMessage($revision)
537 if (!$revision) return '';
538 $dbi =& $GLOBALS['request']->_dbi;
539 $author = $revision->get('author');
540 if (!$author) $author = $revision->get('author_id');
541 if (!$author) return '';
542 if ($dbi->isWikiPage($author)) {
543 return fmt("by %s", WikiLink($author));
545 return fmt("by %s", '"' . $author . '"');
549 ////////////////////////////////////////////////////////////////
551 // Hooks for other formatting
553 ////////////////////////////////////////////////////////////////
555 function getFormatter($type, $format)
557 $method = strtolower("get${type}Formatter");
558 if (method_exists($this, $method))
559 return $this->{$method}($format);
563 ////////////////////////////////////////////////////////////////
567 ////////////////////////////////////////////////////////////////
569 var $_autosplitWikiWords = false;
571 function setAutosplitWikiWords($autosplit = true)
573 $this->_autosplitWikiWords = $autosplit ? true : false;
576 function maybeSplitWikiWord($wikiword)
578 if ($this->_autosplitWikiWords)
579 return SplitPagename($wikiword);
584 var $_anonEditUnknownLinks = true;
586 function setAnonEditUnknownLinks($anonedit = true)
588 $this->_anonEditUnknownLinks = $anonedit ? true : false;
591 function linkExistingWikiWord($wikiword, $linktext = '', $version = false)
595 if ($version !== false and !$this->HTML_DUMP_SUFFIX)
596 $url = WikiURL($wikiword, array('version' => $version));
598 $url = WikiURL($wikiword);
600 // Extra steps for dumping page to an html file.
601 if ($this->HTML_DUMP_SUFFIX) {
602 $url = preg_replace('/^\./', '%2e', $url); // dot pages
605 $link = HTML::a(array('href' => $url));
607 if (isa($wikiword, 'WikiPageName'))
608 $default_text = $wikiword->shortName;
610 $default_text = $wikiword;
612 if (!empty($linktext)) {
613 $link->pushContent($linktext);
614 $link->setAttr('class', 'named-wiki');
615 $link->setAttr('title', $this->maybeSplitWikiWord($default_text));
617 $link->pushContent($this->maybeSplitWikiWord($default_text));
618 $link->setAttr('class', 'wiki');
620 if ($request->getArg('frame'))
621 $link->setAttr('target', '_top');
625 function linkUnknownWikiWord($wikiword, $linktext = '')
629 // Get rid of anchors on unknown wikiwords
630 if (isa($wikiword, 'WikiPageName')) {
631 $default_text = $wikiword->shortName;
632 $wikiword = $wikiword->name;
634 $default_text = $wikiword;
637 if ($this->DUMP_MODE) { // HTML, PDF or XML
638 $link = HTML::span(empty($linktext) ? $wikiword : $linktext);
639 $link->setAttr('style', 'text-decoration: underline');
640 $link->addTooltip(sprintf(_("Empty link to: %s"), $wikiword));
641 $link->setAttr('class', empty($linktext) ? 'wikiunknown' : 'named-wikiunknown');
644 // if AnonEditUnknownLinks show "?" only users which are allowed to edit this page
645 if (!$this->_anonEditUnknownLinks and
646 (!$request->_user->isSignedIn()
647 or !mayAccessPage('edit', $request->getArg('pagename')))
649 $text = HTML::span(empty($linktext) ? $wikiword : $linktext);
650 $text->setAttr('class', empty($linktext) ? 'wikiunknown' : 'named-wikiunknown');
653 $url = WikiURL($wikiword, array('action' => 'create'));
654 $button = $this->makeButton('?', $url);
655 $button->addTooltip(sprintf(_("Create: %s"), $wikiword));
659 $link = HTML::span();
660 if (!empty($linktext)) {
661 $link->pushContent(HTML::span($linktext));
662 $link->setAttr('style', 'text-decoration: underline');
663 $link->setAttr('class', 'named-wikiunknown');
665 $link->pushContent(HTML::span($this->maybeSplitWikiWord($default_text)));
666 $link->setAttr('style', 'text-decoration: underline');
667 $link->setAttr('class', 'wikiunknown');
669 if (!isa($button, "ImageButton"))
670 $button->setAttr('rel', 'nofollow');
671 $link->pushContent($button);
672 if ($request->getPref('googleLink')) {
673 $gbutton = $this->makeButton('G', "http://www.google.com/search?q="
674 . urlencode($wikiword));
675 $gbutton->addTooltip(sprintf(_("Google:%s"), $wikiword));
676 $link->pushContent($gbutton);
678 if ($request->getArg('frame'))
679 $link->setAttr('target', '_top');
684 function linkBadWikiWord($wikiword, $linktext = '')
686 global $ErrorManager;
690 } elseif (isa($wikiword, 'WikiPageName')) {
691 $text = $wikiword->shortName;
696 if (isa($wikiword, 'WikiPageName'))
697 $message = $wikiword->getWarnings();
699 $message = sprintf(_("“%s”: Bad page name"), $wikiword);
700 $ErrorManager->warning($message);
702 return HTML::span(array('class' => 'badwikiword'), $text);
705 ////////////////////////////////////////////////////////////////
709 ////////////////////////////////////////////////////////////////
710 var $_imageAliases = array();
714 * (To disable an image, alias the image to <code>false</code>.
716 function addImageAlias($alias, $image_name)
718 // fall back to the PhpWiki-supplied image if not found
719 if ((empty($this->_imageAliases[$alias])
720 and $this->_findFile("images/$image_name", true))
721 or $image_name === false
723 $this->_imageAliases[$alias] = $image_name;
726 function getImageURL($image)
728 $aliases = &$this->_imageAliases;
730 if (isset($aliases[$image])) {
731 $image = $aliases[$image];
736 // If not extension, default to .png.
737 if (!preg_match('/\.\w+$/', $image))
740 // FIXME: this should probably be made to fall back
741 // automatically to .gif, .jpg.
742 // Also try .gif before .png if browser doesn't like png.
744 $path = $this->_findData("images/$image", 'missing okay');
745 if (!$path) // search explicit images/ or button/ links also
746 $path = $this->_findData("$image", 'missing okay');
748 if ($this->DUMP_MODE) {
749 if (empty($this->dumped_images)) $this->dumped_images = array();
750 $path = "images/" . basename($path);
751 if (!in_array($path, $this->dumped_images))
752 $this->dumped_images[] = $path;
757 function setLinkIcon($proto, $image = false)
762 $this->_linkIcons[$proto] = $image;
765 function getLinkIconURL($proto)
767 $icons = &$this->_linkIcons;
768 if (!empty($icons[$proto]))
769 return $this->getImageURL($icons[$proto]);
770 elseif (!empty($icons['*']))
771 return $this->getImageURL($icons['*']);
775 var $_linkIcon = 'front'; // or 'after' or 'no'.
776 // maybe also 'spanall': there is a scheme currently in effect with front, which
777 // spans the icon only to the first, to let the next words wrap on line breaks
778 // see stdlib.php:PossiblyGlueIconToText()
779 function getLinkIconAttr()
781 return $this->_linkIcon;
784 function setLinkIconAttr($where)
786 $this->_linkIcon = $where;
789 function addButtonAlias($text, $alias = false)
791 $aliases = &$this->_buttonAliases;
794 $aliases = array_merge($aliases, $text);
795 elseif ($alias === false)
796 unset($aliases[$text]); else
797 $aliases[$text] = $alias;
800 function getButtonURL($text)
802 $aliases = &$this->_buttonAliases;
803 if (isset($aliases[$text]))
804 $text = $aliases[$text];
806 $qtext = urlencode($text);
807 $url = $this->_findButton("$qtext.png");
808 if ($url && strstr($url, '%')) {
809 $url = preg_replace('|([^/]+)$|e', 'urlencode("\\1")', $url);
811 if (!$url) { // Jeff complained about png not supported everywhere.
812 // This was not PC until 2005.
813 $url = $this->_findButton("$qtext.gif");
814 if ($url && strstr($url, '%')) {
815 $url = preg_replace('|([^/]+)$|e', 'urlencode("\\1")', $url);
818 if ($url and $this->DUMP_MODE) {
819 if (empty($this->dumped_buttons)) $this->dumped_buttons = array();
821 if (defined('DATA_PATH'))
822 $file = substr($url, strlen(DATA_PATH) + 1);
823 $url = "images/buttons/" . basename($file);
824 if (!array_key_exists($text, $this->dumped_buttons))
825 $this->dumped_buttons[$text] = $file;
830 function _findButton($button_file)
832 if (empty($this->_button_path))
833 $this->_button_path = $this->_getButtonPath();
835 foreach ($this->_button_path as $dir) {
836 if ($path = $this->_findData("$dir/$button_file", 1))
842 function _getButtonPath()
844 $button_dir = $this->_findFile("buttons");
845 $path_dir = $this->_path . $button_dir;
846 if (!file_exists($path_dir) || !is_dir($path_dir))
848 $path = array($button_dir);
850 $dir = dir($path_dir);
851 while (($subdir = $dir->read()) !== false) {
852 if ($subdir[0] == '.')
854 if ($subdir == 'CVS')
856 if (is_dir("$path_dir/$subdir"))
857 $path[] = "$button_dir/$subdir";
860 // add default buttons
861 $path[] = "themes/default/buttons";
862 $path_dir = $this->_path . "themes/default/buttons";
863 $dir = dir($path_dir);
864 while (($subdir = $dir->read()) !== false) {
865 if ($subdir[0] == '.')
867 if ($subdir == 'CVS')
869 if (is_dir("$path_dir/$subdir"))
870 $path[] = "themes/default/buttons/$subdir";
877 ////////////////////////////////////////////////////////////////
881 ////////////////////////////////////////////////////////////////
883 function makeButton($text, $url, $class = false, $options = false)
885 // FIXME: don't always try for image button?
887 // Special case: URLs like 'submit:preview' generate form
888 // submission buttons.
889 if (preg_match('/^submit:(.*)$/', $url, $m))
890 return $this->makeSubmitButton($text, $m[1], $class, $options);
892 if (is_string($text))
893 $imgurl = $this->getButtonURL($text);
897 return new ImageButton($text, $url,
898 in_array($class, array("wikiaction", "wikiadmin")) ? "wikibutton" : $class,
901 return new Button($this->maybeSplitWikiWord($text), $url,
905 function makeSubmitButton($text, $name, $class = false, $options = false)
907 $imgurl = $this->getButtonURL($text);
910 return new SubmitImageButton($text, $name, !$class ? "wikibutton" : $class, $imgurl, $options);
912 return new SubmitButton($text, $name, $class, $options);
916 * Make button to perform action.
918 * This constructs a button which performs an action on the
919 * currently selected version of the current page.
920 * (Or anotherpage or version, if you want...)
922 * @param $action string The action to perform (e.g. 'edit', 'lock').
923 * This can also be the name of an "action page" like 'LikePages'.
924 * Alternatively you can give a hash of query args to be applied
927 * @param $label string Textual label for the button. If left empty,
928 * a suitable name will be guessed.
930 * @param $page_or_rev mixed The page to link to. This can be
931 * given as a string (the page name), a WikiDB_Page object, or as
932 * WikiDB_PageRevision object. If given as a WikiDB_PageRevision
933 * object, the button will link to a specific version of the
934 * designated page, otherwise the button links to the most recent
935 * version of the page.
937 * @return object A Button object.
939 function makeActionButton($action, $label = false,
940 $page_or_rev = false, $options = false)
942 extract($this->_get_name_and_rev($page_or_rev));
944 if (is_array($action)) {
946 $action = isset($attr['action']) ? $attr['action'] : 'browse';
948 $attr['action'] = $action;
950 $class = is_safe_action($action) ? 'wikiaction' : 'wikiadmin';
952 $label = $this->_labelForAction($action);
955 $attr['version'] = $version;
957 if ($action == 'browse')
958 unset($attr['action']);
960 $options = $this->fixAccesskey($options);
962 return $this->makeButton($label, WikiURL($pagename, $attr), $class, $options);
965 function tooltipAccessKeyPrefix()
967 static $tooltipAccessKeyPrefix = null;
968 if ($tooltipAccessKeyPrefix) return $tooltipAccessKeyPrefix;
970 $tooltipAccessKeyPrefix = 'alt';
971 if (isBrowserOpera()) $tooltipAccessKeyPrefix = 'shift-esc';
972 elseif (isBrowserSafari() or browserDetect("Mac") or isBrowserKonqueror())
973 $tooltipAccessKeyPrefix = 'ctrl'; // ff2 win and x11 only
974 elseif ((browserDetect("firefox/2") or browserDetect("minefield/3") or browserDetect("SeaMonkey/1.1"))
975 and ((browserDetect("windows") or browserDetect("x11")))
977 $tooltipAccessKeyPrefix = 'alt-shift';
978 return $tooltipAccessKeyPrefix;
981 /** Define the accesskey in the title only, with ending [p] or [alt-p].
982 * This fixes the prefix in the title and sets the accesskey.
984 function fixAccesskey($attrs)
986 if (!empty($attrs['title']) and preg_match("/\[(alt-)?(.)\]$/", $attrs['title'], $m)) {
987 if (empty($attrs['accesskey'])) $attrs['accesskey'] = $m[2];
988 // firefox 'alt-shift', MSIE: 'alt', ... see wikibits.js
989 $attrs['title'] = preg_replace("/\[(alt-)?(.)\]$/", "[" . $this->tooltipAccessKeyPrefix() . "-\\2]", $attrs['title']);
995 * Make a "button" which links to a wiki-page.
997 * These are really just regular WikiLinks, possibly
998 * disguised (e.g. behind an image button) by the theme.
1000 * This method should probably only be used for links
1001 * which appear in page navigation bars, or similar places.
1003 * Use linkExistingWikiWord, or LinkWikiWord for normal links.
1005 * @param $page_or_rev mixed The page to link to. This can be
1006 * given as a string (the page name), a WikiDB_Page object, or as
1007 * WikiDB_PageRevision object. If given as a WikiDB_PageRevision
1008 * object, the button will link to a specific version of the
1009 * designated page, otherwise the button links to the most recent
1010 * version of the page.
1012 * @return object A Button object.
1014 function makeLinkButton($page_or_rev, $label = false, $action = false)
1016 extract($this->_get_name_and_rev($page_or_rev));
1018 $args = $version ? array('version' => $version) : false;
1019 if ($action) $args['action'] = $action;
1021 return $this->makeButton($label ? $label : $pagename,
1022 WikiURL($pagename, $args), 'wiki');
1025 function _get_name_and_rev($page_or_rev)
1029 if (empty($page_or_rev)) {
1031 $pagename = $request->getArg("pagename");
1032 $version = $request->getArg("version");
1033 } elseif (is_object($page_or_rev)) {
1034 if (isa($page_or_rev, 'WikiDB_PageRevision')) {
1035 $rev = $page_or_rev;
1036 $page = $rev->getPage();
1037 if (!$rev->isCurrent()) $version = $rev->getVersion();
1039 $page = $page_or_rev;
1041 $pagename = $page->getName();
1043 $pagename = (string)$page_or_rev;
1045 return compact('pagename', 'version');
1048 function _labelForAction($action)
1056 return _("Sign Out");
1058 return _("Sign In");
1060 return _("Rename Page");
1062 return _("Lock Page");
1064 return _("Unlock Page");
1066 return _("Remove Page");
1068 return _("Purge Page");
1070 // I don't think the rest of these actually get used.
1072 // 'upload' 'dumpserial' 'loadfile' 'zip'
1074 return gettext(ucfirst($action));
1078 //----------------------------------------------------------------
1079 var $_buttonSeparator = "\n | ";
1081 function setButtonSeparator($separator)
1083 $this->_buttonSeparator = $separator;
1086 function getButtonSeparator()
1088 return $this->_buttonSeparator;
1091 ////////////////////////////////////////////////////////////////
1097 // Based on testing with Galeon 1.2.7 (Mozilla 1.2):
1098 // Automatic media-based style selection (via <link> tags) only
1099 // seems to work for the default style, not for alternate styles.
1103 // <link rel="stylesheet" type="text/css" href="phpwiki.css" />
1104 // <link rel="stylesheet" type="text/css" href="phpwiki-printer.css" media="print" />
1106 // works to make it so that the printer style sheet get used
1107 // automatically when printing (or print-previewing) a page
1108 // (but when only when the default style is selected.)
1112 // <link rel="alternate stylesheet" title="Modern"
1113 // type="text/css" href="phpwiki-modern.css" />
1114 // <link rel="alternate stylesheet" title="Modern"
1115 // type="text/css" href="phpwiki-printer.css" media="print" />
1117 // Result in two "Modern" choices when trying to select alternate style.
1118 // If one selects the first of those choices, one gets phpwiki-modern
1119 // both when browsing and printing. If one selects the second "Modern",
1120 // one gets no CSS when browsing, and phpwiki-printer when printing.
1125 // We should probably move to doing the media based style
1126 // switching in the CSS files themselves using, e.g.:
1128 // @import url(print.css) print;
1130 ////////////////////////////////////////////////////////////////
1132 function _CSSlink($title, $css_file, $media, $is_alt = false)
1134 // Don't set title on default style. This makes it clear to
1135 // the user which is the default (i.e. most supported) style.
1136 if ($is_alt and isBrowserKonqueror())
1138 $link = HTML::link(array('rel' => $is_alt ? 'alternate stylesheet' : 'stylesheet',
1139 'type' => 'text/css',
1140 'charset' => $GLOBALS['charset'],
1141 'href' => $this->_findData($css_file)));
1143 $link->setAttr('title', $title);
1146 $link->setAttr('media', $media);
1147 if ($this->DUMP_MODE) {
1148 if (empty($this->dumped_css)) $this->dumped_css = array();
1149 if (!in_array($css_file, $this->dumped_css)) $this->dumped_css[] = $css_file;
1150 $link->setAttr('href', basename($link->getAttr('href')));
1156 /** Set default CSS source for this theme.
1158 * To set styles to be used for different media, pass a
1159 * hash for the second argument, e.g.
1161 * $theme->setDefaultCSS('default', array('' => 'normal.css',
1162 * 'print' => 'printer.css'));
1164 * If you call this more than once, the last one called takes
1165 * precedence as the default style.
1167 * @param string $title Name of style (currently ignored, unless
1168 * you call this more than once, in which case, some of the style
1169 * will become alternate (rather than default) styles, and then their
1170 * titles will be used.
1172 * @param mixed $css_files Name of CSS file, or hash containing a mapping
1173 * between media types and CSS file names. Use a key of '' (the empty string)
1174 * to set the default CSS for non-specified media. (See above for an example.)
1176 function setDefaultCSS($title, $css_files)
1178 if (!is_array($css_files))
1179 $css_files = array('' => $css_files);
1180 // Add to the front of $this->_css
1181 unset($this->_css[$title]);
1182 $this->_css = array_merge(array($title => $css_files), $this->_css);
1185 /** Set alternate CSS source for this theme.
1187 * @param string $title Name of style.
1188 * @param string $css_files Name of CSS file.
1190 function addAlternateCSS($title, $css_files)
1192 if (!is_array($css_files))
1193 $css_files = array('' => $css_files);
1194 $this->_css[$title] = $css_files;
1198 * @return string HTML for CSS.
1204 foreach ($this->_css as $title => $css_files) {
1205 ksort($css_files); // move $css_files[''] to front.
1206 foreach ($css_files as $media => $css_file) {
1207 if (!empty($this->DUMP_MODE)) {
1208 if ($media == 'print')
1209 $css[] = $this->_CSSlink($title, $css_file, '', $is_alt);
1211 $css[] = $this->_CSSlink($title, $css_file, $media, $is_alt);
1220 function findTemplate($name)
1222 if ($tmp = $this->_findFile("templates/$name.tmpl", 1))
1223 return $this->_path . $tmp;
1225 $f1 = $this->file("templates/$name.tmpl");
1226 foreach ($this->_parents as $parent) {
1227 if ($tmp = $parent->_findFile("templates/$name.tmpl", 1))
1228 return $this->_path . $tmp;
1230 trigger_error("$f1 not found", E_USER_ERROR);
1236 * Add a random header element to head
1237 * TODO: first css, then js. Maybe seperate it into addJSHeaders/addCSSHeaders
1238 * or use an optional type argument, and seperate it within _MoreHeaders[]
1240 //$GLOBALS['request']->_MoreHeaders = array();
1241 function addMoreHeaders($element)
1243 $GLOBALS['request']->_MoreHeaders[] = $element;
1244 if (!empty($this->_headers_printed) and $this->_headers_printed) {
1245 trigger_error(_("Some action(page) wanted to add more headers, but they were already printed.")
1246 . "\n" . $element->asXML(),
1252 * Singleton. Only called once, by the head template. See the warning above.
1254 function getMoreHeaders()
1257 // actionpages cannot add headers, because recursive template expansion
1258 // already expanded the head template before.
1259 $this->_headers_printed = 1;
1260 if (empty($request->_MoreHeaders))
1263 if (false and ($file = $this->_findData('delayed.js'))) {
1264 $request->_MoreHeaders[] = JavaScript('
1265 // Add a script element as a child of the body
1266 function downloadJSAtOnload() {
1267 var element = document.createElement("script");
1268 element.src = "' . $file . '";
1269 document.body.appendChild(element);
1271 // Check for browser support of event handling capability
1272 if (window.addEventListener)
1273 window.addEventListener("load", downloadJSAtOnload, false);
1274 else if (window.attachEvent)
1275 window.attachEvent("onload", downloadJSAtOnload);
1276 else window.onload = downloadJSAtOnload;');
1278 //$out = "<!-- More Headers -->\n";
1279 foreach ($request->_MoreHeaders as $h) {
1281 $out .= $h->printXML();
1288 //$GLOBALS['request']->_MoreAttr = array();
1289 // new arg: named elements to be able to remove them. such as DoubleClickEdit for htmldumps
1290 function addMoreAttr($tag, $name, $element)
1293 // protect from duplicate attr (body jscript: themes, prefs, ...)
1294 static $_attr_cache = array();
1295 $hash = md5($tag . "/" . $element);
1296 if (!empty($_attr_cache[$hash])) return;
1297 $_attr_cache[$hash] = 1;
1299 if (empty($request->_MoreAttr) or !is_array($request->_MoreAttr[$tag]))
1300 $request->_MoreAttr[$tag] = array($name => $element);
1302 $request->_MoreAttr[$tag][$name] = $element;
1305 function getMoreAttr($tag)
1308 if (empty($request->_MoreAttr[$tag]))
1311 foreach ($request->_MoreAttr[$tag] as $name => $element) {
1312 if (is_object($element))
1313 $out .= $element->printXML();
1321 * Common Initialisations
1325 * The ->load() method replaces the formerly global code in themeinfo.php.
1326 * This is run only once for the selected theme, and not for the parent themes.
1327 * Without this you would not be able to derive from other themes.
1332 $this->initGlobals();
1334 // CSS file defines fonts, colors and background images for this
1335 // style. The companion '*-heavy.css' file isn't defined, it's just
1336 // expected to be in the same directory that the base style is in.
1338 // This should result in phpwiki-printer.css being used when
1339 // printing or print-previewing with style "PhpWiki" or "MacOSX" selected.
1340 $this->setDefaultCSS('PhpWiki',
1341 array('' => 'phpwiki.css',
1342 'print' => 'phpwiki-printer.css'));
1344 // This allows one to manually select "Printer" style (when browsing page)
1345 // to see what the printer style looks like.
1346 $this->addAlternateCSS(_("Printer"), 'phpwiki-printer.css', 'print, screen');
1347 $this->addAlternateCSS(_("Top & bottom toolbars"), 'phpwiki-topbottombars.css');
1348 $this->addAlternateCSS(_("Modern"), 'phpwiki-modern.css');
1350 if (isBrowserIE()) {
1351 $this->addMoreHeaders($this->_CSSlink(0,
1352 $this->_findFile('IEFixes.css'), 'all'));
1353 $this->addMoreHeaders("\n");
1357 * The logo image appears on every page and links to the HomePage.
1359 $this->addImageAlias('logo', WIKI_NAME . 'Logo.png');
1361 $this->addImageAlias('search', 'search.png');
1364 * The Signature image is shown after saving an edited page. If this
1365 * is set to false then the "Thank you for editing..." screen will
1369 $this->addImageAlias('signature', WIKI_NAME . "Signature.png");
1370 // Uncomment this next line to disable the signature.
1371 //$this->addImageAlias('signature', false);
1376 $this->setLinkIcon('http');
1377 $this->setLinkIcon('https');
1378 $this->setLinkIcon('ftp');
1379 $this->setLinkIcon('mailto');
1380 $this->setLinkIcon('interwiki');
1381 $this->setLinkIcon('wikiuser');
1382 $this->setLinkIcon('*', 'url');
1384 $this->setButtonSeparator("\n | ");
1387 * WikiWords can automatically be split by inserting spaces between
1388 * the words. The default is to leave WordsSmashedTogetherLikeSo.
1390 $this->setAutosplitWikiWords(false);
1393 * Layout improvement with dangling links for mostly closed wiki's:
1394 * If false, only users with edit permissions will be presented the
1395 * special wikiunknown class with "?" and Tooltip.
1396 * If true (default), any user will see the ?, but will be presented
1397 * the PrintLoginForm on a click.
1399 //$this->setAnonEditUnknownLinks(false);
1402 * You may adjust the formats used for formatting dates and times
1403 * below. (These examples give the default formats.)
1404 * Formats are given as format strings to PHP strftime() function See
1405 * http://www.php.net/manual/en/function.strftime.php for details.
1406 * Do not include the server's zone (%Z), times are converted to the
1409 * Suggestion for french:
1410 * $this->setDateFormat("%A %e %B %Y");
1411 * $this->setTimeFormat("%H:%M:%S");
1412 * Suggestion for capable php versions, using the server locale:
1413 * $this->setDateFormat("%x");
1414 * $this->setTimeFormat("%X");
1416 //$this->setDateFormat("%B %d, %Y");
1417 //$this->setTimeFormat("%I:%M %p");
1420 * To suppress times in the "Last edited on" messages, give a
1421 * give a second argument of false:
1423 //$this->setDateFormat("%B %d, %Y", false);
1426 * Custom UserPreferences:
1427 * A list of name => _UserPreference class pairs.
1428 * Rationale: Certain themes should be able to extend the predefined list
1429 * of preferences. Display/editing is done in the theme specific userprefs.tmpl
1430 * but storage/sanification/update/... must be extended to the Get/SetPreferences methods.
1431 * See themes/wikilens/themeinfo.php
1433 //$this->customUserPreference();
1436 * Register custom PageList type and define custom PageList classes.
1437 * Rationale: Certain themes should be able to extend the predefined list
1438 * of pagelist types. E.g. certain plugins, like MostPopular might use
1439 * info=pagename,hits,rating
1440 * which displays the rating column whenever the wikilens theme is active.
1441 * See themes/wikilens/themeinfo.php
1443 //$this->addPageListColumn();
1448 * Custom UserPreferences:
1449 * A list of name => _UserPreference class pairs.
1450 * Rationale: Certain themes should be able to extend the predefined list
1451 * of preferences. Display/editing is done in the theme specific userprefs.tmpl
1452 * but storage/sanification/update/... must be extended to the Get/SetPreferences methods.
1453 * These values are just ignored if another theme is used.
1455 function customUserPreferences($array)
1457 global $customUserPreferenceColumns; // FIXME: really a global?
1458 if (empty($customUserPreferenceColumns)) $customUserPreferenceColumns = array();
1459 //array('wikilens' => new _UserPreference_wikilens());
1460 foreach ($array as $field => $prefobj) {
1461 $customUserPreferenceColumns[$field] = $prefobj;
1465 /** addPageListColumn(array('rating' => new _PageList_Column_rating('rating', _("Rate"))))
1466 * Register custom PageList types for special themes, like
1467 * 'rating' for wikilens
1469 function addPageListColumn($array)
1471 global $customPageListColumns;
1472 if (empty($customPageListColumns)) $customPageListColumns = array();
1473 foreach ($array as $column => $obj) {
1474 $customPageListColumns[$column] = $obj;
1478 function initGlobals()
1481 static $already = 0;
1483 $script_url = deduce_script_name();
1484 if ((DEBUG & _DEBUG_REMOTE) and isset($_GET['start_debug']))
1485 $script_url .= ("?start_debug=" . $_GET['start_debug']);
1486 $folderArrowPath = dirname($this->_findData('images/folderArrowLoading.gif'));
1487 $pagename = $request->getArg('pagename');
1488 $js = "var data_path = '" . javascript_quote_string(DATA_PATH) . "';\n"
1489 // XSS warning with pagename
1490 . "var pagename = '" . javascript_quote_string($pagename) . "';\n"
1491 . "var script_url= '" . javascript_quote_string($script_url) . "';\n"
1492 . "var stylepath = data_path+'/" . javascript_quote_string($this->_theme) . "/';\n"
1493 . "var folderArrowPath = '" . javascript_quote_string($folderArrowPath) . "';\n"
1494 . "var use_path_info = " . (USE_PATH_INFO ? "true" : "false") . ";\n";
1495 $this->addMoreHeaders(JavaScript($js));
1500 // Works only on action=browse. Patch #970004 by pixels
1501 // Usage: call $WikiTheme->initDoubleClickEdit() from theme init or
1502 // define ENABLE_DOUBLECLICKEDIT
1503 function initDoubleClickEdit()
1505 if (!$this->HTML_DUMP_SUFFIX)
1506 $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';\""));
1509 // Immediate title search results via XMLHTML(HttpRequest)
1510 // by Bitflux GmbH, bitflux.ch. You need to install the livesearch.js seperately.
1511 // Google's or acdropdown is better.
1512 function initLiveSearch()
1514 //subclasses of Sidebar will init this twice
1515 static $already = 0;
1516 if (!$this->HTML_DUMP_SUFFIX and !$already) {
1517 $this->addMoreAttr('body', 'LiveSearch',
1518 HTML::Raw(" onload=\"liveSearchInit()"));
1519 $this->addMoreHeaders(JavaScript('var liveSearchURI="'
1520 . WikiURL(_("TitleSearch"), false, true) . '";'));
1521 $this->addMoreHeaders(JavaScript('', array
1522 ('src' => $this->_findData('livesearch.js'))));
1527 // Immediate title search results via XMLHttpRequest
1528 // using the shipped moacdropdown js-lib
1529 function initMoAcDropDown()
1531 //subclasses of Sidebar will init this twice
1532 static $already = 0;
1533 if (!$this->HTML_DUMP_SUFFIX and !$already) {
1534 $dir = $this->_findData('moacdropdown');
1535 if (!DEBUG and ($css = $this->_findFile('moacdropdown/css/dropdown.css'))) {
1536 $this->addMoreHeaders($this->_CSSlink(0, $css, 'all'));
1538 $this->addMoreHeaders(HTML::style(array('type' => 'text/css'), " @import url( $dir/css/dropdown.css );\n"));
1544 function calendarLink($date = false)
1546 return $this->calendarBase() . SUBPAGE_SEPARATOR .
1547 strftime("%Y-%m-%d", $date ? $date : time());
1550 function calendarBase()
1552 static $UserCalPageTitle = false;
1555 if (!$UserCalPageTitle)
1556 $UserCalPageTitle = $request->_user->getId() .
1557 SUBPAGE_SEPARATOR . _("Calendar");
1558 if (!$UserCalPageTitle)
1559 $UserCalPageTitle = (BLOG_EMPTY_DEFAULT_PREFIX ? ''
1560 : ($request->_user->getId() . SUBPAGE_SEPARATOR)) . "Blog";
1561 return $UserCalPageTitle;
1564 function calendarInit($force = false)
1566 $dbi = $GLOBALS['request']->getDbh();
1567 // display flat calender dhtml in the sidebar
1568 if ($force or $dbi->isWikiPage($this->calendarBase())) {
1569 $jslang = @$GLOBALS['LANG'];
1570 $this->addMoreHeaders
1573 $this->_findFile('jscalendar/calendar-phpwiki.css'), 'all'));
1574 $this->addMoreHeaders
1576 array('src' => $this->_findData('jscalendar/calendar' . (DEBUG ? '' : '_stripped') . '.js'))));
1577 if (!($langfile = $this->_findData("jscalendar/lang/calendar-$jslang.js")))
1578 $langfile = $this->_findData("jscalendar/lang/calendar-en.js");
1579 $this->addMoreHeaders(JavaScript('', array('src' => $langfile)));
1580 $this->addMoreHeaders
1583 $this->_findData('jscalendar/calendar-setup' . (DEBUG ? '' : '_stripped') . '.js'))));
1585 // Get existing date entries for the current user
1586 require_once 'lib/TextSearchQuery.php';
1587 $iter = $dbi->titleSearch(new TextSearchQuery("^" . $this->calendarBase() . SUBPAGE_SEPARATOR, true, "auto"));
1588 $existing = array();
1589 while ($page = $iter->next()) {
1590 if ($page->exists())
1591 $existing[] = basename($page->_pagename);
1593 if (!empty($existing)) {
1594 $js_exist = '{"' . join('":1,"', $existing) . '":1}';
1595 //var SPECIAL_DAYS = {"2004-05-11":1,"2004-05-12":1,"2004-06-01":1}
1596 $this->addMoreHeaders(JavaScript('
1597 /* This table holds the existing calender entries for the current user
1598 * calculated from the database
1601 var SPECIAL_DAYS = ' . javascript_quote_string($js_exist) . ';
1603 /* This function returns true if the date exists in SPECIAL_DAYS */
1604 function dateExists(date, y, m, d) {
1605 var year = date.getFullYear();
1607 m = m < 10 ? "0" + m : m; // integer, 0..11
1608 d = d < 10 ? "0" + d : d; // integer, 1..31
1609 var date = year+"-"+m+"-"+d;
1610 var exists = SPECIAL_DAYS[date];
1611 if (!exists) return false;
1614 // This is the actual date status handler.
1615 // Note that it receives the date object as well as separate
1616 // values of year, month and date.
1617 function dateStatusFunc(date, y, m, d) {
1618 if (dateExists(date, y, m, d)) return "existing";
1623 $this->addMoreHeaders(JavaScript('
1624 function dateStatusFunc(date, y, m, d) { return false;}'));
1629 ////////////////////////////////////////////////////////////////
1633 ////////////////////////////////////////////////////////////////
1635 /** CbUserLogin (&$request, $userid)
1636 * Callback when a user logs in
1638 function CbUserLogin(&$request, $userid)
1643 /** CbNewUserEdit (&$request, $userid)
1644 * Callback when a new user creates or edits a page
1646 function CbNewUserEdit(&$request, $userid)
1648 ; // i.e. create homepage with Template/UserPage
1651 /** CbNewUserLogin (&$request, $userid)
1652 * Callback when a "new user" logs in.
1653 * What is new? We only record changes, not logins.
1654 * Should we track user actions?
1655 * Let's say a new user is a user without homepage.
1657 function CbNewUserLogin(&$request, $userid)
1662 /** CbUserLogout (&$request, $userid)
1663 * Callback when a user logs out
1665 function CbUserLogout(&$request, $userid)
1673 * A class representing a clickable "button".
1675 * In it's simplest (default) form, a "button" is just a link associated
1676 * with some sort of wiki-action.
1678 class Button extends HtmlElement
1682 * @param $text string The text for the button.
1683 * @param $url string The url (href) for the button.
1684 * @param $class string The CSS class for the button.
1685 * @param $options array Additional attributes for the <input> tag.
1687 function Button($text, $url, $class = false, $options = false)
1690 $this->_init('a', array('href' => $url));
1692 $this->setAttr('class', $class);
1693 if ($request->getArg('frame'))
1694 $this->setAttr('target', '_top');
1695 if (!empty($options) and is_array($options)) {
1696 foreach ($options as $key => $val)
1697 $this->setAttr($key, $val);
1699 // Google honors this
1700 if (in_array(strtolower($text), array('edit', 'create', 'diff', 'pdf'))
1701 and !$request->_user->isAuthenticated()
1703 $this->setAttr('rel', 'nofollow');
1704 $this->pushContent($GLOBALS['WikiTheme']->maybeSplitWikiWord($text));
1710 * A clickable image button.
1712 class ImageButton extends Button
1716 * @param $text string The text for the button.
1717 * @param $url string The url (href) for the button.
1718 * @param $class string The CSS class for the button.
1719 * @param $img_url string URL for button's image.
1720 * @param $img_attr array Additional attributes for the <img> tag.
1722 function ImageButton($text, $url, $class, $img_url, $img_attr = false)
1724 $this->__construct('a', array('href' => $url));
1726 $this->setAttr('class', $class);
1727 // Google honors this
1728 if (in_array(strtolower($text), array('edit', 'create', 'diff', 'pdf'))
1729 and !$GLOBALS['request']->_user->isAuthenticated()
1731 $this->setAttr('rel', 'nofollow');
1733 if (!is_array($img_attr))
1734 $img_attr = array();
1735 $img_attr['src'] = $img_url;
1736 $img_attr['alt'] = $text;
1737 $img_attr['class'] = 'wiki-button';
1738 $this->pushContent(HTML::img($img_attr));
1743 * A class representing a form <samp>submit</samp> button.
1745 class SubmitButton extends HtmlElement
1749 * @param $text string The text for the button.
1750 * @param $name string The name of the form field.
1751 * @param $class string The CSS class for the button.
1752 * @param $options array Additional attributes for the <input> tag.
1754 function SubmitButton($text, $name = false, $class = false, $options = false)
1756 $this->__construct('input', array('type' => 'submit',
1759 $this->setAttr('name', $name);
1761 $this->setAttr('class', $class);
1762 if (!empty($options)) {
1763 foreach ($options as $key => $val)
1764 $this->setAttr($key, $val);
1771 * A class representing an image form <samp>submit</samp> button.
1773 class SubmitImageButton extends SubmitButton
1777 * @param $text string The text for the button.
1778 * @param $name string The name of the form field.
1779 * @param $class string The CSS class for the button.
1780 * @param $img_url string URL for button's image.
1781 * @param $img_attr array Additional attributes for the <img> tag.
1783 function SubmitImageButton($text, $name = false, $class = false, $img_url, $img_attr = false)
1785 $this->__construct('input', array('type' => 'image',
1790 $this->setAttr('name', $name);
1792 $this->setAttr('class', $class);
1793 if (!empty($img_attr)) {
1794 foreach ($img_attr as $key => $val)
1795 $this->setAttr($key, $val);
1802 * A sidebar box with title and body, narrow fixed-width.
1803 * To represent abbrevated content of plugins, links or forms,
1804 * like "Getting Started", "Search", "Sarch Pagename",
1805 * "Login", "Menu", "Recent Changes", "Last comments", "Last Blogs"
1807 * ... See http://tikiwiki.org/
1811 * $menu = SidebarBox("Menu",HTML::dl(HTML::dt(...))); $menu->format();
1812 * $menu = PluginSidebarBox("RecentChanges",array('limit'=>10)); $menu->format();
1817 function SidebarBox($title, $body)
1819 require_once 'lib/WikiPlugin.php';
1820 $this->title = $title;
1821 $this->body = $body;
1826 return WikiPlugin::makeBox($this->title, $this->body);
1831 * A sidebar box for plugins.
1832 * Any plugin may provide a box($args=false, $request=false, $basepage=false)
1833 * method, with the help of WikiPlugin::makeBox()
1835 class PluginSidebarBox extends SidebarBox
1838 var $_plugin, $_args = false, $_basepage = false;
1840 function PluginSidebarBox($name, $args = false, $basepage = false)
1842 require_once 'lib/WikiPlugin.php';
1844 $loader = new WikiPluginLoader();
1845 $plugin = $loader->getPlugin($name);
1847 return $loader->_error(sprintf(_("Plugin %s: undefined"),
1851 if (!method_exists($plugin, 'box')) {
1852 return $loader->_error(sprintf(_("%s: has no box method"),
1853 get_class($plugin)));
1855 $this->_plugin =& $plugin;
1856 $this->_args = $args ? $args : array();
1857 $this->_basepage = $basepage;
1860 function format($args = false)
1862 return $this->_plugin->box($args ? array_merge($this->_args, $args) : $this->_args,
1863 $GLOBALS['request'],
1868 // Various boxes which are no plugins
1869 class RelatedLinksBox extends SidebarBox
1871 function RelatedLinksBox($title = false, $body = '', $limit = 20)
1874 $this->title = $title ? $title : _("Related Links");
1875 $this->body = HTML($body);
1876 $page = $request->getPage($request->getArg('pagename'));
1877 $revision = $page->getCurrentRevision();
1878 $page_content = $revision->getTransformedContent();
1879 //$cache = &$page->_wikidb->_cache;
1881 $sp = HTML::Raw('· ');
1882 foreach ($page_content->getWikiPageLinks() as $link) {
1883 $linkto = $link['linkto'];
1884 if (!$request->_dbi->isWikiPage($linkto)) continue;
1885 $this->body->pushContent($sp, WikiLink($linkto), HTML::br());
1887 if ($limit and $counter > $limit) continue;
1892 class RelatedExternalLinksBox extends SidebarBox
1894 function RelatedExternalLinksBox($title = false, $body = '', $limit = 20)
1897 $this->title = $title ? $title : _("External Links");
1898 $this->body = HTML($body);
1899 $page = $request->getPage($request->getArg('pagename'));
1900 $cache = &$page->_wikidb->_cache;
1902 $sp = HTML::Raw('· ');
1903 foreach ($cache->getWikiPageLinks() as $link) {
1904 $linkto = $link['linkto'];
1906 $this->body->pushContent($sp, WikiLink($linkto), HTML::br());
1908 if ($limit and $counter > $limit) continue;
1914 function listAvailableThemes()
1916 $available_themes = array();
1917 $dir_root = 'themes';
1918 if (defined('PHPWIKI_DIR'))
1919 $dir_root = PHPWIKI_DIR . "/$dir_root";
1920 $dir = dir($dir_root);
1922 while ($entry = $dir->read()) {
1923 if (is_dir($dir_root . '/' . $entry)
1924 and file_exists($dir_root . '/' . $entry . '/themeinfo.php')
1926 array_push($available_themes, $entry);
1931 return $available_themes;
1934 function listAvailableLanguages()
1936 $available_languages = array('en');
1937 $dir_root = 'locale';
1938 if (defined('PHPWIKI_DIR'))
1939 $dir_root = PHPWIKI_DIR . "/$dir_root";
1940 if ($dir = dir($dir_root)) {
1941 while ($entry = $dir->read()) {
1942 if (is_dir($dir_root . "/" . $entry) and is_dir($dir_root . '/' . $entry . '/LC_MESSAGES')) {
1943 array_push($available_languages, $entry);
1948 return $available_languages;
1954 // c-basic-offset: 4
1955 // c-hanging-comment-ender-p: nil
1956 // indent-tabs-mode: nil