Added diff navigation
[dokuwiki.git] / inc / html.php
blob9d344a05fe4bfa7a9e17cdd8d0fd27ad4d5f5eb0
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 static $xhtml_renderer = null;
23 if(is_null($xhtml_renderer)){
24 $xhtml_renderer = p_get_renderer('xhtml');
27 return $xhtml_renderer->internallink($id,$name,$search,true,'navigation');
30 /**
31 * Helps building long attribute lists
33 * @deprecated Use buildAttributes instead
34 * @author Andreas Gohr <andi@splitbrain.org>
36 function html_attbuild($attributes){
37 $ret = '';
38 foreach ( $attributes as $key => $value ) {
39 $ret .= $key.'="'.formText($value).'" ';
41 return trim($ret);
44 /**
45 * The loginform
47 * @author Andreas Gohr <andi@splitbrain.org>
49 function html_login(){
50 global $lang;
51 global $conf;
52 global $ID;
53 global $INPUT;
55 print p_locale_xhtml('login');
56 print '<div class="centeralign">'.NL;
57 $form = new Doku_Form(array('id' => 'dw__login'));
58 $form->startFieldset($lang['btn_login']);
59 $form->addHidden('id', $ID);
60 $form->addHidden('do', 'login');
61 $form->addElement(form_makeTextField('u', ((!$INPUT->bool('http_credentials')) ? $INPUT->str('u') : ''), $lang['user'], 'focus__this', 'block'));
62 $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block'));
63 if($conf['rememberme']) {
64 $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple'));
66 $form->addElement(form_makeButton('submit', '', $lang['btn_login']));
67 $form->endFieldset();
69 if(actionOK('register')){
70 $form->addElement('<p>'.$lang['reghere'].': '.tpl_actionlink('register','','','',true).'</p>');
73 if (actionOK('resendpwd')) {
74 $form->addElement('<p>'.$lang['pwdforget'].': '.tpl_actionlink('resendpwd','','','',true).'</p>');
77 html_form('login', $form);
78 print '</div>'.NL;
81 /**
82 * inserts section edit buttons if wanted or removes the markers
84 * @author Andreas Gohr <andi@splitbrain.org>
86 function html_secedit($text,$show=true){
87 global $INFO;
89 $regexp = '#<!-- EDIT(\d+) ([A-Z_]+) (?:"([^"]*)" )?\[(\d+-\d*)\] -->#';
91 if(!$INFO['writable'] || !$show || $INFO['rev']){
92 return preg_replace($regexp,'',$text);
95 return preg_replace_callback($regexp,
96 'html_secedit_button', $text);
99 /**
100 * prepares section edit button data for event triggering
101 * used as a callback in html_secedit
103 * @triggers HTML_SECEDIT_BUTTON
104 * @author Andreas Gohr <andi@splitbrain.org>
106 function html_secedit_button($matches){
107 $data = array('secid' => $matches[1],
108 'target' => strtolower($matches[2]),
109 'range' => $matches[count($matches) - 1]);
110 if (count($matches) === 5) {
111 $data['name'] = $matches[3];
114 return trigger_event('HTML_SECEDIT_BUTTON', $data,
115 'html_secedit_get_button');
119 * prints a section editing button
120 * used as default action form HTML_SECEDIT_BUTTON
122 * @author Adrian Lang <lang@cosmocode.de>
124 function html_secedit_get_button($data) {
125 global $ID;
126 global $INFO;
128 if (!isset($data['name']) || $data['name'] === '') return '';
130 $name = $data['name'];
131 unset($data['name']);
133 $secid = $data['secid'];
134 unset($data['secid']);
136 return "<div class='secedit editbutton_" . $data['target'] .
137 " editbutton_" . $secid . "'>" .
138 html_btn('secedit', $ID, '',
139 array_merge(array('do' => 'edit',
140 'rev' => $INFO['lastmod'],
141 'summary' => '['.$name.'] '), $data),
142 'post', $name) . '</div>';
146 * Just the back to top button (in its own form)
148 * @author Andreas Gohr <andi@splitbrain.org>
150 function html_topbtn(){
151 global $lang;
153 $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>';
155 return $ret;
159 * Displays a button (using its own form)
160 * If tooltip exists, the access key tooltip is replaced.
162 * @author Andreas Gohr <andi@splitbrain.org>
164 function html_btn($name,$id,$akey,$params,$method='get',$tooltip='',$label=false){
165 global $conf;
166 global $lang;
168 if (!$label)
169 $label = $lang['btn_'.$name];
171 $ret = '';
173 //filter id (without urlencoding)
174 $id = idfilter($id,false);
176 //make nice URLs even for buttons
177 if($conf['userewrite'] == 2){
178 $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
179 }elseif($conf['userewrite']){
180 $script = DOKU_BASE.$id;
181 }else{
182 $script = DOKU_BASE.DOKU_SCRIPT;
183 $params['id'] = $id;
186 $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
188 if(is_array($params)){
189 reset($params);
190 while (list($key, $val) = each($params)) {
191 $ret .= '<input type="hidden" name="'.$key.'" ';
192 $ret .= 'value="'.htmlspecialchars($val).'" />';
196 if ($tooltip!='') {
197 $tip = htmlspecialchars($tooltip);
198 }else{
199 $tip = htmlspecialchars($label);
202 $ret .= '<input type="submit" value="'.hsc($label).'" class="button" ';
203 if($akey){
204 $tip .= ' ['.strtoupper($akey).']';
205 $ret .= 'accesskey="'.$akey.'" ';
207 $ret .= 'title="'.$tip.'" ';
208 $ret .= '/>';
209 $ret .= '</div></form>';
211 return $ret;
215 * show a wiki page
217 * @author Andreas Gohr <andi@splitbrain.org>
219 function html_show($txt=null){
220 global $ID;
221 global $REV;
222 global $HIGH;
223 global $INFO;
224 //disable section editing for old revisions or in preview
225 if($txt || $REV){
226 $secedit = false;
227 }else{
228 $secedit = true;
231 if (!is_null($txt)){
232 //PreviewHeader
233 echo '<br id="scroll__here" />';
234 echo p_locale_xhtml('preview');
235 echo '<div class="preview"><div class="pad">';
236 $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
237 if($INFO['prependTOC']) $html = tpl_toc(true).$html;
238 echo $html;
239 echo '<div class="clearer"></div>';
240 echo '</div></div>';
242 }else{
243 if ($REV) print p_locale_xhtml('showrev');
244 $html = p_wiki_xhtml($ID,$REV,true);
245 $html = html_secedit($html,$secedit);
246 if($INFO['prependTOC']) $html = tpl_toc(true).$html;
247 $html = html_hilight($html,$HIGH);
248 echo $html;
253 * ask the user about how to handle an exisiting draft
255 * @author Andreas Gohr <andi@splitbrain.org>
257 function html_draft(){
258 global $INFO;
259 global $ID;
260 global $lang;
261 $draft = unserialize(io_readFile($INFO['draft'],false));
262 $text = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
264 print p_locale_xhtml('draft');
265 $form = new Doku_Form(array('id' => 'dw__editform'));
266 $form->addHidden('id', $ID);
267 $form->addHidden('date', $draft['date']);
268 $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly')));
269 $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
270 $form->addElement($lang['draftdate'].' '. dformat(filemtime($INFO['draft'])));
271 $form->addElement(form_makeCloseTag('div'));
272 $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
273 $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
274 $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3')));
275 html_form('draft', $form);
279 * Highlights searchqueries in HTML code
281 * @author Andreas Gohr <andi@splitbrain.org>
282 * @author Harry Fuecks <hfuecks@gmail.com>
284 function html_hilight($html,$phrases){
285 $phrases = (array) $phrases;
286 $phrases = array_map('preg_quote_cb', $phrases);
287 $phrases = array_map('ft_snippet_re_preprocess', $phrases);
288 $phrases = array_filter($phrases);
289 $regex = join('|',$phrases);
291 if ($regex === '') return $html;
292 if (!utf8_check($regex)) return $html;
293 $html = @preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
294 return $html;
298 * Callback used by html_hilight()
300 * @author Harry Fuecks <hfuecks@gmail.com>
302 function html_hilight_callback($m) {
303 $hlight = unslash($m[0]);
304 if ( !isset($m[2])) {
305 $hlight = '<span class="search_hit">'.$hlight.'</span>';
307 return $hlight;
311 * Run a search and display the result
313 * @author Andreas Gohr <andi@splitbrain.org>
315 function html_search(){
316 global $QUERY;
317 global $lang;
319 $intro = p_locale_xhtml('searchpage');
320 // allow use of placeholder in search intro
321 $intro = str_replace(
322 array('@QUERY@','@SEARCH@'),
323 array(hsc(rawurlencode($QUERY)),hsc($QUERY)),
324 $intro);
325 echo $intro;
326 flush();
328 //show progressbar
329 print '<div id="dw__loading">'.NL;
330 print '<script type="text/javascript">/*<![CDATA[*/'.NL;
331 print 'showLoadBar();'.NL;
332 print '/*!]]>*/</script>'.NL;
333 print '</div>'.NL;
334 flush();
336 //do quick pagesearch
337 $data = ft_pageLookup($QUERY,true,useHeading('navigation'));
338 if(count($data)){
339 print '<div class="search_quickresult">';
340 print '<h3>'.$lang['quickhits'].':</h3>';
341 print '<ul class="search_quickhits">';
342 foreach($data as $id => $title){
343 print '<li> ';
344 if (useHeading('navigation')) {
345 $name = $title;
346 }else{
347 $ns = getNS($id);
348 if($ns){
349 $name = shorten(noNS($id), ' ('.$ns.')',30);
350 }else{
351 $name = $id;
354 print html_wikilink(':'.$id,$name);
355 print '</li> ';
357 print '</ul> ';
358 //clear float (see http://www.complexspiral.com/publications/containing-floats/)
359 print '<div class="clearer"></div>';
360 print '</div>';
362 flush();
364 //do fulltext search
365 $data = ft_pageSearch($QUERY,$regex);
366 if(count($data)){
367 print '<dl class="search_results">';
368 $num = 1;
369 foreach($data as $id => $cnt){
370 print '<dt>';
371 print html_wikilink(':'.$id,useHeading('navigation')?null:$id,$regex);
372 if($cnt !== 0){
373 print ': '.$cnt.' '.$lang['hits'].'';
375 print '</dt>';
376 if($cnt !== 0){
377 if($num < FT_SNIPPET_NUMBER){ // create snippets for the first number of matches only
378 print '<dd>'.ft_snippet($id,$regex).'</dd>';
380 $num++;
382 flush();
384 print '</dl>';
385 }else{
386 print '<div class="nothing">'.$lang['nothingfound'].'</div>';
389 //hide progressbar
390 print '<script type="text/javascript">/*<![CDATA[*/'.NL;
391 print 'hideLoadBar("dw__loading");'.NL;
392 print '/*!]]>*/</script>'.NL;
393 flush();
397 * Display error on locked pages
399 * @author Andreas Gohr <andi@splitbrain.org>
401 function html_locked(){
402 global $ID;
403 global $conf;
404 global $lang;
405 global $INFO;
407 $locktime = filemtime(wikiLockFN($ID));
408 $expire = dformat($locktime + $conf['locktime']);
409 $min = round(($conf['locktime'] - (time() - $locktime) )/60);
411 print p_locale_xhtml('locked');
412 print '<ul>';
413 print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.editorinfo($INFO['locked']).'</div></li>';
414 print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>';
415 print '</ul>';
419 * list old revisions
421 * @author Andreas Gohr <andi@splitbrain.org>
422 * @author Ben Coburn <btcoburn@silicodon.net>
423 * @author Kate Arzamastseva <pshns@ukr.net>
425 function html_revisions($first=0, $media_id = false){
426 global $ID;
427 global $INFO;
428 global $conf;
429 global $lang;
430 $id = $ID;
431 /* we need to get one additionally log entry to be able to
432 * decide if this is the last page or is there another one.
433 * see html_recent()
435 if (!$media_id) $revisions = getRevisions($ID, $first, $conf['recent']+1);
436 else {
437 $revisions = getRevisions($media_id, $first, $conf['recent']+1, 8192, true);
438 $id = $media_id;
441 if(count($revisions)==0 && $first!=0){
442 $first=0;
443 if (!$media_id) $revisions = getRevisions($ID, $first, $conf['recent']+1);
444 else $revisions = getRevisions($media_id, $first, $conf['recent']+1, 8192, true);
446 $hasNext = false;
447 if (count($revisions)>$conf['recent']) {
448 $hasNext = true;
449 array_pop($revisions); // remove extra log entry
452 if (!$media_id) $date = dformat($INFO['lastmod']);
453 else $date = dformat(@filemtime(mediaFN($id)));
455 if (!$media_id) print p_locale_xhtml('revisions');
457 $params = array('id' => 'page__revisions', 'class' => 'changes');
458 if ($media_id) $params['action'] = media_managerURL(array('image' => $media_id), '&');
460 $form = new Doku_Form($params);
461 $form->addElement(form_makeOpenTag('ul'));
463 if (!$media_id) $exists = $INFO['exists'];
464 else $exists = @file_exists(mediaFN($id));
466 $display_name = (!$media_id && useHeading('navigation')) ? hsc(p_get_first_heading($id)) : $id;
467 if (!$display_name) $display_name = $id;
469 if($exists && $first==0){
470 if (!$media_id && isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
471 $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
472 else
473 $form->addElement(form_makeOpenTag('li'));
474 $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
475 $form->addElement(form_makeTag('input', array(
476 'type' => 'checkbox',
477 'name' => 'rev2[]',
478 'value' => 'current')));
480 $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
481 $form->addElement($date);
482 $form->addElement(form_makeCloseTag('span'));
484 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
486 if (!$media_id) $href = wl($id);
487 else $href = media_managerURL(array('image' => $id, 'tab_details' => 'view'), '&');
488 $form->addElement(form_makeOpenTag('a', array(
489 'class' => 'wikilink1',
490 'href' => $href)));
491 $form->addElement($display_name);
492 $form->addElement(form_makeCloseTag('a'));
494 if ($media_id) $form->addElement(form_makeOpenTag('div'));
496 if (!$media_id) {
497 $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
498 $form->addElement(' – ');
499 $form->addElement(htmlspecialchars($INFO['sum']));
500 $form->addElement(form_makeCloseTag('span'));
503 $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
504 if (!$media_id) $editor = $INFO['editor'];
505 else {
506 $revinfo = getRevisionInfo($id, @filemtime(fullpath(mediaFN($id))), 1024, true);
507 if($revinfo['user']){
508 $editor = $revinfo['user'];
509 }else{
510 $editor = $revinfo['ip'];
513 $form->addElement((empty($editor))?('('.$lang['external_edit'].')'):editorinfo($editor));
514 $form->addElement(form_makeCloseTag('span'));
516 $form->addElement('('.$lang['current'].')');
518 if ($media_id) $form->addElement(form_makeCloseTag('div'));
520 $form->addElement(form_makeCloseTag('div'));
521 $form->addElement(form_makeCloseTag('li'));
524 foreach($revisions as $rev){
525 $date = dformat($rev);
526 if (!$media_id) {
527 $info = getRevisionInfo($id,$rev,true);
528 $exists = page_exists($id,$rev);
529 } else {
530 $info = getRevisionInfo($id,$rev,true,true);
531 $exists = @file_exists(mediaFN($id,$rev));
534 if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
535 $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
536 else
537 $form->addElement(form_makeOpenTag('li'));
538 $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
539 if($exists){
540 $form->addElement(form_makeTag('input', array(
541 'type' => 'checkbox',
542 'name' => 'rev2[]',
543 'value' => $rev)));
544 }else{
545 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
548 $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
549 $form->addElement($date);
550 $form->addElement(form_makeCloseTag('span'));
552 if($exists){
553 if (!$media_id) $href = wl($id,"rev=$rev,do=diff", false, '&');
554 else $href = media_managerURL(array('image' => $id, 'rev' => $rev, 'mediado' => 'diff'), '&');
555 $form->addElement(form_makeOpenTag('a', array('href' => $href, 'class' => 'diff_link')));
556 $form->addElement(form_makeTag('img', array(
557 'src' => DOKU_BASE.'lib/images/diff.png',
558 'width' => 15,
559 'height' => 11,
560 'title' => $lang['diff'],
561 'alt' => $lang['diff'])));
562 $form->addElement(form_makeCloseTag('a'));
563 if (!$media_id) $href = wl($id,"rev=$rev",false,'&');
564 else $href = media_managerURL(array('image' => $id, 'tab_details' => 'view', 'rev' => $rev), '&');
565 $form->addElement(form_makeOpenTag('a', array('href' => $href, 'class' => 'wikilink1')));
566 $form->addElement($display_name);
567 $form->addElement(form_makeCloseTag('a'));
568 }else{
569 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
570 $form->addElement($display_name);
573 if ($media_id) $form->addElement(form_makeOpenTag('div'));
575 if ($info['sum']) {
576 $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
577 if (!$media_id) $form->addElement(' – ');
578 $form->addElement(htmlspecialchars($info['sum']));
579 $form->addElement(form_makeCloseTag('span'));
582 $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
583 if($info['user']){
584 $form->addElement(editorinfo($info['user']));
585 if(auth_ismanager()){
586 $form->addElement(' ('.$info['ip'].')');
588 }else{
589 $form->addElement($info['ip']);
591 $form->addElement(form_makeCloseTag('span'));
593 if ($media_id) $form->addElement(form_makeCloseTag('div'));
595 $form->addElement(form_makeCloseTag('div'));
596 $form->addElement(form_makeCloseTag('li'));
598 $form->addElement(form_makeCloseTag('ul'));
599 if (!$media_id) {
600 $form->addElement(form_makeButton('submit', 'diff', $lang['diff2']));
601 } else {
602 $form->addHidden('mediado', 'diff');
603 $form->addElement(form_makeButton('submit', '', $lang['diff2']));
605 html_form('revisions', $form);
607 print '<div class="pagenav">';
608 $last = $first + $conf['recent'];
609 if ($first > 0) {
610 $first -= $conf['recent'];
611 if ($first < 0) $first = 0;
612 print '<div class="pagenav-prev">';
613 if ($media_id) {
614 print html_btn('newer',$media_id,"p",media_managerURL(array('first' => $first), '&amp;', false, true));
615 } else {
616 print html_btn('newer',$id,"p",array('do' => 'revisions', 'first' => $first));
618 print '</div>';
620 if ($hasNext) {
621 print '<div class="pagenav-next">';
622 if ($media_id) {
623 print html_btn('older',$media_id,"n",media_managerURL(array('first' => $last), '&amp;', false, true));
624 } else {
625 print html_btn('older',$id,"n",array('do' => 'revisions', 'first' => $last));
627 print '</div>';
629 print '</div>';
634 * display recent changes
636 * @author Andreas Gohr <andi@splitbrain.org>
637 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
638 * @author Ben Coburn <btcoburn@silicodon.net>
639 * @author Kate Arzamastseva <pshns@ukr.net>
641 function html_recent($first=0, $show_changes='both'){
642 global $conf;
643 global $lang;
644 global $ID;
645 /* we need to get one additionally log entry to be able to
646 * decide if this is the last page or is there another one.
647 * This is the cheapest solution to get this information.
649 $flags = 0;
650 if ($show_changes == 'mediafiles' && $conf['mediarevisions']) {
651 $flags = RECENTS_MEDIA_CHANGES;
652 } elseif ($show_changes == 'pages') {
653 $flags = 0;
654 } elseif ($conf['mediarevisions']) {
655 $show_changes = 'both';
656 $flags = RECENTS_MEDIA_PAGES_MIXED;
659 $recents = getRecents($first,$conf['recent'] + 1,getNS($ID),$flags);
660 if(count($recents) == 0 && $first != 0){
661 $first=0;
662 $recents = getRecents($first,$conf['recent'] + 1,getNS($ID),$flags);
664 $hasNext = false;
665 if (count($recents)>$conf['recent']) {
666 $hasNext = true;
667 array_pop($recents); // remove extra log entry
670 print p_locale_xhtml('recent');
672 if (getNS($ID) != '')
673 print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>';
675 $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET', 'class' => 'changes'));
676 $form->addHidden('sectok', null);
677 $form->addHidden('do', 'recent');
678 $form->addHidden('id', $ID);
680 if ($conf['mediarevisions']) {
681 $form->addElement('<div class="changeType">');
682 $form->addElement(form_makeListboxField(
683 'show_changes',
684 array(
685 'pages' => $lang['pages_changes'],
686 'mediafiles' => $lang['media_changes'],
687 'both' => $lang['both_changes']),
688 $show_changes,
689 $lang['changes_type'],
690 '','',
691 array('class'=>'quickselect')));
693 $form->addElement(form_makeButton('submit', 'recent', $lang['btn_apply']));
694 $form->addElement('</div>');
697 $form->addElement(form_makeOpenTag('ul'));
699 foreach($recents as $recent){
700 $date = dformat($recent['date']);
701 if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
702 $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
703 else
704 $form->addElement(form_makeOpenTag('li'));
706 $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
708 if ($recent['media']) {
709 $form->addElement(media_printicon($recent['id']));
710 } else {
711 $icon = DOKU_BASE.'lib/images/fileicons/file.png';
712 $form->addElement('<img src="'.$icon.'" alt="'.$recent['id'].'" class="icon" />');
715 $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
716 $form->addElement($date);
717 $form->addElement(form_makeCloseTag('span'));
719 $diff = false;
720 $href = '';
722 if ($recent['media']) {
723 $diff = (count(getRevisions($recent['id'], 0, 1, 8192, true)) && @file_exists(mediaFN($recent['id'])));
724 if ($diff) {
725 $href = media_managerURL(array('tab_details' => 'history',
726 'mediado' => 'diff', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&');
728 } else {
729 $href = wl($recent['id'],"do=diff", false, '&');
732 if ($recent['media'] && !$diff) {
733 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
734 } else {
735 $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => $href)));
736 $form->addElement(form_makeTag('img', array(
737 'src' => DOKU_BASE.'lib/images/diff.png',
738 'width' => 15,
739 'height'=> 11,
740 'title' => $lang['diff'],
741 'alt' => $lang['diff']
742 )));
743 $form->addElement(form_makeCloseTag('a'));
746 if ($recent['media']) {
747 $href = media_managerURL(array('tab_details' => 'history',
748 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&');
749 } else {
750 $href = wl($recent['id'],"do=revisions",false,'&');
752 $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => $href)));
753 $form->addElement(form_makeTag('img', array(
754 'src' => DOKU_BASE.'lib/images/history.png',
755 'width' => 12,
756 'height'=> 14,
757 'title' => $lang['btn_revs'],
758 'alt' => $lang['btn_revs']
759 )));
760 $form->addElement(form_makeCloseTag('a'));
762 if ($recent['media']) {
763 $href = media_managerURL(array('tab_details' => 'view', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&');
764 $class = (file_exists(mediaFN($recent['id']))) ? 'wikilink1' : $class = 'wikilink2';
765 $form->addElement(form_makeOpenTag('a', array('class' => $class, 'href' => $href)));
766 $form->addElement($recent['id']);
767 $form->addElement(form_makeCloseTag('a'));
768 } else {
769 $form->addElement(html_wikilink(':'.$recent['id'],useHeading('navigation')?null:$recent['id']));
771 $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
772 $form->addElement(' – '.htmlspecialchars($recent['sum']));
773 $form->addElement(form_makeCloseTag('span'));
775 $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
776 if($recent['user']){
777 $form->addElement(editorinfo($recent['user']));
778 if(auth_ismanager()){
779 $form->addElement(' ('.$recent['ip'].')');
781 }else{
782 $form->addElement($recent['ip']);
784 $form->addElement(form_makeCloseTag('span'));
786 $form->addElement(form_makeCloseTag('div'));
787 $form->addElement(form_makeCloseTag('li'));
789 $form->addElement(form_makeCloseTag('ul'));
791 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
792 $last = $first + $conf['recent'];
793 if ($first > 0) {
794 $first -= $conf['recent'];
795 if ($first < 0) $first = 0;
796 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
797 $form->addElement(form_makeTag('input', array(
798 'type' => 'submit',
799 'name' => 'first['.$first.']',
800 'value' => $lang['btn_newer'],
801 'accesskey' => 'n',
802 'title' => $lang['btn_newer'].' [N]',
803 'class' => 'button show'
804 )));
805 $form->addElement(form_makeCloseTag('div'));
807 if ($hasNext) {
808 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
809 $form->addElement(form_makeTag('input', array(
810 'type' => 'submit',
811 'name' => 'first['.$last.']',
812 'value' => $lang['btn_older'],
813 'accesskey' => 'p',
814 'title' => $lang['btn_older'].' [P]',
815 'class' => 'button show'
816 )));
817 $form->addElement(form_makeCloseTag('div'));
819 $form->addElement(form_makeCloseTag('div'));
820 html_form('recent', $form);
824 * Display page index
826 * @author Andreas Gohr <andi@splitbrain.org>
828 function html_index($ns){
829 global $conf;
830 global $ID;
831 $ns = cleanID($ns);
832 #fixme use appropriate function
833 if(empty($ns)){
834 $ns = dirname(str_replace(':','/',$ID));
835 if($ns == '.') $ns ='';
837 $ns = utf8_encodeFN(str_replace(':','/',$ns));
839 echo p_locale_xhtml('index');
840 echo '<div id="index__tree">';
842 $data = array();
843 search($data,$conf['datadir'],'search_index',array('ns' => $ns));
844 echo html_buildlist($data,'idx','html_list_index','html_li_index');
846 echo '</div>';
850 * Index item formatter
852 * User function for html_buildlist()
854 * @author Andreas Gohr <andi@splitbrain.org>
856 function html_list_index($item){
857 global $ID;
858 $ret = '';
859 $base = ':'.$item['id'];
860 $base = substr($base,strrpos($base,':')+1);
861 if($item['type']=='d'){
862 $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" class="idx_dir"><strong>';
863 $ret .= $base;
864 $ret .= '</strong></a>';
865 }else{
866 // default is noNSorNS($id), but we want noNS($id) when useheading is off FS#2605
867 $ret .= html_wikilink(':'.$item['id'], useHeading('navigation') ? null : noNS($item['id']));
869 return $ret;
873 * Index List item
875 * This user function is used in html_buildlist to build the
876 * <li> tags for namespaces when displaying the page index
877 * it gives different classes to opened or closed "folders"
879 * @author Andreas Gohr <andi@splitbrain.org>
881 function html_li_index($item){
882 if($item['type'] == "f"){
883 return '<li class="level'.$item['level'].'">';
884 }elseif($item['open']){
885 return '<li class="open">';
886 }else{
887 return '<li class="closed">';
892 * Default List item
894 * @author Andreas Gohr <andi@splitbrain.org>
896 function html_li_default($item){
897 return '<li class="level'.$item['level'].'">';
901 * Build an unordered list
903 * Build an unordered list from the given $data array
904 * Each item in the array has to have a 'level' property
905 * the item itself gets printed by the given $func user
906 * function. The second and optional function is used to
907 * print the <li> tag. Both user function need to accept
908 * a single item.
910 * Both user functions can be given as array to point to
911 * a member of an object.
913 * @author Andreas Gohr <andi@splitbrain.org>
915 function html_buildlist($data,$class,$func,$lifunc='html_li_default',$forcewrapper=false){
916 if (count($data) === 0) {
917 return '';
920 $start_level = $data[0]['level'];
921 $level = $start_level;
922 $ret = '';
923 $open = 0;
925 foreach ($data as $item){
927 if( $item['level'] > $level ){
928 //open new list
929 for($i=0; $i<($item['level'] - $level); $i++){
930 if ($i) $ret .= "<li class=\"clear\">";
931 $ret .= "\n<ul class=\"$class\">\n";
932 $open++;
934 $level = $item['level'];
936 }elseif( $item['level'] < $level ){
937 //close last item
938 $ret .= "</li>\n";
939 while( $level > $item['level'] && $open > 0 ){
940 //close higher lists
941 $ret .= "</ul>\n</li>\n";
942 $level--;
943 $open--;
945 } elseif ($ret !== '') {
946 //close previous item
947 $ret .= "</li>\n";
950 //print item
951 $ret .= call_user_func($lifunc,$item);
952 $ret .= '<div class="li">';
954 $ret .= call_user_func($func,$item);
955 $ret .= '</div>';
958 //close remaining items and lists
959 $ret .= "</li>\n";
960 while($open-- > 0) {
961 $ret .= "</ul></li>\n";
964 if ($forcewrapper || $start_level < 2) {
965 // Trigger building a wrapper ul if the first level is
966 // 0 (we have a root object) or 1 (just the root content)
967 $ret = "\n<ul class=\"$class\">\n".$ret."</ul>\n";
970 return $ret;
974 * display backlinks
976 * @author Andreas Gohr <andi@splitbrain.org>
977 * @author Michael Klier <chi@chimeric.de>
979 function html_backlinks(){
980 global $ID;
981 global $lang;
983 print p_locale_xhtml('backlinks');
985 $data = ft_backlinks($ID);
987 if(!empty($data)) {
988 print '<ul class="idx">';
989 foreach($data as $blink){
990 print '<li><div class="li">';
991 print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink);
992 print '</div></li>';
994 print '</ul>';
995 } else {
996 print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
1001 * Get header of diff HTML
1002 * @param string $l_rev Left revisions
1003 * @param string $r_rev Right revision
1004 * @param string $id Page id, if null $ID is used
1005 * @param bool $media If it is for media files
1006 * @return array HTML snippets for diff header
1008 function html_diff_head($l_rev, $r_rev, $id = null, $media = false) {
1009 global $lang;
1010 if ($id === null) {
1011 global $ID;
1012 $id = $ID;
1014 $media_or_wikiFN = $media ? 'mediaFN' : 'wikiFN';
1015 $ml_or_wl = $media ? 'ml' : 'wl';
1016 $l_minor = $r_minor = '';
1018 if(!$l_rev){
1019 $l_head = '&mdash;';
1020 }else{
1021 $l_info = getRevisionInfo($id,$l_rev,true, $media);
1022 if($l_info['user']){
1023 $l_user = editorinfo($l_info['user']);
1024 if(auth_ismanager()) $l_user .= ' ('.$l_info['ip'].')';
1025 } else {
1026 $l_user = $l_info['ip'];
1028 $l_user = '<span class="user">'.$l_user.'</span>';
1029 $l_sum = ($l_info['sum']) ? '<span class="sum">'.hsc($l_info['sum']).'</span>' : '';
1030 if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
1032 $l_head_title = ($media) ? dformat($l_rev) : $id.' ['.dformat($l_rev).']';
1033 $l_head = '<a class="wikilink1" href="'.$ml_or_wl($id,"rev=$l_rev").'">'.
1034 $l_head_title.'</a>'.
1035 '<br />'.$l_user.' '.$l_sum;
1038 if($r_rev){
1039 $r_info = getRevisionInfo($id,$r_rev,true, $media);
1040 if($r_info['user']){
1041 $r_user = editorinfo($r_info['user']);
1042 if(auth_ismanager()) $r_user .= ' ('.$r_info['ip'].')';
1043 } else {
1044 $r_user = $r_info['ip'];
1046 $r_user = '<span class="user">'.$r_user.'</span>';
1047 $r_sum = ($r_info['sum']) ? '<span class="sum">'.hsc($r_info['sum']).'</span>' : '';
1048 if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
1050 $r_head_title = ($media) ? dformat($r_rev) : $id.' ['.dformat($r_rev).']';
1051 $r_head = '<a class="wikilink1" href="'.$ml_or_wl($id,"rev=$r_rev").'">'.
1052 $r_head_title.'</a>'.
1053 '<br />'.$r_user.' '.$r_sum;
1054 }elseif($_rev = @filemtime($media_or_wikiFN($id))){
1055 $_info = getRevisionInfo($id,$_rev,true, $media);
1056 if($_info['user']){
1057 $_user = editorinfo($_info['user']);
1058 if(auth_ismanager()) $_user .= ' ('.$_info['ip'].')';
1059 } else {
1060 $_user = $_info['ip'];
1062 $_user = '<span class="user">'.$_user.'</span>';
1063 $_sum = ($_info['sum']) ? '<span class="sum">'.hsc($_info['sum']).'</span>' : '';
1064 if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
1066 $r_head_title = ($media) ? dformat($_rev) : $id.' ['.dformat($_rev).']';
1067 $r_head = '<a class="wikilink1" href="'.$ml_or_wl($id).'">'.
1068 $r_head_title.'</a> '.
1069 '('.$lang['current'].')'.
1070 '<br />'.$_user.' '.$_sum;
1071 }else{
1072 $r_head = '&mdash; ('.$lang['current'].')';
1075 return array($l_head, $r_head, $l_minor, $r_minor);
1079 * show diff
1081 * @author Andreas Gohr <andi@splitbrain.org>
1082 * @param string $text - compare with this text with most current version
1083 * @param bool $intro - display the intro text
1084 * @param string $type type of the diff (inline or sidebyside)
1086 function html_diff($text='',$intro=true,$type=null){
1087 global $ID;
1088 global $REV;
1089 global $lang;
1090 global $INPUT;
1092 if(!$type) $type = $INPUT->str('difftype');
1093 if($type != 'inline') $type = 'sidebyside';
1095 // we're trying to be clever here, revisions to compare can be either
1096 // given as rev and rev2 parameters, with rev2 being optional. Or in an
1097 // array in rev2.
1098 $rev1 = $REV;
1100 $rev2 = $INPUT->ref('rev2');
1101 if(is_array($rev2)){
1102 $rev1 = (int) $rev2[0];
1103 $rev2 = (int) $rev2[1];
1105 if(!$rev1){
1106 $rev1 = $rev2;
1107 unset($rev2);
1109 }else{
1110 $rev2 = $INPUT->int('rev2');
1113 $r_minor = '';
1114 $l_minor = '';
1116 if($text){ // compare text to the most current revision
1117 $l_rev = '';
1118 $l_text = rawWiki($ID,'');
1119 $l_head = '<a class="wikilink1" href="'.wl($ID).'">'.
1120 $ID.' '.dformat((int) @filemtime(wikiFN($ID))).'</a> '.
1121 $lang['current'];
1123 $r_rev = '';
1124 $r_text = cleanText($text);
1125 $r_head = $lang['yours'];
1126 }else{
1127 if($rev1 && isset($rev2) && $rev2){ // two specific revisions wanted
1128 // make sure order is correct (older on the left)
1129 if($rev1 < $rev2){
1130 $l_rev = $rev1;
1131 $r_rev = $rev2;
1132 }else{
1133 $l_rev = $rev2;
1134 $r_rev = $rev1;
1136 }elseif($rev1){ // single revision given, compare to current
1137 $r_rev = '';
1138 $l_rev = $rev1;
1139 }else{ // no revision was given, compare previous to current
1140 $r_rev = '';
1141 $revs = getRevisions($ID, 0, 1);
1142 $l_rev = $revs[0];
1143 $REV = $l_rev; // store revision back in $REV
1146 // when both revisions are empty then the page was created just now
1147 if(!$l_rev && !$r_rev){
1148 $l_text = '';
1149 }else{
1150 $l_text = rawWiki($ID,$l_rev);
1152 $r_text = rawWiki($ID,$r_rev);
1154 //look for previous/next revision
1155 if($r_rev) {
1156 $next_rev = getRelativeRevision($ID, $r_rev, 1);
1157 } else {
1158 $next_rev = false;
1160 if($l_rev) {
1161 $prev_rev = getRelativeRevision($ID, $l_rev, -1);
1162 } else {
1163 $prev_rev = false;
1166 list($l_head, $r_head, $l_minor, $r_minor) = html_diff_head($l_rev, $r_rev);
1169 $df = new Diff(explode("\n",htmlspecialchars($l_text)),
1170 explode("\n",htmlspecialchars($r_text)));
1172 if($type == 'inline'){
1173 $tdf = new InlineDiffFormatter();
1174 } else {
1175 $tdf = new TableDiffFormatter();
1178 if($intro) print p_locale_xhtml('diff');
1180 if (!$text) {
1181 ptln('<div class="diffoptions">');
1183 $form = new Doku_Form(array('action'=>wl()));
1184 $form->addHidden('id',$ID);
1185 $form->addHidden('rev2[0]',$l_rev);
1186 $form->addHidden('rev2[1]',$r_rev);
1187 $form->addHidden('do','diff');
1188 $form->addElement(form_makeListboxField(
1189 'difftype',
1190 array(
1191 'sidebyside' => $lang['diff_side'],
1192 'inline' => $lang['diff_inline']),
1193 $type,
1194 $lang['diff_type'],
1195 '','',
1196 array('class'=>'quickselect')));
1197 $form->addElement(form_makeButton('submit', 'diff','Go'));
1198 $form->printForm();
1200 $diffurl = wl($ID, array(
1201 'do' => 'diff',
1202 'rev2[0]' => $l_rev,
1203 'rev2[1]' => $r_rev,
1204 'difftype' => $type,
1206 ptln('<p><a class="wikilink1" href="'.$diffurl.'">'.$lang['difflink'].'</a><br />');
1207 if($prev_rev){
1208 $diffurlprev = wl($ID, array(
1209 'do' => 'diff',
1210 'rev2[0]' => $prev_rev,
1211 'rev2[1]' => $l_rev,
1212 'difftype' => $type,
1214 ptln('<a class="wikilink1" href="'.$diffurlprev.'">← '.$lang['diffpreviousedit'].'</a> - ');
1216 $recenturl = wl($ID, array(
1217 'do' => 'revisions'
1219 ptln('<a class="wikilink1" href="'.$recenturl.'">'.$lang['overviewrevs'].'</a>');
1220 if($next_rev){
1221 if($next_rev=='current') {
1222 $diffurlnextparam = array(
1223 'do' => 'diff',
1224 'rev' => $r_rev,
1225 'difftype' => $type,
1227 $navnexttitle = $lang['difflastedit'];
1228 } else {
1229 $diffurlnextparam = array(
1230 'do' => 'diff',
1231 'rev2[0]' => $r_rev,
1232 'rev2[1]' => $next_rev,
1233 'difftype' => $type,
1235 $navnexttitle = $lang['diffnextedit'];
1237 ptln(' - <a class="wikilink1" href="'.wl($ID, $diffurlnextparam).'">'.$navnexttitle.' →</a>');
1239 ptln('</p>');
1240 ptln('</div>');
1243 <div class="table">
1244 <table class="diff diff_<?php echo $type?>">
1245 <tr>
1246 <th colspan="2" <?php echo $l_minor?>>
1247 <?php echo $l_head?>
1248 </th>
1249 <th colspan="2" <?php echo $r_minor?>>
1250 <?php echo $r_head?>
1251 </th>
1252 </tr>
1253 <?php echo $tdf->format($df)?>
1254 </table>
1255 </div>
1256 <?php
1260 * show warning on conflict detection
1262 * @author Andreas Gohr <andi@splitbrain.org>
1264 function html_conflict($text,$summary){
1265 global $ID;
1266 global $lang;
1268 print p_locale_xhtml('conflict');
1269 $form = new Doku_Form(array('id' => 'dw__editform'));
1270 $form->addHidden('id', $ID);
1271 $form->addHidden('wikitext', $text);
1272 $form->addHidden('summary', $summary);
1273 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
1274 $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
1275 html_form('conflict', $form);
1276 print '<br /><br /><br /><br />'.NL;
1280 * Prints the global message array
1282 * @author Andreas Gohr <andi@splitbrain.org>
1284 function html_msgarea(){
1285 global $MSG, $MSG_shown;
1286 /** @var array $MSG */
1287 // store if the global $MSG has already been shown and thus HTML output has been started
1288 $MSG_shown = true;
1290 if(!isset($MSG)) return;
1292 $shown = array();
1293 foreach($MSG as $msg){
1294 $hash = md5($msg['msg']);
1295 if(isset($shown[$hash])) continue; // skip double messages
1296 print '<div class="'.$msg['lvl'].'">';
1297 print $msg['msg'];
1298 print '</div>';
1299 $shown[$hash] = 1;
1302 unset($GLOBALS['MSG']);
1306 * Prints the registration form
1308 * @author Andreas Gohr <andi@splitbrain.org>
1310 function html_register(){
1311 global $lang;
1312 global $conf;
1313 global $INPUT;
1315 print p_locale_xhtml('register');
1316 print '<div class="centeralign">'.NL;
1317 $form = new Doku_Form(array('id' => 'dw__register'));
1318 $form->startFieldset($lang['btn_register']);
1319 $form->addHidden('do', 'register');
1320 $form->addHidden('save', '1');
1321 $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block', array('size'=>'50')));
1322 if (!$conf['autopasswd']) {
1323 $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
1324 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1326 $form->addElement(form_makeTextField('fullname', $INPUT->post->str('fullname'), $lang['fullname'], '', 'block', array('size'=>'50')));
1327 $form->addElement(form_makeTextField('email', $INPUT->post->str('email'), $lang['email'], '', 'block', array('size'=>'50')));
1328 $form->addElement(form_makeButton('submit', '', $lang['btn_register']));
1329 $form->endFieldset();
1330 html_form('register', $form);
1332 print '</div>'.NL;
1336 * Print the update profile form
1338 * @author Christopher Smith <chris@jalakai.co.uk>
1339 * @author Andreas Gohr <andi@splitbrain.org>
1341 function html_updateprofile(){
1342 global $lang;
1343 global $conf;
1344 global $INPUT;
1345 global $INFO;
1346 /** @var auth_basic $auth */
1347 global $auth;
1349 print p_locale_xhtml('updateprofile');
1351 $fullname = $INPUT->post->str('fullname', $INFO['userinfo']['name'], true);
1352 $email = $INPUT->post->str('email', $INFO['userinfo']['mail'], true);
1353 print '<div class="centeralign">'.NL;
1354 $form = new Doku_Form(array('id' => 'dw__register'));
1355 $form->startFieldset($lang['profile']);
1356 $form->addHidden('do', 'profile');
1357 $form->addHidden('save', '1');
1358 $form->addElement(form_makeTextField('login', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
1359 $attr = array('size'=>'50');
1360 if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1361 $form->addElement(form_makeTextField('fullname', $fullname, $lang['fullname'], '', 'block', $attr));
1362 $attr = array('size'=>'50');
1363 if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
1364 $form->addElement(form_makeTextField('email', $email, $lang['email'], '', 'block', $attr));
1365 $form->addElement(form_makeTag('br'));
1366 if ($auth->canDo('modPass')) {
1367 $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1368 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1370 if ($conf['profileconfirm']) {
1371 $form->addElement(form_makeTag('br'));
1372 $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50')));
1374 $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1375 $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
1376 $form->endFieldset();
1377 html_form('updateprofile', $form);
1378 print '</div>'.NL;
1382 * Preprocess edit form data
1384 * @author Andreas Gohr <andi@splitbrain.org>
1386 * @triggers HTML_EDITFORM_OUTPUT
1388 function html_edit(){
1389 global $INPUT;
1390 global $ID;
1391 global $REV;
1392 global $DATE;
1393 global $PRE;
1394 global $SUF;
1395 global $INFO;
1396 global $SUM;
1397 global $lang;
1398 global $conf;
1399 global $TEXT;
1400 global $RANGE;
1402 if ($INPUT->has('changecheck')) {
1403 $check = $INPUT->str('changecheck');
1404 } elseif(!$INFO['exists']){
1405 // $TEXT has been loaded from page template
1406 $check = md5('');
1407 } else {
1408 $check = md5($TEXT);
1410 $mod = md5($TEXT) !== $check;
1412 $wr = $INFO['writable'] && !$INFO['locked'];
1413 $include = 'edit';
1414 if($wr){
1415 if ($REV) $include = 'editrev';
1416 }else{
1417 // check pseudo action 'source'
1418 if(!actionOK('source')){
1419 msg('Command disabled: source',-1);
1420 return;
1422 $include = 'read';
1425 global $license;
1427 $form = new Doku_Form(array('id' => 'dw__editform'));
1428 $form->addHidden('id', $ID);
1429 $form->addHidden('rev', $REV);
1430 $form->addHidden('date', $DATE);
1431 $form->addHidden('prefix', $PRE . '.');
1432 $form->addHidden('suffix', $SUF);
1433 $form->addHidden('changecheck', $check);
1435 $data = array('form' => $form,
1436 'wr' => $wr,
1437 'media_manager' => true,
1438 'target' => ($INPUT->has('target') && $wr) ? $INPUT->str('target') : 'section',
1439 'intro_locale' => $include);
1441 if ($data['target'] !== 'section') {
1442 // Only emit event if page is writable, section edit data is valid and
1443 // edit target is not section.
1444 trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true);
1445 } else {
1446 html_edit_form($data);
1448 if (isset($data['intro_locale'])) {
1449 echo p_locale_xhtml($data['intro_locale']);
1452 $form->addHidden('target', $data['target']);
1453 $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar', 'class'=>'editBar')));
1454 $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1455 $form->addElement(form_makeCloseTag('div'));
1456 if ($wr) {
1457 $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
1458 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
1459 $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
1460 $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
1461 $form->addElement(form_makeCloseTag('div'));
1462 $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
1463 $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
1464 $elem = html_minoredit();
1465 if ($elem) $form->addElement($elem);
1466 $form->addElement(form_makeCloseTag('div'));
1468 $form->addElement(form_makeCloseTag('div'));
1469 if($wr && $conf['license']){
1470 $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1471 $out = $lang['licenseok'];
1472 $out .= ' <a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
1473 if($conf['target']['extern']) $out .= ' target="'.$conf['target']['extern'].'"';
1474 $out .= '>'.$license[$conf['license']]['name'].'</a>';
1475 $form->addElement($out);
1476 $form->addElement(form_makeCloseTag('div'));
1479 if ($wr) {
1480 // sets changed to true when previewed
1481 echo '<script type="text/javascript">/*<![CDATA[*/'. NL;
1482 echo 'textChanged = ' . ($mod ? 'true' : 'false');
1483 echo '/*!]]>*/</script>' . NL;
1484 } ?>
1485 <div class="editBox">
1487 <div class="toolbar">
1488 <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div>
1489 <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']?>"
1490 target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
1491 </div>
1492 <?php
1494 html_form('edit', $form);
1495 print '</div>'.NL;
1499 * Display the default edit form
1501 * Is the default action for HTML_EDIT_FORMSELECTION.
1503 function html_edit_form($param) {
1504 global $TEXT;
1506 if ($param['target'] !== 'section') {
1507 msg('No editor for edit target ' . hsc($param['target']) . ' found.', -1);
1510 $attr = array('tabindex'=>'1');
1511 if (!$param['wr']) $attr['readonly'] = 'readonly';
1513 $param['form']->addElement(form_makeWikiText($TEXT, $attr));
1517 * Adds a checkbox for minor edits for logged in users
1519 * @author Andreas Gohr <andi@splitbrain.org>
1521 function html_minoredit(){
1522 global $conf;
1523 global $lang;
1524 global $INPUT;
1525 // minor edits are for logged in users only
1526 if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1527 return false;
1530 $p = array();
1531 $p['tabindex'] = 3;
1532 if($INPUT->bool('minor')) $p['checked']='checked';
1533 return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
1537 * prints some debug info
1539 * @author Andreas Gohr <andi@splitbrain.org>
1541 function html_debug(){
1542 global $conf;
1543 global $lang;
1544 /** @var auth_basic $auth */
1545 global $auth;
1546 global $INFO;
1548 //remove sensitive data
1549 $cnf = $conf;
1550 debug_guard($cnf);
1551 $nfo = $INFO;
1552 debug_guard($nfo);
1553 $ses = $_SESSION;
1554 debug_guard($ses);
1556 print '<html><body>';
1558 print '<p>When reporting bugs please send all the following ';
1559 print 'output as a mail to andi@splitbrain.org ';
1560 print 'The best way to do this is to save this page in your browser</p>';
1562 print '<b>$INFO:</b><pre>';
1563 print_r($nfo);
1564 print '</pre>';
1566 print '<b>$_SERVER:</b><pre>';
1567 print_r($_SERVER);
1568 print '</pre>';
1570 print '<b>$conf:</b><pre>';
1571 print_r($cnf);
1572 print '</pre>';
1574 print '<b>DOKU_BASE:</b><pre>';
1575 print DOKU_BASE;
1576 print '</pre>';
1578 print '<b>abs DOKU_BASE:</b><pre>';
1579 print DOKU_URL;
1580 print '</pre>';
1582 print '<b>rel DOKU_BASE:</b><pre>';
1583 print dirname($_SERVER['PHP_SELF']).'/';
1584 print '</pre>';
1586 print '<b>PHP Version:</b><pre>';
1587 print phpversion();
1588 print '</pre>';
1590 print '<b>locale:</b><pre>';
1591 print setlocale(LC_ALL,0);
1592 print '</pre>';
1594 print '<b>encoding:</b><pre>';
1595 print $lang['encoding'];
1596 print '</pre>';
1598 if($auth){
1599 print '<b>Auth backend capabilities:</b><pre>';
1600 print_r($auth->cando);
1601 print '</pre>';
1604 print '<b>$_SESSION:</b><pre>';
1605 print_r($ses);
1606 print '</pre>';
1608 print '<b>Environment:</b><pre>';
1609 print_r($_ENV);
1610 print '</pre>';
1612 print '<b>PHP settings:</b><pre>';
1613 $inis = ini_get_all();
1614 print_r($inis);
1615 print '</pre>';
1617 print '</body></html>';
1621 * List available Administration Tasks
1623 * @author Andreas Gohr <andi@splitbrain.org>
1624 * @author Håkan Sandell <hakan.sandell@home.se>
1626 function html_admin(){
1627 global $ID;
1628 global $INFO;
1629 global $conf;
1630 /** @var auth_basic $auth */
1631 global $auth;
1633 // build menu of admin functions from the plugins that handle them
1634 $pluginlist = plugin_list('admin');
1635 $menu = array();
1636 foreach ($pluginlist as $p) {
1637 /** @var DokuWiki_Admin_Plugin $obj */
1638 if($obj =& plugin_load('admin',$p) === null) continue;
1640 // check permissions
1641 if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
1643 $menu[$p] = array('plugin' => $p,
1644 'prompt' => $obj->getMenuText($conf['lang']),
1645 'sort' => $obj->getMenuSort()
1649 // data security check
1650 // @todo: could be checked and only displayed if $conf['savedir'] is under the web root
1651 echo '<a style="border:none; float:right;"
1652 href="http://www.dokuwiki.org/security#web_access_security">
1653 <img src="data/security.png" alt="Your data directory seems to be protected properly."
1654 onerror="this.parentNode.style.display=\'none\'" /></a>';
1656 print p_locale_xhtml('admin');
1658 // Admin Tasks
1659 if($INFO['isadmin']){
1660 ptln('<ul class="admin_tasks">');
1662 if($menu['usermanager'] && $auth && $auth->canDo('getUsers')){
1663 ptln(' <li class="admin_usermanager"><div class="li">'.
1664 '<a href="'.wl($ID, array('do' => 'admin','page' => 'usermanager')).'">'.
1665 $menu['usermanager']['prompt'].'</a></div></li>');
1667 unset($menu['usermanager']);
1669 if($menu['acl']){
1670 ptln(' <li class="admin_acl"><div class="li">'.
1671 '<a href="'.wl($ID, array('do' => 'admin','page' => 'acl')).'">'.
1672 $menu['acl']['prompt'].'</a></div></li>');
1674 unset($menu['acl']);
1676 if($menu['plugin']){
1677 ptln(' <li class="admin_plugin"><div class="li">'.
1678 '<a href="'.wl($ID, array('do' => 'admin','page' => 'plugin')).'">'.
1679 $menu['plugin']['prompt'].'</a></div></li>');
1681 unset($menu['plugin']);
1683 if($menu['config']){
1684 ptln(' <li class="admin_config"><div class="li">'.
1685 '<a href="'.wl($ID, array('do' => 'admin','page' => 'config')).'">'.
1686 $menu['config']['prompt'].'</a></div></li>');
1688 unset($menu['config']);
1690 ptln('</ul>');
1692 // Manager Tasks
1693 ptln('<ul class="admin_tasks">');
1695 if($menu['revert']){
1696 ptln(' <li class="admin_revert"><div class="li">'.
1697 '<a href="'.wl($ID, array('do' => 'admin','page' => 'revert')).'">'.
1698 $menu['revert']['prompt'].'</a></div></li>');
1700 unset($menu['revert']);
1702 if($menu['popularity']){
1703 ptln(' <li class="admin_popularity"><div class="li">'.
1704 '<a href="'.wl($ID, array('do' => 'admin','page' => 'popularity')).'">'.
1705 $menu['popularity']['prompt'].'</a></div></li>');
1707 unset($menu['popularity']);
1709 // print DokuWiki version:
1710 ptln('</ul>');
1711 echo '<div id="admin__version">';
1712 echo getVersion();
1713 echo '</div>';
1715 // print the rest as sorted list
1716 if(count($menu)){
1717 usort($menu, 'p_sort_modes');
1718 // output the menu
1719 ptln('<div class="clearer"></div>');
1720 print p_locale_xhtml('adminplugins');
1721 ptln('<ul>');
1722 foreach ($menu as $item) {
1723 if (!$item['prompt']) continue;
1724 ptln(' <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
1726 ptln('</ul>');
1731 * Form to request a new password for an existing account
1733 * @author Benoit Chesneau <benoit@bchesneau.info>
1734 * @author Andreas Gohr <gohr@cosmocode.de>
1736 function html_resendpwd() {
1737 global $lang;
1738 global $conf;
1739 global $INPUT;
1741 $token = preg_replace('/[^a-f0-9]+/','',$INPUT->str('pwauth'));
1743 if(!$conf['autopasswd'] && $token){
1744 print p_locale_xhtml('resetpwd');
1745 print '<div class="centeralign">'.NL;
1746 $form = new Doku_Form(array('id' => 'dw__resendpwd'));
1747 $form->startFieldset($lang['btn_resendpwd']);
1748 $form->addHidden('token', $token);
1749 $form->addHidden('do', 'resendpwd');
1751 $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
1752 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1754 $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
1755 $form->endFieldset();
1756 html_form('resendpwd', $form);
1757 print '</div>'.NL;
1758 }else{
1759 print p_locale_xhtml('resendpwd');
1760 print '<div class="centeralign">'.NL;
1761 $form = new Doku_Form(array('id' => 'dw__resendpwd'));
1762 $form->startFieldset($lang['resendpwd']);
1763 $form->addHidden('do', 'resendpwd');
1764 $form->addHidden('save', '1');
1765 $form->addElement(form_makeTag('br'));
1766 $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block'));
1767 $form->addElement(form_makeTag('br'));
1768 $form->addElement(form_makeTag('br'));
1769 $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
1770 $form->endFieldset();
1771 html_form('resendpwd', $form);
1772 print '</div>'.NL;
1777 * Return the TOC rendered to XHTML
1779 * @author Andreas Gohr <andi@splitbrain.org>
1781 function html_TOC($toc){
1782 if(!count($toc)) return '';
1783 global $lang;
1784 $out = '<!-- TOC START -->'.DOKU_LF;
1785 $out .= '<div id="dw__toc">'.DOKU_LF;
1786 $out .= '<h3 class="toggle">';
1787 $out .= $lang['toc'];
1788 $out .= '</h3>'.DOKU_LF;
1789 $out .= '<div>'.DOKU_LF;
1790 $out .= html_buildlist($toc,'toc','html_list_toc','html_li_default',true);
1791 $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
1792 $out .= '<!-- TOC END -->'.DOKU_LF;
1793 return $out;
1797 * Callback for html_buildlist
1799 function html_list_toc($item){
1800 if(isset($item['hid'])){
1801 $link = '#'.$item['hid'];
1802 }else{
1803 $link = $item['link'];
1806 return '<a href="'.$link.'">'.hsc($item['title']).'</a>';
1810 * Helper function to build TOC items
1812 * Returns an array ready to be added to a TOC array
1814 * @param string $link - where to link (if $hash set to '#' it's a local anchor)
1815 * @param string $text - what to display in the TOC
1816 * @param int $level - nesting level
1817 * @param string $hash - is prepended to the given $link, set blank if you want full links
1818 * @return array the toc item
1820 function html_mktocitem($link, $text, $level, $hash='#'){
1821 return array( 'link' => $hash.$link,
1822 'title' => $text,
1823 'type' => 'ul',
1824 'level' => $level);
1828 * Output a Doku_Form object.
1829 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
1831 * @author Tom N Harris <tnharris@whoopdedo.org>
1832 * @param string $name The name of the form
1833 * @param Doku_Form $form The form
1835 function html_form($name, &$form) {
1836 // Safety check in case the caller forgets.
1837 $form->endFieldset();
1838 trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
1842 * Form print function.
1843 * Just calls printForm() on the data object.
1844 * @param Doku_Form $data The form
1846 function html_form_output($data) {
1847 $data->printForm();
1851 * Embed a flash object in HTML
1853 * This will create the needed HTML to embed a flash movie in a cross browser
1854 * compatble way using valid XHTML
1856 * The parameters $params, $flashvars and $atts need to be associative arrays.
1857 * No escaping needs to be done for them. The alternative content *has* to be
1858 * escaped because it is used as is. If no alternative content is given
1859 * $lang['noflash'] is used.
1861 * @author Andreas Gohr <andi@splitbrain.org>
1862 * @link http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
1864 * @param string $swf - the SWF movie to embed
1865 * @param int $width - width of the flash movie in pixels
1866 * @param int $height - height of the flash movie in pixels
1867 * @param array $params - additional parameters (<param>)
1868 * @param array $flashvars - parameters to be passed in the flashvar parameter
1869 * @param array $atts - additional attributes for the <object> tag
1870 * @param string $alt - alternative content (is NOT automatically escaped!)
1871 * @return string - the XHTML markup
1873 function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
1874 global $lang;
1876 $out = '';
1878 // prepare the object attributes
1879 if(is_null($atts)) $atts = array();
1880 $atts['width'] = (int) $width;
1881 $atts['height'] = (int) $height;
1882 if(!$atts['width']) $atts['width'] = 425;
1883 if(!$atts['height']) $atts['height'] = 350;
1885 // add object attributes for standard compliant browsers
1886 $std = $atts;
1887 $std['type'] = 'application/x-shockwave-flash';
1888 $std['data'] = $swf;
1890 // add object attributes for IE
1891 $ie = $atts;
1892 $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
1894 // open object (with conditional comments)
1895 $out .= '<!--[if !IE]> -->'.NL;
1896 $out .= '<object '.buildAttributes($std).'>'.NL;
1897 $out .= '<!-- <![endif]-->'.NL;
1898 $out .= '<!--[if IE]>'.NL;
1899 $out .= '<object '.buildAttributes($ie).'>'.NL;
1900 $out .= ' <param name="movie" value="'.hsc($swf).'" />'.NL;
1901 $out .= '<!--><!-- -->'.NL;
1903 // print params
1904 if(is_array($params)) foreach($params as $key => $val){
1905 $out .= ' <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
1908 // add flashvars
1909 if(is_array($flashvars)){
1910 $out .= ' <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
1913 // alternative content
1914 if($alt){
1915 $out .= $alt.NL;
1916 }else{
1917 $out .= $lang['noflash'].NL;
1920 // finish
1921 $out .= '</object>'.NL;
1922 $out .= '<!-- <![endif]-->'.NL;
1924 return $out;
1928 * Prints HTML code for the given tab structure
1930 * @param array $tabs tab structure
1931 * @param string $current_tab the current tab id
1933 function html_tabs($tabs, $current_tab = null) {
1934 echo '<ul class="tabs">'.NL;
1936 foreach($tabs as $id => $tab) {
1937 html_tab($tab['href'], $tab['caption'], $id === $current_tab);
1940 echo '</ul>'.NL;
1943 * Prints a single tab
1945 * @author Kate Arzamastseva <pshns@ukr.net>
1946 * @author Adrian Lang <mail@adrianlang.de>
1948 * @param string $href - tab href
1949 * @param string $caption - tab caption
1950 * @param boolean $selected - is tab selected
1953 function html_tab($href, $caption, $selected=false) {
1954 $tab = '<li>';
1955 if ($selected) {
1956 $tab .= '<strong>';
1957 } else {
1958 $tab .= '<a href="' . hsc($href) . '">';
1960 $tab .= hsc($caption)
1961 . '</' . ($selected ? 'strong' : 'a') . '>'
1962 . '</li>'.NL;
1963 echo $tab;