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 WikiTheme ($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 WikiTheme('default',true);
208 $script_url = deduce_script_name();
209 if ((DEBUG & _DEBUG_REMOTE) and isset($_GET['start_debug']))
210 $script_url .= ("?start_debug=".$_GET['start_debug']);
211 $this->addMoreHeaders(JavaScript("var data_path = '". javascript_quote_string(DATA_PATH) ."';\n"
212 ."var pagename = '". javascript_quote_string($GLOBALS['request']->getArg('pagename')) ."';\n"
213 ."var script_url= '". javascript_quote_string($script_url) ."';\n"
214 ."var stylepath = '". javascript_quote_string(DATA_PATH) . '/'.$this->_theme."/';\n"));
216 if ((is_object($GLOBALS['request']) // guard against unittests
217 and $GLOBALS['request']->getPref('doubleClickEdit'))
218 or ENABLE_DOUBLECLICKEDIT)
219 $this->initDoubleClickEdit();
221 // will be replaced by acDropDown
222 if (ENABLE_LIVESEARCH) { // by bitflux.ch
223 $this->initLiveSearch();
225 // replaces external LiveSearch
226 if (defined("ENABLE_ACDROPDOWN") and ENABLE_ACDROPDOWN) {
227 $this->initMoAcDropDown();
229 $this->_css = array();
232 function file ($file) {
233 return $this->_path . "$this->_theme/$file";
236 function _findFile ($file, $missing_okay = false) {
237 if (file_exists($this->file($file)))
238 return "$this->_theme/$file";
240 // FIXME: this is a short-term hack. Delete this after all files
241 // get moved into themes/...
242 if (file_exists($this->_path . $file))
245 if (isset($this->_default_theme)) {
246 return $this->_default_theme->_findFile($file, $missing_okay);
248 else if (!$missing_okay) {
249 if (DEBUG & function_exists('debug_backtrace')) { // >= 4.3.0
250 echo "<pre>", printSimpleTrace(debug_backtrace()), "</pre>\n";
252 trigger_error("$this->_theme/$file: not found", E_USER_NOTICE);
257 function _findData ($file, $missing_okay = false) {
258 $path = $this->_findFile($file, $missing_okay);
262 if (defined('DATA_PATH'))
263 return DATA_PATH . "/$path";
267 ////////////////////////////////////////////////////////////////
269 // Date and Time formatting
271 ////////////////////////////////////////////////////////////////
273 // Note: Windows' implemetation of strftime does not include certain
274 // format specifiers, such as %e (for date without leading zeros). In
276 // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_strftime.2c_.wcsftime.asp
277 // As a result, we have to use %d, and strip out leading zeros ourselves.
279 var $_dateFormat = "%B %d, %Y";
280 var $_timeFormat = "%I:%M %p";
282 var $_showModTime = true;
285 * Set format string used for dates.
287 * @param $fs string Format string for dates.
289 * @param $show_mod_time bool If true (default) then times
290 * are included in the messages generated by getLastModifiedMessage(),
291 * otherwise, only the date of last modification will be shown.
293 function setDateFormat ($fs, $show_mod_time = true) {
294 $this->_dateFormat = $fs;
295 $this->_showModTime = $show_mod_time;
299 * Set format string used for times.
301 * @param $fs string Format string for times.
303 function setTimeFormat ($fs) {
304 $this->_timeFormat = $fs;
310 * Any time zone offset specified in the users preferences is
311 * taken into account by this method.
313 * @param $time_t integer Unix-style time.
315 * @return string The date.
317 function formatDate ($time_t) {
320 $offset_time = $time_t + 3600 * $request->getPref('timeOffset');
321 // strip leading zeros from date elements (ie space followed by zero)
322 return preg_replace('/ 0/', ' ',
323 strftime($this->_dateFormat, $offset_time));
329 * Any time zone offset specified in the users preferences is
330 * taken into account by this method.
332 * @param $time_t integer Unix-style time.
334 * @return string The time.
336 function formatTime ($time_t) {
337 //FIXME: make 24-hour mode configurable?
339 $offset_time = $time_t + 3600 * $request->getPref('timeOffset');
340 return preg_replace('/^0/', ' ',
341 strtolower(strftime($this->_timeFormat, $offset_time)));
345 * Format a date and time.
347 * Any time zone offset specified in the users preferences is
348 * taken into account by this method.
350 * @param $time_t integer Unix-style time.
352 * @return string The date and time.
354 function formatDateTime ($time_t) {
355 return $this->formatDate($time_t) . ' ' . $this->formatTime($time_t);
359 * Format a (possibly relative) date.
361 * If enabled in the users preferences, this method might
362 * return a relative day (e.g. 'Today', 'Yesterday').
364 * Any time zone offset specified in the users preferences is
365 * taken into account by this method.
367 * @param $time_t integer Unix-style time.
369 * @return string The day.
371 function getDay ($time_t) {
374 if ($request->getPref('relativeDates') && ($date = $this->_relativeDay($time_t))) {
375 return ucfirst($date);
377 return $this->formatDate($time_t);
381 * Format the "last modified" message for a page revision.
383 * @param $revision object A WikiDB_PageRevision object.
385 * @param $show_version bool Should the page version number
386 * be included in the message. (If this argument is omitted,
387 * then the version number will be shown only iff the revision
388 * is not the current one.
390 * @return string The "last modified" message.
392 function getLastModifiedMessage ($revision, $show_version = 'auto') {
394 if (!$revision) return '';
396 // dates >= this are considered invalid.
397 if (! defined('EPOCH'))
398 define('EPOCH', 0); // seconds since ~ January 1 1970
400 $mtime = $revision->get('mtime');
402 return fmt("Never edited");
404 if ($show_version == 'auto')
405 $show_version = !$revision->isCurrent();
407 if ($request->getPref('relativeDates') && ($date = $this->_relativeDay($mtime))) {
408 if ($this->_showModTime)
409 $date = sprintf(_("%s at %s"),
410 $date, $this->formatTime($mtime));
413 return fmt("Version %s, saved %s", $revision->getVersion(), $date);
415 return fmt("Last edited %s", $date);
418 if ($this->_showModTime)
419 $date = $this->formatDateTime($mtime);
421 $date = $this->formatDate($mtime);
424 return fmt("Version %s, saved on %s", $revision->getVersion(), $date);
426 return fmt("Last edited on %s", $date);
429 function _relativeDay ($time_t) {
432 if (is_numeric($request->getPref('timeOffset')))
433 $offset = 3600 * $request->getPref('timeOffset');
437 $now = time() + $offset;
438 $today = localtime($now, true);
439 $time = localtime($time_t + $offset, true);
441 if ($time['tm_yday'] == $today['tm_yday'] && $time['tm_year'] == $today['tm_year'])
444 // Note that due to daylight savings chages (and leap seconds), $now minus
445 // 24 hours is not guaranteed to be yesterday.
446 $yesterday = localtime($now - (12 + $today['tm_hour']) * 3600, true);
447 if ($time['tm_yday'] == $yesterday['tm_yday']
448 and $time['tm_year'] == $yesterday['tm_year'])
449 return _("yesterday");
455 * Format the "Author" and "Owner" messages for a page revision.
457 function getOwnerMessage ($page) {
458 if (!ENABLE_PAGEPERM or !class_exists("PagePermission"))
460 $dbi =& $GLOBALS['request']->_dbi;
461 $owner = $page->getOwner();
464 if ( mayAccessPage('change',$page->getName()) )
465 return fmt("Owner: %s", $this->makeActionButton(array('action'=>_("chown"),
466 's' => $page->getName()),
469 if ( $dbi->isWikiPage($owner) )
470 return fmt("Owner: %s", WikiLink($owner));
472 return fmt("Owner: %s", '"'.$owner.'"');
476 /* New behaviour: (by Matt Brown)
477 Prefer author (name) over internal author_id (IP) */
478 function getAuthorMessage ($revision) {
479 if (!$revision) return '';
480 $dbi =& $GLOBALS['request']->_dbi;
481 $author = $revision->get('author');
482 if (!$author) $author = $revision->get('author_id');
483 if (!$author) return '';
484 if ( $dbi->isWikiPage($author) ) {
485 return fmt("by %s", WikiLink($author));
487 return fmt("by %s", '"'.$author.'"');
491 ////////////////////////////////////////////////////////////////
493 // Hooks for other formatting
495 ////////////////////////////////////////////////////////////////
497 //FIXME: PHP 4.1 Warnings
498 //lib/WikiTheme.php:84: Notice[8]: The call_user_method() function is deprecated,
499 //use the call_user_func variety with the array(&$obj, "method") syntax instead
501 function getFormatter ($type, $format) {
502 $method = strtolower("get${type}Formatter");
503 if (method_exists($this, $method))
504 return $this->{$method}($format);
508 ////////////////////////////////////////////////////////////////
512 ////////////////////////////////////////////////////////////////
514 var $_autosplitWikiWords = false;
515 function setAutosplitWikiWords($autosplit=true) {
516 $this->_autosplitWikiWords = $autosplit ? true : false;
519 function maybeSplitWikiWord ($wikiword) {
520 if ($this->_autosplitWikiWords)
521 return SplitPagename($wikiword);
526 var $_anonEditUnknownLinks = true;
527 function setAnonEditUnknownLinks($anonedit=true) {
528 $this->_anonEditUnknownLinks = $anonedit ? true : false;
531 function linkExistingWikiWord($wikiword, $linktext = '', $version = false) {
534 if ($version !== false and !$this->HTML_DUMP_SUFFIX)
535 $url = WikiURL($wikiword, array('version' => $version));
537 $url = WikiURL($wikiword);
539 // Extra steps for dumping page to an html file.
540 if ($this->HTML_DUMP_SUFFIX) {
541 $url = preg_replace('/^\./', '%2e', $url); // dot pages
544 $link = HTML::a(array('href' => $url));
546 if (isa($wikiword, 'WikiPageName'))
547 $default_text = $wikiword->shortName;
549 $default_text = $wikiword;
551 if (!empty($linktext)) {
552 $link->pushContent($linktext);
553 $link->setAttr('class', 'named-wiki');
554 $link->setAttr('title', $this->maybeSplitWikiWord($default_text));
557 $link->pushContent($this->maybeSplitWikiWord($default_text));
558 $link->setAttr('class', 'wiki');
560 if ($request->getArg('frame'))
561 $link->setAttr('target', '_top');
565 function linkUnknownWikiWord($wikiword, $linktext = '') {
568 // Get rid of anchors on unknown wikiwords
569 if (isa($wikiword, 'WikiPageName')) {
570 $default_text = $wikiword->shortName;
571 $wikiword = $wikiword->name;
574 $default_text = $wikiword;
577 if ($this->DUMP_MODE) { // HTML, PDF or XML
578 $link = HTML::u( empty($linktext) ? $wikiword : $linktext);
579 $link->addTooltip(sprintf(_("Empty link to: %s"), $wikiword));
580 $link->setAttr('class', empty($linktext) ? 'wikiunknown' : 'named-wikiunknown');
583 // if AnonEditUnknownLinks show "?" only users which are allowed to edit this page
584 if (! $this->_anonEditUnknownLinks and
585 ( ! $request->_user->isSignedIn()
586 or ! mayAccessPage('edit', $request->getArg('pagename'))))
588 $text = HTML::span( empty($linktext) ? $wikiword : $linktext);
589 $text->setAttr('class', empty($linktext) ? 'wikiunknown' : 'named-wikiunknown');
592 $url = WikiURL($wikiword, array('action' => 'create'));
593 $button = $this->makeButton('?', $url);
594 $button->addTooltip(sprintf(_("Create: %s"), $wikiword));
598 $link = HTML::span();
599 if (!empty($linktext)) {
600 $link->pushContent(HTML::u($linktext));
601 $link->setAttr('class', 'named-wikiunknown');
604 $link->pushContent(HTML::u($this->maybeSplitWikiWord($default_text)));
605 $link->setAttr('class', 'wikiunknown');
607 if (!isa($button, "ImageButton"))
608 $button->setAttr('rel', 'nofollow');
609 $link->pushContent($button);
610 if ($request->getPref('googleLink')) {
611 $gbutton = $this->makeButton('G', "http://www.google.com/search?q="
612 . urlencode($wikiword));
613 $gbutton->addTooltip(sprintf(_("Google:%s"), $wikiword));
614 $link->pushContent($gbutton);
616 if ($request->getArg('frame'))
617 $link->setAttr('target', '_top');
622 function linkBadWikiWord($wikiword, $linktext = '') {
623 global $ErrorManager;
628 elseif (isa($wikiword, 'WikiPageName')) {
629 $text = $wikiword->shortName;
635 if (isa($wikiword, 'WikiPageName'))
636 $message = $wikiword->getWarnings();
638 $message = sprintf(_("'%s': Bad page name"), $wikiword);
639 $ErrorManager->warning($message);
641 return HTML::span(array('class' => 'badwikiword'), $text);
644 ////////////////////////////////////////////////////////////////
648 ////////////////////////////////////////////////////////////////
649 var $_imageAliases = array();
650 var $_imageAlt = array();
654 * (To disable an image, alias the image to <code>false</code>.
656 function addImageAlias ($alias, $image_name) {
657 // fall back to the PhpWiki-supplied image if not found
658 if ((empty($this->_imageAliases[$alias])
659 and $this->_findFile("images/$image_name", true))
660 or $image_name === false)
661 $this->_imageAliases[$alias] = $image_name;
664 function addImageAlt ($alias, $alt_text) {
665 $this->_imageAlt[$alias] = $alt_text;
667 function getImageAlt ($alias) {
668 return $this->_imageAlt[$alias];
671 function getImageURL ($image) {
672 $aliases = &$this->_imageAliases;
674 if (isset($aliases[$image])) {
675 $image = $aliases[$image];
680 // If not extension, default to .png.
681 if (!preg_match('/\.\w+$/', $image))
684 // FIXME: this should probably be made to fall back
685 // automatically to .gif, .jpg.
686 // Also try .gif before .png if browser doesn't like png.
688 $path = $this->_findData("images/$image", 'missing okay');
689 if (!$path) // search explicit images/ or button/ links also
690 $path = $this->_findData("$image", 'missing okay');
692 if ($this->DUMP_MODE) {
693 if (empty($this->dumped_images)) $this->dumped_images = array();
694 $path = "images/". basename($path);
695 if (!in_array($path,$this->dumped_images))
696 $this->dumped_images[] = $path;
701 function setLinkIcon($proto, $image = false) {
705 $this->_linkIcons[$proto] = $image;
708 function getLinkIconURL ($proto) {
709 $icons = &$this->_linkIcons;
710 if (!empty($icons[$proto]))
711 return $this->getImageURL($icons[$proto]);
712 elseif (!empty($icons['*']))
713 return $this->getImageURL($icons['*']);
717 var $_linkIcon = 'front'; // or 'after' or 'no'.
718 // maybe also 'spanall': there is a scheme currently in effect with front, which
719 // spans the icon only to the first, to let the next words wrap on line breaks
720 // see stdlib.php:PossiblyGlueIconToText()
721 function getLinkIconAttr () {
722 return $this->_linkIcon;
724 function setLinkIconAttr ($where) {
725 $this->_linkIcon = $where;
728 function addButtonAlias ($text, $alias = false) {
729 $aliases = &$this->_buttonAliases;
732 $aliases = array_merge($aliases, $text);
733 elseif ($alias === false)
734 unset($aliases[$text]);
736 $aliases[$text] = $alias;
739 function getButtonURL ($text) {
740 $aliases = &$this->_buttonAliases;
741 if (isset($aliases[$text]))
742 $text = $aliases[$text];
744 $qtext = urlencode($text);
745 $url = $this->_findButton("$qtext.png");
746 if ($url && strstr($url, '%')) {
747 $url = preg_replace('|([^/]+)$|e', 'urlencode("\\1")', $url);
749 if (!$url) {// Jeff complained about png not supported everywhere.
750 // This was not PC until 2005.
751 $url = $this->_findButton("$qtext.gif");
752 if ($url && strstr($url, '%')) {
753 $url = preg_replace('|([^/]+)$|e', 'urlencode("\\1")', $url);
756 if ($url and $this->DUMP_MODE) {
757 if (empty($this->dumped_buttons)) $this->dumped_buttons = array();
759 if (defined('DATA_PATH'))
760 $file = substr($url,strlen(DATA_PATH)+1);
761 $url = "images/buttons/".basename($file);
762 if (!array_key_exists($text, $this->dumped_buttons))
763 $this->dumped_buttons[$text] = $file;
768 function _findButton ($button_file) {
769 if (empty($this->_button_path))
770 $this->_button_path = $this->_getButtonPath();
772 foreach ($this->_button_path as $dir) {
773 if ($path = $this->_findData("$dir/$button_file", 1))
779 function _getButtonPath () {
780 $button_dir = $this->_findFile("buttons");
781 $path_dir = $this->_path . $button_dir;
782 if (!file_exists($path_dir) || !is_dir($path_dir))
784 $path = array($button_dir);
786 $dir = dir($path_dir);
787 while (($subdir = $dir->read()) !== false) {
788 if ($subdir[0] == '.')
790 if ($subdir == 'CVS')
792 if (is_dir("$path_dir/$subdir"))
793 $path[] = "$button_dir/$subdir";
796 // add default buttons
797 $path[] = "themes/default/buttons";
798 $path_dir = $this->_path . "themes/default/buttons";
799 $dir = dir($path_dir);
800 while (($subdir = $dir->read()) !== false) {
801 if ($subdir[0] == '.')
803 if ($subdir == 'CVS')
805 if (is_dir("$path_dir/$subdir"))
806 $path[] = "themes/default/buttons/$subdir";
813 ////////////////////////////////////////////////////////////////
817 ////////////////////////////////////////////////////////////////
819 function makeButton ($text, $url, $class = false, $options = false) {
820 // FIXME: don't always try for image button?
822 // Special case: URLs like 'submit:preview' generate form
823 // submission buttons.
824 if (preg_match('/^submit:(.*)$/', $url, $m))
825 return $this->makeSubmitButton($text, $m[1], $class, $options);
827 if (is_string($text))
828 $imgurl = $this->getButtonURL($text);
832 return new ImageButton($text, $url,
833 in_array($class,array("wikiaction","wikiadmin"))?"wikibutton":$class,
836 return new Button($this->maybeSplitWikiWord($text), $url,
840 function makeSubmitButton ($text, $name, $class = false, $options = false) {
841 $imgurl = $this->getButtonURL($text);
844 return new SubmitImageButton($text, $name, !$class ? "wikibutton" : $class, $imgurl, $options);
846 return new SubmitButton($text, $name, $class, $options);
850 * Make button to perform action.
852 * This constructs a button which performs an action on the
853 * currently selected version of the current page.
854 * (Or anotherpage or version, if you want...)
856 * @param $action string The action to perform (e.g. 'edit', 'lock').
857 * This can also be the name of an "action page" like 'LikePages'.
858 * Alternatively you can give a hash of query args to be applied
861 * @param $label string Textual label for the button. If left empty,
862 * a suitable name will be guessed.
864 * @param $page_or_rev mixed The page to link to. This can be
865 * given as a string (the page name), a WikiDB_Page object, or as
866 * WikiDB_PageRevision object. If given as a WikiDB_PageRevision
867 * object, the button will link to a specific version of the
868 * designated page, otherwise the button links to the most recent
869 * version of the page.
871 * @return object A Button object.
873 function makeActionButton ($action, $label = false, $page_or_rev = false, $options = false) {
874 extract($this->_get_name_and_rev($page_or_rev));
876 if (is_array($action)) {
878 $action = isset($attr['action']) ? $attr['action'] : 'browse';
881 $attr['action'] = $action;
883 $class = is_safe_action($action) ? 'wikiaction' : 'wikiadmin';
885 $label = $this->_labelForAction($action);
888 $attr['version'] = $version;
890 if ($action == 'browse')
891 unset($attr['action']);
893 $options = $this->fixAccesskey($options);
895 return $this->makeButton($label, WikiURL($pagename, $attr), $class, $options);
898 function tooltipAccessKeyPrefix() {
899 static $tooltipAccessKeyPrefix = null;
900 if ($tooltipAccessKeyPrefix) return $tooltipAccessKeyPrefix;
902 $tooltipAccessKeyPrefix = 'alt';
903 if (isBrowserOpera()) $tooltipAccessKeyPrefix = 'shift-esc';
904 elseif (isBrowserSafari() or browserDetect("Mac") or isBrowserKonqueror())
905 $tooltipAccessKeyPrefix = 'ctrl';
906 // ff2 win and x11 only
907 elseif ((browserDetect("firefox/2") or browserDetect("minefield/3") or browserDetect("SeaMonkey/1.1"))
908 and ((browserDetect("windows") or browserDetect("x11"))))
909 $tooltipAccessKeyPrefix = 'alt-shift';
910 return $tooltipAccessKeyPrefix;
913 /** Define the accesskey in the title only, with ending [p] or [alt-p].
914 * This fixes the prefix in the title and sets the accesskey.
916 function fixAccesskey($attrs) {
917 if (!empty($attrs['title']) and preg_match("/\[(alt-)?(.)\]$/", $attrs['title'], $m))
919 if (empty($attrs['accesskey'])) $attrs['accesskey'] = $m[2];
920 // firefox 'alt-shift', MSIE: 'alt', ... see wikibits.js
921 $attrs['title'] = preg_replace("/\[(alt-)?(.)\]$/", "[".$this->tooltipAccessKeyPrefix()."-\\2]", $attrs['title']);
927 * Make a "button" which links to a wiki-page.
929 * These are really just regular WikiLinks, possibly
930 * disguised (e.g. behind an image button) by the theme.
932 * This method should probably only be used for links
933 * which appear in page navigation bars, or similar places.
935 * Use linkExistingWikiWord, or LinkWikiWord for normal links.
937 * @param $page_or_rev mixed The page to link to. This can be
938 * given as a string (the page name), a WikiDB_Page object, or as
939 * WikiDB_PageRevision object. If given as a WikiDB_PageRevision
940 * object, the button will link to a specific version of the
941 * designated page, otherwise the button links to the most recent
942 * version of the page.
944 * @return object A Button object.
946 function makeLinkButton ($page_or_rev, $label = false, $action = false) {
947 extract($this->_get_name_and_rev($page_or_rev));
949 $args = $version ? array('version' => $version) : false;
950 if ($action) $args['action'] = $action;
952 return $this->makeButton($label ? $label : $pagename,
953 WikiURL($pagename, $args), 'wiki');
956 function _get_name_and_rev ($page_or_rev) {
959 if (empty($page_or_rev)) {
961 $pagename = $request->getArg("pagename");
962 $version = $request->getArg("version");
964 elseif (is_object($page_or_rev)) {
965 if (isa($page_or_rev, 'WikiDB_PageRevision')) {
967 $page = $rev->getPage();
968 if (!$rev->isCurrent()) $version = $rev->getVersion();
971 $page = $page_or_rev;
973 $pagename = $page->getName();
975 elseif (is_numeric($page_or_rev)) {
976 $version = $page_or_rev;
979 $pagename = (string) $page_or_rev;
981 return compact('pagename', 'version');
984 function _labelForAction ($action) {
986 case 'edit': return _("Edit");
987 case 'diff': return _("Diff");
988 case 'logout': return _("Sign Out");
989 case 'login': return _("Sign In");
990 case 'rename': return _("Rename Page");
991 case 'lock': return _("Lock Page");
992 case 'unlock': return _("Unlock Page");
993 case 'remove': return _("Remove Page");
994 case 'purge': return _("Purge Page");
996 // I don't think the rest of these actually get used.
998 // 'upload' 'dumpserial' 'loadfile' 'zip'
1000 return gettext(ucfirst($action));
1004 //----------------------------------------------------------------
1005 var $_buttonSeparator = "\n | ";
1007 function setButtonSeparator($separator) {
1008 $this->_buttonSeparator = $separator;
1011 function getButtonSeparator() {
1012 return $this->_buttonSeparator;
1016 ////////////////////////////////////////////////////////////////
1022 // Based on testing with Galeon 1.2.7 (Mozilla 1.2):
1023 // Automatic media-based style selection (via <link> tags) only
1024 // seems to work for the default style, not for alternate styles.
1028 // <link rel="stylesheet" type="text/css" href="phpwiki.css" />
1029 // <link rel="stylesheet" type="text/css" href="phpwiki-printer.css" media="print" />
1031 // works to make it so that the printer style sheet get used
1032 // automatically when printing (or print-previewing) a page
1033 // (but when only when the default style is selected.)
1037 // <link rel="alternate stylesheet" title="Modern"
1038 // type="text/css" href="phpwiki-modern.css" />
1039 // <link rel="alternate stylesheet" title="Modern"
1040 // type="text/css" href="phpwiki-printer.css" media="print" />
1042 // Result in two "Modern" choices when trying to select alternate style.
1043 // If one selects the first of those choices, one gets phpwiki-modern
1044 // both when browsing and printing. If one selects the second "Modern",
1045 // one gets no CSS when browsing, and phpwiki-printer when printing.
1050 // We should probably move to doing the media based style
1051 // switching in the CSS files themselves using, e.g.:
1053 // @import url(print.css) print;
1055 ////////////////////////////////////////////////////////////////
1057 function _CSSlink($title, $css_file, $media, $is_alt = false) {
1058 // Don't set title on default style. This makes it clear to
1059 // the user which is the default (i.e. most supported) style.
1060 if ($is_alt and isBrowserKonqueror())
1062 $link = HTML::link(array('rel' => $is_alt ? 'alternate stylesheet' : 'stylesheet',
1063 'type' => 'text/css',
1064 'charset' => $GLOBALS['charset'],
1065 'href' => $this->_findData($css_file)));
1067 $link->setAttr('title', $title);
1070 $link->setAttr('media', $media);
1071 if ($this->DUMP_MODE) {
1072 if (empty($this->dumped_css)) $this->dumped_css = array();
1073 if (!in_array($css_file,$this->dumped_css)) $this->dumped_css[] = $css_file;
1074 $link->setAttr('href', basename($link->getAttr('href')));
1080 /** Set default CSS source for this theme.
1082 * To set styles to be used for different media, pass a
1083 * hash for the second argument, e.g.
1085 * $theme->setDefaultCSS('default', array('' => 'normal.css',
1086 * 'print' => 'printer.css'));
1088 * If you call this more than once, the last one called takes
1089 * precedence as the default style.
1091 * @param string $title Name of style (currently ignored, unless
1092 * you call this more than once, in which case, some of the style
1093 * will become alternate (rather than default) styles, and then their
1094 * titles will be used.
1096 * @param mixed $css_files Name of CSS file, or hash containing a mapping
1097 * between media types and CSS file names. Use a key of '' (the empty string)
1098 * to set the default CSS for non-specified media. (See above for an example.)
1100 function setDefaultCSS ($title, $css_files) {
1101 if (!is_array($css_files))
1102 $css_files = array('' => $css_files);
1103 // Add to the front of $this->_css
1104 unset($this->_css[$title]);
1105 $this->_css = array_merge(array($title => $css_files), $this->_css);
1108 /** Set alternate CSS source for this theme.
1110 * @param string $title Name of style.
1111 * @param string $css_files Name of CSS file.
1113 function addAlternateCSS ($title, $css_files) {
1114 if (!is_array($css_files))
1115 $css_files = array('' => $css_files);
1116 $this->_css[$title] = $css_files;
1120 * @return string HTML for CSS.
1122 function getCSS () {
1125 foreach ($this->_css as $title => $css_files) {
1126 ksort($css_files); // move $css_files[''] to front.
1127 foreach ($css_files as $media => $css_file) {
1128 if (!empty($this->DUMP_MODE)) {
1129 if ($media == 'print')
1130 $css[] = $this->_CSSlink($title, $css_file, '', $is_alt);
1132 $css[] = $this->_CSSlink($title, $css_file, $media, $is_alt);
1141 function findTemplate ($name) {
1142 if ($tmp = $this->_findFile("templates/$name.tmpl", 1))
1143 return $this->_path . $tmp;
1145 $f1 = $this->file("templates/$name.tmpl");
1146 //trigger_error("findTemplate($name) pwd: ".getcwd(), E_USER_ERROR);
1147 if (isset($this->_default_theme)) {
1148 $f2 = $this->_default_theme->file("templates/$name.tmpl");
1149 //trigger_error("$f1 nor $f2 found", E_USER_ERROR);
1151 trigger_error("$f1 not found", E_USER_ERROR);
1156 var $_MoreHeaders = array();
1157 function addMoreHeaders ($element) {
1158 $this->_MoreHeaders[] = $element;
1159 if (!empty($this->_headers_printed) and $this->_headers_printed) {
1160 trigger_error(_("Some action(page) wanted to add more headers, but they were already printed.")
1161 ."\n". $element->asXML(),
1167 * Singleton. Only called once, by the head template. See the warning above.
1169 function getMoreHeaders () {
1170 // actionpages cannot add headers, because recursive template expansion
1171 // already expanded the head template before.
1172 $this->_headers_printed = 1;
1173 if (empty($this->_MoreHeaders))
1176 //$out = "<!-- More Headers -->\n";
1177 foreach ($this->_MoreHeaders as $h) {
1179 $out .= printXML($h);
1186 var $_MoreAttr = array();
1187 // new arg: named elements to be able to remove them. such as DoubleClickEdit for htmldumps
1188 function addMoreAttr ($tag, $name, $element) {
1189 // protect from duplicate attr (body jscript: themes, prefs, ...)
1190 static $_attr_cache = array();
1191 $hash = md5($tag."/".$element);
1192 if (!empty($_attr_cache[$hash])) return;
1193 $_attr_cache[$hash] = 1;
1195 if (empty($this->_MoreAttr) or !is_array($this->_MoreAttr[$tag]))
1196 $this->_MoreAttr[$tag] = array($name => $element);
1198 $this->_MoreAttr[$tag][$name] = $element;
1201 function getMoreAttr ($tag) {
1202 if (empty($this->_MoreAttr[$tag]))
1205 foreach ($this->_MoreAttr[$tag] as $name => $element) {
1206 if (is_object($element))
1207 $out .= printXML($element);
1215 * Common Initialisations
1219 * The ->load() method replaces the formerly global code in themeinfo.php.
1220 * Without this you would not be able to derive from other themes.
1224 // CSS file defines fonts, colors and background images for this
1225 // style. The companion '*-heavy.css' file isn't defined, it's just
1226 // expected to be in the same directory that the base style is in.
1228 // This should result in phpwiki-printer.css being used when
1229 // printing or print-previewing with style "PhpWiki" or "MacOSX" selected.
1230 $this->setDefaultCSS('PhpWiki',
1231 array('' => 'phpwiki.css',
1232 'print' => 'phpwiki-printer.css'));
1234 // This allows one to manually select "Printer" style (when browsing page)
1235 // to see what the printer style looks like.
1236 $this->addAlternateCSS(_("Printer"), 'phpwiki-printer.css', 'print, screen');
1237 $this->addAlternateCSS(_("Top & bottom toolbars"), 'phpwiki-topbottombars.css');
1238 $this->addAlternateCSS(_("Modern"), 'phpwiki-modern.css');
1240 if (isBrowserIE()) {
1241 $this->addMoreHeaders($this->_CSSlink(0,
1242 $this->_findFile('IEFixes.css'),'all'));
1243 $this->addMoreHeaders("\n");
1247 * The logo image appears on every page and links to the HomePage.
1249 $this->addImageAlias('logo', WIKI_NAME . 'Logo.png');
1251 $this->addImageAlias('search', 'search.png');
1254 * The Signature image is shown after saving an edited page. If this
1255 * is set to false then the "Thank you for editing..." screen will
1259 $this->addImageAlias('signature', WIKI_NAME . "Signature.png");
1260 // Uncomment this next line to disable the signature.
1261 //$this->addImageAlias('signature', false);
1266 $this->setLinkIcon('http');
1267 $this->setLinkIcon('https');
1268 $this->setLinkIcon('ftp');
1269 $this->setLinkIcon('mailto');
1270 $this->setLinkIcon('interwiki');
1271 $this->setLinkIcon('wikiuser');
1272 $this->setLinkIcon('*', 'url');
1274 $this->setButtonSeparator("\n | ");
1277 * WikiWords can automatically be split by inserting spaces between
1278 * the words. The default is to leave WordsSmashedTogetherLikeSo.
1280 $this->setAutosplitWikiWords(false);
1283 * Layout improvement with dangling links for mostly closed wiki's:
1284 * If false, only users with edit permissions will be presented the
1285 * special wikiunknown class with "?" and Tooltip.
1286 * If true (default), any user will see the ?, but will be presented
1287 * the PrintLoginForm on a click.
1289 //$this->setAnonEditUnknownLinks(false);
1292 * You may adjust the formats used for formatting dates and times
1293 * below. (These examples give the default formats.)
1294 * Formats are given as format strings to PHP strftime() function See
1295 * http://www.php.net/manual/en/function.strftime.php for details.
1296 * Do not include the server's zone (%Z), times are converted to the
1299 * Suggestion for french:
1300 * $this->setDateFormat("%A %e %B %Y");
1301 * $this->setTimeFormat("%H:%M:%S");
1302 * Suggestion for capable php versions, using the server locale:
1303 * $this->setDateFormat("%x");
1304 * $this->setTimeFormat("%X");
1306 //$this->setDateFormat("%B %d, %Y");
1307 //$this->setTimeFormat("%I:%M %p");
1310 * To suppress times in the "Last edited on" messages, give a
1311 * give a second argument of false:
1313 //$this->setDateFormat("%B %d, %Y", false);
1317 * Custom UserPreferences:
1318 * A list of name => _UserPreference class pairs.
1319 * Rationale: Certain themes should be able to extend the predefined list
1320 * of preferences. Display/editing is done in the theme specific userprefs.tmpl
1321 * but storage/sanification/update/... must be extended to the Get/SetPreferences methods.
1322 * See themes/wikilens/themeinfo.php
1324 //$this->customUserPreference();
1327 * Register custom PageList type and define custom PageList classes.
1328 * Rationale: Certain themes should be able to extend the predefined list
1329 * of pagelist types. E.g. certain plugins, like MostPopular might use
1330 * info=pagename,hits,rating
1331 * which displays the rating column whenever the wikilens theme is active.
1332 * See themes/wikilens/themeinfo.php
1334 //$this->addPageListColumn();
1339 * Custom UserPreferences:
1340 * A list of name => _UserPreference class pairs.
1341 * Rationale: Certain themes should be able to extend the predefined list
1342 * of preferences. Display/editing is done in the theme specific userprefs.tmpl
1343 * but storage/sanification/update/... must be extended to the Get/SetPreferences methods.
1344 * These values are just ignored if another theme is used.
1346 function customUserPreferences($array) {
1347 global $customUserPreferenceColumns; // FIXME: really a global?
1348 if (empty($customUserPreferenceColumns)) $customUserPreferenceColumns = array();
1349 //array('wikilens' => new _UserPreference_wikilens());
1350 foreach ($array as $field => $prefobj) {
1351 $customUserPreferenceColumns[$field] = $prefobj;
1355 /** addPageListColumn(array('rating' => new _PageList_Column_rating('rating', _("Rate"))))
1356 * Register custom PageList types for special themes, like
1357 * 'rating' for wikilens
1359 function addPageListColumn ($array) {
1360 global $customPageListColumns;
1361 if (empty($customPageListColumns)) $customPageListColumns = array();
1362 foreach ($array as $column => $obj) {
1363 $customPageListColumns[$column] = $obj;
1367 // Works only on action=browse. Patch #970004 by pixels
1368 // Usage: call $WikiTheme->initDoubleClickEdit() from theme init or
1369 // define ENABLE_DOUBLECLICKEDIT
1370 function initDoubleClickEdit() {
1371 if (!$this->HTML_DUMP_SUFFIX)
1372 $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';\""));
1375 // Immediate title search results via XMLHTML(HttpRequest)
1376 // by Bitflux GmbH, bitflux.ch. You need to install the livesearch.js seperately.
1377 // Google's or acdropdown is better.
1378 function initLiveSearch() {
1379 //subclasses of Sidebar will init this twice
1380 static $already = 0;
1381 if (!$this->HTML_DUMP_SUFFIX and !$already) {
1382 $this->addMoreAttr('body', 'LiveSearch',
1383 HTML::Raw(" onload=\"liveSearchInit()"));
1384 $this->addMoreHeaders(JavaScript('var liveSearchURI="'
1385 .WikiURL(_("TitleSearch"),false,true).'";'));
1386 $this->addMoreHeaders(JavaScript('', array
1387 ('src' => $this->_findData('livesearch.js'))));
1392 // Immediate title search results via XMLHttpRequest
1393 // using the shipped moacdropdown js-lib
1394 function initMoAcDropDown() {
1395 //subclasses of Sidebar will init this twice
1396 static $already = 0;
1397 if (!$this->HTML_DUMP_SUFFIX and !$already) {
1398 $dir = $this->_findData('moacdropdown');
1399 // if autocomplete_remote is used: (getobject2 also for calc. the showlist width)
1401 foreach (array("mobrowser.js","modomevent3.js","modomt.js",
1402 "modomext.js","getobject2.js","xmlextras.js") as $js)
1404 $this->addMoreHeaders(JavaScript('', array('src' => "$dir/js/$js")));
1406 $this->addMoreHeaders(JavaScript('', array('src' => "$dir/js/acdropdown.js")));
1408 $this->addMoreHeaders(JavaScript('', array('src' => DATA_PATH . "/themes/default/moacdropdown.js")));
1410 //$this->addMoreHeaders($this->_CSSlink(0,
1411 // $this->_findFile('moacdropdown/css/dropdown.css'), 'all'));
1412 $this->addMoreHeaders(HTML::style(" @import url( $dir/css/dropdown.css );\n"));
1414 // for local xmlrpc requests
1415 $xmlrpc_url = deduce_script_name();
1416 //if (1 or DATABASE_TYPE == 'dba')
1417 $xmlrpc_url = DATA_PATH . "/RPC2.php";
1418 if ((DEBUG & _DEBUG_REMOTE) and isset($_GET['start_debug']))
1419 $xmlrpc_url .= ("?start_debug=".$_GET['start_debug']);
1420 $this->addMoreHeaders(JavaScript("var xmlrpc_url = '$xmlrpc_url'"));
1426 function calendarLink($date = false) {
1427 return $this->calendarBase() . SUBPAGE_SEPARATOR .
1428 strftime("%Y-%m-%d", $date ? $date : time());
1431 function calendarBase() {
1432 static $UserCalPageTitle = false;
1435 if (!$UserCalPageTitle)
1436 $UserCalPageTitle = $request->_user->getId() .
1437 SUBPAGE_SEPARATOR . _("Calendar");
1438 if (!$UserCalPageTitle)
1439 $UserCalPageTitle = (BLOG_EMPTY_DEFAULT_PREFIX ? ''
1440 : ($request->_user->getId() . SUBPAGE_SEPARATOR)) . "Blog";
1441 return $UserCalPageTitle;
1444 function calendarInit($force = false) {
1445 $dbi = $GLOBALS['request']->getDbh();
1446 // display flat calender dhtml in the sidebar
1447 if ($force or $dbi->isWikiPage($this->calendarBase())) {
1448 $jslang = @$GLOBALS['LANG'];
1449 $this->addMoreHeaders
1452 $this->_findFile('jscalendar/calendar-phpwiki.css'), 'all'));
1453 $this->addMoreHeaders
1455 array('src' => $this->_findData('jscalendar/calendar'.(DEBUG?'':'_stripped').'.js'))));
1456 if (!($langfile = $this->_findData("jscalendar/lang/calendar-$jslang.js")))
1457 $langfile = $this->_findData("jscalendar/lang/calendar-en.js");
1458 $this->addMoreHeaders(JavaScript('',array('src' => $langfile)));
1459 $this->addMoreHeaders
1462 $this->_findData('jscalendar/calendar-setup'.(DEBUG?'':'_stripped').'.js'))));
1464 // Get existing date entries for the current user
1465 require_once("lib/TextSearchQuery.php");
1466 $iter = $dbi->titleSearch(new TextSearchQuery("^".$this->calendarBase().SUBPAGE_SEPARATOR, true, "auto"));
1467 $existing = array();
1468 while ($page = $iter->next()) {
1469 if ($page->exists())
1470 $existing[] = basename($page->_pagename);
1472 if (!empty($existing)) {
1473 $js_exist = '{"'.join('":1,"',$existing).'":1}';
1474 //var SPECIAL_DAYS = {"2004-05-11":1,"2004-05-12":1,"2004-06-01":1}
1475 $this->addMoreHeaders(JavaScript('
1476 // This table holds the existing calender entries for the current user
1477 // calculated from the database
1478 var SPECIAL_DAYS = '.$js_exist.';
1479 // This function returns true if the date exists in SPECIAL_DAYS
1480 function dateExists(date, y, m, d) {
1481 var year = date.getFullYear();
1483 m = m < 10 ? "0" + m : m; // integer, 0..11
1484 d = d < 10 ? "0" + d : d; // integer, 1..31
1485 var date = year+"-"+m+"-"+d;
1486 var exists = SPECIAL_DAYS[date];
1487 if (!exists) return false;
1490 // This is the actual date status handler.
1491 // Note that it receives the date object as well as separate
1492 // values of year, month and date.
1493 function dateStatusFunc(date, y, m, d) {
1494 if (dateExists(date, y, m, d)) return "existing";
1499 $this->addMoreHeaders(JavaScript('
1500 function dateStatusFunc(date, y, m, d) { return false;}'));
1505 ////////////////////////////////////////////////////////////////
1509 ////////////////////////////////////////////////////////////////
1511 /** CbUserLogin (&$request, $userid)
1512 * Callback when a user logs in
1514 function CbUserLogin (&$request, $userid) {
1518 /** CbNewUserEdit (&$request, $userid)
1519 * Callback when a new user creates or edits a page
1521 function CbNewUserEdit (&$request, $userid) {
1522 ; // i.e. create homepage with Template/UserPage
1525 /** CbNewUserLogin (&$request, $userid)
1526 * Callback when a "new user" logs in.
1527 * What is new? We only record changes, not logins.
1528 * Should we track user actions?
1529 * Let's say a new user is a user without homepage.
1531 function CbNewUserLogin (&$request, $userid) {
1535 /** CbUserLogout (&$request, $userid)
1536 * Callback when a user logs out
1538 function CbUserLogout (&$request, $userid) {
1546 * A class representing a clickable "button".
1548 * In it's simplest (default) form, a "button" is just a link associated
1549 * with some sort of wiki-action.
1551 class Button extends HtmlElement {
1554 * @param $text string The text for the button.
1555 * @param $url string The url (href) for the button.
1556 * @param $class string The CSS class for the button.
1557 * @param $options array Additional attributes for the <input> tag.
1559 function Button ($text, $url, $class=false, $options=false) {
1562 if (check_php_version(5)) {
1563 $this->_init('a', array('href' => $url));
1565 $this->__construct('a', array('href' => $url));
1568 $this->setAttr('class', $class);
1569 if ($request->getArg('frame'))
1570 $this->setAttr('target', '_top');
1571 if (!empty($options) and is_array($options)) {
1572 foreach ($options as $key => $val)
1573 $this->setAttr($key, $val);
1575 // Google honors this
1576 if (in_array(strtolower($text), array('edit','create','diff','pdf'))
1577 and !$request->_user->isAuthenticated())
1578 $this->setAttr('rel', 'nofollow');
1579 $this->pushContent($GLOBALS['WikiTheme']->maybeSplitWikiWord($text));
1586 * A clickable image button.
1588 class ImageButton extends Button {
1591 * @param $text string The text for the button.
1592 * @param $url string The url (href) for the button.
1593 * @param $class string The CSS class for the button.
1594 * @param $img_url string URL for button's image.
1595 * @param $img_attr array Additional attributes for the <img> tag.
1597 function ImageButton ($text, $url, $class, $img_url, $img_attr=false) {
1598 $this->__construct('a', array('href' => $url));
1600 $this->setAttr('class', $class);
1601 // Google honors this
1602 if (in_array(strtolower($text), array('edit','create','diff','pdf'))
1603 and !$GLOBALS['request']->_user->isAuthenticated())
1604 $this->setAttr('rel', 'nofollow');
1606 if (!is_array($img_attr))
1607 $img_attr = array();
1608 $img_attr['src'] = $img_url;
1609 $img_attr['alt'] = $text;
1610 $img_attr['class'] = 'wiki-button';
1611 $img_attr['border'] = 0;
1612 $this->pushContent(HTML::img($img_attr));
1617 * A class representing a form <samp>submit</samp> button.
1619 class SubmitButton extends HtmlElement {
1622 * @param $text string The text for the button.
1623 * @param $name string The name of the form field.
1624 * @param $class string The CSS class for the button.
1625 * @param $options array Additional attributes for the <input> tag.
1627 function SubmitButton ($text, $name=false, $class=false, $options=false) {
1628 $this->__construct('input', array('type' => 'submit',
1631 $this->setAttr('name', $name);
1633 $this->setAttr('class', $class);
1634 if (!empty($options)) {
1635 foreach ($options as $key => $val)
1636 $this->setAttr($key, $val);
1644 * A class representing an image form <samp>submit</samp> button.
1646 class SubmitImageButton extends SubmitButton {
1649 * @param $text string The text for the button.
1650 * @param $name string The name of the form field.
1651 * @param $class string The CSS class for the button.
1652 * @param $img_url string URL for button's image.
1653 * @param $img_attr array Additional attributes for the <img> tag.
1655 function SubmitImageButton ($text, $name=false, $class=false, $img_url, $img_attr=false) {
1656 $this->__construct('input', array('type' => 'image',
1661 $this->setAttr('name', $name);
1663 $this->setAttr('class', $class);
1664 if (!empty($img_attr)) {
1665 foreach ($img_attr as $key => $val)
1666 $this->setAttr($key, $val);
1673 * A sidebar box with title and body, narrow fixed-width.
1674 * To represent abbrevated content of plugins, links or forms,
1675 * like "Getting Started", "Search", "Sarch Pagename",
1676 * "Login", "Menu", "Recent Changes", "Last comments", "Last Blogs"
1678 * ... See http://tikiwiki.org/
1682 * $menu = SidebarBox("Menu",HTML::dl(HTML::dt(...))); $menu->format();
1683 * $menu = PluginSidebarBox("RecentChanges",array('limit'=>10)); $menu->format();
1687 function SidebarBox($title, $body) {
1688 require_once('lib/WikiPlugin.php');
1689 $this->title = $title;
1690 $this->body = $body;
1693 return WikiPlugin::makeBox($this->title, $this->body);
1698 * A sidebar box for plugins.
1699 * Any plugin may provide a box($args=false, $request=false, $basepage=false)
1700 * method, with the help of WikiPlugin::makeBox()
1702 class PluginSidebarBox extends SidebarBox {
1704 var $_plugin, $_args = false, $_basepage = false;
1706 function PluginSidebarBox($name, $args = false, $basepage = false) {
1707 require_once("lib/WikiPlugin.php");
1709 $loader = new WikiPluginLoader();
1710 $plugin = $loader->getPlugin($name);
1712 return $loader->_error(sprintf(_("Plugin %s: undefined"),
1715 if (!method_exists($plugin, 'box')) {
1716 return $loader->_error(sprintf(_("%s: has no box method"),
1717 get_class($plugin)));
1719 $this->_plugin =& $plugin;
1720 $this->_args = $args ? $args : array();
1721 $this->_basepage = $basepage;
1724 function format($args = false) {
1725 return $this->_plugin->box($args ? array_merge($this->_args, $args) : $this->_args,
1726 $GLOBALS['request'],
1731 // Various boxes which are no plugins
1732 class RelatedLinksBox extends SidebarBox {
1733 function RelatedLinksBox($title = false, $body = '', $limit = 20) {
1735 $this->title = $title ? $title : _("Related Links");
1736 $this->body = HTML($body);
1737 $page = $request->getPage($request->getArg('pagename'));
1738 $revision = $page->getCurrentRevision();
1739 $page_content = $revision->getTransformedContent();
1740 //$cache = &$page->_wikidb->_cache;
1742 $sp = HTML::Raw('· ');
1743 foreach ($page_content->getWikiPageLinks() as $link) {
1744 $linkto = $link['linkto'];
1745 if (!$request->_dbi->isWikiPage($linkto)) continue;
1746 $this->body->pushContent($sp, WikiLink($linkto), HTML::br());
1748 if ($limit and $counter > $limit) continue;
1753 class RelatedExternalLinksBox extends SidebarBox {
1754 function RelatedExternalLinksBox($title = false, $body = '', $limit = 20) {
1756 $this->title = $title ? $title : _("External Links");
1757 $this->body = HTML($body);
1758 $page = $request->getPage($request->getArg('pagename'));
1759 $cache = &$page->_wikidb->_cache;
1761 $sp = HTML::Raw('· ');
1762 foreach ($cache->getWikiPageLinks() as $link) {
1763 $linkto = $link['linkto'];
1765 $this->body->pushContent($sp, WikiLink($linkto), HTML::br());
1767 if ($limit and $counter > $limit) continue;
1773 function listAvailableThemes() {
1774 $available_themes = array();
1775 $dir_root = 'themes';
1776 if (defined('PHPWIKI_DIR'))
1777 $dir_root = PHPWIKI_DIR . "/$dir_root";
1778 $dir = dir($dir_root);
1780 while($entry = $dir->read()) {
1781 if (is_dir($dir_root.'/'.$entry)
1782 and file_exists($dir_root.'/'.$entry.'/themeinfo.php'))
1784 array_push($available_themes, $entry);
1789 return $available_themes;
1792 function listAvailableLanguages() {
1793 $available_languages = array('en');
1794 $dir_root = 'locale';
1795 if (defined('PHPWIKI_DIR'))
1796 $dir_root = PHPWIKI_DIR . "/$dir_root";
1797 if ($dir = dir($dir_root)) {
1798 while($entry = $dir->read()) {
1799 if (is_dir($dir_root."/".$entry) and is_dir($dir_root.'/'.$entry.'/LC_MESSAGES'))
1801 array_push($available_languages, $entry);
1806 return $available_languages;
1809 // (c-file-style: "gnu")
1813 // c-basic-offset: 4
1814 // c-hanging-comment-ender-p: nil
1815 // indent-tabs-mode: nil