xref: /dokuwiki/inc/html.php (revision 2a27e99ac0428ee74f330df0fff0415417765768)
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  require_once(DOKU_INC.'inc/parser/xhtml.php');
20  static $xhtml_renderer = NULL;
21  if(is_null($xhtml_renderer)){
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
51  print p_locale_xhtml('login');
52  ?>
53    <div align="center">
54    <form action="<?=script()?>" accept-charset="<?=$lang['encoding']?>" method="post">
55      <fieldset>
56        <legend><?=$lang['btn_login']?></legend>
57        <input type="hidden" name="id" value="<?=$ID?>" />
58        <input type="hidden" name="do" value="login" />
59        <label>
60          <span><?=$lang['user']?></span>
61          <input type="text" name="u" value="<?=formText($_REQUEST['u'])?>" class="edit" />
62        </label><br />
63        <label>
64          <span><?=$lang['pass']?></span>
65          <input type="password" name="p" class="edit" />
66        </label><br />
67        <input type="submit" value="<?=$lang['btn_login']?>" class="button" />
68        <label for="remember" class="simple">
69          <input type="checkbox" name="r" id="remember" value="1" />
70          <span><?=$lang['remember']?></span>
71        </label>
72      </fieldset>
73    </form>
74  <?
75    if($conf['openregister']){
76      print '<p>';
77      print $lang['reghere'];
78      print ': <a href="'.wl($ID,'do=register').'" class="wikilink1">'.$lang['register'].'</a>';
79      print '</p>';
80    }
81  ?>
82    </div>
83  <?
84/*
85 FIXME provide new hook
86  if(@file_exists('includes/login.txt')){
87    print io_cacheParse('includes/login.txt');
88  }
89*/
90}
91
92/**
93 * shows the edit/source/show button dependent on current mode
94 *
95 * @author Andreas Gohr <andi@splitbrain.org>
96 */
97function html_editbutton(){
98  global $ID;
99  global $REV;
100  global $ACT;
101  global $INFO;
102
103  if($ACT == 'show' || $ACT == 'search'){
104    if($INFO['writable']){
105      if($INFO['exists']){
106        $r = html_btn('edit',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
107      }else{
108        $r = html_btn('create',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
109      }
110    }else{
111      $r = html_btn('source',$ID,'v',array('do' => 'edit','rev' => $REV),'post');
112    }
113  }else{
114    $r = html_btn('show',$ID,'v',array('do' => 'show'));
115  }
116  return $r;
117}
118
119/**
120 * prints a section editing button
121 *
122 * @author Andreas Gohr <andi@splitbrain.org>
123 */
124function html_secedit_button($section,$p){
125  global $ID;
126  global $lang;
127  $secedit  = '';
128#  if($p) $secedit .= "</p>\n";
129  $secedit .= '<div class="secedit">';
130  $secedit .= html_btn('secedit',$ID,'',
131                        array('do'      => 'edit',
132                              'lines'   => "$section"),
133                              'post');
134  $secedit .= '</div>';
135#  if($p) $secedit .= "\n<p>";
136  return $secedit;
137}
138
139/**
140 * inserts section edit buttons if wanted or removes the markers
141 *
142 * @author Andreas Gohr <andi@splitbrain.org>
143 */
144function html_secedit($text,$show=true){
145  global $INFO;
146  if($INFO['writable'] && $show && !$INFO['rev']){
147    $text = preg_replace('#<!-- SECTION \[(\d+-\d+)\] -->#e',
148                         "html_secedit_button('\\1',true)",
149                         $text);
150    $text = preg_replace('#<!-- SECTION \[(\d+-)\] -->#e',
151                         "html_secedit_button('\\1',false)",
152                         $text);
153  }else{
154    $text = preg_replace('#<!-- SECTION \[(\d*-\d*)\] -->#e','',$text);
155  }
156  return $text;
157}
158
159/**
160 * Just the back to top button (in it's own form)
161 *
162 * @author Andreas Gohr <andi@splitbrain.org>
163 */
164function html_topbtn(){
165  global $lang;
166
167  $ret  = '';
168  $ret  = '<a href="#top"><input type="button" class="button" value="Back to top" onclick="window.scrollTo(0, 0)" /></a>';
169
170  return $ret;
171}
172
173/**
174 * Displays a button (using it's own form)
175 *
176 * @author Andreas Gohr <andi@splitbrain.org>
177 */
178function html_btn($name,$id,$akey,$params,$method='get'){
179  global $conf;
180  global $lang;
181
182  $label = $lang['btn_'.$name];
183
184  $ret = '';
185
186  //filter id (without urlencoding)
187  $id = idfilter($id,false);
188
189  //make nice URLs even for buttons
190  if($conf['userewrite'] == 2){
191    $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
192  }elseif($conf['userewrite']){
193    $script = DOKU_BASE.$id;
194  }else{
195    $script = DOKU_BASE.DOKU_SCRIPT;
196    $params['id'] = $id;
197  }
198
199  $ret .= '<form class="button" method="'.$method.'" action="'.$script.'" onsubmit="return svchk()">';
200
201  reset($params);
202  while (list($key, $val) = each($params)) {
203    $ret .= '<input type="hidden" name="'.$key.'" ';
204    $ret .= 'value="'.htmlspecialchars($val).'" />';
205  }
206
207  $ret .= '<input type="submit" value="'.htmlspecialchars($label).'" class="button" ';
208  if($akey){
209    $ret .= 'title="ALT+'.strtoupper($akey).'" ';
210    $ret .= 'accesskey="'.$akey.'" ';
211  }
212  $ret .= '/>';
213  $ret .= '</form>';
214
215  return $ret;
216}
217
218/**
219 * Print the table of contents
220 *
221 * @author Andreas Gohr <andi@splitbrain.org>
222 */
223function html_toc($toc){
224  global $lang;
225  $ret  = '';
226  $ret .= '<div class="toc">';
227  $ret .=   '<div class="tocheader">';
228  $ret .=      $lang['toc'];
229  $ret .=     ' <script type="text/javascript">';
230  $ret .=     'showTocToggle("+","-")';
231  $ret .=     '</script>';
232  $ret .=   '</div>';
233  $ret .=   '<div id="tocinside">';
234  $ret .=   html_buildlist($toc,'toc','html_list_toc');
235  $ret .=   '</div>';
236  $ret .= '</div>';
237  return $ret;
238}
239
240/**
241 * TOC item formatter
242 *
243 * User function for html_buildlist()
244 *
245 * @author Andreas Gohr <andi@splitbrain.org>
246 */
247function html_list_toc($item){
248  $ret  = '';
249  $ret .= '<a href="#'.$item['id'].'" class="toc">';
250  $ret .= $item['name'];
251  $ret .= '</a>';
252  return $ret;
253}
254
255/**
256 * show a wiki page
257 *
258 * @author Andreas Gohr <andi@splitbrain.org>
259 */
260function html_show($txt=''){
261  global $ID;
262  global $REV;
263  global $HIGH;
264  //disable section editing for old revisions or in preview
265  if($txt || $REV){
266    $secedit = false;
267  }else{
268    $secedit = true;
269  }
270
271  if ($txt){
272    //PreviewHeader
273    print p_locale_xhtml('preview');
274    print '<div class="preview">';
275    print html_secedit(p_render('xhtml',p_get_instructions($txt)),$secedit);
276    print '</div>';
277
278  }else{
279    if ($REV) print p_locale_xhtml('showrev');
280    $html = p_wiki_xhtml($ID,$REV,true);
281    $html = html_secedit($html,$secedit);
282    print html_hilight($html,$HIGH);
283  }
284}
285
286/**
287 * Highlights searchqueries in HTML code
288 *
289 * @author Andreas Gohr <andi@splitbrain.org>
290 */
291function html_hilight($html,$query){
292  $queries = preg_split ("/\s/",$query,-1,PREG_SPLIT_NO_EMPTY);
293  foreach ($queries as $q){
294    $q = preg_quote($q,'/');
295    $html = preg_replace("/((<[^>]*)|$q)/ie", '"\2"=="\1"? "\1":"<span class=\"search_hit\">\1</span>"', $html);
296  }
297  return $html;
298}
299
300/**
301 * Run a search and display the result
302 *
303 * @author Andreas Gohr <andi@splitbrain.org>
304 */
305function html_search(){
306  require_once(DOKU_INC.'inc/search.php');
307  global $conf;
308  global $QUERY;
309  global $ID;
310  global $lang;
311
312  print p_locale_xhtml('searchpage');
313  flush();
314
315  //show progressbar
316  print '<div align="center">';
317  print '<script language="JavaScript" type="text/javascript">';
318  print 'showLoadBar();';
319  print '</script>';
320  print '<br /></div>';
321
322  //do quick pagesearch
323  $data = array();
324  search($data,$conf['datadir'],'search_pagename',array(query => cleanID($QUERY)));
325  if(count($data)){
326    sort($data);
327    print '<div class="search_quickresult">';
328    print '<b>'.$lang[quickhits].':</b><br />';
329    foreach($data as $row){
330      print '<div class="search_quickhits">';
331      print html_wikilink(':'.$row['id'],$row['id']);
332      print '</div> ';
333    }
334    //clear float (see http://www.complexspiral.com/publications/containing-floats/)
335    print '<div class="clearer">&nbsp;</div>';
336    print '</div>';
337  }
338  flush();
339
340  //do fulltext search
341  $data = array();
342  search($data,$conf['datadir'],'search_fulltext',array(query => utf8_strtolower($QUERY)));
343  if(count($data)){
344    usort($data,'sort_search_fulltext');
345    foreach($data as $row){
346      print '<div class="search_result">';
347      print html_wikilink(':'.$row['id'],$row['id'],$QUERY);
348      print ': <span class="search_cnt">'.$row['count'].' '.$lang['hits'].'</span><br />';
349      print '<div class="search_snippet">'.$row['snippet'].'</div>';
350      print '</div>';
351    }
352  }else{
353    print '<div class="nothing">'.$lang['nothingfound'].'</div>';
354  }
355
356  //hide progressbar
357  print '<script language="JavaScript" type="text/javascript">';
358  print 'hideLoadBar();';
359  print '</script>';
360}
361
362/**
363 * Display error on locked pages
364 *
365 * @author Andreas Gohr <andi@splitbrain.org>
366 */
367function html_locked($ip){
368  global $ID;
369  global $conf;
370  global $lang;
371
372  $locktime = filemtime(wikiFN($ID).'.lock');
373  $expire = @date($conf['dformat'], $locktime + $conf['locktime'] );
374  $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
375
376  print p_locale_xhtml('locked');
377  print '<ul>';
378  print '<li><b>'.$lang['lockedby'].':</b> '.$ip.'</li>';
379  print '<li><b>'.$lang['lockexpire'].':</b> '.$expire.' ('.$min.' min)</li>';
380  print '</ul>';
381}
382
383/**
384 * list old revisions
385 *
386 * @author Andreas Gohr <andi@splitbrain.org>
387 */
388function html_revisions(){
389  global $ID;
390  global $INFO;
391  global $conf;
392  global $lang;
393  $revisions = getRevisions($ID);
394  $date = @date($conf['dformat'],$INFO['lastmod']);
395
396  print p_locale_xhtml('revisions');
397  print '<ul>';
398  if($INFO['exists']){
399    print '<li>';
400
401    print $date;
402
403    print ' <img src="'.DOKU_BASE.'images/blank.gif" border="0" width="15" height="11" alt="" /> ';
404
405    print '<a class="wikilink1" href="'.wl($ID).'">'.$ID.'</a> ';
406
407    print $INFO['sum'];
408    print ' <span class="user">(';
409    print $INFO['ip'];
410    if($INFO['user']) print ' '.$INFO['user'];
411    print ')</span> ';
412
413    print '('.$lang['current'].')';
414    print '</li>';
415  }
416
417  foreach($revisions as $rev){
418    $date = date($conf['dformat'],$rev);
419    $info = getRevisionInfo($ID,$rev);
420
421    print '<li>';
422
423    print $date;
424
425    print ' <a href="'.wl($ID,"rev=$rev,do=diff").'">';
426    print '<img src="'.DOKU_BASE.'images/diff.png" border="0" width="15" height="11" title="'.$lang['diff'].'" />';
427    print '</a> ';
428
429    print '<a class="wikilink1" href="'.wl($ID,"rev=$rev").'">'.$ID.'</a> ';
430
431    print htmlspecialchars($info['sum']);
432    print ' <span class="user">(';
433    print $info['ip'];
434    if($info['user']) print ' '.$info['user'];
435    print ')</span>';
436
437    print '</li>';
438  }
439  print '</ul>';
440}
441
442/**
443 * display recent changes
444 *
445 * @author Andreas Gohr <andi@splitbrain.org>
446 */
447function html_recent(){
448  global $conf;
449  global $lang;
450  $recents = getRecents(0,true);
451
452  print p_locale_xhtml('recent');
453  print '<ul>';
454  foreach(array_keys($recents) as $id){
455    $date = date($conf['dformat'],$recents[$id]['date']);
456    print '<li>';
457
458    print $date.' ';
459
460    print '<a href="'.wl($id,"do=diff").'">';
461    print '<img src="'.DOKU_BASE.'images/diff.png" border="0" width="15" height="11" title="'.$lang['diff'].'" />';
462    print '</a> ';
463
464    print '<a href="'.wl($id,"do=revisions").'">';
465    print '<img src="'.DOKU_BASE.'images/history.png" border="0" width="12" height="14" title="'.$lang['btn_revs'].'" />';
466    print '</a> ';
467
468    print html_wikilink($id,$id);
469
470    print ' '.htmlspecialchars($recents[$id]['sum']);
471    print ' <span class="user">(';
472    print $recents[$id]['ip'];
473    if($recents[$id]['user']) print ' '.$recents[$id]['user'];
474    print ')</span>';
475
476    print '</li>';
477  }
478  print '</ul>';
479}
480
481/**
482 * Display page index
483 *
484 * @author Andreas Gohr <andi@splitbrain.org>
485 */
486function html_index($ns){
487  require_once(DOKU_INC.'inc/search.php');
488  global $conf;
489  global $ID;
490  $dir = $conf['datadir'];
491  $ns  = cleanID($ns);
492  #fixme use appropriate function
493  if(empty($ns)){
494    $ns = dirname(str_replace(':','/',$ID));
495    if($ns == '.') $ns ='';
496  }
497  $ns  = utf8_encodeFN(str_replace(':','/',$ns));
498
499  print p_locale_xhtml('index');
500
501  $data = array();
502  search($data,$conf['datadir'],'search_index',array('ns' => $ns));
503  print html_buildlist($data,'idx','html_list_index','html_li_index');
504}
505
506/**
507 * Index item formatter
508 *
509 * User function for html_buildlist()
510 *
511 * @author Andreas Gohr <andi@splitbrain.org>
512 */
513function html_list_index($item){
514  $ret = '';
515  $base = ':'.$item['id'];
516  $base = substr($base,strrpos($base,':')+1);
517  if($item['type']=='d'){
518    $ret .= '<a href="'.wl($ID,'idx='.$item['id']).'" class="idx_dir">';
519    $ret .= $base;
520    $ret .= '</a>';
521  }else{
522    $ret .= html_wikilink(':'.$item['id']);
523  }
524  return $ret;
525}
526
527/**
528 * Index List item
529 *
530 * This user function is used in html_build_lidt to build the
531 * <li> tags for namespaces when displaying the page index
532 * it gives different classes to opened or closed "folders"
533 *
534 * @author Andreas Gohr <andi@splitbrain.org>
535 */
536function html_li_index($item){
537  if($item['type'] == "f"){
538    return '<li class="level'.$item['level'].'">';
539  }elseif($item['open']){
540    return '<li class="open">';
541  }else{
542    return '<li class="closed">';
543  }
544}
545
546/**
547 * Default List item
548 *
549 * @author Andreas Gohr <andi@splitbrain.org>
550 */
551function html_li_default($item){
552  return '<li class="level'.$item['level'].'">';
553}
554
555/**
556 * Build an unordered list
557 *
558 * Build an unordered list from the given $data array
559 * Each item in the array has to have a 'level' property
560 * the item itself gets printed by the given $func user
561 * function. The second and optional function is used to
562 * print the <li> tag. Both user function need to accept
563 * a single item.
564 *
565 * @author Andreas Gohr <andi@splitbrain.org>
566 */
567function html_buildlist($data,$class,$func,$lifunc='html_li_default'){
568  $level = 0;
569  $opens = 0;
570  $ret   = '';
571
572  foreach ($data as $item){
573
574    if( $item['level'] > $level ){
575      //open new list
576      for($i=0; $i<($item['level'] - $level); $i++){
577        if ($i) $ret .= "<li class=\"clear\">\n";
578        $ret .= "\n<ul class=\"$class\">\n";
579      }
580    }elseif( $item['level'] < $level ){
581      //close last item
582      $ret .= "</li>\n";
583      for ($i=0; $i<($level - $item['level']); $i++){
584        //close higher lists
585        $ret .= "</ul>\n</li>\n";
586      }
587    }else{
588      //close last item
589      $ret .= "</li>\n";
590    }
591
592    //remember current level
593    $level = $item['level'];
594
595    //print item
596    $ret .= $lifunc($item); //user function
597    $ret .= '<span class="li">';
598    $ret .= $func($item); //user function
599    $ret .= '</span>';
600  }
601
602  //close remaining items and lists
603  for ($i=0; $i < $level; $i++){
604    $ret .= "</li></ul>\n";
605  }
606
607  return $ret;
608}
609
610/**
611 * display backlinks
612 *
613 * @author Andreas Gohr <andi@splitbrain.org>
614 */
615function html_backlinks(){
616  require_once(DOKU_INC.'inc/search.php');
617  global $ID;
618  global $conf;
619
620  if(preg_match('#^(.*):(.*)$#',$ID,$matches)){
621    $opts['ns']   = $matches[1];
622    $opts['name'] = $matches[2];
623  }else{
624    $opts['ns']   = '';
625    $opts['name'] = $ID;
626  }
627
628  print p_locale_xhtml('backlinks');
629
630  $data = array();
631  search($data,$conf['datadir'],'search_backlinks',$opts);
632  sort($data);
633
634  print '<ul class="idx">';
635  foreach($data as $row){
636    print '<li>';
637    print html_wikilink(':'.$row['id'],$row['id']);
638    print '</li>';
639  }
640  print '</ul>';
641}
642
643/**
644 * show diff
645 *
646 * @author Andreas Gohr <andi@splitbrain.org>
647 */
648function html_diff($text='',$intro=true){
649  require_once(DOKU_INC.'inc/DifferenceEngine.php');
650  global $ID;
651  global $REV;
652  global $lang;
653  global $conf;
654  if($text){
655    $df  = new Diff(split("\n",htmlspecialchars(rawWiki($ID,''))),
656                    split("\n",htmlspecialchars(cleanText($text))));
657    $left  = '<a class="wikilink1" href="'.wl($ID).'">'.
658              $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a>'.
659              $lang['current'];
660    $right = $lang['yours'];
661  }else{
662    if($REV){
663      $r = $REV;
664    }else{
665      //use last revision if none given
666      $revs = getRevisions($ID);
667      $r = $revs[0];
668    }
669
670    $df  = new Diff(split("\n",htmlspecialchars(rawWiki($ID,$r))),
671                    split("\n",htmlspecialchars(rawWiki($ID,''))));
672    $left  = '<a class="wikilink1" href="'.wl($ID,"rev=$r").'">'.
673              $ID.' '.date($conf['dformat'],$r).'</a>';
674    $right = '<a class="wikilink1" href="'.wl($ID).'">'.
675              $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a> '.
676              $lang['current'];
677  }
678  $tdf = new TableDiffFormatter();
679  if($intro) print p_locale_xhtml('diff');
680  ?>
681    <table class="diff" width="100%">
682      <tr>
683        <td colspan="2" width="50%" class="diff-header">
684          <?=$left?>
685        </td>
686        <td colspan="2" width="50%" class="diff-header">
687          <?=$right?>
688        </td>
689      </tr>
690      <?=$tdf->format($df)?>
691    </table>
692  <?
693}
694
695/**
696 * show warning on conflict detection
697 *
698 * @author Andreas Gohr <andi@splitbrain.org>
699 */
700function html_conflict($text,$summary){
701  global $ID;
702  global $lang;
703
704  print p_locale_xhtml('conflict');
705  ?>
706  <form name="editform" method="post" action="<?=script()?>" accept-charset="<?=$lang['encoding']?>">
707  <input type="hidden" name="id" value="<?=$ID?>" />
708  <input type="hidden" name="wikitext" value="<?=formText($text)?>" />
709  <input type="hidden" name="summary" value="<?=formText($summary)?>" />
710
711  <div align="center">
712    <input class="button" type="submit" name="do" value="<?=$lang['btn_save']?>" accesskey="s" title="[ALT+S]" />
713    <input class="button" type="submit" name="do" value="<?=$lang['btn_cancel']?>" />
714  </div>
715  </form>
716  <br /><br /><br /><br />
717  <?
718}
719
720/**
721 * Prints the global message array
722 *
723 * @author Andreas Gohr <andi@splitbrain.org>
724 */
725function html_msgarea(){
726  global $MSG;
727
728  if(!isset($MSG)) return;
729
730  foreach($MSG as $msg){
731    print '<div class="'.$msg['lvl'].'">';
732    print $msg['msg'];
733    print '</div>';
734  }
735}
736
737/**
738 * Prints the registration form
739 *
740 * @author Andreas Gohr <andi@splitbrain.org>
741 */
742function html_register(){
743  global $lang;
744  global $ID;
745
746  print p_locale_xhtml('register');
747?>
748  <div align="center">
749  <form name="register" method="post" action="<?=wl($ID)?>" accept-charset="<?=$lang['encoding']?>">
750  <input type="hidden" name="do" value="register" />
751  <input type="hidden" name="save" value="1" />
752  <fieldset>
753    <legend><?=$lang['register']?></legend>
754    <label>
755      <?=$lang['user']?>
756      <input type="text" name="login" class="edit" size="50" value="<?=formText($_POST['login'])?>" />
757    </label><br />
758    <label>
759      <?=$lang['fullname']?>
760      <input type="text" name="fullname" class="edit" size="50" value="<?=formText($_POST['fullname'])?>" />
761    </label><br />
762    <label>
763      <?=$lang['email']?>
764      <input type="text" name="email" class="edit" size="50" value="<?=formText($_POST['email'])?>" />
765    </label><br />
766    <input type="submit" class="button" value="<?=$lang['register']?>" />
767  </fieldset>
768  </form>
769  </div>
770<?
771}
772
773/**
774 * This displays the edit form (lots of logic included)
775 *
776 * @author Andreas Gohr <andi@splitbrain.org>
777 */
778function html_edit($text=null,$include='edit'){ //FIXME: include needed?
779  global $ID;
780  global $REV;
781  global $DATE;
782  global $RANGE;
783  global $PRE;
784  global $SUF;
785  global $INFO;
786  global $SUM;
787  global $lang;
788  global $conf;
789
790  //set summary default
791  if(!$SUM){
792    if($REV){
793      $SUM = $lang['restored'];
794    }elseif(!$INFO['exists']){
795      $SUM = $lang['created'];
796    }
797  }
798
799  //no text? Load it!
800  if(!isset($text)){
801    $pr = false; //no preview mode
802    if($RANGE){
803      list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
804    }else{
805      $text = rawWiki($ID,$REV);
806    }
807  }else{
808    $pr = true; //preview mode
809  }
810
811  $wr = $INFO['writable'];
812  if($wr){
813    if ($REV) print p_locale_xhtml('editrev');
814    print p_locale_xhtml($include);
815  }else{
816    print p_locale_xhtml('read');
817    $ro='readonly="readonly"';
818  }
819  if(!$DATE) $DATE = $INFO['lastmod'];
820?>
821  <form name="editform" method="post" action="<?=script()?>" accept-charset="<?=$lang['encoding']?>" onsubmit="return svchk()">
822  <input type="hidden" name="id"   value="<?=$ID?>" />
823  <input type="hidden" name="rev"  value="<?=$REV?>" />
824  <input type="hidden" name="date" value="<?=$DATE?>" />
825  <input type="hidden" name="prefix" value="<?=formText($PRE)?>" />
826  <input type="hidden" name="suffix" value="<?=formText($SUF)?>" />
827  <table style="width:99%">
828    <tr>
829      <td class="toolbar" colspan="3">
830        <?if($wr){?>
831        <script language="JavaScript" type="text/javascript">
832          <?/* sets changed to true when previewed */?>
833          textChanged = <? ($pr) ? print 'true' : print 'false' ?>;
834
835          formatButton('images/bold.png','<?=$lang['qb_bold']?>','**','**','<?=$lang['qb_bold']?>','b');
836          formatButton('images/italic.png','<?=$lang['qb_italic']?>',"\/\/","\/\/",'<?=$lang['qb_italic']?>','i');
837          formatButton('images/underline.png','<?=$lang['qb_underl']?>','__','__','<?=$lang['qb_underl']?>','u');
838          formatButton('images/code.png','<?=$lang['qb_code']?>','\'\'','\'\'','<?=$lang['qb_code']?>','c');
839
840          formatButton('images/fonth1.png','<?=$lang['qb_h1']?>','====== ',' ======\n','<?=$lang['qb_h1']?>','1');
841          formatButton('images/fonth2.png','<?=$lang['qb_h2']?>','===== ',' =====\n','<?=$lang['qb_h2']?>','2');
842          formatButton('images/fonth3.png','<?=$lang['qb_h3']?>','==== ',' ====\n','<?=$lang['qb_h3']?>','3');
843          formatButton('images/fonth4.png','<?=$lang['qb_h4']?>','=== ',' ===\n','<?=$lang['qb_h4']?>','4');
844          formatButton('images/fonth5.png','<?=$lang['qb_h5']?>','== ',' ==\n','<?=$lang['qb_h5']?>','5');
845
846          formatButton('images/link.png','<?=$lang['qb_link']?>','[[',']]','<?=$lang['qb_link']?>','l');
847          formatButton('images/extlink.png','<?=$lang['qb_extlink']?>','[[',']]','http://www.example.com|<?=$lang['qb_extlink']?>');
848
849          formatButton('images/list.png','<?=$lang['qb_ol']?>','  - ','\n','<?=$lang['qb_ol']?>');
850          formatButton('images/list_ul.png','<?=$lang['qb_ul']?>','  * ','\n','<?=$lang['qb_ul']?>');
851
852          insertButton('images/rule.png','<?=$lang['qb_hr']?>','----\n');
853          mediaButton('images/image.png','<?=$lang['qb_media']?>','m','<?=$INFO['namespace']?>');
854
855          <?
856          if($conf['useacl'] && $_SERVER['REMOTE_USER']){
857            echo "insertButton('images/sig.png','".$lang['qb_sig']."','".html_signature()."','y');";
858          }
859          ?>
860        </script>
861        <?}?>
862      </td>
863    </tr>
864    <tr>
865      <td colspan="3">
866        <textarea name="wikitext" id="wikitext" <?=$ro?> cols="80" rows="10" class="edit" onchange="textChanged = true;" onkeyup="summaryCheck();" tabindex="1"><?="\n".formText($text)?></textarea>
867      </td>
868    </tr>
869    <tr>
870      <td>
871      <?if($wr){?>
872        <input class="button" type="submit" name="do" value="<?=$lang['btn_save']?>" accesskey="s" title="[ALT+S]" onclick="textChanged=false" onkeypress="textChanged=false" tabindex="3" />
873        <input class="button" type="submit" name="do" value="<?=$lang['btn_preview']?>" accesskey="p" title="[ALT+P]" onclick="textChanged=false" onkeypress="textChanged=false" tabindex="4" />
874        <input class="button" type="submit" name="do" value="<?=$lang['btn_cancel']?>" tabindex="5" />
875      <?}?>
876      </td>
877      <td>
878      <?if($wr){?>
879        <?=$lang['summary']?>:
880        <input type="text" class="edit" name="summary" id="summary" size="50" onkeyup="summaryCheck();" value="<?=formText($SUM)?>" tabindex="2" />
881      <?}?>
882      </td>
883      <td align="right">
884        <script type="text/javascript">
885          showSizeCtl();
886          <?if($wr){?>
887            init_locktimer(<?=$conf['locktime']-60?>,'<?=$lang['willexpire']?>');
888            document.editform.wikitext.focus();
889          <?}?>
890        </script>
891      </td>
892    </tr>
893  </table>
894  </form>
895<?
896}
897
898/**
899 * prepares the signature string as configured in the config
900 *
901 * @author Andreas Gohr <andi@splitbrain.org>
902 */
903function html_signature(){
904  global $conf;
905  global $INFO;
906
907  $sig = $conf['signature'];
908  $sig = strftime($sig);
909  $sig = str_replace('@USER@',$_SERVER['REMOTE_USER'],$sig);
910  $sig = str_replace('@NAME@',$INFO['userinfo']['name'],$sig);
911  $sig = str_replace('@MAIL@',$INFO['userinfo']['mail'],$sig);
912  $sig = str_replace('@DATE@',date($conf['dformat']),$sig);
913  return $sig;
914}
915
916/**
917 * prints some debug info
918 *
919 * @author Andreas Gohr <andi@splitbrain.org>
920 */
921function html_debug(){
922  global $conf;
923  global $lang;
924  //remove sensitive data
925  $cnf = $conf;
926  $cnf['auth']='***';
927  $cnf['notify']='***';
928  $cnf['ftp']='***';
929
930  print '<html><body>';
931
932  print '<p>When reporting bugs please send all the following ';
933  print 'output as a mail to andi@splitbrain.org ';
934  print 'The best way to do this is to save this page in your browser</p>';
935
936  print '<b>$_SERVER:</b><pre>';
937  print_r($_SERVER);
938  print '</pre>';
939
940  print '<b>$conf:</b><pre>';
941  print_r($cnf);
942  print '</pre>';
943
944  print '<b>DOKU_BASE:</b><pre>';
945  print DOKU_BASE;
946  print '</pre>';
947
948  print '<b>abs DOKU_BASE:</b><pre>';
949  print DOKU_URL;
950  print '</pre>';
951
952  print '<b>rel DOKU_BASE:</b><pre>';
953  print dirname($_SERVER['PHP_SELF']).'/';
954  print '</pre>';
955
956  print '<b>PHP Version:</b><pre>';
957  print phpversion();
958  print '</pre>';
959
960  print '<b>locale:</b><pre>';
961  print setlocale(LC_ALL,0);
962  print '</pre>';
963
964  print '<b>encoding:</b><pre>';
965  print $lang['encoding'];
966  print '</pre>';
967
968  print '<b>Environment:</b><pre>';
969  print_r($_ENV);
970  print '</pre>';
971
972  print '<b>PHP settings:</b><pre>';
973  $inis = ini_get_all();
974  print_r($inis);
975  print '</pre>';
976
977  print '</body></html>';
978}
979
980/**
981 * Print the admin overview page
982 *
983 * @author  Andreas Gohr <andi@splitbrain.org>
984 */
985function html_admin(){
986  global $ID;
987  global $lang;
988
989  print p_locale_xhtml('admin');
990
991  ptln('<ul class="admin">');
992
993  // currently ACL only - more to come
994  ptln('<li><a href="'.wl($ID,'do=admin&page=acl').'">'.$lang['admin_acl'].'</a></li>');
995
996  ptln('</ul>');
997}
998
999
1000//Setup VIM: ex: et ts=2 enc=utf-8 :
1001