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)
58 * @var WikiRequest $request
62 if ($type == 'button') {
63 return $WikiTheme->makeLinkButton($page_or_rev, $label);
68 if (is_a($page_or_rev, 'WikiDB_PageRevision')) {
69 $version = $page_or_rev->getVersion();
70 if ($page_or_rev->isCurrent())
72 $page = $page_or_rev->getPage();
73 $pagename = $page->getName();
74 $wikipage = $pagename;
75 } elseif (is_a($page_or_rev, 'WikiDB_Page')) {
77 $pagename = $page->getName();
78 $wikipage = $pagename;
79 } elseif (is_a($page_or_rev, 'WikiPageName')) {
80 $wikipage = $page_or_rev;
81 $pagename = $wikipage->name;
82 if (!$wikipage->isValid('strict'))
83 return $WikiTheme->linkBadWikiWord($wikipage, $label);
85 $wikipage = new WikiPageName($page_or_rev, $request->getPage());
86 $pagename = $wikipage->name;
87 if (!$wikipage->isValid('strict'))
88 return $WikiTheme->linkBadWikiWord($wikipage, $label);
91 if ($type == 'auto' or $type == 'if_known') {
93 $exists = $page->exists();
95 $dbi =& $request->_dbi;
96 $exists = $dbi->isWikiPage($wikipage->name);
98 } elseif ($type == 'unknown') {
104 // FIXME: this should be somewhere else, if really needed.
105 // WikiLink makes A link, not a string of fancy ones.
106 // (I think that the fancy split links are just confusing.)
107 // Todo: test external ImageLinks http://some/images/next.gif
108 if (is_a($wikipage, 'WikiPageName') and
110 strchr(substr($wikipage->shortName, 1), '/')
112 $parts = explode('/', $wikipage->shortName);
113 $last_part = array_pop($parts);
115 $link = HTML::span();
116 foreach ($parts as $part) {
118 $parent = join('/', $path);
119 if ($WikiTheme->getAutosplitWikiWords())
122 $link->pushContent($WikiTheme->linkExistingWikiWord($parent, $sep . $part));
123 $sep = $WikiTheme->getAutosplitWikiWords()
127 $link->pushContent($WikiTheme->linkExistingWikiWord($wikipage, $sep . $last_part,
130 $link->pushContent($WikiTheme->linkUnknownWikiWord($wikipage, $sep . $last_part));
135 return $WikiTheme->linkExistingWikiWord($wikipage, $label, $version);
136 } elseif ($type == 'if_known') {
137 if (!$label && is_a($wikipage, 'WikiPageName'))
138 $label = $wikipage->shortName;
139 return HTML($label ? $label : $pagename);
141 return $WikiTheme->linkUnknownWikiWord($wikipage, $label);
148 * This is a convenience function.
150 * @param string $action
152 * <dt>[action]</dt><dd>Perform action (e.g. 'edit') on the selected page.</dd>
153 * <dt>[ActionPage]</dt><dd>Run the actionpage (e.g. 'BackLinks') on the selected page.</dd>
154 * <dt>'submit:'[name]</dt><dd>Make a form submission button with the given name.
155 * ([name] can be blank for a nameless submit button.)</dd>
156 * <dt>a hash</dt><dd>Query args for the action. E.g.<pre>
157 * array('action' => 'diff', 'previous' => 'author')
161 * @param string $label
162 * A label for the button. If ommited, a suitable default (based on the valued of $action)
165 * @param mixed $page_or_rev
166 * Which page (& version) to perform the action on.
168 * <dt>A string</dt><dd>The pagename.</dd>
169 * <dt>A WikiDB_Page object</dt><dd>The page.</dd>
170 * <dt>A WikiDB_PageRevision object</dt><dd>A specific version of the page.</dd>
172 * ($Page_or_rev is ignored for submit buttons.)
174 * @param array $options
178 function Button($action, $label = '', $page_or_rev = false, $options = array())
182 if (!is_array($action) && preg_match('/^submit:(.*)/', $action, $m))
183 return $WikiTheme->makeSubmitButton($label, $m[1], $page_or_rev, $options);
185 return $WikiTheme->makeActionButton($action, $label, $page_or_rev, $options);
188 function ActionButton($action, $label = false, $page_or_rev = false, $options = false)
192 if (is_array($action)) {
194 $act = isset($attr['action']) ? $attr['action'] : 'browse';
197 $class = is_safe_action($act) ? 'named-wiki' : 'wikiadmin';
198 /* if selected action is current then prepend selected */
199 $curract = $request->getArg("action");
200 if ($curract == $act and $curract != 'browse')
201 $class = "selected $class";
202 if (!empty($options['class'])) {
203 if ($curract == 'browse')
204 $class = "$class " . $options['class'];
206 $class = $options['class'];
208 return HTML::li(array('class' => $class),
209 $WikiTheme->makeActionButton($action, $label, $page_or_rev, $options));
214 public $HTML_DUMP_SUFFIX = '';
215 public $DUMP_MODE = false, $dumped_images, $dumped_css;
218 * noinit: Do not initialize unnecessary items in default_theme fallback twice.
219 * @param string $theme_name
220 * @param bool $noinit
222 function WikiTheme($theme_name = 'default', $noinit = false)
225 * @var WikiRequest $request
229 $this->_name = $theme_name;
230 $this->_themes_dir = NormalizeLocalFileName("themes");
231 $this->_path = defined('PHPWIKI_DIR') ? NormalizeLocalFileName("") : "";
232 $this->_theme = "themes/$theme_name";
233 $this->_parents = array();
235 if ($theme_name != 'default') {
237 /* derived classes should search all parent classes */
238 while ($parent = get_parent_class($parent)) {
239 if (strtolower($parent) == 'wikitheme') {
240 $this->_default_theme = new WikiTheme('default', true);
241 $this->_parents[] = $this->_default_theme;
243 $this->_parents[] = new WikiTheme
244 (preg_replace("/^WikiTheme_/i", "", $parent), true);
253 $this->_css = array();
255 // on derived classes do not add headers twice
256 if (count($this->_parents) > 1) {
259 $this->addMoreHeaders(JavaScript('', array('src' => $this->_findData("wikicommon.js"))));
260 if (!(defined('FUSIONFORGE') && FUSIONFORGE)) {
261 // FusionForge already loads this
262 $this->addMoreHeaders(JavaScript('', array('src' => $this->_findData("jquery-1.11.2.min.js"))));
263 $this->addMoreHeaders(JavaScript('', array('src' => $this->_findData("jquery.tablesorter.min.js"))));
266 if ((is_object($request) // guard against unittests
267 and $request->getPref('doubleClickEdit'))
268 or ENABLE_DOUBLECLICKEDIT
270 $this->initDoubleClickEdit();
275 return $this->_path . "$this->_theme/$file";
278 function _findFile($file, $missing_okay = false)
280 if (file_exists($this->file($file)))
281 return "$this->_theme/$file";
283 // FIXME: this is a short-term hack. Delete this after all files
284 // get moved into themes/...
285 // Needed for button paths in parent themes
286 if (file_exists($this->_path . $file))
289 /* Derived classes should search all parent classes */
290 foreach ($this->_parents as $parent) {
291 $path = $parent->_findFile($file, 1);
294 } elseif (0 and DEBUG & (_DEBUG_VERBOSE + _DEBUG_REMOTE)) {
295 trigger_error("$parent->_theme/$file: not found", E_USER_NOTICE);
298 if (isset($this->_default_theme)) {
299 return $this->_default_theme->_findFile($file, $missing_okay);
300 } elseif (!$missing_okay) {
301 trigger_error("$this->_theme/$file: not found", E_USER_NOTICE);
302 if (DEBUG & _DEBUG_TRACE) {
304 printSimpleTrace(debug_backtrace());
311 function _findData($file, $missing_okay = false)
313 if (!string_starts_with($file, "themes")) { // common case
314 $path = $this->_findFile($file, $missing_okay);
317 if (file_exists($file)) {
319 } elseif (defined('DATA_PATH')
320 and file_exists(DATA_PATH . "/$file")
323 } else { // fallback for buttons in parent themes
324 $path = $this->_findFile($file, $missing_okay);
330 $min = preg_replace("/\.(css|js)$/", "-min.\\1", $file);
331 if ($min and ($x = $this->_findFile($min, true))) $path = $x;
334 if (defined('DATA_PATH'))
335 return DATA_PATH . "/$path";
339 ////////////////////////////////////////////////////////////////
341 // Date and Time formatting
343 ////////////////////////////////////////////////////////////////
345 // Note: Windows' implementation of strftime does not include certain
346 // format specifiers, such as %e (for date without leading zeros). In
348 // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_strftime.2c_.wcsftime.asp
349 // As a result, we have to use %d, and strip out leading zeros ourselves.
351 private $dateFormat = "%B %d, %Y";
352 private $timeFormat = "%I:%M %p";
353 private $showModTime = true;
356 * Set format string used for dates.
358 * @param string $fs Format string for dates.
360 * @param bool $show_mod_time If true (default) then times
361 * are included in the messages generated by getLastModifiedMessage(),
362 * otherwise, only the date of last modification will be shown.
364 function setDateFormat($fs, $show_mod_time = true)
366 $this->dateFormat = $fs;
367 $this->showModTime = $show_mod_time;
371 * Set format string used for times.
373 * @param string $fs Format string for times.
375 function setTimeFormat($fs)
377 $this->timeFormat = $fs;
383 * Any time zone offset specified in the users preferences is
384 * taken into account by this method.
386 * @param int $time_t Unix-style time.
388 * @return string The date.
390 function formatDate($time_t)
393 * @var WikiRequest $request
397 $offset_time = $time_t + 3600 * $request->getPref('timeOffset');
398 // strip leading zeros from date elements (ie space followed by zero
399 // or leading 0 as in French "09 mai 2009")
400 return preg_replace('/ 0/', ' ', preg_replace('/^0/', ' ',
401 strftime($this->dateFormat, $offset_time)));
407 * Any time zone offset specified in the users preferences is
408 * taken into account by this method.
410 * @param int $time_t Unix-style time.
412 * @return string The time.
414 function formatTime($time_t)
416 //FIXME: make 24-hour mode configurable?
419 * @var WikiRequest $request
423 $offset_time = $time_t + 3600 * $request->getPref('timeOffset');
424 return preg_replace('/^0/', ' ',
425 strtolower(strftime($this->timeFormat, $offset_time)));
429 * Format a date and time.
431 * Any time zone offset specified in the users preferences is
432 * taken into account by this method.
434 * @param int $time_t Unix-style time.
436 * @return string The date and time.
438 function formatDateTime($time_t)
441 // Do not display "01 January 1970 1:00" for nonexistent pages
444 return $this->formatDate($time_t) . ' ' . $this->formatTime($time_t);
449 * Format a (possibly relative) date.
451 * If enabled in the users preferences, this method might
452 * return a relative day (e.g. 'Today', 'Yesterday').
454 * Any time zone offset specified in the users preferences is
455 * taken into account by this method.
457 * @param int $time_t Unix-style time.
459 * @return string The day.
461 function getDay($time_t)
464 * @var WikiRequest $request
468 if ($request->getPref('relativeDates') && ($date = $this->_relativeDay($time_t))) {
469 return ucfirst($date);
471 return $this->formatDate($time_t);
475 * Format the "last modified" message for a page revision.
477 * @param object $revision A WikiDB_PageRevision object.
479 * @param string $show_version Should the page version number
480 * be included in the message. (If this argument is omitted,
481 * then the version number will be shown only iff the revision
482 * is not the current one.
484 * @return string The "last modified" message.
486 function getLastModifiedMessage($revision, $show_version = 'auto')
489 * @var WikiRequest $request
496 // dates >= this are considered invalid.
497 if (!defined('EPOCH'))
498 define('EPOCH', 0); // seconds since ~ January 1 1970
500 $mtime = $revision->get('mtime');
502 return _("Never edited");
504 if ($show_version == 'auto')
505 $show_version = !$revision->isCurrent();
507 if ($request->getPref('relativeDates') && ($date = $this->_relativeDay($mtime))) {
508 if ($this->showModTime)
509 $date = sprintf(_("%s at %s"),
510 $date, $this->formatTime($mtime));
513 return fmt("Version %s, saved on %s", $revision->getVersion(), $date);
515 return fmt("Last edited on %s", $date);
518 if ($this->showModTime)
519 $date = $this->formatDateTime($mtime);
521 $date = $this->formatDate($mtime);
524 return fmt("Version %s, saved on %s", $revision->getVersion(), $date);
526 return fmt("Last edited on %s", $date);
529 private function _relativeDay($time_t)
532 * @var WikiRequest $request
536 if (is_numeric($request->getPref('timeOffset')))
537 $offset = 3600 * $request->getPref('timeOffset');
541 $now = time() + $offset;
542 $today = localtime($now, true);
543 $time = localtime($time_t + $offset, true);
545 if ($time['tm_yday'] == $today['tm_yday'] && $time['tm_year'] == $today['tm_year'])
548 // Note that due to daylight savings chages (and leap seconds), $now minus
549 // 24 hours is not guaranteed to be yesterday.
550 $yesterday = localtime($now - (12 + $today['tm_hour']) * 3600, true);
551 if ($time['tm_yday'] == $yesterday['tm_yday']
552 and $time['tm_year'] == $yesterday['tm_year']
554 return _("yesterday");
560 * Format the "Author" and "Owner" messages for a page revision.
562 * @param WikiDB_Page $page
565 function getOwnerMessage($page)
568 * @var WikiRequest $request
572 if (!ENABLE_PAGEPERM or !class_exists("PagePermission"))
574 $dbi =& $request->_dbi;
575 $owner = $page->getOwner();
578 if ( mayAccessPage('change',$page->getName()) )
579 return fmt("Owner: %s", $this->makeActionButton(array('action'=>_("chown"),
580 's' => $page->getName()),
583 if ($dbi->isWikiPage($owner))
584 return fmt("Owner: %s", WikiLink($owner));
586 return fmt("Owner: %s", '"' . $owner . '"');
591 /* New behaviour: (by Matt Brown)
592 Prefer author (name) over internal author_id (IP) */
593 function getAuthorMessage($revision)
596 * @var WikiRequest $request
602 $dbi =& $request->_dbi;
603 $author = $revision->get('author');
605 $author = $revision->get('author_id');
608 if ($dbi->isWikiPage($author)) {
609 return fmt("by %s", WikiLink($author));
611 return fmt("by %s", '"' . $author . '"');
615 ////////////////////////////////////////////////////////////////
617 // Hooks for other formatting
619 ////////////////////////////////////////////////////////////////
621 function getFormatter($type, $format)
623 $method = strtolower("get${type}Formatter");
624 if (method_exists($this, $method))
625 return $this->{$method}($format);
629 ////////////////////////////////////////////////////////////////
633 ////////////////////////////////////////////////////////////////
635 private $autosplitWikiWords = false;
637 function setAutosplitWikiWords($autosplit = true)
639 $this->autosplitWikiWords = $autosplit ? true : false;
642 function getAutosplitWikiWords()
644 return $this->autosplitWikiWords;
647 function maybeSplitWikiWord($wikiword)
649 if ($this->autosplitWikiWords)
650 return SplitPagename($wikiword);
655 private $anonEditUnknownLinks = true;
657 function setAnonEditUnknownLinks($anonedit = true)
659 $this->anonEditUnknownLinks = $anonedit ? true : false;
662 function linkExistingWikiWord($wikiword, $linktext = '', $version = false)
664 if ($version !== false and !$this->HTML_DUMP_SUFFIX)
665 $url = WikiURL($wikiword, array('version' => $version));
667 $url = WikiURL($wikiword);
669 // Extra steps for dumping page to an html file.
670 if ($this->HTML_DUMP_SUFFIX) {
671 $url = preg_replace('/^\./', '%2e', $url); // dot pages
674 $link = HTML::a(array('href' => $url));
676 if (is_a($wikiword, 'WikiPageName'))
677 $default_text = $wikiword->shortName;
679 $default_text = $wikiword;
681 if (!empty($linktext)) {
682 $link->pushContent($linktext);
683 $link->setAttr('class', 'named-wiki');
684 $link->setAttr('title', $this->maybeSplitWikiWord($default_text));
686 $link->pushContent($this->maybeSplitWikiWord($default_text));
687 $link->setAttr('class', 'wiki');
692 function linkUnknownWikiWord($wikiword, $linktext = '')
695 * @var WikiRequest $request
699 // Get rid of anchors on unknown wikiwords
700 if (is_a($wikiword, 'WikiPageName')) {
701 $default_text = $wikiword->shortName;
702 $wikiword = $wikiword->name;
704 $default_text = $wikiword;
707 if ($this->DUMP_MODE) { // HTML, PDF or XML
708 $link = HTML::span(empty($linktext) ? $wikiword : $linktext);
709 $link->setAttr('style', 'text-decoration: underline');
710 $link->addTooltip(sprintf(_("Empty link to: %s"), $wikiword));
711 $link->setAttr('class', empty($linktext) ? 'wikiunknown' : 'named-wikiunknown');
714 // if AnonEditUnknownLinks show "?" only users which are allowed to edit this page
715 if (!$this->anonEditUnknownLinks and
716 (!$request->_user->isSignedIn()
717 or !mayAccessPage('edit', $request->getArg('pagename')))
719 $text = HTML::span(empty($linktext) ? $wikiword : $linktext);
720 $text->setAttr('class', empty($linktext) ? 'wikiunknown' : 'named-wikiunknown');
723 $url = WikiURL($wikiword, array('action' => 'create'));
724 $button = $this->makeButton('?', $url);
725 $button->addTooltip(sprintf(_("Create: %s"), $wikiword));
729 $link = HTML::span();
730 if (!empty($linktext)) {
731 $link->pushContent(HTML::span($linktext));
732 $link->setAttr('style', 'text-decoration: underline');
733 $link->setAttr('class', 'named-wikiunknown');
735 $link->pushContent(HTML::span($this->maybeSplitWikiWord($default_text)));
736 $link->setAttr('style', 'text-decoration: underline');
737 $link->setAttr('class', 'wikiunknown');
739 if (!is_a($button, "ImageButton"))
740 $button->setAttr('rel', 'nofollow');
741 $link->pushContent($button);
742 if ($request->getPref('googleLink')) {
743 $gbutton = $this->makeButton('G', "http://www.google.com/search?q="
744 . urlencode($wikiword));
745 $gbutton->addTooltip(sprintf(_("Google:%s"), $wikiword));
746 $link->pushContent($gbutton);
751 function linkBadWikiWord($wikiword, $linktext = '')
753 global $ErrorManager;
757 } elseif (is_a($wikiword, 'WikiPageName')) {
758 $text = $wikiword->shortName;
763 if (is_a($wikiword, 'WikiPageName'))
764 $message = $wikiword->getWarnings();
766 $message = sprintf(_("“%s”: Bad page name"), $wikiword);
767 $ErrorManager->warning($message);
769 return HTML::span(array('class' => 'badwikiword'), $text);
772 ////////////////////////////////////////////////////////////////
776 ////////////////////////////////////////////////////////////////
777 private $imageAliases = array();
781 * (To disable an image, alias the image to <code>false</code>.
783 function addImageAlias($alias, $image_name)
785 // fall back to the PhpWiki-supplied image if not found
786 if ((empty($this->imageAliases[$alias])
787 and $this->_findFile("images/$image_name", true))
788 or $image_name === false
790 $this->imageAliases[$alias] = $image_name;
793 function getImageURL($image)
795 $aliases = &$this->imageAliases;
797 if (isset($aliases[$image])) {
798 $image = $aliases[$image];
803 // If not extension, default to .png.
804 if (!preg_match('/\.\w+$/', $image))
807 // FIXME: this should probably be made to fall back
808 // automatically to .gif, .jpg.
809 // Also try .gif before .png if browser doesn't like png.
811 $path = $this->_findData("images/$image", 'missing okay');
812 if (!$path) // search explicit images/ or button/ links also
813 $path = $this->_findData("$image", 'missing okay');
815 if ($this->DUMP_MODE) {
816 if (empty($this->dumped_images)) $this->dumped_images = array();
817 $path = "images/" . basename($path);
818 if (!in_array($path, $this->dumped_images))
819 $this->dumped_images[] = $path;
826 function setLinkIcon($proto, $image = false)
831 $this->linkIcons[$proto] = $image;
834 function getLinkIconURL($proto)
836 $icons = &$this->linkIcons;
837 if (!empty($icons[$proto]))
838 return $this->getImageURL($icons[$proto]);
839 elseif (!empty($icons['*']))
840 return $this->getImageURL($icons['*']);
844 private $linkIcon = 'front'; // or 'after' or 'no'.
845 // maybe also 'spanall': there is a scheme currently in effect with front, which
846 // spans the icon only to the first, to let the next words wrap on line breaks
847 // see stdlib.php:PossiblyGlueIconToText()
848 function getLinkIconAttr()
850 return $this->linkIcon;
853 function setLinkIconAttr($where)
855 $this->linkIcon = $where;
858 private $buttonAliases;
860 function addButtonAlias($text, $alias = false)
862 $aliases = &$this->buttonAliases;
865 $aliases = array_merge($aliases, $text);
866 elseif ($alias === false)
867 unset($aliases[$text]); else
868 $aliases[$text] = $alias;
871 public $dumped_buttons;
873 function getButtonURL($text)
875 $aliases = &$this->buttonAliases;
876 if (isset($aliases[$text]))
877 $text = $aliases[$text];
879 $qtext = urlencode($text);
880 $url = $this->_findButton("$qtext.png");
881 if ($url && strstr($url, '%')) {
882 $url = preg_replace('|([^/]+)$|e', 'urlencode("\\1")', $url);
884 if (!$url) { // Jeff complained about png not supported everywhere.
885 // This was not PC until 2005.
886 $url = $this->_findButton("$qtext.gif");
887 if ($url && strstr($url, '%')) {
888 $url = preg_replace('|([^/]+)$|e', 'urlencode("\\1")', $url);
891 if ($url and $this->DUMP_MODE) {
892 if (empty($this->dumped_buttons)) $this->dumped_buttons = array();
894 if (defined('DATA_PATH'))
895 $file = substr($url, strlen(DATA_PATH) + 1);
896 $url = "images/buttons/" . basename($file);
897 if (!array_key_exists($text, $this->dumped_buttons))
898 $this->dumped_buttons[$text] = $file;
903 private $button_path;
905 private function _findButton($button_file)
907 if (empty($this->button_path))
908 $this->button_path = $this->_getButtonPath();
910 foreach ($this->button_path as $dir) {
911 if ($path = $this->_findData("$dir/$button_file", 1))
917 private function _getButtonPath()
919 $button_dir = $this->_findFile("buttons");
920 $path_dir = $this->_path . $button_dir;
921 if (!file_exists($path_dir) || !is_dir($path_dir))
923 $path = array($button_dir);
925 $dir = dir($path_dir);
926 while (($subdir = $dir->read()) !== false) {
927 if ($subdir[0] == '.')
929 if (is_dir("$path_dir/$subdir"))
930 $path[] = "$button_dir/$subdir";
933 // add default buttons
934 $path[] = "themes/default/buttons";
935 $path_dir = $this->_path . "themes/default/buttons";
936 $dir = dir($path_dir);
937 while (($subdir = $dir->read()) !== false) {
938 if ($subdir[0] == '.')
940 if (is_dir("$path_dir/$subdir"))
941 $path[] = "themes/default/buttons/$subdir";
948 ////////////////////////////////////////////////////////////////
952 ////////////////////////////////////////////////////////////////
954 function makeButton($text, $url, $class = false, $options = array())
956 // FIXME: don't always try for image button?
958 // Special case: URLs like 'submit:preview' generate form
959 // submission buttons.
960 if (preg_match('/^submit:(.*)$/', $url, $m))
961 return $this->makeSubmitButton($text, $m[1], $class, $options);
963 if (is_string($text))
964 $imgurl = $this->getButtonURL($text);
968 return new ImageButton($text, $url,
969 in_array($class, array("wikiaction", "wikiadmin")) ? "wikibutton" : $class,
972 return new Button($this->maybeSplitWikiWord($text), $url,
976 function makeSubmitButton($text, $name, $class = false, $options = array())
978 $imgurl = $this->getButtonURL($text);
981 return new SubmitImageButton($text, $name, !$class ? "wikibutton" : $class, $imgurl, $options);
983 return new SubmitButton($text, $name, $class, $options);
987 * Make button to perform action.
989 * This constructs a button which performs an action on the
990 * currently selected version of the current page.
991 * (Or anotherpage or version, if you want...)
993 * @param $action string The action to perform (e.g. 'edit', 'lock').
994 * This can also be the name of an "action page" like 'LikePages'.
995 * Alternatively you can give a hash of query args to be applied
998 * @param $label string Textual label for the button. If left empty,
999 * a suitable name will be guessed.
1001 * @param $page_or_rev mixed The page to link to. This can be
1002 * given as a string (the page name), a WikiDB_Page object, or as
1003 * WikiDB_PageRevision object. If given as a WikiDB_PageRevision
1004 * object, the button will link to a specific version of the
1005 * designated page, otherwise the button links to the most recent
1006 * version of the page.
1008 * @param array $options
1010 * @return object A Button object.
1012 function makeActionButton($action, $label = '',
1013 $page_or_rev = false, $options = array())
1015 extract($this->_get_name_and_rev($page_or_rev));
1017 if (is_array($action)) {
1019 $action = isset($attr['action']) ? $attr['action'] : 'browse';
1021 $attr['action'] = $action;
1023 $class = is_safe_action($action) ? 'wikiaction' : 'wikiadmin';
1025 $label = $this->_labelForAction($action);
1028 $attr['version'] = $version;
1030 if ($action == 'browse')
1031 unset($attr['action']);
1033 $options = $this->fixAccesskey($options);
1035 return $this->makeButton($label, WikiURL($pagename, $attr), $class, $options);
1038 function tooltipAccessKeyPrefix()
1040 static $tooltipAccessKeyPrefix = null;
1041 if ($tooltipAccessKeyPrefix) return $tooltipAccessKeyPrefix;
1043 $tooltipAccessKeyPrefix = 'alt';
1044 if (isBrowserOpera()) $tooltipAccessKeyPrefix = 'shift-esc';
1045 elseif (isBrowserSafari() or browserDetect("Mac") or isBrowserKonqueror())
1046 $tooltipAccessKeyPrefix = 'ctrl'; // ff2 win and x11 only
1047 elseif ((browserDetect("firefox/2") or browserDetect("minefield/3") or browserDetect("SeaMonkey/1.1"))
1048 and ((browserDetect("windows") or browserDetect("x11")))
1050 $tooltipAccessKeyPrefix = 'alt-shift';
1051 return $tooltipAccessKeyPrefix;
1055 * Define the access key in the title only, with ending [p] or [alt-p].
1056 * This fixes the prefix in the title and sets the access key.
1058 function fixAccesskey($attrs)
1060 if (!empty($attrs['title']) and preg_match("/\[(alt-)?(.)\]$/", $attrs['title'], $m)) {
1061 if (empty($attrs['accesskey'])) $attrs['accesskey'] = $m[2];
1062 // firefox 'alt-shift', MSIE: 'alt', ... see wikibits.js
1063 $attrs['title'] = preg_replace("/\[(alt-)?(.)\]$/", "[" . $this->tooltipAccessKeyPrefix() . "-\\2]", $attrs['title']);
1069 * Make a "button" which links to a wiki-page.
1071 * These are really just regular WikiLinks, possibly
1072 * disguised (e.g. behind an image button) by the theme.
1074 * This method should probably only be used for links
1075 * which appear in page navigation bars, or similar places.
1077 * Use linkExistingWikiWord, or LinkWikiWord for normal links.
1079 * @param mixed $page_or_rev The page to link to. This can be
1080 * given as a string (the page name), a WikiDB_Page object, or as
1081 * WikiDB_PageRevision object. If given as a WikiDB_PageRevision
1082 * object, the button will link to a specific version of the
1083 * designated page, otherwise the button links to the most recent
1084 * version of the page.
1086 * @param string $label
1088 * @param string $action
1090 * @return object A Button object.
1092 function makeLinkButton($page_or_rev, $label = '', $action = '')
1094 extract($this->_get_name_and_rev($page_or_rev));
1096 $args = $version ? array('version' => $version) : false;
1097 if ($action) $args['action'] = $action;
1099 return $this->makeButton($label ? $label : $pagename,
1100 WikiURL($pagename, $args), 'wiki');
1103 protected function _get_name_and_rev($page_or_rev)
1107 if (empty($page_or_rev)) {
1109 * @var WikiRequest $request
1112 $pagename = $request->getArg("pagename");
1113 $version = $request->getArg("version");
1114 } elseif (is_object($page_or_rev)) {
1115 if (is_a($page_or_rev, 'WikiDB_PageRevision')) {
1116 $rev = $page_or_rev;
1117 $page = $rev->getPage();
1118 if (!$rev->isCurrent()) $version = $rev->getVersion();
1120 $page = $page_or_rev;
1122 $pagename = $page->getName();
1124 $pagename = (string)$page_or_rev;
1126 return compact('pagename', 'version');
1129 protected function _labelForAction($action)
1137 return _("Sign Out");
1139 return _("Sign In");
1141 return _("Rename Page");
1143 return _("Lock Page");
1145 return _("Unlock Page");
1147 return _("Remove Page");
1149 return _("Purge Page");
1151 // I don't think the rest of these actually get used.
1153 // 'upload' 'dumpserial' 'loadfile' 'zip'
1155 return gettext(ucfirst($action));
1159 //----------------------------------------------------------------
1160 private $buttonSeparator = "\n | ";
1162 function setButtonSeparator($separator)
1164 $this->buttonSeparator = $separator;
1167 function getButtonSeparator()
1169 return $this->buttonSeparator;
1172 ////////////////////////////////////////////////////////////////
1178 // Based on testing with Galeon 1.2.7 (Mozilla 1.2):
1179 // Automatic media-based style selection (via <link> tags) only
1180 // seems to work for the default style, not for alternate styles.
1184 // <link rel="stylesheet" type="text/css" href="phpwiki.css" />
1185 // <link rel="stylesheet" type="text/css" href="phpwiki-printer.css" media="print" />
1187 // works to make it so that the printer style sheet get used
1188 // automatically when printing (or print-previewing) a page
1189 // (but when only when the default style is selected.)
1193 // <link rel="alternate stylesheet" title="Modern"
1194 // type="text/css" href="phpwiki-modern.css" />
1195 // <link rel="alternate stylesheet" title="Modern"
1196 // type="text/css" href="phpwiki-printer.css" media="print" />
1198 // Result in two "Modern" choices when trying to select alternate style.
1199 // If one selects the first of those choices, one gets phpwiki-modern
1200 // both when browsing and printing. If one selects the second "Modern",
1201 // one gets no CSS when browsing, and phpwiki-printer when printing.
1206 // We should probably move to doing the media based style
1207 // switching in the CSS files themselves using, e.g.:
1209 // @import url(print.css) print;
1211 ////////////////////////////////////////////////////////////////
1213 protected function _CSSlink($title, $css_file, $media, $is_alt = false)
1215 // Don't set title on default style. This makes it clear to
1216 // the user which is the default (i.e. most supported) style.
1217 if ($is_alt and isBrowserKonqueror())
1219 $link = HTML::link(array('rel' => $is_alt ? 'alternate stylesheet' : 'stylesheet',
1220 'type' => 'text/css',
1221 'href' => $this->_findData($css_file)));
1223 $link->setAttr('title', $title);
1226 $link->setAttr('media', $media);
1227 if ($this->DUMP_MODE) {
1228 if (empty($this->dumped_css)) $this->dumped_css = array();
1229 if (!in_array($css_file, $this->dumped_css)) $this->dumped_css[] = $css_file;
1230 $link->setAttr('href', basename($link->getAttr('href')));
1236 /** Set default CSS source for this theme.
1238 * To set styles to be used for different media, pass a
1239 * hash for the second argument, e.g.
1241 * $theme->setDefaultCSS('default', array('' => 'normal.css',
1242 * 'print' => 'printer.css'));
1244 * If you call this more than once, the last one called takes
1245 * precedence as the default style.
1247 * @param string $title Name of style (currently ignored, unless
1248 * you call this more than once, in which case, some of the style
1249 * will become alternate (rather than default) styles, and then their
1250 * titles will be used.
1252 * @param mixed $css_files Name of CSS file, or hash containing a mapping
1253 * between media types and CSS file names. Use a key of '' (the empty string)
1254 * to set the default CSS for non-specified media. (See above for an example.)
1256 protected function setDefaultCSS($title, $css_files)
1258 if (!is_array($css_files))
1259 $css_files = array('' => $css_files);
1260 // Add to the front of $this->_css
1261 unset($this->_css[$title]);
1262 $this->_css = array_merge(array($title => $css_files), $this->_css);
1265 /** Set alternate CSS source for this theme.
1267 * @param string $title Name of style.
1268 * @param string $css_files Name of CSS file.
1270 protected function addAlternateCSS($title, $css_files)
1272 if (!is_array($css_files))
1273 $css_files = array('' => $css_files);
1274 $this->_css[$title] = $css_files;
1278 * @return string HTML for CSS.
1284 foreach ($this->_css as $title => $css_files) {
1285 ksort($css_files); // move $css_files[''] to front.
1286 foreach ($css_files as $media => $css_file) {
1287 if (!empty($this->DUMP_MODE)) {
1288 if ($media == 'print')
1289 $css[] = $this->_CSSlink($title, $css_file, '', $is_alt);
1291 $css[] = $this->_CSSlink($title, $css_file, $media, $is_alt);
1300 function findTemplate($name)
1302 if ($tmp = $this->_findFile("templates/$name.tmpl", 1))
1303 return $this->_path . $tmp;
1305 $f1 = $this->file("templates/$name.tmpl");
1306 foreach ($this->_parents as $parent) {
1307 if ($tmp = $parent->_findFile("templates/$name.tmpl", 1))
1308 return $this->_path . $tmp;
1310 trigger_error("$f1 not found", E_USER_ERROR);
1315 public $_headers_printed;
1317 * Add a random header element to head
1318 * TODO: first css, then js. Maybe separate it into addJSHeaders/addCSSHeaders
1319 * or use an optional type argument, and separate it within _MoreHeaders[]
1321 function addMoreHeaders($element)
1324 * @var WikiRequest $request
1328 $request->_MoreHeaders[] = $element;
1329 if (!empty($this->_headers_printed) and $this->_headers_printed) {
1330 trigger_error(_("Some action(page) wanted to add more headers, but they were already printed.")
1331 . "\n" . $element->asXML(),
1337 * Singleton. Only called once, by the head template. See the warning above.
1339 function getMoreHeaders()
1342 * @var WikiRequest $request
1346 // actionpages cannot add headers, because recursive template expansion
1347 // already expanded the head template before.
1348 $this->_headers_printed = 1;
1349 if (empty($request->_MoreHeaders))
1352 if (false and ($file = $this->_findData('delayed.js'))) {
1353 $request->_MoreHeaders[] = JavaScript('
1354 // Add a script element as a child of the body
1355 function downloadJSAtOnload() {
1356 var element = document.createElement("script");
1357 element.src = "' . $file . '";
1358 document.body.appendChild(element);
1360 // Check for browser support of event handling capability
1361 if (window.addEventListener)
1362 window.addEventListener("load", downloadJSAtOnload, false);
1363 else if (window.attachEvent)
1364 window.attachEvent("onload", downloadJSAtOnload);
1365 else window.onload = downloadJSAtOnload;');
1367 //$out = "<!-- More Headers -->\n";
1368 foreach ($request->_MoreHeaders as $h) {
1370 $out .= $h->printXML();
1377 // new arg: named elements to be able to remove them. such as DoubleClickEdit for htmldumps
1378 function addMoreAttr($tag, $name, $element)
1381 * @var WikiRequest $request
1384 // protect from duplicate attr (body jscript: themes, prefs, ...)
1385 static $_attr_cache = array();
1386 $hash = md5($tag . "/" . $element);
1387 if (!empty($_attr_cache[$hash])) return;
1388 $_attr_cache[$hash] = 1;
1390 if (empty($request->_MoreAttr) or !is_array($request->_MoreAttr[$tag]))
1391 $request->_MoreAttr[$tag] = array($name => $element);
1393 $request->_MoreAttr[$tag][$name] = $element;
1396 function getMoreAttr($tag)
1399 * @var WikiRequest $request
1403 if (empty($request->_MoreAttr[$tag]))
1406 foreach ($request->_MoreAttr[$tag] as $name => $element) {
1407 if (is_object($element))
1408 $out .= $element->printXML();
1416 * Common Initialisations
1420 * The ->load() method replaces the formerly global code in themeinfo.php.
1421 * This is run only once for the selected theme, and not for the parent themes.
1422 * Without this you would not be able to derive from other themes.
1427 $this->initGlobals();
1429 // CSS file defines fonts, colors and background images for this
1430 // style. The companion '*-heavy.css' file isn't defined, it's just
1431 // expected to be in the same directory that the base style is in.
1433 // This should result in phpwiki-printer.css being used when
1434 // printing or print-previewing with style "PhpWiki" or "MacOSX" selected.
1435 $this->setDefaultCSS('PhpWiki',
1436 array('' => 'phpwiki.css',
1437 'print' => 'phpwiki-printer.css'));
1439 // This allows one to manually select "Printer" style (when browsing page)
1440 // to see what the printer style looks like.
1441 $this->addAlternateCSS(_("Printer"), 'phpwiki-printer.css', 'print, screen');
1442 $this->addAlternateCSS(_("Top & bottom toolbars"), 'phpwiki-topbottombars.css');
1443 $this->addAlternateCSS(_("Modern"), 'phpwiki-modern.css');
1446 * The logo image appears on every page and links to the HomePage.
1448 $this->addImageAlias('logo', WIKI_NAME . 'Logo.png');
1450 $this->addImageAlias('search', 'search.png');
1453 * The Signature image is shown after saving an edited page. If this
1454 * is set to false then the "Thank you for editing..." screen will
1458 $this->addImageAlias('signature', WIKI_NAME . "Signature.png");
1459 // Uncomment this next line to disable the signature.
1460 //$this->addImageAlias('signature', false);
1465 $this->setLinkIcon('http');
1466 $this->setLinkIcon('https');
1467 $this->setLinkIcon('ftp');
1468 $this->setLinkIcon('mailto');
1469 $this->setLinkIcon('interwiki');
1470 $this->setLinkIcon('wikiuser');
1471 $this->setLinkIcon('*', 'url');
1473 $this->setButtonSeparator("\n | ");
1476 * WikiWords can automatically be split by inserting spaces between
1477 * the words. The default is to leave WordsSmashedTogetherLikeSo.
1479 $this->setAutosplitWikiWords(false);
1482 * Layout improvement with dangling links for mostly closed wiki's:
1483 * If false, only users with edit permissions will be presented the
1484 * special wikiunknown class with "?" and Tooltip.
1485 * If true (default), any user will see the ?, but will be presented
1486 * the PrintLoginForm on a click.
1488 //$this->setAnonEditUnknownLinks(false);
1491 * You may adjust the formats used for formatting dates and times
1492 * below. (These examples give the default formats.)
1493 * Formats are given as format strings to PHP strftime() function See
1494 * http://www.php.net/manual/en/function.strftime.php for details.
1495 * Do not include the server's zone (%Z), times are converted to the
1498 * Suggestion for french:
1499 * $this->setDateFormat("%A %e %B %Y");
1500 * $this->setTimeFormat("%H:%M:%S");
1501 * Suggestion for capable php versions, using the server locale:
1502 * $this->setDateFormat("%x");
1503 * $this->setTimeFormat("%X");
1505 //$this->setDateFormat("%B %d, %Y");
1506 //$this->setTimeFormat("%I:%M %p");
1509 * To suppress times in the "Last edited on" messages, give a
1510 * give a second argument of false:
1512 //$this->setDateFormat("%B %d, %Y", false);
1515 * Custom UserPreferences:
1516 * A list of name => _UserPreference class pairs.
1517 * Rationale: Certain themes should be able to extend the predefined list
1518 * of preferences. Display/editing is done in the theme specific userprefs.tmpl
1519 * but storage/sanification/update/... must be extended to the Get/SetPreferences methods.
1520 * See themes/wikilens/themeinfo.php
1522 //$this->customUserPreference();
1525 * Register custom PageList type and define custom PageList classes.
1526 * Rationale: Certain themes should be able to extend the predefined list
1527 * of pagelist types. E.g. certain plugins, like MostPopular might use
1528 * info=pagename,hits,rating
1529 * which displays the rating column whenever the wikilens theme is active.
1530 * See themes/wikilens/themeinfo.php
1532 //$this->addPageListColumn();
1537 * Custom UserPreferences:
1538 * A list of name => _UserPreference class pairs.
1539 * Rationale: Certain themes should be able to extend the predefined list
1540 * of preferences. Display/editing is done in the theme specific userprefs.tmpl
1541 * but storage/sanification/update/... must be extended to the Get/SetPreferences methods.
1542 * These values are just ignored if another theme is used.
1544 function customUserPreferences($array)
1546 global $customUserPreferenceColumns; // FIXME: really a global?
1547 if (empty($customUserPreferenceColumns)) $customUserPreferenceColumns = array();
1548 //array('wikilens' => new _UserPreference_wikilens());
1549 foreach ($array as $field => $prefobj) {
1550 $customUserPreferenceColumns[$field] = $prefobj;
1555 * addPageListColumn(array('rating' => new _PageList_Column_rating('rating', _("Rate"))))
1556 * Register custom PageList types for special themes, like
1557 * 'rating' for wikilens
1559 function addPageListColumn($array)
1561 global $customPageListColumns;
1562 if (empty($customPageListColumns)) $customPageListColumns = array();
1563 foreach ($array as $column => $obj) {
1564 $customPageListColumns[$column] = $obj;
1568 function initGlobals()
1571 * @var WikiRequest $request
1575 static $already = 0;
1577 $script_url = deduce_script_name();
1578 if ((DEBUG & _DEBUG_REMOTE) and isset($_GET['start_debug']))
1579 $script_url .= ("?start_debug=" . $_GET['start_debug']);
1580 $folderArrowPath = dirname($this->_findData('images/folderArrowLoading.gif'));
1581 $pagename = $request->getArg('pagename');
1582 $js = "var data_path = '" . javascript_quote_string(DATA_PATH) . "';\n"
1583 // XSS warning with pagename
1584 . "var pagename = '" . javascript_quote_string($pagename) . "';\n"
1585 . "var script_url= '" . javascript_quote_string($script_url) . "';\n"
1586 . "var stylepath = data_path+'/" . javascript_quote_string($this->_theme) . "/';\n"
1587 . "var folderArrowPath = '" . javascript_quote_string($folderArrowPath) . "';\n"
1588 . "var use_path_info = " . (USE_PATH_INFO ? "true" : "false") . ";\n";
1589 $this->addMoreHeaders(JavaScript($js));
1594 // Works only on action=browse. Patch #970004 by pixels
1595 // Usage: call $WikiTheme->initDoubleClickEdit() from theme init or
1596 // define ENABLE_DOUBLECLICKEDIT
1597 private function initDoubleClickEdit()
1599 if (!$this->HTML_DUMP_SUFFIX)
1600 $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';\""));
1603 function calendarLink($date = false)
1605 return $this->calendarBase() . '/' .
1606 strftime("%Y-%m-%d", $date ? $date : time());
1609 function calendarBase()
1611 static $UserCalPageTitle = false;
1613 * @var WikiRequest $request
1617 if (!$UserCalPageTitle) {
1618 if (isset($request->_user) && is_a($request->_user, "_WikiUser")) {
1619 $UserCalPageTitle = $request->_user->getId().'/'._("Calendar");
1622 if (!$UserCalPageTitle) {
1623 if (defined('BLOG_DEFAULT_EMPTY_PREFIX') and BLOG_DEFAULT_EMPTY_PREFIX) {
1624 $UserCalPageTitle = "Blog";
1626 $UserCalPageTitle = $request->_user->getId() . '/' . "Blog";
1629 return $UserCalPageTitle;
1632 function calendarInit()
1635 * @var WikiRequest $request
1639 $dbi = $request->getDbh();
1640 // display flat calender dhtml in the sidebar
1641 $jslang = @$GLOBALS['LANG'];
1642 $this->addMoreHeaders(
1644 $this->_findFile('jscalendar/calendar-phpwiki.css'), 'all'));
1645 $this->addMoreHeaders
1647 array('src' => $this->_findData('jscalendar/calendar' . (DEBUG ? '' : '_stripped') . '.js'))));
1648 if (!($langfile = $this->_findData("jscalendar/lang/calendar-$jslang.js")))
1649 $langfile = $this->_findData("jscalendar/lang/calendar-en.js");
1650 $this->addMoreHeaders(JavaScript('', array('src' => $langfile)));
1651 $this->addMoreHeaders
1654 $this->_findData('jscalendar/calendar-setup' . (DEBUG ? '' : '_stripped') . '.js'))));
1656 // Get existing date entries for the current user
1657 require_once 'lib/TextSearchQuery.php';
1658 $iter = $dbi->titleSearch(new TextSearchQuery("^" . $this->calendarBase() . '/', true, "auto"));
1659 $existing = array();
1660 while ($page = $iter->next()) {
1661 if ($page->exists())
1662 $existing[] = basename($page->_pagename);
1664 if (!empty($existing)) {
1665 $js_exist = '{"' . join('":1,"', $existing) . '":1}';
1666 //var SPECIAL_DAYS = {"2004-05-11":1,"2004-05-12":1,"2004-06-01":1}
1667 $this->addMoreHeaders(JavaScript('
1668 /* This table holds the existing calender entries for the current user
1669 * calculated from the database
1672 var SPECIAL_DAYS = ' . javascript_quote_string($js_exist) . ';
1674 /* This function returns true if the date exists in SPECIAL_DAYS */
1675 function dateExists(date, y, m, d) {
1676 var year = date.getFullYear();
1678 m = m < 10 ? "0" + m : m; // integer, 0..11
1679 d = d < 10 ? "0" + d : d; // integer, 1..31
1680 var date = year+"-"+m+"-"+d;
1681 var exists = SPECIAL_DAYS[date];
1682 if (!exists) return false;
1685 // This is the actual date status handler.
1686 // Note that it receives the date object as well as separate
1687 // values of year, month and date.
1688 function dateStatusFunc(date, y, m, d) {
1689 if (dateExists(date, y, m, d)) return "existing";
1694 $this->addMoreHeaders(JavaScript('
1695 function dateStatusFunc(date, y, m, d) { return false;}'));
1699 ////////////////////////////////////////////////////////////////
1703 ////////////////////////////////////////////////////////////////
1706 * CbUserLogin (&$request, $userid)
1707 * Callback when a user logs in
1709 function CbUserLogin(&$request, $userid)
1715 * CbNewUserEdit (&$request, $userid)
1716 * Callback when a new user creates or edits a page
1718 function CbNewUserEdit(&$request, $userid)
1720 ; // i.e. create homepage with Template/UserPage
1724 * CbNewUserLogin (&$request, $userid)
1725 * Callback when a "new user" logs in.
1726 * What is new? We only record changes, not logins.
1727 * Should we track user actions?
1728 * Let's say a new user is a user without homepage.
1730 function CbNewUserLogin(&$request, $userid)
1736 * CbUserLogout (&$request, $userid)
1737 * Callback when a user logs out
1739 function CbUserLogout(&$request, $userid)
1747 * A class representing a clickable "button".
1749 * In its simplest (default) form, a "button" is just a link associated
1750 * with some sort of wiki-action.
1752 class Button extends HtmlElement
1755 * @param string $text The text for the button.
1756 * @param string $url The url (href) for the button.
1757 * @param string $class The CSS class for the button.
1758 * @param array $options Additional attributes for the <input> tag.
1760 function Button($text, $url, $class = '', $options = array())
1763 * @var WikiRequest $request
1767 $this->_init('a', array('href' => $url));
1769 $this->setAttr('class', $class);
1770 if (!empty($options) and is_array($options)) {
1771 foreach ($options as $key => $val)
1772 $this->setAttr($key, $val);
1774 // Google honors this
1775 if (in_array(strtolower($text), array('edit', 'create', 'diff', 'pdf'))
1776 and !$request->_user->isAuthenticated()
1778 $this->setAttr('rel', 'nofollow');
1779 $this->pushContent($GLOBALS['WikiTheme']->maybeSplitWikiWord($text));
1785 * A clickable image button.
1787 class ImageButton extends Button
1791 * @param $text string The text for the button.
1792 * @param $url string The url (href) for the button.
1793 * @param $class string The CSS class for the button.
1794 * @param $img_url string URL for button's image.
1795 * @param $img_attr array Additional attributes for the <img> tag.
1797 function ImageButton($text, $url, $class, $img_url, $img_attr = array())
1800 * @var WikiRequest $request
1804 $this->__construct('a', array('href' => $url));
1806 $this->setAttr('class', $class);
1807 // Google honors this
1808 if (in_array(strtolower($text), array('edit', 'create', 'diff', 'pdf'))
1809 and !$request->_user->isAuthenticated()
1811 $this->setAttr('rel', 'nofollow');
1813 if (!is_array($img_attr))
1814 $img_attr = array();
1815 $img_attr['src'] = $img_url;
1816 $img_attr['alt'] = $text;
1817 $img_attr['class'] = 'wiki-button';
1818 $this->pushContent(HTML::img($img_attr));
1823 * A class representing a form <samp>submit</samp> button.
1825 class SubmitButton extends HtmlElement
1828 * @param $text string The text for the button.
1829 * @param $name string The name of the form field.
1830 * @param $class string The CSS class for the button.
1831 * @param $options array Additional attributes for the <input> tag.
1833 function SubmitButton($text, $name = '', $class = '', $options = array())
1835 $this->__construct('input', array('type' => 'submit', 'value' => $text));
1837 $this->setAttr('name', $name);
1839 $this->setAttr('class', $class);
1840 if (!empty($options)) {
1841 foreach ($options as $key => $val)
1842 $this->setAttr($key, $val);
1849 * A class representing an image form <samp>submit</samp> button.
1851 class SubmitImageButton extends SubmitButton
1854 * @param $text string The text for the button.
1855 * @param $name string The name of the form field.
1856 * @param $class string The CSS class for the button.
1857 * @param $img_url string URL for button's image.
1858 * @param $img_attr array Additional attributes for the <img> tag.
1860 function SubmitImageButton($text, $name = '', $class = '', $img_url, $img_attr = array())
1862 $this->__construct('input', array('type' => 'image',
1866 $this->setAttr('name', $name);
1868 $this->setAttr('class', $class);
1869 if (!empty($img_attr)) {
1870 foreach ($img_attr as $key => $val)
1871 $this->setAttr($key, $val);
1878 * A sidebar box with title and body, narrow fixed-width.
1879 * To represent abbrevated content of plugins, links or forms,
1880 * like "Getting Started", "Search", "Sarch Pagename",
1881 * "Login", "Menu", "Recent Changes", "Last comments", "Last Blogs"
1883 * ... See http://tikiwiki.org/
1887 * $menu = SidebarBox("Menu",HTML::dl(HTML::dt(...))); $menu->format();
1888 * $menu = PluginSidebarBox("RecentChanges",array('limit'=>10)); $menu->format();
1892 function SidebarBox($title, $body)
1894 require_once 'lib/WikiPlugin.php';
1895 $this->title = $title;
1896 $this->body = $body;
1901 return WikiPlugin::makeBox($this->title, $this->body);
1906 * A sidebar box for plugins.
1907 * Any plugin may provide a box($args=false, $request=false, $basepage=false)
1908 * method, with the help of WikiPlugin::makeBox()
1910 class PluginSidebarBox extends SidebarBox
1913 public $_plugin, $_args = false, $_basepage = false;
1915 function PluginSidebarBox($name, $args = false, $basepage = false)
1917 require_once 'lib/WikiPlugin.php';
1919 $loader = new WikiPluginLoader();
1920 $plugin = $loader->getPlugin($name);
1922 $loader->_error(sprintf(_("Plugin %s: undefined"), $name));
1925 $this->_plugin =& $plugin;
1926 $this->_args = $args ? $args : array();
1927 $this->_basepage = $basepage;
1930 function format($args = array())
1933 * @var WikiRequest $request
1937 return $this->_plugin->box($args ? array_merge($this->_args, $args) : $this->_args,
1943 // Various boxes which are no plugins
1944 class RelatedLinksBox extends SidebarBox
1946 function RelatedLinksBox($title = false, $body = '', $limit = 20)
1949 * @var WikiRequest $request
1953 $this->title = $title ? $title : _("Related Links");
1954 $this->body = HTML::ul($body);
1955 $page = $request->getPage($request->getArg('pagename'));
1956 $revision = $page->getCurrentRevision();
1957 $page_content = $revision->getTransformedContent();
1959 foreach ($page_content->getWikiPageLinks() as $link) {
1960 $linkto = $link['linkto'];
1961 if (!$request->_dbi->isWikiPage($linkto))
1963 $this->body->pushContent(HTML::li(WikiLink($linkto)));
1965 if ($limit and $counter > $limit)
1971 class RelatedExternalLinksBox extends SidebarBox
1973 function RelatedExternalLinksBox($title = false, $body = '', $limit = 20)
1976 * @var WikiRequest $request
1980 $this->title = $title ? $title : _("External Links");
1981 $this->body = HTML::ul($body);
1982 $page = $request->getPage($request->getArg('pagename'));
1983 $cache = &$page->_wikidb->_cache;
1985 foreach ($cache->getWikiPageLinks() as $link) {
1986 $linkto = $link['linkto'];
1988 $this->body->pushContent(HTML::li(WikiLink($linkto)));
1990 if ($limit and $counter > $limit)
1997 function listAvailableThemes()
1999 if (THEME == 'fusionforge') {
2000 return array(THEME);
2002 $available_themes = array();
2003 $dir_root = 'themes';
2004 if (defined('PHPWIKI_DIR'))
2005 $dir_root = PHPWIKI_DIR . "/$dir_root";
2006 $dir = dir($dir_root);
2008 while ($entry = $dir->read()) {
2009 // 'fusionforge' cannot be selected as standalone theme
2010 if (($entry != 'fusionforge') and (is_dir($dir_root . '/' . $entry)
2011 and file_exists($dir_root . '/' . $entry . '/themeinfo.php'))) {
2012 array_push($available_themes, $entry);
2017 natcasesort($available_themes);
2018 return $available_themes;
2021 function listAvailableLanguages()
2023 $available_languages = array('en');
2024 $dir_root = 'locale';
2025 if (defined('PHPWIKI_DIR'))
2026 $dir_root = PHPWIKI_DIR . "/$dir_root";
2027 if ($dir = dir($dir_root)) {
2028 while ($entry = $dir->read()) {
2029 if (is_dir($dir_root . "/" . $entry) and is_dir($dir_root . '/' . $entry . '/LC_MESSAGES')) {
2030 array_push($available_languages, $entry);
2035 natcasesort($available_languages);
2036 return $available_languages;
2042 // c-basic-offset: 4
2043 // c-hanging-comment-ender-p: nil
2044 // indent-tabs-mode: nil