xref: /dokuwiki/inc/html.php (revision 0cba610bea94e5841d211c0d3f57ae96e8ad1379)
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
90c3a5702SAndreas Gohruse dokuwiki\ChangeLog\MediaChangeLog;
100c3a5702SAndreas Gohruse dokuwiki\ChangeLog\PageChangeLog;
11e1d9dcc8SAndreas Gohruse dokuwiki\Extension\AuthPlugin;
12cbb44eabSAndreas Gohruse dokuwiki\Extension\Event;
13*0cba610bSSatoshi Saharause dokuwiki\Search\FulltextSearch;
14*0cba610bSSatoshi Saharause dokuwiki\Search\MetadataSearch;
150c3a5702SAndreas Gohr
162d3b082eSMichael Großeif (!defined('SEC_EDIT_PATTERN')) {
1737c80e0eSLarsDW223    define('SEC_EDIT_PATTERN', '#<!-- EDIT({.*?}) -->#');
182d3b082eSMichael Große}
192d3b082eSMichael Große
206bbae538Sandi
21f3f0262cSandi/**
22f3f0262cSandi * Convenience function to quickly build a wikilink
2315fae107Sandi *
2415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
258d5e837eSMichael Hamann * @param string  $id      id of the target page
268d5e837eSMichael Hamann * @param string  $name    the name of the link, i.e. the text that is displayed
278d5e837eSMichael Hamann * @param string|array  $search  search string(s) that shall be highlighted in the target page
288d5e837eSMichael Hamann * @return string the HTML code of the link
29f3f0262cSandi */
30db959ae3SAndreas Gohrfunction html_wikilink($id,$name=null,$search=''){
31a8397511SGerrit Uitslag    /** @var Doku_Renderer_xhtml $xhtml_renderer */
32db959ae3SAndreas Gohr    static $xhtml_renderer = null;
33723d78dbSandi    if(is_null($xhtml_renderer)){
347aea91afSChris Smith        $xhtml_renderer = p_get_renderer('xhtml');
35f3f0262cSandi    }
36f3f0262cSandi
37fe9ec250SChris Smith    return $xhtml_renderer->internallink($id,$name,$search,true,'navigation');
38f3f0262cSandi}
39f3f0262cSandi
40f3f0262cSandi/**
41f3f0262cSandi * The loginform
4215fae107Sandi *
4315fae107Sandi * @author   Andreas Gohr <andi@splitbrain.org>
44d1d904bbSMichael Große *
45d1d904bbSMichael Große * @param bool $svg Whether to show svg icons in the register and resendpwd links or not
46f3f0262cSandi */
47d1d904bbSMichael Großefunction html_login($svg = false){
48f3f0262cSandi    global $lang;
49f3f0262cSandi    global $conf;
50f3f0262cSandi    global $ID;
51f0859d4bSTom N Harris    global $INPUT;
52f3f0262cSandi
53c112d578Sandi    print p_locale_xhtml('login');
54fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
553f552e56SAndreas Gohr    $form = new Doku_Form(array('id' => 'dw__login', 'action'=>wl($ID)));
56fdb8d77bSTom N Harris    $form->startFieldset($lang['btn_login']);
57fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
58fdb8d77bSTom N Harris    $form->addHidden('do', 'login');
5964159a61SAndreas Gohr    $form->addElement(form_makeTextField(
6064159a61SAndreas Gohr        'u',
6164159a61SAndreas Gohr        ((!$INPUT->bool('http_credentials')) ? $INPUT->str('u') : ''),
6264159a61SAndreas Gohr        $lang['user'],
6364159a61SAndreas Gohr        'focus__this',
6464159a61SAndreas Gohr        'block')
6564159a61SAndreas Gohr    );
66fdb8d77bSTom N Harris    $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block'));
6717f89d7eSMichael Klier    if($conf['rememberme']) {
68fdb8d77bSTom N Harris        $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple'));
6917f89d7eSMichael Klier    }
70fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['btn_login']));
71fdb8d77bSTom N Harris    $form->endFieldset();
725b62573aSAndreas Gohr
73de4d479aSAdrian Lang    if(actionOK('register')){
74d1d904bbSMichael Große        $registerLink = (new \dokuwiki\Menu\Item\Register())->asHtmlLink('', $svg);
75d1d904bbSMichael Große        $form->addElement('<p>'.$lang['reghere'].': '. $registerLink .'</p>');
76f3f0262cSandi    }
778b06d178Schris
78de4d479aSAdrian Lang    if (actionOK('resendpwd')) {
79d1d904bbSMichael Große        $resendPwLink = (new \dokuwiki\Menu\Item\Resendpwd())->asHtmlLink('', $svg);
80d1d904bbSMichael Große        $form->addElement('<p>'.$lang['pwdforget'].': '. $resendPwLink .'</p>');
818b06d178Schris    }
8276ec5467SMichael Klier
8376ec5467SMichael Klier    html_form('login', $form);
84fdb8d77bSTom N Harris    print '</div>'.NL;
85f3f0262cSandi}
86f3f0262cSandi
87d59dea9fSGerrit Uitslag
88d59dea9fSGerrit Uitslag/**
89d59dea9fSGerrit Uitslag * Denied page content
90d59dea9fSGerrit Uitslag *
91d59dea9fSGerrit Uitslag * @return string html
92d59dea9fSGerrit Uitslag */
93d59dea9fSGerrit Uitslagfunction html_denied() {
94d1e9181eSGerrit Uitslag    print p_locale_xhtml('denied');
95f019ab46SGerrit Uitslag
960db7a50dSThammi    if(empty($_SERVER['REMOTE_USER']) && actionOK('login')){
97f019ab46SGerrit Uitslag        html_login();
98f019ab46SGerrit Uitslag    }
99d59dea9fSGerrit Uitslag}
100d59dea9fSGerrit Uitslag
101f3f0262cSandi/**
10215fae107Sandi * inserts section edit buttons if wanted or removes the markers
10315fae107Sandi *
10415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
10542ea7f44SGerrit Uitslag *
10642ea7f44SGerrit Uitslag * @param string $text
10742ea7f44SGerrit Uitslag * @param bool   $show show section edit buttons?
10842ea7f44SGerrit Uitslag * @return string
10915fae107Sandi */
110f3f0262cSandifunction html_secedit($text,$show=true){
111f3f0262cSandi    global $INFO;
11235dae8b0SBen Coburn
11340868f2fSAdrian Lang    if(!$INFO['writable'] || !$show || $INFO['rev']){
1142d3b082eSMichael Große        return preg_replace(SEC_EDIT_PATTERN,'',$text);
115f3f0262cSandi    }
11635dae8b0SBen Coburn
1172d3b082eSMichael Große    return preg_replace_callback(SEC_EDIT_PATTERN,
11840868f2fSAdrian Lang                'html_secedit_button', $text);
11940868f2fSAdrian Lang}
12040868f2fSAdrian Lang
12140868f2fSAdrian Lang/**
12240868f2fSAdrian Lang * prepares section edit button data for event triggering
12340868f2fSAdrian Lang * used as a callback in html_secedit
12440868f2fSAdrian Lang *
12540868f2fSAdrian Lang * @author Andreas Gohr <andi@splitbrain.org>
12642ea7f44SGerrit Uitslag *
12742ea7f44SGerrit Uitslag * @param array $matches matches with regexp
12842ea7f44SGerrit Uitslag * @return string
12942ea7f44SGerrit Uitslag * @triggers HTML_SECEDIT_BUTTON
13040868f2fSAdrian Lang */
13140868f2fSAdrian Langfunction html_secedit_button($matches){
132ada0d779SMichael Hamann    $json = htmlspecialchars_decode($matches[1], ENT_QUOTES);
133ada0d779SMichael Hamann    $data = json_decode($json, true);
134ec57f119SLarsDW223    if ($data == NULL) {
135ec57f119SLarsDW223        return;
13606917fceSMichael Große    }
137ec57f119SLarsDW223    $data ['target'] = strtolower($data['target']);
138ec57f119SLarsDW223    $data ['hid'] = strtolower($data['hid']);
13940868f2fSAdrian Lang
140cbb44eabSAndreas Gohr    return Event::createAndTrigger('HTML_SECEDIT_BUTTON', $data,
14140868f2fSAdrian Lang                         'html_secedit_get_button');
14240868f2fSAdrian Lang}
14340868f2fSAdrian Lang
14440868f2fSAdrian Lang/**
14540868f2fSAdrian Lang * prints a section editing button
14640868f2fSAdrian Lang * used as default action form HTML_SECEDIT_BUTTON
14740868f2fSAdrian Lang *
14840868f2fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de>
14942ea7f44SGerrit Uitslag *
15042ea7f44SGerrit Uitslag * @param array $data name, section id and target
15142ea7f44SGerrit Uitslag * @return string html
15240868f2fSAdrian Lang */
15340868f2fSAdrian Langfunction html_secedit_get_button($data) {
15440868f2fSAdrian Lang    global $ID;
15540868f2fSAdrian Lang    global $INFO;
15640868f2fSAdrian Lang
1576d9eab4dSMichael Hamann    if (!isset($data['name']) || $data['name'] === '') return '';
15840868f2fSAdrian Lang
15940868f2fSAdrian Lang    $name = $data['name'];
16040868f2fSAdrian Lang    unset($data['name']);
16140868f2fSAdrian Lang
162905fa971SAdrian Lang    $secid = $data['secid'];
163905fa971SAdrian Lang    unset($data['secid']);
164905fa971SAdrian Lang
16540868f2fSAdrian Lang    return "<div class='secedit editbutton_" . $data['target'] .
166defa93a1SAdrian Lang                       " editbutton_" . $secid . "'>" .
16740868f2fSAdrian Lang           html_btn('secedit', $ID, '',
16840868f2fSAdrian Lang                    array_merge(array('do'  => 'edit',
169b150cd2cSGina Haeussge                                      'rev' => $INFO['lastmod'],
170b150cd2cSGina Haeussge                                      'summary' => '['.$name.'] '), $data),
17140868f2fSAdrian Lang                    'post', $name) . '</div>';
172f3f0262cSandi}
173f3f0262cSandi
174f3f0262cSandi/**
175d6c9c552Smatthiasgrimm * Just the back to top button (in its own form)
1766b13307fSandi *
1776b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
17842ea7f44SGerrit Uitslag *
17942ea7f44SGerrit Uitslag * @return string html
1806b13307fSandi */
1816b13307fSandifunction html_topbtn(){
1826b13307fSandi    global $lang;
1836b13307fSandi
18464159a61SAndreas Gohr    $ret = '<a class="nolink" href="#dokuwiki__top">' .
18564159a61SAndreas Gohr        '<button class="button" onclick="window.scrollTo(0, 0)" title="' . $lang['btn_top'] . '">' .
18664159a61SAndreas Gohr        $lang['btn_top'] .
18764159a61SAndreas Gohr        '</button></a>';
188df7b6005Sandi
1896b13307fSandi    return $ret;
1906b13307fSandi}
1916b13307fSandi
1926b13307fSandi/**
193d67ca2c0Smatthiasgrimm * Displays a button (using its own form)
19435dae8b0SBen Coburn * If tooltip exists, the access key tooltip is replaced.
19515fae107Sandi *
19615fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
19742ea7f44SGerrit Uitslag *
19842ea7f44SGerrit Uitslag * @param string         $name
19942ea7f44SGerrit Uitslag * @param string         $id
20042ea7f44SGerrit Uitslag * @param string         $akey   access key
201e3710957SGerrit Uitslag * @param string[] $params key-value pairs added as hidden inputs
20242ea7f44SGerrit Uitslag * @param string         $method
20342ea7f44SGerrit Uitslag * @param string         $tooltip
20442ea7f44SGerrit Uitslag * @param bool|string    $label  label text, false: lookup btn_$name in localization
205e824d633SMichael Große * @param string         $svg (optional) svg code, inserted into the button
20642ea7f44SGerrit Uitslag * @return string
207f3f0262cSandi */
208e824d633SMichael Großefunction html_btn($name, $id, $akey, $params, $method='get', $tooltip='', $label=false, $svg=null){
209f3f0262cSandi    global $conf;
210f3f0262cSandi    global $lang;
211f3f0262cSandi
212f5baf821SAnika Henke    if (!$label)
213f3f0262cSandi        $label = $lang['btn_'.$name];
214f3f0262cSandi
215f3f0262cSandi    $ret = '';
216f3f0262cSandi
21749c713a3Sandi    //filter id (without urlencoding)
21849c713a3Sandi    $id = idfilter($id,false);
219f3f0262cSandi
220f3f0262cSandi    //make nice URLs even for buttons
2216c7843b5Sandi    if($conf['userewrite'] == 2){
2226c7843b5Sandi        $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
2236c7843b5Sandi    }elseif($conf['userewrite']){
2246c7843b5Sandi        $script = DOKU_BASE.$id;
2256c7843b5Sandi    }else{
2268b00ebcfSandi        $script = DOKU_BASE.DOKU_SCRIPT;
227f3f0262cSandi        $params['id'] = $id;
228f3f0262cSandi    }
229f3f0262cSandi
230b278f2deSAndreas Gohr    $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
231f3f0262cSandi
23206a4bf8fSAndreas Gohr    if(is_array($params)){
2339e491c01SAndreas Gohr        foreach($params as $key => $val) {
234f3f0262cSandi            $ret .= '<input type="hidden" name="'.$key.'" ';
23565cc1598SPhy            $ret .= 'value="'.hsc($val).'" />';
236f3f0262cSandi        }
23706a4bf8fSAndreas Gohr    }
238f3f0262cSandi
23935dae8b0SBen Coburn    if ($tooltip!='') {
24065cc1598SPhy        $tip = hsc($tooltip);
24111ea018fSAndreas Gohr    }else{
24265cc1598SPhy        $tip = hsc($label);
24311ea018fSAndreas Gohr    }
24411ea018fSAndreas Gohr
245ae614416SAnika Henke    $ret .= '<button type="submit" ';
24611ea018fSAndreas Gohr    if($akey){
24707493d05SAnika Henke        $tip .= ' ['.strtoupper($akey).']';
24887cb01b7SAnika Henke        $ret .= 'accesskey="'.$akey.'" ';
24935dae8b0SBen Coburn    }
2509c65e2a9SAndreas Gohr    $ret .= 'title="'.$tip.'">';
251e824d633SMichael Große    if ($svg) {
252679dba01SMichael Große        $ret .= '<span>' . hsc($label) . '</span>';
253e824d633SMichael Große        $ret .= inlineSVG($svg);
254679dba01SMichael Große    } else {
255ae614416SAnika Henke        $ret .= hsc($label);
256679dba01SMichael Große    }
257ae614416SAnika Henke    $ret .= '</button>';
2584beabca9SAnika Henke    $ret .= '</div></form>';
259f3f0262cSandi
260f3f0262cSandi    return $ret;
261f3f0262cSandi}
2620747f5d7Sghi/**
2630747f5d7Sghi * show a revision warning
2640747f5d7Sghi *
2650747f5d7Sghi * @author Szymon Olewniczak <dokuwiki@imz.re>
2660747f5d7Sghi */
267c8556525Sghifunction html_showrev() {
268c8556525Sghi    print p_locale_xhtml('showrev');
2690747f5d7Sghi}
270f3f0262cSandi
271f3f0262cSandi/**
27242ea7f44SGerrit Uitslag * Show a wiki page
27315fae107Sandi *
27415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
27542ea7f44SGerrit Uitslag *
27642ea7f44SGerrit Uitslag * @param null|string $txt wiki text or null for showing $ID
27715fae107Sandi */
27811c78c94SAndreas Gohrfunction html_show($txt=null){
279f3f0262cSandi    global $ID;
280f3f0262cSandi    global $REV;
281f3f0262cSandi    global $HIGH;
282b8595a66SAndreas Gohr    global $INFO;
2835c2eed9aSlisps    global $DATE_AT;
284f3f0262cSandi    //disable section editing for old revisions or in preview
2855400331dSandi    if($txt || $REV){
2866bbae538Sandi        $secedit = false;
2876bbae538Sandi    }else{
2886bbae538Sandi        $secedit = true;
289f3f0262cSandi    }
290f3f0262cSandi
29111c78c94SAndreas Gohr    if (!is_null($txt)){
292f3f0262cSandi        //PreviewHeader
293e0959e88SDeathCamel57        echo '<br id="scroll__here" />';
294b8595a66SAndreas Gohr        echo p_locale_xhtml('preview');
295fc8dc822SAnika Henke        echo '<div class="preview"><div class="pad">';
296b8595a66SAndreas Gohr        $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
297b8595a66SAndreas Gohr        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
298b8595a66SAndreas Gohr        echo $html;
299b8595a66SAndreas Gohr        echo '<div class="clearer"></div>';
300fc8dc822SAnika Henke        echo '</div></div>';
3016bbae538Sandi
302f3f0262cSandi    }else{
3030747f5d7Sghi        if ($REV||$DATE_AT){
304c8556525Sghi            $data = array('rev' => &$REV, 'date_at' => &$DATE_AT);
305cbb44eabSAndreas Gohr            Event::createAndTrigger('HTML_SHOWREV_OUTPUT', $data, 'html_showrev');
3060747f5d7Sghi        }
3075c2eed9aSlisps        $html = p_wiki_xhtml($ID,$REV,true,$DATE_AT);
3086bbae538Sandi        $html = html_secedit($html,$secedit);
309b8595a66SAndreas Gohr        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
310b8595a66SAndreas Gohr        $html = html_hilight($html,$HIGH);
311b8595a66SAndreas Gohr        echo $html;
312f3f0262cSandi    }
313f3f0262cSandi}
314f3f0262cSandi
315f3f0262cSandi/**
316ee4c4a1bSAndreas Gohr * ask the user about how to handle an exisiting draft
317ee4c4a1bSAndreas Gohr *
318ee4c4a1bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
319ee4c4a1bSAndreas Gohr */
320ee4c4a1bSAndreas Gohrfunction html_draft(){
321ee4c4a1bSAndreas Gohr    global $INFO;
322ee4c4a1bSAndreas Gohr    global $ID;
323ee4c4a1bSAndreas Gohr    global $lang;
3240aabe6f8SMichael Große    $draft = new \dokuwiki\Draft($ID, $INFO['client']);
3250aabe6f8SMichael Große    $text  = $draft->getDraftText();
326ee4c4a1bSAndreas Gohr
327fdb8d77bSTom N Harris    print p_locale_xhtml('draft');
32837816f76SLukas Rademacher    html_diff($text, false);
329e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
330fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
331520438b3SMichael Große    $form->addHidden('date', $draft->getDraftDate());
3321362c8afSAndreas Gohr    $form->addHidden('wikitext', $text);
333fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
334520438b3SMichael Große    $form->addElement($draft->getDraftMessage());
335fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
336fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
337fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
338fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3')));
339fdb8d77bSTom N Harris    html_form('draft', $form);
340ee4c4a1bSAndreas Gohr}
341ee4c4a1bSAndreas Gohr
342ee4c4a1bSAndreas Gohr/**
343f3f0262cSandi * Highlights searchqueries in HTML code
34415fae107Sandi *
34515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
3467209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
34742ea7f44SGerrit Uitslag *
34842ea7f44SGerrit Uitslag * @param string $html
34942ea7f44SGerrit Uitslag * @param array|string $phrases
35042ea7f44SGerrit Uitslag * @return string html
351f3f0262cSandi */
352546d3a99SAndreas Gohrfunction html_hilight($html,$phrases){
3538a803caeSAndreas Gohr    $phrases = (array) $phrases;
3548a803caeSAndreas Gohr    $phrases = array_map('preg_quote_cb', $phrases);
355*0cba610bSSatoshi Sahara    $phrases = array_map(['dokuwiki\Search\FulltextSearch','snippet_re_preprocess'], $phrases);
3568a803caeSAndreas Gohr    $phrases = array_filter($phrases);
357*0cba610bSSatoshi Sahara    $regex = implode('|',$phrases);
35860c15d7dSAndreas Gohr
35960c15d7dSAndreas Gohr    if ($regex === '') return $html;
3608cbc5ee8SAndreas Gohr    if (!\dokuwiki\Utf8\Clean::isUtf8($regex)) return $html;
36124a6c235SAndreas Gohr    $html = @preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
362f3f0262cSandi    return $html;
363f3f0262cSandi}
364f3f0262cSandi
365f3f0262cSandi/**
3667209be23SAndreas Gohr * Callback used by html_hilight()
3677209be23SAndreas Gohr *
3687209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
36942ea7f44SGerrit Uitslag *
37042ea7f44SGerrit Uitslag * @param array $m matches
37142ea7f44SGerrit Uitslag * @return string html
3727209be23SAndreas Gohr */
3737209be23SAndreas Gohrfunction html_hilight_callback($m) {
3747209be23SAndreas Gohr    $hlight = unslash($m[0]);
3757209be23SAndreas Gohr    if ( !isset($m[2])) {
376688774a0SAnika Henke        $hlight = '<span class="search_hit">'.$hlight.'</span>';
3777209be23SAndreas Gohr    }
3787209be23SAndreas Gohr    return $hlight;
3797209be23SAndreas Gohr}
3807209be23SAndreas Gohr
3817209be23SAndreas Gohr/**
38215fae107Sandi * Display error on locked pages
38315fae107Sandi *
38415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
38515fae107Sandi */
386ee20e7d1Sandifunction html_locked(){
387f3f0262cSandi    global $ID;
388f3f0262cSandi    global $conf;
389f3f0262cSandi    global $lang;
39088f522e9Sandi    global $INFO;
391f3f0262cSandi
392c9b4bd1eSBen Coburn    $locktime = filemtime(wikiLockFN($ID));
393f2263577SAndreas Gohr    $expire = dformat($locktime + $conf['locktime']);
394f3f0262cSandi    $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
395f3f0262cSandi
396c112d578Sandi    print p_locale_xhtml('locked');
397f3f0262cSandi    print '<ul>';
398fde860beSGerrit Uitslag    print '<li><div class="li"><strong>'.$lang['lockedby'].'</strong> '.editorinfo($INFO['locked']).'</div></li>';
399fde860beSGerrit Uitslag    print '<li><div class="li"><strong>'.$lang['lockexpire'].'</strong> '.$expire.' ('.$min.' min)</div></li>';
400f3f0262cSandi    print '</ul>';
401f3f0262cSandi}
402f3f0262cSandi
40315fae107Sandi/**
40415fae107Sandi * list old revisions
40515fae107Sandi *
40615fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
40771726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
4088e69fd30SKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
409e0c26282SGerrit Uitslag *
410e0c26282SGerrit Uitslag * @param int $first skip the first n changelog lines
411e0c26282SGerrit Uitslag * @param bool|string $media_id id of media, or false for current page
41215fae107Sandi */
4138e69fd30SKate Arzamastsevafunction html_revisions($first=0, $media_id = false){
414f3f0262cSandi    global $ID;
415f3f0262cSandi    global $INFO;
416f3f0262cSandi    global $conf;
417f3f0262cSandi    global $lang;
4188e69fd30SKate Arzamastseva    $id = $ID;
419047bad06SGerrit Uitslag    if ($media_id) {
420047bad06SGerrit Uitslag        $id = $media_id;
421047bad06SGerrit Uitslag        $changelog = new MediaChangeLog($id);
422047bad06SGerrit Uitslag    } else {
423047bad06SGerrit Uitslag        $changelog = new PageChangeLog($id);
424047bad06SGerrit Uitslag    }
425f523c971SGerrit Uitslag
42661e0b2f8SChristopher Smith    /* we need to get one additional 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     */
430047bad06SGerrit Uitslag
431047bad06SGerrit Uitslag    $revisions = $changelog->getRevisions($first, $conf['recent']+1);
4328e69fd30SKate Arzamastseva
43371726d78SBen Coburn    if(count($revisions)==0 && $first!=0){
43471726d78SBen Coburn        $first=0;
435047bad06SGerrit Uitslag        $revisions = $changelog->getRevisions($first, $conf['recent']+1);
43671726d78SBen Coburn    }
43771726d78SBen Coburn    $hasNext = false;
43871726d78SBen Coburn    if (count($revisions)>$conf['recent']) {
43971726d78SBen Coburn        $hasNext = true;
44071726d78SBen Coburn        array_pop($revisions); // remove extra log entry
44171726d78SBen Coburn    }
44271726d78SBen Coburn
4438e69fd30SKate Arzamastseva    if (!$media_id) print p_locale_xhtml('revisions');
44437a1dc12Smichael
4450607bfeeSAnika Henke    $params = array('id' => 'page__revisions', 'class' => 'changes');
446551be3f9SGerrit Uitslag    if($media_id) {
447551be3f9SGerrit Uitslag        $params['action'] = media_managerURL(array('image' => $media_id), '&');
448551be3f9SGerrit Uitslag    }
449551be3f9SGerrit Uitslag
450551be3f9SGerrit Uitslag    if(!$media_id) {
451551be3f9SGerrit Uitslag        $exists = $INFO['exists'];
452551be3f9SGerrit Uitslag        $display_name = useHeading('navigation') ? hsc(p_get_first_heading($id)) : $id;
453551be3f9SGerrit Uitslag        if(!$display_name) {
454551be3f9SGerrit Uitslag            $display_name = $id;
455551be3f9SGerrit Uitslag        }
456551be3f9SGerrit Uitslag    } else {
457551be3f9SGerrit Uitslag        $exists = file_exists(mediaFN($id));
458551be3f9SGerrit Uitslag        $display_name = $id;
459551be3f9SGerrit Uitslag    }
4607d7ab775SKate Arzamastseva
4617d7ab775SKate Arzamastseva    $form = new Doku_Form($params);
46237a1dc12Smichael    $form->addElement(form_makeOpenTag('ul'));
4638e69fd30SKate Arzamastseva
4648e69fd30SKate Arzamastseva    if($exists && $first == 0) {
465551be3f9SGerrit Uitslag        $minor = false;
466551be3f9SGerrit Uitslag        if($media_id) {
467551be3f9SGerrit Uitslag            $date = dformat(@filemtime(mediaFN($id)));
468551be3f9SGerrit Uitslag            $href = media_managerURL(array('image' => $id, 'tab_details' => 'view'), '&');
469551be3f9SGerrit Uitslag
470551be3f9SGerrit Uitslag            $changelog->setChunkSize(1024);
471551be3f9SGerrit Uitslag            $revinfo = $changelog->getRevisionInfo(@filemtime(fullpath(mediaFN($id))));
472551be3f9SGerrit Uitslag
473551be3f9SGerrit Uitslag            $summary = $revinfo['sum'];
474551be3f9SGerrit Uitslag            if($revinfo['user']) {
475551be3f9SGerrit Uitslag                $editor = $revinfo['user'];
476551be3f9SGerrit Uitslag            } else {
477551be3f9SGerrit Uitslag                $editor = $revinfo['ip'];
478551be3f9SGerrit Uitslag            }
479551be3f9SGerrit Uitslag            $sizechange = $revinfo['sizechange'];
480551be3f9SGerrit Uitslag        } else {
481551be3f9SGerrit Uitslag            $date = dformat($INFO['lastmod']);
482551be3f9SGerrit Uitslag            if(isset($INFO['meta']) && isset($INFO['meta']['last_change'])) {
483551be3f9SGerrit Uitslag                if($INFO['meta']['last_change']['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) {
484551be3f9SGerrit Uitslag                    $minor = true;
485551be3f9SGerrit Uitslag                }
486551be3f9SGerrit Uitslag                if(isset($INFO['meta']['last_change']['sizechange'])) {
487551be3f9SGerrit Uitslag                    $sizechange = $INFO['meta']['last_change']['sizechange'];
488551be3f9SGerrit Uitslag                } else {
489551be3f9SGerrit Uitslag                    $sizechange = null;
490551be3f9SGerrit Uitslag                }
491551be3f9SGerrit Uitslag            }
492fe101f30SMetin Güler            $pagelog = new PageChangeLog($ID);
49370635395SAndreas Gohr            $latestrev = $pagelog->getRevisions(-1, 1);
49470635395SAndreas Gohr            $latestrev = array_pop($latestrev);
495fe101f30SMetin Güler            $href = wl($id,"rev=$latestrev",false,'&');
496551be3f9SGerrit Uitslag            $summary = $INFO['sum'];
497551be3f9SGerrit Uitslag            $editor = $INFO['editor'];
498551be3f9SGerrit Uitslag        }
499551be3f9SGerrit Uitslag
500551be3f9SGerrit Uitslag        $form->addElement(form_makeOpenTag('li', array('class' => ($minor ? 'minor' : ''))));
50137a1dc12Smichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
50237a1dc12Smichael        $form->addElement(form_makeTag('input', array(
50337a1dc12Smichael                        'type' => 'checkbox',
50437a1dc12Smichael                        'name' => 'rev2[]',
50537a1dc12Smichael                        'value' => 'current')));
506f9b2fe70Sandi
50737a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
50837a1dc12Smichael        $form->addElement($date);
50937a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
510f9b2fe70Sandi
511c2e73886SAnika Henke        $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
512cffcc403Sandi
51337a1dc12Smichael        $form->addElement(form_makeOpenTag('a', array(
51437a1dc12Smichael                        'class' => 'wikilink1',
515dad6764eSKate Arzamastseva                        'href'  => $href)));
51690658f38SMichael Hamann        $form->addElement($display_name);
51737a1dc12Smichael        $form->addElement(form_makeCloseTag('a'));
518652610a2Sandi
51967c8cda1SKate Arzamastseva        if ($media_id) $form->addElement(form_makeOpenTag('div'));
52067c8cda1SKate Arzamastseva
521551be3f9SGerrit Uitslag        if($summary) {
52237a1dc12Smichael            $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
523551be3f9SGerrit Uitslag            if(!$media_id) $form->addElement(' – ');
52465cc1598SPhy            $form->addElement('<bdi>' . hsc($summary) . '</bdi>');
52537a1dc12Smichael            $form->addElement(form_makeCloseTag('span'));
526035e07f1SKate Arzamastseva        }
527652610a2Sandi
52837a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
529551be3f9SGerrit Uitslag        $form->addElement((empty($editor))?('('.$lang['external_edit'].')'):'<bdi>'.editorinfo($editor).'</bdi>');
53037a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
53137a1dc12Smichael
532cd2a4cfdSAnika Henke        html_sizechange($sizechange, $form);
533551be3f9SGerrit Uitslag
53437a1dc12Smichael        $form->addElement('('.$lang['current'].')');
53567c8cda1SKate Arzamastseva
53667c8cda1SKate Arzamastseva        if ($media_id) $form->addElement(form_makeCloseTag('div'));
53767c8cda1SKate Arzamastseva
53837a1dc12Smichael        $form->addElement(form_makeCloseTag('div'));
53937a1dc12Smichael        $form->addElement(form_makeCloseTag('li'));
540f3f0262cSandi    }
541f3f0262cSandi
542f3f0262cSandi    foreach($revisions as $rev) {
543f2263577SAndreas Gohr        $date = dformat($rev);
544047bad06SGerrit Uitslag        $info = $changelog->getRevisionInfo($rev);
545047bad06SGerrit Uitslag        if($media_id) {
54679e79377SAndreas Gohr            $exists = file_exists(mediaFN($id, $rev));
547047bad06SGerrit Uitslag        } else {
548047bad06SGerrit Uitslag            $exists = page_exists($id, $rev);
549dad6764eSKate Arzamastseva        }
550652610a2Sandi
551551be3f9SGerrit Uitslag        $class = '';
552551be3f9SGerrit Uitslag        if($info['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) {
553551be3f9SGerrit Uitslag            $class = 'minor';
554551be3f9SGerrit Uitslag        }
555551be3f9SGerrit Uitslag        $form->addElement(form_makeOpenTag('li', array('class' => $class)));
55637a1dc12Smichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
55777707b04SAndreas Gohr        if($exists){
55837a1dc12Smichael            $form->addElement(form_makeTag('input', array(
55937a1dc12Smichael                            'type' => 'checkbox',
56037a1dc12Smichael                            'name' => 'rev2[]',
56137a1dc12Smichael                            'value' => $rev)));
56277707b04SAndreas Gohr        }else{
563c2e73886SAnika Henke            $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
56441396b71SAndreas Gohr        }
565f9b2fe70Sandi
56637a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
56737a1dc12Smichael        $form->addElement($date);
56837a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
56937a1dc12Smichael
57037a1dc12Smichael        if($exists){
571551be3f9SGerrit Uitslag            if (!$media_id) {
572551be3f9SGerrit Uitslag                $href = wl($id,"rev=$rev,do=diff", false, '&');
573551be3f9SGerrit Uitslag            } else {
574551be3f9SGerrit Uitslag                $href = media_managerURL(array('image' => $id, 'rev' => $rev, 'mediado' => 'diff'), '&');
575551be3f9SGerrit Uitslag            }
576551be3f9SGerrit Uitslag            $form->addElement(form_makeOpenTag('a', array(
577551be3f9SGerrit Uitslag                            'class' => 'diff_link',
578551be3f9SGerrit Uitslag                            'href' => $href)));
57937a1dc12Smichael            $form->addElement(form_makeTag('img', array(
58037a1dc12Smichael                            'src'    => DOKU_BASE.'lib/images/diff.png',
58137a1dc12Smichael                            'width'  => 15,
58237a1dc12Smichael                            'height' => 11,
58337a1dc12Smichael                            'title'  => $lang['diff'],
58437a1dc12Smichael                            'alt'    => $lang['diff'])));
58537a1dc12Smichael            $form->addElement(form_makeCloseTag('a'));
586551be3f9SGerrit Uitslag
587551be3f9SGerrit Uitslag            if (!$media_id) {
588551be3f9SGerrit Uitslag                $href = wl($id,"rev=$rev",false,'&');
589551be3f9SGerrit Uitslag            } else {
590551be3f9SGerrit Uitslag                $href = media_managerURL(array('image' => $id, 'tab_details' => 'view', 'rev' => $rev), '&');
591551be3f9SGerrit Uitslag            }
592551be3f9SGerrit Uitslag            $form->addElement(form_makeOpenTag('a', array(
593551be3f9SGerrit Uitslag                            'class' => 'wikilink1',
594551be3f9SGerrit Uitslag                            'href' => $href)));
59590658f38SMichael Hamann            $form->addElement($display_name);
59637a1dc12Smichael            $form->addElement(form_makeCloseTag('a'));
59737a1dc12Smichael        }else{
598c2e73886SAnika Henke            $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
59990658f38SMichael Hamann            $form->addElement($display_name);
60037a1dc12Smichael        }
60137a1dc12Smichael
60267c8cda1SKate Arzamastseva        if ($media_id) $form->addElement(form_makeOpenTag('div'));
60367c8cda1SKate Arzamastseva
604035e07f1SKate Arzamastseva        if ($info['sum']) {
60537a1dc12Smichael            $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
606e260f93bSAnika Henke            if(!$media_id) $form->addElement(' – ');
60765cc1598SPhy            $form->addElement('<bdi>'.hsc($info['sum']).'</bdi>');
60837a1dc12Smichael            $form->addElement(form_makeCloseTag('span'));
609035e07f1SKate Arzamastseva        }
61037a1dc12Smichael
61137a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
61288f522e9Sandi        if($info['user']){
613d317fb5dSAnika Henke            $form->addElement('<bdi>'.editorinfo($info['user']).'</bdi>');
614433efb25SAndreas Gohr            if(auth_ismanager()){
615d317fb5dSAnika Henke                $form->addElement(' <bdo dir="ltr">('.$info['ip'].')</bdo>');
616433efb25SAndreas Gohr            }
61788f522e9Sandi        }else{
618d317fb5dSAnika Henke            $form->addElement('<bdo dir="ltr">'.$info['ip'].'</bdo>');
61988f522e9Sandi        }
62037a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
621652610a2Sandi
622cd2a4cfdSAnika Henke        html_sizechange($info['sizechange'], $form);
623551be3f9SGerrit Uitslag
62467c8cda1SKate Arzamastseva        if ($media_id) $form->addElement(form_makeCloseTag('div'));
62567c8cda1SKate Arzamastseva
62637a1dc12Smichael        $form->addElement(form_makeCloseTag('div'));
62737a1dc12Smichael        $form->addElement(form_makeCloseTag('li'));
628f3f0262cSandi    }
62937a1dc12Smichael    $form->addElement(form_makeCloseTag('ul'));
6302e55802cSKate Arzamastseva    if (!$media_id) {
6312e55802cSKate Arzamastseva        $form->addElement(form_makeButton('submit', 'diff', $lang['diff2']));
6322e55802cSKate Arzamastseva    } else {
6332e55802cSKate Arzamastseva        $form->addHidden('mediado', 'diff');
6342e55802cSKate Arzamastseva        $form->addElement(form_makeButton('submit', '', $lang['diff2']));
6352e55802cSKate Arzamastseva    }
63637a1dc12Smichael    html_form('revisions', $form);
63771726d78SBen Coburn
63871726d78SBen Coburn    print '<div class="pagenav">';
63971726d78SBen Coburn    $last = $first + $conf['recent'];
64071726d78SBen Coburn    if ($first > 0) {
64171726d78SBen Coburn        $first -= $conf['recent'];
64271726d78SBen Coburn        if ($first < 0) $first = 0;
64371726d78SBen Coburn        print '<div class="pagenav-prev">';
6447e6b49bbSKate Arzamastseva        if ($media_id) {
645035e07f1SKate Arzamastseva            print html_btn('newer',$media_id,"p",media_managerURL(array('first' => $first), '&amp;', false, true));
6467e6b49bbSKate Arzamastseva        } else {
6478e69fd30SKate Arzamastseva            print html_btn('newer',$id,"p",array('do' => 'revisions', 'first' => $first));
6487e6b49bbSKate Arzamastseva        }
64971726d78SBen Coburn        print '</div>';
65071726d78SBen Coburn    }
65171726d78SBen Coburn    if ($hasNext) {
65271726d78SBen Coburn        print '<div class="pagenav-next">';
6537e6b49bbSKate Arzamastseva        if ($media_id) {
654035e07f1SKate Arzamastseva            print html_btn('older',$media_id,"n",media_managerURL(array('first' => $last), '&amp;', false, true));
6557e6b49bbSKate Arzamastseva        } else {
6568e69fd30SKate Arzamastseva            print html_btn('older',$id,"n",array('do' => 'revisions', 'first' => $last));
6577e6b49bbSKate Arzamastseva        }
65871726d78SBen Coburn        print '</div>';
65971726d78SBen Coburn    }
66071726d78SBen Coburn    print '</div>';
66171726d78SBen Coburn
662f3f0262cSandi}
663f3f0262cSandi
66415fae107Sandi/**
66515fae107Sandi * display recent changes
66615fae107Sandi *
66715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
6685749f1ceSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
66971726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
6708d40b4b6SKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
67142ea7f44SGerrit Uitslag *
67242ea7f44SGerrit Uitslag * @param int $first
67342ea7f44SGerrit Uitslag * @param string $show_changes
67415fae107Sandi */
6750739a638SKate Arzamastsevafunction html_recent($first = 0, $show_changes = 'both') {
676f3f0262cSandi    global $conf;
677cffcc403Sandi    global $lang;
678dbb00abcSEsther Brunner    global $ID;
6795749f1ceSmatthiasgrimm    /* we need to get one additionally log entry to be able to
6805749f1ceSmatthiasgrimm     * decide if this is the last page or is there another one.
6815749f1ceSmatthiasgrimm     * This is the cheapest solution to get this information.
6825749f1ceSmatthiasgrimm     */
683e5d185e1SKate Arzamastseva    $flags = 0;
684e5d185e1SKate Arzamastseva    if($show_changes == 'mediafiles' && $conf['mediarevisions']) {
685b5941dfaSKate Arzamastseva        $flags = RECENTS_MEDIA_CHANGES;
686b5941dfaSKate Arzamastseva    } elseif($show_changes == 'pages') {
687b5941dfaSKate Arzamastseva        $flags = 0;
688e5d185e1SKate Arzamastseva    } elseif($conf['mediarevisions']) {
689b5941dfaSKate Arzamastseva        $show_changes = 'both';
690b5941dfaSKate Arzamastseva        $flags = RECENTS_MEDIA_PAGES_MIXED;
691b5941dfaSKate Arzamastseva    }
6928d40b4b6SKate Arzamastseva
6938d40b4b6SKate Arzamastseva    $recents = getRecents($first, $conf['recent'] + 1, getNS($ID), $flags);
6945749f1ceSmatthiasgrimm    if(count($recents) == 0 && $first != 0) {
6955749f1ceSmatthiasgrimm        $first = 0;
6968d40b4b6SKate Arzamastseva        $recents = getRecents($first, $conf['recent'] + 1, getNS($ID), $flags);
6975749f1ceSmatthiasgrimm    }
69871726d78SBen Coburn    $hasNext = false;
69971726d78SBen Coburn    if(count($recents) > $conf['recent']) {
70071726d78SBen Coburn        $hasNext = true;
70171726d78SBen Coburn        array_pop($recents); // remove extra log entry
70271726d78SBen Coburn    }
703f3f0262cSandi
704c112d578Sandi    print p_locale_xhtml('recent');
705e83cef14SGina Haeussge
706a023425bSGerrit Uitslag    if(getNS($ID) != '') {
70764159a61SAndreas Gohr        print '<div class="level1"><p>' .
70864159a61SAndreas Gohr            sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) .
70964159a61SAndreas Gohr            '</p></div>';
710a023425bSGerrit Uitslag    }
711e83cef14SGina Haeussge
712d1264ecfSAndreas Gohr    $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET', 'class' => 'changes', 'action'=>wl($ID)));
713abdcc39fSmichael    $form->addHidden('sectok', null);
714abdcc39fSmichael    $form->addHidden('do', 'recent');
715abdcc39fSmichael    $form->addHidden('id', $ID);
7168d40b4b6SKate Arzamastseva
717e5d185e1SKate Arzamastseva    if($conf['mediarevisions']) {
7180607bfeeSAnika Henke        $form->addElement('<div class="changeType">');
719b5941dfaSKate Arzamastseva        $form->addElement(form_makeListboxField(
720b5941dfaSKate Arzamastseva                    'show_changes',
721b5941dfaSKate Arzamastseva                    array(
722b5941dfaSKate Arzamastseva                        'pages'      => $lang['pages_changes'],
723b5941dfaSKate Arzamastseva                        'mediafiles' => $lang['media_changes'],
72453cba3d0SGerrit Uitslag                        'both'       => $lang['both_changes']
72553cba3d0SGerrit Uitslag                    ),
726b5941dfaSKate Arzamastseva                    $show_changes,
727b5941dfaSKate Arzamastseva                    $lang['changes_type'],
728b5941dfaSKate Arzamastseva                    '', '',
729b5941dfaSKate Arzamastseva                    array('class' => 'quickselect')));
730b5941dfaSKate Arzamastseva
731b5941dfaSKate Arzamastseva        $form->addElement(form_makeButton('submit', 'recent', $lang['btn_apply']));
7320607bfeeSAnika Henke        $form->addElement('</div>');
733e5d185e1SKate Arzamastseva    }
7348d40b4b6SKate Arzamastseva
735abdcc39fSmichael    $form->addElement(form_makeOpenTag('ul'));
736a39955b0Smatthiasgrimm
737d437bcc4SAndreas Gohr    foreach($recents as $recent) {
738f2263577SAndreas Gohr        $date = dformat($recent['date']);
739cffcc403Sandi
740a023425bSGerrit Uitslag        $class = '';
741a023425bSGerrit Uitslag        if($recent['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) {
742a023425bSGerrit Uitslag            $class = 'minor';
743a023425bSGerrit Uitslag        }
744a023425bSGerrit Uitslag        $form->addElement(form_makeOpenTag('li', array('class' => $class)));
745abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
746f9b2fe70Sandi
7470e80bb5eSChristopher Smith        if(!empty($recent['media'])) {
748421ec38eSKate Arzamastseva            $form->addElement(media_printicon($recent['id']));
749421ec38eSKate Arzamastseva        } else {
750421ec38eSKate Arzamastseva            $icon = DOKU_BASE . 'lib/images/fileicons/file.png';
7510686da46SMichael Hamann            $form->addElement('<img src="' . $icon . '" alt="' . $recent['id'] . '" class="icon" />');
752421ec38eSKate Arzamastseva        }
753421ec38eSKate Arzamastseva
754abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
755abdcc39fSmichael        $form->addElement($date);
756abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
757cffcc403Sandi
7586d9eab4dSMichael Hamann        $diff = false;
7596d9eab4dSMichael Hamann        $href = '';
7606d9eab4dSMichael Hamann
7610e80bb5eSChristopher Smith        if(!empty($recent['media'])) {
76268921571SGerrit Uitslag            $changelog = new MediaChangeLog($recent['id']);
76368921571SGerrit Uitslag            $revs = $changelog->getRevisions(0, 1);
76468921571SGerrit Uitslag            $diff = (count($revs) && file_exists(mediaFN($recent['id'])));
76592cac9a9SKate Arzamastseva            if($diff) {
76668921571SGerrit Uitslag                $href = media_managerURL(array(
76768921571SGerrit Uitslag                                            'tab_details' => 'history',
76868921571SGerrit Uitslag                                            'mediado' => 'diff',
76968921571SGerrit Uitslag                                            'image' => $recent['id'],
77068921571SGerrit Uitslag                                            'ns' => getNS($recent['id'])
77168921571SGerrit Uitslag                                        ), '&');
77292cac9a9SKate Arzamastseva            }
773b5941dfaSKate Arzamastseva        } else {
774b5941dfaSKate Arzamastseva            $href = wl($recent['id'], "do=diff", false, '&');
775b5941dfaSKate Arzamastseva        }
77692cac9a9SKate Arzamastseva
7770e80bb5eSChristopher Smith        if(!empty($recent['media']) && !$diff) {
77892cac9a9SKate Arzamastseva            $form->addElement('<img src="' . DOKU_BASE . 'lib/images/blank.gif" width="15" height="11" alt="" />');
77992cac9a9SKate Arzamastseva        } else {
780b5941dfaSKate Arzamastseva            $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => $href)));
781abdcc39fSmichael            $form->addElement(form_makeTag('img', array(
782abdcc39fSmichael                            'src'    => DOKU_BASE . 'lib/images/diff.png',
783abdcc39fSmichael                            'width'  => 15,
784abdcc39fSmichael                            'height' => 11,
785abdcc39fSmichael                            'title'  => $lang['diff'],
786abdcc39fSmichael                            'alt'    => $lang['diff']
787abdcc39fSmichael                        )));
788abdcc39fSmichael            $form->addElement(form_makeCloseTag('a'));
78992cac9a9SKate Arzamastseva        }
790cffcc403Sandi
7910e80bb5eSChristopher Smith        if(!empty($recent['media'])) {
79264159a61SAndreas Gohr            $href = media_managerURL(
79364159a61SAndreas Gohr                array(
79464159a61SAndreas Gohr                    'tab_details' => 'history',
79564159a61SAndreas Gohr                    'image' => $recent['id'],
79664159a61SAndreas Gohr                    'ns' => getNS($recent['id'])
79764159a61SAndreas Gohr                ),
79864159a61SAndreas Gohr                '&'
79964159a61SAndreas Gohr            );
800b5941dfaSKate Arzamastseva        } else {
801b5941dfaSKate Arzamastseva            $href = wl($recent['id'], "do=revisions", false, '&');
802b5941dfaSKate Arzamastseva        }
803a023425bSGerrit Uitslag        $form->addElement(form_makeOpenTag('a', array(
804a023425bSGerrit Uitslag                        'class' => 'revisions_link',
805a023425bSGerrit Uitslag                        'href'  => $href)));
806abdcc39fSmichael        $form->addElement(form_makeTag('img', array(
807abdcc39fSmichael                        'src'    => DOKU_BASE . 'lib/images/history.png',
808abdcc39fSmichael                        'width'  => 12,
809abdcc39fSmichael                        'height' => 14,
810abdcc39fSmichael                        'title'  => $lang['btn_revs'],
811abdcc39fSmichael                        'alt'    => $lang['btn_revs']
812abdcc39fSmichael                    )));
813abdcc39fSmichael        $form->addElement(form_makeCloseTag('a'));
814b6912aeaSAndreas Gohr
8150e80bb5eSChristopher Smith        if(!empty($recent['media'])) {
81664159a61SAndreas Gohr            $href = media_managerURL(
81764159a61SAndreas Gohr                array(
81864159a61SAndreas Gohr                    'tab_details' => 'view',
81964159a61SAndreas Gohr                    'image' => $recent['id'],
82064159a61SAndreas Gohr                    'ns' => getNS($recent['id'])
82164159a61SAndreas Gohr                ),
82264159a61SAndreas Gohr                '&'
82364159a61SAndreas Gohr            );
824a023425bSGerrit Uitslag            $class = file_exists(mediaFN($recent['id'])) ? 'wikilink1' : 'wikilink2';
825a023425bSGerrit Uitslag            $form->addElement(form_makeOpenTag('a', array(
826a023425bSGerrit Uitslag                        'class' => $class,
827a023425bSGerrit Uitslag                        'href'  => $href)));
828b5941dfaSKate Arzamastseva            $form->addElement($recent['id']);
829b5941dfaSKate Arzamastseva            $form->addElement(form_makeCloseTag('a'));
830b5941dfaSKate Arzamastseva        } else {
831b5941dfaSKate Arzamastseva            $form->addElement(html_wikilink(':' . $recent['id'], useHeading('navigation') ? null : $recent['id']));
832b5941dfaSKate Arzamastseva        }
833abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
83465cc1598SPhy        $form->addElement(' – ' . hsc($recent['sum']));
835abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
836abdcc39fSmichael
837abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
838d437bcc4SAndreas Gohr        if($recent['user']) {
839d317fb5dSAnika Henke            $form->addElement('<bdi>' . editorinfo($recent['user']) . '</bdi>');
840433efb25SAndreas Gohr            if(auth_ismanager()) {
841d317fb5dSAnika Henke                $form->addElement(' <bdo dir="ltr">(' . $recent['ip'] . ')</bdo>');
842433efb25SAndreas Gohr            }
84388f522e9Sandi        } else {
844d317fb5dSAnika Henke            $form->addElement('<bdo dir="ltr">' . $recent['ip'] . '</bdo>');
84588f522e9Sandi        }
846abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
847cffcc403Sandi
848cd2a4cfdSAnika Henke        html_sizechange($recent['sizechange'], $form);
849976b572aSGerrit Uitslag
850abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
851abdcc39fSmichael        $form->addElement(form_makeCloseTag('li'));
852f3f0262cSandi    }
853abdcc39fSmichael    $form->addElement(form_makeCloseTag('ul'));
854a39955b0Smatthiasgrimm
855abdcc39fSmichael    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
8565749f1ceSmatthiasgrimm    $last = $first + $conf['recent'];
857a39955b0Smatthiasgrimm    if($first > 0) {
858a39955b0Smatthiasgrimm        $first -= $conf['recent'];
859a39955b0Smatthiasgrimm        if($first < 0) $first = 0;
860abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
861ae614416SAnika Henke        $form->addElement(form_makeOpenTag('button', array(
862abdcc39fSmichael                        'type'      => 'submit',
863abdcc39fSmichael                        'name'      => 'first[' . $first . ']',
864cddd152cSmichael                        'accesskey' => 'n',
865f948eeabSMichael Klier                        'title'     => $lang['btn_newer'] . ' [N]',
866d5daba10SKate Arzamastseva                        'class'     => 'button show'
867abdcc39fSmichael                    )));
868ae614416SAnika Henke        $form->addElement($lang['btn_newer']);
869ae614416SAnika Henke        $form->addElement(form_makeCloseTag('button'));
870abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
871a39955b0Smatthiasgrimm    }
87271726d78SBen Coburn    if($hasNext) {
873abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
874ae614416SAnika Henke        $form->addElement(form_makeOpenTag('button', array(
875abdcc39fSmichael                        'type'      => 'submit',
876abdcc39fSmichael                        'name'      => 'first[' . $last . ']',
877cddd152cSmichael                        'accesskey' => 'p',
878f948eeabSMichael Klier                        'title'     => $lang['btn_older'] . ' [P]',
879d5daba10SKate Arzamastseva                        'class'     => 'button show'
880abdcc39fSmichael                    )));
881ae614416SAnika Henke        $form->addElement($lang['btn_older']);
882ae614416SAnika Henke        $form->addElement(form_makeCloseTag('button'));
883abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
884a39955b0Smatthiasgrimm    }
885abdcc39fSmichael    $form->addElement(form_makeCloseTag('div'));
886abdcc39fSmichael    html_form('recent', $form);
887f3f0262cSandi}
888f3f0262cSandi
88915fae107Sandi/**
89015fae107Sandi * Display page index
89115fae107Sandi *
89215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
89342ea7f44SGerrit Uitslag *
89442ea7f44SGerrit Uitslag * @param string $ns
89515fae107Sandi */
896f3f0262cSandifunction html_index($ns){
897f3f0262cSandi    global $conf;
898f3f0262cSandi    global $ID;
899f3f0262cSandi    $ns  = cleanID($ns);
900f3f0262cSandi    if(empty($ns)){
90182f5f399SSatoshi Sahara        $ns = getNS($ID);
902dab290efSSatoshi Sahara        if($ns === false) $ns ='';
903f3f0262cSandi    }
90488d3a917Sandi    $ns  = utf8_encodeFN(str_replace(':','/',$ns));
905f3f0262cSandi
906a06884abSAndreas Gohr    echo p_locale_xhtml('index');
907158a5bffSDeathCamel57    echo '<div id="index__tree" class="index__tree">';
908f3f0262cSandi
909f3f0262cSandi    $data = array();
910f3f0262cSandi    search($data,$conf['datadir'],'search_index',array('ns' => $ns));
911a06884abSAndreas Gohr    echo html_buildlist($data,'idx','html_list_index','html_li_index');
912a06884abSAndreas Gohr
913a06884abSAndreas Gohr    echo '</div>';
914f3f0262cSandi}
915f3f0262cSandi
916f3f0262cSandi/**
91715fae107Sandi * Index item formatter
91815fae107Sandi *
919f3f0262cSandi * User function for html_buildlist()
92015fae107Sandi *
92115fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
92242ea7f44SGerrit Uitslag *
92342ea7f44SGerrit Uitslag * @param array $item
92442ea7f44SGerrit Uitslag * @return string
925f3f0262cSandi */
926f3f0262cSandifunction html_list_index($item){
92774ef1778SChristopher Smith    global $ID, $conf;
92874ef1778SChristopher Smith
929b8bc53ceSChristopher Smith    // prevent searchbots needlessly following links
93074ef1778SChristopher Smith    $nofollow = ($ID != $conf['start'] || $conf['sitemap']) ? 'rel="nofollow"' : '';
93174ef1778SChristopher Smith
932f3f0262cSandi    $ret = '';
933f3f0262cSandi    $base = ':'.$item['id'];
934f3f0262cSandi    $base = substr($base,strrpos($base,':')+1);
935f3f0262cSandi    if($item['type']=='d'){
936b1af9014SChristopher Smith        // FS#2766, no need for search bots to follow namespace links in the index
93764159a61SAndreas Gohr        $link = wl($ID, 'idx=' . rawurlencode($item['id']));
93864159a61SAndreas Gohr        $ret .= '<a href="' . $link . '" title="' . $item['id'] . '" class="idx_dir" ' . $nofollow . '><strong>';
939f3f0262cSandi        $ret .= $base;
940ed7ecb79SAnika Henke        $ret .= '</strong></a>';
941f3f0262cSandi    }else{
9429aa38483SMichael Hamann        // default is noNSorNS($id), but we want noNS($id) when useheading is off FS#2605
9439aa38483SMichael Hamann        $ret .= html_wikilink(':'.$item['id'], useHeading('navigation') ? null : noNS($item['id']));
944f3f0262cSandi    }
945f3f0262cSandi    return $ret;
946f3f0262cSandi}
947f3f0262cSandi
948f3f0262cSandi/**
949cb70c441Sandi * Index List item
950cb70c441Sandi *
951a1dee2b9SAdrian Lang * This user function is used in html_buildlist to build the
952cb70c441Sandi * <li> tags for namespaces when displaying the page index
953cb70c441Sandi * it gives different classes to opened or closed "folders"
954cb70c441Sandi *
955cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
95642ea7f44SGerrit Uitslag *
95742ea7f44SGerrit Uitslag * @param array $item
95842ea7f44SGerrit Uitslag * @return string html
959cb70c441Sandi */
960cb70c441Sandifunction html_li_index($item){
961f7dbf175SAndreas Gohr    global $INFO;
96221b07cb4SAndreas Gohr    global $ACT;
963f7dbf175SAndreas Gohr
9646fa4721aSAndreas Gohr    $class = '';
9656fa4721aSAndreas Gohr    $id = '';
9666fa4721aSAndreas Gohr
967cb70c441Sandi    if($item['type'] == "f"){
968f7dbf175SAndreas Gohr        // scroll to the current item
96921b07cb4SAndreas Gohr        if($item['id'] == $INFO['id'] && $ACT == 'index') {
970f7dbf175SAndreas Gohr            $id = ' id="scroll__here"';
971772f3c51SDeathCamel57            $class = ' bounce';
972f7dbf175SAndreas Gohr        }
9736fa4721aSAndreas Gohr        return '<li class="level'.$item['level'].$class.'" '.$id.'>';
974cb70c441Sandi    }elseif($item['open']){
975cb70c441Sandi        return '<li class="open">';
976cb70c441Sandi    }else{
977cb70c441Sandi        return '<li class="closed">';
978cb70c441Sandi    }
979cb70c441Sandi}
980cb70c441Sandi
981cb70c441Sandi/**
982cb70c441Sandi * Default List item
983cb70c441Sandi *
984cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
98542ea7f44SGerrit Uitslag *
98642ea7f44SGerrit Uitslag * @param array $item
98742ea7f44SGerrit Uitslag * @return string html
988cb70c441Sandi */
989cb70c441Sandifunction html_li_default($item){
990cb70c441Sandi    return '<li class="level'.$item['level'].'">';
991cb70c441Sandi}
992cb70c441Sandi
993cb70c441Sandi/**
99415fae107Sandi * Build an unordered list
99515fae107Sandi *
996f3f0262cSandi * Build an unordered list from the given $data array
997f3f0262cSandi * Each item in the array has to have a 'level' property
998f3f0262cSandi * the item itself gets printed by the given $func user
999cb70c441Sandi * function. The second and optional function is used to
1000cb70c441Sandi * print the <li> tag. Both user function need to accept
1001cb70c441Sandi * a single item.
100215fae107Sandi *
1003c5a8fd96SAndreas Gohr * Both user functions can be given as array to point to
1004c5a8fd96SAndreas Gohr * a member of an object.
1005c5a8fd96SAndreas Gohr *
100615fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
100780679bafSGerrit Uitslag *
100880679bafSGerrit Uitslag * @param array    $data  array with item arrays
100980679bafSGerrit Uitslag * @param string   $class class of ul wrapper
101080679bafSGerrit Uitslag * @param callable $func  callback to print an list item
10115a9597bbSTakamura * @param callable $lifunc callback to the opening li tag
101280679bafSGerrit Uitslag * @param bool     $forcewrapper Trigger building a wrapper ul if the first level is
1013ae614416SAnika Henke *                               0 (we have a root object) or 1 (just the root content)
101480679bafSGerrit Uitslag * @return string html of an unordered list
1015f3f0262cSandi */
101687671313SHakan Sandellfunction html_buildlist($data,$class,$func,$lifunc='html_li_default',$forcewrapper=false){
1017a1dee2b9SAdrian Lang    if (count($data) === 0) {
1018a1dee2b9SAdrian Lang        return '';
1019a1dee2b9SAdrian Lang    }
1020a1dee2b9SAdrian Lang
10212689c55fSMichael Große    $firstElement = reset($data);
10222689c55fSMichael Große    $start_level = $firstElement['level'];
10239e4f7880SAdrian Lang    $level = $start_level;
1024434f5921SHakan Sandell    $ret   = '';
1025434f5921SHakan Sandell    $open  = 0;
10269e4f7880SAdrian Lang
1027f3f0262cSandi    foreach ($data as $item){
1028f3f0262cSandi
1029f3f0262cSandi        if( $item['level'] > $level ){
1030f3f0262cSandi            //open new list
1031df52d0feSandi            for($i=0; $i<($item['level'] - $level); $i++){
1032434f5921SHakan Sandell                if ($i) $ret .= "<li class=\"clear\">";
1033f3f0262cSandi                $ret .= "\n<ul class=\"$class\">\n";
1034434f5921SHakan Sandell                $open++;
1035df52d0feSandi            }
1036434f5921SHakan Sandell            $level = $item['level'];
1037434f5921SHakan Sandell
1038f3f0262cSandi        }elseif( $item['level'] < $level ){
1039f3f0262cSandi            //close last item
1040f3f0262cSandi            $ret .= "</li>\n";
1041434f5921SHakan Sandell            while( $level > $item['level'] && $open > 0 ){
1042f3f0262cSandi                //close higher lists
1043f3f0262cSandi                $ret .= "</ul>\n</li>\n";
1044434f5921SHakan Sandell                $level--;
1045434f5921SHakan Sandell                $open--;
1046f3f0262cSandi            }
1047a1dee2b9SAdrian Lang        } elseif ($ret !== '') {
104887671313SHakan Sandell            //close previous item
1049f3f0262cSandi            $ret .= "</li>\n";
1050f3f0262cSandi        }
1051f3f0262cSandi
1052f3f0262cSandi        //print item
105334dbe711Schris        $ret .= call_user_func($lifunc,$item);
10540c6b58a8SAndreas Gohr        $ret .= '<div class="li">';
105534dbe711Schris
105634dbe711Schris        $ret .= call_user_func($func,$item);
10570c6b58a8SAndreas Gohr        $ret .= '</div>';
1058f3f0262cSandi    }
1059f3f0262cSandi
1060f3f0262cSandi    //close remaining items and lists
1061434f5921SHakan Sandell    $ret .= "</li>\n";
1062434f5921SHakan Sandell    while($open-- > 0) {
1063434f5921SHakan Sandell        $ret .= "</ul></li>\n";
1064434f5921SHakan Sandell    }
1065434f5921SHakan Sandell
1066434f5921SHakan Sandell    if ($forcewrapper || $start_level < 2) {
1067434f5921SHakan Sandell        // Trigger building a wrapper ul if the first level is
1068434f5921SHakan Sandell        // 0 (we have a root object) or 1 (just the root content)
1069434f5921SHakan Sandell        $ret = "\n<ul class=\"$class\">\n".$ret."</ul>\n";
1070f3f0262cSandi    }
1071f3f0262cSandi
1072f3f0262cSandi    return $ret;
1073f3f0262cSandi}
1074f3f0262cSandi
107515fae107Sandi/**
107615fae107Sandi * display backlinks
107715fae107Sandi *
107815fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
107911df47ecSMichael Klier * @author Michael Klier <chi@chimeric.de>
108015fae107Sandi */
1081f3f0262cSandifunction html_backlinks(){
1082f3f0262cSandi    global $ID;
108311df47ecSMichael Klier    global $lang;
1084f3f0262cSandi
1085c112d578Sandi    print p_locale_xhtml('backlinks');
1086f3f0262cSandi
1087*0cba610bSSatoshi Sahara    $data = MetadataSearch::backlinks($ID);
1088f3f0262cSandi
108911df47ecSMichael Klier    if(!empty($data)) {
1090f3f0262cSandi        print '<ul class="idx">';
109154f4c056SAndreas Gohr        foreach($data as $blink){
10920c6b58a8SAndreas Gohr            print '<li><div class="li">';
1093db959ae3SAndreas Gohr            print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink);
10940c6b58a8SAndreas Gohr            print '</div></li>';
1095f3f0262cSandi        }
1096f3f0262cSandi        print '</ul>';
109711df47ecSMichael Klier    } else {
109811df47ecSMichael Klier        print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
109911df47ecSMichael Klier    }
1100f3f0262cSandi}
1101f3f0262cSandi
11028d5e837eSMichael Hamann/**
11038d5e837eSMichael Hamann * Get header of diff HTML
110442ea7f44SGerrit Uitslag *
11058d5e837eSMichael Hamann * @param string $l_rev   Left revisions
11068d5e837eSMichael Hamann * @param string $r_rev   Right revision
11078d5e837eSMichael Hamann * @param string $id      Page id, if null $ID is used
11088d5e837eSMichael Hamann * @param bool   $media   If it is for media files
1109f76724a4STom N Harris * @param bool   $inline  Return the header on a single line
111042ea7f44SGerrit Uitslag * @return string[] HTML snippets for diff header
11118d5e837eSMichael Hamann */
1112f76724a4STom N Harrisfunction html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = false) {
111395b451bcSAdrian Lang    global $lang;
111495b451bcSAdrian Lang    if ($id === null) {
111595b451bcSAdrian Lang        global $ID;
111695b451bcSAdrian Lang        $id = $ID;
111795b451bcSAdrian Lang    }
1118f76724a4STom N Harris    $head_separator = $inline ? ' ' : '<br />';
111995b451bcSAdrian Lang    $media_or_wikiFN = $media ? 'mediaFN' : 'wikiFN';
112095b451bcSAdrian Lang    $ml_or_wl = $media ? 'ml' : 'wl';
112195b451bcSAdrian Lang    $l_minor = $r_minor = '';
112295b451bcSAdrian Lang
1123047bad06SGerrit Uitslag    if($media) {
11244f6e20c7SGerrit Uitslag        $changelog = new MediaChangeLog($id);
1125047bad06SGerrit Uitslag    } else {
11264f6e20c7SGerrit Uitslag        $changelog = new PageChangeLog($id);
1127047bad06SGerrit Uitslag    }
112895b451bcSAdrian Lang    if(!$l_rev){
112995b451bcSAdrian Lang        $l_head = '&mdash;';
113095b451bcSAdrian Lang    }else{
11314f6e20c7SGerrit Uitslag        $l_info   = $changelog->getRevisionInfo($l_rev);
113295b451bcSAdrian Lang        if($l_info['user']){
1133d317fb5dSAnika Henke            $l_user = '<bdi>'.editorinfo($l_info['user']).'</bdi>';
1134d317fb5dSAnika Henke            if(auth_ismanager()) $l_user .= ' <bdo dir="ltr">('.$l_info['ip'].')</bdo>';
113595b451bcSAdrian Lang        } else {
1136d317fb5dSAnika Henke            $l_user = '<bdo dir="ltr">'.$l_info['ip'].'</bdo>';
113795b451bcSAdrian Lang        }
113895b451bcSAdrian Lang        $l_user  = '<span class="user">'.$l_user.'</span>';
1139d317fb5dSAnika Henke        $l_sum   = ($l_info['sum']) ? '<span class="sum"><bdi>'.hsc($l_info['sum']).'</bdi></span>' : '';
114095b451bcSAdrian Lang        if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
114195b451bcSAdrian Lang
1142699c5072SAnika Henke        $l_head_title = ($media) ? dformat($l_rev) : $id.' ['.dformat($l_rev).']';
1143d317fb5dSAnika Henke        $l_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$l_rev").'">'.
1144d317fb5dSAnika Henke        $l_head_title.'</a></bdi>'.
1145f76724a4STom N Harris        $head_separator.$l_user.' '.$l_sum;
114695b451bcSAdrian Lang    }
114795b451bcSAdrian Lang
114895b451bcSAdrian Lang    if($r_rev){
11494f6e20c7SGerrit Uitslag        $r_info   = $changelog->getRevisionInfo($r_rev);
115095b451bcSAdrian Lang        if($r_info['user']){
1151d317fb5dSAnika Henke            $r_user = '<bdi>'.editorinfo($r_info['user']).'</bdi>';
1152d317fb5dSAnika Henke            if(auth_ismanager()) $r_user .= ' <bdo dir="ltr">('.$r_info['ip'].')</bdo>';
115395b451bcSAdrian Lang        } else {
1154d317fb5dSAnika Henke            $r_user = '<bdo dir="ltr">'.$r_info['ip'].'</bdo>';
115595b451bcSAdrian Lang        }
115695b451bcSAdrian Lang        $r_user = '<span class="user">'.$r_user.'</span>';
1157d317fb5dSAnika Henke        $r_sum  = ($r_info['sum']) ? '<span class="sum"><bdi>'.hsc($r_info['sum']).'</bdi></span>' : '';
115895b451bcSAdrian Lang        if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
115995b451bcSAdrian Lang
1160699c5072SAnika Henke        $r_head_title = ($media) ? dformat($r_rev) : $id.' ['.dformat($r_rev).']';
1161d317fb5dSAnika Henke        $r_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$r_rev").'">'.
1162d317fb5dSAnika Henke        $r_head_title.'</a></bdi>'.
1163f76724a4STom N Harris        $head_separator.$r_user.' '.$r_sum;
116495b451bcSAdrian Lang    }elseif($_rev = @filemtime($media_or_wikiFN($id))){
11654f6e20c7SGerrit Uitslag        $_info   = $changelog->getRevisionInfo($_rev);
116695b451bcSAdrian Lang        if($_info['user']){
1167d317fb5dSAnika Henke            $_user = '<bdi>'.editorinfo($_info['user']).'</bdi>';
1168d317fb5dSAnika Henke            if(auth_ismanager()) $_user .= ' <bdo dir="ltr">('.$_info['ip'].')</bdo>';
116995b451bcSAdrian Lang        } else {
1170d317fb5dSAnika Henke            $_user = '<bdo dir="ltr">'.$_info['ip'].'</bdo>';
117195b451bcSAdrian Lang        }
117295b451bcSAdrian Lang        $_user = '<span class="user">'.$_user.'</span>';
1173d317fb5dSAnika Henke        $_sum  = ($_info['sum']) ? '<span class="sum"><bdi>'.hsc($_info['sum']).'</span></bdi>' : '';
117495b451bcSAdrian Lang        if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
117595b451bcSAdrian Lang
1176699c5072SAnika Henke        $r_head_title = ($media) ? dformat($_rev) : $id.' ['.dformat($_rev).']';
1177d317fb5dSAnika Henke        $r_head  = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id).'">'.
1178d317fb5dSAnika Henke        $r_head_title.'</a></bdi> '.
117995b451bcSAdrian Lang        '('.$lang['current'].')'.
1180f76724a4STom N Harris        $head_separator.$_user.' '.$_sum;
118195b451bcSAdrian Lang    }else{
118295b451bcSAdrian Lang        $r_head = '&mdash; ('.$lang['current'].')';
118395b451bcSAdrian Lang    }
118495b451bcSAdrian Lang
118595b451bcSAdrian Lang    return array($l_head, $r_head, $l_minor, $r_minor);
118695b451bcSAdrian Lang}
118795b451bcSAdrian Lang
118815fae107Sandi/**
118904e99fe1SGerrit Uitslag * Show diff
1190baf0c3e5SGerrit Uitslag * between current page version and provided $text
1191baf0c3e5SGerrit Uitslag * or between the revisions provided via GET or POST
119215fae107Sandi *
119315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1194baf0c3e5SGerrit Uitslag * @param  string $text  when non-empty: compare with this text with most current version
119504e99fe1SGerrit Uitslag * @param  bool   $intro display the intro text
11968d5e837eSMichael Hamann * @param  string $type  type of the diff (inline or sidebyside)
119715fae107Sandi */
119872165381SAndreas Gohrfunction html_diff($text = '', $intro = true, $type = null) {
1199f3f0262cSandi    global $ID;
1200f3f0262cSandi    global $REV;
1201f3f0262cSandi    global $lang;
1202f0859d4bSTom N Harris    global $INPUT;
12033c94d07bSAnika Henke    global $INFO;
1204047bad06SGerrit Uitslag    $pagelog = new PageChangeLog($ID);
1205e1bd90ffSAndreas Gohr
1206c7686ac1SGerrit Uitslag    /*
1207c7686ac1SGerrit Uitslag     * Determine diff type
1208c7686ac1SGerrit Uitslag     */
12093c94d07bSAnika Henke    if(!$type) {
12103c94d07bSAnika Henke        $type = $INPUT->str('difftype');
12113c94d07bSAnika Henke        if(empty($type)) {
12123c94d07bSAnika Henke            $type = get_doku_pref('difftype', $type);
12133c94d07bSAnika Henke            if(empty($type) && $INFO['ismobile']) {
12143c94d07bSAnika Henke                $type = 'inline';
12153c94d07bSAnika Henke            }
12163c94d07bSAnika Henke        }
12173c94d07bSAnika Henke    }
121872165381SAndreas Gohr    if($type != 'inline') $type = 'sidebyside';
121972165381SAndreas Gohr
1220c7686ac1SGerrit Uitslag    /*
1221c7686ac1SGerrit Uitslag     * Determine requested revision(s)
1222c7686ac1SGerrit Uitslag     */
122377707b04SAndreas Gohr    // we're trying to be clever here, revisions to compare can be either
122477707b04SAndreas Gohr    // given as rev and rev2 parameters, with rev2 being optional. Or in an
122577707b04SAndreas Gohr    // array in rev2.
122677707b04SAndreas Gohr    $rev1 = $REV;
12277b3f8b16SAndreas Gohr
1228f1d7655bSAndreas Gohr    $rev2 = $INPUT->ref('rev2');
1229f1d7655bSAndreas Gohr    if(is_array($rev2)) {
1230f1d7655bSAndreas Gohr        $rev1 = (int) $rev2[0];
1231f1d7655bSAndreas Gohr        $rev2 = (int) $rev2[1];
123254041c77SAndreas Gohr
123354041c77SAndreas Gohr        if(!$rev1) {
123454041c77SAndreas Gohr            $rev1 = $rev2;
123554041c77SAndreas Gohr            unset($rev2);
123654041c77SAndreas Gohr        }
1237f3f0262cSandi    } else {
1238f0859d4bSTom N Harris        $rev2 = $INPUT->int('rev2');
12394d58bd99Sandi    }
12404d58bd99Sandi
1241c7686ac1SGerrit Uitslag    /*
1242c7686ac1SGerrit Uitslag     * Determine left and right revision, its texts and the header
1243c7686ac1SGerrit Uitslag     */
12443733161eSAdrian Lang    $r_minor = '';
12453733161eSAdrian Lang    $l_minor = '';
12463733161eSAdrian Lang
124777707b04SAndreas Gohr    if($text) { // compare text to the most current revision
124877707b04SAndreas Gohr        $l_rev = '';
124977707b04SAndreas Gohr        $l_text = rawWiki($ID, '');
125077707b04SAndreas Gohr        $l_head = '<a class="wikilink1" href="' . wl($ID) . '">' .
1251f2263577SAndreas Gohr            $ID . ' ' . dformat((int) @filemtime(wikiFN($ID))) . '</a> ' .
125277707b04SAndreas Gohr            $lang['current'];
125377707b04SAndreas Gohr
125477707b04SAndreas Gohr        $r_rev = '';
125577707b04SAndreas Gohr        $r_text = cleanText($text);
125677707b04SAndreas Gohr        $r_head = $lang['yours'];
1257e1bd90ffSAndreas Gohr    } else {
12586d9eab4dSMichael Hamann        if($rev1 && isset($rev2) && $rev2) { // two specific revisions wanted
125954041c77SAndreas Gohr            // make sure order is correct (older on the left)
126077707b04SAndreas Gohr            if($rev1 < $rev2) {
126177707b04SAndreas Gohr                $l_rev = $rev1;
126277707b04SAndreas Gohr                $r_rev = $rev2;
126377707b04SAndreas Gohr            } else {
126477707b04SAndreas Gohr                $l_rev = $rev2;
126577707b04SAndreas Gohr                $r_rev = $rev1;
1266e1bd90ffSAndreas Gohr            }
126777707b04SAndreas Gohr        } elseif($rev1) { // single revision given, compare to current
126877707b04SAndreas Gohr            $r_rev = '';
126977707b04SAndreas Gohr            $l_rev = $rev1;
127077707b04SAndreas Gohr        } else { // no revision was given, compare previous to current
127177707b04SAndreas Gohr            $r_rev = '';
1272f523c971SGerrit Uitslag            $revs = $pagelog->getRevisions(0, 1);
127377707b04SAndreas Gohr            $l_rev = $revs[0];
12746f8e9f59SAndreas Gohr            $REV = $l_rev; // store revision back in $REV
127577707b04SAndreas Gohr        }
127677707b04SAndreas Gohr
12777b3f8b16SAndreas Gohr        // when both revisions are empty then the page was created just now
12787b3f8b16SAndreas Gohr        if(!$l_rev && !$r_rev) {
12797b3f8b16SAndreas Gohr            $l_text = '';
12807b3f8b16SAndreas Gohr        } else {
128177707b04SAndreas Gohr            $l_text = rawWiki($ID, $l_rev);
12827b3f8b16SAndreas Gohr        }
128377707b04SAndreas Gohr        $r_text = rawWiki($ID, $r_rev);
128477707b04SAndreas Gohr
1285f76724a4STom N Harris        list($l_head, $r_head, $l_minor, $r_minor) = html_diff_head($l_rev, $r_rev, null, false, $type == 'inline');
128677707b04SAndreas Gohr    }
128777707b04SAndreas Gohr
1288c7686ac1SGerrit Uitslag    /*
1289c7686ac1SGerrit Uitslag     * Build navigation
1290c7686ac1SGerrit Uitslag     */
1291c7686ac1SGerrit Uitslag    $l_nav = '';
1292c7686ac1SGerrit Uitslag    $r_nav = '';
1293c7686ac1SGerrit Uitslag    if(!$text) {
1294baf0c3e5SGerrit Uitslag        list($l_nav, $r_nav) = html_diff_navigation($pagelog, $type, $l_rev, $r_rev);
1295c7686ac1SGerrit Uitslag    }
1296c7686ac1SGerrit Uitslag    /*
1297c7686ac1SGerrit Uitslag     * Create diff object and the formatter
1298c7686ac1SGerrit Uitslag     */
129904e99fe1SGerrit Uitslag    $diff = new Diff(explode("\n", $l_text), explode("\n", $r_text));
130077707b04SAndreas Gohr
130172165381SAndreas Gohr    if($type == 'inline') {
130204e99fe1SGerrit Uitslag        $diffformatter = new InlineDiffFormatter();
130372165381SAndreas Gohr    } else {
130404e99fe1SGerrit Uitslag        $diffformatter = new TableDiffFormatter();
130572165381SAndreas Gohr    }
1306c7686ac1SGerrit Uitslag    /*
1307c7686ac1SGerrit Uitslag     * Display intro
1308c7686ac1SGerrit Uitslag     */
1309c112d578Sandi    if($intro) print p_locale_xhtml('diff');
1310226bf2dcSGina Haeussge
1311c7686ac1SGerrit Uitslag    /*
1312c7686ac1SGerrit Uitslag     * Display type and exact reference
1313c7686ac1SGerrit Uitslag     */
1314226bf2dcSGina Haeussge    if(!$text) {
1315c130b0f8SAnika Henke        ptln('<div class="diffoptions group">');
131672165381SAndreas Gohr
1317c7686ac1SGerrit Uitslag
131872165381SAndreas Gohr        $form = new Doku_Form(array('action' => wl()));
13191b885c58SAndreas Gohr        $form->addHidden('id', $ID);
132072165381SAndreas Gohr        $form->addHidden('rev2[0]', $l_rev);
132172165381SAndreas Gohr        $form->addHidden('rev2[1]', $r_rev);
132272165381SAndreas Gohr        $form->addHidden('do', 'diff');
132304e99fe1SGerrit Uitslag        $form->addElement(
132404e99fe1SGerrit Uitslag             form_makeListboxField(
132572165381SAndreas Gohr                 'difftype',
132672165381SAndreas Gohr                 array(
132772165381SAndreas Gohr                     'sidebyside' => $lang['diff_side'],
132804e99fe1SGerrit Uitslag                     'inline' => $lang['diff_inline']
132904e99fe1SGerrit Uitslag                 ),
133072165381SAndreas Gohr                 $type,
133172165381SAndreas Gohr                 $lang['diff_type'],
133272165381SAndreas Gohr                 '', '',
133304e99fe1SGerrit Uitslag                 array('class' => 'quickselect')
133404e99fe1SGerrit Uitslag             )
133504e99fe1SGerrit Uitslag        );
133672165381SAndreas Gohr        $form->addElement(form_makeButton('submit', 'diff', 'Go'));
133772165381SAndreas Gohr        $form->printForm();
133872165381SAndreas Gohr
13394fc1354aSGerrit Uitslag        ptln('<p>');
13404fc1354aSGerrit Uitslag        // link to exactly this view FS#2835
13418fcb305dSGerrit Uitslag        echo html_diff_navigationlink($type, 'difflink', $l_rev, $r_rev ? $r_rev : $INFO['currentrev']);
134298a6b214SAnika Henke        ptln('</p>');
1343cfe2f202SGerrit Uitslag
1344cfe2f202SGerrit Uitslag        ptln('</div>'); // .diffoptions
134504e99fe1SGerrit Uitslag    }
1346f1f2f711SGerrit Uitslag
134751684808SGerrit Uitslag    /*
1348c7686ac1SGerrit Uitslag     * Display diff view table
134951684808SGerrit Uitslag     */
1350f3f0262cSandi    ?>
1351c7b28ffdSAnika Henke    <div class="table">
135272165381SAndreas Gohr    <table class="diff diff_<?php echo $type ?>">
1353c7686ac1SGerrit Uitslag
135404e99fe1SGerrit Uitslag        <?php
1355c7686ac1SGerrit Uitslag        //navigation and header
1356cfe2f202SGerrit Uitslag        if($type == 'inline') {
1357cfe2f202SGerrit Uitslag            if(!$text) { ?>
1358cfe2f202SGerrit Uitslag                <tr>
1359cfe2f202SGerrit Uitslag                    <td class="diff-lineheader">-</td>
1360cfe2f202SGerrit Uitslag                    <td class="diffnav"><?php echo $l_nav ?></td>
1361cfe2f202SGerrit Uitslag                </tr>
1362f76724a4STom N Harris                <tr>
136304e99fe1SGerrit Uitslag                    <th class="diff-lineheader">-</th>
136404e99fe1SGerrit Uitslag                    <th <?php echo $l_minor ?>>
1365f76724a4STom N Harris                        <?php echo $l_head ?>
1366f76724a4STom N Harris                    </th>
1367f76724a4STom N Harris                </tr>
1368cfe2f202SGerrit Uitslag            <?php } ?>
1369cfe2f202SGerrit Uitslag            <tr>
1370cfe2f202SGerrit Uitslag                <td class="diff-lineheader">+</td>
1371cfe2f202SGerrit Uitslag                <td class="diffnav"><?php echo $r_nav ?></td>
1372cfe2f202SGerrit Uitslag            </tr>
1373f76724a4STom N Harris            <tr>
137404e99fe1SGerrit Uitslag                <th class="diff-lineheader">+</th>
137504e99fe1SGerrit Uitslag                <th <?php echo $r_minor ?>>
1376f76724a4STom N Harris                    <?php echo $r_head ?>
1377f76724a4STom N Harris                </th>
1378f76724a4STom N Harris            </tr>
1379cfe2f202SGerrit Uitslag        <?php } else {
1380cfe2f202SGerrit Uitslag            if(!$text) { ?>
1381cfe2f202SGerrit Uitslag                <tr>
1382cfe2f202SGerrit Uitslag                    <td colspan="2" class="diffnav"><?php echo $l_nav ?></td>
1383cfe2f202SGerrit Uitslag                    <td colspan="2" class="diffnav"><?php echo $r_nav ?></td>
1384cfe2f202SGerrit Uitslag                </tr>
1385cfe2f202SGerrit Uitslag            <?php } ?>
1386f3f0262cSandi            <tr>
1387e5e61eb0SAnika Henke                <th colspan="2" <?php echo $l_minor ?>>
138877707b04SAndreas Gohr                    <?php echo $l_head ?>
1389daf4ca4eSAnika Henke                </th>
1390e5e61eb0SAnika Henke                <th colspan="2" <?php echo $r_minor ?>>
139177707b04SAndreas Gohr                    <?php echo $r_head ?>
1392daf4ca4eSAnika Henke                </th>
1393f3f0262cSandi            </tr>
1394f76724a4STom N Harris        <?php }
1395c7686ac1SGerrit Uitslag
1396c7686ac1SGerrit Uitslag        //diff view
139704e99fe1SGerrit Uitslag        echo html_insert_softbreaks($diffformatter->format($diff)); ?>
1398c7686ac1SGerrit Uitslag
1399f3f0262cSandi    </table>
1400c7b28ffdSAnika Henke    </div>
14014da078a3Smatthiasgrimm<?php
1402f3f0262cSandi}
1403f3f0262cSandi
14044fc1354aSGerrit Uitslag/**
1405baf0c3e5SGerrit Uitslag * Create html for revision navigation
1406baf0c3e5SGerrit Uitslag *
1407baf0c3e5SGerrit Uitslag * @param PageChangeLog $pagelog changelog object of current page
1408baf0c3e5SGerrit Uitslag * @param string        $type    inline vs sidebyside
1409baf0c3e5SGerrit Uitslag * @param int           $l_rev   left revision timestamp
1410baf0c3e5SGerrit Uitslag * @param int           $r_rev   right revision timestamp
1411baf0c3e5SGerrit Uitslag * @return string[] html of left and right navigation elements
1412baf0c3e5SGerrit Uitslag */
1413baf0c3e5SGerrit Uitslagfunction html_diff_navigation($pagelog, $type, $l_rev, $r_rev) {
1414baf0c3e5SGerrit Uitslag    global $INFO, $ID;
1415baf0c3e5SGerrit Uitslag
14164d5954c8SGerrit Uitslag    // last timestamp is not in changelog, retrieve timestamp from metadata
14174d5954c8SGerrit Uitslag    // note: when page is removed, the metadata timestamp is zero
1418bdca103aSAndreas Gohr    if(!$r_rev) {
1419bdca103aSAndreas Gohr        if(isset($INFO['meta']['last_change']['date'])) {
1420bdca103aSAndreas Gohr            $r_rev = $INFO['meta']['last_change']['date'];
1421bdca103aSAndreas Gohr        } else {
1422bdca103aSAndreas Gohr            $r_rev = 0;
1423bdca103aSAndreas Gohr        }
1424bdca103aSAndreas Gohr    }
1425baf0c3e5SGerrit Uitslag
1426baf0c3e5SGerrit Uitslag    //retrieve revisions with additional info
1427baf0c3e5SGerrit Uitslag    list($l_revs, $r_revs) = $pagelog->getRevisionsAround($l_rev, $r_rev);
1428baf0c3e5SGerrit Uitslag    $l_revisions = array();
1429621bbd2aSGerrit Uitslag    if(!$l_rev) {
1430621bbd2aSGerrit Uitslag        $l_revisions[0] = array(0, "", false); //no left revision given, add dummy
1431621bbd2aSGerrit Uitslag    }
1432baf0c3e5SGerrit Uitslag    foreach($l_revs as $rev) {
1433baf0c3e5SGerrit Uitslag        $info = $pagelog->getRevisionInfo($rev);
1434baf0c3e5SGerrit Uitslag        $l_revisions[$rev] = array(
1435baf0c3e5SGerrit Uitslag            $rev,
1436c006b6aaSGerrit Uitslag            dformat($info['date']) . ' ' . editorinfo($info['user'], true) . ' ' . $info['sum'],
1437621bbd2aSGerrit Uitslag            $r_rev ? $rev >= $r_rev : false //disable?
1438baf0c3e5SGerrit Uitslag        );
1439baf0c3e5SGerrit Uitslag    }
1440baf0c3e5SGerrit Uitslag    $r_revisions = array();
1441621bbd2aSGerrit Uitslag    if(!$r_rev) {
1442621bbd2aSGerrit Uitslag        $r_revisions[0] = array(0, "", false); //no right revision given, add dummy
1443621bbd2aSGerrit Uitslag    }
1444baf0c3e5SGerrit Uitslag    foreach($r_revs as $rev) {
1445baf0c3e5SGerrit Uitslag        $info = $pagelog->getRevisionInfo($rev);
1446baf0c3e5SGerrit Uitslag        $r_revisions[$rev] = array(
1447baf0c3e5SGerrit Uitslag            $rev,
1448c006b6aaSGerrit Uitslag            dformat($info['date']) . ' ' . editorinfo($info['user'], true) . ' ' . $info['sum'],
1449baf0c3e5SGerrit Uitslag            $rev <= $l_rev //disable?
1450baf0c3e5SGerrit Uitslag        );
1451baf0c3e5SGerrit Uitslag    }
1452621bbd2aSGerrit Uitslag
1453baf0c3e5SGerrit Uitslag    //determine previous/next revisions
1454baf0c3e5SGerrit Uitslag    $l_index = array_search($l_rev, $l_revs);
1455baf0c3e5SGerrit Uitslag    $l_prev = $l_revs[$l_index + 1];
1456baf0c3e5SGerrit Uitslag    $l_next = $l_revs[$l_index - 1];
1457621bbd2aSGerrit Uitslag    if($r_rev) {
1458baf0c3e5SGerrit Uitslag        $r_index = array_search($r_rev, $r_revs);
1459baf0c3e5SGerrit Uitslag        $r_prev = $r_revs[$r_index + 1];
1460baf0c3e5SGerrit Uitslag        $r_next = $r_revs[$r_index - 1];
1461621bbd2aSGerrit Uitslag    } else {
1462621bbd2aSGerrit Uitslag        //removed page
1463621bbd2aSGerrit Uitslag        if($l_next) {
1464621bbd2aSGerrit Uitslag            $r_prev = $r_revs[0];
1465621bbd2aSGerrit Uitslag        } else {
1466621bbd2aSGerrit Uitslag            $r_prev = null;
1467621bbd2aSGerrit Uitslag        }
1468621bbd2aSGerrit Uitslag        $r_next = null;
1469621bbd2aSGerrit Uitslag    }
1470baf0c3e5SGerrit Uitslag
1471baf0c3e5SGerrit Uitslag    /*
1472baf0c3e5SGerrit Uitslag     * Left side:
1473baf0c3e5SGerrit Uitslag     */
1474baf0c3e5SGerrit Uitslag    $l_nav = '';
1475baf0c3e5SGerrit Uitslag    //move back
1476baf0c3e5SGerrit Uitslag    if($l_prev) {
1477baf0c3e5SGerrit Uitslag        $l_nav .= html_diff_navigationlink($type, 'diffbothprevrev', $l_prev, $r_prev);
1478baf0c3e5SGerrit Uitslag        $l_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_prev, $r_rev);
1479baf0c3e5SGerrit Uitslag    }
1480baf0c3e5SGerrit Uitslag    //dropdown
1481baf0c3e5SGerrit Uitslag    $form = new Doku_Form(array('action' => wl()));
1482baf0c3e5SGerrit Uitslag    $form->addHidden('id', $ID);
1483baf0c3e5SGerrit Uitslag    $form->addHidden('difftype', $type);
1484baf0c3e5SGerrit Uitslag    $form->addHidden('rev2[1]', $r_rev);
1485baf0c3e5SGerrit Uitslag    $form->addHidden('do', 'diff');
1486baf0c3e5SGerrit Uitslag    $form->addElement(
1487baf0c3e5SGerrit Uitslag         form_makeListboxField(
1488baf0c3e5SGerrit Uitslag             'rev2[0]',
1489baf0c3e5SGerrit Uitslag             $l_revisions,
1490baf0c3e5SGerrit Uitslag             $l_rev,
1491baf0c3e5SGerrit Uitslag             '', '', '',
1492baf0c3e5SGerrit Uitslag             array('class' => 'quickselect')
1493baf0c3e5SGerrit Uitslag         )
1494baf0c3e5SGerrit Uitslag    );
1495baf0c3e5SGerrit Uitslag    $form->addElement(form_makeButton('submit', 'diff', 'Go'));
1496baf0c3e5SGerrit Uitslag    $l_nav .= $form->getForm();
1497baf0c3e5SGerrit Uitslag    //move forward
1498621bbd2aSGerrit Uitslag    if($l_next && ($l_next < $r_rev || !$r_rev)) {
1499baf0c3e5SGerrit Uitslag        $l_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_next, $r_rev);
1500baf0c3e5SGerrit Uitslag    }
1501baf0c3e5SGerrit Uitslag
1502baf0c3e5SGerrit Uitslag    /*
1503baf0c3e5SGerrit Uitslag     * Right side:
1504baf0c3e5SGerrit Uitslag     */
1505baf0c3e5SGerrit Uitslag    $r_nav = '';
1506baf0c3e5SGerrit Uitslag    //move back
1507baf0c3e5SGerrit Uitslag    if($l_rev < $r_prev) {
1508baf0c3e5SGerrit Uitslag        $r_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_rev, $r_prev);
1509baf0c3e5SGerrit Uitslag    }
1510baf0c3e5SGerrit Uitslag    //dropdown
1511baf0c3e5SGerrit Uitslag    $form = new Doku_Form(array('action' => wl()));
1512baf0c3e5SGerrit Uitslag    $form->addHidden('id', $ID);
1513baf0c3e5SGerrit Uitslag    $form->addHidden('rev2[0]', $l_rev);
1514baf0c3e5SGerrit Uitslag    $form->addHidden('difftype', $type);
1515baf0c3e5SGerrit Uitslag    $form->addHidden('do', 'diff');
1516baf0c3e5SGerrit Uitslag    $form->addElement(
1517baf0c3e5SGerrit Uitslag         form_makeListboxField(
1518baf0c3e5SGerrit Uitslag             'rev2[1]',
1519baf0c3e5SGerrit Uitslag             $r_revisions,
1520baf0c3e5SGerrit Uitslag             $r_rev,
1521baf0c3e5SGerrit Uitslag             '', '', '',
1522baf0c3e5SGerrit Uitslag             array('class' => 'quickselect')
1523baf0c3e5SGerrit Uitslag         )
1524baf0c3e5SGerrit Uitslag    );
1525baf0c3e5SGerrit Uitslag    $form->addElement(form_makeButton('submit', 'diff', 'Go'));
1526baf0c3e5SGerrit Uitslag    $r_nav .= $form->getForm();
1527baf0c3e5SGerrit Uitslag    //move forward
1528baf0c3e5SGerrit Uitslag    if($r_next) {
1529baf0c3e5SGerrit Uitslag        if($pagelog->isCurrentRevision($r_next)) {
1530baf0c3e5SGerrit Uitslag            $r_nav .= html_diff_navigationlink($type, 'difflastrev', $l_rev); //last revision is diff with current page
1531baf0c3e5SGerrit Uitslag        } else {
1532baf0c3e5SGerrit Uitslag            $r_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_rev, $r_next);
1533baf0c3e5SGerrit Uitslag        }
1534baf0c3e5SGerrit Uitslag        $r_nav .= html_diff_navigationlink($type, 'diffbothnextrev', $l_next, $r_next);
1535baf0c3e5SGerrit Uitslag    }
1536baf0c3e5SGerrit Uitslag    return array($l_nav, $r_nav);
1537baf0c3e5SGerrit Uitslag}
1538baf0c3e5SGerrit Uitslag
1539baf0c3e5SGerrit Uitslag/**
15404fc1354aSGerrit Uitslag * Create html link to a diff defined by two revisions
15414fc1354aSGerrit Uitslag *
154298a6b214SAnika Henke * @param string $difftype display type
154398a6b214SAnika Henke * @param string $linktype
15444fc1354aSGerrit Uitslag * @param int $lrev oldest revision
15454fc1354aSGerrit Uitslag * @param int $rrev newest revision or null for diff with current revision
15464fc1354aSGerrit Uitslag * @return string html of link to a diff
15474fc1354aSGerrit Uitslag */
154898a6b214SAnika Henkefunction html_diff_navigationlink($difftype, $linktype, $lrev, $rrev = null) {
154998a6b214SAnika Henke    global $ID, $lang;
1550621bbd2aSGerrit Uitslag    if(!$rrev) {
15514fc1354aSGerrit Uitslag        $urlparam = array(
15524fc1354aSGerrit Uitslag            'do' => 'diff',
15534fc1354aSGerrit Uitslag            'rev' => $lrev,
155498a6b214SAnika Henke            'difftype' => $difftype,
15554fc1354aSGerrit Uitslag        );
15564fc1354aSGerrit Uitslag    } else {
15574fc1354aSGerrit Uitslag        $urlparam = array(
15584fc1354aSGerrit Uitslag            'do' => 'diff',
15594fc1354aSGerrit Uitslag            'rev2[0]' => $lrev,
15604fc1354aSGerrit Uitslag            'rev2[1]' => $rrev,
156198a6b214SAnika Henke            'difftype' => $difftype,
15624fc1354aSGerrit Uitslag        );
15634fc1354aSGerrit Uitslag    }
1564cfe2f202SGerrit Uitslag    return  '<a class="' . $linktype . '" href="' . wl($ID, $urlparam) . '" title="' . $lang[$linktype] . '">' .
1565cfe2f202SGerrit Uitslag                '<span>' . $lang[$linktype] . '</span>' .
1566cfe2f202SGerrit Uitslag            '</a>' . "\n";
15674fc1354aSGerrit Uitslag}
15684fc1354aSGerrit Uitslag
1569a8397511SGerrit Uitslag/**
1570a8397511SGerrit Uitslag * Insert soft breaks in diff html
1571a8397511SGerrit Uitslag *
157242ea7f44SGerrit Uitslag * @param string $diffhtml
1573a8397511SGerrit Uitslag * @return string
1574a8397511SGerrit Uitslag */
1575fcfecb69SChristopher Smithfunction html_insert_softbreaks($diffhtml) {
1576fcfecb69SChristopher Smith    // search the diff html string for both:
1577fcfecb69SChristopher Smith    // - html tags, so these can be ignored
1578fcfecb69SChristopher Smith    // - long strings of characters without breaking characters
1579fcfecb69SChristopher Smith    return preg_replace_callback('/<[^>]*>|[^<> ]{12,}/','html_softbreak_callback',$diffhtml);
1580fcfecb69SChristopher Smith}
1581fcfecb69SChristopher Smith
1582a8397511SGerrit Uitslag/**
1583a8397511SGerrit Uitslag * callback which adds softbreaks
1584a8397511SGerrit Uitslag *
1585a8397511SGerrit Uitslag * @param array $match array with first the complete match
1586a8397511SGerrit Uitslag * @return string the replacement
1587a8397511SGerrit Uitslag */
1588fcfecb69SChristopher Smithfunction html_softbreak_callback($match){
1589fcfecb69SChristopher Smith    // if match is an html tag, return it intact
15902401f18dSSyntaxseed    if ($match[0][0] == '<') return $match[0];
1591fcfecb69SChristopher Smith
1592fcfecb69SChristopher Smith    // its a long string without a breaking character,
1593fcfecb69SChristopher Smith    // make certain characters into breaking characters by inserting a
159454436b19Sbleistivt    // word break opportunity (<wbr> tag) in front of them.
1595fcfecb69SChristopher Smith    $regex = <<< REGEX
1596fcfecb69SChristopher Smith(?(?=              # start a conditional expression with a positive look ahead ...
1597298a7e08SChristopher Smith&\#?\\w{1,6};)     # ... for html entities - we don't want to split them (ok to catch some invalid combinations)
1598298a7e08SChristopher Smith&\#?\\w{1,6};      # yes pattern - a quicker match for the html entity, since we know we have one
1599fcfecb69SChristopher Smith|
160007a7d21aSChristopher Smith[?/,&\#;:]         # no pattern - any other group of 'special' characters to insert a breaking character after
160107a7d21aSChristopher Smith)+                 # end conditional expression
1602fcfecb69SChristopher SmithREGEX;
1603fcfecb69SChristopher Smith
160454436b19Sbleistivt    return preg_replace('<'.$regex.'>xu','\0<wbr>',$match[0]);
1605fcfecb69SChristopher Smith}
1606fcfecb69SChristopher Smith
160715fae107Sandi/**
160815fae107Sandi * show warning on conflict detection
160915fae107Sandi *
161015fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
161142ea7f44SGerrit Uitslag *
161242ea7f44SGerrit Uitslag * @param string $text
161342ea7f44SGerrit Uitslag * @param string $summary
161415fae107Sandi */
1615f3f0262cSandifunction html_conflict($text,$summary){
1616f3f0262cSandi    global $ID;
1617f3f0262cSandi    global $lang;
1618f3f0262cSandi
1619c112d578Sandi    print p_locale_xhtml('conflict');
1620e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
1621fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
1622fdb8d77bSTom N Harris    $form->addHidden('wikitext', $text);
1623fdb8d77bSTom N Harris    $form->addHidden('summary', $summary);
1624fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
1625fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
1626fdb8d77bSTom N Harris    html_form('conflict', $form);
1627fdb8d77bSTom N Harris    print '<br /><br /><br /><br />'.NL;
1628f3f0262cSandi}
1629f3f0262cSandi
1630f3f0262cSandi/**
163115fae107Sandi * Prints the global message array
163215fae107Sandi *
163315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1634f3f0262cSandi */
1635f3f0262cSandifunction html_msgarea(){
1636cc58224cSMichael Hamann    global $MSG, $MSG_shown;
16378d5e837eSMichael Hamann    /** @var array $MSG */
1638cc58224cSMichael Hamann    // store if the global $MSG has already been shown and thus HTML output has been started
1639cc58224cSMichael Hamann    $MSG_shown = true;
1640cc58224cSMichael Hamann
1641f3f0262cSandi    if(!isset($MSG)) return;
1642f3f0262cSandi
16434af9f0d4SAndreas Gohr    $shown = array();
1644f3f0262cSandi    foreach($MSG as $msg){
16454af9f0d4SAndreas Gohr        $hash = md5($msg['msg']);
16464af9f0d4SAndreas Gohr        if(isset($shown[$hash])) continue; // skip double messages
1647f755f9abSChristopher Smith        if(info_msg_allowed($msg)){
1648f3f0262cSandi            print '<div class="'.$msg['lvl'].'">';
1649f3f0262cSandi            print $msg['msg'];
1650f3f0262cSandi            print '</div>';
1651d3bae478SChristopher Smith        }
16524af9f0d4SAndreas Gohr        $shown[$hash] = 1;
1653f3f0262cSandi    }
1654cc58224cSMichael Hamann
1655cc58224cSMichael Hamann    unset($GLOBALS['MSG']);
1656f3f0262cSandi}
1657f3f0262cSandi
1658f3f0262cSandi/**
1659f3f0262cSandi * Prints the registration form
166015fae107Sandi *
166115fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1662f3f0262cSandi */
1663f3f0262cSandifunction html_register(){
1664f3f0262cSandi    global $lang;
1665cab2716aSmatthias.grimm    global $conf;
1666f0859d4bSTom N Harris    global $INPUT;
1667f3f0262cSandi
1668a669bfe0SChristopher Smith    $base_attrs = array('size'=>50,'required'=>'required');
1669a669bfe0SChristopher Smith    $email_attrs = $base_attrs + array('type'=>'email','class'=>'edit');
1670a669bfe0SChristopher Smith
1671c112d578Sandi    print p_locale_xhtml('register');
1672fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1673e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__register'));
1674bf413a4eSAnika Henke    $form->startFieldset($lang['btn_register']);
1675fdb8d77bSTom N Harris    $form->addHidden('do', 'register');
1676fdb8d77bSTom N Harris    $form->addHidden('save', '1');
167764159a61SAndreas Gohr    $form->addElement(
167864159a61SAndreas Gohr        form_makeTextField(
167964159a61SAndreas Gohr            'login',
168064159a61SAndreas Gohr            $INPUT->post->str('login'),
168164159a61SAndreas Gohr            $lang['user'],
168264159a61SAndreas Gohr            '',
168364159a61SAndreas Gohr            'block',
168464159a61SAndreas Gohr            $base_attrs
168564159a61SAndreas Gohr        )
168664159a61SAndreas Gohr    );
1687cab2716aSmatthias.grimm    if (!$conf['autopasswd']) {
1688a669bfe0SChristopher Smith        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', $base_attrs));
1689a669bfe0SChristopher Smith        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', $base_attrs));
1690cab2716aSmatthias.grimm    }
169164159a61SAndreas Gohr    $form->addElement(
169264159a61SAndreas Gohr        form_makeTextField(
169364159a61SAndreas Gohr            'fullname',
169464159a61SAndreas Gohr            $INPUT->post->str('fullname'),
169564159a61SAndreas Gohr            $lang['fullname'],
169664159a61SAndreas Gohr            '',
169764159a61SAndreas Gohr            'block',
169864159a61SAndreas Gohr            $base_attrs
169964159a61SAndreas Gohr        )
170064159a61SAndreas Gohr    );
170164159a61SAndreas Gohr    $form->addElement(
170264159a61SAndreas Gohr        form_makeField(
170364159a61SAndreas Gohr            'email',
170464159a61SAndreas Gohr            'email',
170564159a61SAndreas Gohr            $INPUT->post->str('email'),
170664159a61SAndreas Gohr            $lang['email'],
170764159a61SAndreas Gohr            '',
170864159a61SAndreas Gohr            'block',
170964159a61SAndreas Gohr            $email_attrs
171064159a61SAndreas Gohr        )
171164159a61SAndreas Gohr    );
1712bf413a4eSAnika Henke    $form->addElement(form_makeButton('submit', '', $lang['btn_register']));
1713fdb8d77bSTom N Harris    $form->endFieldset();
1714fdb8d77bSTom N Harris    html_form('register', $form);
1715cab2716aSmatthias.grimm
1716fdb8d77bSTom N Harris    print '</div>'.NL;
1717f3f0262cSandi}
1718f3f0262cSandi
1719f3f0262cSandi/**
17208b06d178Schris * Print the update profile form
17218b06d178Schris *
17228b06d178Schris * @author Christopher Smith <chris@jalakai.co.uk>
17238b06d178Schris * @author Andreas Gohr <andi@splitbrain.org>
17248b06d178Schris */
17258b06d178Schrisfunction html_updateprofile(){
17268b06d178Schris    global $lang;
17278b06d178Schris    global $conf;
1728f0859d4bSTom N Harris    global $INPUT;
17298b06d178Schris    global $INFO;
1730e1d9dcc8SAndreas Gohr    /** @var AuthPlugin $auth */
173182fd59b6SAndreas Gohr    global $auth;
17328b06d178Schris
17338b06d178Schris    print p_locale_xhtml('updateprofile');
17343b1338ffSChristopher Smith    print '<div class="centeralign">'.NL;
17358b06d178Schris
1736f0859d4bSTom N Harris    $fullname = $INPUT->post->str('fullname', $INFO['userinfo']['name'], true);
1737f0859d4bSTom N Harris    $email = $INPUT->post->str('email', $INFO['userinfo']['mail'], true);
1738e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__register'));
1739fdb8d77bSTom N Harris    $form->startFieldset($lang['profile']);
1740fdb8d77bSTom N Harris    $form->addHidden('do', 'profile');
1741fdb8d77bSTom N Harris    $form->addHidden('save', '1');
174264159a61SAndreas Gohr    $form->addElement(
174364159a61SAndreas Gohr        form_makeTextField(
174464159a61SAndreas Gohr            'login',
174564159a61SAndreas Gohr            $_SERVER['REMOTE_USER'],
174664159a61SAndreas Gohr            $lang['user'],
174764159a61SAndreas Gohr            '',
174864159a61SAndreas Gohr            'block',
174964159a61SAndreas Gohr            array('size' => '50', 'disabled' => 'disabled')
175064159a61SAndreas Gohr        )
175164159a61SAndreas Gohr    );
1752fdb8d77bSTom N Harris    $attr = array('size'=>'50');
1753fdb8d77bSTom N Harris    if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1754f0859d4bSTom N Harris    $form->addElement(form_makeTextField('fullname', $fullname, $lang['fullname'], '', 'block', $attr));
17553b1338ffSChristopher Smith    $attr = array('size'=>'50', 'class'=>'edit');
175639ba8890SAndreas Gohr    if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
17573b1338ffSChristopher Smith    $form->addElement(form_makeField('email','email', $email, $lang['email'], '', 'block', $attr));
1758fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1759fdb8d77bSTom N Harris    if ($auth->canDo('modPass')) {
1760fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1761fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1762fdb8d77bSTom N Harris    }
1763fdb8d77bSTom N Harris    if ($conf['profileconfirm']) {
1764fdb8d77bSTom N Harris        $form->addElement(form_makeTag('br'));
176564159a61SAndreas Gohr        $form->addElement(
176664159a61SAndreas Gohr            form_makePasswordField(
176764159a61SAndreas Gohr                'oldpass',
176864159a61SAndreas Gohr                $lang['oldpass'],
176964159a61SAndreas Gohr                '',
177064159a61SAndreas Gohr                'block',
177164159a61SAndreas Gohr                array('size' => '50', 'required' => 'required')
177264159a61SAndreas Gohr            )
177364159a61SAndreas Gohr        );
1774fdb8d77bSTom N Harris    }
1775fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1776fdb8d77bSTom N Harris    $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
17773b1338ffSChristopher Smith
1778fdb8d77bSTom N Harris    $form->endFieldset();
1779fdb8d77bSTom N Harris    html_form('updateprofile', $form);
17802a7abf2dSChristopher Smith
17812a7abf2dSChristopher Smith    if ($auth->canDo('delUser') && actionOK('profile_delete')) {
17822a7abf2dSChristopher Smith        $form_profiledelete = new Doku_Form(array('id' => 'dw__profiledelete'));
17832a7abf2dSChristopher Smith        $form_profiledelete->startFieldset($lang['profdeleteuser']);
17842a7abf2dSChristopher Smith        $form_profiledelete->addHidden('do', 'profile_delete');
17852a7abf2dSChristopher Smith        $form_profiledelete->addHidden('delete', '1');
178664159a61SAndreas Gohr        $form_profiledelete->addElement(
178764159a61SAndreas Gohr            form_makeCheckboxField(
178864159a61SAndreas Gohr                'confirm_delete',
178964159a61SAndreas Gohr                '1',
179064159a61SAndreas Gohr                $lang['profconfdelete'],
179164159a61SAndreas Gohr                'dw__confirmdelete',
179264159a61SAndreas Gohr                '',
179364159a61SAndreas Gohr                array('required' => 'required')
179464159a61SAndreas Gohr            )
179564159a61SAndreas Gohr        );
17962a7abf2dSChristopher Smith        if ($conf['profileconfirm']) {
17972a7abf2dSChristopher Smith            $form_profiledelete->addElement(form_makeTag('br'));
179864159a61SAndreas Gohr            $form_profiledelete->addElement(
179964159a61SAndreas Gohr                form_makePasswordField(
180064159a61SAndreas Gohr                    'oldpass',
180164159a61SAndreas Gohr                    $lang['oldpass'],
180264159a61SAndreas Gohr                    '',
180364159a61SAndreas Gohr                    'block',
180464159a61SAndreas Gohr                    array('size' => '50', 'required' => 'required')
180564159a61SAndreas Gohr                )
180664159a61SAndreas Gohr            );
18072a7abf2dSChristopher Smith        }
18082a7abf2dSChristopher Smith        $form_profiledelete->addElement(form_makeButton('submit', '', $lang['btn_deleteuser']));
18092a7abf2dSChristopher Smith        $form_profiledelete->endFieldset();
18102a7abf2dSChristopher Smith
18112a7abf2dSChristopher Smith        html_form('profiledelete', $form_profiledelete);
18122a7abf2dSChristopher Smith    }
18132a7abf2dSChristopher Smith
1814fdb8d77bSTom N Harris    print '</div>'.NL;
18158b06d178Schris}
18168b06d178Schris
18178b06d178Schris/**
18187c4635c4SAdrian Lang * Preprocess edit form data
181915fae107Sandi *
182015fae107Sandi * @author   Andreas Gohr <andi@splitbrain.org>
18212ffea8f2SAdrian Lang *
18222ffea8f2SAdrian Lang * @triggers HTML_EDITFORM_OUTPUT
1823f3f0262cSandi */
18245a932e77SAdrian Langfunction html_edit(){
1825f0859d4bSTom N Harris    global $INPUT;
1826f3f0262cSandi    global $ID;
1827f3f0262cSandi    global $REV;
1828f3f0262cSandi    global $DATE;
1829f3f0262cSandi    global $PRE;
1830f3f0262cSandi    global $SUF;
1831f3f0262cSandi    global $INFO;
1832f3f0262cSandi    global $SUM;
1833f3f0262cSandi    global $lang;
1834f3f0262cSandi    global $conf;
183545a99335SAdrian Lang    global $TEXT;
1836f3f0262cSandi
1837f0859d4bSTom N Harris    if ($INPUT->has('changecheck')) {
1838f0859d4bSTom N Harris        $check = $INPUT->str('changecheck');
183945a99335SAdrian Lang    } elseif(!$INFO['exists']){
184045a99335SAdrian Lang        // $TEXT has been loaded from page template
184145a99335SAdrian Lang        $check = md5('');
18428fe3bb00STom N Harris    } else {
184345a99335SAdrian Lang        $check = md5($TEXT);
18448fe3bb00STom N Harris    }
184545a99335SAdrian Lang    $mod = md5($TEXT) !== $check;
1846f3f0262cSandi
184727eb9321SAnika Henke    $wr = $INFO['writable'] && !$INFO['locked'];
184845a99335SAdrian Lang    $include = 'edit';
1849f3f0262cSandi    if($wr){
1850ffde0ac9SAdrian Lang        if ($REV) $include = 'editrev';
1851f3f0262cSandi    }else{
1852409d7af7SAndreas Gohr        // check pseudo action 'source'
1853409d7af7SAndreas Gohr        if(!actionOK('source')){
1854409d7af7SAndreas Gohr            msg('Command disabled: source',-1);
1855409d7af7SAndreas Gohr            return;
1856409d7af7SAndreas Gohr        }
1857ffde0ac9SAdrian Lang        $include = 'read';
1858f3f0262cSandi    }
18597c4635c4SAdrian Lang
18607c4635c4SAdrian Lang    global $license;
186142c7abd6SAndreas Gohr
1862e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
1863fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
1864fdb8d77bSTom N Harris    $form->addHidden('rev', $REV);
1865fdb8d77bSTom N Harris    $form->addHidden('date', $DATE);
186642de51b1SAdrian Lang    $form->addHidden('prefix', $PRE . '.');
1867fdb8d77bSTom N Harris    $form->addHidden('suffix', $SUF);
1868fdb8d77bSTom N Harris    $form->addHidden('changecheck', $check);
18698e4da260SAdrian Lang
18702ffea8f2SAdrian Lang    $data = array('form' => $form,
18712ffea8f2SAdrian Lang                  'wr'   => $wr,
18722ffea8f2SAdrian Lang                  'media_manager' => true,
1873182ac905SAndreas Gohr                  'target' => ($INPUT->has('target') && $wr) ? $INPUT->str('target') : 'section',
18742ffea8f2SAdrian Lang                  'intro_locale' => $include);
187512c96aceSAdrian Lang
187612c96aceSAdrian Lang    if ($data['target'] !== 'section') {
187712c96aceSAdrian Lang        // Only emit event if page is writable, section edit data is valid and
187812c96aceSAdrian Lang        // edit target is not section.
1879cbb44eabSAndreas Gohr        Event::createAndTrigger('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true);
18802ffea8f2SAdrian Lang    } else {
18812ffea8f2SAdrian Lang        html_edit_form($data);
18822ffea8f2SAdrian Lang    }
1883ffde0ac9SAdrian Lang    if (isset($data['intro_locale'])) {
1884ffde0ac9SAdrian Lang        echo p_locale_xhtml($data['intro_locale']);
1885ffde0ac9SAdrian Lang    }
18868e4da260SAdrian Lang
1887b7eccc60SAdrian Lang    $form->addHidden('target', $data['target']);
18882571786cSLarsDW223    if ($INPUT->has('hid')) {
18892571786cSLarsDW223        $form->addHidden('hid', $INPUT->str('hid'));
18902571786cSLarsDW223    }
1891ec57f119SLarsDW223    if ($INPUT->has('codeblockOffset')) {
1892ec57f119SLarsDW223        $form->addHidden('codeblockOffset', $INPUT->str('codeblockOffset'));
1893ec57f119SLarsDW223    }
18940607bfeeSAnika Henke    $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar', 'class'=>'editBar')));
1895fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1896fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
1897fdb8d77bSTom N Harris    if ($wr) {
1898fdb8d77bSTom N Harris        $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
189964159a61SAndreas Gohr        $form->addElement(
190064159a61SAndreas Gohr            form_makeButton(
190164159a61SAndreas Gohr                'submit',
190264159a61SAndreas Gohr                'save',
190364159a61SAndreas Gohr                $lang['btn_save'],
190464159a61SAndreas Gohr                array('id' => 'edbtn__save', 'accesskey' => 's', 'tabindex' => '4')
190564159a61SAndreas Gohr            )
190664159a61SAndreas Gohr        );
190764159a61SAndreas Gohr        $form->addElement(
190864159a61SAndreas Gohr            form_makeButton(
190964159a61SAndreas Gohr                'submit',
191064159a61SAndreas Gohr                'preview',
191164159a61SAndreas Gohr                $lang['btn_preview'],
191264159a61SAndreas Gohr                array('id' => 'edbtn__preview', 'accesskey' => 'p', 'tabindex' => '5')
191364159a61SAndreas Gohr            )
191464159a61SAndreas Gohr        );
19153f5c3c1eSAndreas Gohr        $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel'], array('tabindex'=>'6')));
1916fdb8d77bSTom N Harris        $form->addElement(form_makeCloseTag('div'));
1917fdb8d77bSTom N Harris        $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
191864159a61SAndreas Gohr        $form->addElement(
191964159a61SAndreas Gohr            form_makeTextField(
192064159a61SAndreas Gohr                'summary',
192164159a61SAndreas Gohr                $SUM,
192264159a61SAndreas Gohr                $lang['summary'],
192364159a61SAndreas Gohr                'edit__summary',
192464159a61SAndreas Gohr                'nowrap',
192564159a61SAndreas Gohr                array('size' => '50', 'tabindex' => '2')
192664159a61SAndreas Gohr            )
192764159a61SAndreas Gohr        );
1928fdb8d77bSTom N Harris        $elem = html_minoredit();
1929fdb8d77bSTom N Harris        if ($elem) $form->addElement($elem);
1930fdb8d77bSTom N Harris        $form->addElement(form_makeCloseTag('div'));
1931fdb8d77bSTom N Harris    }
1932fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
19335808bc54SAndreas Gohr    if($wr && $conf['license']){
1934066fee30SAndreas Gohr        $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1935066fee30SAndreas Gohr        $out  = $lang['licenseok'];
1936066fee30SAndreas Gohr        $out .= ' <a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
1937507a2aebSAnika Henke        if($conf['target']['extern']) $out .= ' target="'.$conf['target']['extern'].'"';
1938066fee30SAndreas Gohr        $out .= '>'.$license[$conf['license']]['name'].'</a>';
1939066fee30SAndreas Gohr        $form->addElement($out);
1940066fee30SAndreas Gohr        $form->addElement(form_makeCloseTag('div'));
1941066fee30SAndreas Gohr    }
19428e4da260SAdrian Lang
19438e4da260SAdrian Lang    if ($wr) {
19448e4da260SAdrian Lang        // sets changed to true when previewed
1945677d2785SDominik Eckelmann        echo '<script type="text/javascript">/*<![CDATA[*/'. NL;
19468e4da260SAdrian Lang        echo 'textChanged = ' . ($mod ? 'true' : 'false');
1947677d2785SDominik Eckelmann        echo '/*!]]>*/</script>' . NL;
19488e4da260SAdrian Lang    } ?>
19495a99d25bSAnika Henke    <div class="editBox" role="application">
19508e4da260SAdrian Lang
19518a65ef2eSAnika Henke    <div class="toolbar group">
195264159a61SAndreas Gohr        <div id="tool__bar" class="tool__bar"><?php
195364159a61SAndreas Gohr            if ($wr && $data['media_manager']){
195464159a61SAndreas Gohr                ?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
195564159a61SAndreas Gohr                target="_blank"><?php echo $lang['mediaselect'] ?></a><?php
19569ddafcedSAndreas Gohr            }?>
19579ddafcedSAndreas Gohr        </div>
1958c49e647bSMichael Große    </div>
19590aabe6f8SMichael Große    <div id="draft__status" class="draft__status">
19600aabe6f8SMichael Große        <?php
19610aabe6f8SMichael Große        $draft = new \dokuwiki\Draft($ID, $INFO['client']);
19620aabe6f8SMichael Große        if ($draft->isDraftAvailable()) {
19630aabe6f8SMichael Große            echo $draft->getDraftMessage();
19640aabe6f8SMichael Große        }
19650aabe6f8SMichael Große        ?>
19668e4da260SAdrian Lang    </div>
19678e4da260SAdrian Lang    <?php
19688e4da260SAdrian Lang
1969fdb8d77bSTom N Harris    html_form('edit', $form);
1970fdb8d77bSTom N Harris    print '</div>'.NL;
1971f3f0262cSandi}
1972f3f0262cSandi
1973f3f0262cSandi/**
19748e4da260SAdrian Lang * Display the default edit form
19758e4da260SAdrian Lang *
19768e4da260SAdrian Lang * Is the default action for HTML_EDIT_FORMSELECTION.
197742ea7f44SGerrit Uitslag *
1978baf0c3e5SGerrit Uitslag * @param mixed[] $param
19798e4da260SAdrian Lang */
19808e4da260SAdrian Langfunction html_edit_form($param) {
198145a99335SAdrian Lang    global $TEXT;
198212c96aceSAdrian Lang
198312c96aceSAdrian Lang    if ($param['target'] !== 'section') {
1984ff711734SAndreas Gohr        msg('No editor for edit target ' . hsc($param['target']) . ' found.', -1);
198512c96aceSAdrian Lang    }
198612c96aceSAdrian Lang
19878e4da260SAdrian Lang    $attr = array('tabindex'=>'1');
198812c96aceSAdrian Lang    if (!$param['wr']) $attr['readonly'] = 'readonly';
198912c96aceSAdrian Lang
199012c96aceSAdrian Lang    $param['form']->addElement(form_makeWikiText($TEXT, $attr));
19918e4da260SAdrian Lang}
19928e4da260SAdrian Lang
19938e4da260SAdrian Lang/**
1994b6912aeaSAndreas Gohr * Adds a checkbox for minor edits for logged in users
1995b6912aeaSAndreas Gohr *
1996b1f92db2SAdrian Lang * @author Andreas Gohr <andi@splitbrain.org>
199742ea7f44SGerrit Uitslag *
199842ea7f44SGerrit Uitslag * @return array|bool
1999b6912aeaSAndreas Gohr */
2000b6912aeaSAndreas Gohrfunction html_minoredit(){
2001b6912aeaSAndreas Gohr    global $conf;
2002b6912aeaSAndreas Gohr    global $lang;
2003f0859d4bSTom N Harris    global $INPUT;
2004b6912aeaSAndreas Gohr    // minor edits are for logged in users only
2005b6912aeaSAndreas Gohr    if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
2006fdb8d77bSTom N Harris        return false;
2007b6912aeaSAndreas Gohr    }
2008b6912aeaSAndreas Gohr
2009b6912aeaSAndreas Gohr    $p = array();
2010b6912aeaSAndreas Gohr    $p['tabindex'] = 3;
2011f0859d4bSTom N Harris    if($INPUT->bool('minor')) $p['checked']='checked';
2012fdb8d77bSTom N Harris    return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
2013b6912aeaSAndreas Gohr}
2014b6912aeaSAndreas Gohr
2015b6912aeaSAndreas Gohr/**
2016f3f0262cSandi * prints some debug info
201715fae107Sandi *
201815fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
2019f3f0262cSandi */
2020f3f0262cSandifunction html_debug(){
2021f3f0262cSandi    global $conf;
2022d16a4edaSandi    global $lang;
2023e1d9dcc8SAndreas Gohr    /** @var AuthPlugin $auth */
20245298a619SAndreas Gohr    global $auth;
2025100a97e3SAndreas Gohr    global $INFO;
2026100a97e3SAndreas Gohr
202728fb55ffSandi    //remove sensitive data
202828fb55ffSandi    $cnf = $conf;
202924297a69SAndreas Gohr    debug_guard($cnf);
2030100a97e3SAndreas Gohr    $nfo = $INFO;
203124297a69SAndreas Gohr    debug_guard($nfo);
2032100a97e3SAndreas Gohr    $ses = $_SESSION;
203324297a69SAndreas Gohr    debug_guard($ses);
2034f3f0262cSandi
2035f3f0262cSandi    print '<html><body>';
2036f3f0262cSandi
2037f3f0262cSandi    print '<p>When reporting bugs please send all the following ';
2038f3f0262cSandi    print 'output as a mail to andi@splitbrain.org ';
2039f3f0262cSandi    print 'The best way to do this is to save this page in your browser</p>';
2040f3f0262cSandi
2041100a97e3SAndreas Gohr    print '<b>$INFO:</b><pre>';
2042100a97e3SAndreas Gohr    print_r($nfo);
2043100a97e3SAndreas Gohr    print '</pre>';
2044100a97e3SAndreas Gohr
2045f3f0262cSandi    print '<b>$_SERVER:</b><pre>';
2046f3f0262cSandi    print_r($_SERVER);
2047f3f0262cSandi    print '</pre>';
2048f3f0262cSandi
2049f3f0262cSandi    print '<b>$conf:</b><pre>';
205028fb55ffSandi    print_r($cnf);
2051f3f0262cSandi    print '</pre>';
2052f3f0262cSandi
2053ed7b5f09Sandi    print '<b>DOKU_BASE:</b><pre>';
2054ed7b5f09Sandi    print DOKU_BASE;
2055f3f0262cSandi    print '</pre>';
2056f3f0262cSandi
2057ed7b5f09Sandi    print '<b>abs DOKU_BASE:</b><pre>';
2058ed7b5f09Sandi    print DOKU_URL;
2059ed7b5f09Sandi    print '</pre>';
2060ed7b5f09Sandi
2061ed7b5f09Sandi    print '<b>rel DOKU_BASE:</b><pre>';
2062f3f0262cSandi    print dirname($_SERVER['PHP_SELF']).'/';
2063f3f0262cSandi    print '</pre>';
2064f3f0262cSandi
2065f3f0262cSandi    print '<b>PHP Version:</b><pre>';
2066f3f0262cSandi    print phpversion();
2067f3f0262cSandi    print '</pre>';
2068f3f0262cSandi
2069f3f0262cSandi    print '<b>locale:</b><pre>';
2070f3f0262cSandi    print setlocale(LC_ALL,0);
2071f3f0262cSandi    print '</pre>';
2072f3f0262cSandi
2073d16a4edaSandi    print '<b>encoding:</b><pre>';
2074d16a4edaSandi    print $lang['encoding'];
2075d16a4edaSandi    print '</pre>';
2076d16a4edaSandi
20775298a619SAndreas Gohr    if($auth){
20785298a619SAndreas Gohr        print '<b>Auth backend capabilities:</b><pre>';
20792f46ade0SChristopher Smith        foreach ($auth->getCapabilities() as $cando){
20802f46ade0SChristopher Smith            print '   '.str_pad($cando,16) . ' => ' . (int)$auth->canDo($cando) . NL;
20812f46ade0SChristopher Smith        }
20825298a619SAndreas Gohr        print '</pre>';
20835298a619SAndreas Gohr    }
20845298a619SAndreas Gohr
20853aa54d7cSAndreas Gohr    print '<b>$_SESSION:</b><pre>';
2086100a97e3SAndreas Gohr    print_r($ses);
20873aa54d7cSAndreas Gohr    print '</pre>';
20883aa54d7cSAndreas Gohr
2089f3f0262cSandi    print '<b>Environment:</b><pre>';
2090f3f0262cSandi    print_r($_ENV);
2091f3f0262cSandi    print '</pre>';
2092f3f0262cSandi
2093f3f0262cSandi    print '<b>PHP settings:</b><pre>';
2094f3f0262cSandi    $inis = ini_get_all();
2095f3f0262cSandi    print_r($inis);
2096f3f0262cSandi    print '</pre>';
2097f3f0262cSandi
2098e89b7c1eSChristopher Smith    if (function_exists('apache_get_version')) {
209959bc3b48SGerrit Uitslag        $apache = array();
2100e89b7c1eSChristopher Smith        $apache['version'] = apache_get_version();
2101e89b7c1eSChristopher Smith
2102e89b7c1eSChristopher Smith        if (function_exists('apache_get_modules')) {
2103e89b7c1eSChristopher Smith            $apache['modules'] = apache_get_modules();
2104e89b7c1eSChristopher Smith        }
2105e89b7c1eSChristopher Smith        print '<b>Apache</b><pre>';
2106e89b7c1eSChristopher Smith        print_r($apache);
2107e89b7c1eSChristopher Smith        print '</pre>';
2108e89b7c1eSChristopher Smith    }
2109e89b7c1eSChristopher Smith
2110f3f0262cSandi    print '</body></html>';
2111f3f0262cSandi}
2112f3f0262cSandi
211310271ce4SAndreas Gohr/**
21148b06d178Schris * Form to request a new password for an existing account
21158b06d178Schris *
21168b06d178Schris * @author Benoit Chesneau <benoit@bchesneau.info>
2117cc204bbdSAndreas Gohr * @author Andreas Gohr <gohr@cosmocode.de>
211811e2ce22Schris */
21198b06d178Schrisfunction html_resendpwd() {
21208b06d178Schris    global $lang;
21218b06d178Schris    global $conf;
2122f0859d4bSTom N Harris    global $INPUT;
2123c19fe9c0Sandi
2124f0859d4bSTom N Harris    $token = preg_replace('/[^a-f0-9]+/','',$INPUT->str('pwauth'));
2125cc204bbdSAndreas Gohr
2126cc204bbdSAndreas Gohr    if(!$conf['autopasswd'] && $token){
2127cc204bbdSAndreas Gohr        print p_locale_xhtml('resetpwd');
2128cc204bbdSAndreas Gohr        print '<div class="centeralign">'.NL;
2129cc204bbdSAndreas Gohr        $form = new Doku_Form(array('id' => 'dw__resendpwd'));
2130cc204bbdSAndreas Gohr        $form->startFieldset($lang['btn_resendpwd']);
2131cc204bbdSAndreas Gohr        $form->addHidden('token', $token);
2132cc204bbdSAndreas Gohr        $form->addHidden('do', 'resendpwd');
2133cc204bbdSAndreas Gohr
2134cc204bbdSAndreas Gohr        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
2135cc204bbdSAndreas Gohr        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
2136cc204bbdSAndreas Gohr
2137cc204bbdSAndreas Gohr        $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
2138cc204bbdSAndreas Gohr        $form->endFieldset();
2139cc204bbdSAndreas Gohr        html_form('resendpwd', $form);
2140cc204bbdSAndreas Gohr        print '</div>'.NL;
2141cc204bbdSAndreas Gohr    }else{
21428b06d178Schris        print p_locale_xhtml('resendpwd');
2143fdb8d77bSTom N Harris        print '<div class="centeralign">'.NL;
2144e351c80dSAdrian Lang        $form = new Doku_Form(array('id' => 'dw__resendpwd'));
2145fdb8d77bSTom N Harris        $form->startFieldset($lang['resendpwd']);
2146fdb8d77bSTom N Harris        $form->addHidden('do', 'resendpwd');
2147fdb8d77bSTom N Harris        $form->addHidden('save', '1');
2148fdb8d77bSTom N Harris        $form->addElement(form_makeTag('br'));
2149f0859d4bSTom N Harris        $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block'));
2150fdb8d77bSTom N Harris        $form->addElement(form_makeTag('br'));
2151fdb8d77bSTom N Harris        $form->addElement(form_makeTag('br'));
2152fdb8d77bSTom N Harris        $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
2153fdb8d77bSTom N Harris        $form->endFieldset();
2154fdb8d77bSTom N Harris        html_form('resendpwd', $form);
2155fdb8d77bSTom N Harris        print '</div>'.NL;
2156fdb8d77bSTom N Harris    }
2157cc204bbdSAndreas Gohr}
2158cc204bbdSAndreas Gohr
2159fdb8d77bSTom N Harris/**
2160b8595a66SAndreas Gohr * Return the TOC rendered to XHTML
2161b8595a66SAndreas Gohr *
2162b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
216342ea7f44SGerrit Uitslag *
216442ea7f44SGerrit Uitslag * @param array $toc
216542ea7f44SGerrit Uitslag * @return string html
2166b8595a66SAndreas Gohr */
2167b8595a66SAndreas Gohrfunction html_TOC($toc){
2168b8595a66SAndreas Gohr    if(!count($toc)) return '';
2169b8595a66SAndreas Gohr    global $lang;
2170b8595a66SAndreas Gohr    $out  = '<!-- TOC START -->'.DOKU_LF;
2171158a5bffSDeathCamel57    $out .= '<div id="dw__toc" class="dw__toc">'.DOKU_LF;
217248722ac8SAnika Henke    $out .= '<h3 class="toggle">';
2173b8595a66SAndreas Gohr    $out .= $lang['toc'];
2174d5acc30dSAnika Henke    $out .= '</h3>'.DOKU_LF;
2175d5acc30dSAnika Henke    $out .= '<div>'.DOKU_LF;
217687671313SHakan Sandell    $out .= html_buildlist($toc,'toc','html_list_toc','html_li_default',true);
2177b8595a66SAndreas Gohr    $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
2178b8595a66SAndreas Gohr    $out .= '<!-- TOC END -->'.DOKU_LF;
2179db959ae3SAndreas Gohr    return $out;
2180db959ae3SAndreas Gohr}
2181b8595a66SAndreas Gohr
2182b8595a66SAndreas Gohr/**
2183b8595a66SAndreas Gohr * Callback for html_buildlist
218442ea7f44SGerrit Uitslag *
218542ea7f44SGerrit Uitslag * @param array $item
218642ea7f44SGerrit Uitslag * @return string html
2187b8595a66SAndreas Gohr */
2188b8595a66SAndreas Gohrfunction html_list_toc($item){
2189c66972f2SAdrian Lang    if(isset($item['hid'])){
21907d91652aSAndreas Gohr        $link = '#'.$item['hid'];
21917d91652aSAndreas Gohr    }else{
21927d91652aSAndreas Gohr        $link = $item['link'];
21937d91652aSAndreas Gohr    }
21947d91652aSAndreas Gohr
2195d5acc30dSAnika Henke    return '<a href="'.$link.'">'.hsc($item['title']).'</a>';
2196b8595a66SAndreas Gohr}
2197b8595a66SAndreas Gohr
2198b8595a66SAndreas Gohr/**
2199b8595a66SAndreas Gohr * Helper function to build TOC items
2200b8595a66SAndreas Gohr *
2201b8595a66SAndreas Gohr * Returns an array ready to be added to a TOC array
2202b8595a66SAndreas Gohr *
2203b8595a66SAndreas Gohr * @param string $link  - where to link (if $hash set to '#' it's a local anchor)
2204b8595a66SAndreas Gohr * @param string $text  - what to display in the TOC
2205b8595a66SAndreas Gohr * @param int    $level - nesting level
2206b8595a66SAndreas Gohr * @param string $hash  - is prepended to the given $link, set blank if you want full links
22078d5e837eSMichael Hamann * @return array the toc item
2208b8595a66SAndreas Gohr */
2209b8595a66SAndreas Gohrfunction html_mktocitem($link, $text, $level, $hash='#'){
2210b8595a66SAndreas Gohr    return  array( 'link'  => $hash.$link,
2211b8595a66SAndreas Gohr            'title' => $text,
2212b8595a66SAndreas Gohr            'type'  => 'ul',
22132bb0d541Schris            'level' => $level);
2214b8595a66SAndreas Gohr}
2215b8595a66SAndreas Gohr
2216b8595a66SAndreas Gohr/**
2217fdb8d77bSTom N Harris * Output a Doku_Form object.
2218fdb8d77bSTom N Harris * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
2219fdb8d77bSTom N Harris *
2220fdb8d77bSTom N Harris * @author Tom N Harris <tnharris@whoopdedo.org>
222142ea7f44SGerrit Uitslag *
22228d5e837eSMichael Hamann * @param string     $name The name of the form
22238d5e837eSMichael Hamann * @param Doku_Form  $form The form
2224fdb8d77bSTom N Harris */
2225fdb8d77bSTom N Harrisfunction html_form($name, &$form) {
2226fdb8d77bSTom N Harris    // Safety check in case the caller forgets.
2227fdb8d77bSTom N Harris    $form->endFieldset();
2228cbb44eabSAndreas Gohr    Event::createAndTrigger('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
2229fdb8d77bSTom N Harris}
2230fdb8d77bSTom N Harris
2231fdb8d77bSTom N Harris/**
2232fdb8d77bSTom N Harris * Form print function.
2233fdb8d77bSTom N Harris * Just calls printForm() on the data object.
223442ea7f44SGerrit Uitslag *
22358d5e837eSMichael Hamann * @param Doku_Form $data The form
2236fdb8d77bSTom N Harris */
2237fdb8d77bSTom N Harrisfunction html_form_output($data) {
2238fdb8d77bSTom N Harris    $data->printForm();
22398b06d178Schris}
2240340756e4Sandi
224107bf32b2SAndreas Gohr/**
224207bf32b2SAndreas Gohr * Embed a flash object in HTML
224307bf32b2SAndreas Gohr *
224407bf32b2SAndreas Gohr * This will create the needed HTML to embed a flash movie in a cross browser
224507bf32b2SAndreas Gohr * compatble way using valid XHTML
224607bf32b2SAndreas Gohr *
224707bf32b2SAndreas Gohr * The parameters $params, $flashvars and $atts need to be associative arrays.
224807bf32b2SAndreas Gohr * No escaping needs to be done for them. The alternative content *has* to be
224907bf32b2SAndreas Gohr * escaped because it is used as is. If no alternative content is given
225007bf32b2SAndreas Gohr * $lang['noflash'] is used.
225107bf32b2SAndreas Gohr *
225207bf32b2SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
225307bf32b2SAndreas Gohr * @link   http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
225407bf32b2SAndreas Gohr *
225507bf32b2SAndreas Gohr * @param string $swf      - the SWF movie to embed
225607bf32b2SAndreas Gohr * @param int $width       - width of the flash movie in pixels
225707bf32b2SAndreas Gohr * @param int $height      - height of the flash movie in pixels
225807bf32b2SAndreas Gohr * @param array $params    - additional parameters (<param>)
225907bf32b2SAndreas Gohr * @param array $flashvars - parameters to be passed in the flashvar parameter
226007bf32b2SAndreas Gohr * @param array $atts      - additional attributes for the <object> tag
226107bf32b2SAndreas Gohr * @param string $alt      - alternative content (is NOT automatically escaped!)
2262b3d1090eSMichael Hamann * @return string         - the XHTML markup
226307bf32b2SAndreas Gohr */
226407bf32b2SAndreas Gohrfunction html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
226507bf32b2SAndreas Gohr    global $lang;
226607bf32b2SAndreas Gohr
226707bf32b2SAndreas Gohr    $out = '';
226807bf32b2SAndreas Gohr
226907bf32b2SAndreas Gohr    // prepare the object attributes
227007bf32b2SAndreas Gohr    if(is_null($atts)) $atts = array();
227107bf32b2SAndreas Gohr    $atts['width']  = (int) $width;
2272d4c61e61SAndreas Gohr    $atts['height'] = (int) $height;
227307bf32b2SAndreas Gohr    if(!$atts['width'])  $atts['width']  = 425;
227407bf32b2SAndreas Gohr    if(!$atts['height']) $atts['height'] = 350;
227507bf32b2SAndreas Gohr
227607bf32b2SAndreas Gohr    // add object attributes for standard compliant browsers
227707bf32b2SAndreas Gohr    $std = $atts;
227807bf32b2SAndreas Gohr    $std['type'] = 'application/x-shockwave-flash';
227907bf32b2SAndreas Gohr    $std['data'] = $swf;
228007bf32b2SAndreas Gohr
228107bf32b2SAndreas Gohr    // add object attributes for IE
228207bf32b2SAndreas Gohr    $ie  = $atts;
228307bf32b2SAndreas Gohr    $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
228407bf32b2SAndreas Gohr
228507bf32b2SAndreas Gohr    // open object (with conditional comments)
228607bf32b2SAndreas Gohr    $out .= '<!--[if !IE]> -->'.NL;
228707bf32b2SAndreas Gohr    $out .= '<object '.buildAttributes($std).'>'.NL;
228807bf32b2SAndreas Gohr    $out .= '<!-- <![endif]-->'.NL;
228907bf32b2SAndreas Gohr    $out .= '<!--[if IE]>'.NL;
229007bf32b2SAndreas Gohr    $out .= '<object '.buildAttributes($ie).'>'.NL;
229107bf32b2SAndreas Gohr    $out .= '    <param name="movie" value="'.hsc($swf).'" />'.NL;
22929ae41cdcSAndreas Gohr    $out .= '<!--><!-- -->'.NL;
229307bf32b2SAndreas Gohr
229407bf32b2SAndreas Gohr    // print params
229507bf32b2SAndreas Gohr    if(is_array($params)) foreach($params as $key => $val){
229607bf32b2SAndreas Gohr        $out .= '  <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
229707bf32b2SAndreas Gohr    }
229807bf32b2SAndreas Gohr
229907bf32b2SAndreas Gohr    // add flashvars
230007bf32b2SAndreas Gohr    if(is_array($flashvars)){
2301d4c61e61SAndreas Gohr        $out .= '  <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
230207bf32b2SAndreas Gohr    }
230307bf32b2SAndreas Gohr
230407bf32b2SAndreas Gohr    // alternative content
230507bf32b2SAndreas Gohr    if($alt){
230607bf32b2SAndreas Gohr        $out .= $alt.NL;
230707bf32b2SAndreas Gohr    }else{
230807bf32b2SAndreas Gohr        $out .= $lang['noflash'].NL;
230907bf32b2SAndreas Gohr    }
231007bf32b2SAndreas Gohr
231107bf32b2SAndreas Gohr    // finish
231207bf32b2SAndreas Gohr    $out .= '</object>'.NL;
231307bf32b2SAndreas Gohr    $out .= '<!-- <![endif]-->'.NL;
231407bf32b2SAndreas Gohr
231507bf32b2SAndreas Gohr    return $out;
231607bf32b2SAndreas Gohr}
231707bf32b2SAndreas Gohr
23188d5e837eSMichael Hamann/**
23198d5e837eSMichael Hamann * Prints HTML code for the given tab structure
23208d5e837eSMichael Hamann *
23218d5e837eSMichael Hamann * @param array  $tabs        tab structure
23228d5e837eSMichael Hamann * @param string $current_tab the current tab id
23238d5e837eSMichael Hamann */
232495b451bcSAdrian Langfunction html_tabs($tabs, $current_tab = null) {
232594add303SAnika Henke    echo '<ul class="tabs">'.NL;
232695b451bcSAdrian Lang
232795b451bcSAdrian Lang    foreach($tabs as $id => $tab) {
232895b451bcSAdrian Lang        html_tab($tab['href'], $tab['caption'], $id === $current_tab);
232995b451bcSAdrian Lang    }
233095b451bcSAdrian Lang
233194add303SAnika Henke    echo '</ul>'.NL;
233295b451bcSAdrian Lang}
2333cd2a4cfdSAnika Henke
233495b451bcSAdrian Lang/**
233595b451bcSAdrian Lang * Prints a single tab
233695b451bcSAdrian Lang *
233795b451bcSAdrian Lang * @author Kate Arzamastseva <pshns@ukr.net>
233895b451bcSAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
233995b451bcSAdrian Lang *
234095b451bcSAdrian Lang * @param string $href - tab href
234195b451bcSAdrian Lang * @param string $caption - tab caption
234295b451bcSAdrian Lang * @param boolean $selected - is tab selected
234395b451bcSAdrian Lang */
234495b451bcSAdrian Lang
234595b451bcSAdrian Langfunction html_tab($href, $caption, $selected=false) {
234695b451bcSAdrian Lang    $tab = '<li>';
234795b451bcSAdrian Lang    if ($selected) {
234895b451bcSAdrian Lang        $tab .= '<strong>';
234995b451bcSAdrian Lang    } else {
235095b451bcSAdrian Lang        $tab .= '<a href="' . hsc($href) . '">';
235195b451bcSAdrian Lang    }
235295b451bcSAdrian Lang    $tab .= hsc($caption)
235395b451bcSAdrian Lang         .  '</' . ($selected ? 'strong' : 'a') . '>'
235494add303SAnika Henke         .  '</li>'.NL;
235595b451bcSAdrian Lang    echo $tab;
235695b451bcSAdrian Lang}
235795b451bcSAdrian Lang
2358cd2a4cfdSAnika Henke/**
2359cd2a4cfdSAnika Henke * Display size change
2360cd2a4cfdSAnika Henke *
2361cd2a4cfdSAnika Henke * @param int $sizechange - size of change in Bytes
2362cd2a4cfdSAnika Henke * @param Doku_Form $form - form to add elements to
2363cd2a4cfdSAnika Henke */
2364cd2a4cfdSAnika Henke
2365cd2a4cfdSAnika Henkefunction html_sizechange($sizechange, Doku_Form $form) {
2366cd2a4cfdSAnika Henke    if(isset($sizechange)) {
2367cd2a4cfdSAnika Henke        $class = 'sizechange';
2368cd2a4cfdSAnika Henke        $value = filesize_h(abs($sizechange));
2369cd2a4cfdSAnika Henke        if($sizechange > 0) {
2370cd2a4cfdSAnika Henke            $class .= ' positive';
2371cd2a4cfdSAnika Henke            $value = '+' . $value;
2372cd2a4cfdSAnika Henke        } elseif($sizechange < 0) {
2373cd2a4cfdSAnika Henke            $class .= ' negative';
2374cd2a4cfdSAnika Henke            $value = '-' . $value;
23750b78a6edSAnika Henke        } else {
23760b78a6edSAnika Henke            $value = '±' . $value;
2377cd2a4cfdSAnika Henke        }
2378cd2a4cfdSAnika Henke        $form->addElement(form_makeOpenTag('span', array('class' => $class)));
2379cd2a4cfdSAnika Henke        $form->addElement($value);
2380cd2a4cfdSAnika Henke        $form->addElement(form_makeCloseTag('span'));
2381cd2a4cfdSAnika Henke    }
2382cd2a4cfdSAnika Henke}
2383