fix: access first element of associative arrays
[dokuwiki.git] / inc / html.php
blob120d72b1f1bd06a2265c1bdce22dbf6b10b0fb45
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 'hid' => strtolower($matches[4]),
118 'range' => $matches[count($matches) - 1]);
119 if (count($matches) === 6) {
120 $data['name'] = $matches[3];
123 return trigger_event('HTML_SECEDIT_BUTTON', $data,
124 'html_secedit_get_button');
128 * prints a section editing button
129 * used as default action form HTML_SECEDIT_BUTTON
131 * @author Adrian Lang <lang@cosmocode.de>
133 * @param array $data name, section id and target
134 * @return string html
136 function html_secedit_get_button($data) {
137 global $ID;
138 global $INFO;
140 if (!isset($data['name']) || $data['name'] === '') return '';
142 $name = $data['name'];
143 unset($data['name']);
145 $secid = $data['secid'];
146 unset($data['secid']);
148 return "<div class='secedit editbutton_" . $data['target'] .
149 " editbutton_" . $secid . "'>" .
150 html_btn('secedit', $ID, '',
151 array_merge(array('do' => 'edit',
152 'rev' => $INFO['lastmod'],
153 'summary' => '['.$name.'] '), $data),
154 'post', $name) . '</div>';
158 * Just the back to top button (in its own form)
160 * @author Andreas Gohr <andi@splitbrain.org>
162 * @return string html
164 function html_topbtn(){
165 global $lang;
167 $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>';
169 return $ret;
173 * Displays a button (using its own form)
174 * If tooltip exists, the access key tooltip is replaced.
176 * @author Andreas Gohr <andi@splitbrain.org>
178 * @param string $name
179 * @param string $id
180 * @param string $akey access key
181 * @param string[] $params key-value pairs added as hidden inputs
182 * @param string $method
183 * @param string $tooltip
184 * @param bool|string $label label text, false: lookup btn_$name in localization
185 * @return string
187 function html_btn($name, $id, $akey, $params, $method='get', $tooltip='', $label=false){
188 global $conf;
189 global $lang;
191 if (!$label)
192 $label = $lang['btn_'.$name];
194 $ret = '';
196 //filter id (without urlencoding)
197 $id = idfilter($id,false);
199 //make nice URLs even for buttons
200 if($conf['userewrite'] == 2){
201 $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
202 }elseif($conf['userewrite']){
203 $script = DOKU_BASE.$id;
204 }else{
205 $script = DOKU_BASE.DOKU_SCRIPT;
206 $params['id'] = $id;
209 $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
211 if(is_array($params)){
212 foreach($params as $key => $val) {
213 $ret .= '<input type="hidden" name="'.$key.'" ';
214 $ret .= 'value="'.hsc($val).'" />';
218 if ($tooltip!='') {
219 $tip = hsc($tooltip);
220 }else{
221 $tip = hsc($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;
373 //do quick pagesearch
374 $data = ft_pageLookup($QUERY,true,useHeading('navigation'));
375 if(count($data)){
376 print '<div class="search_quickresult">';
377 print '<h3>'.$lang['quickhits'].':</h3>';
378 print '<ul class="search_quickhits">';
379 foreach($data as $id => $title){
380 print '<li> ';
381 if (useHeading('navigation')) {
382 $name = $title;
383 }else{
384 $ns = getNS($id);
385 if($ns){
386 $name = shorten(noNS($id), ' ('.$ns.')',30);
387 }else{
388 $name = $id;
391 print html_wikilink(':'.$id,$name);
392 print '</li> ';
394 print '</ul> ';
395 //clear float (see http://www.complexspiral.com/publications/containing-floats/)
396 print '<div class="clearer"></div>';
397 print '</div>';
400 //do fulltext search
401 $regex = array();
402 $data = ft_pageSearch($QUERY,$regex);
403 if(count($data)){
404 print '<dl class="search_results">';
405 $num = 1;
406 foreach($data as $id => $cnt){
407 print '<dt>';
408 print html_wikilink(':'.$id,useHeading('navigation')?null:$id,$regex);
409 if($cnt !== 0){
410 print ': '.$cnt.' '.$lang['hits'].'';
412 print '</dt>';
413 if($cnt !== 0){
414 if($num < FT_SNIPPET_NUMBER){ // create snippets for the first number of matches only
415 print '<dd>'.ft_snippet($id,$regex).'</dd>';
417 $num++;
420 print '</dl>';
421 }else{
422 print '<div class="nothing">'.$lang['nothingfound'].'</div>';
427 * Display error on locked pages
429 * @author Andreas Gohr <andi@splitbrain.org>
431 function html_locked(){
432 global $ID;
433 global $conf;
434 global $lang;
435 global $INFO;
437 $locktime = filemtime(wikiLockFN($ID));
438 $expire = dformat($locktime + $conf['locktime']);
439 $min = round(($conf['locktime'] - (time() - $locktime) )/60);
441 print p_locale_xhtml('locked');
442 print '<ul>';
443 print '<li><div class="li"><strong>'.$lang['lockedby'].'</strong> '.editorinfo($INFO['locked']).'</div></li>';
444 print '<li><div class="li"><strong>'.$lang['lockexpire'].'</strong> '.$expire.' ('.$min.' min)</div></li>';
445 print '</ul>';
449 * list old revisions
451 * @author Andreas Gohr <andi@splitbrain.org>
452 * @author Ben Coburn <btcoburn@silicodon.net>
453 * @author Kate Arzamastseva <pshns@ukr.net>
455 * @param int $first skip the first n changelog lines
456 * @param bool|string $media_id id of media, or false for current page
458 function html_revisions($first=0, $media_id = false){
459 global $ID;
460 global $INFO;
461 global $conf;
462 global $lang;
463 $id = $ID;
464 if ($media_id) {
465 $id = $media_id;
466 $changelog = new MediaChangeLog($id);
467 } else {
468 $changelog = new PageChangeLog($id);
471 /* we need to get one additional log entry to be able to
472 * decide if this is the last page or is there another one.
473 * see html_recent()
476 $revisions = $changelog->getRevisions($first, $conf['recent']+1);
478 if(count($revisions)==0 && $first!=0){
479 $first=0;
480 $revisions = $changelog->getRevisions($first, $conf['recent']+1);
482 $hasNext = false;
483 if (count($revisions)>$conf['recent']) {
484 $hasNext = true;
485 array_pop($revisions); // remove extra log entry
488 if (!$media_id) print p_locale_xhtml('revisions');
490 $params = array('id' => 'page__revisions', 'class' => 'changes');
491 if($media_id) {
492 $params['action'] = media_managerURL(array('image' => $media_id), '&');
495 if(!$media_id) {
496 $exists = $INFO['exists'];
497 $display_name = useHeading('navigation') ? hsc(p_get_first_heading($id)) : $id;
498 if(!$display_name) {
499 $display_name = $id;
501 } else {
502 $exists = file_exists(mediaFN($id));
503 $display_name = $id;
506 $form = new Doku_Form($params);
507 $form->addElement(form_makeOpenTag('ul'));
509 if($exists && $first == 0) {
510 $minor = false;
511 if($media_id) {
512 $date = dformat(@filemtime(mediaFN($id)));
513 $href = media_managerURL(array('image' => $id, 'tab_details' => 'view'), '&');
515 $changelog->setChunkSize(1024);
516 $revinfo = $changelog->getRevisionInfo(@filemtime(fullpath(mediaFN($id))));
518 $summary = $revinfo['sum'];
519 if($revinfo['user']) {
520 $editor = $revinfo['user'];
521 } else {
522 $editor = $revinfo['ip'];
524 $sizechange = $revinfo['sizechange'];
525 } else {
526 $date = dformat($INFO['lastmod']);
527 if(isset($INFO['meta']) && isset($INFO['meta']['last_change'])) {
528 if($INFO['meta']['last_change']['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) {
529 $minor = true;
531 if(isset($INFO['meta']['last_change']['sizechange'])) {
532 $sizechange = $INFO['meta']['last_change']['sizechange'];
533 } else {
534 $sizechange = null;
537 $pagelog = new PageChangeLog($ID);
538 $latestrev = $pagelog->getRevisions(-1, 1);
539 $latestrev = array_pop($latestrev);
540 $href = wl($id,"rev=$latestrev",false,'&');
541 $summary = $INFO['sum'];
542 $editor = $INFO['editor'];
545 $form->addElement(form_makeOpenTag('li', array('class' => ($minor ? 'minor' : ''))));
546 $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
547 $form->addElement(form_makeTag('input', array(
548 'type' => 'checkbox',
549 'name' => 'rev2[]',
550 'value' => 'current')));
552 $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
553 $form->addElement($date);
554 $form->addElement(form_makeCloseTag('span'));
556 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
558 $form->addElement(form_makeOpenTag('a', array(
559 'class' => 'wikilink1',
560 'href' => $href)));
561 $form->addElement($display_name);
562 $form->addElement(form_makeCloseTag('a'));
564 if ($media_id) $form->addElement(form_makeOpenTag('div'));
566 if($summary) {
567 $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
568 if(!$media_id) $form->addElement(' – ');
569 $form->addElement('<bdi>' . hsc($summary) . '</bdi>');
570 $form->addElement(form_makeCloseTag('span'));
573 $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
574 $form->addElement((empty($editor))?('('.$lang['external_edit'].')'):'<bdi>'.editorinfo($editor).'</bdi>');
575 $form->addElement(form_makeCloseTag('span'));
577 html_sizechange($sizechange, $form);
579 $form->addElement('('.$lang['current'].')');
581 if ($media_id) $form->addElement(form_makeCloseTag('div'));
583 $form->addElement(form_makeCloseTag('div'));
584 $form->addElement(form_makeCloseTag('li'));
587 foreach($revisions as $rev) {
588 $date = dformat($rev);
589 $info = $changelog->getRevisionInfo($rev);
590 if($media_id) {
591 $exists = file_exists(mediaFN($id, $rev));
592 } else {
593 $exists = page_exists($id, $rev);
596 $class = '';
597 if($info['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) {
598 $class = 'minor';
600 $form->addElement(form_makeOpenTag('li', array('class' => $class)));
601 $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
602 if($exists){
603 $form->addElement(form_makeTag('input', array(
604 'type' => 'checkbox',
605 'name' => 'rev2[]',
606 'value' => $rev)));
607 }else{
608 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
611 $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
612 $form->addElement($date);
613 $form->addElement(form_makeCloseTag('span'));
615 if($exists){
616 if (!$media_id) {
617 $href = wl($id,"rev=$rev,do=diff", false, '&');
618 } else {
619 $href = media_managerURL(array('image' => $id, 'rev' => $rev, 'mediado' => 'diff'), '&');
621 $form->addElement(form_makeOpenTag('a', array(
622 'class' => 'diff_link',
623 'href' => $href)));
624 $form->addElement(form_makeTag('img', array(
625 'src' => DOKU_BASE.'lib/images/diff.png',
626 'width' => 15,
627 'height' => 11,
628 'title' => $lang['diff'],
629 'alt' => $lang['diff'])));
630 $form->addElement(form_makeCloseTag('a'));
632 if (!$media_id) {
633 $href = wl($id,"rev=$rev",false,'&');
634 } else {
635 $href = media_managerURL(array('image' => $id, 'tab_details' => 'view', 'rev' => $rev), '&');
637 $form->addElement(form_makeOpenTag('a', array(
638 'class' => 'wikilink1',
639 'href' => $href)));
640 $form->addElement($display_name);
641 $form->addElement(form_makeCloseTag('a'));
642 }else{
643 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
644 $form->addElement($display_name);
647 if ($media_id) $form->addElement(form_makeOpenTag('div'));
649 if ($info['sum']) {
650 $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
651 if(!$media_id) $form->addElement(' – ');
652 $form->addElement('<bdi>'.hsc($info['sum']).'</bdi>');
653 $form->addElement(form_makeCloseTag('span'));
656 $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
657 if($info['user']){
658 $form->addElement('<bdi>'.editorinfo($info['user']).'</bdi>');
659 if(auth_ismanager()){
660 $form->addElement(' <bdo dir="ltr">('.$info['ip'].')</bdo>');
662 }else{
663 $form->addElement('<bdo dir="ltr">'.$info['ip'].'</bdo>');
665 $form->addElement(form_makeCloseTag('span'));
667 html_sizechange($info['sizechange'], $form);
669 if ($media_id) $form->addElement(form_makeCloseTag('div'));
671 $form->addElement(form_makeCloseTag('div'));
672 $form->addElement(form_makeCloseTag('li'));
674 $form->addElement(form_makeCloseTag('ul'));
675 if (!$media_id) {
676 $form->addElement(form_makeButton('submit', 'diff', $lang['diff2']));
677 } else {
678 $form->addHidden('mediado', 'diff');
679 $form->addElement(form_makeButton('submit', '', $lang['diff2']));
681 html_form('revisions', $form);
683 print '<div class="pagenav">';
684 $last = $first + $conf['recent'];
685 if ($first > 0) {
686 $first -= $conf['recent'];
687 if ($first < 0) $first = 0;
688 print '<div class="pagenav-prev">';
689 if ($media_id) {
690 print html_btn('newer',$media_id,"p",media_managerURL(array('first' => $first), '&amp;', false, true));
691 } else {
692 print html_btn('newer',$id,"p",array('do' => 'revisions', 'first' => $first));
694 print '</div>';
696 if ($hasNext) {
697 print '<div class="pagenav-next">';
698 if ($media_id) {
699 print html_btn('older',$media_id,"n",media_managerURL(array('first' => $last), '&amp;', false, true));
700 } else {
701 print html_btn('older',$id,"n",array('do' => 'revisions', 'first' => $last));
703 print '</div>';
705 print '</div>';
710 * display recent changes
712 * @author Andreas Gohr <andi@splitbrain.org>
713 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
714 * @author Ben Coburn <btcoburn@silicodon.net>
715 * @author Kate Arzamastseva <pshns@ukr.net>
717 * @param int $first
718 * @param string $show_changes
720 function html_recent($first = 0, $show_changes = 'both') {
721 global $conf;
722 global $lang;
723 global $ID;
724 /* we need to get one additionally log entry to be able to
725 * decide if this is the last page or is there another one.
726 * This is the cheapest solution to get this information.
728 $flags = 0;
729 if($show_changes == 'mediafiles' && $conf['mediarevisions']) {
730 $flags = RECENTS_MEDIA_CHANGES;
731 } elseif($show_changes == 'pages') {
732 $flags = 0;
733 } elseif($conf['mediarevisions']) {
734 $show_changes = 'both';
735 $flags = RECENTS_MEDIA_PAGES_MIXED;
738 $recents = getRecents($first, $conf['recent'] + 1, getNS($ID), $flags);
739 if(count($recents) == 0 && $first != 0) {
740 $first = 0;
741 $recents = getRecents($first, $conf['recent'] + 1, getNS($ID), $flags);
743 $hasNext = false;
744 if(count($recents) > $conf['recent']) {
745 $hasNext = true;
746 array_pop($recents); // remove extra log entry
749 print p_locale_xhtml('recent');
751 if(getNS($ID) != '') {
752 print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>';
755 $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET', 'class' => 'changes'));
756 $form->addHidden('sectok', null);
757 $form->addHidden('do', 'recent');
758 $form->addHidden('id', $ID);
760 if($conf['mediarevisions']) {
761 $form->addElement('<div class="changeType">');
762 $form->addElement(form_makeListboxField(
763 'show_changes',
764 array(
765 'pages' => $lang['pages_changes'],
766 'mediafiles' => $lang['media_changes'],
767 'both' => $lang['both_changes']
769 $show_changes,
770 $lang['changes_type'],
771 '', '',
772 array('class' => 'quickselect')));
774 $form->addElement(form_makeButton('submit', 'recent', $lang['btn_apply']));
775 $form->addElement('</div>');
778 $form->addElement(form_makeOpenTag('ul'));
780 foreach($recents as $recent) {
781 $date = dformat($recent['date']);
783 $class = '';
784 if($recent['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) {
785 $class = 'minor';
787 $form->addElement(form_makeOpenTag('li', array('class' => $class)));
788 $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
790 if(!empty($recent['media'])) {
791 $form->addElement(media_printicon($recent['id']));
792 } else {
793 $icon = DOKU_BASE . 'lib/images/fileicons/file.png';
794 $form->addElement('<img src="' . $icon . '" alt="' . $recent['id'] . '" class="icon" />');
797 $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
798 $form->addElement($date);
799 $form->addElement(form_makeCloseTag('span'));
801 $diff = false;
802 $href = '';
804 if(!empty($recent['media'])) {
805 $changelog = new MediaChangeLog($recent['id']);
806 $revs = $changelog->getRevisions(0, 1);
807 $diff = (count($revs) && file_exists(mediaFN($recent['id'])));
808 if($diff) {
809 $href = media_managerURL(array(
810 'tab_details' => 'history',
811 'mediado' => 'diff',
812 'image' => $recent['id'],
813 'ns' => getNS($recent['id'])
814 ), '&');
816 } else {
817 $href = wl($recent['id'], "do=diff", false, '&');
820 if(!empty($recent['media']) && !$diff) {
821 $form->addElement('<img src="' . DOKU_BASE . 'lib/images/blank.gif" width="15" height="11" alt="" />');
822 } else {
823 $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => $href)));
824 $form->addElement(form_makeTag('img', array(
825 'src' => DOKU_BASE . 'lib/images/diff.png',
826 'width' => 15,
827 'height' => 11,
828 'title' => $lang['diff'],
829 'alt' => $lang['diff']
830 )));
831 $form->addElement(form_makeCloseTag('a'));
834 if(!empty($recent['media'])) {
835 $href = media_managerURL(array('tab_details' => 'history', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&');
836 } else {
837 $href = wl($recent['id'], "do=revisions", false, '&');
839 $form->addElement(form_makeOpenTag('a', array(
840 'class' => 'revisions_link',
841 'href' => $href)));
842 $form->addElement(form_makeTag('img', array(
843 'src' => DOKU_BASE . 'lib/images/history.png',
844 'width' => 12,
845 'height' => 14,
846 'title' => $lang['btn_revs'],
847 'alt' => $lang['btn_revs']
848 )));
849 $form->addElement(form_makeCloseTag('a'));
851 if(!empty($recent['media'])) {
852 $href = media_managerURL(array('tab_details' => 'view', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&');
853 $class = file_exists(mediaFN($recent['id'])) ? 'wikilink1' : 'wikilink2';
854 $form->addElement(form_makeOpenTag('a', array(
855 'class' => $class,
856 'href' => $href)));
857 $form->addElement($recent['id']);
858 $form->addElement(form_makeCloseTag('a'));
859 } else {
860 $form->addElement(html_wikilink(':' . $recent['id'], useHeading('navigation') ? null : $recent['id']));
862 $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
863 $form->addElement(' – ' . hsc($recent['sum']));
864 $form->addElement(form_makeCloseTag('span'));
866 $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
867 if($recent['user']) {
868 $form->addElement('<bdi>' . editorinfo($recent['user']) . '</bdi>');
869 if(auth_ismanager()) {
870 $form->addElement(' <bdo dir="ltr">(' . $recent['ip'] . ')</bdo>');
872 } else {
873 $form->addElement('<bdo dir="ltr">' . $recent['ip'] . '</bdo>');
875 $form->addElement(form_makeCloseTag('span'));
877 html_sizechange($recent['sizechange'], $form);
879 $form->addElement(form_makeCloseTag('div'));
880 $form->addElement(form_makeCloseTag('li'));
882 $form->addElement(form_makeCloseTag('ul'));
884 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
885 $last = $first + $conf['recent'];
886 if($first > 0) {
887 $first -= $conf['recent'];
888 if($first < 0) $first = 0;
889 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
890 $form->addElement(form_makeOpenTag('button', array(
891 'type' => 'submit',
892 'name' => 'first[' . $first . ']',
893 'accesskey' => 'n',
894 'title' => $lang['btn_newer'] . ' [N]',
895 'class' => 'button show'
896 )));
897 $form->addElement($lang['btn_newer']);
898 $form->addElement(form_makeCloseTag('button'));
899 $form->addElement(form_makeCloseTag('div'));
901 if($hasNext) {
902 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
903 $form->addElement(form_makeOpenTag('button', array(
904 'type' => 'submit',
905 'name' => 'first[' . $last . ']',
906 'accesskey' => 'p',
907 'title' => $lang['btn_older'] . ' [P]',
908 'class' => 'button show'
909 )));
910 $form->addElement($lang['btn_older']);
911 $form->addElement(form_makeCloseTag('button'));
912 $form->addElement(form_makeCloseTag('div'));
914 $form->addElement(form_makeCloseTag('div'));
915 html_form('recent', $form);
919 * Display page index
921 * @author Andreas Gohr <andi@splitbrain.org>
923 * @param string $ns
925 function html_index($ns){
926 global $conf;
927 global $ID;
928 $ns = cleanID($ns);
929 if(empty($ns)){
930 $ns = getNS($ID);
931 if($ns === false) $ns ='';
933 $ns = utf8_encodeFN(str_replace(':','/',$ns));
935 echo p_locale_xhtml('index');
936 echo '<div id="index__tree">';
938 $data = array();
939 search($data,$conf['datadir'],'search_index',array('ns' => $ns));
940 echo html_buildlist($data,'idx','html_list_index','html_li_index');
942 echo '</div>';
946 * Index item formatter
948 * User function for html_buildlist()
950 * @author Andreas Gohr <andi@splitbrain.org>
952 * @param array $item
953 * @return string
955 function html_list_index($item){
956 global $ID, $conf;
958 // prevent searchbots needlessly following links
959 $nofollow = ($ID != $conf['start'] || $conf['sitemap']) ? ' rel="nofollow"' : '';
961 $ret = '';
962 $base = ':'.$item['id'];
963 $base = substr($base,strrpos($base,':')+1);
964 if($item['type']=='d'){
965 // FS#2766, no need for search bots to follow namespace links in the index
966 $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" title="' . $item['id'] . '" class="idx_dir"' . $nofollow . '><strong>';
967 $ret .= $base;
968 $ret .= '</strong></a>';
969 }else{
970 // default is noNSorNS($id), but we want noNS($id) when useheading is off FS#2605
971 $ret .= html_wikilink(':'.$item['id'], useHeading('navigation') ? null : noNS($item['id']));
973 return $ret;
977 * Index List item
979 * This user function is used in html_buildlist to build the
980 * <li> tags for namespaces when displaying the page index
981 * it gives different classes to opened or closed "folders"
983 * @author Andreas Gohr <andi@splitbrain.org>
985 * @param array $item
986 * @return string html
988 function html_li_index($item){
989 global $INFO;
990 global $ACT;
992 $class = '';
993 $id = '';
995 if($item['type'] == "f"){
996 // scroll to the current item
997 if($item['id'] == $INFO['id'] && $ACT == 'index') {
998 $id = ' id="scroll__here"';
999 $class = ' bounce';
1001 return '<li class="level'.$item['level'].$class.'" '.$id.'>';
1002 }elseif($item['open']){
1003 return '<li class="open">';
1004 }else{
1005 return '<li class="closed">';
1010 * Default List item
1012 * @author Andreas Gohr <andi@splitbrain.org>
1014 * @param array $item
1015 * @return string html
1017 function html_li_default($item){
1018 return '<li class="level'.$item['level'].'">';
1022 * Build an unordered list
1024 * Build an unordered list from the given $data array
1025 * Each item in the array has to have a 'level' property
1026 * the item itself gets printed by the given $func user
1027 * function. The second and optional function is used to
1028 * print the <li> tag. Both user function need to accept
1029 * a single item.
1031 * Both user functions can be given as array to point to
1032 * a member of an object.
1034 * @author Andreas Gohr <andi@splitbrain.org>
1036 * @param array $data array with item arrays
1037 * @param string $class class of ul wrapper
1038 * @param callable $func callback to print an list item
1039 * @param callable $lifunc callback to the opening li tag
1040 * @param bool $forcewrapper Trigger building a wrapper ul if the first level is
1041 * 0 (we have a root object) or 1 (just the root content)
1042 * @return string html of an unordered list
1044 function html_buildlist($data,$class,$func,$lifunc='html_li_default',$forcewrapper=false){
1045 if (count($data) === 0) {
1046 return '';
1049 $firstElement = reset($data);
1050 $start_level = $firstElement['level'];
1051 $level = $start_level;
1052 $ret = '';
1053 $open = 0;
1055 foreach ($data as $item){
1057 if( $item['level'] > $level ){
1058 //open new list
1059 for($i=0; $i<($item['level'] - $level); $i++){
1060 if ($i) $ret .= "<li class=\"clear\">";
1061 $ret .= "\n<ul class=\"$class\">\n";
1062 $open++;
1064 $level = $item['level'];
1066 }elseif( $item['level'] < $level ){
1067 //close last item
1068 $ret .= "</li>\n";
1069 while( $level > $item['level'] && $open > 0 ){
1070 //close higher lists
1071 $ret .= "</ul>\n</li>\n";
1072 $level--;
1073 $open--;
1075 } elseif ($ret !== '') {
1076 //close previous item
1077 $ret .= "</li>\n";
1080 //print item
1081 $ret .= call_user_func($lifunc,$item);
1082 $ret .= '<div class="li">';
1084 $ret .= call_user_func($func,$item);
1085 $ret .= '</div>';
1088 //close remaining items and lists
1089 $ret .= "</li>\n";
1090 while($open-- > 0) {
1091 $ret .= "</ul></li>\n";
1094 if ($forcewrapper || $start_level < 2) {
1095 // Trigger building a wrapper ul if the first level is
1096 // 0 (we have a root object) or 1 (just the root content)
1097 $ret = "\n<ul class=\"$class\">\n".$ret."</ul>\n";
1100 return $ret;
1104 * display backlinks
1106 * @author Andreas Gohr <andi@splitbrain.org>
1107 * @author Michael Klier <chi@chimeric.de>
1109 function html_backlinks(){
1110 global $ID;
1111 global $lang;
1113 print p_locale_xhtml('backlinks');
1115 $data = ft_backlinks($ID);
1117 if(!empty($data)) {
1118 print '<ul class="idx">';
1119 foreach($data as $blink){
1120 print '<li><div class="li">';
1121 print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink);
1122 print '</div></li>';
1124 print '</ul>';
1125 } else {
1126 print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
1131 * Get header of diff HTML
1133 * @param string $l_rev Left revisions
1134 * @param string $r_rev Right revision
1135 * @param string $id Page id, if null $ID is used
1136 * @param bool $media If it is for media files
1137 * @param bool $inline Return the header on a single line
1138 * @return string[] HTML snippets for diff header
1140 function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = false) {
1141 global $lang;
1142 if ($id === null) {
1143 global $ID;
1144 $id = $ID;
1146 $head_separator = $inline ? ' ' : '<br />';
1147 $media_or_wikiFN = $media ? 'mediaFN' : 'wikiFN';
1148 $ml_or_wl = $media ? 'ml' : 'wl';
1149 $l_minor = $r_minor = '';
1151 if($media) {
1152 $changelog = new MediaChangeLog($id);
1153 } else {
1154 $changelog = new PageChangeLog($id);
1156 if(!$l_rev){
1157 $l_head = '&mdash;';
1158 }else{
1159 $l_info = $changelog->getRevisionInfo($l_rev);
1160 if($l_info['user']){
1161 $l_user = '<bdi>'.editorinfo($l_info['user']).'</bdi>';
1162 if(auth_ismanager()) $l_user .= ' <bdo dir="ltr">('.$l_info['ip'].')</bdo>';
1163 } else {
1164 $l_user = '<bdo dir="ltr">'.$l_info['ip'].'</bdo>';
1166 $l_user = '<span class="user">'.$l_user.'</span>';
1167 $l_sum = ($l_info['sum']) ? '<span class="sum"><bdi>'.hsc($l_info['sum']).'</bdi></span>' : '';
1168 if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
1170 $l_head_title = ($media) ? dformat($l_rev) : $id.' ['.dformat($l_rev).']';
1171 $l_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$l_rev").'">'.
1172 $l_head_title.'</a></bdi>'.
1173 $head_separator.$l_user.' '.$l_sum;
1176 if($r_rev){
1177 $r_info = $changelog->getRevisionInfo($r_rev);
1178 if($r_info['user']){
1179 $r_user = '<bdi>'.editorinfo($r_info['user']).'</bdi>';
1180 if(auth_ismanager()) $r_user .= ' <bdo dir="ltr">('.$r_info['ip'].')</bdo>';
1181 } else {
1182 $r_user = '<bdo dir="ltr">'.$r_info['ip'].'</bdo>';
1184 $r_user = '<span class="user">'.$r_user.'</span>';
1185 $r_sum = ($r_info['sum']) ? '<span class="sum"><bdi>'.hsc($r_info['sum']).'</bdi></span>' : '';
1186 if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
1188 $r_head_title = ($media) ? dformat($r_rev) : $id.' ['.dformat($r_rev).']';
1189 $r_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$r_rev").'">'.
1190 $r_head_title.'</a></bdi>'.
1191 $head_separator.$r_user.' '.$r_sum;
1192 }elseif($_rev = @filemtime($media_or_wikiFN($id))){
1193 $_info = $changelog->getRevisionInfo($_rev);
1194 if($_info['user']){
1195 $_user = '<bdi>'.editorinfo($_info['user']).'</bdi>';
1196 if(auth_ismanager()) $_user .= ' <bdo dir="ltr">('.$_info['ip'].')</bdo>';
1197 } else {
1198 $_user = '<bdo dir="ltr">'.$_info['ip'].'</bdo>';
1200 $_user = '<span class="user">'.$_user.'</span>';
1201 $_sum = ($_info['sum']) ? '<span class="sum"><bdi>'.hsc($_info['sum']).'</span></bdi>' : '';
1202 if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
1204 $r_head_title = ($media) ? dformat($_rev) : $id.' ['.dformat($_rev).']';
1205 $r_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id).'">'.
1206 $r_head_title.'</a></bdi> '.
1207 '('.$lang['current'].')'.
1208 $head_separator.$_user.' '.$_sum;
1209 }else{
1210 $r_head = '&mdash; ('.$lang['current'].')';
1213 return array($l_head, $r_head, $l_minor, $r_minor);
1217 * Show diff
1218 * between current page version and provided $text
1219 * or between the revisions provided via GET or POST
1221 * @author Andreas Gohr <andi@splitbrain.org>
1222 * @param string $text when non-empty: compare with this text with most current version
1223 * @param bool $intro display the intro text
1224 * @param string $type type of the diff (inline or sidebyside)
1226 function html_diff($text = '', $intro = true, $type = null) {
1227 global $ID;
1228 global $REV;
1229 global $lang;
1230 global $INPUT;
1231 global $INFO;
1232 $pagelog = new PageChangeLog($ID);
1235 * Determine diff type
1237 if(!$type) {
1238 $type = $INPUT->str('difftype');
1239 if(empty($type)) {
1240 $type = get_doku_pref('difftype', $type);
1241 if(empty($type) && $INFO['ismobile']) {
1242 $type = 'inline';
1246 if($type != 'inline') $type = 'sidebyside';
1249 * Determine requested revision(s)
1251 // we're trying to be clever here, revisions to compare can be either
1252 // given as rev and rev2 parameters, with rev2 being optional. Or in an
1253 // array in rev2.
1254 $rev1 = $REV;
1256 $rev2 = $INPUT->ref('rev2');
1257 if(is_array($rev2)) {
1258 $rev1 = (int) $rev2[0];
1259 $rev2 = (int) $rev2[1];
1261 if(!$rev1) {
1262 $rev1 = $rev2;
1263 unset($rev2);
1265 } else {
1266 $rev2 = $INPUT->int('rev2');
1270 * Determine left and right revision, its texts and the header
1272 $r_minor = '';
1273 $l_minor = '';
1275 if($text) { // compare text to the most current revision
1276 $l_rev = '';
1277 $l_text = rawWiki($ID, '');
1278 $l_head = '<a class="wikilink1" href="' . wl($ID) . '">' .
1279 $ID . ' ' . dformat((int) @filemtime(wikiFN($ID))) . '</a> ' .
1280 $lang['current'];
1282 $r_rev = '';
1283 $r_text = cleanText($text);
1284 $r_head = $lang['yours'];
1285 } else {
1286 if($rev1 && isset($rev2) && $rev2) { // two specific revisions wanted
1287 // make sure order is correct (older on the left)
1288 if($rev1 < $rev2) {
1289 $l_rev = $rev1;
1290 $r_rev = $rev2;
1291 } else {
1292 $l_rev = $rev2;
1293 $r_rev = $rev1;
1295 } elseif($rev1) { // single revision given, compare to current
1296 $r_rev = '';
1297 $l_rev = $rev1;
1298 } else { // no revision was given, compare previous to current
1299 $r_rev = '';
1300 $revs = $pagelog->getRevisions(0, 1);
1301 $l_rev = $revs[0];
1302 $REV = $l_rev; // store revision back in $REV
1305 // when both revisions are empty then the page was created just now
1306 if(!$l_rev && !$r_rev) {
1307 $l_text = '';
1308 } else {
1309 $l_text = rawWiki($ID, $l_rev);
1311 $r_text = rawWiki($ID, $r_rev);
1313 list($l_head, $r_head, $l_minor, $r_minor) = html_diff_head($l_rev, $r_rev, null, false, $type == 'inline');
1317 * Build navigation
1319 $l_nav = '';
1320 $r_nav = '';
1321 if(!$text) {
1322 list($l_nav, $r_nav) = html_diff_navigation($pagelog, $type, $l_rev, $r_rev);
1325 * Create diff object and the formatter
1327 $diff = new Diff(explode("\n", $l_text), explode("\n", $r_text));
1329 if($type == 'inline') {
1330 $diffformatter = new InlineDiffFormatter();
1331 } else {
1332 $diffformatter = new TableDiffFormatter();
1335 * Display intro
1337 if($intro) print p_locale_xhtml('diff');
1340 * Display type and exact reference
1342 if(!$text) {
1343 ptln('<div class="diffoptions group">');
1346 $form = new Doku_Form(array('action' => wl()));
1347 $form->addHidden('id', $ID);
1348 $form->addHidden('rev2[0]', $l_rev);
1349 $form->addHidden('rev2[1]', $r_rev);
1350 $form->addHidden('do', 'diff');
1351 $form->addElement(
1352 form_makeListboxField(
1353 'difftype',
1354 array(
1355 'sidebyside' => $lang['diff_side'],
1356 'inline' => $lang['diff_inline']
1358 $type,
1359 $lang['diff_type'],
1360 '', '',
1361 array('class' => 'quickselect')
1364 $form->addElement(form_makeButton('submit', 'diff', 'Go'));
1365 $form->printForm();
1367 ptln('<p>');
1368 // link to exactly this view FS#2835
1369 echo html_diff_navigationlink($type, 'difflink', $l_rev, $r_rev ? $r_rev : $INFO['currentrev']);
1370 ptln('</p>');
1372 ptln('</div>'); // .diffoptions
1376 * Display diff view table
1379 <div class="table">
1380 <table class="diff diff_<?php echo $type ?>">
1382 <?php
1383 //navigation and header
1384 if($type == 'inline') {
1385 if(!$text) { ?>
1386 <tr>
1387 <td class="diff-lineheader">-</td>
1388 <td class="diffnav"><?php echo $l_nav ?></td>
1389 </tr>
1390 <tr>
1391 <th class="diff-lineheader">-</th>
1392 <th <?php echo $l_minor ?>>
1393 <?php echo $l_head ?>
1394 </th>
1395 </tr>
1396 <?php } ?>
1397 <tr>
1398 <td class="diff-lineheader">+</td>
1399 <td class="diffnav"><?php echo $r_nav ?></td>
1400 </tr>
1401 <tr>
1402 <th class="diff-lineheader">+</th>
1403 <th <?php echo $r_minor ?>>
1404 <?php echo $r_head ?>
1405 </th>
1406 </tr>
1407 <?php } else {
1408 if(!$text) { ?>
1409 <tr>
1410 <td colspan="2" class="diffnav"><?php echo $l_nav ?></td>
1411 <td colspan="2" class="diffnav"><?php echo $r_nav ?></td>
1412 </tr>
1413 <?php } ?>
1414 <tr>
1415 <th colspan="2" <?php echo $l_minor ?>>
1416 <?php echo $l_head ?>
1417 </th>
1418 <th colspan="2" <?php echo $r_minor ?>>
1419 <?php echo $r_head ?>
1420 </th>
1421 </tr>
1422 <?php }
1424 //diff view
1425 echo html_insert_softbreaks($diffformatter->format($diff)); ?>
1427 </table>
1428 </div>
1429 <?php
1433 * Create html for revision navigation
1435 * @param PageChangeLog $pagelog changelog object of current page
1436 * @param string $type inline vs sidebyside
1437 * @param int $l_rev left revision timestamp
1438 * @param int $r_rev right revision timestamp
1439 * @return string[] html of left and right navigation elements
1441 function html_diff_navigation($pagelog, $type, $l_rev, $r_rev) {
1442 global $INFO, $ID;
1444 // last timestamp is not in changelog, retrieve timestamp from metadata
1445 // note: when page is removed, the metadata timestamp is zero
1446 if(!$r_rev) {
1447 if(isset($INFO['meta']['last_change']['date'])) {
1448 $r_rev = $INFO['meta']['last_change']['date'];
1449 } else {
1450 $r_rev = 0;
1454 //retrieve revisions with additional info
1455 list($l_revs, $r_revs) = $pagelog->getRevisionsAround($l_rev, $r_rev);
1456 $l_revisions = array();
1457 if(!$l_rev) {
1458 $l_revisions[0] = array(0, "", false); //no left revision given, add dummy
1460 foreach($l_revs as $rev) {
1461 $info = $pagelog->getRevisionInfo($rev);
1462 $l_revisions[$rev] = array(
1463 $rev,
1464 dformat($info['date']) . ' ' . editorinfo($info['user'], true) . ' ' . $info['sum'],
1465 $r_rev ? $rev >= $r_rev : false //disable?
1468 $r_revisions = array();
1469 if(!$r_rev) {
1470 $r_revisions[0] = array(0, "", false); //no right revision given, add dummy
1472 foreach($r_revs as $rev) {
1473 $info = $pagelog->getRevisionInfo($rev);
1474 $r_revisions[$rev] = array(
1475 $rev,
1476 dformat($info['date']) . ' ' . editorinfo($info['user'], true) . ' ' . $info['sum'],
1477 $rev <= $l_rev //disable?
1481 //determine previous/next revisions
1482 $l_index = array_search($l_rev, $l_revs);
1483 $l_prev = $l_revs[$l_index + 1];
1484 $l_next = $l_revs[$l_index - 1];
1485 if($r_rev) {
1486 $r_index = array_search($r_rev, $r_revs);
1487 $r_prev = $r_revs[$r_index + 1];
1488 $r_next = $r_revs[$r_index - 1];
1489 } else {
1490 //removed page
1491 if($l_next) {
1492 $r_prev = $r_revs[0];
1493 } else {
1494 $r_prev = null;
1496 $r_next = null;
1500 * Left side:
1502 $l_nav = '';
1503 //move back
1504 if($l_prev) {
1505 $l_nav .= html_diff_navigationlink($type, 'diffbothprevrev', $l_prev, $r_prev);
1506 $l_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_prev, $r_rev);
1508 //dropdown
1509 $form = new Doku_Form(array('action' => wl()));
1510 $form->addHidden('id', $ID);
1511 $form->addHidden('difftype', $type);
1512 $form->addHidden('rev2[1]', $r_rev);
1513 $form->addHidden('do', 'diff');
1514 $form->addElement(
1515 form_makeListboxField(
1516 'rev2[0]',
1517 $l_revisions,
1518 $l_rev,
1519 '', '', '',
1520 array('class' => 'quickselect')
1523 $form->addElement(form_makeButton('submit', 'diff', 'Go'));
1524 $l_nav .= $form->getForm();
1525 //move forward
1526 if($l_next && ($l_next < $r_rev || !$r_rev)) {
1527 $l_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_next, $r_rev);
1531 * Right side:
1533 $r_nav = '';
1534 //move back
1535 if($l_rev < $r_prev) {
1536 $r_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_rev, $r_prev);
1538 //dropdown
1539 $form = new Doku_Form(array('action' => wl()));
1540 $form->addHidden('id', $ID);
1541 $form->addHidden('rev2[0]', $l_rev);
1542 $form->addHidden('difftype', $type);
1543 $form->addHidden('do', 'diff');
1544 $form->addElement(
1545 form_makeListboxField(
1546 'rev2[1]',
1547 $r_revisions,
1548 $r_rev,
1549 '', '', '',
1550 array('class' => 'quickselect')
1553 $form->addElement(form_makeButton('submit', 'diff', 'Go'));
1554 $r_nav .= $form->getForm();
1555 //move forward
1556 if($r_next) {
1557 if($pagelog->isCurrentRevision($r_next)) {
1558 $r_nav .= html_diff_navigationlink($type, 'difflastrev', $l_rev); //last revision is diff with current page
1559 } else {
1560 $r_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_rev, $r_next);
1562 $r_nav .= html_diff_navigationlink($type, 'diffbothnextrev', $l_next, $r_next);
1564 return array($l_nav, $r_nav);
1568 * Create html link to a diff defined by two revisions
1570 * @param string $difftype display type
1571 * @param string $linktype
1572 * @param int $lrev oldest revision
1573 * @param int $rrev newest revision or null for diff with current revision
1574 * @return string html of link to a diff
1576 function html_diff_navigationlink($difftype, $linktype, $lrev, $rrev = null) {
1577 global $ID, $lang;
1578 if(!$rrev) {
1579 $urlparam = array(
1580 'do' => 'diff',
1581 'rev' => $lrev,
1582 'difftype' => $difftype,
1584 } else {
1585 $urlparam = array(
1586 'do' => 'diff',
1587 'rev2[0]' => $lrev,
1588 'rev2[1]' => $rrev,
1589 'difftype' => $difftype,
1592 return '<a class="' . $linktype . '" href="' . wl($ID, $urlparam) . '" title="' . $lang[$linktype] . '">' .
1593 '<span>' . $lang[$linktype] . '</span>' .
1594 '</a>' . "\n";
1598 * Insert soft breaks in diff html
1600 * @param string $diffhtml
1601 * @return string
1603 function html_insert_softbreaks($diffhtml) {
1604 // search the diff html string for both:
1605 // - html tags, so these can be ignored
1606 // - long strings of characters without breaking characters
1607 return preg_replace_callback('/<[^>]*>|[^<> ]{12,}/','html_softbreak_callback',$diffhtml);
1611 * callback which adds softbreaks
1613 * @param array $match array with first the complete match
1614 * @return string the replacement
1616 function html_softbreak_callback($match){
1617 // if match is an html tag, return it intact
1618 if ($match[0]{0} == '<') return $match[0];
1620 // its a long string without a breaking character,
1621 // make certain characters into breaking characters by inserting a
1622 // breaking character (zero length space, U+200B / #8203) in front them.
1623 $regex = <<< REGEX
1624 (?(?= # start a conditional expression with a positive look ahead ...
1625 &\#?\\w{1,6};) # ... for html entities - we don't want to split them (ok to catch some invalid combinations)
1626 &\#?\\w{1,6}; # yes pattern - a quicker match for the html entity, since we know we have one
1628 [?/,&\#;:] # no pattern - any other group of 'special' characters to insert a breaking character after
1629 )+ # end conditional expression
1630 REGEX;
1632 return preg_replace('<'.$regex.'>xu','\0&#8203;',$match[0]);
1636 * show warning on conflict detection
1638 * @author Andreas Gohr <andi@splitbrain.org>
1640 * @param string $text
1641 * @param string $summary
1643 function html_conflict($text,$summary){
1644 global $ID;
1645 global $lang;
1647 print p_locale_xhtml('conflict');
1648 $form = new Doku_Form(array('id' => 'dw__editform'));
1649 $form->addHidden('id', $ID);
1650 $form->addHidden('wikitext', $text);
1651 $form->addHidden('summary', $summary);
1652 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
1653 $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
1654 html_form('conflict', $form);
1655 print '<br /><br /><br /><br />'.NL;
1659 * Prints the global message array
1661 * @author Andreas Gohr <andi@splitbrain.org>
1663 function html_msgarea(){
1664 global $MSG, $MSG_shown;
1665 /** @var array $MSG */
1666 // store if the global $MSG has already been shown and thus HTML output has been started
1667 $MSG_shown = true;
1669 if(!isset($MSG)) return;
1671 $shown = array();
1672 foreach($MSG as $msg){
1673 $hash = md5($msg['msg']);
1674 if(isset($shown[$hash])) continue; // skip double messages
1675 if(info_msg_allowed($msg)){
1676 print '<div class="'.$msg['lvl'].'">';
1677 print $msg['msg'];
1678 print '</div>';
1680 $shown[$hash] = 1;
1683 unset($GLOBALS['MSG']);
1687 * Prints the registration form
1689 * @author Andreas Gohr <andi@splitbrain.org>
1691 function html_register(){
1692 global $lang;
1693 global $conf;
1694 global $INPUT;
1696 $base_attrs = array('size'=>50,'required'=>'required');
1697 $email_attrs = $base_attrs + array('type'=>'email','class'=>'edit');
1699 print p_locale_xhtml('register');
1700 print '<div class="centeralign">'.NL;
1701 $form = new Doku_Form(array('id' => 'dw__register'));
1702 $form->startFieldset($lang['btn_register']);
1703 $form->addHidden('do', 'register');
1704 $form->addHidden('save', '1');
1705 $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block', $base_attrs));
1706 if (!$conf['autopasswd']) {
1707 $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', $base_attrs));
1708 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', $base_attrs));
1710 $form->addElement(form_makeTextField('fullname', $INPUT->post->str('fullname'), $lang['fullname'], '', 'block', $base_attrs));
1711 $form->addElement(form_makeField('email','email', $INPUT->post->str('email'), $lang['email'], '', 'block', $email_attrs));
1712 $form->addElement(form_makeButton('submit', '', $lang['btn_register']));
1713 $form->endFieldset();
1714 html_form('register', $form);
1716 print '</div>'.NL;
1720 * Print the update profile form
1722 * @author Christopher Smith <chris@jalakai.co.uk>
1723 * @author Andreas Gohr <andi@splitbrain.org>
1725 function html_updateprofile(){
1726 global $lang;
1727 global $conf;
1728 global $INPUT;
1729 global $INFO;
1730 /** @var DokuWiki_Auth_Plugin $auth */
1731 global $auth;
1733 print p_locale_xhtml('updateprofile');
1734 print '<div class="centeralign">'.NL;
1736 $fullname = $INPUT->post->str('fullname', $INFO['userinfo']['name'], true);
1737 $email = $INPUT->post->str('email', $INFO['userinfo']['mail'], true);
1738 $form = new Doku_Form(array('id' => 'dw__register'));
1739 $form->startFieldset($lang['profile']);
1740 $form->addHidden('do', 'profile');
1741 $form->addHidden('save', '1');
1742 $form->addElement(form_makeTextField('login', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
1743 $attr = array('size'=>'50');
1744 if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1745 $form->addElement(form_makeTextField('fullname', $fullname, $lang['fullname'], '', 'block', $attr));
1746 $attr = array('size'=>'50', 'class'=>'edit');
1747 if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
1748 $form->addElement(form_makeField('email','email', $email, $lang['email'], '', 'block', $attr));
1749 $form->addElement(form_makeTag('br'));
1750 if ($auth->canDo('modPass')) {
1751 $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1752 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1754 if ($conf['profileconfirm']) {
1755 $form->addElement(form_makeTag('br'));
1756 $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50', 'required' => 'required')));
1758 $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1759 $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
1761 $form->endFieldset();
1762 html_form('updateprofile', $form);
1764 if ($auth->canDo('delUser') && actionOK('profile_delete')) {
1765 $form_profiledelete = new Doku_Form(array('id' => 'dw__profiledelete'));
1766 $form_profiledelete->startFieldset($lang['profdeleteuser']);
1767 $form_profiledelete->addHidden('do', 'profile_delete');
1768 $form_profiledelete->addHidden('delete', '1');
1769 $form_profiledelete->addElement(form_makeCheckboxField('confirm_delete', '1', $lang['profconfdelete'],'dw__confirmdelete','', array('required' => 'required')));
1770 if ($conf['profileconfirm']) {
1771 $form_profiledelete->addElement(form_makeTag('br'));
1772 $form_profiledelete->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50', 'required' => 'required')));
1774 $form_profiledelete->addElement(form_makeButton('submit', '', $lang['btn_deleteuser']));
1775 $form_profiledelete->endFieldset();
1777 html_form('profiledelete', $form_profiledelete);
1780 print '</div>'.NL;
1784 * Preprocess edit form data
1786 * @author Andreas Gohr <andi@splitbrain.org>
1788 * @triggers HTML_EDITFORM_OUTPUT
1790 function html_edit(){
1791 global $INPUT;
1792 global $ID;
1793 global $REV;
1794 global $DATE;
1795 global $PRE;
1796 global $SUF;
1797 global $INFO;
1798 global $SUM;
1799 global $lang;
1800 global $conf;
1801 global $TEXT;
1803 if ($INPUT->has('changecheck')) {
1804 $check = $INPUT->str('changecheck');
1805 } elseif(!$INFO['exists']){
1806 // $TEXT has been loaded from page template
1807 $check = md5('');
1808 } else {
1809 $check = md5($TEXT);
1811 $mod = md5($TEXT) !== $check;
1813 $wr = $INFO['writable'] && !$INFO['locked'];
1814 $include = 'edit';
1815 if($wr){
1816 if ($REV) $include = 'editrev';
1817 }else{
1818 // check pseudo action 'source'
1819 if(!actionOK('source')){
1820 msg('Command disabled: source',-1);
1821 return;
1823 $include = 'read';
1826 global $license;
1828 $form = new Doku_Form(array('id' => 'dw__editform'));
1829 $form->addHidden('id', $ID);
1830 $form->addHidden('rev', $REV);
1831 $form->addHidden('date', $DATE);
1832 $form->addHidden('prefix', $PRE . '.');
1833 $form->addHidden('suffix', $SUF);
1834 $form->addHidden('changecheck', $check);
1836 $data = array('form' => $form,
1837 'wr' => $wr,
1838 'media_manager' => true,
1839 'target' => ($INPUT->has('target') && $wr) ? $INPUT->str('target') : 'section',
1840 'intro_locale' => $include);
1842 if ($data['target'] !== 'section') {
1843 // Only emit event if page is writable, section edit data is valid and
1844 // edit target is not section.
1845 trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true);
1846 } else {
1847 html_edit_form($data);
1849 if (isset($data['intro_locale'])) {
1850 echo p_locale_xhtml($data['intro_locale']);
1853 $form->addHidden('target', $data['target']);
1854 if ($INPUT->has('hid')) {
1855 $form->addHidden('hid', $INPUT->str('hid'));
1857 $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar', 'class'=>'editBar')));
1858 $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1859 $form->addElement(form_makeCloseTag('div'));
1860 if ($wr) {
1861 $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
1862 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
1863 $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
1864 $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
1865 $form->addElement(form_makeCloseTag('div'));
1866 $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
1867 $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
1868 $elem = html_minoredit();
1869 if ($elem) $form->addElement($elem);
1870 $form->addElement(form_makeCloseTag('div'));
1872 $form->addElement(form_makeCloseTag('div'));
1873 if($wr && $conf['license']){
1874 $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1875 $out = $lang['licenseok'];
1876 $out .= ' <a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
1877 if($conf['target']['extern']) $out .= ' target="'.$conf['target']['extern'].'"';
1878 $out .= '>'.$license[$conf['license']]['name'].'</a>';
1879 $form->addElement($out);
1880 $form->addElement(form_makeCloseTag('div'));
1883 if ($wr) {
1884 // sets changed to true when previewed
1885 echo '<script type="text/javascript">/*<![CDATA[*/'. NL;
1886 echo 'textChanged = ' . ($mod ? 'true' : 'false');
1887 echo '/*!]]>*/</script>' . NL;
1888 } ?>
1889 <div class="editBox" role="application">
1891 <div class="toolbar group">
1892 <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div>
1893 <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']?>"
1894 target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
1895 </div>
1896 <?php
1898 html_form('edit', $form);
1899 print '</div>'.NL;
1903 * Display the default edit form
1905 * Is the default action for HTML_EDIT_FORMSELECTION.
1907 * @param mixed[] $param
1909 function html_edit_form($param) {
1910 global $TEXT;
1912 if ($param['target'] !== 'section') {
1913 msg('No editor for edit target ' . hsc($param['target']) . ' found.', -1);
1916 $attr = array('tabindex'=>'1');
1917 if (!$param['wr']) $attr['readonly'] = 'readonly';
1919 $param['form']->addElement(form_makeWikiText($TEXT, $attr));
1923 * Adds a checkbox for minor edits for logged in users
1925 * @author Andreas Gohr <andi@splitbrain.org>
1927 * @return array|bool
1929 function html_minoredit(){
1930 global $conf;
1931 global $lang;
1932 global $INPUT;
1933 // minor edits are for logged in users only
1934 if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1935 return false;
1938 $p = array();
1939 $p['tabindex'] = 3;
1940 if($INPUT->bool('minor')) $p['checked']='checked';
1941 return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
1945 * prints some debug info
1947 * @author Andreas Gohr <andi@splitbrain.org>
1949 function html_debug(){
1950 global $conf;
1951 global $lang;
1952 /** @var DokuWiki_Auth_Plugin $auth */
1953 global $auth;
1954 global $INFO;
1956 //remove sensitive data
1957 $cnf = $conf;
1958 debug_guard($cnf);
1959 $nfo = $INFO;
1960 debug_guard($nfo);
1961 $ses = $_SESSION;
1962 debug_guard($ses);
1964 print '<html><body>';
1966 print '<p>When reporting bugs please send all the following ';
1967 print 'output as a mail to andi@splitbrain.org ';
1968 print 'The best way to do this is to save this page in your browser</p>';
1970 print '<b>$INFO:</b><pre>';
1971 print_r($nfo);
1972 print '</pre>';
1974 print '<b>$_SERVER:</b><pre>';
1975 print_r($_SERVER);
1976 print '</pre>';
1978 print '<b>$conf:</b><pre>';
1979 print_r($cnf);
1980 print '</pre>';
1982 print '<b>DOKU_BASE:</b><pre>';
1983 print DOKU_BASE;
1984 print '</pre>';
1986 print '<b>abs DOKU_BASE:</b><pre>';
1987 print DOKU_URL;
1988 print '</pre>';
1990 print '<b>rel DOKU_BASE:</b><pre>';
1991 print dirname($_SERVER['PHP_SELF']).'/';
1992 print '</pre>';
1994 print '<b>PHP Version:</b><pre>';
1995 print phpversion();
1996 print '</pre>';
1998 print '<b>locale:</b><pre>';
1999 print setlocale(LC_ALL,0);
2000 print '</pre>';
2002 print '<b>encoding:</b><pre>';
2003 print $lang['encoding'];
2004 print '</pre>';
2006 if($auth){
2007 print '<b>Auth backend capabilities:</b><pre>';
2008 foreach ($auth->getCapabilities() as $cando){
2009 print ' '.str_pad($cando,16) . ' => ' . (int)$auth->canDo($cando) . NL;
2011 print '</pre>';
2014 print '<b>$_SESSION:</b><pre>';
2015 print_r($ses);
2016 print '</pre>';
2018 print '<b>Environment:</b><pre>';
2019 print_r($_ENV);
2020 print '</pre>';
2022 print '<b>PHP settings:</b><pre>';
2023 $inis = ini_get_all();
2024 print_r($inis);
2025 print '</pre>';
2027 if (function_exists('apache_get_version')) {
2028 $apache = array();
2029 $apache['version'] = apache_get_version();
2031 if (function_exists('apache_get_modules')) {
2032 $apache['modules'] = apache_get_modules();
2034 print '<b>Apache</b><pre>';
2035 print_r($apache);
2036 print '</pre>';
2039 print '</body></html>';
2043 * Form to request a new password for an existing account
2045 * @author Benoit Chesneau <benoit@bchesneau.info>
2046 * @author Andreas Gohr <gohr@cosmocode.de>
2048 function html_resendpwd() {
2049 global $lang;
2050 global $conf;
2051 global $INPUT;
2053 $token = preg_replace('/[^a-f0-9]+/','',$INPUT->str('pwauth'));
2055 if(!$conf['autopasswd'] && $token){
2056 print p_locale_xhtml('resetpwd');
2057 print '<div class="centeralign">'.NL;
2058 $form = new Doku_Form(array('id' => 'dw__resendpwd'));
2059 $form->startFieldset($lang['btn_resendpwd']);
2060 $form->addHidden('token', $token);
2061 $form->addHidden('do', 'resendpwd');
2063 $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
2064 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
2066 $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
2067 $form->endFieldset();
2068 html_form('resendpwd', $form);
2069 print '</div>'.NL;
2070 }else{
2071 print p_locale_xhtml('resendpwd');
2072 print '<div class="centeralign">'.NL;
2073 $form = new Doku_Form(array('id' => 'dw__resendpwd'));
2074 $form->startFieldset($lang['resendpwd']);
2075 $form->addHidden('do', 'resendpwd');
2076 $form->addHidden('save', '1');
2077 $form->addElement(form_makeTag('br'));
2078 $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block'));
2079 $form->addElement(form_makeTag('br'));
2080 $form->addElement(form_makeTag('br'));
2081 $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
2082 $form->endFieldset();
2083 html_form('resendpwd', $form);
2084 print '</div>'.NL;
2089 * Return the TOC rendered to XHTML
2091 * @author Andreas Gohr <andi@splitbrain.org>
2093 * @param array $toc
2094 * @return string html
2096 function html_TOC($toc){
2097 if(!count($toc)) return '';
2098 global $lang;
2099 $out = '<!-- TOC START -->'.DOKU_LF;
2100 $out .= '<div id="dw__toc">'.DOKU_LF;
2101 $out .= '<h3 class="toggle">';
2102 $out .= $lang['toc'];
2103 $out .= '</h3>'.DOKU_LF;
2104 $out .= '<div>'.DOKU_LF;
2105 $out .= html_buildlist($toc,'toc','html_list_toc','html_li_default',true);
2106 $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
2107 $out .= '<!-- TOC END -->'.DOKU_LF;
2108 return $out;
2112 * Callback for html_buildlist
2114 * @param array $item
2115 * @return string html
2117 function html_list_toc($item){
2118 if(isset($item['hid'])){
2119 $link = '#'.$item['hid'];
2120 }else{
2121 $link = $item['link'];
2124 return '<a href="'.$link.'">'.hsc($item['title']).'</a>';
2128 * Helper function to build TOC items
2130 * Returns an array ready to be added to a TOC array
2132 * @param string $link - where to link (if $hash set to '#' it's a local anchor)
2133 * @param string $text - what to display in the TOC
2134 * @param int $level - nesting level
2135 * @param string $hash - is prepended to the given $link, set blank if you want full links
2136 * @return array the toc item
2138 function html_mktocitem($link, $text, $level, $hash='#'){
2139 return array( 'link' => $hash.$link,
2140 'title' => $text,
2141 'type' => 'ul',
2142 'level' => $level);
2146 * Output a Doku_Form object.
2147 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
2149 * @author Tom N Harris <tnharris@whoopdedo.org>
2151 * @param string $name The name of the form
2152 * @param Doku_Form $form The form
2154 function html_form($name, &$form) {
2155 // Safety check in case the caller forgets.
2156 $form->endFieldset();
2157 trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
2161 * Form print function.
2162 * Just calls printForm() on the data object.
2164 * @param Doku_Form $data The form
2166 function html_form_output($data) {
2167 $data->printForm();
2171 * Embed a flash object in HTML
2173 * This will create the needed HTML to embed a flash movie in a cross browser
2174 * compatble way using valid XHTML
2176 * The parameters $params, $flashvars and $atts need to be associative arrays.
2177 * No escaping needs to be done for them. The alternative content *has* to be
2178 * escaped because it is used as is. If no alternative content is given
2179 * $lang['noflash'] is used.
2181 * @author Andreas Gohr <andi@splitbrain.org>
2182 * @link http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
2184 * @param string $swf - the SWF movie to embed
2185 * @param int $width - width of the flash movie in pixels
2186 * @param int $height - height of the flash movie in pixels
2187 * @param array $params - additional parameters (<param>)
2188 * @param array $flashvars - parameters to be passed in the flashvar parameter
2189 * @param array $atts - additional attributes for the <object> tag
2190 * @param string $alt - alternative content (is NOT automatically escaped!)
2191 * @return string - the XHTML markup
2193 function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
2194 global $lang;
2196 $out = '';
2198 // prepare the object attributes
2199 if(is_null($atts)) $atts = array();
2200 $atts['width'] = (int) $width;
2201 $atts['height'] = (int) $height;
2202 if(!$atts['width']) $atts['width'] = 425;
2203 if(!$atts['height']) $atts['height'] = 350;
2205 // add object attributes for standard compliant browsers
2206 $std = $atts;
2207 $std['type'] = 'application/x-shockwave-flash';
2208 $std['data'] = $swf;
2210 // add object attributes for IE
2211 $ie = $atts;
2212 $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
2214 // open object (with conditional comments)
2215 $out .= '<!--[if !IE]> -->'.NL;
2216 $out .= '<object '.buildAttributes($std).'>'.NL;
2217 $out .= '<!-- <![endif]-->'.NL;
2218 $out .= '<!--[if IE]>'.NL;
2219 $out .= '<object '.buildAttributes($ie).'>'.NL;
2220 $out .= ' <param name="movie" value="'.hsc($swf).'" />'.NL;
2221 $out .= '<!--><!-- -->'.NL;
2223 // print params
2224 if(is_array($params)) foreach($params as $key => $val){
2225 $out .= ' <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
2228 // add flashvars
2229 if(is_array($flashvars)){
2230 $out .= ' <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
2233 // alternative content
2234 if($alt){
2235 $out .= $alt.NL;
2236 }else{
2237 $out .= $lang['noflash'].NL;
2240 // finish
2241 $out .= '</object>'.NL;
2242 $out .= '<!-- <![endif]-->'.NL;
2244 return $out;
2248 * Prints HTML code for the given tab structure
2250 * @param array $tabs tab structure
2251 * @param string $current_tab the current tab id
2253 function html_tabs($tabs, $current_tab = null) {
2254 echo '<ul class="tabs">'.NL;
2256 foreach($tabs as $id => $tab) {
2257 html_tab($tab['href'], $tab['caption'], $id === $current_tab);
2260 echo '</ul>'.NL;
2264 * Prints a single tab
2266 * @author Kate Arzamastseva <pshns@ukr.net>
2267 * @author Adrian Lang <mail@adrianlang.de>
2269 * @param string $href - tab href
2270 * @param string $caption - tab caption
2271 * @param boolean $selected - is tab selected
2274 function html_tab($href, $caption, $selected=false) {
2275 $tab = '<li>';
2276 if ($selected) {
2277 $tab .= '<strong>';
2278 } else {
2279 $tab .= '<a href="' . hsc($href) . '">';
2281 $tab .= hsc($caption)
2282 . '</' . ($selected ? 'strong' : 'a') . '>'
2283 . '</li>'.NL;
2284 echo $tab;
2288 * Display size change
2290 * @param int $sizechange - size of change in Bytes
2291 * @param Doku_Form $form - form to add elements to
2294 function html_sizechange($sizechange, Doku_Form $form) {
2295 if(isset($sizechange)) {
2296 $class = 'sizechange';
2297 $value = filesize_h(abs($sizechange));
2298 if($sizechange > 0) {
2299 $class .= ' positive';
2300 $value = '+' . $value;
2301 } elseif($sizechange < 0) {
2302 $class .= ' negative';
2303 $value = '-' . $value;
2304 } else {
2305 $value = '±' . $value;
2307 $form->addElement(form_makeOpenTag('span', array('class' => $class)));
2308 $form->addElement($value);
2309 $form->addElement(form_makeCloseTag('span'));