xref: /dokuwiki/inc/html.php (revision 2e55802c049a2388811419cc4acd287b29279928)
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
9fa8adffeSAndreas Gohrif(!defined('DOKU_INC')) die('meh.');
10e226efe1SAndreas Gohrif(!defined('NL')) define('NL',"\n");
116bbae538Sandi
12f3f0262cSandi/**
13f3f0262cSandi * Convenience function to quickly build a wikilink
1415fae107Sandi *
1515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
16f3f0262cSandi */
17db959ae3SAndreas Gohrfunction html_wikilink($id,$name=null,$search=''){
18db959ae3SAndreas Gohr    static $xhtml_renderer = null;
19723d78dbSandi    if(is_null($xhtml_renderer)){
207aea91afSChris Smith        $xhtml_renderer = p_get_renderer('xhtml');
21f3f0262cSandi    }
22f3f0262cSandi
23fe9ec250SChris Smith    return $xhtml_renderer->internallink($id,$name,$search,true,'navigation');
24f3f0262cSandi}
25f3f0262cSandi
26f3f0262cSandi/**
27c19fe9c0Sandi * Helps building long attribute lists
28c19fe9c0Sandi *
29c277a6bdSTom N Harris * @deprecated Use buildAttributes instead
30c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org>
31c19fe9c0Sandi */
32c19fe9c0Sandifunction html_attbuild($attributes){
33c19fe9c0Sandi    $ret = '';
34c19fe9c0Sandi    foreach ( $attributes as $key => $value ) {
35e351c80dSAdrian Lang        $ret .= $key.'="'.formText($value).'" ';
36c19fe9c0Sandi    }
37c19fe9c0Sandi    return trim($ret);
38c19fe9c0Sandi}
39c19fe9c0Sandi
40c19fe9c0Sandi/**
41f3f0262cSandi * The loginform
4215fae107Sandi *
4315fae107Sandi * @author   Andreas Gohr <andi@splitbrain.org>
44f3f0262cSandi */
45f3f0262cSandifunction html_login(){
46f3f0262cSandi    global $lang;
47f3f0262cSandi    global $conf;
48f3f0262cSandi    global $ID;
49f3f0262cSandi
50c112d578Sandi    print p_locale_xhtml('login');
51fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
52e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__login'));
53fdb8d77bSTom N Harris    $form->startFieldset($lang['btn_login']);
54fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
55fdb8d77bSTom N Harris    $form->addHidden('do', 'login');
56aab557e9SGina Haeussge    $form->addElement(form_makeTextField('u', ((!$_REQUEST['http_credentials']) ? $_REQUEST['u'] : ''), $lang['user'], 'focus__this', 'block'));
57fdb8d77bSTom N Harris    $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block'));
5817f89d7eSMichael Klier    if($conf['rememberme']) {
59fdb8d77bSTom N Harris        $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple'));
6017f89d7eSMichael Klier    }
61fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['btn_login']));
62fdb8d77bSTom N Harris    $form->endFieldset();
635b62573aSAndreas Gohr
64de4d479aSAdrian Lang    if(actionOK('register')){
65bf413a4eSAnika Henke        $form->addElement('<p>'.$lang['reghere'].': '.tpl_actionlink('register','','','',true).'</p>');
66f3f0262cSandi    }
678b06d178Schris
68de4d479aSAdrian Lang    if (actionOK('resendpwd')) {
69bf413a4eSAnika Henke        $form->addElement('<p>'.$lang['pwdforget'].': '.tpl_actionlink('resendpwd','','','',true).'</p>');
708b06d178Schris    }
7176ec5467SMichael Klier
7276ec5467SMichael Klier    html_form('login', $form);
73fdb8d77bSTom N Harris    print '</div>'.NL;
74f3f0262cSandi}
75f3f0262cSandi
76f3f0262cSandi/**
7715fae107Sandi * inserts section edit buttons if wanted or removes the markers
7815fae107Sandi *
7915fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
8015fae107Sandi */
81f3f0262cSandifunction html_secedit($text,$show=true){
82f3f0262cSandi    global $INFO;
8335dae8b0SBen Coburn
843f9e3215SAdrian Lang    $regexp = '#<!-- EDIT(\d+) ([A-Z_]+) (?:"([^"]*)" )?\[(\d+-\d*)\] -->#';
85b081e262SAdrian Lang
8640868f2fSAdrian Lang    if(!$INFO['writable'] || !$show || $INFO['rev']){
8740868f2fSAdrian Lang        return preg_replace($regexp,'',$text);
88f3f0262cSandi    }
8935dae8b0SBen Coburn
9040868f2fSAdrian Lang    return preg_replace_callback($regexp,
9140868f2fSAdrian Lang                'html_secedit_button', $text);
9240868f2fSAdrian Lang}
9340868f2fSAdrian Lang
9440868f2fSAdrian Lang/**
9540868f2fSAdrian Lang * prepares section edit button data for event triggering
9640868f2fSAdrian Lang * used as a callback in html_secedit
9740868f2fSAdrian Lang *
9840868f2fSAdrian Lang * @triggers HTML_SECEDIT_BUTTON
9940868f2fSAdrian Lang * @author Andreas Gohr <andi@splitbrain.org>
10040868f2fSAdrian Lang */
10140868f2fSAdrian Langfunction html_secedit_button($matches){
102905fa971SAdrian Lang    $data = array('secid'  => $matches[1],
10340868f2fSAdrian Lang                  'target' => strtolower($matches[2]),
10440868f2fSAdrian Lang                  'range'  => $matches[count($matches) - 1]);
10540868f2fSAdrian Lang    if (count($matches) === 5) {
10640868f2fSAdrian Lang        $data['name'] = $matches[3];
10740868f2fSAdrian Lang    }
10840868f2fSAdrian Lang
10940868f2fSAdrian Lang    return trigger_event('HTML_SECEDIT_BUTTON', $data,
11040868f2fSAdrian Lang                         'html_secedit_get_button');
11140868f2fSAdrian Lang}
11240868f2fSAdrian Lang
11340868f2fSAdrian Lang/**
11440868f2fSAdrian Lang * prints a section editing button
11540868f2fSAdrian Lang * used as default action form HTML_SECEDIT_BUTTON
11640868f2fSAdrian Lang *
11740868f2fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de>
11840868f2fSAdrian Lang */
11940868f2fSAdrian Langfunction html_secedit_get_button($data) {
12040868f2fSAdrian Lang    global $ID;
12140868f2fSAdrian Lang    global $INFO;
12240868f2fSAdrian Lang
12340868f2fSAdrian Lang    if (!isset($data['name']) || $data['name'] === '') return;
12440868f2fSAdrian Lang
12540868f2fSAdrian Lang    $name = $data['name'];
12640868f2fSAdrian Lang    unset($data['name']);
12740868f2fSAdrian Lang
128905fa971SAdrian Lang    $secid = $data['secid'];
129905fa971SAdrian Lang    unset($data['secid']);
130905fa971SAdrian Lang
13140868f2fSAdrian Lang    return "<div class='secedit editbutton_" . $data['target'] .
132defa93a1SAdrian Lang                       " editbutton_" . $secid . "'>" .
13340868f2fSAdrian Lang           html_btn('secedit', $ID, '',
13440868f2fSAdrian Lang                    array_merge(array('do'  => 'edit',
135b150cd2cSGina Haeussge                                      'rev' => $INFO['lastmod'],
136b150cd2cSGina Haeussge                                      'summary' => '['.$name.'] '), $data),
13740868f2fSAdrian Lang                    'post', $name) . '</div>';
138f3f0262cSandi}
139f3f0262cSandi
140f3f0262cSandi/**
141d6c9c552Smatthiasgrimm * Just the back to top button (in its own form)
1426b13307fSandi *
1436b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
1446b13307fSandi */
1456b13307fSandifunction html_topbtn(){
1466b13307fSandi    global $lang;
1476b13307fSandi
1486b13307fSandi    $ret  = '';
14911ea018fSAndreas 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>';
150df7b6005Sandi
1516b13307fSandi    return $ret;
1526b13307fSandi}
1536b13307fSandi
1546b13307fSandi/**
155d67ca2c0Smatthiasgrimm * Displays a button (using its own form)
15635dae8b0SBen Coburn * If tooltip exists, the access key tooltip is replaced.
15715fae107Sandi *
15815fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
159f3f0262cSandi */
160f5baf821SAnika Henkefunction html_btn($name,$id,$akey,$params,$method='get',$tooltip='',$label=false){
161f3f0262cSandi    global $conf;
162f3f0262cSandi    global $lang;
163f3f0262cSandi
164f5baf821SAnika Henke    if (!$label)
165f3f0262cSandi        $label = $lang['btn_'.$name];
166f3f0262cSandi
167f3f0262cSandi    $ret = '';
16835dae8b0SBen Coburn    $tip = '';
169f3f0262cSandi
17049c713a3Sandi    //filter id (without urlencoding)
17149c713a3Sandi    $id = idfilter($id,false);
172f3f0262cSandi
173f3f0262cSandi    //make nice URLs even for buttons
1746c7843b5Sandi    if($conf['userewrite'] == 2){
1756c7843b5Sandi        $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
1766c7843b5Sandi    }elseif($conf['userewrite']){
1776c7843b5Sandi        $script = DOKU_BASE.$id;
1786c7843b5Sandi    }else{
1798b00ebcfSandi        $script = DOKU_BASE.DOKU_SCRIPT;
180f3f0262cSandi        $params['id'] = $id;
181f3f0262cSandi    }
182f3f0262cSandi
183b278f2deSAndreas Gohr    $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
184f3f0262cSandi
18506a4bf8fSAndreas Gohr    if(is_array($params)){
186f3f0262cSandi        reset($params);
187f3f0262cSandi        while (list($key, $val) = each($params)) {
188f3f0262cSandi            $ret .= '<input type="hidden" name="'.$key.'" ';
189f3f0262cSandi            $ret .= 'value="'.htmlspecialchars($val).'" />';
190f3f0262cSandi        }
19106a4bf8fSAndreas Gohr    }
192f3f0262cSandi
19335dae8b0SBen Coburn    if ($tooltip!='') {
19435dae8b0SBen Coburn        $tip = htmlspecialchars($tooltip);
19511ea018fSAndreas Gohr    }else{
19611ea018fSAndreas Gohr        $tip = htmlspecialchars($label);
19711ea018fSAndreas Gohr    }
19811ea018fSAndreas Gohr
199d822118cSAdrian Lang    $ret .= '<input type="submit" value="'.hsc($label).'" class="button" ';
20011ea018fSAndreas Gohr    if($akey){
20107493d05SAnika Henke        $tip .= ' ['.strtoupper($akey).']';
20287cb01b7SAnika Henke        $ret .= 'accesskey="'.$akey.'" ';
20335dae8b0SBen Coburn    }
20435dae8b0SBen Coburn    $ret .= 'title="'.$tip.'" ';
205f3f0262cSandi    $ret .= '/>';
2064beabca9SAnika Henke    $ret .= '</div></form>';
207f3f0262cSandi
208f3f0262cSandi    return $ret;
209f3f0262cSandi}
210f3f0262cSandi
211f3f0262cSandi/**
21215fae107Sandi * show a wiki page
21315fae107Sandi *
21415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
21515fae107Sandi */
21611c78c94SAndreas Gohrfunction html_show($txt=null){
217f3f0262cSandi    global $ID;
218f3f0262cSandi    global $REV;
219f3f0262cSandi    global $HIGH;
220b8595a66SAndreas Gohr    global $INFO;
221f3f0262cSandi    //disable section editing for old revisions or in preview
2225400331dSandi    if($txt || $REV){
2236bbae538Sandi        $secedit = false;
2246bbae538Sandi    }else{
2256bbae538Sandi        $secedit = true;
226f3f0262cSandi    }
227f3f0262cSandi
22811c78c94SAndreas Gohr    if (!is_null($txt)){
229f3f0262cSandi        //PreviewHeader
230b8595a66SAndreas Gohr        echo '<br id="scroll__here" />';
231b8595a66SAndreas Gohr        echo p_locale_xhtml('preview');
232b8595a66SAndreas Gohr        echo '<div class="preview">';
233b8595a66SAndreas Gohr        $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
234b8595a66SAndreas Gohr        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
235b8595a66SAndreas Gohr        echo $html;
236b8595a66SAndreas Gohr        echo '<div class="clearer"></div>';
237b8595a66SAndreas Gohr        echo '</div>';
2386bbae538Sandi
239f3f0262cSandi    }else{
240c112d578Sandi        if ($REV) print p_locale_xhtml('showrev');
241c112d578Sandi        $html = p_wiki_xhtml($ID,$REV,true);
2426bbae538Sandi        $html = html_secedit($html,$secedit);
243b8595a66SAndreas Gohr        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
244b8595a66SAndreas Gohr        $html = html_hilight($html,$HIGH);
245b8595a66SAndreas Gohr        echo $html;
246f3f0262cSandi    }
247f3f0262cSandi}
248f3f0262cSandi
249f3f0262cSandi/**
250ee4c4a1bSAndreas Gohr * ask the user about how to handle an exisiting draft
251ee4c4a1bSAndreas Gohr *
252ee4c4a1bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
253ee4c4a1bSAndreas Gohr */
254ee4c4a1bSAndreas Gohrfunction html_draft(){
255ee4c4a1bSAndreas Gohr    global $INFO;
256ee4c4a1bSAndreas Gohr    global $ID;
257ee4c4a1bSAndreas Gohr    global $lang;
258ee4c4a1bSAndreas Gohr    global $conf;
259ee4c4a1bSAndreas Gohr    $draft = unserialize(io_readFile($INFO['draft'],false));
260ee4c4a1bSAndreas Gohr    $text  = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
261ee4c4a1bSAndreas Gohr
262fdb8d77bSTom N Harris    print p_locale_xhtml('draft');
263e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
264fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
265fdb8d77bSTom N Harris    $form->addHidden('date', $draft['date']);
266fdb8d77bSTom N Harris    $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly')));
267fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
268f2263577SAndreas Gohr    $form->addElement($lang['draftdate'].' '. dformat(filemtime($INFO['draft'])));
269fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
270fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
271fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
272fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3')));
273fdb8d77bSTom N Harris    html_form('draft', $form);
274ee4c4a1bSAndreas Gohr}
275ee4c4a1bSAndreas Gohr
276ee4c4a1bSAndreas Gohr/**
277f3f0262cSandi * Highlights searchqueries in HTML code
27815fae107Sandi *
27915fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
2807209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
281f3f0262cSandi */
282546d3a99SAndreas Gohrfunction html_hilight($html,$phrases){
283808551e3SAndreas Gohr    $phrases = array_filter((array) $phrases);
2842237b4faSAndreas Gohr    $regex = join('|',array_map('ft_snippet_re_preprocess', array_map('preg_quote_cb',$phrases)));
28560c15d7dSAndreas Gohr
28660c15d7dSAndreas Gohr    if ($regex === '') return $html;
28724a6c235SAndreas Gohr    if (!utf8_check($regex)) return $html;
28824a6c235SAndreas Gohr    $html = @preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
289f3f0262cSandi    return $html;
290f3f0262cSandi}
291f3f0262cSandi
292f3f0262cSandi/**
2937209be23SAndreas Gohr * Callback used by html_hilight()
2947209be23SAndreas Gohr *
2957209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
2967209be23SAndreas Gohr */
2977209be23SAndreas Gohrfunction html_hilight_callback($m) {
2987209be23SAndreas Gohr    $hlight = unslash($m[0]);
2997209be23SAndreas Gohr    if ( !isset($m[2])) {
300688774a0SAnika Henke        $hlight = '<span class="search_hit">'.$hlight.'</span>';
3017209be23SAndreas Gohr    }
3027209be23SAndreas Gohr    return $hlight;
3037209be23SAndreas Gohr}
3047209be23SAndreas Gohr
3057209be23SAndreas Gohr/**
30615fae107Sandi * Run a search and display the result
30715fae107Sandi *
30815fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
309f3f0262cSandi */
310f3f0262cSandifunction html_search(){
311f3f0262cSandi    global $conf;
312f3f0262cSandi    global $QUERY;
313f3f0262cSandi    global $ID;
314f3f0262cSandi    global $lang;
315f3f0262cSandi
31606756ad2SAndreas Gohr    $intro = p_locale_xhtml('searchpage');
31706756ad2SAndreas Gohr    // allow use of placeholder in search intro
31806756ad2SAndreas Gohr    $intro = str_replace(
31906756ad2SAndreas Gohr                array('@QUERY@','@SEARCH@'),
32006756ad2SAndreas Gohr                array(hsc(rawurlencode($QUERY)),hsc($QUERY)),
32106756ad2SAndreas Gohr                $intro);
32206756ad2SAndreas Gohr    echo $intro;
323f3f0262cSandi    flush();
324f3f0262cSandi
3254d9ff3d5Sandi    //show progressbar
326e226efe1SAndreas Gohr    print '<div class="centeralign" id="dw__loading">'.NL;
327e226efe1SAndreas Gohr    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
328e226efe1SAndreas Gohr    print 'showLoadBar();'.NL;
329e226efe1SAndreas Gohr    print '//--><!]]></script>'.NL;
330e226efe1SAndreas Gohr    print '<br /></div>'.NL;
3319edac8a8SAndreas Gohr    flush();
3324d9ff3d5Sandi
333f3f0262cSandi    //do quick pagesearch
334f3f0262cSandi    $data = array();
335d0ab54f6SMichael Klier chi@chimeric.de
3366ef71970SAdrian Lang    $data = ft_pageLookup($QUERY,true,useHeading('navigation'));
337f3f0262cSandi    if(count($data)){
338f3f0262cSandi        print '<div class="search_quickresult">';
339746855cfSBen Coburn        print '<h3>'.$lang['quickhits'].':</h3>';
3404f732f0eSAnika Henke        print '<ul class="search_quickhits">';
3418d22f1e9SAndreas Gohr        foreach($data as $id => $title){
3424f732f0eSAnika Henke            print '<li> ';
3438d22f1e9SAndreas Gohr            if (useHeading('navigation')) {
3448d22f1e9SAndreas Gohr                $name = $title;
3458d22f1e9SAndreas Gohr            }else{
346bd2f6c2fSAndreas Gohr                $ns = getNS($id);
347bd2f6c2fSAndreas Gohr                if($ns){
348bd2f6c2fSAndreas Gohr                    $name = shorten(noNS($id), ' ('.$ns.')',30);
349bd2f6c2fSAndreas Gohr                }else{
350bd2f6c2fSAndreas Gohr                    $name = $id;
351bd2f6c2fSAndreas Gohr                }
3528d22f1e9SAndreas Gohr            }
353bd2f6c2fSAndreas Gohr            print html_wikilink(':'.$id,$name);
3544f732f0eSAnika Henke            print '</li> ';
355f3f0262cSandi        }
356140c93f3SAnika Henke        print '</ul> ';
357f3f0262cSandi        //clear float (see http://www.complexspiral.com/publications/containing-floats/)
358be62ff97SAnika Henke        print '<div class="clearer"></div>';
359f3f0262cSandi        print '</div>';
360f3f0262cSandi    }
361f3f0262cSandi    flush();
362f3f0262cSandi
363f3f0262cSandi    //do fulltext search
36460c15d7dSAndreas Gohr    $data = ft_pageSearch($QUERY,$regex);
365f3f0262cSandi    if(count($data)){
366506fa893SAndreas Gohr        $num = 1;
367506fa893SAndreas Gohr        foreach($data as $id => $cnt){
368f3f0262cSandi            print '<div class="search_result">';
369db959ae3SAndreas Gohr            print html_wikilink(':'.$id,useHeading('navigation')?null:$id,$regex);
370865c2687SKazutaka Miyasaka            if($cnt !== 0){
371506fa893SAndreas Gohr                print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />';
372bd0293e7SAndreas Gohr                if($num < FT_SNIPPET_NUMBER){ // create snippets for the first number of matches only
37360c15d7dSAndreas Gohr                    print '<div class="search_snippet">'.ft_snippet($id,$regex).'</div>';
374506fa893SAndreas Gohr                }
375865c2687SKazutaka Miyasaka                $num++;
376865c2687SKazutaka Miyasaka            }
377f3f0262cSandi            print '</div>';
378506fa893SAndreas Gohr            flush();
379f3f0262cSandi        }
380f3f0262cSandi    }else{
381820fa24bSandi        print '<div class="nothing">'.$lang['nothingfound'].'</div>';
382f3f0262cSandi    }
3834d9ff3d5Sandi
3844d9ff3d5Sandi    //hide progressbar
385e226efe1SAndreas Gohr    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
386e226efe1SAndreas Gohr    print 'hideLoadBar("dw__loading");'.NL;
387e226efe1SAndreas Gohr    print '//--><!]]></script>'.NL;
3889edac8a8SAndreas Gohr    flush();
389f3f0262cSandi}
390f3f0262cSandi
39115fae107Sandi/**
39215fae107Sandi * Display error on locked pages
39315fae107Sandi *
39415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
39515fae107Sandi */
396ee20e7d1Sandifunction html_locked(){
397f3f0262cSandi    global $ID;
398f3f0262cSandi    global $conf;
399f3f0262cSandi    global $lang;
40088f522e9Sandi    global $INFO;
401f3f0262cSandi
402c9b4bd1eSBen Coburn    $locktime = filemtime(wikiLockFN($ID));
403f2263577SAndreas Gohr    $expire = dformat($locktime + $conf['locktime']);
404f3f0262cSandi    $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
405f3f0262cSandi
406c112d578Sandi    print p_locale_xhtml('locked');
407f3f0262cSandi    print '<ul>';
4086d233a0cSAndy Webber    print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.editorinfo($INFO['locked']).'</div></li>';
4090c6b58a8SAndreas Gohr    print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>';
410f3f0262cSandi    print '</ul>';
411f3f0262cSandi}
412f3f0262cSandi
41315fae107Sandi/**
41415fae107Sandi * list old revisions
41515fae107Sandi *
41615fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
41771726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
4188e69fd30SKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
41915fae107Sandi */
4208e69fd30SKate Arzamastsevafunction html_revisions($first=0, $media_id = false){
421f3f0262cSandi    global $ID;
422f3f0262cSandi    global $INFO;
423f3f0262cSandi    global $conf;
424f3f0262cSandi    global $lang;
4258e69fd30SKate Arzamastseva    $id = $ID;
42671726d78SBen Coburn    /* we need to get one additionally log entry to be able to
42771726d78SBen Coburn     * decide if this is the last page or is there another one.
42871726d78SBen Coburn     * see html_recent()
42971726d78SBen Coburn     */
4308e69fd30SKate Arzamastseva    if (!$media_id) $revisions = getRevisions($ID, $first, $conf['recent']+1);
4318e69fd30SKate Arzamastseva    else {
4328e69fd30SKate Arzamastseva        $revisions = getRevisions($media_id, $first, $conf['recent']+1, 8192, true);
4338e69fd30SKate Arzamastseva        $id = $media_id;
4348e69fd30SKate Arzamastseva    }
4358e69fd30SKate Arzamastseva
43671726d78SBen Coburn    if(count($revisions)==0 && $first!=0){
43771726d78SBen Coburn        $first=0;
4388e69fd30SKate Arzamastseva        if (!$media_id) $revisions = getRevisions($ID, $first, $conf['recent']+1);
4398e69fd30SKate Arzamastseva        else $revisions = getRevisions($media_id, $first, $conf['recent']+1, 8192, true);
44071726d78SBen Coburn    }
44171726d78SBen Coburn    $hasNext = false;
44271726d78SBen Coburn    if (count($revisions)>$conf['recent']) {
44371726d78SBen Coburn        $hasNext = true;
44471726d78SBen Coburn        array_pop($revisions); // remove extra log entry
44571726d78SBen Coburn    }
44671726d78SBen Coburn
4478e69fd30SKate Arzamastseva    if (!$media_id) $date = dformat($INFO['lastmod']);
4488e69fd30SKate Arzamastseva    else $date = dformat(@filemtime(mediaFN($id)));
449f3f0262cSandi
4508e69fd30SKate Arzamastseva    if (!$media_id) print p_locale_xhtml('revisions');
45137a1dc12Smichael
452e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'page__revisions'));
45337a1dc12Smichael    $form->addElement(form_makeOpenTag('ul'));
4548e69fd30SKate Arzamastseva
4558e69fd30SKate Arzamastseva    if (!$media_id) $exists = $INFO['exists'];
4568e69fd30SKate Arzamastseva    else $exists = @file_exists(mediaFN($id));
4578e69fd30SKate Arzamastseva
4588e69fd30SKate Arzamastseva    if($exists && $first==0){
4598e69fd30SKate Arzamastseva        if (!$media_id && isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
46037a1dc12Smichael            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
46137a1dc12Smichael        else
46237a1dc12Smichael            $form->addElement(form_makeOpenTag('li'));
46337a1dc12Smichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
46437a1dc12Smichael        $form->addElement(form_makeTag('input', array(
46537a1dc12Smichael                        'type' => 'checkbox',
46637a1dc12Smichael                        'name' => 'rev2[]',
46737a1dc12Smichael                        'value' => 'current')));
468f9b2fe70Sandi
46937a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
47037a1dc12Smichael        $form->addElement($date);
47137a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
472f9b2fe70Sandi
473c2e73886SAnika Henke        $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
474cffcc403Sandi
475dad6764eSKate Arzamastseva        if (!$media_id) $href = wl($id);
476dad6764eSKate Arzamastseva        else $href = media_managerURL(array('image' => $id, 'tab_details' => 'view'));
47737a1dc12Smichael        $form->addElement(form_makeOpenTag('a', array(
47837a1dc12Smichael                        'class' => 'wikilink1',
479dad6764eSKate Arzamastseva                        'href'  => $href)));
4808e69fd30SKate Arzamastseva        $form->addElement($id);
48137a1dc12Smichael        $form->addElement(form_makeCloseTag('a'));
482652610a2Sandi
48337a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
48437a1dc12Smichael        $form->addElement(' &ndash; ');
485dad6764eSKate Arzamastseva        if (!$media_id) $form->addElement(htmlspecialchars($INFO['sum']));
48637a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
487652610a2Sandi
48837a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
489dad6764eSKate Arzamastseva        if (!$media_id) $editor = $INFO['editor'];
490dad6764eSKate Arzamastseva        else {
491dad6764eSKate Arzamastseva            $revinfo = getRevisionInfo($id, @filemtime(fullpath(mediaFN($id))), 1024, true);
492dad6764eSKate Arzamastseva            if($revinfo['user']){
493dad6764eSKate Arzamastseva                $editor = $revinfo['user'];
494dad6764eSKate Arzamastseva            }else{
495dad6764eSKate Arzamastseva                $editor = $revinfo['ip'];
496dad6764eSKate Arzamastseva            }
497dad6764eSKate Arzamastseva        }
498dad6764eSKate Arzamastseva        $form->addElement((empty($editor))?('('.$lang['external_edit'].')'):editorinfo($editor));
49937a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
50037a1dc12Smichael
50137a1dc12Smichael        $form->addElement('('.$lang['current'].')');
50237a1dc12Smichael        $form->addElement(form_makeCloseTag('div'));
50337a1dc12Smichael        $form->addElement(form_makeCloseTag('li'));
504f3f0262cSandi    }
505f3f0262cSandi
506f3f0262cSandi    foreach($revisions as $rev){
507f2263577SAndreas Gohr        $date = dformat($rev);
508dad6764eSKate Arzamastseva        if (!$media_id) {
5098e69fd30SKate Arzamastseva            $info = getRevisionInfo($id,$rev,true);
510dad6764eSKate Arzamastseva            $exists = page_exists($id,$rev);
511dad6764eSKate Arzamastseva        }  else {
512dad6764eSKate Arzamastseva            $info = getRevisionInfo($id,$rev,true,true);
513dad6764eSKate Arzamastseva            $exists = @file_exists(mediaFN($id,$rev));
514dad6764eSKate Arzamastseva        }
515652610a2Sandi
51637a1dc12Smichael        if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
51737a1dc12Smichael            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
51837a1dc12Smichael        else
51937a1dc12Smichael            $form->addElement(form_makeOpenTag('li'));
52037a1dc12Smichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
52177707b04SAndreas Gohr        if($exists){
52237a1dc12Smichael            $form->addElement(form_makeTag('input', array(
52337a1dc12Smichael                            'type' => 'checkbox',
52437a1dc12Smichael                            'name' => 'rev2[]',
52537a1dc12Smichael                            'value' => $rev)));
52677707b04SAndreas Gohr        }else{
527c2e73886SAnika Henke            $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
52841396b71SAndreas Gohr        }
529f9b2fe70Sandi
53037a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
53137a1dc12Smichael        $form->addElement($date);
53237a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
53337a1dc12Smichael
53437a1dc12Smichael        if($exists){
535dad6764eSKate Arzamastseva            if (!$media_id) $href = wl($id,"rev=$rev,do=diff", false, '&');
536*2e55802cSKate Arzamastseva            else $href = media_managerURL(array('image' => $id, 'rev' => $rev, 'mediado' => 'diff'));
537dad6764eSKate Arzamastseva            $form->addElement(form_makeOpenTag('a', array('href' => $href, 'class' => 'diff_link')));
53837a1dc12Smichael            $form->addElement(form_makeTag('img', array(
53937a1dc12Smichael                            'src'    => DOKU_BASE.'lib/images/diff.png',
54037a1dc12Smichael                            'width'  => 15,
54137a1dc12Smichael                            'height' => 11,
54237a1dc12Smichael                            'title'  => $lang['diff'],
54337a1dc12Smichael                            'alt'    => $lang['diff'])));
54437a1dc12Smichael            $form->addElement(form_makeCloseTag('a'));
545dad6764eSKate Arzamastseva            if (!$media_id) $href = wl($id,"rev=$rev",false,'&');
546dad6764eSKate Arzamastseva            else $href = media_managerURL(array('image' => $id, 'tab_details' => 'view', 'rev' => $rev));
547dad6764eSKate Arzamastseva            $form->addElement(form_makeOpenTag('a', array('href' => $href, 'class' => 'wikilink1')));
5488e69fd30SKate Arzamastseva            $form->addElement($id);
54937a1dc12Smichael            $form->addElement(form_makeCloseTag('a'));
55037a1dc12Smichael        }else{
551c2e73886SAnika Henke            $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
5528e69fd30SKate Arzamastseva            $form->addElement($id);
55337a1dc12Smichael        }
55437a1dc12Smichael
55537a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
55637a1dc12Smichael        $form->addElement(' &ndash; ');
55737a1dc12Smichael        $form->addElement(htmlspecialchars($info['sum']));
55837a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
55937a1dc12Smichael
56037a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
56188f522e9Sandi        if($info['user']){
56237a1dc12Smichael            $form->addElement(editorinfo($info['user']));
563433efb25SAndreas Gohr            if(auth_ismanager()){
564433efb25SAndreas Gohr                $form->addElement(' ('.$info['ip'].')');
565433efb25SAndreas Gohr            }
56688f522e9Sandi        }else{
56737a1dc12Smichael            $form->addElement($info['ip']);
56888f522e9Sandi        }
56937a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
570652610a2Sandi
57137a1dc12Smichael        $form->addElement(form_makeCloseTag('div'));
57237a1dc12Smichael        $form->addElement(form_makeCloseTag('li'));
573f3f0262cSandi    }
57437a1dc12Smichael    $form->addElement(form_makeCloseTag('ul'));
575*2e55802cSKate Arzamastseva    if (!$media_id) {
576*2e55802cSKate Arzamastseva        $form->addElement(form_makeButton('submit', 'diff', $lang['diff2']));
577*2e55802cSKate Arzamastseva    } else {
578*2e55802cSKate Arzamastseva        $form->addHidden('mediado', 'diff');
579*2e55802cSKate Arzamastseva        $form->addElement(form_makeButton('submit', '', $lang['diff2']));
580*2e55802cSKate Arzamastseva    }
58137a1dc12Smichael    html_form('revisions', $form);
58271726d78SBen Coburn
58371726d78SBen Coburn    print '<div class="pagenav">';
58471726d78SBen Coburn    $last = $first + $conf['recent'];
58571726d78SBen Coburn    if ($first > 0) {
58671726d78SBen Coburn        $first -= $conf['recent'];
58771726d78SBen Coburn        if ($first < 0) $first = 0;
58871726d78SBen Coburn        print '<div class="pagenav-prev">';
5898e69fd30SKate Arzamastseva        print html_btn('newer',$id,"p",array('do' => 'revisions', 'first' => $first));
59071726d78SBen Coburn        print '</div>';
59171726d78SBen Coburn    }
59271726d78SBen Coburn    if ($hasNext) {
59371726d78SBen Coburn        print '<div class="pagenav-next">';
5948e69fd30SKate Arzamastseva        print html_btn('older',$id,"n",array('do' => 'revisions', 'first' => $last));
59571726d78SBen Coburn        print '</div>';
59671726d78SBen Coburn    }
59771726d78SBen Coburn    print '</div>';
59871726d78SBen Coburn
599f3f0262cSandi}
600f3f0262cSandi
60115fae107Sandi/**
60215fae107Sandi * display recent changes
60315fae107Sandi *
60415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
6055749f1ceSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
60671726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
6078d40b4b6SKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
60815fae107Sandi */
6090739a638SKate Arzamastsevafunction html_recent($first=0, $show_changes='both'){
610f3f0262cSandi    global $conf;
611cffcc403Sandi    global $lang;
612dbb00abcSEsther Brunner    global $ID;
6135749f1ceSmatthiasgrimm    /* we need to get one additionally log entry to be able to
6145749f1ceSmatthiasgrimm     * decide if this is the last page or is there another one.
6155749f1ceSmatthiasgrimm     * This is the cheapest solution to get this information.
6165749f1ceSmatthiasgrimm     */
6170b926329SKate Arzamastseva    if (!$show_changes || $show_changes == 'both') $flags = RECENTS_MEDIA_PAGES_MIXED;
6180b926329SKate Arzamastseva    if ($show_changes == 'mediafiles') $flags = RECENTS_MEDIA_CHANGES;
6198d40b4b6SKate Arzamastseva    if ($show_changes == 'pages') $flags = 0;
6208d40b4b6SKate Arzamastseva
6218d40b4b6SKate Arzamastseva    $recents = getRecents($first,$conf['recent'] + 1,getNS($ID),$flags);
6225749f1ceSmatthiasgrimm    if(count($recents) == 0 && $first != 0){
6235749f1ceSmatthiasgrimm        $first=0;
6248d40b4b6SKate Arzamastseva        $recents = getRecents($first,$conf['recent'] + 1,getNS($ID),$flags);
6255749f1ceSmatthiasgrimm    }
62671726d78SBen Coburn    $hasNext = false;
62771726d78SBen Coburn    if (count($recents)>$conf['recent']) {
62871726d78SBen Coburn        $hasNext = true;
62971726d78SBen Coburn        array_pop($recents); // remove extra log entry
63071726d78SBen Coburn    }
631f3f0262cSandi
632c112d578Sandi    print p_locale_xhtml('recent');
633e83cef14SGina Haeussge
634e83cef14SGina Haeussge    if (getNS($ID) != '')
6359e561443SAndreas Gohr        print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>';
636e83cef14SGina Haeussge
637e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET'));
638abdcc39fSmichael    $form->addHidden('sectok', null);
639abdcc39fSmichael    $form->addHidden('do', 'recent');
640abdcc39fSmichael    $form->addHidden('id', $ID);
6418d40b4b6SKate Arzamastseva
6428d40b4b6SKate Arzamastseva    $form->addElement(form_makeOpenTag('div', array('class' => 'changestypenav')));
6438d40b4b6SKate Arzamastseva    $attrs = array('name' => 'show_changes',
6448d40b4b6SKate Arzamastseva                   'value' => 'pages',
6458d40b4b6SKate Arzamastseva                   '_text' => $lang['pages_changes']);
6468d40b4b6SKate Arzamastseva    if ($show_changes == 'pages') $attrs['checked'] = 'checked';
6478d40b4b6SKate Arzamastseva    $form->addElement(form_radiofield($attrs));
6488d40b4b6SKate Arzamastseva    $attrs = array('name' => 'show_changes',
6498d40b4b6SKate Arzamastseva                   'value' => 'mediafiles',
6508d40b4b6SKate Arzamastseva                   '_text' => $lang['media_changes']);
6518d40b4b6SKate Arzamastseva    if ($show_changes == 'mediafiles') $attrs['checked'] = 'checked';
6528d40b4b6SKate Arzamastseva    $form->addElement(form_radiofield($attrs));
6538d40b4b6SKate Arzamastseva    $attrs = array('name' => 'show_changes',
6548d40b4b6SKate Arzamastseva                   'value' => 'both',
6558d40b4b6SKate Arzamastseva                   '_text' => $lang['both_changes'] );
6568d40b4b6SKate Arzamastseva    if (empty($show_changes) || $show_changes == 'both') $attrs['checked'] = 'checked';
6578d40b4b6SKate Arzamastseva    $form->addElement(form_radiofield($attrs));
6588d40b4b6SKate Arzamastseva    $form->addElement(form_makeTag('input', array(
6598d40b4b6SKate Arzamastseva                    'type'  => 'submit',
6608d40b4b6SKate Arzamastseva                    'value' => $lang['btn_apply'],
6618d40b4b6SKate Arzamastseva                    'title' => $lang['btn_apply'],
6628d40b4b6SKate Arzamastseva                    'class' => 'button'
6638d40b4b6SKate Arzamastseva                    )));
6648d40b4b6SKate Arzamastseva    $form->addElement(form_makeCloseTag('div'));
6658d40b4b6SKate Arzamastseva
666abdcc39fSmichael    $form->addElement(form_makeOpenTag('ul'));
667a39955b0Smatthiasgrimm
668d437bcc4SAndreas Gohr    foreach($recents as $recent){
669f2263577SAndreas Gohr        $date = dformat($recent['date']);
670abdcc39fSmichael        if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
671abdcc39fSmichael            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
672abdcc39fSmichael        else
673abdcc39fSmichael            $form->addElement(form_makeOpenTag('li'));
674cffcc403Sandi
675abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
676f9b2fe70Sandi
677abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
678abdcc39fSmichael        $form->addElement($date);
679abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
680cffcc403Sandi
681cddd152cSmichael        $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => wl($recent['id'],"do=diff", false, '&'))));
682abdcc39fSmichael        $form->addElement(form_makeTag('img', array(
683abdcc39fSmichael                        'src'   => DOKU_BASE.'lib/images/diff.png',
684abdcc39fSmichael                        'width' => 15,
685abdcc39fSmichael                        'height'=> 11,
686abdcc39fSmichael                        'title' => $lang['diff'],
687abdcc39fSmichael                        'alt'   => $lang['diff']
688abdcc39fSmichael                        )));
689abdcc39fSmichael        $form->addElement(form_makeCloseTag('a'));
690cffcc403Sandi
691cddd152cSmichael        $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => wl($recent['id'],"do=revisions",false,'&'))));
692abdcc39fSmichael        $form->addElement(form_makeTag('img', array(
693abdcc39fSmichael                        'src'   => DOKU_BASE.'lib/images/history.png',
694abdcc39fSmichael                        'width' => 12,
695abdcc39fSmichael                        'height'=> 14,
696abdcc39fSmichael                        'title' => $lang['btn_revs'],
697abdcc39fSmichael                        'alt'   => $lang['btn_revs']
698abdcc39fSmichael                        )));
699abdcc39fSmichael        $form->addElement(form_makeCloseTag('a'));
700b6912aeaSAndreas Gohr
701db959ae3SAndreas Gohr        $form->addElement(html_wikilink(':'.$recent['id'],useHeading('navigation')?null:$recent['id']));
702abdcc39fSmichael
703abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
704abdcc39fSmichael        $form->addElement(' &ndash; '.htmlspecialchars($recent['sum']));
705abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
706abdcc39fSmichael
707abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
708d437bcc4SAndreas Gohr        if($recent['user']){
709abdcc39fSmichael            $form->addElement(editorinfo($recent['user']));
710433efb25SAndreas Gohr            if(auth_ismanager()){
711433efb25SAndreas Gohr                $form->addElement(' ('.$recent['ip'].')');
712433efb25SAndreas Gohr            }
71388f522e9Sandi        }else{
714abdcc39fSmichael            $form->addElement($recent['ip']);
71588f522e9Sandi        }
716abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
717cffcc403Sandi
718abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
719abdcc39fSmichael        $form->addElement(form_makeCloseTag('li'));
720f3f0262cSandi    }
721abdcc39fSmichael    $form->addElement(form_makeCloseTag('ul'));
722a39955b0Smatthiasgrimm
723abdcc39fSmichael    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
7245749f1ceSmatthiasgrimm    $last = $first + $conf['recent'];
725a39955b0Smatthiasgrimm    if ($first > 0) {
726a39955b0Smatthiasgrimm        $first -= $conf['recent'];
727a39955b0Smatthiasgrimm        if ($first < 0) $first = 0;
728abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
729abdcc39fSmichael        $form->addElement(form_makeTag('input', array(
730abdcc39fSmichael                    'type'  => 'submit',
731abdcc39fSmichael                    'name'  => 'first['.$first.']',
732cddd152cSmichael                    'value' => $lang['btn_newer'],
733cddd152cSmichael                    'accesskey' => 'n',
734f948eeabSMichael Klier                    'title' => $lang['btn_newer'].' [N]',
73518d107cbSMichael Klier                    'class' => 'button'
736abdcc39fSmichael                    )));
737abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
738a39955b0Smatthiasgrimm    }
73971726d78SBen Coburn    if ($hasNext) {
740abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
741abdcc39fSmichael        $form->addElement(form_makeTag('input', array(
742abdcc39fSmichael                        'type'  => 'submit',
743abdcc39fSmichael                        'name'  => 'first['.$last.']',
744cddd152cSmichael                        'value' => $lang['btn_older'],
745cddd152cSmichael                        'accesskey' => 'p',
746f948eeabSMichael Klier                        'title' => $lang['btn_older'].' [P]',
74718d107cbSMichael Klier                        'class' => 'button'
748abdcc39fSmichael                        )));
749abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
750a39955b0Smatthiasgrimm    }
751abdcc39fSmichael    $form->addElement(form_makeCloseTag('div'));
752abdcc39fSmichael    html_form('recent', $form);
753f3f0262cSandi}
754f3f0262cSandi
75515fae107Sandi/**
75615fae107Sandi * Display page index
75715fae107Sandi *
75815fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
75915fae107Sandi */
760f3f0262cSandifunction html_index($ns){
761f3f0262cSandi    global $conf;
762f3f0262cSandi    global $ID;
763f3f0262cSandi    $dir = $conf['datadir'];
764f3f0262cSandi    $ns  = cleanID($ns);
76530f1737dSandi    #fixme use appropriate function
766f3f0262cSandi    if(empty($ns)){
767f3f0262cSandi        $ns = dirname(str_replace(':','/',$ID));
768f3f0262cSandi        if($ns == '.') $ns ='';
769f3f0262cSandi    }
77088d3a917Sandi    $ns  = utf8_encodeFN(str_replace(':','/',$ns));
771f3f0262cSandi
772a06884abSAndreas Gohr    echo p_locale_xhtml('index');
773a06884abSAndreas Gohr    echo '<div id="index__tree">';
774f3f0262cSandi
775f3f0262cSandi    $data = array();
776f3f0262cSandi    search($data,$conf['datadir'],'search_index',array('ns' => $ns));
777a06884abSAndreas Gohr    echo html_buildlist($data,'idx','html_list_index','html_li_index');
778a06884abSAndreas Gohr
779a06884abSAndreas Gohr    echo '</div>';
780f3f0262cSandi}
781f3f0262cSandi
782f3f0262cSandi/**
78315fae107Sandi * Index item formatter
78415fae107Sandi *
785f3f0262cSandi * User function for html_buildlist()
78615fae107Sandi *
78715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
788f3f0262cSandi */
789f3f0262cSandifunction html_list_index($item){
790d98d4540SBen Coburn    global $ID;
791f3f0262cSandi    $ret = '';
792f3f0262cSandi    $base = ':'.$item['id'];
793f3f0262cSandi    $base = substr($base,strrpos($base,':')+1);
794f3f0262cSandi    if($item['type']=='d'){
7954a119027SAndreas Gohr        $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" class="idx_dir"><strong>';
796f3f0262cSandi        $ret .= $base;
797ed7ecb79SAnika Henke        $ret .= '</strong></a>';
798f3f0262cSandi    }else{
799f3f0262cSandi        $ret .= html_wikilink(':'.$item['id']);
800f3f0262cSandi    }
801f3f0262cSandi    return $ret;
802f3f0262cSandi}
803f3f0262cSandi
804f3f0262cSandi/**
805cb70c441Sandi * Index List item
806cb70c441Sandi *
807cb70c441Sandi * This user function is used in html_build_lidt to build the
808cb70c441Sandi * <li> tags for namespaces when displaying the page index
809cb70c441Sandi * it gives different classes to opened or closed "folders"
810cb70c441Sandi *
811cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
812cb70c441Sandi */
813cb70c441Sandifunction html_li_index($item){
814cb70c441Sandi    if($item['type'] == "f"){
815cb70c441Sandi        return '<li class="level'.$item['level'].'">';
816cb70c441Sandi    }elseif($item['open']){
817cb70c441Sandi        return '<li class="open">';
818cb70c441Sandi    }else{
819cb70c441Sandi        return '<li class="closed">';
820cb70c441Sandi    }
821cb70c441Sandi}
822cb70c441Sandi
823cb70c441Sandi/**
824cb70c441Sandi * Default List item
825cb70c441Sandi *
826cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
827cb70c441Sandi */
828cb70c441Sandifunction html_li_default($item){
829cb70c441Sandi    return '<li class="level'.$item['level'].'">';
830cb70c441Sandi}
831cb70c441Sandi
832cb70c441Sandi/**
83315fae107Sandi * Build an unordered list
83415fae107Sandi *
835f3f0262cSandi * Build an unordered list from the given $data array
836f3f0262cSandi * Each item in the array has to have a 'level' property
837f3f0262cSandi * the item itself gets printed by the given $func user
838cb70c441Sandi * function. The second and optional function is used to
839cb70c441Sandi * print the <li> tag. Both user function need to accept
840cb70c441Sandi * a single item.
84115fae107Sandi *
842c5a8fd96SAndreas Gohr * Both user functions can be given as array to point to
843c5a8fd96SAndreas Gohr * a member of an object.
844c5a8fd96SAndreas Gohr *
84515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
846f3f0262cSandi */
847cb70c441Sandifunction html_buildlist($data,$class,$func,$lifunc='html_li_default'){
848f3f0262cSandi    $level = 0;
849f3f0262cSandi    $opens = 0;
850f3f0262cSandi    $ret   = '';
851f3f0262cSandi
852f3f0262cSandi    foreach ($data as $item){
853f3f0262cSandi
854f3f0262cSandi        if( $item['level'] > $level ){
855f3f0262cSandi            //open new list
856df52d0feSandi            for($i=0; $i<($item['level'] - $level); $i++){
857df52d0feSandi                if ($i) $ret .= "<li class=\"clear\">\n";
858f3f0262cSandi                $ret .= "\n<ul class=\"$class\">\n";
859df52d0feSandi            }
860f3f0262cSandi        }elseif( $item['level'] < $level ){
861f3f0262cSandi            //close last item
862f3f0262cSandi            $ret .= "</li>\n";
863f3f0262cSandi            for ($i=0; $i<($level - $item['level']); $i++){
864f3f0262cSandi                //close higher lists
865f3f0262cSandi                $ret .= "</ul>\n</li>\n";
866f3f0262cSandi            }
867f3f0262cSandi        }else{
868f3f0262cSandi            //close last item
869f3f0262cSandi            $ret .= "</li>\n";
870f3f0262cSandi        }
871f3f0262cSandi
872f3f0262cSandi        //remember current level
873f3f0262cSandi        $level = $item['level'];
874f3f0262cSandi
875f3f0262cSandi        //print item
87634dbe711Schris        $ret .= call_user_func($lifunc,$item);
8770c6b58a8SAndreas Gohr        $ret .= '<div class="li">';
87834dbe711Schris
87934dbe711Schris        $ret .= call_user_func($func,$item);
8800c6b58a8SAndreas Gohr        $ret .= '</div>';
881f3f0262cSandi    }
882f3f0262cSandi
883f3f0262cSandi    //close remaining items and lists
884f3f0262cSandi    for ($i=0; $i < $level; $i++){
885f3f0262cSandi        $ret .= "</li></ul>\n";
886f3f0262cSandi    }
887f3f0262cSandi
888f3f0262cSandi    return $ret;
889f3f0262cSandi}
890f3f0262cSandi
89115fae107Sandi/**
89215fae107Sandi * display backlinks
89315fae107Sandi *
89415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
89511df47ecSMichael Klier * @author Michael Klier <chi@chimeric.de>
89615fae107Sandi */
897f3f0262cSandifunction html_backlinks(){
898f3f0262cSandi    global $ID;
899f3f0262cSandi    global $conf;
90011df47ecSMichael Klier    global $lang;
901f3f0262cSandi
902c112d578Sandi    print p_locale_xhtml('backlinks');
903f3f0262cSandi
90454f4c056SAndreas Gohr    $data = ft_backlinks($ID);
905f3f0262cSandi
90611df47ecSMichael Klier    if(!empty($data)) {
907f3f0262cSandi        print '<ul class="idx">';
90854f4c056SAndreas Gohr        foreach($data as $blink){
9090c6b58a8SAndreas Gohr            print '<li><div class="li">';
910db959ae3SAndreas Gohr            print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink);
9110c6b58a8SAndreas Gohr            print '</div></li>';
912f3f0262cSandi        }
913f3f0262cSandi        print '</ul>';
91411df47ecSMichael Klier    } else {
91511df47ecSMichael Klier        print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
91611df47ecSMichael Klier    }
917f3f0262cSandi}
918f3f0262cSandi
91915fae107Sandi/**
92015fae107Sandi * show diff
92115fae107Sandi *
92215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
92372165381SAndreas Gohr * @param  string $text - compare with this text with most current version
92472165381SAndreas Gohr * @param  bool   $intr - display the intro text
92515fae107Sandi */
92672165381SAndreas Gohrfunction html_diff($text='',$intro=true,$type=null){
927f3f0262cSandi    global $ID;
928f3f0262cSandi    global $REV;
929f3f0262cSandi    global $lang;
930f3f0262cSandi    global $conf;
931e1bd90ffSAndreas Gohr
93272165381SAndreas Gohr    if(!$type) $type = $_REQUEST['difftype'];
93372165381SAndreas Gohr    if($type != 'inline') $type = 'sidebyside';
93472165381SAndreas Gohr
93577707b04SAndreas Gohr    // we're trying to be clever here, revisions to compare can be either
93677707b04SAndreas Gohr    // given as rev and rev2 parameters, with rev2 being optional. Or in an
93777707b04SAndreas Gohr    // array in rev2.
93877707b04SAndreas Gohr    $rev1 = $REV;
9397b3f8b16SAndreas Gohr
94077707b04SAndreas Gohr    if(is_array($_REQUEST['rev2'])){
94177707b04SAndreas Gohr        $rev1 = (int) $_REQUEST['rev2'][0];
94277707b04SAndreas Gohr        $rev2 = (int) $_REQUEST['rev2'][1];
94354041c77SAndreas Gohr
94454041c77SAndreas Gohr        if(!$rev1){
94554041c77SAndreas Gohr            $rev1 = $rev2;
94654041c77SAndreas Gohr            unset($rev2);
94754041c77SAndreas Gohr        }
948f3f0262cSandi    }else{
94977707b04SAndreas Gohr        $rev2 = (int) $_REQUEST['rev2'];
9504d58bd99Sandi    }
9514d58bd99Sandi
9523733161eSAdrian Lang    $r_minor = '';
9533733161eSAdrian Lang    $l_minor = '';
9543733161eSAdrian Lang
95577707b04SAndreas Gohr    if($text){                      // compare text to the most current revision
95677707b04SAndreas Gohr        $l_rev   = '';
95777707b04SAndreas Gohr        $l_text  = rawWiki($ID,'');
95877707b04SAndreas Gohr        $l_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
959f2263577SAndreas Gohr            $ID.' '.dformat((int) @filemtime(wikiFN($ID))).'</a> '.
96077707b04SAndreas Gohr            $lang['current'];
96177707b04SAndreas Gohr
96277707b04SAndreas Gohr        $r_rev   = '';
96377707b04SAndreas Gohr        $r_text  = cleanText($text);
96477707b04SAndreas Gohr        $r_head  = $lang['yours'];
965e1bd90ffSAndreas Gohr    }else{
96677707b04SAndreas Gohr        if($rev1 && $rev2){            // two specific revisions wanted
96754041c77SAndreas Gohr            // make sure order is correct (older on the left)
96877707b04SAndreas Gohr            if($rev1 < $rev2){
96977707b04SAndreas Gohr                $l_rev = $rev1;
97077707b04SAndreas Gohr                $r_rev = $rev2;
97177707b04SAndreas Gohr            }else{
97277707b04SAndreas Gohr                $l_rev = $rev2;
97377707b04SAndreas Gohr                $r_rev = $rev1;
974e1bd90ffSAndreas Gohr            }
97577707b04SAndreas Gohr        }elseif($rev1){                // single revision given, compare to current
97677707b04SAndreas Gohr            $r_rev = '';
97777707b04SAndreas Gohr            $l_rev = $rev1;
97877707b04SAndreas Gohr        }else{                        // no revision was given, compare previous to current
97977707b04SAndreas Gohr            $r_rev = '';
98077707b04SAndreas Gohr            $revs = getRevisions($ID, 0, 1);
98177707b04SAndreas Gohr            $l_rev = $revs[0];
9826f8e9f59SAndreas Gohr            $REV = $l_rev; // store revision back in $REV
98377707b04SAndreas Gohr        }
98477707b04SAndreas Gohr
9857b3f8b16SAndreas Gohr        // when both revisions are empty then the page was created just now
9867b3f8b16SAndreas Gohr        if(!$l_rev && !$r_rev){
9877b3f8b16SAndreas Gohr            $l_text = '';
9887b3f8b16SAndreas Gohr        }else{
98977707b04SAndreas Gohr            $l_text = rawWiki($ID,$l_rev);
9907b3f8b16SAndreas Gohr        }
99177707b04SAndreas Gohr        $r_text = rawWiki($ID,$r_rev);
99277707b04SAndreas Gohr
9937b3f8b16SAndreas Gohr        if(!$l_rev){
9947b3f8b16SAndreas Gohr            $l_head = '&mdash;';
9957b3f8b16SAndreas Gohr        }else{
996e5e61eb0SAnika Henke            $l_info   = getRevisionInfo($ID,$l_rev,true);
997db959ae3SAndreas Gohr            if($l_info['user']){
998db959ae3SAndreas Gohr                $l_user = editorinfo($l_info['user']);
999e5e61eb0SAnika Henke                if(auth_ismanager()) $l_user .= ' ('.$l_info['ip'].')';
1000db959ae3SAndreas Gohr            } else {
1001db959ae3SAndreas Gohr                $l_user = $l_info['ip'];
1002db959ae3SAndreas Gohr            }
1003e5e61eb0SAnika Henke            $l_user  = '<span class="user">'.$l_user.'</span>';
1004e5e61eb0SAnika Henke            $l_sum   = ($l_info['sum']) ? '<span class="sum">'.hsc($l_info['sum']).'</span>' : '';
1005e5e61eb0SAnika Henke            if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
1006e5e61eb0SAnika Henke
100777707b04SAndreas Gohr            $l_head = '<a class="wikilink1" href="'.wl($ID,"rev=$l_rev").'">'.
1008f2263577SAndreas Gohr            $ID.' ['.dformat($l_rev).']</a>'.
1009e5e61eb0SAnika Henke            '<br />'.$l_user.' '.$l_sum;
10107b3f8b16SAndreas Gohr        }
101177707b04SAndreas Gohr
1012820923f1SMichael Hamann        if($r_rev){
1013820923f1SMichael Hamann            $r_info   = getRevisionInfo($ID,$r_rev,true);
1014db959ae3SAndreas Gohr            if($r_info['user']){
1015db959ae3SAndreas Gohr                $r_user = editorinfo($r_info['user']);
1016e5e61eb0SAnika Henke                if(auth_ismanager()) $r_user .= ' ('.$r_info['ip'].')';
1017db959ae3SAndreas Gohr            } else {
1018db959ae3SAndreas Gohr                $r_user = $r_info['ip'];
1019db959ae3SAndreas Gohr            }
1020e5e61eb0SAnika Henke            $r_user = '<span class="user">'.$r_user.'</span>';
1021e5e61eb0SAnika Henke            $r_sum  = ($r_info['sum']) ? '<span class="sum">'.hsc($r_info['sum']).'</span>' : '';
1022e5e61eb0SAnika Henke            if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
1023e5e61eb0SAnika Henke
102477707b04SAndreas Gohr            $r_head = '<a class="wikilink1" href="'.wl($ID,"rev=$r_rev").'">'.
1025f2263577SAndreas Gohr            $ID.' ['.dformat($r_rev).']</a>'.
1026e5e61eb0SAnika Henke            '<br />'.$r_user.' '.$r_sum;
10277b3f8b16SAndreas Gohr        }elseif($_rev = @filemtime(wikiFN($ID))){
1028e5e61eb0SAnika Henke            $_info   = getRevisionInfo($ID,$_rev,true);
1029db959ae3SAndreas Gohr            if($_info['user']){
1030db959ae3SAndreas Gohr                $_user = editorinfo($_info['user']);
1031e5e61eb0SAnika Henke                if(auth_ismanager()) $_user .= ' ('.$_info['ip'].')';
1032db959ae3SAndreas Gohr            } else {
1033db959ae3SAndreas Gohr                $_user = $_info['ip'];
1034db959ae3SAndreas Gohr            }
1035e5e61eb0SAnika Henke            $_user = '<span class="user">'.$_user.'</span>';
1036e5e61eb0SAnika Henke            $_sum  = ($_info['sum']) ? '<span class="sum">'.hsc($_info['sum']).'</span>' : '';
1037e5e61eb0SAnika Henke            if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
1038e5e61eb0SAnika Henke
103977707b04SAndreas Gohr            $r_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
1040f2263577SAndreas Gohr            $ID.' ['.dformat($_rev).']</a> '.
1041658b1aa0SAnika Henke            '('.$lang['current'].')'.
1042e5e61eb0SAnika Henke            '<br />'.$_user.' '.$_sum;
10437b3f8b16SAndreas Gohr        }else{
1044658b1aa0SAnika Henke            $r_head = '&mdash; ('.$lang['current'].')';
1045f3f0262cSandi        }
104677707b04SAndreas Gohr    }
104777707b04SAndreas Gohr
104877707b04SAndreas Gohr    $df = new Diff(explode("\n",htmlspecialchars($l_text)),
104977707b04SAndreas Gohr        explode("\n",htmlspecialchars($r_text)));
105077707b04SAndreas Gohr
105172165381SAndreas Gohr    if($type == 'inline'){
105272165381SAndreas Gohr        $tdf = new InlineDiffFormatter();
105372165381SAndreas Gohr    } else {
1054f3f0262cSandi        $tdf = new TableDiffFormatter();
105572165381SAndreas Gohr    }
105672165381SAndreas Gohr
105772165381SAndreas Gohr
105872165381SAndreas Gohr
1059c112d578Sandi    if($intro) print p_locale_xhtml('diff');
1060226bf2dcSGina Haeussge
1061226bf2dcSGina Haeussge    if (!$text) {
1062e8af313fSAnika Henke        ptln('<div class="diffoptions">');
106372165381SAndreas Gohr
106472165381SAndreas Gohr        $form = new Doku_Form(array('action'=>wl()));
10651b885c58SAndreas Gohr        $form->addHidden('id',$ID);
106672165381SAndreas Gohr        $form->addHidden('rev2[0]',$l_rev);
106772165381SAndreas Gohr        $form->addHidden('rev2[1]',$r_rev);
106872165381SAndreas Gohr        $form->addHidden('do','diff');
106972165381SAndreas Gohr        $form->addElement(form_makeListboxField(
107072165381SAndreas Gohr                            'difftype',
107172165381SAndreas Gohr                            array(
107272165381SAndreas Gohr                                'sidebyside' => $lang['diff_side'],
107372165381SAndreas Gohr                                'inline'     => $lang['diff_inline']),
107472165381SAndreas Gohr                            $type,
107572165381SAndreas Gohr                            $lang['diff_type'],
107672165381SAndreas Gohr                            '','',
107772165381SAndreas Gohr                            array('class'=>'quickselect')));
107872165381SAndreas Gohr        $form->addElement(form_makeButton('submit', 'diff','Go'));
107972165381SAndreas Gohr        $form->printForm();
108072165381SAndreas Gohr
108172165381SAndreas Gohr
108272165381SAndreas Gohr        $diffurl = wl($ID, array(
108372165381SAndreas Gohr                        'do'       => 'diff',
108472165381SAndreas Gohr                        'rev2[0]'  => $l_rev,
108572165381SAndreas Gohr                        'rev2[1]'  => $r_rev,
108672165381SAndreas Gohr                        'difftype' => $type,
108772165381SAndreas Gohr                      ));
1088e8af313fSAnika Henke        ptln('<p><a class="wikilink1" href="'.$diffurl.'">'.$lang['difflink'].'</a></p>');
1089e8af313fSAnika Henke        ptln('</div>');
1090226bf2dcSGina Haeussge    }
1091f3f0262cSandi    ?>
109272165381SAndreas Gohr    <table class="diff diff_<?php echo $type?>">
1093f3f0262cSandi    <tr>
1094e5e61eb0SAnika Henke    <th colspan="2" <?php echo $l_minor?>>
109577707b04SAndreas Gohr    <?php echo $l_head?>
1096daf4ca4eSAnika Henke    </th>
1097e5e61eb0SAnika Henke    <th colspan="2" <?php echo $r_minor?>>
109877707b04SAndreas Gohr    <?php echo $r_head?>
1099daf4ca4eSAnika Henke    </th>
1100f3f0262cSandi    </tr>
11014da078a3Smatthiasgrimm    <?php echo $tdf->format($df)?>
1102f3f0262cSandi    </table>
11034da078a3Smatthiasgrimm    <?php
1104f3f0262cSandi}
1105f3f0262cSandi
110615fae107Sandi/**
110715fae107Sandi * show warning on conflict detection
110815fae107Sandi *
110915fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
111015fae107Sandi */
1111f3f0262cSandifunction html_conflict($text,$summary){
1112f3f0262cSandi    global $ID;
1113f3f0262cSandi    global $lang;
1114f3f0262cSandi
1115c112d578Sandi    print p_locale_xhtml('conflict');
1116e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
1117fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
1118fdb8d77bSTom N Harris    $form->addHidden('wikitext', $text);
1119fdb8d77bSTom N Harris    $form->addHidden('summary', $summary);
1120fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
1121fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
1122fdb8d77bSTom N Harris    html_form('conflict', $form);
1123fdb8d77bSTom N Harris    print '<br /><br /><br /><br />'.NL;
1124f3f0262cSandi}
1125f3f0262cSandi
1126f3f0262cSandi/**
112715fae107Sandi * Prints the global message array
112815fae107Sandi *
112915fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1130f3f0262cSandi */
1131f3f0262cSandifunction html_msgarea(){
1132cc58224cSMichael Hamann    global $MSG, $MSG_shown;
1133cc58224cSMichael Hamann    // store if the global $MSG has already been shown and thus HTML output has been started
1134cc58224cSMichael Hamann    $MSG_shown = true;
1135cc58224cSMichael Hamann
1136f3f0262cSandi    if(!isset($MSG)) return;
1137f3f0262cSandi
11384af9f0d4SAndreas Gohr    $shown = array();
1139f3f0262cSandi    foreach($MSG as $msg){
11404af9f0d4SAndreas Gohr        $hash = md5($msg['msg']);
11414af9f0d4SAndreas Gohr        if(isset($shown[$hash])) continue; // skip double messages
1142f3f0262cSandi        print '<div class="'.$msg['lvl'].'">';
1143f3f0262cSandi        print $msg['msg'];
1144f3f0262cSandi        print '</div>';
11454af9f0d4SAndreas Gohr        $shown[$hash] = 1;
1146f3f0262cSandi    }
1147cc58224cSMichael Hamann
1148cc58224cSMichael Hamann    unset($GLOBALS['MSG']);
1149f3f0262cSandi}
1150f3f0262cSandi
1151f3f0262cSandi/**
1152f3f0262cSandi * Prints the registration form
115315fae107Sandi *
115415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1155f3f0262cSandi */
1156f3f0262cSandifunction html_register(){
1157f3f0262cSandi    global $lang;
1158cab2716aSmatthias.grimm    global $conf;
1159f3f0262cSandi    global $ID;
1160f3f0262cSandi
1161c112d578Sandi    print p_locale_xhtml('register');
1162fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1163e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__register'));
1164bf413a4eSAnika Henke    $form->startFieldset($lang['btn_register']);
1165fdb8d77bSTom N Harris    $form->addHidden('do', 'register');
1166fdb8d77bSTom N Harris    $form->addHidden('save', '1');
116790f84a7bSAnika Henke    $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block', array('size'=>'50')));
1168cab2716aSmatthias.grimm    if (!$conf['autopasswd']) {
1169fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
1170fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1171cab2716aSmatthias.grimm    }
1172fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', array('size'=>'50')));
1173fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', array('size'=>'50')));
1174bf413a4eSAnika Henke    $form->addElement(form_makeButton('submit', '', $lang['btn_register']));
1175fdb8d77bSTom N Harris    $form->endFieldset();
1176fdb8d77bSTom N Harris    html_form('register', $form);
1177cab2716aSmatthias.grimm
1178fdb8d77bSTom N Harris    print '</div>'.NL;
1179f3f0262cSandi}
1180f3f0262cSandi
1181f3f0262cSandi/**
11828b06d178Schris * Print the update profile form
11838b06d178Schris *
11848b06d178Schris * @author Christopher Smith <chris@jalakai.co.uk>
11858b06d178Schris * @author Andreas Gohr <andi@splitbrain.org>
11868b06d178Schris */
11878b06d178Schrisfunction html_updateprofile(){
11888b06d178Schris    global $lang;
11898b06d178Schris    global $conf;
11908b06d178Schris    global $ID;
11918b06d178Schris    global $INFO;
119282fd59b6SAndreas Gohr    global $auth;
11938b06d178Schris
11948b06d178Schris    print p_locale_xhtml('updateprofile');
11958b06d178Schris
11968b06d178Schris    if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
11978b06d178Schris    if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
1198fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1199e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__register'));
1200fdb8d77bSTom N Harris    $form->startFieldset($lang['profile']);
1201fdb8d77bSTom N Harris    $form->addHidden('do', 'profile');
1202fdb8d77bSTom N Harris    $form->addHidden('save', '1');
1203fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('fullname', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
1204fdb8d77bSTom N Harris    $attr = array('size'=>'50');
1205fdb8d77bSTom N Harris    if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1206fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', $attr));
120739ba8890SAndreas Gohr    $attr = array('size'=>'50');
120839ba8890SAndreas Gohr    if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
1209fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', $attr));
1210fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1211fdb8d77bSTom N Harris    if ($auth->canDo('modPass')) {
1212fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1213fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1214fdb8d77bSTom N Harris    }
1215fdb8d77bSTom N Harris    if ($conf['profileconfirm']) {
1216fdb8d77bSTom N Harris        $form->addElement(form_makeTag('br'));
1217fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50')));
1218fdb8d77bSTom N Harris    }
1219fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1220fdb8d77bSTom N Harris    $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
1221fdb8d77bSTom N Harris    $form->endFieldset();
1222fdb8d77bSTom N Harris    html_form('updateprofile', $form);
1223fdb8d77bSTom N Harris    print '</div>'.NL;
12248b06d178Schris}
12258b06d178Schris
12268b06d178Schris/**
12277c4635c4SAdrian Lang * Preprocess edit form data
122815fae107Sandi *
122915fae107Sandi * @author   Andreas Gohr <andi@splitbrain.org>
12302ffea8f2SAdrian Lang *
12312ffea8f2SAdrian Lang * @triggers HTML_EDITFORM_OUTPUT
1232f3f0262cSandi */
12335a932e77SAdrian Langfunction html_edit(){
1234f3f0262cSandi    global $ID;
1235f3f0262cSandi    global $REV;
1236f3f0262cSandi    global $DATE;
1237f3f0262cSandi    global $PRE;
1238f3f0262cSandi    global $SUF;
1239f3f0262cSandi    global $INFO;
1240f3f0262cSandi    global $SUM;
1241f3f0262cSandi    global $lang;
1242f3f0262cSandi    global $conf;
124345a99335SAdrian Lang    global $TEXT;
1244d141c8dcSAdrian Lang    global $RANGE;
1245f3f0262cSandi
12468fe3bb00STom N Harris    if (isset($_REQUEST['changecheck'])) {
12478fe3bb00STom N Harris        $check = $_REQUEST['changecheck'];
124845a99335SAdrian Lang    } elseif(!$INFO['exists']){
124945a99335SAdrian Lang        // $TEXT has been loaded from page template
125045a99335SAdrian Lang        $check = md5('');
12518fe3bb00STom N Harris    } else {
125245a99335SAdrian Lang        $check = md5($TEXT);
12538fe3bb00STom N Harris    }
125445a99335SAdrian Lang    $mod = md5($TEXT) !== $check;
1255f3f0262cSandi
125627eb9321SAnika Henke    $wr = $INFO['writable'] && !$INFO['locked'];
125745a99335SAdrian Lang    $include = 'edit';
1258f3f0262cSandi    if($wr){
1259ffde0ac9SAdrian Lang        if ($REV) $include = 'editrev';
1260f3f0262cSandi    }else{
1261409d7af7SAndreas Gohr        // check pseudo action 'source'
1262409d7af7SAndreas Gohr        if(!actionOK('source')){
1263409d7af7SAndreas Gohr            msg('Command disabled: source',-1);
1264409d7af7SAndreas Gohr            return;
1265409d7af7SAndreas Gohr        }
1266ffde0ac9SAdrian Lang        $include = 'read';
1267f3f0262cSandi    }
12687c4635c4SAdrian Lang
12697c4635c4SAdrian Lang    global $license;
127042c7abd6SAndreas Gohr
1271e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
1272fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
1273fdb8d77bSTom N Harris    $form->addHidden('rev', $REV);
1274fdb8d77bSTom N Harris    $form->addHidden('date', $DATE);
127542de51b1SAdrian Lang    $form->addHidden('prefix', $PRE . '.');
1276fdb8d77bSTom N Harris    $form->addHidden('suffix', $SUF);
1277fdb8d77bSTom N Harris    $form->addHidden('changecheck', $check);
12788e4da260SAdrian Lang
12792ffea8f2SAdrian Lang    $data = array('form' => $form,
12802ffea8f2SAdrian Lang                  'wr'   => $wr,
12812ffea8f2SAdrian Lang                  'media_manager' => true,
128212c96aceSAdrian Lang                  'target' => (isset($_REQUEST['target']) && $wr &&
128312c96aceSAdrian Lang                               $RANGE !== '') ? $_REQUEST['target'] : 'section',
12842ffea8f2SAdrian Lang                  'intro_locale' => $include);
128512c96aceSAdrian Lang
128612c96aceSAdrian Lang    if ($data['target'] !== 'section') {
128712c96aceSAdrian Lang        // Only emit event if page is writable, section edit data is valid and
128812c96aceSAdrian Lang        // edit target is not section.
12898e4da260SAdrian Lang        trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true);
12902ffea8f2SAdrian Lang    } else {
12912ffea8f2SAdrian Lang        html_edit_form($data);
12922ffea8f2SAdrian Lang    }
1293ffde0ac9SAdrian Lang    if (isset($data['intro_locale'])) {
1294ffde0ac9SAdrian Lang        echo p_locale_xhtml($data['intro_locale']);
1295ffde0ac9SAdrian Lang    }
12968e4da260SAdrian Lang
1297b7eccc60SAdrian Lang    $form->addHidden('target', $data['target']);
1298fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar')));
1299fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1300fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
1301fdb8d77bSTom N Harris    if ($wr) {
1302fdb8d77bSTom N Harris        $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
1303fdb8d77bSTom N Harris        $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
1304fdb8d77bSTom N Harris        $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
1305fdb8d77bSTom N Harris        $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
1306fdb8d77bSTom N Harris        $form->addElement(form_makeCloseTag('div'));
1307fdb8d77bSTom N Harris        $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
1308fdb8d77bSTom N Harris        $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
1309fdb8d77bSTom N Harris        $elem = html_minoredit();
1310fdb8d77bSTom N Harris        if ($elem) $form->addElement($elem);
1311fdb8d77bSTom N Harris        $form->addElement(form_makeCloseTag('div'));
1312fdb8d77bSTom N Harris    }
1313fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
13145808bc54SAndreas Gohr    if($wr && $conf['license']){
1315066fee30SAndreas Gohr        $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1316066fee30SAndreas Gohr        $out  = $lang['licenseok'];
1317066fee30SAndreas Gohr        $out .= ' <a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
131884645d8cSAndreas Gohr        if(isset($conf['target']['extern'])) $out .= ' target="'.$conf['target']['extern'].'"';
1319066fee30SAndreas Gohr        $out .= '>'.$license[$conf['license']]['name'].'</a>';
1320066fee30SAndreas Gohr        $form->addElement($out);
1321066fee30SAndreas Gohr        $form->addElement(form_makeCloseTag('div'));
1322066fee30SAndreas Gohr    }
13238e4da260SAdrian Lang
13248e4da260SAdrian Lang    if ($wr) {
13258e4da260SAdrian Lang        // sets changed to true when previewed
13262e61e4dfSAdrian Lang        echo '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'. NL;
13278e4da260SAdrian Lang        echo 'textChanged = ' . ($mod ? 'true' : 'false');
13282e61e4dfSAdrian Lang        echo '//--><!]]></script>' . NL;
13298e4da260SAdrian Lang    } ?>
13308e4da260SAdrian Lang    <div style="width:99%;">
13318e4da260SAdrian Lang
13328e4da260SAdrian Lang    <div class="toolbar">
13338e4da260SAdrian Lang    <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div>
13348e4da260SAdrian Lang    <div id="tool__bar"><?php if ($wr && $data['media_manager']){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
13358e4da260SAdrian Lang        target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
13368e4da260SAdrian Lang
13378e4da260SAdrian Lang    </div>
13388e4da260SAdrian Lang    <?php
13398e4da260SAdrian Lang
1340fdb8d77bSTom N Harris    html_form('edit', $form);
1341fdb8d77bSTom N Harris    print '</div>'.NL;
1342f3f0262cSandi}
1343f3f0262cSandi
1344f3f0262cSandi/**
13458e4da260SAdrian Lang * Display the default edit form
13468e4da260SAdrian Lang *
13478e4da260SAdrian Lang * Is the default action for HTML_EDIT_FORMSELECTION.
13488e4da260SAdrian Lang */
13498e4da260SAdrian Langfunction html_edit_form($param) {
135045a99335SAdrian Lang    global $TEXT;
135112c96aceSAdrian Lang
135212c96aceSAdrian Lang    if ($param['target'] !== 'section') {
135312c96aceSAdrian Lang        msg('No editor for edit target ' . $param['target'] . ' found.', -1);
135412c96aceSAdrian Lang    }
135512c96aceSAdrian Lang
13568e4da260SAdrian Lang    $attr = array('tabindex'=>'1');
135712c96aceSAdrian Lang    if (!$param['wr']) $attr['readonly'] = 'readonly';
135812c96aceSAdrian Lang
135912c96aceSAdrian Lang    $param['form']->addElement(form_makeWikiText($TEXT, $attr));
13608e4da260SAdrian Lang}
13618e4da260SAdrian Lang
13628e4da260SAdrian Lang/**
1363b6912aeaSAndreas Gohr * Adds a checkbox for minor edits for logged in users
1364b6912aeaSAndreas Gohr *
1365b1f92db2SAdrian Lang * @author Andreas Gohr <andi@splitbrain.org>
1366b6912aeaSAndreas Gohr */
1367b6912aeaSAndreas Gohrfunction html_minoredit(){
1368b6912aeaSAndreas Gohr    global $conf;
1369b6912aeaSAndreas Gohr    global $lang;
1370b6912aeaSAndreas Gohr    // minor edits are for logged in users only
1371b6912aeaSAndreas Gohr    if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1372fdb8d77bSTom N Harris        return false;
1373b6912aeaSAndreas Gohr    }
1374b6912aeaSAndreas Gohr
1375b6912aeaSAndreas Gohr    $p = array();
1376b6912aeaSAndreas Gohr    $p['tabindex'] = 3;
1377bb4866bdSchris    if(!empty($_REQUEST['minor'])) $p['checked']='checked';
1378fdb8d77bSTom N Harris    return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
1379b6912aeaSAndreas Gohr}
1380b6912aeaSAndreas Gohr
1381b6912aeaSAndreas Gohr/**
1382f3f0262cSandi * prints some debug info
138315fae107Sandi *
138415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1385f3f0262cSandi */
1386f3f0262cSandifunction html_debug(){
1387f3f0262cSandi    global $conf;
1388d16a4edaSandi    global $lang;
13895298a619SAndreas Gohr    global $auth;
1390100a97e3SAndreas Gohr    global $INFO;
1391100a97e3SAndreas Gohr
139228fb55ffSandi    //remove sensitive data
139328fb55ffSandi    $cnf = $conf;
139424297a69SAndreas Gohr    debug_guard($cnf);
1395100a97e3SAndreas Gohr    $nfo = $INFO;
139624297a69SAndreas Gohr    debug_guard($nfo);
1397100a97e3SAndreas Gohr    $ses = $_SESSION;
139824297a69SAndreas Gohr    debug_guard($ses);
1399f3f0262cSandi
1400f3f0262cSandi    print '<html><body>';
1401f3f0262cSandi
1402f3f0262cSandi    print '<p>When reporting bugs please send all the following ';
1403f3f0262cSandi    print 'output as a mail to andi@splitbrain.org ';
1404f3f0262cSandi    print 'The best way to do this is to save this page in your browser</p>';
1405f3f0262cSandi
1406100a97e3SAndreas Gohr    print '<b>$INFO:</b><pre>';
1407100a97e3SAndreas Gohr    print_r($nfo);
1408100a97e3SAndreas Gohr    print '</pre>';
1409100a97e3SAndreas Gohr
1410f3f0262cSandi    print '<b>$_SERVER:</b><pre>';
1411f3f0262cSandi    print_r($_SERVER);
1412f3f0262cSandi    print '</pre>';
1413f3f0262cSandi
1414f3f0262cSandi    print '<b>$conf:</b><pre>';
141528fb55ffSandi    print_r($cnf);
1416f3f0262cSandi    print '</pre>';
1417f3f0262cSandi
1418ed7b5f09Sandi    print '<b>DOKU_BASE:</b><pre>';
1419ed7b5f09Sandi    print DOKU_BASE;
1420f3f0262cSandi    print '</pre>';
1421f3f0262cSandi
1422ed7b5f09Sandi    print '<b>abs DOKU_BASE:</b><pre>';
1423ed7b5f09Sandi    print DOKU_URL;
1424ed7b5f09Sandi    print '</pre>';
1425ed7b5f09Sandi
1426ed7b5f09Sandi    print '<b>rel DOKU_BASE:</b><pre>';
1427f3f0262cSandi    print dirname($_SERVER['PHP_SELF']).'/';
1428f3f0262cSandi    print '</pre>';
1429f3f0262cSandi
1430f3f0262cSandi    print '<b>PHP Version:</b><pre>';
1431f3f0262cSandi    print phpversion();
1432f3f0262cSandi    print '</pre>';
1433f3f0262cSandi
1434f3f0262cSandi    print '<b>locale:</b><pre>';
1435f3f0262cSandi    print setlocale(LC_ALL,0);
1436f3f0262cSandi    print '</pre>';
1437f3f0262cSandi
1438d16a4edaSandi    print '<b>encoding:</b><pre>';
1439d16a4edaSandi    print $lang['encoding'];
1440d16a4edaSandi    print '</pre>';
1441d16a4edaSandi
14425298a619SAndreas Gohr    if($auth){
14435298a619SAndreas Gohr        print '<b>Auth backend capabilities:</b><pre>';
14445298a619SAndreas Gohr        print_r($auth->cando);
14455298a619SAndreas Gohr        print '</pre>';
14465298a619SAndreas Gohr    }
14475298a619SAndreas Gohr
14483aa54d7cSAndreas Gohr    print '<b>$_SESSION:</b><pre>';
1449100a97e3SAndreas Gohr    print_r($ses);
14503aa54d7cSAndreas Gohr    print '</pre>';
14513aa54d7cSAndreas Gohr
1452f3f0262cSandi    print '<b>Environment:</b><pre>';
1453f3f0262cSandi    print_r($_ENV);
1454f3f0262cSandi    print '</pre>';
1455f3f0262cSandi
1456f3f0262cSandi    print '<b>PHP settings:</b><pre>';
1457f3f0262cSandi    $inis = ini_get_all();
1458f3f0262cSandi    print_r($inis);
1459f3f0262cSandi    print '</pre>';
1460f3f0262cSandi
1461f3f0262cSandi    print '</body></html>';
1462f3f0262cSandi}
1463f3f0262cSandi
146410271ce4SAndreas Gohr/**
146510271ce4SAndreas Gohr * List available Administration Tasks
146610271ce4SAndreas Gohr *
146710271ce4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
146810271ce4SAndreas Gohr * @author Håkan Sandell <hakan.sandell@home.se>
146910271ce4SAndreas Gohr */
1470c19fe9c0Sandifunction html_admin(){
1471c19fe9c0Sandi    global $ID;
1472f8cc712eSAndreas Gohr    global $INFO;
1473c19fe9c0Sandi    global $lang;
1474ca3a6df1SMatthias Grimm    global $conf;
147510271ce4SAndreas Gohr    global $auth;
1476c19fe9c0Sandi
147711e2ce22Schris    // build menu of admin functions from the plugins that handle them
147811e2ce22Schris    $pluginlist = plugin_list('admin');
147911e2ce22Schris    $menu = array();
148011e2ce22Schris    foreach ($pluginlist as $p) {
1481db959ae3SAndreas Gohr        if($obj =& plugin_load('admin',$p) === null) continue;
1482f8cc712eSAndreas Gohr
1483f8cc712eSAndreas Gohr        // check permissions
1484f8cc712eSAndreas Gohr        if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
1485f8cc712eSAndreas Gohr
148610271ce4SAndreas Gohr        $menu[$p] = array('plugin' => $p,
148711e2ce22Schris                'prompt' => $obj->getMenuText($conf['lang']),
148811e2ce22Schris                'sort' => $obj->getMenuSort()
148911e2ce22Schris                );
149011e2ce22Schris    }
149111e2ce22Schris
1492c95a5b7dSAndreas Gohr    // data security check
1493b2f0ffd0SAnika Henke    // @todo: could be checked and only displayed if $conf['savedir'] is under the web root
1494f24af591SAnika Henke    echo '<a style="border:none; float:right;"
1495b2f0ffd0SAnika Henke            href="http://www.dokuwiki.org/security#web_access_security">
1496e8188911SAndreas Gohr            <img src="data/security.png" alt="Your data directory seems to be protected properly."
1497e8188911SAndreas Gohr             onerror="this.parentNode.style.display=\'none\'" /></a>';
1498c95a5b7dSAndreas Gohr
149910271ce4SAndreas Gohr    print p_locale_xhtml('admin');
150010271ce4SAndreas Gohr
150110271ce4SAndreas Gohr    // Admin Tasks
150210271ce4SAndreas Gohr    if($INFO['isadmin']){
150310271ce4SAndreas Gohr        ptln('<ul class="admin_tasks">');
150410271ce4SAndreas Gohr
150576c65fd3SAndreas Gohr        if($menu['usermanager'] && $auth && $auth->canDo('getUsers')){
150610271ce4SAndreas Gohr            ptln('  <li class="admin_usermanager"><div class="li">'.
150710271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'usermanager')).'">'.
150810271ce4SAndreas Gohr                    $menu['usermanager']['prompt'].'</a></div></li>');
150910271ce4SAndreas Gohr        }
151010271ce4SAndreas Gohr        unset($menu['usermanager']);
151110271ce4SAndreas Gohr
151276c65fd3SAndreas Gohr        if($menu['acl']){
151310271ce4SAndreas Gohr            ptln('  <li class="admin_acl"><div class="li">'.
151410271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'acl')).'">'.
151510271ce4SAndreas Gohr                    $menu['acl']['prompt'].'</a></div></li>');
151676c65fd3SAndreas Gohr        }
151710271ce4SAndreas Gohr        unset($menu['acl']);
151810271ce4SAndreas Gohr
151976c65fd3SAndreas Gohr        if($menu['plugin']){
152010271ce4SAndreas Gohr            ptln('  <li class="admin_plugin"><div class="li">'.
152110271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'plugin')).'">'.
152210271ce4SAndreas Gohr                    $menu['plugin']['prompt'].'</a></div></li>');
152376c65fd3SAndreas Gohr        }
152410271ce4SAndreas Gohr        unset($menu['plugin']);
152510271ce4SAndreas Gohr
152676c65fd3SAndreas Gohr        if($menu['config']){
152710271ce4SAndreas Gohr            ptln('  <li class="admin_config"><div class="li">'.
152810271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'config')).'">'.
152910271ce4SAndreas Gohr                    $menu['config']['prompt'].'</a></div></li>');
153076c65fd3SAndreas Gohr        }
153110271ce4SAndreas Gohr        unset($menu['config']);
153210271ce4SAndreas Gohr    }
153310271ce4SAndreas Gohr    ptln('</ul>');
153410271ce4SAndreas Gohr
153510271ce4SAndreas Gohr    // Manager Tasks
153610271ce4SAndreas Gohr    ptln('<ul class="admin_tasks">');
153710271ce4SAndreas Gohr
153876c65fd3SAndreas Gohr    if($menu['revert']){
153910271ce4SAndreas Gohr        ptln('  <li class="admin_revert"><div class="li">'.
154010271ce4SAndreas Gohr                '<a href="'.wl($ID, array('do' => 'admin','page' => 'revert')).'">'.
154110271ce4SAndreas Gohr                $menu['revert']['prompt'].'</a></div></li>');
154276c65fd3SAndreas Gohr    }
154310271ce4SAndreas Gohr    unset($menu['revert']);
154410271ce4SAndreas Gohr
154576c65fd3SAndreas Gohr    if($menu['popularity']){
154610271ce4SAndreas Gohr        ptln('  <li class="admin_popularity"><div class="li">'.
154710271ce4SAndreas Gohr                '<a href="'.wl($ID, array('do' => 'admin','page' => 'popularity')).'">'.
154810271ce4SAndreas Gohr                $menu['popularity']['prompt'].'</a></div></li>');
154976c65fd3SAndreas Gohr    }
155010271ce4SAndreas Gohr    unset($menu['popularity']);
155110271ce4SAndreas Gohr
15529a2cec2eSAndreas Gohr    // print DokuWiki version:
155310271ce4SAndreas Gohr    ptln('</ul>');
15549a2cec2eSAndreas Gohr    echo '<div id="admin__version">';
15559a2cec2eSAndreas Gohr    echo getVersion();
15569a2cec2eSAndreas Gohr    echo '</div>';
155710271ce4SAndreas Gohr
155810271ce4SAndreas Gohr    // print the rest as sorted list
155910271ce4SAndreas Gohr    if(count($menu)){
1560746855cfSBen Coburn        usort($menu, 'p_sort_modes');
156111e2ce22Schris        // output the menu
156210271ce4SAndreas Gohr        ptln('<div class="clearer"></div>');
156310271ce4SAndreas Gohr        print p_locale_xhtml('adminplugins');
156411e2ce22Schris        ptln('<ul>');
156511e2ce22Schris        foreach ($menu as $item) {
156611e2ce22Schris            if (!$item['prompt']) continue;
15670c6b58a8SAndreas Gohr            ptln('  <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
156811e2ce22Schris        }
156911e2ce22Schris        ptln('</ul>');
1570ca3a6df1SMatthias Grimm    }
157110271ce4SAndreas Gohr}
1572c19fe9c0Sandi
15738b06d178Schris/**
15748b06d178Schris * Form to request a new password for an existing account
15758b06d178Schris *
15768b06d178Schris * @author Benoit Chesneau <benoit@bchesneau.info>
157711e2ce22Schris */
15788b06d178Schrisfunction html_resendpwd() {
15798b06d178Schris    global $lang;
15808b06d178Schris    global $conf;
15818b06d178Schris    global $ID;
1582c19fe9c0Sandi
15838b06d178Schris    print p_locale_xhtml('resendpwd');
1584fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1585e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__resendpwd'));
1586fdb8d77bSTom N Harris    $form->startFieldset($lang['resendpwd']);
1587fdb8d77bSTom N Harris    $form->addHidden('do', 'resendpwd');
1588fdb8d77bSTom N Harris    $form->addHidden('save', '1');
1589fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1590fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block'));
1591fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1592fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1593fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
1594fdb8d77bSTom N Harris    $form->endFieldset();
1595fdb8d77bSTom N Harris    html_form('resendpwd', $form);
1596fdb8d77bSTom N Harris    print '</div>'.NL;
1597fdb8d77bSTom N Harris}
1598fdb8d77bSTom N Harris
1599fdb8d77bSTom N Harris/**
1600b8595a66SAndreas Gohr * Return the TOC rendered to XHTML
1601b8595a66SAndreas Gohr *
1602b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1603b8595a66SAndreas Gohr */
1604b8595a66SAndreas Gohrfunction html_TOC($toc){
1605b8595a66SAndreas Gohr    if(!count($toc)) return '';
1606b8595a66SAndreas Gohr    global $lang;
1607b8595a66SAndreas Gohr    $out  = '<!-- TOC START -->'.DOKU_LF;
1608b8595a66SAndreas Gohr    $out .= '<div class="toc">'.DOKU_LF;
1609b8595a66SAndreas Gohr    $out .= '<div class="tocheader toctoggle" id="toc__header">';
1610b8595a66SAndreas Gohr    $out .= $lang['toc'];
1611b8595a66SAndreas Gohr    $out .= '</div>'.DOKU_LF;
1612b8595a66SAndreas Gohr    $out .= '<div id="toc__inside">'.DOKU_LF;
1613b8595a66SAndreas Gohr    $out .= html_buildlist($toc,'toc','html_list_toc');
1614b8595a66SAndreas Gohr    $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
1615b8595a66SAndreas Gohr    $out .= '<!-- TOC END -->'.DOKU_LF;
1616db959ae3SAndreas Gohr    return $out;
1617db959ae3SAndreas Gohr}
1618b8595a66SAndreas Gohr
1619b8595a66SAndreas Gohr/**
1620b8595a66SAndreas Gohr * Callback for html_buildlist
1621b8595a66SAndreas Gohr */
1622b8595a66SAndreas Gohrfunction html_list_toc($item){
1623c66972f2SAdrian Lang    if(isset($item['hid'])){
16247d91652aSAndreas Gohr        $link = '#'.$item['hid'];
16257d91652aSAndreas Gohr    }else{
16267d91652aSAndreas Gohr        $link = $item['link'];
16277d91652aSAndreas Gohr    }
16287d91652aSAndreas Gohr
16297d91652aSAndreas Gohr    return '<span class="li"><a href="'.$link.'" class="toc">'.
1630b8595a66SAndreas Gohr        hsc($item['title']).'</a></span>';
1631b8595a66SAndreas Gohr}
1632b8595a66SAndreas Gohr
1633b8595a66SAndreas Gohr/**
1634b8595a66SAndreas Gohr * Helper function to build TOC items
1635b8595a66SAndreas Gohr *
1636b8595a66SAndreas Gohr * Returns an array ready to be added to a TOC array
1637b8595a66SAndreas Gohr *
1638b8595a66SAndreas Gohr * @param string $link  - where to link (if $hash set to '#' it's a local anchor)
1639b8595a66SAndreas Gohr * @param string $text  - what to display in the TOC
1640b8595a66SAndreas Gohr * @param int    $level - nesting level
1641b8595a66SAndreas Gohr * @param string $hash  - is prepended to the given $link, set blank if you want full links
1642b8595a66SAndreas Gohr */
1643b8595a66SAndreas Gohrfunction html_mktocitem($link, $text, $level, $hash='#'){
1644b8595a66SAndreas Gohr    global $conf;
1645b8595a66SAndreas Gohr    return  array( 'link'  => $hash.$link,
1646b8595a66SAndreas Gohr            'title' => $text,
1647b8595a66SAndreas Gohr            'type'  => 'ul',
16482bb0d541Schris            'level' => $level);
1649b8595a66SAndreas Gohr}
1650b8595a66SAndreas Gohr
1651b8595a66SAndreas Gohr/**
1652fdb8d77bSTom N Harris * Output a Doku_Form object.
1653fdb8d77bSTom N Harris * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
1654fdb8d77bSTom N Harris *
1655fdb8d77bSTom N Harris * @author Tom N Harris <tnharris@whoopdedo.org>
1656fdb8d77bSTom N Harris */
1657fdb8d77bSTom N Harrisfunction html_form($name, &$form) {
1658fdb8d77bSTom N Harris    // Safety check in case the caller forgets.
1659fdb8d77bSTom N Harris    $form->endFieldset();
1660fdb8d77bSTom N Harris    trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
1661fdb8d77bSTom N Harris}
1662fdb8d77bSTom N Harris
1663fdb8d77bSTom N Harris/**
1664fdb8d77bSTom N Harris * Form print function.
1665fdb8d77bSTom N Harris * Just calls printForm() on the data object.
1666fdb8d77bSTom N Harris */
1667fdb8d77bSTom N Harrisfunction html_form_output($data) {
1668fdb8d77bSTom N Harris    $data->printForm();
16698b06d178Schris}
1670340756e4Sandi
167107bf32b2SAndreas Gohr/**
167207bf32b2SAndreas Gohr * Embed a flash object in HTML
167307bf32b2SAndreas Gohr *
167407bf32b2SAndreas Gohr * This will create the needed HTML to embed a flash movie in a cross browser
167507bf32b2SAndreas Gohr * compatble way using valid XHTML
167607bf32b2SAndreas Gohr *
167707bf32b2SAndreas Gohr * The parameters $params, $flashvars and $atts need to be associative arrays.
167807bf32b2SAndreas Gohr * No escaping needs to be done for them. The alternative content *has* to be
167907bf32b2SAndreas Gohr * escaped because it is used as is. If no alternative content is given
168007bf32b2SAndreas Gohr * $lang['noflash'] is used.
168107bf32b2SAndreas Gohr *
168207bf32b2SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
168307bf32b2SAndreas Gohr * @link   http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
168407bf32b2SAndreas Gohr *
168507bf32b2SAndreas Gohr * @param string $swf      - the SWF movie to embed
168607bf32b2SAndreas Gohr * @param int $width       - width of the flash movie in pixels
168707bf32b2SAndreas Gohr * @param int $height      - height of the flash movie in pixels
168807bf32b2SAndreas Gohr * @param array $params    - additional parameters (<param>)
168907bf32b2SAndreas Gohr * @param array $flashvars - parameters to be passed in the flashvar parameter
169007bf32b2SAndreas Gohr * @param array $atts      - additional attributes for the <object> tag
169107bf32b2SAndreas Gohr * @param string $alt      - alternative content (is NOT automatically escaped!)
169207bf32b2SAndreas Gohr * @returns string         - the XHTML markup
169307bf32b2SAndreas Gohr */
169407bf32b2SAndreas Gohrfunction html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
169507bf32b2SAndreas Gohr    global $lang;
169607bf32b2SAndreas Gohr
169707bf32b2SAndreas Gohr    $out = '';
169807bf32b2SAndreas Gohr
169907bf32b2SAndreas Gohr    // prepare the object attributes
170007bf32b2SAndreas Gohr    if(is_null($atts)) $atts = array();
170107bf32b2SAndreas Gohr    $atts['width']  = (int) $width;
1702d4c61e61SAndreas Gohr    $atts['height'] = (int) $height;
170307bf32b2SAndreas Gohr    if(!$atts['width'])  $atts['width']  = 425;
170407bf32b2SAndreas Gohr    if(!$atts['height']) $atts['height'] = 350;
170507bf32b2SAndreas Gohr
170607bf32b2SAndreas Gohr    // add object attributes for standard compliant browsers
170707bf32b2SAndreas Gohr    $std = $atts;
170807bf32b2SAndreas Gohr    $std['type'] = 'application/x-shockwave-flash';
170907bf32b2SAndreas Gohr    $std['data'] = $swf;
171007bf32b2SAndreas Gohr
171107bf32b2SAndreas Gohr    // add object attributes for IE
171207bf32b2SAndreas Gohr    $ie  = $atts;
171307bf32b2SAndreas Gohr    $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
171407bf32b2SAndreas Gohr
171507bf32b2SAndreas Gohr    // open object (with conditional comments)
171607bf32b2SAndreas Gohr    $out .= '<!--[if !IE]> -->'.NL;
171707bf32b2SAndreas Gohr    $out .= '<object '.buildAttributes($std).'>'.NL;
171807bf32b2SAndreas Gohr    $out .= '<!-- <![endif]-->'.NL;
171907bf32b2SAndreas Gohr    $out .= '<!--[if IE]>'.NL;
172007bf32b2SAndreas Gohr    $out .= '<object '.buildAttributes($ie).'>'.NL;
172107bf32b2SAndreas Gohr    $out .= '    <param name="movie" value="'.hsc($swf).'" />'.NL;
17229ae41cdcSAndreas Gohr    $out .= '<!--><!-- -->'.NL;
172307bf32b2SAndreas Gohr
172407bf32b2SAndreas Gohr    // print params
172507bf32b2SAndreas Gohr    if(is_array($params)) foreach($params as $key => $val){
172607bf32b2SAndreas Gohr        $out .= '  <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
172707bf32b2SAndreas Gohr    }
172807bf32b2SAndreas Gohr
172907bf32b2SAndreas Gohr    // add flashvars
173007bf32b2SAndreas Gohr    if(is_array($flashvars)){
1731d4c61e61SAndreas Gohr        $out .= '  <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
173207bf32b2SAndreas Gohr    }
173307bf32b2SAndreas Gohr
173407bf32b2SAndreas Gohr    // alternative content
173507bf32b2SAndreas Gohr    if($alt){
173607bf32b2SAndreas Gohr        $out .= $alt.NL;
173707bf32b2SAndreas Gohr    }else{
173807bf32b2SAndreas Gohr        $out .= $lang['noflash'].NL;
173907bf32b2SAndreas Gohr    }
174007bf32b2SAndreas Gohr
174107bf32b2SAndreas Gohr    // finish
174207bf32b2SAndreas Gohr    $out .= '</object>'.NL;
174307bf32b2SAndreas Gohr    $out .= '<!-- <![endif]-->'.NL;
174407bf32b2SAndreas Gohr
174507bf32b2SAndreas Gohr    return $out;
174607bf32b2SAndreas Gohr}
174707bf32b2SAndreas Gohr
1748