xref: /dokuwiki/inc/html.php (revision cddd152cd07fff794aa5023d9cd6e61e26ab433c)
1ed7b5f09Sandi<?php
215fae107Sandi/**
315fae107Sandi * HTML output functions
415fae107Sandi *
515fae107Sandi * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
615fae107Sandi * @author     Andreas Gohr <andi@splitbrain.org>
715fae107Sandi */
815fae107Sandi
900976812SAndreas Gohrif(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
10e226efe1SAndreas Gohrif(!defined('NL')) define('NL',"\n");
116bbae538Sandirequire_once(DOKU_INC.'inc/parserutils.php');
12fdb8d77bSTom N Harrisrequire_once(DOKU_INC.'inc/form.php');
136bbae538Sandi
14f3f0262cSandi/**
15f3f0262cSandi * Convenience function to quickly build a wikilink
1615fae107Sandi *
1715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
18f3f0262cSandi */
1930f1737dSandifunction html_wikilink($id,$name=NULL,$search=''){
20723d78dbSandi  static $xhtml_renderer = NULL;
21723d78dbSandi  if(is_null($xhtml_renderer)){
22fdf3dcb9SMatthias Urlichs    require_once(DOKU_INC.'inc/parser/xhtml.php');
23723d78dbSandi    $xhtml_renderer = new Doku_Renderer_xhtml();
24f3f0262cSandi  }
25f3f0262cSandi
26cffcc403Sandi  return $xhtml_renderer->internallink($id,$name,$search,true);
27f3f0262cSandi}
28f3f0262cSandi
29f3f0262cSandi/**
30c19fe9c0Sandi * Helps building long attribute lists
31c19fe9c0Sandi *
32c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org>
33c19fe9c0Sandi */
34c19fe9c0Sandifunction html_attbuild($attributes){
35c19fe9c0Sandi  $ret = '';
36c19fe9c0Sandi  foreach ( $attributes as $key => $value ) {
37c19fe9c0Sandi    $ret .= $key.'="'.formtext($value).'" ';
38c19fe9c0Sandi  }
39c19fe9c0Sandi  return trim($ret);
40c19fe9c0Sandi}
41c19fe9c0Sandi
42c19fe9c0Sandi/**
43f3f0262cSandi * The loginform
4415fae107Sandi *
4515fae107Sandi * @author   Andreas Gohr <andi@splitbrain.org>
46f3f0262cSandi */
47f3f0262cSandifunction html_login(){
48f3f0262cSandi  global $lang;
49f3f0262cSandi  global $conf;
50f3f0262cSandi  global $ID;
51cd52f92dSchris  global $auth;
52f3f0262cSandi
53c112d578Sandi  print p_locale_xhtml('login');
54fdb8d77bSTom N Harris  print '<div class="centeralign">'.NL;
55fdb8d77bSTom N Harris  $form = new Doku_Form('dw__login');
56fdb8d77bSTom N Harris  $form->startFieldset($lang['btn_login']);
57fdb8d77bSTom N Harris  $form->addHidden('id', $ID);
58fdb8d77bSTom N Harris  $form->addHidden('do', 'login');
59aab557e9SGina Haeussge  $form->addElement(form_makeTextField('u', ((!$_REQUEST['http_credentials']) ? $_REQUEST['u'] : ''), $lang['user'], 'focus__this', 'block'));
60fdb8d77bSTom N Harris  $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block'));
6117f89d7eSMichael Klier  if($conf['rememberme']) {
62fdb8d77bSTom N Harris      $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple'));
6317f89d7eSMichael Klier  }
64fdb8d77bSTom N Harris  $form->addElement(form_makeButton('submit', '', $lang['btn_login']));
65fdb8d77bSTom N Harris  $form->endFieldset();
66fdb8d77bSTom N Harris  html_form('login', $form);
675b62573aSAndreas Gohr
686957b2eaSAndreas Gohr  if($auth && $auth->canDo('addUser') && actionOK('register')){
69f3f0262cSandi    print '<p>';
70f3f0262cSandi    print $lang['reghere'];
711d5856cfSAndreas Gohr    print ': <a href="'.wl($ID,'do=register').'" rel="nofollow" class="wikilink1">'.$lang['register'].'</a>';
72f3f0262cSandi    print '</p>';
73f3f0262cSandi  }
748b06d178Schris
756957b2eaSAndreas Gohr  if ($auth && $auth->canDo('modPass') && actionOK('resendpwd')) {
768b06d178Schris    print '<p>';
778b06d178Schris    print $lang['pwdforget'];
781d5856cfSAndreas Gohr    print ': <a href="'.wl($ID,'do=resendpwd').'" rel="nofollow" class="wikilink1">'.$lang['btn_resendpwd'].'</a>';
798b06d178Schris    print '</p>';
808b06d178Schris  }
81fdb8d77bSTom N Harris  print '</div>'.NL;
82f3f0262cSandi}
83f3f0262cSandi
84f3f0262cSandi/**
8515fae107Sandi * prints a section editing button
8635dae8b0SBen Coburn * used as a callback in html_secedit
8715fae107Sandi *
8815fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
8915fae107Sandi */
9035dae8b0SBen Coburnfunction html_secedit_button($matches){
91f3f0262cSandi  global $ID;
92041d7a86SBen Coburn  global $INFO;
93041d7a86SBen Coburn
94041d7a86SBen Coburn  $section = $matches[2];
95041d7a86SBen Coburn  $name = $matches[1];
96041d7a86SBen Coburn
97f3f0262cSandi  $secedit  = '';
98f3f0262cSandi  $secedit .= '<div class="secedit">';
99f3f0262cSandi  $secedit .= html_btn('secedit',$ID,'',
100f3f0262cSandi                        array('do'      => 'edit',
101306b2c85SDenis Simakov                              'lines'   => "$section",
102306b2c85SDenis Simakov                              'rev' => $INFO['lastmod']),
10335dae8b0SBen Coburn                              'post', $name);
104f3f0262cSandi  $secedit .= '</div>';
105f3f0262cSandi  return $secedit;
106f3f0262cSandi}
107f3f0262cSandi
10815fae107Sandi/**
10915fae107Sandi * inserts section edit buttons if wanted or removes the markers
11015fae107Sandi *
11115fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
11215fae107Sandi */
113f3f0262cSandifunction html_secedit($text,$show=true){
114f3f0262cSandi  global $INFO;
11535dae8b0SBen Coburn
116c112d578Sandi  if($INFO['writable'] && $show && !$INFO['rev']){
11735dae8b0SBen Coburn    $text = preg_replace_callback('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#',
11835dae8b0SBen Coburn                         'html_secedit_button', $text);
119f3f0262cSandi  }else{
12035dae8b0SBen Coburn    $text = preg_replace('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#','',$text);
121f3f0262cSandi  }
12235dae8b0SBen Coburn
123f3f0262cSandi  return $text;
124f3f0262cSandi}
125f3f0262cSandi
126f3f0262cSandi/**
127d6c9c552Smatthiasgrimm * Just the back to top button (in its own form)
1286b13307fSandi *
1296b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
1306b13307fSandi */
1316b13307fSandifunction html_topbtn(){
1326b13307fSandi  global $lang;
1336b13307fSandi
1346b13307fSandi  $ret  = '';
13511ea018fSAndreas Gohr  $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>';
136df7b6005Sandi
1376b13307fSandi  return $ret;
1386b13307fSandi}
1396b13307fSandi
1406b13307fSandi/**
141d67ca2c0Smatthiasgrimm * Displays a button (using its own form)
14235dae8b0SBen Coburn * If tooltip exists, the access key tooltip is replaced.
14315fae107Sandi *
14415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
145f3f0262cSandi */
14635dae8b0SBen Coburnfunction html_btn($name,$id,$akey,$params,$method='get',$tooltip=''){
147f3f0262cSandi  global $conf;
148f3f0262cSandi  global $lang;
149f3f0262cSandi
150f3f0262cSandi  $label = $lang['btn_'.$name];
151f3f0262cSandi
152f3f0262cSandi  $ret = '';
15335dae8b0SBen Coburn  $tip = '';
154f3f0262cSandi
15549c713a3Sandi  //filter id (without urlencoding)
15649c713a3Sandi  $id = idfilter($id,false);
157f3f0262cSandi
158f3f0262cSandi  //make nice URLs even for buttons
1596c7843b5Sandi  if($conf['userewrite'] == 2){
1606c7843b5Sandi    $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
1616c7843b5Sandi  }elseif($conf['userewrite']){
1626c7843b5Sandi    $script = DOKU_BASE.$id;
1636c7843b5Sandi  }else{
1648b00ebcfSandi    $script = DOKU_BASE.DOKU_SCRIPT;
165f3f0262cSandi    $params['id'] = $id;
166f3f0262cSandi  }
167f3f0262cSandi
168b278f2deSAndreas Gohr  $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
169f3f0262cSandi
17006a4bf8fSAndreas Gohr  if(is_array($params)){
171f3f0262cSandi    reset($params);
172f3f0262cSandi    while (list($key, $val) = each($params)) {
173f3f0262cSandi      $ret .= '<input type="hidden" name="'.$key.'" ';
174f3f0262cSandi      $ret .= 'value="'.htmlspecialchars($val).'" />';
175f3f0262cSandi    }
17606a4bf8fSAndreas Gohr  }
177f3f0262cSandi
17835dae8b0SBen Coburn  if ($tooltip!='') {
17935dae8b0SBen Coburn      $tip = htmlspecialchars($tooltip);
18011ea018fSAndreas Gohr  }else{
18111ea018fSAndreas Gohr      $tip = htmlspecialchars($label);
18211ea018fSAndreas Gohr  }
18311ea018fSAndreas Gohr
18411ea018fSAndreas Gohr  $ret .= '<input type="submit" value="'.htmlspecialchars($label).'" class="button" ';
18511ea018fSAndreas Gohr  if($akey){
18607493d05SAnika Henke    $tip .= ' ['.strtoupper($akey).']';
18707493d05SAnika Henke    $ret .= 'accesskey="'.htmlspecialchars($label).' '.$akey.'" ';
18835dae8b0SBen Coburn  }
18935dae8b0SBen Coburn  $ret .= 'title="'.$tip.'" ';
190f3f0262cSandi  $ret .= '/>';
1914beabca9SAnika Henke  $ret .= '</div></form>';
192f3f0262cSandi
193f3f0262cSandi  return $ret;
194f3f0262cSandi}
195f3f0262cSandi
196f3f0262cSandi/**
19715fae107Sandi * show a wiki page
19815fae107Sandi *
19915fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
20015fae107Sandi */
2016bbae538Sandifunction html_show($txt=''){
202f3f0262cSandi  global $ID;
203f3f0262cSandi  global $REV;
204f3f0262cSandi  global $HIGH;
205b8595a66SAndreas Gohr  global $INFO;
206f3f0262cSandi  //disable section editing for old revisions or in preview
2075400331dSandi  if($txt || $REV){
2086bbae538Sandi    $secedit = false;
2096bbae538Sandi  }else{
2106bbae538Sandi    $secedit = true;
211f3f0262cSandi  }
212f3f0262cSandi
2136bbae538Sandi  if ($txt){
214f3f0262cSandi    //PreviewHeader
215b8595a66SAndreas Gohr    echo '<br id="scroll__here" />';
216b8595a66SAndreas Gohr    echo p_locale_xhtml('preview');
217b8595a66SAndreas Gohr    echo '<div class="preview">';
218b8595a66SAndreas Gohr    $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
219b8595a66SAndreas Gohr    if($INFO['prependTOC']) $html = tpl_toc(true).$html;
220b8595a66SAndreas Gohr    echo $html;
221b8595a66SAndreas Gohr    echo '<div class="clearer"></div>';
222b8595a66SAndreas Gohr    echo '</div>';
2236bbae538Sandi
224f3f0262cSandi  }else{
225c112d578Sandi    if ($REV) print p_locale_xhtml('showrev');
226c112d578Sandi    $html = p_wiki_xhtml($ID,$REV,true);
2276bbae538Sandi    $html = html_secedit($html,$secedit);
228b8595a66SAndreas Gohr    if($INFO['prependTOC']) $html = tpl_toc(true).$html;
229b8595a66SAndreas Gohr    $html = html_hilight($html,$HIGH);
230b8595a66SAndreas Gohr    echo $html;
231f3f0262cSandi  }
232f3f0262cSandi}
233f3f0262cSandi
234f3f0262cSandi/**
235ee4c4a1bSAndreas Gohr * ask the user about how to handle an exisiting draft
236ee4c4a1bSAndreas Gohr *
237ee4c4a1bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
238ee4c4a1bSAndreas Gohr */
239ee4c4a1bSAndreas Gohrfunction html_draft(){
240ee4c4a1bSAndreas Gohr  global $INFO;
241ee4c4a1bSAndreas Gohr  global $ID;
242ee4c4a1bSAndreas Gohr  global $lang;
243ee4c4a1bSAndreas Gohr  global $conf;
244ee4c4a1bSAndreas Gohr  $draft = unserialize(io_readFile($INFO['draft'],false));
245ee4c4a1bSAndreas Gohr  $text  = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
246ee4c4a1bSAndreas Gohr
247fdb8d77bSTom N Harris  print p_locale_xhtml('draft');
248fdb8d77bSTom N Harris  $form = new Doku_Form('dw__editform');
249fdb8d77bSTom N Harris  $form->addHidden('id', $ID);
250fdb8d77bSTom N Harris  $form->addHidden('date', $draft['date']);
251fdb8d77bSTom N Harris  $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly')));
252fdb8d77bSTom N Harris  $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
253e656dcd4SAndreas Gohr  $form->addElement($lang['draftdate'].' '. strftime($conf['dformat'],filemtime($INFO['draft'])));
254fdb8d77bSTom N Harris  $form->addElement(form_makeCloseTag('div'));
255fdb8d77bSTom N Harris  $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
256fdb8d77bSTom N Harris  $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
257fdb8d77bSTom N Harris  $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3')));
258fdb8d77bSTom N Harris  html_form('draft', $form);
259ee4c4a1bSAndreas Gohr}
260ee4c4a1bSAndreas Gohr
261ee4c4a1bSAndreas Gohr/**
262f3f0262cSandi * Highlights searchqueries in HTML code
26315fae107Sandi *
26415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
2657209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
266f3f0262cSandi */
267546d3a99SAndreas Gohrfunction html_hilight($html,$phrases){
268546d3a99SAndreas Gohr  $regex = join('|',array_map('preg_quote_cb',array_filter((array) $phrases)));
26960c15d7dSAndreas Gohr
27060c15d7dSAndreas Gohr  if ($regex === '') return $html;
2711db218e9SAndreas Gohr  $html = preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
272f3f0262cSandi  return $html;
273f3f0262cSandi}
274f3f0262cSandi
275f3f0262cSandi/**
2767209be23SAndreas Gohr * Callback used by html_hilight()
2777209be23SAndreas Gohr *
2787209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
2797209be23SAndreas Gohr */
2807209be23SAndreas Gohrfunction html_hilight_callback($m) {
2817209be23SAndreas Gohr  $hlight = unslash($m[0]);
2827209be23SAndreas Gohr  if ( !isset($m[2])) {
283688774a0SAnika Henke    $hlight = '<span class="search_hit">'.$hlight.'</span>';
2847209be23SAndreas Gohr  }
2857209be23SAndreas Gohr  return $hlight;
2867209be23SAndreas Gohr}
2877209be23SAndreas Gohr
2887209be23SAndreas Gohr/**
28915fae107Sandi * Run a search and display the result
29015fae107Sandi *
29115fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
292f3f0262cSandi */
293f3f0262cSandifunction html_search(){
294ed7b5f09Sandi  require_once(DOKU_INC.'inc/search.php');
295506fa893SAndreas Gohr  require_once(DOKU_INC.'inc/fulltext.php');
296f3f0262cSandi  global $conf;
297f3f0262cSandi  global $QUERY;
298f3f0262cSandi  global $ID;
299f3f0262cSandi  global $lang;
300f3f0262cSandi
301c112d578Sandi  print p_locale_xhtml('searchpage');
302f3f0262cSandi  flush();
303f3f0262cSandi
304d0ab54f6SMichael Klier chi@chimeric.de  //check if search is restricted to namespace
305d0ab54f6SMichael Klier chi@chimeric.de  if(preg_match('/([^@]*)@([^@]*)/',$QUERY,$match)) {
306d0ab54f6SMichael Klier chi@chimeric.de      $id = cleanID($match[1]);
307d0ab54f6SMichael Klier chi@chimeric.de      if(empty($id)) {
308d0ab54f6SMichael Klier chi@chimeric.de        print '<div class="nothing">'.$lang['nothingfound'].'</div>';
309d0ab54f6SMichael Klier chi@chimeric.de        flush();
310d0ab54f6SMichael Klier chi@chimeric.de        return;
311d0ab54f6SMichael Klier chi@chimeric.de      }
312d0ab54f6SMichael Klier chi@chimeric.de  } else {
313d0ab54f6SMichael Klier chi@chimeric.de      $id = cleanID($QUERY);
314d0ab54f6SMichael Klier chi@chimeric.de  }
315d0ab54f6SMichael Klier chi@chimeric.de
3164d9ff3d5Sandi  //show progressbar
317e226efe1SAndreas Gohr  print '<div class="centeralign" id="dw__loading">'.NL;
318e226efe1SAndreas Gohr  print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
319e226efe1SAndreas Gohr  print 'showLoadBar();'.NL;
320e226efe1SAndreas Gohr  print '//--><!]]></script>'.NL;
321e226efe1SAndreas Gohr  print '<br /></div>'.NL;
3229edac8a8SAndreas Gohr  flush();
3234d9ff3d5Sandi
324f3f0262cSandi  //do quick pagesearch
325f3f0262cSandi  $data = array();
326d0ab54f6SMichael Klier chi@chimeric.de
327d0ab54f6SMichael Klier chi@chimeric.de  $data = ft_pageLookup($id);
328f3f0262cSandi  if(count($data)){
329f3f0262cSandi    print '<div class="search_quickresult">';
330746855cfSBen Coburn    print '<h3>'.$lang['quickhits'].':</h3>';
3314f732f0eSAnika Henke    print '<ul class="search_quickhits">';
332140c93f3SAnika Henke    foreach($data as $id){
3334f732f0eSAnika Henke      print '<li> ';
334bd2f6c2fSAndreas Gohr      $ns = getNS($id);
335bd2f6c2fSAndreas Gohr      if($ns){
336bd2f6c2fSAndreas Gohr        $name = shorten(noNS($id), ' ('.$ns.')',30);
337bd2f6c2fSAndreas Gohr      }else{
338bd2f6c2fSAndreas Gohr        $name = $id;
339bd2f6c2fSAndreas Gohr      }
340bd2f6c2fSAndreas Gohr      print html_wikilink(':'.$id,$name);
3414f732f0eSAnika Henke      print '</li> ';
342f3f0262cSandi    }
343140c93f3SAnika Henke    print '</ul> ';
344f3f0262cSandi    //clear float (see http://www.complexspiral.com/publications/containing-floats/)
345f3f0262cSandi    print '<div class="clearer">&nbsp;</div>';
346f3f0262cSandi    print '</div>';
347f3f0262cSandi  }
348f3f0262cSandi  flush();
349f3f0262cSandi
350f3f0262cSandi  //do fulltext search
35160c15d7dSAndreas Gohr  $data = ft_pageSearch($QUERY,$regex);
352f3f0262cSandi  if(count($data)){
353506fa893SAndreas Gohr    $num = 1;
354506fa893SAndreas Gohr    foreach($data as $id => $cnt){
355f3f0262cSandi      print '<div class="search_result">';
35660c15d7dSAndreas Gohr      print html_wikilink(':'.$id,$conf['useheading']?NULL:$id,$regex);
357506fa893SAndreas Gohr      print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />';
358506fa893SAndreas Gohr      if($num < 15){ // create snippets for the first number of matches only #FIXME add to conf ?
35960c15d7dSAndreas Gohr        print '<div class="search_snippet">'.ft_snippet($id,$regex).'</div>';
360506fa893SAndreas Gohr      }
361f3f0262cSandi      print '</div>';
362506fa893SAndreas Gohr      flush();
363506fa893SAndreas Gohr      $num++;
364f3f0262cSandi    }
365f3f0262cSandi  }else{
366820fa24bSandi    print '<div class="nothing">'.$lang['nothingfound'].'</div>';
367f3f0262cSandi  }
3684d9ff3d5Sandi
3694d9ff3d5Sandi  //hide progressbar
370e226efe1SAndreas Gohr  print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
371e226efe1SAndreas Gohr  print 'hideLoadBar("dw__loading");'.NL;
372e226efe1SAndreas Gohr  print '//--><!]]></script>'.NL;
3739edac8a8SAndreas Gohr  flush();
374f3f0262cSandi}
375f3f0262cSandi
37615fae107Sandi/**
37715fae107Sandi * Display error on locked pages
37815fae107Sandi *
37915fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
38015fae107Sandi */
381ee20e7d1Sandifunction html_locked(){
382f3f0262cSandi  global $ID;
383f3f0262cSandi  global $conf;
384f3f0262cSandi  global $lang;
38588f522e9Sandi  global $INFO;
386f3f0262cSandi
387c9b4bd1eSBen Coburn  $locktime = filemtime(wikiLockFN($ID));
388e656dcd4SAndreas Gohr  $expire = @strftime($conf['dformat'], $locktime + $conf['locktime'] );
389f3f0262cSandi  $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
390f3f0262cSandi
391c112d578Sandi  print p_locale_xhtml('locked');
392f3f0262cSandi  print '<ul>';
393f7c7911aSGina Haeussge  print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.$INFO['locked'].'</div></li>';
3940c6b58a8SAndreas Gohr  print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>';
395f3f0262cSandi  print '</ul>';
396f3f0262cSandi}
397f3f0262cSandi
39815fae107Sandi/**
39915fae107Sandi * list old revisions
40015fae107Sandi *
40115fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
40271726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
40315fae107Sandi */
40471726d78SBen Coburnfunction html_revisions($first=0){
405f3f0262cSandi  global $ID;
406f3f0262cSandi  global $INFO;
407f3f0262cSandi  global $conf;
408f3f0262cSandi  global $lang;
40971726d78SBen Coburn  /* we need to get one additionally log entry to be able to
41071726d78SBen Coburn   * decide if this is the last page or is there another one.
41171726d78SBen Coburn   * see html_recent()
41271726d78SBen Coburn   */
41371726d78SBen Coburn  $revisions = getRevisions($ID, $first, $conf['recent']+1);
41471726d78SBen Coburn  if(count($revisions)==0 && $first!=0){
41571726d78SBen Coburn    $first=0;
41671726d78SBen Coburn    $revisions = getRevisions($ID, $first, $conf['recent']+1);;
41771726d78SBen Coburn  }
41871726d78SBen Coburn  $hasNext = false;
41971726d78SBen Coburn  if (count($revisions)>$conf['recent']) {
42071726d78SBen Coburn    $hasNext = true;
42171726d78SBen Coburn    array_pop($revisions); // remove extra log entry
42271726d78SBen Coburn  }
42371726d78SBen Coburn
424e656dcd4SAndreas Gohr  $date = @strftime($conf['dformat'],$INFO['lastmod']);
425f3f0262cSandi
426c112d578Sandi  print p_locale_xhtml('revisions');
42777707b04SAndreas Gohr  print '<form action="'.wl($ID).'" method="post" id="page__revisions">';
428f3f0262cSandi  print '<ul>';
42971726d78SBen Coburn  if($INFO['exists'] && $first==0){
430ebf1501fSBen Coburn    print (isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>';
4310c6b58a8SAndreas Gohr    print '<div class="li">';
43277707b04SAndreas Gohr    print '<input type="checkbox" name="rev2[]" value="current" /> ';
433f9b2fe70Sandi
434f9b2fe70Sandi    print $date;
435f9b2fe70Sandi
43602e51121SAnika Henke    print ' <img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" /> ';
437cffcc403Sandi
438f9b2fe70Sandi    print '<a class="wikilink1" href="'.wl($ID).'">'.$ID.'</a> ';
439652610a2Sandi
44041396b71SAndreas Gohr    print ' &ndash; ';
441ebbef3b1SAndreas Gohr    print htmlspecialchars($INFO['sum']);
44288f522e9Sandi    print ' <span class="user">';
443dc58b6f4SAndy Webber    print (empty($INFO['editor']))?('('.$lang['external_edit'].')'):editorinfo($INFO['editor']);
44488f522e9Sandi    print '</span> ';
445652610a2Sandi
446652610a2Sandi    print '('.$lang['current'].')';
4470c6b58a8SAndreas Gohr    print '</div>';
448652610a2Sandi    print '</li>';
449f3f0262cSandi  }
450f3f0262cSandi
451f3f0262cSandi  foreach($revisions as $rev){
452e656dcd4SAndreas Gohr    $date   = strftime($conf['dformat'],$rev);
453fb53bfe2SBen Coburn    $info   = getRevisionInfo($ID,$rev,true);
454103c256aSChris Smith    $exists = page_exists($ID,$rev);
455652610a2Sandi
456ebf1501fSBen Coburn    print ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>';
4570c6b58a8SAndreas Gohr    print '<div class="li">';
45877707b04SAndreas Gohr    if($exists){
45977707b04SAndreas Gohr      print '<input type="checkbox" name="rev2[]" value="'.$rev.'" /> ';
46077707b04SAndreas Gohr    }else{
46177707b04SAndreas Gohr      print '<img src="'.DOKU_BASE.'lib/images/blank.gif" width="14" height="11" alt="" /> ';
46277707b04SAndreas Gohr    }
463f9b2fe70Sandi    print $date;
464f9b2fe70Sandi
46577707b04SAndreas Gohr    if($exists){
466cffcc403Sandi      print ' <a href="'.wl($ID,"rev=$rev,do=diff").'">';
467d94f4568SAndreas Gohr      $p = array();
468d94f4568SAndreas Gohr      $p['src']    = DOKU_BASE.'lib/images/diff.png';
469d94f4568SAndreas Gohr      $p['width']  = 15;
470d94f4568SAndreas Gohr      $p['height'] = 11;
471d94f4568SAndreas Gohr      $p['title']  = $lang['diff'];
472d94f4568SAndreas Gohr      $p['alt']    = $lang['diff'];
473d94f4568SAndreas Gohr      $att = buildAttributes($p);
474d94f4568SAndreas Gohr      print "<img $att />";
475cffcc403Sandi      print '</a> ';
476cffcc403Sandi
477f9b2fe70Sandi      print '<a class="wikilink1" href="'.wl($ID,"rev=$rev").'">'.$ID.'</a>';
47841396b71SAndreas Gohr    }else{
47941396b71SAndreas Gohr      print ' <img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" /> ';
48041396b71SAndreas Gohr      print $ID;
48141396b71SAndreas Gohr    }
482f9b2fe70Sandi
48341396b71SAndreas Gohr    print ' &ndash; ';
484f243a77fSandi    print htmlspecialchars($info['sum']);
48588f522e9Sandi    print ' <span class="user">';
48688f522e9Sandi    if($info['user']){
487dc58b6f4SAndy Webber      print editorinfo($info['user']);
48888f522e9Sandi    }else{
489652610a2Sandi      print $info['ip'];
49088f522e9Sandi    }
49188f522e9Sandi    print '</span>';
492652610a2Sandi
4930c6b58a8SAndreas Gohr    print '</div>';
494f3f0262cSandi    print '</li>';
495f3f0262cSandi  }
496f3f0262cSandi  print '</ul>';
49777707b04SAndreas Gohr  print '<input name="do[diff]" type="submit" value="'.$lang['diff2'].'" class="button" />';
49877707b04SAndreas Gohr  print '</form>';
49971726d78SBen Coburn
50071726d78SBen Coburn  print '<div class="pagenav">';
50171726d78SBen Coburn  $last = $first + $conf['recent'];
50271726d78SBen Coburn  if ($first > 0) {
50371726d78SBen Coburn    $first -= $conf['recent'];
50471726d78SBen Coburn    if ($first < 0) $first = 0;
50571726d78SBen Coburn    print '<div class="pagenav-prev">';
506eeb83e57SBen Coburn    print html_btn('newer',$ID,"p",array('do' => 'revisions', 'first' => $first));
50771726d78SBen Coburn    print '</div>';
50871726d78SBen Coburn  }
50971726d78SBen Coburn  if ($hasNext) {
51071726d78SBen Coburn    print '<div class="pagenav-next">';
511eeb83e57SBen Coburn    print html_btn('older',$ID,"n",array('do' => 'revisions', 'first' => $last));
51271726d78SBen Coburn    print '</div>';
51371726d78SBen Coburn  }
51471726d78SBen Coburn  print '</div>';
51571726d78SBen Coburn
516f3f0262cSandi}
517f3f0262cSandi
51815fae107Sandi/**
51915fae107Sandi * display recent changes
52015fae107Sandi *
52115fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
5225749f1ceSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
52371726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
52415fae107Sandi */
525a39955b0Smatthiasgrimmfunction html_recent($first=0){
526f3f0262cSandi  global $conf;
527cffcc403Sandi  global $lang;
528dbb00abcSEsther Brunner  global $ID;
5295749f1ceSmatthiasgrimm  /* we need to get one additionally log entry to be able to
5305749f1ceSmatthiasgrimm   * decide if this is the last page or is there another one.
5315749f1ceSmatthiasgrimm   * This is the cheapest solution to get this information.
5325749f1ceSmatthiasgrimm   */
533b6912aeaSAndreas Gohr  $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
5345749f1ceSmatthiasgrimm  if(count($recents) == 0 && $first != 0){
5355749f1ceSmatthiasgrimm    $first=0;
53671726d78SBen Coburn    $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
5375749f1ceSmatthiasgrimm  }
53871726d78SBen Coburn  $hasNext = false;
53971726d78SBen Coburn  if (count($recents)>$conf['recent']) {
54071726d78SBen Coburn    $hasNext = true;
54171726d78SBen Coburn    array_pop($recents); // remove extra log entry
54271726d78SBen Coburn  }
543f3f0262cSandi
544c112d578Sandi  print p_locale_xhtml('recent');
545e83cef14SGina Haeussge
546e83cef14SGina Haeussge  if (getNS($ID) != '')
5479e561443SAndreas Gohr    print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>';
548e83cef14SGina Haeussge
549abdcc39fSmichael  $form = new Doku_Form('dw__recent', script(), 'get');
550abdcc39fSmichael  $form->addHidden('sectok', null);
551abdcc39fSmichael  $form->addHidden('do', 'recent');
552abdcc39fSmichael  $form->addHidden('id', $ID);
553abdcc39fSmichael  $form->addElement(form_makeOpenTag('ul'));
554a39955b0Smatthiasgrimm
555d437bcc4SAndreas Gohr  foreach($recents as $recent){
556e656dcd4SAndreas Gohr    $date = strftime($conf['dformat'],$recent['date']);
557abdcc39fSmichael    if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
558abdcc39fSmichael      $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
559abdcc39fSmichael    else
560abdcc39fSmichael      $form->addElement(form_makeOpenTag('li'));
561cffcc403Sandi
562abdcc39fSmichael    $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
563f9b2fe70Sandi
564abdcc39fSmichael    $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
565abdcc39fSmichael    $form->addElement($date);
566abdcc39fSmichael    $form->addElement(form_makeCloseTag('span'));
567cffcc403Sandi
568*cddd152cSmichael    $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => wl($recent['id'],"do=diff", false, '&'))));
569abdcc39fSmichael    $form->addElement(form_makeTag('img', array(
570abdcc39fSmichael      'src'   => DOKU_BASE.'lib/images/diff.png',
571abdcc39fSmichael      'width' => 15,
572abdcc39fSmichael      'height'=> 11,
573abdcc39fSmichael      'title' => $lang['diff'],
574abdcc39fSmichael      'alt'   => $lang['diff']
575abdcc39fSmichael    )));
576abdcc39fSmichael    $form->addElement(form_makeCloseTag('a'));
577cffcc403Sandi
578*cddd152cSmichael    $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => wl($recent['id'],"do=revisions",false,'&'))));
579abdcc39fSmichael    $form->addElement(form_makeTag('img', array(
580abdcc39fSmichael      'src'   => DOKU_BASE.'lib/images/history.png',
581abdcc39fSmichael      'width' => 12,
582abdcc39fSmichael      'height'=> 14,
583abdcc39fSmichael      'title' => $lang['btn_revs'],
584abdcc39fSmichael      'alt'   => $lang['btn_revs']
585abdcc39fSmichael    )));
586abdcc39fSmichael    $form->addElement(form_makeCloseTag('a'));
587b6912aeaSAndreas Gohr
588abdcc39fSmichael    $form->addElement(html_wikilink(':'.$recent['id'],$conf['useheading']?NULL:$recent['id']));
589abdcc39fSmichael
590abdcc39fSmichael    $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
591abdcc39fSmichael    $form->addElement(' &ndash; '.htmlspecialchars($recent['sum']));
592abdcc39fSmichael    $form->addElement(form_makeCloseTag('span'));
593abdcc39fSmichael
594abdcc39fSmichael    $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
595d437bcc4SAndreas Gohr    if($recent['user']){
596abdcc39fSmichael      $form->addElement(editorinfo($recent['user']));
59788f522e9Sandi    }else{
598abdcc39fSmichael      $form->addElement($recent['ip']);
59988f522e9Sandi    }
600abdcc39fSmichael    $form->addElement(form_makeCloseTag('span'));
601cffcc403Sandi
602abdcc39fSmichael    $form->addElement(form_makeCloseTag('div'));
603abdcc39fSmichael    $form->addElement(form_makeCloseTag('li'));
604f3f0262cSandi  }
605abdcc39fSmichael  $form->addElement(form_makeCloseTag('ul'));
606a39955b0Smatthiasgrimm
607abdcc39fSmichael  $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
6085749f1ceSmatthiasgrimm  $last = $first + $conf['recent'];
609a39955b0Smatthiasgrimm  if ($first > 0) {
610a39955b0Smatthiasgrimm    $first -= $conf['recent'];
611a39955b0Smatthiasgrimm    if ($first < 0) $first = 0;
612abdcc39fSmichael    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
613abdcc39fSmichael    $form->addElement(form_makeTag('input', array(
614abdcc39fSmichael      'type'  => 'submit',
615abdcc39fSmichael      'name'  => 'first['.$first.']',
616*cddd152cSmichael      'value' => $lang['btn_newer'],
617*cddd152cSmichael      'accesskey' => 'n',
618*cddd152cSmichael      'title' => '[ALT+N]'
619abdcc39fSmichael    )));
620abdcc39fSmichael    $form->addElement(form_makeCloseTag('div'));
621a39955b0Smatthiasgrimm  }
62271726d78SBen Coburn  if ($hasNext) {
623abdcc39fSmichael    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
624abdcc39fSmichael    $form->addElement(form_makeTag('input', array(
625abdcc39fSmichael      'type'  => 'submit',
626abdcc39fSmichael      'name'  => 'first['.$last.']',
627*cddd152cSmichael      'value' => $lang['btn_older'],
628*cddd152cSmichael      'accesskey' => 'p',
629*cddd152cSmichael      'title'  => '[ALT+P]'
630abdcc39fSmichael    )));
631abdcc39fSmichael    $form->addElement(form_makeCloseTag('div'));
632a39955b0Smatthiasgrimm  }
633abdcc39fSmichael  $form->addElement(form_makeCloseTag('div'));
634abdcc39fSmichael  html_form('recent', $form);
635f3f0262cSandi}
636f3f0262cSandi
63715fae107Sandi/**
63815fae107Sandi * Display page index
63915fae107Sandi *
64015fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
64115fae107Sandi */
642f3f0262cSandifunction html_index($ns){
643ed7b5f09Sandi  require_once(DOKU_INC.'inc/search.php');
644f3f0262cSandi  global $conf;
645f3f0262cSandi  global $ID;
646f3f0262cSandi  $dir = $conf['datadir'];
647f3f0262cSandi  $ns  = cleanID($ns);
64830f1737dSandi  #fixme use appropriate function
649f3f0262cSandi  if(empty($ns)){
650f3f0262cSandi    $ns = dirname(str_replace(':','/',$ID));
651f3f0262cSandi    if($ns == '.') $ns ='';
652f3f0262cSandi  }
65388d3a917Sandi  $ns  = utf8_encodeFN(str_replace(':','/',$ns));
654f3f0262cSandi
655a06884abSAndreas Gohr  echo p_locale_xhtml('index');
656a06884abSAndreas Gohr  echo '<div id="index__tree">';
657f3f0262cSandi
658f3f0262cSandi  $data = array();
659f3f0262cSandi  search($data,$conf['datadir'],'search_index',array('ns' => $ns));
660a06884abSAndreas Gohr  echo html_buildlist($data,'idx','html_list_index','html_li_index');
661a06884abSAndreas Gohr
662a06884abSAndreas Gohr  echo '</div>';
663f3f0262cSandi}
664f3f0262cSandi
665f3f0262cSandi/**
66615fae107Sandi * Index item formatter
66715fae107Sandi *
668f3f0262cSandi * User function for html_buildlist()
66915fae107Sandi *
67015fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
671f3f0262cSandi */
672f3f0262cSandifunction html_list_index($item){
673d98d4540SBen Coburn  global $ID;
674f3f0262cSandi  $ret = '';
675f3f0262cSandi  $base = ':'.$item['id'];
676f3f0262cSandi  $base = substr($base,strrpos($base,':')+1);
677f3f0262cSandi  if($item['type']=='d'){
6784a119027SAndreas Gohr    $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" class="idx_dir"><strong>';
679f3f0262cSandi    $ret .= $base;
680ed7ecb79SAnika Henke    $ret .= '</strong></a>';
681f3f0262cSandi  }else{
682f3f0262cSandi    $ret .= html_wikilink(':'.$item['id']);
683f3f0262cSandi  }
684f3f0262cSandi  return $ret;
685f3f0262cSandi}
686f3f0262cSandi
687f3f0262cSandi/**
688cb70c441Sandi * Index List item
689cb70c441Sandi *
690cb70c441Sandi * This user function is used in html_build_lidt to build the
691cb70c441Sandi * <li> tags for namespaces when displaying the page index
692cb70c441Sandi * it gives different classes to opened or closed "folders"
693cb70c441Sandi *
694cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
695cb70c441Sandi */
696cb70c441Sandifunction html_li_index($item){
697cb70c441Sandi  if($item['type'] == "f"){
698cb70c441Sandi    return '<li class="level'.$item['level'].'">';
699cb70c441Sandi  }elseif($item['open']){
700cb70c441Sandi    return '<li class="open">';
701cb70c441Sandi  }else{
702cb70c441Sandi    return '<li class="closed">';
703cb70c441Sandi  }
704cb70c441Sandi}
705cb70c441Sandi
706cb70c441Sandi/**
707cb70c441Sandi * Default List item
708cb70c441Sandi *
709cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
710cb70c441Sandi */
711cb70c441Sandifunction html_li_default($item){
712cb70c441Sandi  return '<li class="level'.$item['level'].'">';
713cb70c441Sandi}
714cb70c441Sandi
715cb70c441Sandi/**
71615fae107Sandi * Build an unordered list
71715fae107Sandi *
718f3f0262cSandi * Build an unordered list from the given $data array
719f3f0262cSandi * Each item in the array has to have a 'level' property
720f3f0262cSandi * the item itself gets printed by the given $func user
721cb70c441Sandi * function. The second and optional function is used to
722cb70c441Sandi * print the <li> tag. Both user function need to accept
723cb70c441Sandi * a single item.
72415fae107Sandi *
725c5a8fd96SAndreas Gohr * Both user functions can be given as array to point to
726c5a8fd96SAndreas Gohr * a member of an object.
727c5a8fd96SAndreas Gohr *
72815fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
729f3f0262cSandi */
730cb70c441Sandifunction html_buildlist($data,$class,$func,$lifunc='html_li_default'){
731f3f0262cSandi  $level = 0;
732f3f0262cSandi  $opens = 0;
733f3f0262cSandi  $ret   = '';
734f3f0262cSandi
735f3f0262cSandi  foreach ($data as $item){
736f3f0262cSandi
737f3f0262cSandi    if( $item['level'] > $level ){
738f3f0262cSandi      //open new list
739df52d0feSandi      for($i=0; $i<($item['level'] - $level); $i++){
740df52d0feSandi        if ($i) $ret .= "<li class=\"clear\">\n";
741f3f0262cSandi        $ret .= "\n<ul class=\"$class\">\n";
742df52d0feSandi      }
743f3f0262cSandi    }elseif( $item['level'] < $level ){
744f3f0262cSandi      //close last item
745f3f0262cSandi      $ret .= "</li>\n";
746f3f0262cSandi      for ($i=0; $i<($level - $item['level']); $i++){
747f3f0262cSandi        //close higher lists
748f3f0262cSandi        $ret .= "</ul>\n</li>\n";
749f3f0262cSandi      }
750f3f0262cSandi    }else{
751f3f0262cSandi      //close last item
752f3f0262cSandi      $ret .= "</li>\n";
753f3f0262cSandi    }
754f3f0262cSandi
755f3f0262cSandi    //remember current level
756f3f0262cSandi    $level = $item['level'];
757f3f0262cSandi
758f3f0262cSandi    //print item
75934dbe711Schris    $ret .= call_user_func($lifunc,$item);
7600c6b58a8SAndreas Gohr    $ret .= '<div class="li">';
76134dbe711Schris
76234dbe711Schris    $ret .= call_user_func($func,$item);
7630c6b58a8SAndreas Gohr    $ret .= '</div>';
764f3f0262cSandi  }
765f3f0262cSandi
766f3f0262cSandi  //close remaining items and lists
767f3f0262cSandi  for ($i=0; $i < $level; $i++){
768f3f0262cSandi    $ret .= "</li></ul>\n";
769f3f0262cSandi  }
770f3f0262cSandi
771f3f0262cSandi  return $ret;
772f3f0262cSandi}
773f3f0262cSandi
77415fae107Sandi/**
77515fae107Sandi * display backlinks
77615fae107Sandi *
77715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
77811df47ecSMichael Klier * @author Michael Klier <chi@chimeric.de>
77915fae107Sandi */
780f3f0262cSandifunction html_backlinks(){
78154f4c056SAndreas Gohr  require_once(DOKU_INC.'inc/fulltext.php');
782f3f0262cSandi  global $ID;
783f3f0262cSandi  global $conf;
78411df47ecSMichael Klier  global $lang;
785f3f0262cSandi
786c112d578Sandi  print p_locale_xhtml('backlinks');
787f3f0262cSandi
78854f4c056SAndreas Gohr  $data = ft_backlinks($ID);
789f3f0262cSandi
79011df47ecSMichael Klier  if(!empty($data)) {
791f3f0262cSandi      print '<ul class="idx">';
79254f4c056SAndreas Gohr      foreach($data as $blink){
7930c6b58a8SAndreas Gohr        print '<li><div class="li">';
79454f4c056SAndreas Gohr        print html_wikilink(':'.$blink,$conf['useheading']?NULL:$blink);
7950c6b58a8SAndreas Gohr        print '</div></li>';
796f3f0262cSandi      }
797f3f0262cSandi      print '</ul>';
79811df47ecSMichael Klier  } else {
79911df47ecSMichael Klier      print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
80011df47ecSMichael Klier  }
801f3f0262cSandi}
802f3f0262cSandi
80315fae107Sandi/**
80415fae107Sandi * show diff
80515fae107Sandi *
80615fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
80715fae107Sandi */
808f3f0262cSandifunction html_diff($text='',$intro=true){
809ed7b5f09Sandi  require_once(DOKU_INC.'inc/DifferenceEngine.php');
810f3f0262cSandi  global $ID;
811f3f0262cSandi  global $REV;
812f3f0262cSandi  global $lang;
813f3f0262cSandi  global $conf;
814e1bd90ffSAndreas Gohr
81577707b04SAndreas Gohr  // we're trying to be clever here, revisions to compare can be either
81677707b04SAndreas Gohr  // given as rev and rev2 parameters, with rev2 being optional. Or in an
81777707b04SAndreas Gohr  // array in rev2.
81877707b04SAndreas Gohr  $rev1 = $REV;
8197b3f8b16SAndreas Gohr
82077707b04SAndreas Gohr  if(is_array($_REQUEST['rev2'])){
82177707b04SAndreas Gohr    $rev1 = (int) $_REQUEST['rev2'][0];
82277707b04SAndreas Gohr    $rev2 = (int) $_REQUEST['rev2'][1];
82354041c77SAndreas Gohr
82454041c77SAndreas Gohr    if(!$rev1){
82554041c77SAndreas Gohr        $rev1 = $rev2;
82654041c77SAndreas Gohr        unset($rev2);
82754041c77SAndreas Gohr    }
828f3f0262cSandi  }else{
82977707b04SAndreas Gohr    $rev2 = (int) $_REQUEST['rev2'];
8304d58bd99Sandi  }
8314d58bd99Sandi
83277707b04SAndreas Gohr  if($text){                      // compare text to the most current revision
83377707b04SAndreas Gohr    $l_rev   = '';
83477707b04SAndreas Gohr    $l_text  = rawWiki($ID,'');
83577707b04SAndreas Gohr    $l_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
836e656dcd4SAndreas Gohr               $ID.' '.strftime($conf['dformat'],@filemtime(wikiFN($ID))).'</a> '.
83777707b04SAndreas Gohr               $lang['current'];
83877707b04SAndreas Gohr
83977707b04SAndreas Gohr    $r_rev   = '';
84077707b04SAndreas Gohr    $r_text  = cleanText($text);
84177707b04SAndreas Gohr    $r_head  = $lang['yours'];
842e1bd90ffSAndreas Gohr  }else{
84377707b04SAndreas Gohr    if($rev1 && $rev2){            // two specific revisions wanted
84454041c77SAndreas Gohr      // make sure order is correct (older on the left)
84577707b04SAndreas Gohr      if($rev1 < $rev2){
84677707b04SAndreas Gohr        $l_rev = $rev1;
84777707b04SAndreas Gohr        $r_rev = $rev2;
84877707b04SAndreas Gohr      }else{
84977707b04SAndreas Gohr        $l_rev = $rev2;
85077707b04SAndreas Gohr        $r_rev = $rev1;
851e1bd90ffSAndreas Gohr      }
85277707b04SAndreas Gohr    }elseif($rev1){                // single revision given, compare to current
85377707b04SAndreas Gohr      $r_rev = '';
85477707b04SAndreas Gohr      $l_rev = $rev1;
85577707b04SAndreas Gohr    }else{                        // no revision was given, compare previous to current
85677707b04SAndreas Gohr      $r_rev = '';
85777707b04SAndreas Gohr      $revs = getRevisions($ID, 0, 1);
85877707b04SAndreas Gohr      $l_rev = $revs[0];
85977707b04SAndreas Gohr    }
86077707b04SAndreas Gohr
8617b3f8b16SAndreas Gohr    // when both revisions are empty then the page was created just now
8627b3f8b16SAndreas Gohr    if(!$l_rev && !$r_rev){
8637b3f8b16SAndreas Gohr      $l_text = '';
8647b3f8b16SAndreas Gohr    }else{
86577707b04SAndreas Gohr      $l_text = rawWiki($ID,$l_rev);
8667b3f8b16SAndreas Gohr    }
86777707b04SAndreas Gohr    $r_text = rawWiki($ID,$r_rev);
86877707b04SAndreas Gohr
8697b3f8b16SAndreas Gohr
8707b3f8b16SAndreas Gohr    if(!$l_rev){
8717b3f8b16SAndreas Gohr      $l_head = '&mdash;';
8727b3f8b16SAndreas Gohr    }else{
87377707b04SAndreas Gohr      $l_head = '<a class="wikilink1" href="'.wl($ID,"rev=$l_rev").'">'.
874e656dcd4SAndreas Gohr                $ID.' '.strftime($conf['dformat'],$l_rev).'</a>';
8757b3f8b16SAndreas Gohr    }
87677707b04SAndreas Gohr
87777707b04SAndreas Gohr    if($r_rev){
87877707b04SAndreas Gohr      $r_head = '<a class="wikilink1" href="'.wl($ID,"rev=$r_rev").'">'.
879e656dcd4SAndreas Gohr                $ID.' '.strftime($conf['dformat'],$r_rev).'</a>';
8807b3f8b16SAndreas Gohr    }elseif($_rev = @filemtime(wikiFN($ID))){
88177707b04SAndreas Gohr      $r_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
8827b3f8b16SAndreas Gohr               $ID.' '.strftime($conf['dformat'],$_rev).'</a> '.
883f3f0262cSandi               $lang['current'];
8847b3f8b16SAndreas Gohr    }else{
8857b3f8b16SAndreas Gohr      $r_head = '&mdash; '.$lang['current'];
886f3f0262cSandi    }
88777707b04SAndreas Gohr  }
88877707b04SAndreas Gohr
88977707b04SAndreas Gohr  $df = new Diff(explode("\n",htmlspecialchars($l_text)),
89077707b04SAndreas Gohr                 explode("\n",htmlspecialchars($r_text)));
89177707b04SAndreas Gohr
892f3f0262cSandi  $tdf = new TableDiffFormatter();
893c112d578Sandi  if($intro) print p_locale_xhtml('diff');
894f3f0262cSandi  ?>
895daf4ca4eSAnika Henke    <table class="diff">
896f3f0262cSandi      <tr>
897daf4ca4eSAnika Henke        <th colspan="2">
89877707b04SAndreas Gohr          <?php echo $l_head?>
899daf4ca4eSAnika Henke        </th>
900daf4ca4eSAnika Henke        <th colspan="2">
90177707b04SAndreas Gohr          <?php echo $r_head?>
902daf4ca4eSAnika Henke        </th>
903f3f0262cSandi      </tr>
9044da078a3Smatthiasgrimm      <?php echo $tdf->format($df)?>
905f3f0262cSandi    </table>
9064da078a3Smatthiasgrimm  <?php
907f3f0262cSandi}
908f3f0262cSandi
90915fae107Sandi/**
91015fae107Sandi * show warning on conflict detection
91115fae107Sandi *
91215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
91315fae107Sandi */
914f3f0262cSandifunction html_conflict($text,$summary){
915f3f0262cSandi  global $ID;
916f3f0262cSandi  global $lang;
917f3f0262cSandi
918c112d578Sandi  print p_locale_xhtml('conflict');
919fdb8d77bSTom N Harris  $form = new Doku_Form('dw__editform');
920fdb8d77bSTom N Harris  $form->addHidden('id', $ID);
921fdb8d77bSTom N Harris  $form->addHidden('wikitext', $text);
922fdb8d77bSTom N Harris  $form->addHidden('summary', $summary);
923fdb8d77bSTom N Harris  $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
924fdb8d77bSTom N Harris  $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
925fdb8d77bSTom N Harris  html_form('conflict', $form);
926fdb8d77bSTom N Harris  print '<br /><br /><br /><br />'.NL;
927f3f0262cSandi}
928f3f0262cSandi
929f3f0262cSandi/**
93015fae107Sandi * Prints the global message array
93115fae107Sandi *
93215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
933f3f0262cSandi */
934f3f0262cSandifunction html_msgarea(){
935f3f0262cSandi  global $MSG;
936f3f0262cSandi
937f3f0262cSandi  if(!isset($MSG)) return;
938f3f0262cSandi
939f3f0262cSandi  foreach($MSG as $msg){
940f3f0262cSandi    print '<div class="'.$msg['lvl'].'">';
941f3f0262cSandi    print $msg['msg'];
942f3f0262cSandi    print '</div>';
943f3f0262cSandi  }
944f3f0262cSandi}
945f3f0262cSandi
946f3f0262cSandi/**
947f3f0262cSandi * Prints the registration form
94815fae107Sandi *
94915fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
950f3f0262cSandi */
951f3f0262cSandifunction html_register(){
952f3f0262cSandi  global $lang;
953cab2716aSmatthias.grimm  global $conf;
954f3f0262cSandi  global $ID;
955f3f0262cSandi
956c112d578Sandi  print p_locale_xhtml('register');
957fdb8d77bSTom N Harris  print '<div class="centeralign">'.NL;
958fdb8d77bSTom N Harris  $form = new Doku_Form('dw__register', wl($ID));
959fdb8d77bSTom N Harris  $form->startFieldset($lang['register']);
960fdb8d77bSTom N Harris  $form->addHidden('do', 'register');
961fdb8d77bSTom N Harris  $form->addHidden('save', '1');
962fdb8d77bSTom N Harris  $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], null, 'block', array('size'=>'50')));
963cab2716aSmatthias.grimm  if (!$conf['autopasswd']) {
964fdb8d77bSTom N Harris    $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
965fdb8d77bSTom N Harris    $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
966cab2716aSmatthias.grimm  }
967fdb8d77bSTom N Harris  $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', array('size'=>'50')));
968fdb8d77bSTom N Harris  $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', array('size'=>'50')));
969fdb8d77bSTom N Harris  $form->addElement(form_makeButton('submit', '', $lang['register']));
970fdb8d77bSTom N Harris  $form->endFieldset();
971fdb8d77bSTom N Harris  html_form('register', $form);
972cab2716aSmatthias.grimm
973fdb8d77bSTom N Harris  print '</div>'.NL;
974f3f0262cSandi}
975f3f0262cSandi
976f3f0262cSandi/**
9778b06d178Schris * Print the update profile form
9788b06d178Schris *
9798b06d178Schris * @author Christopher Smith <chris@jalakai.co.uk>
9808b06d178Schris * @author Andreas Gohr <andi@splitbrain.org>
9818b06d178Schris */
9828b06d178Schrisfunction html_updateprofile(){
9838b06d178Schris  global $lang;
9848b06d178Schris  global $conf;
9858b06d178Schris  global $ID;
9868b06d178Schris  global $INFO;
98782fd59b6SAndreas Gohr  global $auth;
9888b06d178Schris
9898b06d178Schris  print p_locale_xhtml('updateprofile');
9908b06d178Schris
9918b06d178Schris  if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
9928b06d178Schris  if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
993fdb8d77bSTom N Harris  print '<div class="centeralign">'.NL;
994fdb8d77bSTom N Harris  $form = new Doku_Form('dw__register', wl($ID));
995fdb8d77bSTom N Harris  $form->startFieldset($lang['profile']);
996fdb8d77bSTom N Harris  $form->addHidden('do', 'profile');
997fdb8d77bSTom N Harris  $form->addHidden('save', '1');
998fdb8d77bSTom N Harris  $form->addElement(form_makeTextField('fullname', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
999fdb8d77bSTom N Harris  $attr = array('size'=>'50');
1000fdb8d77bSTom N Harris  if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1001fdb8d77bSTom N Harris  $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', $attr));
100239ba8890SAndreas Gohr  $attr = array('size'=>'50');
100339ba8890SAndreas Gohr  if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
1004fdb8d77bSTom N Harris  $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', $attr));
1005fdb8d77bSTom N Harris  $form->addElement(form_makeTag('br'));
1006fdb8d77bSTom N Harris  if ($auth->canDo('modPass')) {
1007fdb8d77bSTom N Harris    $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1008fdb8d77bSTom N Harris    $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1009fdb8d77bSTom N Harris  }
1010fdb8d77bSTom N Harris  if ($conf['profileconfirm']) {
1011fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1012fdb8d77bSTom N Harris    $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50')));
1013fdb8d77bSTom N Harris  }
1014fdb8d77bSTom N Harris  $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1015fdb8d77bSTom N Harris  $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
1016fdb8d77bSTom N Harris  $form->endFieldset();
1017fdb8d77bSTom N Harris  html_form('updateprofile', $form);
1018fdb8d77bSTom N Harris  print '</div>'.NL;
10198b06d178Schris}
10208b06d178Schris
10218b06d178Schris/**
1022f3f0262cSandi * This displays the edit form (lots of logic included)
102315fae107Sandi *
10247146cee2SAndreas Gohr * @fixme    this is a huge lump of code and should be modularized
1025016b6153SAndreas Gohr * @triggers HTML_PAGE_FROMTEMPLATE
1026c9570649SAndreas Gohr * @triggers HTML_EDITFORM_INJECTION
102715fae107Sandi * @author   Andreas Gohr <andi@splitbrain.org>
1028f3f0262cSandi */
1029f3f0262cSandifunction html_edit($text=null,$include='edit'){ //FIXME: include needed?
1030f3f0262cSandi  global $ID;
1031f3f0262cSandi  global $REV;
1032f3f0262cSandi  global $DATE;
1033f3f0262cSandi  global $RANGE;
1034f3f0262cSandi  global $PRE;
1035f3f0262cSandi  global $SUF;
1036f3f0262cSandi  global $INFO;
1037f3f0262cSandi  global $SUM;
1038f3f0262cSandi  global $lang;
1039f3f0262cSandi  global $conf;
1040066fee30SAndreas Gohr  global $license;
1041f3f0262cSandi
1042f3f0262cSandi  //set summary default
1043f3f0262cSandi  if(!$SUM){
1044f3f0262cSandi    if($REV){
1045f3f0262cSandi      $SUM = $lang['restored'];
1046f3f0262cSandi    }elseif(!$INFO['exists']){
1047f3f0262cSandi      $SUM = $lang['created'];
1048f3f0262cSandi    }
1049f3f0262cSandi  }
1050f3f0262cSandi
1051f3f0262cSandi  //no text? Load it!
1052f3f0262cSandi  if(!isset($text)){
1053f3f0262cSandi    $pr = false; //no preview mode
10547146cee2SAndreas Gohr    if($INFO['exists']){
1055f3f0262cSandi      if($RANGE){
1056f3f0262cSandi        list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
1057f3f0262cSandi      }else{
1058f3f0262cSandi        $text = rawWiki($ID,$REV);
1059f3f0262cSandi      }
10608fe3bb00STom N Harris      $check = md5($text);
10618fe3bb00STom N Harris      $mod = false;
1062f3f0262cSandi    }else{
10637146cee2SAndreas Gohr      //try to load a pagetemplate
1064b7d5a5f0SAndreas Gohr      $data = array($ID);
1065016b6153SAndreas Gohr      $text = trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true);
10668fe3bb00STom N Harris      $check = md5('');
10678fe3bb00STom N Harris      $mod = $text!=='';
10687146cee2SAndreas Gohr    }
10697146cee2SAndreas Gohr  }else{
1070f3f0262cSandi    $pr = true; //preview mode
10718fe3bb00STom N Harris    if (isset($_REQUEST['changecheck'])) {
10728fe3bb00STom N Harris      $check = $_REQUEST['changecheck'];
10738fe3bb00STom N Harris      $mod = md5($text)!==$check;
10748fe3bb00STom N Harris    } else {
10758fe3bb00STom N Harris      // Why? Assume default text is unmodified.
10768fe3bb00STom N Harris      $check = md5($text);
10778fe3bb00STom N Harris      $mod = false;
10788fe3bb00STom N Harris    }
1079f3f0262cSandi  }
1080f3f0262cSandi
108127eb9321SAnika Henke  $wr = $INFO['writable'] && !$INFO['locked'];
1082f3f0262cSandi  if($wr){
1083c112d578Sandi    if ($REV) print p_locale_xhtml('editrev');
1084c112d578Sandi    print p_locale_xhtml($include);
1085f3f0262cSandi  }else{
1086409d7af7SAndreas Gohr    // check pseudo action 'source'
1087409d7af7SAndreas Gohr    if(!actionOK('source')){
1088409d7af7SAndreas Gohr      msg('Command disabled: source',-1);
1089409d7af7SAndreas Gohr      return;
1090409d7af7SAndreas Gohr    }
1091c112d578Sandi    print p_locale_xhtml('read');
1092f3f0262cSandi  }
1093f3f0262cSandi  if(!$DATE) $DATE = $INFO['lastmod'];
1094dc57ef04Sandi
1095dc57ef04Sandi
1096f3f0262cSandi?>
109763afe2a6SAnika Henke  <div style="width:99%;">
109842c7abd6SAndreas Gohr
109963afe2a6SAnika Henke   <div class="toolbar">
1100e656dcd4SAndreas Gohr      <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.strftime($conf['dformat']);?></div>
1101fdb8d77bSTom N Harris      <div id="tool__bar"><?php if($wr){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
1102409d7af7SAndreas Gohr      target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
110320d062caSAndreas Gohr
11044da078a3Smatthiasgrimm      <?php if($wr){?>
1105e226efe1SAndreas Gohr      <script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--
11064da078a3Smatthiasgrimm        <?php /* sets changed to true when previewed */?>
11078fe3bb00STom N Harris        textChanged = <?php ($mod) ? print 'true' : print 'false' ?>;
1108e226efe1SAndreas Gohr      //--><!]]></script>
110924a33b42SAndreas Gohr      <span id="spell__action"></span>
111024a33b42SAndreas Gohr      <div id="spell__suggest"></div>
1111ee4c4a1bSAndreas Gohr      <?php } ?>
111263afe2a6SAnika Henke   </div>
111324a33b42SAndreas Gohr   <div id="spell__result"></div>
11144da078a3Smatthiasgrimm<?php
1115fdb8d77bSTom N Harris  $form = new Doku_Form('dw__editform');
1116fdb8d77bSTom N Harris  $form->addHidden('id', $ID);
1117fdb8d77bSTom N Harris  $form->addHidden('rev', $REV);
1118fdb8d77bSTom N Harris  $form->addHidden('date', $DATE);
1119fdb8d77bSTom N Harris  $form->addHidden('prefix', $PRE);
1120fdb8d77bSTom N Harris  $form->addHidden('suffix', $SUF);
1121fdb8d77bSTom N Harris  $form->addHidden('changecheck', $check);
1122fdb8d77bSTom N Harris  $attr = array('tabindex'=>'1');
1123fdb8d77bSTom N Harris  if (!$wr) $attr['readonly'] = 'readonly';
1124fdb8d77bSTom N Harris  $form->addElement(form_makeWikiText($text, $attr));
1125fdb8d77bSTom N Harris  $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar')));
1126fdb8d77bSTom N Harris  $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1127fdb8d77bSTom N Harris  $form->addElement(form_makeCloseTag('div'));
1128fdb8d77bSTom N Harris  if ($wr) {
1129fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
1130fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
1131fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
1132fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
1133fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
1134fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
1135fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
1136fdb8d77bSTom N Harris    $elem = html_minoredit();
1137fdb8d77bSTom N Harris    if ($elem) $form->addElement($elem);
1138fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
1139fdb8d77bSTom N Harris  }
1140fdb8d77bSTom N Harris  $form->addElement(form_makeCloseTag('div'));
1141066fee30SAndreas Gohr  if($conf['license']){
1142066fee30SAndreas Gohr    $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1143066fee30SAndreas Gohr    $out  = $lang['licenseok'];
1144066fee30SAndreas Gohr    $out .= '<a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
1145066fee30SAndreas Gohr    if($conf['target']['external']) $out .= ' target="'.$conf['target']['external'].'"';
1146066fee30SAndreas Gohr    $out .= '> '.$license[$conf['license']]['name'].'</a>';
1147066fee30SAndreas Gohr    $form->addElement($out);
1148066fee30SAndreas Gohr    $form->addElement(form_makeCloseTag('div'));
1149066fee30SAndreas Gohr  }
1150fdb8d77bSTom N Harris  html_form('edit', $form);
1151fdb8d77bSTom N Harris  print '</div>'.NL;
1152f3f0262cSandi}
1153f3f0262cSandi
1154f3f0262cSandi/**
1155b6912aeaSAndreas Gohr * Adds a checkbox for minor edits for logged in users
1156b6912aeaSAndreas Gohr *
1157b6912aeaSAndreas Gohr * @author Andrea Gohr <andi@splitbrain.org>
1158b6912aeaSAndreas Gohr */
1159b6912aeaSAndreas Gohrfunction html_minoredit(){
1160b6912aeaSAndreas Gohr  global $conf;
1161b6912aeaSAndreas Gohr  global $lang;
1162b6912aeaSAndreas Gohr  // minor edits are for logged in users only
1163b6912aeaSAndreas Gohr  if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1164fdb8d77bSTom N Harris    return false;
1165b6912aeaSAndreas Gohr  }
1166b6912aeaSAndreas Gohr
1167b6912aeaSAndreas Gohr  $p = array();
1168b6912aeaSAndreas Gohr  $p['tabindex'] = 3;
1169bb4866bdSchris  if(!empty($_REQUEST['minor'])) $p['checked']='checked';
1170fdb8d77bSTom N Harris  return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
1171b6912aeaSAndreas Gohr}
1172b6912aeaSAndreas Gohr
1173b6912aeaSAndreas Gohr/**
1174f3f0262cSandi * prints some debug info
117515fae107Sandi *
117615fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1177f3f0262cSandi */
1178f3f0262cSandifunction html_debug(){
1179f3f0262cSandi  global $conf;
1180d16a4edaSandi  global $lang;
11815298a619SAndreas Gohr  global $auth;
1182100a97e3SAndreas Gohr  global $INFO;
1183100a97e3SAndreas Gohr
118428fb55ffSandi  //remove sensitive data
118528fb55ffSandi  $cnf = $conf;
118624297a69SAndreas Gohr  debug_guard($cnf);
1187100a97e3SAndreas Gohr  $nfo = $INFO;
118824297a69SAndreas Gohr  debug_guard($nfo);
1189100a97e3SAndreas Gohr  $ses = $_SESSION;
119024297a69SAndreas Gohr  debug_guard($ses);
1191f3f0262cSandi
1192f3f0262cSandi  print '<html><body>';
1193f3f0262cSandi
1194f3f0262cSandi  print '<p>When reporting bugs please send all the following ';
1195f3f0262cSandi  print 'output as a mail to andi@splitbrain.org ';
1196f3f0262cSandi  print 'The best way to do this is to save this page in your browser</p>';
1197f3f0262cSandi
1198100a97e3SAndreas Gohr  print '<b>$INFO:</b><pre>';
1199100a97e3SAndreas Gohr  print_r($nfo);
1200100a97e3SAndreas Gohr  print '</pre>';
1201100a97e3SAndreas Gohr
1202f3f0262cSandi  print '<b>$_SERVER:</b><pre>';
1203f3f0262cSandi  print_r($_SERVER);
1204f3f0262cSandi  print '</pre>';
1205f3f0262cSandi
1206f3f0262cSandi  print '<b>$conf:</b><pre>';
120728fb55ffSandi  print_r($cnf);
1208f3f0262cSandi  print '</pre>';
1209f3f0262cSandi
1210ed7b5f09Sandi  print '<b>DOKU_BASE:</b><pre>';
1211ed7b5f09Sandi  print DOKU_BASE;
1212f3f0262cSandi  print '</pre>';
1213f3f0262cSandi
1214ed7b5f09Sandi  print '<b>abs DOKU_BASE:</b><pre>';
1215ed7b5f09Sandi  print DOKU_URL;
1216ed7b5f09Sandi  print '</pre>';
1217ed7b5f09Sandi
1218ed7b5f09Sandi  print '<b>rel DOKU_BASE:</b><pre>';
1219f3f0262cSandi  print dirname($_SERVER['PHP_SELF']).'/';
1220f3f0262cSandi  print '</pre>';
1221f3f0262cSandi
1222f3f0262cSandi  print '<b>PHP Version:</b><pre>';
1223f3f0262cSandi  print phpversion();
1224f3f0262cSandi  print '</pre>';
1225f3f0262cSandi
1226f3f0262cSandi  print '<b>locale:</b><pre>';
1227f3f0262cSandi  print setlocale(LC_ALL,0);
1228f3f0262cSandi  print '</pre>';
1229f3f0262cSandi
1230d16a4edaSandi  print '<b>encoding:</b><pre>';
1231d16a4edaSandi  print $lang['encoding'];
1232d16a4edaSandi  print '</pre>';
1233d16a4edaSandi
12345298a619SAndreas Gohr  if($auth){
12355298a619SAndreas Gohr    print '<b>Auth backend capabilities:</b><pre>';
12365298a619SAndreas Gohr    print_r($auth->cando);
12375298a619SAndreas Gohr    print '</pre>';
12385298a619SAndreas Gohr  }
12395298a619SAndreas Gohr
12403aa54d7cSAndreas Gohr  print '<b>$_SESSION:</b><pre>';
1241100a97e3SAndreas Gohr  print_r($ses);
12423aa54d7cSAndreas Gohr  print '</pre>';
12433aa54d7cSAndreas Gohr
1244f3f0262cSandi  print '<b>Environment:</b><pre>';
1245f3f0262cSandi  print_r($_ENV);
1246f3f0262cSandi  print '</pre>';
1247f3f0262cSandi
1248f3f0262cSandi  print '<b>PHP settings:</b><pre>';
1249f3f0262cSandi  $inis = ini_get_all();
1250f3f0262cSandi  print_r($inis);
1251f3f0262cSandi  print '</pre>';
1252f3f0262cSandi
1253f3f0262cSandi  print '</body></html>';
1254f3f0262cSandi}
1255f3f0262cSandi
1256c19fe9c0Sandifunction html_admin(){
1257c19fe9c0Sandi  global $ID;
1258f8cc712eSAndreas Gohr  global $INFO;
1259c19fe9c0Sandi  global $lang;
1260ca3a6df1SMatthias Grimm  global $conf;
1261c19fe9c0Sandi
1262c112d578Sandi  print p_locale_xhtml('admin');
1263c19fe9c0Sandi
126411e2ce22Schris  // build menu of admin functions from the plugins that handle them
126511e2ce22Schris  $pluginlist = plugin_list('admin');
126611e2ce22Schris  $menu = array();
126711e2ce22Schris  foreach ($pluginlist as $p) {
126811e2ce22Schris    if($obj =& plugin_load('admin',$p) === NULL) continue;
1269f8cc712eSAndreas Gohr
1270f8cc712eSAndreas Gohr    // check permissions
1271f8cc712eSAndreas Gohr    if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
1272f8cc712eSAndreas Gohr
127311e2ce22Schris    $menu[] = array('plugin' => $p,
127411e2ce22Schris                    'prompt' => $obj->getMenuText($conf['lang']),
127511e2ce22Schris                    'sort' => $obj->getMenuSort()
127611e2ce22Schris                   );
127711e2ce22Schris  }
127811e2ce22Schris
1279746855cfSBen Coburn  usort($menu, 'p_sort_modes');
128011e2ce22Schris
128111e2ce22Schris  // output the menu
128211e2ce22Schris  ptln('<ul>');
128311e2ce22Schris
128411e2ce22Schris  foreach ($menu as $item) {
128511e2ce22Schris    if (!$item['prompt']) continue;
12860c6b58a8SAndreas Gohr    ptln('  <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
128711e2ce22Schris  }
128811e2ce22Schris
128911e2ce22Schris  ptln('</ul>');
1290ca3a6df1SMatthias Grimm}
1291c19fe9c0Sandi
12928b06d178Schris/**
12938b06d178Schris * Form to request a new password for an existing account
12948b06d178Schris *
12958b06d178Schris * @author Benoit Chesneau <benoit@bchesneau.info>
129611e2ce22Schris */
12978b06d178Schrisfunction html_resendpwd() {
12988b06d178Schris  global $lang;
12998b06d178Schris  global $conf;
13008b06d178Schris  global $ID;
1301c19fe9c0Sandi
13028b06d178Schris  print p_locale_xhtml('resendpwd');
1303fdb8d77bSTom N Harris  print '<div class="centeralign">'.NL;
1304fdb8d77bSTom N Harris  $form = new Doku_Form('dw__resendpwd', wl($ID));
1305fdb8d77bSTom N Harris  $form->startFieldset($lang['resendpwd']);
1306fdb8d77bSTom N Harris  $form->addHidden('do', 'resendpwd');
1307fdb8d77bSTom N Harris  $form->addHidden('save', '1');
1308fdb8d77bSTom N Harris  $form->addElement(form_makeTag('br'));
1309fdb8d77bSTom N Harris  $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block'));
1310fdb8d77bSTom N Harris  $form->addElement(form_makeTag('br'));
1311fdb8d77bSTom N Harris  $form->addElement(form_makeTag('br'));
1312fdb8d77bSTom N Harris  $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
1313fdb8d77bSTom N Harris  $form->endFieldset();
1314fdb8d77bSTom N Harris  html_form('resendpwd', $form);
1315fdb8d77bSTom N Harris  print '</div>'.NL;
1316fdb8d77bSTom N Harris}
1317fdb8d77bSTom N Harris
1318fdb8d77bSTom N Harris/**
1319b8595a66SAndreas Gohr * Return the TOC rendered to XHTML
1320b8595a66SAndreas Gohr *
1321b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1322b8595a66SAndreas Gohr */
1323b8595a66SAndreas Gohrfunction html_TOC($toc){
1324b8595a66SAndreas Gohr    if(!count($toc)) return '';
1325b8595a66SAndreas Gohr    global $lang;
1326b8595a66SAndreas Gohr    $out  = '<!-- TOC START -->'.DOKU_LF;
1327b8595a66SAndreas Gohr    $out .= '<div class="toc">'.DOKU_LF;
1328b8595a66SAndreas Gohr    $out .= '<div class="tocheader toctoggle" id="toc__header">';
1329b8595a66SAndreas Gohr    $out .= $lang['toc'];
1330b8595a66SAndreas Gohr    $out .= '</div>'.DOKU_LF;
1331b8595a66SAndreas Gohr    $out .= '<div id="toc__inside">'.DOKU_LF;
1332b8595a66SAndreas Gohr    $out .= html_buildlist($toc,'toc','html_list_toc');
1333b8595a66SAndreas Gohr    $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
1334b8595a66SAndreas Gohr    $out .= '<!-- TOC END -->'.DOKU_LF;
1335b8595a66SAndreas Gohr    return $out;                                                                                                }
1336b8595a66SAndreas Gohr
1337b8595a66SAndreas Gohr/**
1338b8595a66SAndreas Gohr * Callback for html_buildlist
1339b8595a66SAndreas Gohr */
1340b8595a66SAndreas Gohrfunction html_list_toc($item){
13417d91652aSAndreas Gohr    if($item['hid']){
13427d91652aSAndreas Gohr        $link = '#'.$item['hid'];
13437d91652aSAndreas Gohr    }else{
13447d91652aSAndreas Gohr        $link = $item['link'];
13457d91652aSAndreas Gohr    }
13467d91652aSAndreas Gohr
13477d91652aSAndreas Gohr    return '<span class="li"><a href="'.$link.'" class="toc">'.
1348b8595a66SAndreas Gohr           hsc($item['title']).'</a></span>';
1349b8595a66SAndreas Gohr}
1350b8595a66SAndreas Gohr
1351b8595a66SAndreas Gohr/**
1352b8595a66SAndreas Gohr * Helper function to build TOC items
1353b8595a66SAndreas Gohr *
1354b8595a66SAndreas Gohr * Returns an array ready to be added to a TOC array
1355b8595a66SAndreas Gohr *
1356b8595a66SAndreas Gohr * @param string $link  - where to link (if $hash set to '#' it's a local anchor)
1357b8595a66SAndreas Gohr * @param string $text  - what to display in the TOC
1358b8595a66SAndreas Gohr * @param int    $level - nesting level
1359b8595a66SAndreas Gohr * @param string $hash  - is prepended to the given $link, set blank if you want full links
1360b8595a66SAndreas Gohr */
1361b8595a66SAndreas Gohrfunction html_mktocitem($link, $text, $level, $hash='#'){
1362b8595a66SAndreas Gohr    global $conf;
1363b8595a66SAndreas Gohr    return  array( 'link'  => $hash.$link,
1364b8595a66SAndreas Gohr                   'title' => $text,
1365b8595a66SAndreas Gohr                   'type'  => 'ul',
13662bb0d541Schris                   'level' => $level);
1367b8595a66SAndreas Gohr}
1368b8595a66SAndreas Gohr
1369b8595a66SAndreas Gohr/**
1370fdb8d77bSTom N Harris * Output a Doku_Form object.
1371fdb8d77bSTom N Harris * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
1372fdb8d77bSTom N Harris *
1373fdb8d77bSTom N Harris * @author Tom N Harris <tnharris@whoopdedo.org>
1374fdb8d77bSTom N Harris */
1375fdb8d77bSTom N Harrisfunction html_form($name, &$form) {
1376fdb8d77bSTom N Harris  // Safety check in case the caller forgets.
1377fdb8d77bSTom N Harris  $form->endFieldset();
1378fdb8d77bSTom N Harris  trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
1379fdb8d77bSTom N Harris}
1380fdb8d77bSTom N Harris
1381fdb8d77bSTom N Harris/**
1382fdb8d77bSTom N Harris * Form print function.
1383fdb8d77bSTom N Harris * Just calls printForm() on the data object.
1384fdb8d77bSTom N Harris */
1385fdb8d77bSTom N Harrisfunction html_form_output($data) {
1386fdb8d77bSTom N Harris  $data->printForm();
13878b06d178Schris}
1388340756e4Sandi
1389340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 :
1390