Hotfix Release 2017-02-19c "Frusterick Manners"
[dokuwiki.git] / inc / html.php
blob70ba4dcfe55fe55364b93c7c783cee8b11058a61
1 <?php
2 /**
3 * HTML output functions
5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author Andreas Gohr <andi@splitbrain.org>
7 */
9 if(!defined('DOKU_INC')) die('meh.');
10 if(!defined('NL')) define('NL',"\n");
12 /**
13 * Convenience function to quickly build a wikilink
15 * @author Andreas Gohr <andi@splitbrain.org>
16 * @param string $id id of the target page
17 * @param string $name the name of the link, i.e. the text that is displayed
18 * @param string|array $search search string(s) that shall be highlighted in the target page
19 * @return string the HTML code of the link
21 function html_wikilink($id,$name=null,$search=''){
22 /** @var Doku_Renderer_xhtml $xhtml_renderer */
23 static $xhtml_renderer = null;
24 if(is_null($xhtml_renderer)){
25 $xhtml_renderer = p_get_renderer('xhtml');
28 return $xhtml_renderer->internallink($id,$name,$search,true,'navigation');
31 /**
32 * The loginform
34 * @author Andreas Gohr <andi@splitbrain.org>
36 function html_login(){
37 global $lang;
38 global $conf;
39 global $ID;
40 global $INPUT;
42 print p_locale_xhtml('login');
43 print '<div class="centeralign">'.NL;
44 $form = new Doku_Form(array('id' => 'dw__login'));
45 $form->startFieldset($lang['btn_login']);
46 $form->addHidden('id', $ID);
47 $form->addHidden('do', 'login');
48 $form->addElement(form_makeTextField('u', ((!$INPUT->bool('http_credentials')) ? $INPUT->str('u') : ''), $lang['user'], 'focus__this', 'block'));
49 $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block'));
50 if($conf['rememberme']) {
51 $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple'));
53 $form->addElement(form_makeButton('submit', '', $lang['btn_login']));
54 $form->endFieldset();
56 if(actionOK('register')){
57 $form->addElement('<p>'.$lang['reghere'].': '.tpl_actionlink('register','','','',true).'</p>');
60 if (actionOK('resendpwd')) {
61 $form->addElement('<p>'.$lang['pwdforget'].': '.tpl_actionlink('resendpwd','','','',true).'</p>');
64 html_form('login', $form);
65 print '</div>'.NL;
69 /**
70 * Denied page content
72 * @return string html
74 function html_denied() {
75 print p_locale_xhtml('denied');
77 if(empty($_SERVER['REMOTE_USER'])){
78 html_login();
82 /**
83 * inserts section edit buttons if wanted or removes the markers
85 * @author Andreas Gohr <andi@splitbrain.org>
87 * @param string $text
88 * @param bool $show show section edit buttons?
89 * @return string
91 function html_secedit($text,$show=true){
92 global $INFO;
94 $regexp = '#<!-- EDIT(\d+) ([A-Z_]+) (?:"([^"]*)" )?\[(\d+-\d*)\] -->#';
96 if(!$INFO['writable'] || !$show || $INFO['rev']){
97 return preg_replace($regexp,'',$text);
100 return preg_replace_callback($regexp,
101 'html_secedit_button', $text);
105 * prepares section edit button data for event triggering
106 * used as a callback in html_secedit
108 * @author Andreas Gohr <andi@splitbrain.org>
110 * @param array $matches matches with regexp
111 * @return string
112 * @triggers HTML_SECEDIT_BUTTON
114 function html_secedit_button($matches){
115 $data = array('secid' => $matches[1],
116 'target' => strtolower($matches[2]),
117 'range' => $matches[count($matches) - 1]);
118 if (count($matches) === 5) {
119 $data['name'] = $matches[3];
122 return trigger_event('HTML_SECEDIT_BUTTON', $data,
123 'html_secedit_get_button');
127 * prints a section editing button
128 * used as default action form HTML_SECEDIT_BUTTON
130 * @author Adrian Lang <lang@cosmocode.de>
132 * @param array $data name, section id and target
133 * @return string html
135 function html_secedit_get_button($data) {
136 global $ID;
137 global $INFO;
139 if (!isset($data['name']) || $data['name'] === '') return '';
141 $name = $data['name'];
142 unset($data['name']);
144 $secid = $data['secid'];
145 unset($data['secid']);
147 return "<div class='secedit editbutton_" . $data['target'] .
148 " editbutton_" . $secid . "'>" .
149 html_btn('secedit', $ID, '',
150 array_merge(array('do' => 'edit',
151 'rev' => $INFO['lastmod'],
152 'summary' => '['.$name.'] '), $data),
153 'post', $name) . '</div>';
157 * Just the back to top button (in its own form)
159 * @author Andreas Gohr <andi@splitbrain.org>
161 * @return string html
163 function html_topbtn(){
164 global $lang;
166 $ret = '<a class="nolink" href="#dokuwiki__top"><input type="button" class="button" value="'.$lang['btn_top'].'" onclick="window.scrollTo(0, 0)" title="'.$lang['btn_top'].'" /></a>';
168 return $ret;
172 * Displays a button (using its own form)
173 * If tooltip exists, the access key tooltip is replaced.
175 * @author Andreas Gohr <andi@splitbrain.org>
177 * @param string $name
178 * @param string $id
179 * @param string $akey access key
180 * @param string[] $params key-value pairs added as hidden inputs
181 * @param string $method
182 * @param string $tooltip
183 * @param bool|string $label label text, false: lookup btn_$name in localization
184 * @return string
186 function html_btn($name, $id, $akey, $params, $method='get', $tooltip='', $label=false){
187 global $conf;
188 global $lang;
190 if (!$label)
191 $label = $lang['btn_'.$name];
193 $ret = '';
195 //filter id (without urlencoding)
196 $id = idfilter($id,false);
198 //make nice URLs even for buttons
199 if($conf['userewrite'] == 2){
200 $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
201 }elseif($conf['userewrite']){
202 $script = DOKU_BASE.$id;
203 }else{
204 $script = DOKU_BASE.DOKU_SCRIPT;
205 $params['id'] = $id;
208 $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
210 if(is_array($params)){
211 reset($params);
212 while (list($key, $val) = each($params)) {
213 $ret .= '<input type="hidden" name="'.$key.'" ';
214 $ret .= 'value="'.htmlspecialchars($val).'" />';
218 if ($tooltip!='') {
219 $tip = htmlspecialchars($tooltip);
220 }else{
221 $tip = htmlspecialchars($label);
224 $ret .= '<button type="submit" ';
225 if($akey){
226 $tip .= ' ['.strtoupper($akey).']';
227 $ret .= 'accesskey="'.$akey.'" ';
229 $ret .= 'title="'.$tip.'">';
230 $ret .= hsc($label);
231 $ret .= '</button>';
232 $ret .= '</div></form>';
234 return $ret;
237 * show a revision warning
239 * @author Szymon Olewniczak <dokuwiki@imz.re>
241 function html_showrev() {
242 print p_locale_xhtml('showrev');
246 * Show a wiki page
248 * @author Andreas Gohr <andi@splitbrain.org>
250 * @param null|string $txt wiki text or null for showing $ID
252 function html_show($txt=null){
253 global $ID;
254 global $REV;
255 global $HIGH;
256 global $INFO;
257 global $DATE_AT;
258 //disable section editing for old revisions or in preview
259 if($txt || $REV){
260 $secedit = false;
261 }else{
262 $secedit = true;
265 if (!is_null($txt)){
266 //PreviewHeader
267 echo '<br id="scroll__here" />';
268 echo p_locale_xhtml('preview');
269 echo '<div class="preview"><div class="pad">';
270 $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
271 if($INFO['prependTOC']) $html = tpl_toc(true).$html;
272 echo $html;
273 echo '<div class="clearer"></div>';
274 echo '</div></div>';
276 }else{
277 if ($REV||$DATE_AT){
278 $data = array('rev' => &$REV, 'date_at' => &$DATE_AT);
279 trigger_event('HTML_SHOWREV_OUTPUT', $data, 'html_showrev');
281 $html = p_wiki_xhtml($ID,$REV,true,$DATE_AT);
282 $html = html_secedit($html,$secedit);
283 if($INFO['prependTOC']) $html = tpl_toc(true).$html;
284 $html = html_hilight($html,$HIGH);
285 echo $html;
290 * ask the user about how to handle an exisiting draft
292 * @author Andreas Gohr <andi@splitbrain.org>
294 function html_draft(){
295 global $INFO;
296 global $ID;
297 global $lang;
298 $draft = unserialize(io_readFile($INFO['draft'],false));
299 $text = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
301 print p_locale_xhtml('draft');
302 $form = new Doku_Form(array('id' => 'dw__editform'));
303 $form->addHidden('id', $ID);
304 $form->addHidden('date', $draft['date']);
305 $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly')));
306 $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
307 $form->addElement($lang['draftdate'].' '. dformat(filemtime($INFO['draft'])));
308 $form->addElement(form_makeCloseTag('div'));
309 $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
310 $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
311 $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3')));
312 html_form('draft', $form);
316 * Highlights searchqueries in HTML code
318 * @author Andreas Gohr <andi@splitbrain.org>
319 * @author Harry Fuecks <hfuecks@gmail.com>
321 * @param string $html
322 * @param array|string $phrases
323 * @return string html
325 function html_hilight($html,$phrases){
326 $phrases = (array) $phrases;
327 $phrases = array_map('preg_quote_cb', $phrases);
328 $phrases = array_map('ft_snippet_re_preprocess', $phrases);
329 $phrases = array_filter($phrases);
330 $regex = join('|',$phrases);
332 if ($regex === '') return $html;
333 if (!utf8_check($regex)) return $html;
334 $html = @preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
335 return $html;
339 * Callback used by html_hilight()
341 * @author Harry Fuecks <hfuecks@gmail.com>
343 * @param array $m matches
344 * @return string html
346 function html_hilight_callback($m) {
347 $hlight = unslash($m[0]);
348 if ( !isset($m[2])) {
349 $hlight = '<span class="search_hit">'.$hlight.'</span>';
351 return $hlight;
355 * Run a search and display the result
357 * @author Andreas Gohr <andi@splitbrain.org>
359 function html_search(){
360 global $QUERY, $ID;
361 global $lang;
363 $intro = p_locale_xhtml('searchpage');
364 // allow use of placeholder in search intro
365 $pagecreateinfo = (auth_quickaclcheck($ID) >= AUTH_CREATE) ? $lang['searchcreatepage'] : '';
366 $intro = str_replace(
367 array('@QUERY@', '@SEARCH@', '@CREATEPAGEINFO@'),
368 array(hsc(rawurlencode($QUERY)), hsc($QUERY), $pagecreateinfo),
369 $intro
371 echo $intro;
372 flush();
374 //show progressbar
375 print '<div id="dw__loading">'.NL;
376 print '<script type="text/javascript">/*<![CDATA[*/'.NL;
377 print 'showLoadBar();'.NL;
378 print '/*!]]>*/</script>'.NL;
379 print '</div>'.NL;
380 flush();
382 //do quick pagesearch
383 $data = ft_pageLookup($QUERY,true,useHeading('navigation'));
384 if(count($data)){
385 print '<div class="search_quickresult">';
386 print '<h3>'.$lang['quickhits'].':</h3>';
387 print '<ul class="search_quickhits">';
388 foreach($data as $id => $title){
389 print '<li> ';
390 if (useHeading('navigation')) {
391 $name = $title;
392 }else{
393 $ns = getNS($id);
394 if($ns){
395 $name = shorten(noNS($id), ' ('.$ns.')',30);
396 }else{
397 $name = $id;
400 print html_wikilink(':'.$id,$name);
401 print '</li> ';
403 print '</ul> ';
404 //clear float (see http://www.complexspiral.com/publications/containing-floats/)
405 print '<div class="clearer"></div>';
406 print '</div>';
408 flush();
410 //do fulltext search
411 $data = ft_pageSearch($QUERY,$regex);
412 if(count($data)){
413 print '<dl class="search_results">';
414 $num = 1;
415 foreach($data as $id => $cnt){
416 print '<dt>';
417 print html_wikilink(':'.$id,useHeading('navigation')?null:$id,$regex);
418 if($cnt !== 0){
419 print ': '.$cnt.' '.$lang['hits'].'';
421 print '</dt>';
422 if($cnt !== 0){
423 if($num < FT_SNIPPET_NUMBER){ // create snippets for the first number of matches only
424 print '<dd>'.ft_snippet($id,$regex).'</dd>';
426 $num++;
428 flush();
430 print '</dl>';
431 }else{
432 print '<div class="nothing">'.$lang['nothingfound'].'</div>';
435 //hide progressbar
436 print '<script type="text/javascript">/*<![CDATA[*/'.NL;
437 print 'hideLoadBar("dw__loading");'.NL;
438 print '/*!]]>*/</script>'.NL;
439 flush();
443 * Display error on locked pages
445 * @author Andreas Gohr <andi@splitbrain.org>
447 function html_locked(){
448 global $ID;
449 global $conf;
450 global $lang;
451 global $INFO;
453 $locktime = filemtime(wikiLockFN($ID));
454 $expire = dformat($locktime + $conf['locktime']);
455 $min = round(($conf['locktime'] - (time() - $locktime) )/60);
457 print p_locale_xhtml('locked');
458 print '<ul>';
459 print '<li><div class="li"><strong>'.$lang['lockedby'].'</strong> '.editorinfo($INFO['locked']).'</div></li>';
460 print '<li><div class="li"><strong>'.$lang['lockexpire'].'</strong> '.$expire.' ('.$min.' min)</div></li>';
461 print '</ul>';
465 * list old revisions
467 * @author Andreas Gohr <andi@splitbrain.org>
468 * @author Ben Coburn <btcoburn@silicodon.net>
469 * @author Kate Arzamastseva <pshns@ukr.net>
471 * @param int $first skip the first n changelog lines
472 * @param bool|string $media_id id of media, or false for current page
474 function html_revisions($first=0, $media_id = false){
475 global $ID;
476 global $INFO;
477 global $conf;
478 global $lang;
479 $id = $ID;
480 if ($media_id) {
481 $id = $media_id;
482 $changelog = new MediaChangeLog($id);
483 } else {
484 $changelog = new PageChangeLog($id);
487 /* we need to get one additional log entry to be able to
488 * decide if this is the last page or is there another one.
489 * see html_recent()
492 $revisions = $changelog->getRevisions($first, $conf['recent']+1);
494 if(count($revisions)==0 && $first!=0){
495 $first=0;
496 $revisions = $changelog->getRevisions($first, $conf['recent']+1);
498 $hasNext = false;
499 if (count($revisions)>$conf['recent']) {
500 $hasNext = true;
501 array_pop($revisions); // remove extra log entry
504 if (!$media_id) print p_locale_xhtml('revisions');
506 $params = array('id' => 'page__revisions', 'class' => 'changes');
507 if($media_id) {
508 $params['action'] = media_managerURL(array('image' => $media_id), '&');
511 if(!$media_id) {
512 $exists = $INFO['exists'];
513 $display_name = useHeading('navigation') ? hsc(p_get_first_heading($id)) : $id;
514 if(!$display_name) {
515 $display_name = $id;
517 } else {
518 $exists = file_exists(mediaFN($id));
519 $display_name = $id;
522 $form = new Doku_Form($params);
523 $form->addElement(form_makeOpenTag('ul'));
525 if($exists && $first == 0) {
526 $minor = false;
527 if($media_id) {
528 $date = dformat(@filemtime(mediaFN($id)));
529 $href = media_managerURL(array('image' => $id, 'tab_details' => 'view'), '&');
531 $changelog->setChunkSize(1024);
532 $revinfo = $changelog->getRevisionInfo(@filemtime(fullpath(mediaFN($id))));
534 $summary = $revinfo['sum'];
535 if($revinfo['user']) {
536 $editor = $revinfo['user'];
537 } else {
538 $editor = $revinfo['ip'];
540 $sizechange = $revinfo['sizechange'];
541 } else {
542 $date = dformat($INFO['lastmod']);
543 if(isset($INFO['meta']) && isset($INFO['meta']['last_change'])) {
544 if($INFO['meta']['last_change']['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) {
545 $minor = true;
547 if(isset($INFO['meta']['last_change']['sizechange'])) {
548 $sizechange = $INFO['meta']['last_change']['sizechange'];
549 } else {
550 $sizechange = null;
553 $pagelog = new PageChangeLog($ID);
554 $latestrev = $pagelog->getRevisions(-1, 1);
555 $latestrev = array_pop($latestrev);
556 $href = wl($id,"rev=$latestrev",false,'&');
557 $summary = $INFO['sum'];
558 $editor = $INFO['editor'];
561 $form->addElement(form_makeOpenTag('li', array('class' => ($minor ? 'minor' : ''))));
562 $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
563 $form->addElement(form_makeTag('input', array(
564 'type' => 'checkbox',
565 'name' => 'rev2[]',
566 'value' => 'current')));
568 $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
569 $form->addElement($date);
570 $form->addElement(form_makeCloseTag('span'));
572 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
574 $form->addElement(form_makeOpenTag('a', array(
575 'class' => 'wikilink1',
576 'href' => $href)));
577 $form->addElement($display_name);
578 $form->addElement(form_makeCloseTag('a'));
580 if ($media_id) $form->addElement(form_makeOpenTag('div'));
582 if($summary) {
583 $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
584 if(!$media_id) $form->addElement(' – ');
585 $form->addElement('<bdi>' . htmlspecialchars($summary) . '</bdi>');
586 $form->addElement(form_makeCloseTag('span'));
589 $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
590 $form->addElement((empty($editor))?('('.$lang['external_edit'].')'):'<bdi>'.editorinfo($editor).'</bdi>');
591 $form->addElement(form_makeCloseTag('span'));
593 html_sizechange($sizechange, $form);
595 $form->addElement('('.$lang['current'].')');
597 if ($media_id) $form->addElement(form_makeCloseTag('div'));
599 $form->addElement(form_makeCloseTag('div'));
600 $form->addElement(form_makeCloseTag('li'));
603 foreach($revisions as $rev) {
604 $date = dformat($rev);
605 $info = $changelog->getRevisionInfo($rev);
606 if($media_id) {
607 $exists = file_exists(mediaFN($id, $rev));
608 } else {
609 $exists = page_exists($id, $rev);
612 $class = '';
613 if($info['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) {
614 $class = 'minor';
616 $form->addElement(form_makeOpenTag('li', array('class' => $class)));
617 $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
618 if($exists){
619 $form->addElement(form_makeTag('input', array(
620 'type' => 'checkbox',
621 'name' => 'rev2[]',
622 'value' => $rev)));
623 }else{
624 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
627 $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
628 $form->addElement($date);
629 $form->addElement(form_makeCloseTag('span'));
631 if($exists){
632 if (!$media_id) {
633 $href = wl($id,"rev=$rev,do=diff", false, '&');
634 } else {
635 $href = media_managerURL(array('image' => $id, 'rev' => $rev, 'mediado' => 'diff'), '&');
637 $form->addElement(form_makeOpenTag('a', array(
638 'class' => 'diff_link',
639 'href' => $href)));
640 $form->addElement(form_makeTag('img', array(
641 'src' => DOKU_BASE.'lib/images/diff.png',
642 'width' => 15,
643 'height' => 11,
644 'title' => $lang['diff'],
645 'alt' => $lang['diff'])));
646 $form->addElement(form_makeCloseTag('a'));
648 if (!$media_id) {
649 $href = wl($id,"rev=$rev",false,'&');
650 } else {
651 $href = media_managerURL(array('image' => $id, 'tab_details' => 'view', 'rev' => $rev), '&');
653 $form->addElement(form_makeOpenTag('a', array(
654 'class' => 'wikilink1',
655 'href' => $href)));
656 $form->addElement($display_name);
657 $form->addElement(form_makeCloseTag('a'));
658 }else{
659 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
660 $form->addElement($display_name);
663 if ($media_id) $form->addElement(form_makeOpenTag('div'));
665 if ($info['sum']) {
666 $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
667 if(!$media_id) $form->addElement(' – ');
668 $form->addElement('<bdi>'.htmlspecialchars($info['sum']).'</bdi>');
669 $form->addElement(form_makeCloseTag('span'));
672 $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
673 if($info['user']){
674 $form->addElement('<bdi>'.editorinfo($info['user']).'</bdi>');
675 if(auth_ismanager()){
676 $form->addElement(' <bdo dir="ltr">('.$info['ip'].')</bdo>');
678 }else{
679 $form->addElement('<bdo dir="ltr">'.$info['ip'].'</bdo>');
681 $form->addElement(form_makeCloseTag('span'));
683 html_sizechange($info['sizechange'], $form);
685 if ($media_id) $form->addElement(form_makeCloseTag('div'));
687 $form->addElement(form_makeCloseTag('div'));
688 $form->addElement(form_makeCloseTag('li'));
690 $form->addElement(form_makeCloseTag('ul'));
691 if (!$media_id) {
692 $form->addElement(form_makeButton('submit', 'diff', $lang['diff2']));
693 } else {
694 $form->addHidden('mediado', 'diff');
695 $form->addElement(form_makeButton('submit', '', $lang['diff2']));
697 html_form('revisions', $form);
699 print '<div class="pagenav">';
700 $last = $first + $conf['recent'];
701 if ($first > 0) {
702 $first -= $conf['recent'];
703 if ($first < 0) $first = 0;
704 print '<div class="pagenav-prev">';
705 if ($media_id) {
706 print html_btn('newer',$media_id,"p",media_managerURL(array('first' => $first), '&amp;', false, true));
707 } else {
708 print html_btn('newer',$id,"p",array('do' => 'revisions', 'first' => $first));
710 print '</div>';
712 if ($hasNext) {
713 print '<div class="pagenav-next">';
714 if ($media_id) {
715 print html_btn('older',$media_id,"n",media_managerURL(array('first' => $last), '&amp;', false, true));
716 } else {
717 print html_btn('older',$id,"n",array('do' => 'revisions', 'first' => $last));
719 print '</div>';
721 print '</div>';
726 * display recent changes
728 * @author Andreas Gohr <andi@splitbrain.org>
729 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
730 * @author Ben Coburn <btcoburn@silicodon.net>
731 * @author Kate Arzamastseva <pshns@ukr.net>
733 * @param int $first
734 * @param string $show_changes
736 function html_recent($first = 0, $show_changes = 'both') {
737 global $conf;
738 global $lang;
739 global $ID;
740 /* we need to get one additionally log entry to be able to
741 * decide if this is the last page or is there another one.
742 * This is the cheapest solution to get this information.
744 $flags = 0;
745 if($show_changes == 'mediafiles' && $conf['mediarevisions']) {
746 $flags = RECENTS_MEDIA_CHANGES;
747 } elseif($show_changes == 'pages') {
748 $flags = 0;
749 } elseif($conf['mediarevisions']) {
750 $show_changes = 'both';
751 $flags = RECENTS_MEDIA_PAGES_MIXED;
754 $recents = getRecents($first, $conf['recent'] + 1, getNS($ID), $flags);
755 if(count($recents) == 0 && $first != 0) {
756 $first = 0;
757 $recents = getRecents($first, $conf['recent'] + 1, getNS($ID), $flags);
759 $hasNext = false;
760 if(count($recents) > $conf['recent']) {
761 $hasNext = true;
762 array_pop($recents); // remove extra log entry
765 print p_locale_xhtml('recent');
767 if(getNS($ID) != '') {
768 print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>';
771 $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET', 'class' => 'changes'));
772 $form->addHidden('sectok', null);
773 $form->addHidden('do', 'recent');
774 $form->addHidden('id', $ID);
776 if($conf['mediarevisions']) {
777 $form->addElement('<div class="changeType">');
778 $form->addElement(form_makeListboxField(
779 'show_changes',
780 array(
781 'pages' => $lang['pages_changes'],
782 'mediafiles' => $lang['media_changes'],
783 'both' => $lang['both_changes']
785 $show_changes,
786 $lang['changes_type'],
787 '', '',
788 array('class' => 'quickselect')));
790 $form->addElement(form_makeButton('submit', 'recent', $lang['btn_apply']));
791 $form->addElement('</div>');
794 $form->addElement(form_makeOpenTag('ul'));
796 foreach($recents as $recent) {
797 $date = dformat($recent['date']);
799 $class = '';
800 if($recent['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) {
801 $class = 'minor';
803 $form->addElement(form_makeOpenTag('li', array('class' => $class)));
804 $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
806 if(!empty($recent['media'])) {
807 $form->addElement(media_printicon($recent['id']));
808 } else {
809 $icon = DOKU_BASE . 'lib/images/fileicons/file.png';
810 $form->addElement('<img src="' . $icon . '" alt="' . $recent['id'] . '" class="icon" />');
813 $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
814 $form->addElement($date);
815 $form->addElement(form_makeCloseTag('span'));
817 $diff = false;
818 $href = '';
820 if(!empty($recent['media'])) {
821 $changelog = new MediaChangeLog($recent['id']);
822 $revs = $changelog->getRevisions(0, 1);
823 $diff = (count($revs) && file_exists(mediaFN($recent['id'])));
824 if($diff) {
825 $href = media_managerURL(array(
826 'tab_details' => 'history',
827 'mediado' => 'diff',
828 'image' => $recent['id'],
829 'ns' => getNS($recent['id'])
830 ), '&');
832 } else {
833 $href = wl($recent['id'], "do=diff", false, '&');
836 if(!empty($recent['media']) && !$diff) {
837 $form->addElement('<img src="' . DOKU_BASE . 'lib/images/blank.gif" width="15" height="11" alt="" />');
838 } else {
839 $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => $href)));
840 $form->addElement(form_makeTag('img', array(
841 'src' => DOKU_BASE . 'lib/images/diff.png',
842 'width' => 15,
843 'height' => 11,
844 'title' => $lang['diff'],
845 'alt' => $lang['diff']
846 )));
847 $form->addElement(form_makeCloseTag('a'));
850 if(!empty($recent['media'])) {
851 $href = media_managerURL(array('tab_details' => 'history', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&');
852 } else {
853 $href = wl($recent['id'], "do=revisions", false, '&');
855 $form->addElement(form_makeOpenTag('a', array(
856 'class' => 'revisions_link',
857 'href' => $href)));
858 $form->addElement(form_makeTag('img', array(
859 'src' => DOKU_BASE . 'lib/images/history.png',
860 'width' => 12,
861 'height' => 14,
862 'title' => $lang['btn_revs'],
863 'alt' => $lang['btn_revs']
864 )));
865 $form->addElement(form_makeCloseTag('a'));
867 if(!empty($recent['media'])) {
868 $href = media_managerURL(array('tab_details' => 'view', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&');
869 $class = file_exists(mediaFN($recent['id'])) ? 'wikilink1' : 'wikilink2';
870 $form->addElement(form_makeOpenTag('a', array(
871 'class' => $class,
872 'href' => $href)));
873 $form->addElement($recent['id']);
874 $form->addElement(form_makeCloseTag('a'));
875 } else {
876 $form->addElement(html_wikilink(':' . $recent['id'], useHeading('navigation') ? null : $recent['id']));
878 $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
879 $form->addElement(' – ' . htmlspecialchars($recent['sum']));
880 $form->addElement(form_makeCloseTag('span'));
882 $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
883 if($recent['user']) {
884 $form->addElement('<bdi>' . editorinfo($recent['user']) . '</bdi>');
885 if(auth_ismanager()) {
886 $form->addElement(' <bdo dir="ltr">(' . $recent['ip'] . ')</bdo>');
888 } else {
889 $form->addElement('<bdo dir="ltr">' . $recent['ip'] . '</bdo>');
891 $form->addElement(form_makeCloseTag('span'));
893 html_sizechange($recent['sizechange'], $form);
895 $form->addElement(form_makeCloseTag('div'));
896 $form->addElement(form_makeCloseTag('li'));
898 $form->addElement(form_makeCloseTag('ul'));
900 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
901 $last = $first + $conf['recent'];
902 if($first > 0) {
903 $first -= $conf['recent'];
904 if($first < 0) $first = 0;
905 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
906 $form->addElement(form_makeOpenTag('button', array(
907 'type' => 'submit',
908 'name' => 'first[' . $first . ']',
909 'accesskey' => 'n',
910 'title' => $lang['btn_newer'] . ' [N]',
911 'class' => 'button show'
912 )));
913 $form->addElement($lang['btn_newer']);
914 $form->addElement(form_makeCloseTag('button'));
915 $form->addElement(form_makeCloseTag('div'));
917 if($hasNext) {
918 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
919 $form->addElement(form_makeOpenTag('button', array(
920 'type' => 'submit',
921 'name' => 'first[' . $last . ']',
922 'accesskey' => 'p',
923 'title' => $lang['btn_older'] . ' [P]',
924 'class' => 'button show'
925 )));
926 $form->addElement($lang['btn_older']);
927 $form->addElement(form_makeCloseTag('button'));
928 $form->addElement(form_makeCloseTag('div'));
930 $form->addElement(form_makeCloseTag('div'));
931 html_form('recent', $form);
935 * Display page index
937 * @author Andreas Gohr <andi@splitbrain.org>
939 * @param string $ns
941 function html_index($ns){
942 global $conf;
943 global $ID;
944 $ns = cleanID($ns);
945 if(empty($ns)){
946 $ns = getNS($ID);
947 if($ns === false) $ns ='';
949 $ns = utf8_encodeFN(str_replace(':','/',$ns));
951 echo p_locale_xhtml('index');
952 echo '<div id="index__tree">';
954 $data = array();
955 search($data,$conf['datadir'],'search_index',array('ns' => $ns));
956 echo html_buildlist($data,'idx','html_list_index','html_li_index');
958 echo '</div>';
962 * Index item formatter
964 * User function for html_buildlist()
966 * @author Andreas Gohr <andi@splitbrain.org>
968 * @param array $item
969 * @return string
971 function html_list_index($item){
972 global $ID, $conf;
974 // prevent searchbots needlessly following links
975 $nofollow = ($ID != $conf['start'] || $conf['sitemap']) ? ' rel="nofollow"' : '';
977 $ret = '';
978 $base = ':'.$item['id'];
979 $base = substr($base,strrpos($base,':')+1);
980 if($item['type']=='d'){
981 // FS#2766, no need for search bots to follow namespace links in the index
982 $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" title="' . $item['id'] . '" class="idx_dir"' . $nofollow . '><strong>';
983 $ret .= $base;
984 $ret .= '</strong></a>';
985 }else{
986 // default is noNSorNS($id), but we want noNS($id) when useheading is off FS#2605
987 $ret .= html_wikilink(':'.$item['id'], useHeading('navigation') ? null : noNS($item['id']));
989 return $ret;
993 * Index List item
995 * This user function is used in html_buildlist to build the
996 * <li> tags for namespaces when displaying the page index
997 * it gives different classes to opened or closed "folders"
999 * @author Andreas Gohr <andi@splitbrain.org>
1001 * @param array $item
1002 * @return string html
1004 function html_li_index($item){
1005 global $INFO;
1006 global $ACT;
1008 $class = '';
1009 $id = '';
1011 if($item['type'] == "f"){
1012 // scroll to the current item
1013 if($item['id'] == $INFO['id'] && $ACT == 'index') {
1014 $id = ' id="scroll__here"';
1015 $class = ' bounce';
1017 return '<li class="level'.$item['level'].$class.'" '.$id.'>';
1018 }elseif($item['open']){
1019 return '<li class="open">';
1020 }else{
1021 return '<li class="closed">';
1026 * Default List item
1028 * @author Andreas Gohr <andi@splitbrain.org>
1030 * @param array $item
1031 * @return string html
1033 function html_li_default($item){
1034 return '<li class="level'.$item['level'].'">';
1038 * Build an unordered list
1040 * Build an unordered list from the given $data array
1041 * Each item in the array has to have a 'level' property
1042 * the item itself gets printed by the given $func user
1043 * function. The second and optional function is used to
1044 * print the <li> tag. Both user function need to accept
1045 * a single item.
1047 * Both user functions can be given as array to point to
1048 * a member of an object.
1050 * @author Andreas Gohr <andi@splitbrain.org>
1052 * @param array $data array with item arrays
1053 * @param string $class class of ul wrapper
1054 * @param callable $func callback to print an list item
1055 * @param callable $lifunc callback to the opening li tag
1056 * @param bool $forcewrapper Trigger building a wrapper ul if the first level is
1057 * 0 (we have a root object) or 1 (just the root content)
1058 * @return string html of an unordered list
1060 function html_buildlist($data,$class,$func,$lifunc='html_li_default',$forcewrapper=false){
1061 if (count($data) === 0) {
1062 return '';
1065 $start_level = $data[0]['level'];
1066 $level = $start_level;
1067 $ret = '';
1068 $open = 0;
1070 foreach ($data as $item){
1072 if( $item['level'] > $level ){
1073 //open new list
1074 for($i=0; $i<($item['level'] - $level); $i++){
1075 if ($i) $ret .= "<li class=\"clear\">";
1076 $ret .= "\n<ul class=\"$class\">\n";
1077 $open++;
1079 $level = $item['level'];
1081 }elseif( $item['level'] < $level ){
1082 //close last item
1083 $ret .= "</li>\n";
1084 while( $level > $item['level'] && $open > 0 ){
1085 //close higher lists
1086 $ret .= "</ul>\n</li>\n";
1087 $level--;
1088 $open--;
1090 } elseif ($ret !== '') {
1091 //close previous item
1092 $ret .= "</li>\n";
1095 //print item
1096 $ret .= call_user_func($lifunc,$item);
1097 $ret .= '<div class="li">';
1099 $ret .= call_user_func($func,$item);
1100 $ret .= '</div>';
1103 //close remaining items and lists
1104 $ret .= "</li>\n";
1105 while($open-- > 0) {
1106 $ret .= "</ul></li>\n";
1109 if ($forcewrapper || $start_level < 2) {
1110 // Trigger building a wrapper ul if the first level is
1111 // 0 (we have a root object) or 1 (just the root content)
1112 $ret = "\n<ul class=\"$class\">\n".$ret."</ul>\n";
1115 return $ret;
1119 * display backlinks
1121 * @author Andreas Gohr <andi@splitbrain.org>
1122 * @author Michael Klier <chi@chimeric.de>
1124 function html_backlinks(){
1125 global $ID;
1126 global $lang;
1128 print p_locale_xhtml('backlinks');
1130 $data = ft_backlinks($ID);
1132 if(!empty($data)) {
1133 print '<ul class="idx">';
1134 foreach($data as $blink){
1135 print '<li><div class="li">';
1136 print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink);
1137 print '</div></li>';
1139 print '</ul>';
1140 } else {
1141 print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
1146 * Get header of diff HTML
1148 * @param string $l_rev Left revisions
1149 * @param string $r_rev Right revision
1150 * @param string $id Page id, if null $ID is used
1151 * @param bool $media If it is for media files
1152 * @param bool $inline Return the header on a single line
1153 * @return string[] HTML snippets for diff header
1155 function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = false) {
1156 global $lang;
1157 if ($id === null) {
1158 global $ID;
1159 $id = $ID;
1161 $head_separator = $inline ? ' ' : '<br />';
1162 $media_or_wikiFN = $media ? 'mediaFN' : 'wikiFN';
1163 $ml_or_wl = $media ? 'ml' : 'wl';
1164 $l_minor = $r_minor = '';
1166 if($media) {
1167 $changelog = new MediaChangeLog($id);
1168 } else {
1169 $changelog = new PageChangeLog($id);
1171 if(!$l_rev){
1172 $l_head = '&mdash;';
1173 }else{
1174 $l_info = $changelog->getRevisionInfo($l_rev);
1175 if($l_info['user']){
1176 $l_user = '<bdi>'.editorinfo($l_info['user']).'</bdi>';
1177 if(auth_ismanager()) $l_user .= ' <bdo dir="ltr">('.$l_info['ip'].')</bdo>';
1178 } else {
1179 $l_user = '<bdo dir="ltr">'.$l_info['ip'].'</bdo>';
1181 $l_user = '<span class="user">'.$l_user.'</span>';
1182 $l_sum = ($l_info['sum']) ? '<span class="sum"><bdi>'.hsc($l_info['sum']).'</bdi></span>' : '';
1183 if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
1185 $l_head_title = ($media) ? dformat($l_rev) : $id.' ['.dformat($l_rev).']';
1186 $l_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$l_rev").'">'.
1187 $l_head_title.'</a></bdi>'.
1188 $head_separator.$l_user.' '.$l_sum;
1191 if($r_rev){
1192 $r_info = $changelog->getRevisionInfo($r_rev);
1193 if($r_info['user']){
1194 $r_user = '<bdi>'.editorinfo($r_info['user']).'</bdi>';
1195 if(auth_ismanager()) $r_user .= ' <bdo dir="ltr">('.$r_info['ip'].')</bdo>';
1196 } else {
1197 $r_user = '<bdo dir="ltr">'.$r_info['ip'].'</bdo>';
1199 $r_user = '<span class="user">'.$r_user.'</span>';
1200 $r_sum = ($r_info['sum']) ? '<span class="sum"><bdi>'.hsc($r_info['sum']).'</bdi></span>' : '';
1201 if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
1203 $r_head_title = ($media) ? dformat($r_rev) : $id.' ['.dformat($r_rev).']';
1204 $r_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$r_rev").'">'.
1205 $r_head_title.'</a></bdi>'.
1206 $head_separator.$r_user.' '.$r_sum;
1207 }elseif($_rev = @filemtime($media_or_wikiFN($id))){
1208 $_info = $changelog->getRevisionInfo($_rev);
1209 if($_info['user']){
1210 $_user = '<bdi>'.editorinfo($_info['user']).'</bdi>';
1211 if(auth_ismanager()) $_user .= ' <bdo dir="ltr">('.$_info['ip'].')</bdo>';
1212 } else {
1213 $_user = '<bdo dir="ltr">'.$_info['ip'].'</bdo>';
1215 $_user = '<span class="user">'.$_user.'</span>';
1216 $_sum = ($_info['sum']) ? '<span class="sum"><bdi>'.hsc($_info['sum']).'</span></bdi>' : '';
1217 if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
1219 $r_head_title = ($media) ? dformat($_rev) : $id.' ['.dformat($_rev).']';
1220 $r_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id).'">'.
1221 $r_head_title.'</a></bdi> '.
1222 '('.$lang['current'].')'.
1223 $head_separator.$_user.' '.$_sum;
1224 }else{
1225 $r_head = '&mdash; ('.$lang['current'].')';
1228 return array($l_head, $r_head, $l_minor, $r_minor);
1232 * Show diff
1233 * between current page version and provided $text
1234 * or between the revisions provided via GET or POST
1236 * @author Andreas Gohr <andi@splitbrain.org>
1237 * @param string $text when non-empty: compare with this text with most current version
1238 * @param bool $intro display the intro text
1239 * @param string $type type of the diff (inline or sidebyside)
1241 function html_diff($text = '', $intro = true, $type = null) {
1242 global $ID;
1243 global $REV;
1244 global $lang;
1245 global $INPUT;
1246 global $INFO;
1247 $pagelog = new PageChangeLog($ID);
1250 * Determine diff type
1252 if(!$type) {
1253 $type = $INPUT->str('difftype');
1254 if(empty($type)) {
1255 $type = get_doku_pref('difftype', $type);
1256 if(empty($type) && $INFO['ismobile']) {
1257 $type = 'inline';
1261 if($type != 'inline') $type = 'sidebyside';
1264 * Determine requested revision(s)
1266 // we're trying to be clever here, revisions to compare can be either
1267 // given as rev and rev2 parameters, with rev2 being optional. Or in an
1268 // array in rev2.
1269 $rev1 = $REV;
1271 $rev2 = $INPUT->ref('rev2');
1272 if(is_array($rev2)) {
1273 $rev1 = (int) $rev2[0];
1274 $rev2 = (int) $rev2[1];
1276 if(!$rev1) {
1277 $rev1 = $rev2;
1278 unset($rev2);
1280 } else {
1281 $rev2 = $INPUT->int('rev2');
1285 * Determine left and right revision, its texts and the header
1287 $r_minor = '';
1288 $l_minor = '';
1290 if($text) { // compare text to the most current revision
1291 $l_rev = '';
1292 $l_text = rawWiki($ID, '');
1293 $l_head = '<a class="wikilink1" href="' . wl($ID) . '">' .
1294 $ID . ' ' . dformat((int) @filemtime(wikiFN($ID))) . '</a> ' .
1295 $lang['current'];
1297 $r_rev = '';
1298 $r_text = cleanText($text);
1299 $r_head = $lang['yours'];
1300 } else {
1301 if($rev1 && isset($rev2) && $rev2) { // two specific revisions wanted
1302 // make sure order is correct (older on the left)
1303 if($rev1 < $rev2) {
1304 $l_rev = $rev1;
1305 $r_rev = $rev2;
1306 } else {
1307 $l_rev = $rev2;
1308 $r_rev = $rev1;
1310 } elseif($rev1) { // single revision given, compare to current
1311 $r_rev = '';
1312 $l_rev = $rev1;
1313 } else { // no revision was given, compare previous to current
1314 $r_rev = '';
1315 $revs = $pagelog->getRevisions(0, 1);
1316 $l_rev = $revs[0];
1317 $REV = $l_rev; // store revision back in $REV
1320 // when both revisions are empty then the page was created just now
1321 if(!$l_rev && !$r_rev) {
1322 $l_text = '';
1323 } else {
1324 $l_text = rawWiki($ID, $l_rev);
1326 $r_text = rawWiki($ID, $r_rev);
1328 list($l_head, $r_head, $l_minor, $r_minor) = html_diff_head($l_rev, $r_rev, null, false, $type == 'inline');
1332 * Build navigation
1334 $l_nav = '';
1335 $r_nav = '';
1336 if(!$text) {
1337 list($l_nav, $r_nav) = html_diff_navigation($pagelog, $type, $l_rev, $r_rev);
1340 * Create diff object and the formatter
1342 $diff = new Diff(explode("\n", $l_text), explode("\n", $r_text));
1344 if($type == 'inline') {
1345 $diffformatter = new InlineDiffFormatter();
1346 } else {
1347 $diffformatter = new TableDiffFormatter();
1350 * Display intro
1352 if($intro) print p_locale_xhtml('diff');
1355 * Display type and exact reference
1357 if(!$text) {
1358 ptln('<div class="diffoptions group">');
1361 $form = new Doku_Form(array('action' => wl()));
1362 $form->addHidden('id', $ID);
1363 $form->addHidden('rev2[0]', $l_rev);
1364 $form->addHidden('rev2[1]', $r_rev);
1365 $form->addHidden('do', 'diff');
1366 $form->addElement(
1367 form_makeListboxField(
1368 'difftype',
1369 array(
1370 'sidebyside' => $lang['diff_side'],
1371 'inline' => $lang['diff_inline']
1373 $type,
1374 $lang['diff_type'],
1375 '', '',
1376 array('class' => 'quickselect')
1379 $form->addElement(form_makeButton('submit', 'diff', 'Go'));
1380 $form->printForm();
1382 ptln('<p>');
1383 // link to exactly this view FS#2835
1384 echo html_diff_navigationlink($type, 'difflink', $l_rev, $r_rev ? $r_rev : $INFO['currentrev']);
1385 ptln('</p>');
1387 ptln('</div>'); // .diffoptions
1391 * Display diff view table
1394 <div class="table">
1395 <table class="diff diff_<?php echo $type ?>">
1397 <?php
1398 //navigation and header
1399 if($type == 'inline') {
1400 if(!$text) { ?>
1401 <tr>
1402 <td class="diff-lineheader">-</td>
1403 <td class="diffnav"><?php echo $l_nav ?></td>
1404 </tr>
1405 <tr>
1406 <th class="diff-lineheader">-</th>
1407 <th <?php echo $l_minor ?>>
1408 <?php echo $l_head ?>
1409 </th>
1410 </tr>
1411 <?php } ?>
1412 <tr>
1413 <td class="diff-lineheader">+</td>
1414 <td class="diffnav"><?php echo $r_nav ?></td>
1415 </tr>
1416 <tr>
1417 <th class="diff-lineheader">+</th>
1418 <th <?php echo $r_minor ?>>
1419 <?php echo $r_head ?>
1420 </th>
1421 </tr>
1422 <?php } else {
1423 if(!$text) { ?>
1424 <tr>
1425 <td colspan="2" class="diffnav"><?php echo $l_nav ?></td>
1426 <td colspan="2" class="diffnav"><?php echo $r_nav ?></td>
1427 </tr>
1428 <?php } ?>
1429 <tr>
1430 <th colspan="2" <?php echo $l_minor ?>>
1431 <?php echo $l_head ?>
1432 </th>
1433 <th colspan="2" <?php echo $r_minor ?>>
1434 <?php echo $r_head ?>
1435 </th>
1436 </tr>
1437 <?php }
1439 //diff view
1440 echo html_insert_softbreaks($diffformatter->format($diff)); ?>
1442 </table>
1443 </div>
1444 <?php
1448 * Create html for revision navigation
1450 * @param PageChangeLog $pagelog changelog object of current page
1451 * @param string $type inline vs sidebyside
1452 * @param int $l_rev left revision timestamp
1453 * @param int $r_rev right revision timestamp
1454 * @return string[] html of left and right navigation elements
1456 function html_diff_navigation($pagelog, $type, $l_rev, $r_rev) {
1457 global $INFO, $ID;
1459 // last timestamp is not in changelog, retrieve timestamp from metadata
1460 // note: when page is removed, the metadata timestamp is zero
1461 if(!$r_rev) {
1462 if(isset($INFO['meta']['last_change']['date'])) {
1463 $r_rev = $INFO['meta']['last_change']['date'];
1464 } else {
1465 $r_rev = 0;
1469 //retrieve revisions with additional info
1470 list($l_revs, $r_revs) = $pagelog->getRevisionsAround($l_rev, $r_rev);
1471 $l_revisions = array();
1472 if(!$l_rev) {
1473 $l_revisions[0] = array(0, "", false); //no left revision given, add dummy
1475 foreach($l_revs as $rev) {
1476 $info = $pagelog->getRevisionInfo($rev);
1477 $l_revisions[$rev] = array(
1478 $rev,
1479 dformat($info['date']) . ' ' . editorinfo($info['user'], true) . ' ' . $info['sum'],
1480 $r_rev ? $rev >= $r_rev : false //disable?
1483 $r_revisions = array();
1484 if(!$r_rev) {
1485 $r_revisions[0] = array(0, "", false); //no right revision given, add dummy
1487 foreach($r_revs as $rev) {
1488 $info = $pagelog->getRevisionInfo($rev);
1489 $r_revisions[$rev] = array(
1490 $rev,
1491 dformat($info['date']) . ' ' . editorinfo($info['user'], true) . ' ' . $info['sum'],
1492 $rev <= $l_rev //disable?
1496 //determine previous/next revisions
1497 $l_index = array_search($l_rev, $l_revs);
1498 $l_prev = $l_revs[$l_index + 1];
1499 $l_next = $l_revs[$l_index - 1];
1500 if($r_rev) {
1501 $r_index = array_search($r_rev, $r_revs);
1502 $r_prev = $r_revs[$r_index + 1];
1503 $r_next = $r_revs[$r_index - 1];
1504 } else {
1505 //removed page
1506 if($l_next) {
1507 $r_prev = $r_revs[0];
1508 } else {
1509 $r_prev = null;
1511 $r_next = null;
1515 * Left side:
1517 $l_nav = '';
1518 //move back
1519 if($l_prev) {
1520 $l_nav .= html_diff_navigationlink($type, 'diffbothprevrev', $l_prev, $r_prev);
1521 $l_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_prev, $r_rev);
1523 //dropdown
1524 $form = new Doku_Form(array('action' => wl()));
1525 $form->addHidden('id', $ID);
1526 $form->addHidden('difftype', $type);
1527 $form->addHidden('rev2[1]', $r_rev);
1528 $form->addHidden('do', 'diff');
1529 $form->addElement(
1530 form_makeListboxField(
1531 'rev2[0]',
1532 $l_revisions,
1533 $l_rev,
1534 '', '', '',
1535 array('class' => 'quickselect')
1538 $form->addElement(form_makeButton('submit', 'diff', 'Go'));
1539 $l_nav .= $form->getForm();
1540 //move forward
1541 if($l_next && ($l_next < $r_rev || !$r_rev)) {
1542 $l_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_next, $r_rev);
1546 * Right side:
1548 $r_nav = '';
1549 //move back
1550 if($l_rev < $r_prev) {
1551 $r_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_rev, $r_prev);
1553 //dropdown
1554 $form = new Doku_Form(array('action' => wl()));
1555 $form->addHidden('id', $ID);
1556 $form->addHidden('rev2[0]', $l_rev);
1557 $form->addHidden('difftype', $type);
1558 $form->addHidden('do', 'diff');
1559 $form->addElement(
1560 form_makeListboxField(
1561 'rev2[1]',
1562 $r_revisions,
1563 $r_rev,
1564 '', '', '',
1565 array('class' => 'quickselect')
1568 $form->addElement(form_makeButton('submit', 'diff', 'Go'));
1569 $r_nav .= $form->getForm();
1570 //move forward
1571 if($r_next) {
1572 if($pagelog->isCurrentRevision($r_next)) {
1573 $r_nav .= html_diff_navigationlink($type, 'difflastrev', $l_rev); //last revision is diff with current page
1574 } else {
1575 $r_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_rev, $r_next);
1577 $r_nav .= html_diff_navigationlink($type, 'diffbothnextrev', $l_next, $r_next);
1579 return array($l_nav, $r_nav);
1583 * Create html link to a diff defined by two revisions
1585 * @param string $difftype display type
1586 * @param string $linktype
1587 * @param int $lrev oldest revision
1588 * @param int $rrev newest revision or null for diff with current revision
1589 * @return string html of link to a diff
1591 function html_diff_navigationlink($difftype, $linktype, $lrev, $rrev = null) {
1592 global $ID, $lang;
1593 if(!$rrev) {
1594 $urlparam = array(
1595 'do' => 'diff',
1596 'rev' => $lrev,
1597 'difftype' => $difftype,
1599 } else {
1600 $urlparam = array(
1601 'do' => 'diff',
1602 'rev2[0]' => $lrev,
1603 'rev2[1]' => $rrev,
1604 'difftype' => $difftype,
1607 return '<a class="' . $linktype . '" href="' . wl($ID, $urlparam) . '" title="' . $lang[$linktype] . '">' .
1608 '<span>' . $lang[$linktype] . '</span>' .
1609 '</a>' . "\n";
1613 * Insert soft breaks in diff html
1615 * @param string $diffhtml
1616 * @return string
1618 function html_insert_softbreaks($diffhtml) {
1619 // search the diff html string for both:
1620 // - html tags, so these can be ignored
1621 // - long strings of characters without breaking characters
1622 return preg_replace_callback('/<[^>]*>|[^<> ]{12,}/','html_softbreak_callback',$diffhtml);
1626 * callback which adds softbreaks
1628 * @param array $match array with first the complete match
1629 * @return string the replacement
1631 function html_softbreak_callback($match){
1632 // if match is an html tag, return it intact
1633 if ($match[0]{0} == '<') return $match[0];
1635 // its a long string without a breaking character,
1636 // make certain characters into breaking characters by inserting a
1637 // breaking character (zero length space, U+200B / #8203) in front them.
1638 $regex = <<< REGEX
1639 (?(?= # start a conditional expression with a positive look ahead ...
1640 &\#?\\w{1,6};) # ... for html entities - we don't want to split them (ok to catch some invalid combinations)
1641 &\#?\\w{1,6}; # yes pattern - a quicker match for the html entity, since we know we have one
1643 [?/,&\#;:] # no pattern - any other group of 'special' characters to insert a breaking character after
1644 )+ # end conditional expression
1645 REGEX;
1647 return preg_replace('<'.$regex.'>xu','\0&#8203;',$match[0]);
1651 * show warning on conflict detection
1653 * @author Andreas Gohr <andi@splitbrain.org>
1655 * @param string $text
1656 * @param string $summary
1658 function html_conflict($text,$summary){
1659 global $ID;
1660 global $lang;
1662 print p_locale_xhtml('conflict');
1663 $form = new Doku_Form(array('id' => 'dw__editform'));
1664 $form->addHidden('id', $ID);
1665 $form->addHidden('wikitext', $text);
1666 $form->addHidden('summary', $summary);
1667 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
1668 $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
1669 html_form('conflict', $form);
1670 print '<br /><br /><br /><br />'.NL;
1674 * Prints the global message array
1676 * @author Andreas Gohr <andi@splitbrain.org>
1678 function html_msgarea(){
1679 global $MSG, $MSG_shown;
1680 /** @var array $MSG */
1681 // store if the global $MSG has already been shown and thus HTML output has been started
1682 $MSG_shown = true;
1684 if(!isset($MSG)) return;
1686 $shown = array();
1687 foreach($MSG as $msg){
1688 $hash = md5($msg['msg']);
1689 if(isset($shown[$hash])) continue; // skip double messages
1690 if(info_msg_allowed($msg)){
1691 print '<div class="'.$msg['lvl'].'">';
1692 print $msg['msg'];
1693 print '</div>';
1695 $shown[$hash] = 1;
1698 unset($GLOBALS['MSG']);
1702 * Prints the registration form
1704 * @author Andreas Gohr <andi@splitbrain.org>
1706 function html_register(){
1707 global $lang;
1708 global $conf;
1709 global $INPUT;
1711 $base_attrs = array('size'=>50,'required'=>'required');
1712 $email_attrs = $base_attrs + array('type'=>'email','class'=>'edit');
1714 print p_locale_xhtml('register');
1715 print '<div class="centeralign">'.NL;
1716 $form = new Doku_Form(array('id' => 'dw__register'));
1717 $form->startFieldset($lang['btn_register']);
1718 $form->addHidden('do', 'register');
1719 $form->addHidden('save', '1');
1720 $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block', $base_attrs));
1721 if (!$conf['autopasswd']) {
1722 $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', $base_attrs));
1723 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', $base_attrs));
1725 $form->addElement(form_makeTextField('fullname', $INPUT->post->str('fullname'), $lang['fullname'], '', 'block', $base_attrs));
1726 $form->addElement(form_makeField('email','email', $INPUT->post->str('email'), $lang['email'], '', 'block', $email_attrs));
1727 $form->addElement(form_makeButton('submit', '', $lang['btn_register']));
1728 $form->endFieldset();
1729 html_form('register', $form);
1731 print '</div>'.NL;
1735 * Print the update profile form
1737 * @author Christopher Smith <chris@jalakai.co.uk>
1738 * @author Andreas Gohr <andi@splitbrain.org>
1740 function html_updateprofile(){
1741 global $lang;
1742 global $conf;
1743 global $INPUT;
1744 global $INFO;
1745 /** @var DokuWiki_Auth_Plugin $auth */
1746 global $auth;
1748 print p_locale_xhtml('updateprofile');
1749 print '<div class="centeralign">'.NL;
1751 $fullname = $INPUT->post->str('fullname', $INFO['userinfo']['name'], true);
1752 $email = $INPUT->post->str('email', $INFO['userinfo']['mail'], true);
1753 $form = new Doku_Form(array('id' => 'dw__register'));
1754 $form->startFieldset($lang['profile']);
1755 $form->addHidden('do', 'profile');
1756 $form->addHidden('save', '1');
1757 $form->addElement(form_makeTextField('login', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
1758 $attr = array('size'=>'50');
1759 if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1760 $form->addElement(form_makeTextField('fullname', $fullname, $lang['fullname'], '', 'block', $attr));
1761 $attr = array('size'=>'50', 'class'=>'edit');
1762 if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
1763 $form->addElement(form_makeField('email','email', $email, $lang['email'], '', 'block', $attr));
1764 $form->addElement(form_makeTag('br'));
1765 if ($auth->canDo('modPass')) {
1766 $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1767 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1769 if ($conf['profileconfirm']) {
1770 $form->addElement(form_makeTag('br'));
1771 $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50', 'required' => 'required')));
1773 $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1774 $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
1776 $form->endFieldset();
1777 html_form('updateprofile', $form);
1779 if ($auth->canDo('delUser') && actionOK('profile_delete')) {
1780 $form_profiledelete = new Doku_Form(array('id' => 'dw__profiledelete'));
1781 $form_profiledelete->startFieldset($lang['profdeleteuser']);
1782 $form_profiledelete->addHidden('do', 'profile_delete');
1783 $form_profiledelete->addHidden('delete', '1');
1784 $form_profiledelete->addElement(form_makeCheckboxField('confirm_delete', '1', $lang['profconfdelete'],'dw__confirmdelete','', array('required' => 'required')));
1785 if ($conf['profileconfirm']) {
1786 $form_profiledelete->addElement(form_makeTag('br'));
1787 $form_profiledelete->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50', 'required' => 'required')));
1789 $form_profiledelete->addElement(form_makeButton('submit', '', $lang['btn_deleteuser']));
1790 $form_profiledelete->endFieldset();
1792 html_form('profiledelete', $form_profiledelete);
1795 print '</div>'.NL;
1799 * Preprocess edit form data
1801 * @author Andreas Gohr <andi@splitbrain.org>
1803 * @triggers HTML_EDITFORM_OUTPUT
1805 function html_edit(){
1806 global $INPUT;
1807 global $ID;
1808 global $REV;
1809 global $DATE;
1810 global $PRE;
1811 global $SUF;
1812 global $INFO;
1813 global $SUM;
1814 global $lang;
1815 global $conf;
1816 global $TEXT;
1818 if ($INPUT->has('changecheck')) {
1819 $check = $INPUT->str('changecheck');
1820 } elseif(!$INFO['exists']){
1821 // $TEXT has been loaded from page template
1822 $check = md5('');
1823 } else {
1824 $check = md5($TEXT);
1826 $mod = md5($TEXT) !== $check;
1828 $wr = $INFO['writable'] && !$INFO['locked'];
1829 $include = 'edit';
1830 if($wr){
1831 if ($REV) $include = 'editrev';
1832 }else{
1833 // check pseudo action 'source'
1834 if(!actionOK('source')){
1835 msg('Command disabled: source',-1);
1836 return;
1838 $include = 'read';
1841 global $license;
1843 $form = new Doku_Form(array('id' => 'dw__editform'));
1844 $form->addHidden('id', $ID);
1845 $form->addHidden('rev', $REV);
1846 $form->addHidden('date', $DATE);
1847 $form->addHidden('prefix', $PRE . '.');
1848 $form->addHidden('suffix', $SUF);
1849 $form->addHidden('changecheck', $check);
1851 $data = array('form' => $form,
1852 'wr' => $wr,
1853 'media_manager' => true,
1854 'target' => ($INPUT->has('target') && $wr) ? $INPUT->str('target') : 'section',
1855 'intro_locale' => $include);
1857 if ($data['target'] !== 'section') {
1858 // Only emit event if page is writable, section edit data is valid and
1859 // edit target is not section.
1860 trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true);
1861 } else {
1862 html_edit_form($data);
1864 if (isset($data['intro_locale'])) {
1865 echo p_locale_xhtml($data['intro_locale']);
1868 $form->addHidden('target', $data['target']);
1869 $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar', 'class'=>'editBar')));
1870 $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1871 $form->addElement(form_makeCloseTag('div'));
1872 if ($wr) {
1873 $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
1874 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
1875 $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
1876 $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
1877 $form->addElement(form_makeCloseTag('div'));
1878 $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
1879 $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
1880 $elem = html_minoredit();
1881 if ($elem) $form->addElement($elem);
1882 $form->addElement(form_makeCloseTag('div'));
1884 $form->addElement(form_makeCloseTag('div'));
1885 if($wr && $conf['license']){
1886 $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1887 $out = $lang['licenseok'];
1888 $out .= ' <a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
1889 if($conf['target']['extern']) $out .= ' target="'.$conf['target']['extern'].'"';
1890 $out .= '>'.$license[$conf['license']]['name'].'</a>';
1891 $form->addElement($out);
1892 $form->addElement(form_makeCloseTag('div'));
1895 if ($wr) {
1896 // sets changed to true when previewed
1897 echo '<script type="text/javascript">/*<![CDATA[*/'. NL;
1898 echo 'textChanged = ' . ($mod ? 'true' : 'false');
1899 echo '/*!]]>*/</script>' . NL;
1900 } ?>
1901 <div class="editBox" role="application">
1903 <div class="toolbar group">
1904 <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div>
1905 <div id="tool__bar"><?php if ($wr && $data['media_manager']){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
1906 target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
1907 </div>
1908 <?php
1910 html_form('edit', $form);
1911 print '</div>'.NL;
1915 * Display the default edit form
1917 * Is the default action for HTML_EDIT_FORMSELECTION.
1919 * @param mixed[] $param
1921 function html_edit_form($param) {
1922 global $TEXT;
1924 if ($param['target'] !== 'section') {
1925 msg('No editor for edit target ' . hsc($param['target']) . ' found.', -1);
1928 $attr = array('tabindex'=>'1');
1929 if (!$param['wr']) $attr['readonly'] = 'readonly';
1931 $param['form']->addElement(form_makeWikiText($TEXT, $attr));
1935 * Adds a checkbox for minor edits for logged in users
1937 * @author Andreas Gohr <andi@splitbrain.org>
1939 * @return array|bool
1941 function html_minoredit(){
1942 global $conf;
1943 global $lang;
1944 global $INPUT;
1945 // minor edits are for logged in users only
1946 if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1947 return false;
1950 $p = array();
1951 $p['tabindex'] = 3;
1952 if($INPUT->bool('minor')) $p['checked']='checked';
1953 return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
1957 * prints some debug info
1959 * @author Andreas Gohr <andi@splitbrain.org>
1961 function html_debug(){
1962 global $conf;
1963 global $lang;
1964 /** @var DokuWiki_Auth_Plugin $auth */
1965 global $auth;
1966 global $INFO;
1968 //remove sensitive data
1969 $cnf = $conf;
1970 debug_guard($cnf);
1971 $nfo = $INFO;
1972 debug_guard($nfo);
1973 $ses = $_SESSION;
1974 debug_guard($ses);
1976 print '<html><body>';
1978 print '<p>When reporting bugs please send all the following ';
1979 print 'output as a mail to andi@splitbrain.org ';
1980 print 'The best way to do this is to save this page in your browser</p>';
1982 print '<b>$INFO:</b><pre>';
1983 print_r($nfo);
1984 print '</pre>';
1986 print '<b>$_SERVER:</b><pre>';
1987 print_r($_SERVER);
1988 print '</pre>';
1990 print '<b>$conf:</b><pre>';
1991 print_r($cnf);
1992 print '</pre>';
1994 print '<b>DOKU_BASE:</b><pre>';
1995 print DOKU_BASE;
1996 print '</pre>';
1998 print '<b>abs DOKU_BASE:</b><pre>';
1999 print DOKU_URL;
2000 print '</pre>';
2002 print '<b>rel DOKU_BASE:</b><pre>';
2003 print dirname($_SERVER['PHP_SELF']).'/';
2004 print '</pre>';
2006 print '<b>PHP Version:</b><pre>';
2007 print phpversion();
2008 print '</pre>';
2010 print '<b>locale:</b><pre>';
2011 print setlocale(LC_ALL,0);
2012 print '</pre>';
2014 print '<b>encoding:</b><pre>';
2015 print $lang['encoding'];
2016 print '</pre>';
2018 if($auth){
2019 print '<b>Auth backend capabilities:</b><pre>';
2020 foreach ($auth->getCapabilities() as $cando){
2021 print ' '.str_pad($cando,16) . ' => ' . (int)$auth->canDo($cando) . NL;
2023 print '</pre>';
2026 print '<b>$_SESSION:</b><pre>';
2027 print_r($ses);
2028 print '</pre>';
2030 print '<b>Environment:</b><pre>';
2031 print_r($_ENV);
2032 print '</pre>';
2034 print '<b>PHP settings:</b><pre>';
2035 $inis = ini_get_all();
2036 print_r($inis);
2037 print '</pre>';
2039 if (function_exists('apache_get_version')) {
2040 $apache = array();
2041 $apache['version'] = apache_get_version();
2043 if (function_exists('apache_get_modules')) {
2044 $apache['modules'] = apache_get_modules();
2046 print '<b>Apache</b><pre>';
2047 print_r($apache);
2048 print '</pre>';
2051 print '</body></html>';
2055 * Form to request a new password for an existing account
2057 * @author Benoit Chesneau <benoit@bchesneau.info>
2058 * @author Andreas Gohr <gohr@cosmocode.de>
2060 function html_resendpwd() {
2061 global $lang;
2062 global $conf;
2063 global $INPUT;
2065 $token = preg_replace('/[^a-f0-9]+/','',$INPUT->str('pwauth'));
2067 if(!$conf['autopasswd'] && $token){
2068 print p_locale_xhtml('resetpwd');
2069 print '<div class="centeralign">'.NL;
2070 $form = new Doku_Form(array('id' => 'dw__resendpwd'));
2071 $form->startFieldset($lang['btn_resendpwd']);
2072 $form->addHidden('token', $token);
2073 $form->addHidden('do', 'resendpwd');
2075 $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
2076 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
2078 $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
2079 $form->endFieldset();
2080 html_form('resendpwd', $form);
2081 print '</div>'.NL;
2082 }else{
2083 print p_locale_xhtml('resendpwd');
2084 print '<div class="centeralign">'.NL;
2085 $form = new Doku_Form(array('id' => 'dw__resendpwd'));
2086 $form->startFieldset($lang['resendpwd']);
2087 $form->addHidden('do', 'resendpwd');
2088 $form->addHidden('save', '1');
2089 $form->addElement(form_makeTag('br'));
2090 $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block'));
2091 $form->addElement(form_makeTag('br'));
2092 $form->addElement(form_makeTag('br'));
2093 $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
2094 $form->endFieldset();
2095 html_form('resendpwd', $form);
2096 print '</div>'.NL;
2101 * Return the TOC rendered to XHTML
2103 * @author Andreas Gohr <andi@splitbrain.org>
2105 * @param array $toc
2106 * @return string html
2108 function html_TOC($toc){
2109 if(!count($toc)) return '';
2110 global $lang;
2111 $out = '<!-- TOC START -->'.DOKU_LF;
2112 $out .= '<div id="dw__toc">'.DOKU_LF;
2113 $out .= '<h3 class="toggle">';
2114 $out .= $lang['toc'];
2115 $out .= '</h3>'.DOKU_LF;
2116 $out .= '<div>'.DOKU_LF;
2117 $out .= html_buildlist($toc,'toc','html_list_toc','html_li_default',true);
2118 $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
2119 $out .= '<!-- TOC END -->'.DOKU_LF;
2120 return $out;
2124 * Callback for html_buildlist
2126 * @param array $item
2127 * @return string html
2129 function html_list_toc($item){
2130 if(isset($item['hid'])){
2131 $link = '#'.$item['hid'];
2132 }else{
2133 $link = $item['link'];
2136 return '<a href="'.$link.'">'.hsc($item['title']).'</a>';
2140 * Helper function to build TOC items
2142 * Returns an array ready to be added to a TOC array
2144 * @param string $link - where to link (if $hash set to '#' it's a local anchor)
2145 * @param string $text - what to display in the TOC
2146 * @param int $level - nesting level
2147 * @param string $hash - is prepended to the given $link, set blank if you want full links
2148 * @return array the toc item
2150 function html_mktocitem($link, $text, $level, $hash='#'){
2151 return array( 'link' => $hash.$link,
2152 'title' => $text,
2153 'type' => 'ul',
2154 'level' => $level);
2158 * Output a Doku_Form object.
2159 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
2161 * @author Tom N Harris <tnharris@whoopdedo.org>
2163 * @param string $name The name of the form
2164 * @param Doku_Form $form The form
2166 function html_form($name, &$form) {
2167 // Safety check in case the caller forgets.
2168 $form->endFieldset();
2169 trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
2173 * Form print function.
2174 * Just calls printForm() on the data object.
2176 * @param Doku_Form $data The form
2178 function html_form_output($data) {
2179 $data->printForm();
2183 * Embed a flash object in HTML
2185 * This will create the needed HTML to embed a flash movie in a cross browser
2186 * compatble way using valid XHTML
2188 * The parameters $params, $flashvars and $atts need to be associative arrays.
2189 * No escaping needs to be done for them. The alternative content *has* to be
2190 * escaped because it is used as is. If no alternative content is given
2191 * $lang['noflash'] is used.
2193 * @author Andreas Gohr <andi@splitbrain.org>
2194 * @link http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
2196 * @param string $swf - the SWF movie to embed
2197 * @param int $width - width of the flash movie in pixels
2198 * @param int $height - height of the flash movie in pixels
2199 * @param array $params - additional parameters (<param>)
2200 * @param array $flashvars - parameters to be passed in the flashvar parameter
2201 * @param array $atts - additional attributes for the <object> tag
2202 * @param string $alt - alternative content (is NOT automatically escaped!)
2203 * @return string - the XHTML markup
2205 function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
2206 global $lang;
2208 $out = '';
2210 // prepare the object attributes
2211 if(is_null($atts)) $atts = array();
2212 $atts['width'] = (int) $width;
2213 $atts['height'] = (int) $height;
2214 if(!$atts['width']) $atts['width'] = 425;
2215 if(!$atts['height']) $atts['height'] = 350;
2217 // add object attributes for standard compliant browsers
2218 $std = $atts;
2219 $std['type'] = 'application/x-shockwave-flash';
2220 $std['data'] = $swf;
2222 // add object attributes for IE
2223 $ie = $atts;
2224 $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
2226 // open object (with conditional comments)
2227 $out .= '<!--[if !IE]> -->'.NL;
2228 $out .= '<object '.buildAttributes($std).'>'.NL;
2229 $out .= '<!-- <![endif]-->'.NL;
2230 $out .= '<!--[if IE]>'.NL;
2231 $out .= '<object '.buildAttributes($ie).'>'.NL;
2232 $out .= ' <param name="movie" value="'.hsc($swf).'" />'.NL;
2233 $out .= '<!--><!-- -->'.NL;
2235 // print params
2236 if(is_array($params)) foreach($params as $key => $val){
2237 $out .= ' <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
2240 // add flashvars
2241 if(is_array($flashvars)){
2242 $out .= ' <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
2245 // alternative content
2246 if($alt){
2247 $out .= $alt.NL;
2248 }else{
2249 $out .= $lang['noflash'].NL;
2252 // finish
2253 $out .= '</object>'.NL;
2254 $out .= '<!-- <![endif]-->'.NL;
2256 return $out;
2260 * Prints HTML code for the given tab structure
2262 * @param array $tabs tab structure
2263 * @param string $current_tab the current tab id
2265 function html_tabs($tabs, $current_tab = null) {
2266 echo '<ul class="tabs">'.NL;
2268 foreach($tabs as $id => $tab) {
2269 html_tab($tab['href'], $tab['caption'], $id === $current_tab);
2272 echo '</ul>'.NL;
2276 * Prints a single tab
2278 * @author Kate Arzamastseva <pshns@ukr.net>
2279 * @author Adrian Lang <mail@adrianlang.de>
2281 * @param string $href - tab href
2282 * @param string $caption - tab caption
2283 * @param boolean $selected - is tab selected
2286 function html_tab($href, $caption, $selected=false) {
2287 $tab = '<li>';
2288 if ($selected) {
2289 $tab .= '<strong>';
2290 } else {
2291 $tab .= '<a href="' . hsc($href) . '">';
2293 $tab .= hsc($caption)
2294 . '</' . ($selected ? 'strong' : 'a') . '>'
2295 . '</li>'.NL;
2296 echo $tab;
2300 * Display size change
2302 * @param int $sizechange - size of change in Bytes
2303 * @param Doku_Form $form - form to add elements to
2306 function html_sizechange($sizechange, Doku_Form $form) {
2307 if(isset($sizechange)) {
2308 $class = 'sizechange';
2309 $value = filesize_h(abs($sizechange));
2310 if($sizechange > 0) {
2311 $class .= ' positive';
2312 $value = '+' . $value;
2313 } elseif($sizechange < 0) {
2314 $class .= ' negative';
2315 $value = '-' . $value;
2316 } else {
2317 $value = '±' . $value;
2319 $form->addElement(form_makeOpenTag('span', array('class' => $class)));
2320 $form->addElement($value);
2321 $form->addElement(form_makeCloseTag('span'));