xref: /dokuwiki/inc/html.php (revision 306ca8aa54954ea2623d9e4927a2c07b9efdfea3)
1<?php
2/**
3 * HTML output functions
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Andreas Gohr <andi@splitbrain.org>
7 */
8
9  if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
10
11  require_once(DOKU_INC.'inc/parserutils.php');
12
13/**
14 * Convenience function to quickly build a wikilink
15 *
16 * @author Andreas Gohr <andi@splitbrain.org>
17 */
18function html_wikilink($id,$name=NULL,$search=''){
19  static $xhtml_renderer = NULL;
20  if(is_null($xhtml_renderer)){
21    require_once(DOKU_INC.'inc/parser/xhtml.php');
22    $xhtml_renderer = new Doku_Renderer_xhtml();
23  }
24
25  return $xhtml_renderer->internallink($id,$name,$search,true);
26}
27
28/**
29 * Helps building long attribute lists
30 *
31 * @author Andreas Gohr <andi@splitbrain.org>
32 */
33function html_attbuild($attributes){
34  $ret = '';
35  foreach ( $attributes as $key => $value ) {
36    $ret .= $key.'="'.formtext($value).'" ';
37  }
38  return trim($ret);
39}
40
41/**
42 * The loginform
43 *
44 * @author Andreas Gohr <andi@splitbrain.org>
45 */
46function html_login(){
47  global $lang;
48  global $conf;
49  global $ID;
50  global $auth;
51
52  print p_locale_xhtml('login');
53  ?>
54    <div class="centeralign">
55    <form action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>"
56          method="post" name="login">
57      <fieldset>
58        <legend><?php echo $lang['btn_login']?></legend>
59        <input type="hidden" name="id" value="<?php echo $ID?>" />
60        <input type="hidden" name="do" value="login" />
61        <label class="block">
62          <span><?php echo $lang['user']?></span>
63          <input type="text" name="u" value="<?php echo formText($_REQUEST['u'])?>"
64                 class="edit" id="focus__this" />
65        </label><br />
66        <label class="block">
67          <span><?php echo $lang['pass']?></span>
68          <input type="password" name="p" class="edit" />
69        </label><br />
70        <label for="remember__me" class="simple">
71          <input type="checkbox" name="r" id="remember__me" value="1" />
72          <span><?php echo $lang['remember']?></span>
73        </label>
74        <input type="submit" value="<?php echo $lang['btn_login']?>" class="button" />
75      </fieldset>
76    </form>
77  <?php
78    if($auth->canDo('addUser') && actionOK('register')){
79      print '<p>';
80      print $lang['reghere'];
81      print ': <a href="'.wl($ID,'do=register').'" class="wikilink1">'.$lang['register'].'</a>';
82      print '</p>';
83    }
84
85    if ($auth->canDo('modPass') && actionOK('resendpwd')) {
86      print '<p>';
87      print $lang['pwdforget'];
88      print ': <a href="'.wl($ID,'do=resendpwd').'" class="wikilink1">'.$lang['btn_resendpwd'].'</a>';
89      print '</p>';
90    }
91  ?>
92    </div>
93  <?php
94/*
95 FIXME provide new hook
96  if(@file_exists('includes/login.txt')){
97    print io_cacheParse('includes/login.txt');
98  }
99*/
100}
101
102/**
103 * prints a section editing button
104 * used as a callback in html_secedit
105 *
106 * @author Andreas Gohr <andi@splitbrain.org>
107 */
108function html_secedit_button($matches){
109  global $ID;
110  global $INFO;
111
112  $section = $matches[2];
113  $name = $matches[1];
114
115  $secedit  = '';
116  $secedit .= '<div class="secedit">';
117  $secedit .= html_btn('secedit',$ID,'',
118                        array('do'      => 'edit',
119                              'lines'   => "$section",
120                              'rev' => $INFO['lastmod']),
121                              'post', $name);
122  $secedit .= '</div>';
123  return $secedit;
124}
125
126/**
127 * inserts section edit buttons if wanted or removes the markers
128 *
129 * @author Andreas Gohr <andi@splitbrain.org>
130 */
131function html_secedit($text,$show=true){
132  global $INFO;
133
134  if($INFO['writable'] && $show && !$INFO['rev']){
135    $text = preg_replace_callback('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#',
136                         'html_secedit_button', $text);
137  }else{
138    $text = preg_replace('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#','',$text);
139  }
140
141  return $text;
142}
143
144/**
145 * Just the back to top button (in its own form)
146 *
147 * @author Andreas Gohr <andi@splitbrain.org>
148 */
149function html_topbtn(){
150  global $lang;
151
152  $ret  = '';
153  $ret  = '<a class="nolink" href="#dokuwiki__top"><input type="button" class="button" value="'.$lang['btn_top'].'" onclick="window.scrollTo(0, 0)" /></a>';
154
155  return $ret;
156}
157
158/**
159 * Just the back to media window button in its own form
160 *
161 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
162 */
163function html_backtomedia_button($params,$akey=''){
164  global $conf;
165  global $lang;
166
167  $ret = '<form class="button" method="get" action="'.DOKU_BASE.'lib/exe/mediamanager.php"><div class="no">';
168
169  reset($params);
170  while (list($key, $val) = each($params)) {
171    $ret .= '<input type="hidden" name="'.$key.'" ';
172    $ret .= 'value="'.htmlspecialchars($val).'" />';
173  }
174
175  $ret .= '<input type="submit" value="'.htmlspecialchars($lang['btn_backtomedia']).'" class="button" ';
176  if($akey){
177    $ret .= 'title="ALT+'.strtoupper($akey).'" ';
178    $ret .= 'accesskey="'.$akey.'" ';
179  }
180  $ret .= '/>';
181  $ret .= '</div></form>';
182
183  return $ret;
184}
185
186/**
187 * Displays a button (using its own form)
188 * If tooltip exists, the access key tooltip is replaced.
189 *
190 * @author Andreas Gohr <andi@splitbrain.org>
191 */
192function html_btn($name,$id,$akey,$params,$method='get',$tooltip=''){
193  global $conf;
194  global $lang;
195
196  $label = $lang['btn_'.$name];
197
198  $ret = '';
199  $tip = '';
200
201  //filter id (without urlencoding)
202  $id = idfilter($id,false);
203
204  //make nice URLs even for buttons
205  if($conf['userewrite'] == 2){
206    $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
207  }elseif($conf['userewrite']){
208    $script = DOKU_BASE.$id;
209  }else{
210    $script = DOKU_BASE.DOKU_SCRIPT;
211    $params['id'] = $id;
212  }
213
214  $ret .= '<form class="button" method="'.$method.'" action="'.$script.'"><div class="no">';
215
216  if(is_array($params)){
217    reset($params);
218    while (list($key, $val) = each($params)) {
219      $ret .= '<input type="hidden" name="'.$key.'" ';
220      $ret .= 'value="'.htmlspecialchars($val).'" />';
221    }
222  }
223
224  $ret .= '<input type="submit" value="'.htmlspecialchars($label).'" class="button" ';
225  if($akey){
226    $tip = '[ALT+'.strtoupper($akey).']';
227    $ret .= 'accesskey="'.$akey.'" ';
228  }
229  if ($tooltip!='') {
230      $tip = htmlspecialchars($tooltip);
231  }
232  $ret .= 'title="'.$tip.'" ';
233  $ret .= '/>';
234  $ret .= '</div></form>';
235
236  return $ret;
237}
238
239/**
240 * show a wiki page
241 *
242 * @author Andreas Gohr <andi@splitbrain.org>
243 */
244function html_show($txt=''){
245  global $ID;
246  global $REV;
247  global $HIGH;
248  //disable section editing for old revisions or in preview
249  if($txt || $REV){
250    $secedit = false;
251  }else{
252    $secedit = true;
253  }
254
255  if ($txt){
256    //PreviewHeader
257    print '<br id="scroll__here" />';
258    print p_locale_xhtml('preview');
259    print '<div class="preview">';
260    print html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
261    print '<div class="clearer"></div>';
262    print '</div>';
263
264  }else{
265    if ($REV) print p_locale_xhtml('showrev');
266    $html = p_wiki_xhtml($ID,$REV,true);
267    $html = html_secedit($html,$secedit);
268    print html_hilight($html,$HIGH);
269  }
270}
271
272/**
273 * ask the user about how to handle an exisiting draft
274 *
275 * @author Andreas Gohr <andi@splitbrain.org>
276 */
277function html_draft(){
278  global $INFO;
279  global $ID;
280  global $lang;
281  global $conf;
282  $draft = unserialize(io_readFile($INFO['draft'],false));
283  $text  = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
284
285  echo p_locale_xhtml('draft');
286  ?>
287  <form id="dw__editform" method="post" action="<?php echo script()?>"
288   accept-charset="<?php echo $lang['encoding']?>"><div class="no">
289    <input type="hidden" name="id"   value="<?php echo $ID?>" />
290    <input type="hidden" name="date" value="<?php echo $draft['date']?>" /></div>
291    <textarea name="wikitext" id="wiki__text" readonly="readonly" cols="80" rows="10" class="edit"><?php echo "\n".formText($text)?></textarea>
292
293    <div id="draft__status"><?php echo $lang['draftdate'].' '.date($conf['dformat'],filemtime($INFO['draft']))?></div>
294
295    <input class="button" type="submit" name="do" value="<?php echo $lang['btn_recover']?>" tabindex="1" />
296    <input class="button" type="submit" name="do" value="<?php echo $lang['btn_draftdel']?>" tabindex="2" />
297    <input class="button" type="submit" name="do" value="<?php echo $lang['btn_cancel']?>" tabindex="3" />
298  </form>
299  <?php
300}
301
302/**
303 * Highlights searchqueries in HTML code
304 *
305 * @author Andreas Gohr <andi@splitbrain.org>
306 * @author Harry Fuecks <hfuecks@gmail.com>
307 */
308function html_hilight($html,$query){
309  //split at common delimiters
310  $queries = preg_split ('/[\s\'"\\\\`()\]\[?:!\.{};,#+*<>\\/]+/',$query,-1,PREG_SPLIT_NO_EMPTY);
311  foreach ($queries as $q){
312     $q = preg_quote($q,'/');
313     $html = preg_replace_callback("/((<[^>]*)|$q)/i",'html_hilight_callback',$html);
314  }
315  return $html;
316}
317
318/**
319 * Callback used by html_hilight()
320 *
321 * @author Harry Fuecks <hfuecks@gmail.com>
322 */
323function html_hilight_callback($m) {
324  $hlight = unslash($m[0]);
325  if ( !isset($m[2])) {
326    $hlight = '<span class="search_hit">'.$hlight.'</span>';
327  }
328  return $hlight;
329}
330
331/**
332 * Run a search and display the result
333 *
334 * @author Andreas Gohr <andi@splitbrain.org>
335 */
336function html_search(){
337  require_once(DOKU_INC.'inc/search.php');
338  require_once(DOKU_INC.'inc/fulltext.php');
339  global $conf;
340  global $QUERY;
341  global $ID;
342  global $lang;
343
344  print p_locale_xhtml('searchpage');
345  flush();
346
347  //check if search is restricted to namespace
348  if(preg_match('/([^@]*)@([^@]*)/',$QUERY,$match)) {
349      $id = cleanID($match[1]);
350      if(empty($id)) {
351        print '<div class="nothing">'.$lang['nothingfound'].'</div>';
352        flush();
353        return;
354      }
355  } else {
356      $id = cleanID($QUERY);
357  }
358
359  //show progressbar
360  print '<div class="centeralign" id="dw__loading">';
361  print '<br /></div>';
362  print '<script type="text/javascript" charset="utf-8">';
363  print 'showLoadBar("dw__loading");';
364  print '</script>';
365  flush();
366
367  //do quick pagesearch
368  $data = array();
369
370  $data = ft_pageLookup($id);
371  if(count($data)){
372    sort($data);
373    print '<div class="search_quickresult">';
374    print '<h3>'.$lang[quickhits].':</h3>';
375    print '<ul class="search_quickhits">';
376    foreach($data as $id){
377      print '<li> ';
378      print html_wikilink(':'.$id,$conf['useheading']?NULL:$id);
379      print '</li> ';
380    }
381    print '</ul> ';
382    //clear float (see http://www.complexspiral.com/publications/containing-floats/)
383    print '<div class="clearer">&nbsp;</div>';
384    print '</div>';
385  }
386  flush();
387
388  //do fulltext search
389  $data = ft_pageSearch($QUERY,$poswords);
390  if(count($data)){
391    $num = 1;
392    foreach($data as $id => $cnt){
393      print '<div class="search_result">';
394      print html_wikilink(':'.$id,$conf['useheading']?NULL:$id,$poswords);
395      print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />';
396      if($num < 15){ // create snippets for the first number of matches only #FIXME add to conf ?
397        print '<div class="search_snippet">'.ft_snippet($id,$poswords).'</div>';
398      }
399      print '</div>';
400      flush();
401      $num++;
402    }
403  }else{
404    print '<div class="nothing">'.$lang['nothingfound'].'</div>';
405  }
406
407  //hide progressbar
408  print '<script type="text/javascript" charset="utf-8">';
409  print 'hideLoadBar("dw__loading");';
410  print '</script>';
411  flush();
412}
413
414/**
415 * Display error on locked pages
416 *
417 * @author Andreas Gohr <andi@splitbrain.org>
418 */
419function html_locked(){
420  global $ID;
421  global $conf;
422  global $lang;
423  global $INFO;
424
425  $locktime = filemtime(wikiFN($ID).'.lock');
426  $expire = @date($conf['dformat'], $locktime + $conf['locktime'] );
427  $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
428
429  print p_locale_xhtml('locked');
430  print '<ul>';
431  print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.$INFO['locked'].'</li>';
432  print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>';
433  print '</ul>';
434}
435
436/**
437 * list old revisions
438 *
439 * @author Andreas Gohr <andi@splitbrain.org>
440 */
441function html_revisions(){
442  global $ID;
443  global $INFO;
444  global $conf;
445  global $lang;
446  $revisions = getRevisions($ID);
447  $date = @date($conf['dformat'],$INFO['lastmod']);
448
449  print p_locale_xhtml('revisions');
450  print '<ul>';
451  if($INFO['exists']){
452    print ($INFO['minor']) ? '<li class="minor">' : '<li>';
453    print '<div class="li">';
454
455    print $date;
456
457    print ' <img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" /> ';
458
459    print '<a class="wikilink1" href="'.wl($ID).'">'.$ID.'</a> ';
460
461    print $INFO['sum'];
462    print ' <span class="user">';
463    print $INFO['editor'];
464    print '</span> ';
465
466    print '('.$lang['current'].')';
467    print '</div>';
468    print '</li>';
469  }
470
471  foreach($revisions as $rev){
472    $date = date($conf['dformat'],$rev);
473    $info = getRevisionInfo($ID,$rev,true);
474
475    print ($info['minor']) ? '<li class="minor">' : '<li>';
476    print '<div class="li">';
477    print $date;
478
479    print ' <a href="'.wl($ID,"rev=$rev,do=diff").'">';
480    $p = array();
481    $p['src']    = DOKU_BASE.'lib/images/diff.png';
482    $p['width']  = 15;
483    $p['height'] = 11;
484    $p['title']  = $lang['diff'];
485    $p['alt']    = $lang['diff'];
486    $att = buildAttributes($p);
487    print "<img $att />";
488    print '</a> ';
489
490    print '<a class="wikilink1" href="'.wl($ID,"rev=$rev").'">'.$ID.'</a> ';
491
492    print htmlspecialchars($info['sum']);
493    print ' <span class="user">';
494    if($info['user']){
495      print $info['user'];
496    }else{
497      print $info['ip'];
498    }
499    print '</span>';
500
501    print '</div>';
502    print '</li>';
503  }
504  print '</ul>';
505}
506
507/**
508 * display recent changes
509 *
510 * @author Andreas Gohr <andi@splitbrain.org>
511 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
512 */
513function html_recent($first=0){
514  global $conf;
515  global $lang;
516  global $ID;
517  /* we need to get one additionally log entry to be able to
518   * decide if this is the last page or is there another one.
519   * This is the cheapest solution to get this information.
520   */
521  $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
522  if(count($recents) == 0 && $first != 0){
523    $first=0;
524    $recents = getRecents(0,$conf['recent'] + 1,getNS($ID));
525  }
526  $cnt = count($recents) <= $conf['recent'] ? count($recents) : $conf['recent'];
527
528  print p_locale_xhtml('recent');
529  print '<ul>';
530
531  foreach($recents as $recent){
532    $date = date($conf['dformat'],$recent['date']);
533    print ($recent['minor']) ? '<li class="minor">' : '<li>';
534    print '<div class="li">';
535
536    print $date.' ';
537
538    print '<a href="'.wl($recent['id'],"do=diff").'">';
539    $p = array();
540    $p['src']    = DOKU_BASE.'lib/images/diff.png';
541    $p['width']  = 15;
542    $p['height'] = 11;
543    $p['title']  = $lang['diff'];
544    $p['alt']    = $lang['diff'];
545    $att = buildAttributes($p);
546    print "<img $att />";
547    print '</a> ';
548
549    print '<a href="'.wl($recent['id'],"do=revisions").'">';
550    $p = array();
551    $p['src']    = DOKU_BASE.'lib/images/history.png';
552    $p['width']  = 12;
553    $p['height'] = 14;
554    $p['title']  = $lang['btn_revs'];
555    $p['alt']    = $lang['btn_revs'];
556    $att = buildAttributes($p);
557    print "<img $att />";
558    print '</a> ';
559
560    print html_wikilink(':'.$recent['id'],$conf['useheading']?NULL:$recent['id']);
561    print ' '.htmlspecialchars($recent['sum']);
562
563    print ' <span class="user">';
564    if($recent['user']){
565      print $recent['user'];
566    }else{
567      print $recent['ip'];
568    }
569    print '</span>';
570
571    print '</div>';
572    print '</li>';
573  }
574  print '</ul>';
575
576  print '<div class="pagenav">';
577  $last = $first + $conf['recent'];
578  if ($first > 0) {
579    $first -= $conf['recent'];
580    if ($first < 0) $first = 0;
581    print '<div class="pagenav-prev">';
582    print html_btn('newer','',"p",array('do' => 'recent', 'first' => $first));
583    print '</div>';
584  }
585  if ($conf['recent'] < count($recents)) {
586    print '<div class="pagenav-next">';
587    print html_btn('older','',"n",array('do' => 'recent', 'first' => $last));
588    print '</div>';
589  }
590  print '</div>';
591}
592
593/**
594 * Display page index
595 *
596 * @author Andreas Gohr <andi@splitbrain.org>
597 */
598function html_index($ns){
599  require_once(DOKU_INC.'inc/search.php');
600  global $conf;
601  global $ID;
602  $dir = $conf['datadir'];
603  $ns  = cleanID($ns);
604  #fixme use appropriate function
605  if(empty($ns)){
606    $ns = dirname(str_replace(':','/',$ID));
607    if($ns == '.') $ns ='';
608  }
609  $ns  = utf8_encodeFN(str_replace(':','/',$ns));
610
611  print p_locale_xhtml('index');
612
613  $data = array();
614  search($data,$conf['datadir'],'search_index',array('ns' => $ns));
615  print html_buildlist($data,'idx','html_list_index','html_li_index');
616}
617
618/**
619 * Index item formatter
620 *
621 * User function for html_buildlist()
622 *
623 * @author Andreas Gohr <andi@splitbrain.org>
624 */
625function html_list_index($item){
626  $ret = '';
627  $base = ':'.$item['id'];
628  $base = substr($base,strrpos($base,':')+1);
629  if($item['type']=='d'){
630    $ret .= '<a href="'.wl($ID,'idx='.$item['id']).'" class="idx_dir">';
631    $ret .= $base;
632    $ret .= '</a>';
633  }else{
634    $ret .= html_wikilink(':'.$item['id']);
635  }
636  return $ret;
637}
638
639/**
640 * Index List item
641 *
642 * This user function is used in html_build_lidt to build the
643 * <li> tags for namespaces when displaying the page index
644 * it gives different classes to opened or closed "folders"
645 *
646 * @author Andreas Gohr <andi@splitbrain.org>
647 */
648function html_li_index($item){
649  if($item['type'] == "f"){
650    return '<li class="level'.$item['level'].'">';
651  }elseif($item['open']){
652    return '<li class="open">';
653  }else{
654    return '<li class="closed">';
655  }
656}
657
658/**
659 * Default List item
660 *
661 * @author Andreas Gohr <andi@splitbrain.org>
662 */
663function html_li_default($item){
664  return '<li class="level'.$item['level'].'">';
665}
666
667/**
668 * Build an unordered list
669 *
670 * Build an unordered list from the given $data array
671 * Each item in the array has to have a 'level' property
672 * the item itself gets printed by the given $func user
673 * function. The second and optional function is used to
674 * print the <li> tag. Both user function need to accept
675 * a single item.
676 *
677 * Both user functions can be given as array to point to
678 * a member of an object.
679 *
680 * @author Andreas Gohr <andi@splitbrain.org>
681 */
682function html_buildlist($data,$class,$func,$lifunc='html_li_default'){
683  $level = 0;
684  $opens = 0;
685  $ret   = '';
686
687  foreach ($data as $item){
688
689    if( $item['level'] > $level ){
690      //open new list
691      for($i=0; $i<($item['level'] - $level); $i++){
692        if ($i) $ret .= "<li class=\"clear\">\n";
693        $ret .= "\n<ul class=\"$class\">\n";
694      }
695    }elseif( $item['level'] < $level ){
696      //close last item
697      $ret .= "</li>\n";
698      for ($i=0; $i<($level - $item['level']); $i++){
699        //close higher lists
700        $ret .= "</ul>\n</li>\n";
701      }
702    }else{
703      //close last item
704      $ret .= "</li>\n";
705    }
706
707    //remember current level
708    $level = $item['level'];
709
710    //print item
711    if(is_array($lifunc)){
712      $ret .= $lifunc[0]->$lifunc[1]($item); //user object method
713    }else{
714      $ret .= $lifunc($item); //user function
715    }
716    $ret .= '<div class="li">';
717    if(is_array($func)){
718      $ret .= $func[0]->$func[1]($item); //user object method
719    }else{
720    $ret .= $func($item); //user function
721    }
722    $ret .= '</div>';
723  }
724
725  //close remaining items and lists
726  for ($i=0; $i < $level; $i++){
727    $ret .= "</li></ul>\n";
728  }
729
730  return $ret;
731}
732
733/**
734 * display backlinks
735 *
736 * @author Andreas Gohr <andi@splitbrain.org>
737 */
738function html_backlinks(){
739  require_once(DOKU_INC.'inc/fulltext.php');
740  global $ID;
741  global $conf;
742
743  print p_locale_xhtml('backlinks');
744
745  $data = ft_backlinks($ID);
746
747  print '<ul class="idx">';
748  foreach($data as $blink){
749    print '<li><div class="li">';
750    print html_wikilink(':'.$blink,$conf['useheading']?NULL:$blink);
751    print '</div></li>';
752  }
753  print '</ul>';
754}
755
756/**
757 * show diff
758 *
759 * @author Andreas Gohr <andi@splitbrain.org>
760 */
761function html_diff($text='',$intro=true){
762  require_once(DOKU_INC.'inc/DifferenceEngine.php');
763  global $ID;
764  global $REV;
765  global $lang;
766  global $conf;
767  if($text){
768    $df  = new Diff(split("\n",htmlspecialchars(rawWiki($ID,''))),
769                    split("\n",htmlspecialchars(cleanText($text))));
770    $left  = '<a class="wikilink1" href="'.wl($ID).'">'.
771              $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a>'.
772              $lang['current'];
773    $right = $lang['yours'];
774  }else{
775    if($REV){
776      $r = $REV;
777    }else{
778      //use last revision if none given
779      $revs = getRevisions($ID);
780      $r = $revs[0];
781    }
782
783    $df  = new Diff(split("\n",htmlspecialchars(rawWiki($ID,$r))),
784                    split("\n",htmlspecialchars(rawWiki($ID,''))));
785    $left  = '<a class="wikilink1" href="'.wl($ID,"rev=$r").'">'.
786              $ID.' '.date($conf['dformat'],$r).'</a>';
787    $right = '<a class="wikilink1" href="'.wl($ID).'">'.
788              $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a> '.
789              $lang['current'];
790  }
791  $tdf = new TableDiffFormatter();
792  if($intro) print p_locale_xhtml('diff');
793  ?>
794    <table class="diff">
795      <tr>
796        <th colspan="2">
797          <?php echo $left?>
798        </th>
799        <th colspan="2">
800          <?php echo $right?>
801        </th>
802      </tr>
803      <?php echo $tdf->format($df)?>
804    </table>
805  <?php
806}
807
808/**
809 * show warning on conflict detection
810 *
811 * @author Andreas Gohr <andi@splitbrain.org>
812 */
813function html_conflict($text,$summary){
814  global $ID;
815  global $lang;
816
817  print p_locale_xhtml('conflict');
818  ?>
819  <form id="dw__editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>">
820  <div class="centeralign">
821    <input type="hidden" name="id" value="<?php echo $ID?>" />
822    <input type="hidden" name="wikitext" value="<?php echo formText($text)?>" />
823    <input type="hidden" name="summary" value="<?php echo formText($summary)?>" />
824
825    <input class="button" type="submit" name="do" value="<?php echo $lang['btn_save']?>" accesskey="s" title="[ALT+S]" />
826    <input class="button" type="submit" name="do" value="<?php echo $lang['btn_cancel']?>" />
827  </div>
828  </form>
829  <br /><br /><br /><br />
830  <?php
831}
832
833/**
834 * Prints the global message array
835 *
836 * @author Andreas Gohr <andi@splitbrain.org>
837 */
838function html_msgarea(){
839  global $MSG;
840
841  if(!isset($MSG)) return;
842
843  foreach($MSG as $msg){
844    print '<div class="'.$msg['lvl'].'">';
845    print $msg['msg'];
846    print '</div>';
847  }
848}
849
850/**
851 * Prints the registration form
852 *
853 * @author Andreas Gohr <andi@splitbrain.org>
854 */
855function html_register(){
856  global $lang;
857  global $conf;
858  global $ID;
859
860  print p_locale_xhtml('register');
861?>
862  <div class="centeralign">
863  <form id="dw__register" method="post" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>">
864  <fieldset>
865    <input type="hidden" name="do" value="register" />
866    <input type="hidden" name="save" value="1" />
867
868    <legend><?php echo $lang['register']?></legend>
869    <label class="block">
870      <?php echo $lang['user']?>
871      <input type="text" name="login" class="edit" size="50" value="<?php echo formText($_POST['login'])?>" />
872    </label><br />
873
874    <?php
875      if (!$conf['autopasswd']) {
876    ?>
877      <label class="block">
878        <?php echo $lang['pass']?>
879        <input type="password" name="pass" class="edit" size="50" />
880      </label><br />
881      <label class="block">
882        <?php echo $lang['passchk']?>
883        <input type="password" name="passchk" class="edit" size="50" />
884      </label><br />
885    <?php
886      }
887    ?>
888
889    <label class="block">
890      <?php echo $lang['fullname']?>
891      <input type="text" name="fullname" class="edit" size="50" value="<?php echo formText($_POST['fullname'])?>" />
892    </label><br />
893    <label class="block">
894      <?php echo $lang['email']?>
895      <input type="text" name="email" class="edit" size="50" value="<?php echo formText($_POST['email'])?>" />
896    </label><br />
897    <input type="submit" class="button" value="<?php echo $lang['register']?>" />
898  </fieldset>
899  </form>
900  </div>
901<?php
902}
903
904/**
905 * Print the update profile form
906 *
907 * @author Christopher Smith <chris@jalakai.co.uk>
908 * @author Andreas Gohr <andi@splitbrain.org>
909 */
910function html_updateprofile(){
911  global $lang;
912  global $conf;
913  global $ID;
914  global $INFO;
915  global $auth;
916
917  print p_locale_xhtml('updateprofile');
918
919  if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
920  if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
921?>
922  <div class="centeralign">
923  <form id="dw__register" method="post" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>">
924  <fieldset style="width: 80%;">
925    <input type="hidden" name="do" value="profile" />
926    <input type="hidden" name="save" value="1" />
927
928    <legend><?php echo $lang['profile']?></legend>
929    <label class="block">
930      <?php echo $lang['user']?>
931      <input type="text" name="fullname" disabled="disabled" class="edit" size="50" value="<?php echo formText($_SERVER['REMOTE_USER'])?>" />
932    </label><br />
933    <label class="block">
934      <?php echo $lang['fullname']?>
935      <input type="text" name="fullname" <?php if(!$auth->canDo('modName')) echo 'disabled="disabled"'?> class="edit" size="50" value="<?php echo formText($_POST['fullname'])?>" />
936    </label><br />
937    <label class="block">
938      <?php echo $lang['email']?>
939      <input type="text" name="email" <?php if(!$auth->canDo('modName')) echo 'disabled="disabled"'?> class="edit" size="50" value="<?php echo formText($_POST['email'])?>" />
940    </label><br /><br />
941
942    <?php if($auth->canDo('modPass')) { ?>
943    <label class="block">
944      <?php echo $lang['newpass']?>
945      <input type="password" name="newpass" class="edit" size="50" />
946    </label><br />
947    <label class="block">
948      <?php echo $lang['passchk']?>
949      <input type="password" name="passchk" class="edit" size="50" />
950    </label><br />
951    <?php } ?>
952
953    <?php if ($conf['profileconfirm']) { ?>
954      <br />
955      <label class="block">
956      <?php echo $lang['oldpass']?>
957      <input type="password" name="oldpass" class="edit" size="50" />
958    </label><br />
959    <?php } ?>
960
961    <input type="submit" class="button" value="<?php echo $lang['btn_save']?>" />
962    <input type="reset" class="button" value="<?php echo $lang['btn_reset']?>" />
963  </fieldset>
964  </form>
965  </div>
966<?php
967}
968
969/**
970 * This displays the edit form (lots of logic included)
971 *
972 * @fixme  this is a huge lump of code and should be modularized
973 * @author Andreas Gohr <andi@splitbrain.org>
974 */
975function html_edit($text=null,$include='edit'){ //FIXME: include needed?
976  global $ID;
977  global $REV;
978  global $DATE;
979  global $RANGE;
980  global $PRE;
981  global $SUF;
982  global $INFO;
983  global $SUM;
984  global $lang;
985  global $conf;
986
987  //set summary default
988  if(!$SUM){
989    if($REV){
990      $SUM = $lang['restored'];
991    }elseif(!$INFO['exists']){
992      $SUM = $lang['created'];
993    }
994  }
995
996  //no text? Load it!
997  if(!isset($text)){
998    $pr = false; //no preview mode
999    if($INFO['exists']){
1000      if($RANGE){
1001        list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
1002      }else{
1003        $text = rawWiki($ID,$REV);
1004      }
1005    }else{
1006      //try to load a pagetemplate
1007      $text = pageTemplate($ID);
1008    }
1009  }else{
1010    $pr = true; //preview mode
1011  }
1012
1013  $wr = $INFO['writable'];
1014  if($wr){
1015    if ($REV) print p_locale_xhtml('editrev');
1016    print p_locale_xhtml($include);
1017  }else{
1018    // check pseudo action 'source'
1019    if(!actionOK('source')){
1020      msg('Command disabled: source',-1);
1021      return;
1022    }
1023    print p_locale_xhtml('read');
1024    $ro='readonly="readonly"';
1025  }
1026  if(!$DATE) $DATE = $INFO['lastmod'];
1027
1028
1029?>
1030  <div style="width:99%;">
1031
1032   <div class="toolbar">
1033      <div id="draft__status"><?php if($INFO['draft']) echo $lang['draftdate'].' '.date($conf['dformat']);?></div>
1034      <div id="tool__bar"><?php if(!$ro){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
1035      target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
1036
1037      <?php if($wr){?>
1038      <script type="text/javascript" charset="utf-8">
1039        <?php /* sets changed to true when previewed */?>
1040        textChanged = <?php ($pr) ? print 'true' : print 'false' ?>;
1041      </script>
1042      <span id="spell__action"></span>
1043      <div id="spell__suggest"></div>
1044      <?php } ?>
1045   </div>
1046   <div id="spell__result"></div>
1047
1048
1049   <form id="dw__editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>"><div class="no">
1050      <input type="hidden" name="id"   value="<?php echo $ID?>" />
1051      <input type="hidden" name="rev"  value="<?php echo $REV?>" />
1052      <input type="hidden" name="date" value="<?php echo $DATE?>" />
1053      <input type="hidden" name="prefix" value="<?php echo formText($PRE)?>" />
1054      <input type="hidden" name="suffix" value="<?php echo formText($SUF)?>" />
1055    </div>
1056
1057    <textarea name="wikitext" id="wiki__text" <?php echo $ro?> cols="80" rows="10" class="edit" tabindex="1"><?php echo "\n".formText($text)?></textarea>
1058
1059    <div id="wiki__editbar">
1060      <div id="size__ctl"></div>
1061      <?php if($wr){?>
1062         <div class="editButtons">
1063            <input class="button" id="edbtn__save" type="submit" name="do" value="<?php echo $lang['btn_save']?>" accesskey="s" title="[ALT+S]" tabindex="4" />
1064            <input class="button" id="edbtn__preview" type="submit" name="do" value="<?php echo $lang['btn_preview']?>" accesskey="p" title="[ALT+P]" tabindex="5" />
1065            <input class="button" type="submit" name="do[draftdel]" value="<?php echo $lang['btn_cancel']?>" tabindex="6" />
1066         </div>
1067      <?php } ?>
1068      <?php if($wr){ ?>
1069        <div class="summary">
1070           <label for="edit__summary" class="nowrap"><?php echo $lang['summary']?>:</label>
1071           <input type="text" class="edit" name="summary" id="edit__summary" size="50" value="<?php echo formText($SUM)?>" tabindex="2" />
1072           <?php html_minoredit()?>
1073        </div>
1074      <?php }?>
1075    </div>
1076  </form>
1077  </div>
1078<?php
1079}
1080
1081/**
1082 * Adds a checkbox for minor edits for logged in users
1083 *
1084 * @author Andrea Gohr <andi@splitbrain.org>
1085 */
1086function html_minoredit(){
1087  global $conf;
1088  global $lang;
1089  // minor edits are for logged in users only
1090  if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1091    return;
1092  }
1093
1094  $p = array();
1095  $p['name']     = 'minor';
1096  $p['type']     = 'checkbox';
1097  $p['id']       = 'minoredit';
1098  $p['tabindex'] = 3;
1099  $p['value']    = '1';
1100  if($_REQUEST['minor']) $p['checked']='checked';
1101  $att = buildAttributes($p);
1102
1103  print '<span class="nowrap">';
1104  print "<input $att />";
1105  print '<label for="minoredit">';
1106  print $lang['minoredit'];
1107  print '</label>';
1108  print '</span>';
1109}
1110
1111/**
1112 * prints some debug info
1113 *
1114 * @author Andreas Gohr <andi@splitbrain.org>
1115 */
1116function html_debug(){
1117  global $conf;
1118  global $lang;
1119  global $auth;
1120  //remove sensitive data
1121  $cnf = $conf;
1122  $cnf['auth']='***';
1123  $cnf['notify']='***';
1124  $cnf['ftp']='***';
1125
1126  print '<html><body>';
1127
1128  print '<p>When reporting bugs please send all the following ';
1129  print 'output as a mail to andi@splitbrain.org ';
1130  print 'The best way to do this is to save this page in your browser</p>';
1131
1132  print '<b>$_SERVER:</b><pre>';
1133  print_r($_SERVER);
1134  print '</pre>';
1135
1136  print '<b>$conf:</b><pre>';
1137  print_r($cnf);
1138  print '</pre>';
1139
1140  print '<b>DOKU_BASE:</b><pre>';
1141  print DOKU_BASE;
1142  print '</pre>';
1143
1144  print '<b>abs DOKU_BASE:</b><pre>';
1145  print DOKU_URL;
1146  print '</pre>';
1147
1148  print '<b>rel DOKU_BASE:</b><pre>';
1149  print dirname($_SERVER['PHP_SELF']).'/';
1150  print '</pre>';
1151
1152  print '<b>PHP Version:</b><pre>';
1153  print phpversion();
1154  print '</pre>';
1155
1156  print '<b>locale:</b><pre>';
1157  print setlocale(LC_ALL,0);
1158  print '</pre>';
1159
1160  print '<b>encoding:</b><pre>';
1161  print $lang['encoding'];
1162  print '</pre>';
1163
1164  if($auth){
1165    print '<b>Auth backend capabilities:</b><pre>';
1166    print_r($auth->cando);
1167    print '</pre>';
1168  }
1169
1170  print '<b>$_SESSION:</b><pre>';
1171  print_r($_SESSION);
1172  print '</pre>';
1173
1174  print '<b>Environment:</b><pre>';
1175  print_r($_ENV);
1176  print '</pre>';
1177
1178  print '<b>PHP settings:</b><pre>';
1179  $inis = ini_get_all();
1180  print_r($inis);
1181  print '</pre>';
1182
1183  print '</body></html>';
1184}
1185
1186function html_admin(){
1187  global $ID;
1188  global $lang;
1189  global $conf;
1190
1191  print p_locale_xhtml('admin');
1192
1193  // build menu of admin functions from the plugins that handle them
1194  $pluginlist = plugin_list('admin');
1195  $menu = array();
1196  foreach ($pluginlist as $p) {
1197    if($obj =& plugin_load('admin',$p) === NULL) continue;
1198    $menu[] = array('plugin' => $p,
1199                    'prompt' => $obj->getMenuText($conf['lang']),
1200                    'sort' => $obj->getMenuSort()
1201                   );
1202  }
1203
1204  usort($menu, p_sort_modes);
1205
1206  // output the menu
1207  ptln('<ul>');
1208
1209  foreach ($menu as $item) {
1210    if (!$item['prompt']) continue;
1211    ptln('  <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
1212  }
1213
1214  ptln('</ul>');
1215}
1216
1217/**
1218 * Form to request a new password for an existing account
1219 *
1220 * @author Benoit Chesneau <benoit@bchesneau.info>
1221 */
1222function html_resendpwd() {
1223  global $lang;
1224  global $conf;
1225  global $ID;
1226
1227  print p_locale_xhtml('resendpwd');
1228?>
1229  <div class="centeralign">
1230  <form id="dw__resendpwd" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>" method="post">
1231    <fieldset>
1232      <br />
1233      <legend><?php echo $lang['resendpwd']?></legend>
1234      <input type="hidden" name="do" value="resendpwd" />
1235      <input type="hidden" name="save" value="1" />
1236      <label class="block">
1237        <span><?php echo $lang['user']?></span>
1238        <input type="text" name="login" value="<?php echo formText($_POST['login'])?>" class="edit" /><br /><br />
1239      </label><br />
1240      <input type="submit" value="<?php echo $lang['btn_resendpwd']?>" class="button" />
1241    </fieldset>
1242  </form>
1243  </div>
1244<?php
1245}
1246
1247//Setup VIM: ex: et ts=2 enc=utf-8 :
1248