xref: /dokuwiki/inc/html.php (revision cc3a3cde95a4a0b4a256109c08f12d3d6227a56a)
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;
130cba610bSSatoshi Saharause dokuwiki\Search\FulltextSearch;
144a90f94bSSatoshi Saharause dokuwiki\Search\MetadataIndex;
15efe70805SSatoshi Saharause dokuwiki\Utf8;
160c3a5702SAndreas Gohr
172d3b082eSMichael Großeif (!defined('SEC_EDIT_PATTERN')) {
1837c80e0eSLarsDW223    define('SEC_EDIT_PATTERN', '#<!-- EDIT({.*?}) -->#');
192d3b082eSMichael Große}
202d3b082eSMichael Große
216bbae538Sandi
22f3f0262cSandi/**
23f3f0262cSandi * Convenience function to quickly build a wikilink
2415fae107Sandi *
2515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
268d5e837eSMichael Hamann * @param string  $id      id of the target page
278d5e837eSMichael Hamann * @param string  $name    the name of the link, i.e. the text that is displayed
288d5e837eSMichael Hamann * @param string|array  $search  search string(s) that shall be highlighted in the target page
298d5e837eSMichael Hamann * @return string the HTML code of the link
30f3f0262cSandi */
31db959ae3SAndreas Gohrfunction html_wikilink($id,$name=null,$search=''){
32a8397511SGerrit Uitslag    /** @var Doku_Renderer_xhtml $xhtml_renderer */
33db959ae3SAndreas Gohr    static $xhtml_renderer = null;
34723d78dbSandi    if(is_null($xhtml_renderer)){
357aea91afSChris Smith        $xhtml_renderer = p_get_renderer('xhtml');
36f3f0262cSandi    }
37f3f0262cSandi
38fe9ec250SChris Smith    return $xhtml_renderer->internallink($id,$name,$search,true,'navigation');
39f3f0262cSandi}
40f3f0262cSandi
41f3f0262cSandi/**
42f3f0262cSandi * The loginform
4315fae107Sandi *
4415fae107Sandi * @author   Andreas Gohr <andi@splitbrain.org>
45d1d904bbSMichael Große *
46d1d904bbSMichael Große * @param bool $svg Whether to show svg icons in the register and resendpwd links or not
47f3f0262cSandi */
48d1d904bbSMichael Großefunction html_login($svg = false){
49f3f0262cSandi    global $lang;
50f3f0262cSandi    global $conf;
51f3f0262cSandi    global $ID;
52f0859d4bSTom N Harris    global $INPUT;
53f3f0262cSandi
54c112d578Sandi    print p_locale_xhtml('login');
55fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
563f552e56SAndreas Gohr    $form = new Doku_Form(array('id' => 'dw__login', 'action'=>wl($ID)));
57fdb8d77bSTom N Harris    $form->startFieldset($lang['btn_login']);
58fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
59fdb8d77bSTom N Harris    $form->addHidden('do', 'login');
6064159a61SAndreas Gohr    $form->addElement(form_makeTextField(
6164159a61SAndreas Gohr        'u',
6264159a61SAndreas Gohr        ((!$INPUT->bool('http_credentials')) ? $INPUT->str('u') : ''),
6364159a61SAndreas Gohr        $lang['user'],
6464159a61SAndreas Gohr        'focus__this',
6564159a61SAndreas Gohr        'block')
6664159a61SAndreas Gohr    );
67fdb8d77bSTom N Harris    $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block'));
6817f89d7eSMichael Klier    if($conf['rememberme']) {
69fdb8d77bSTom N Harris        $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple'));
7017f89d7eSMichael Klier    }
71fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['btn_login']));
72fdb8d77bSTom N Harris    $form->endFieldset();
735b62573aSAndreas Gohr
74de4d479aSAdrian Lang    if(actionOK('register')){
75d1d904bbSMichael Große        $registerLink = (new \dokuwiki\Menu\Item\Register())->asHtmlLink('', $svg);
76d1d904bbSMichael Große        $form->addElement('<p>'.$lang['reghere'].': '. $registerLink .'</p>');
77f3f0262cSandi    }
788b06d178Schris
79de4d479aSAdrian Lang    if (actionOK('resendpwd')) {
80d1d904bbSMichael Große        $resendPwLink = (new \dokuwiki\Menu\Item\Resendpwd())->asHtmlLink('', $svg);
81d1d904bbSMichael Große        $form->addElement('<p>'.$lang['pwdforget'].': '. $resendPwLink .'</p>');
828b06d178Schris    }
8376ec5467SMichael Klier
8476ec5467SMichael Klier    html_form('login', $form);
85fdb8d77bSTom N Harris    print '</div>'.NL;
86f3f0262cSandi}
87f3f0262cSandi
88d59dea9fSGerrit Uitslag
89d59dea9fSGerrit Uitslag/**
90d59dea9fSGerrit Uitslag * Denied page content
91d59dea9fSGerrit Uitslag *
92d59dea9fSGerrit Uitslag * @return string html
93d59dea9fSGerrit Uitslag */
94d59dea9fSGerrit Uitslagfunction html_denied() {
95d1e9181eSGerrit Uitslag    print p_locale_xhtml('denied');
96f019ab46SGerrit Uitslag
970db7a50dSThammi    if(empty($_SERVER['REMOTE_USER']) && actionOK('login')){
98f019ab46SGerrit Uitslag        html_login();
99f019ab46SGerrit Uitslag    }
100d59dea9fSGerrit Uitslag}
101d59dea9fSGerrit Uitslag
102f3f0262cSandi/**
10315fae107Sandi * inserts section edit buttons if wanted or removes the markers
10415fae107Sandi *
10515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
10642ea7f44SGerrit Uitslag *
10742ea7f44SGerrit Uitslag * @param string $text
10842ea7f44SGerrit Uitslag * @param bool   $show show section edit buttons?
10942ea7f44SGerrit Uitslag * @return string
11015fae107Sandi */
111f3f0262cSandifunction html_secedit($text,$show=true){
112f3f0262cSandi    global $INFO;
11335dae8b0SBen Coburn
114aac83cd4SPhy    if((isset($INFO) && !$INFO['writable']) || !$show || (isset($INFO) && $INFO['rev'])){
1152d3b082eSMichael Große        return preg_replace(SEC_EDIT_PATTERN,'',$text);
116f3f0262cSandi    }
11735dae8b0SBen Coburn
1182d3b082eSMichael Große    return preg_replace_callback(SEC_EDIT_PATTERN,
11940868f2fSAdrian Lang                'html_secedit_button', $text);
12040868f2fSAdrian Lang}
12140868f2fSAdrian Lang
12240868f2fSAdrian Lang/**
12340868f2fSAdrian Lang * prepares section edit button data for event triggering
12440868f2fSAdrian Lang * used as a callback in html_secedit
12540868f2fSAdrian Lang *
12640868f2fSAdrian Lang * @author Andreas Gohr <andi@splitbrain.org>
12742ea7f44SGerrit Uitslag *
12842ea7f44SGerrit Uitslag * @param array $matches matches with regexp
12942ea7f44SGerrit Uitslag * @return string
13042ea7f44SGerrit Uitslag * @triggers HTML_SECEDIT_BUTTON
13140868f2fSAdrian Lang */
13240868f2fSAdrian Langfunction html_secedit_button($matches){
133ada0d779SMichael Hamann    $json = htmlspecialchars_decode($matches[1], ENT_QUOTES);
134ada0d779SMichael Hamann    $data = json_decode($json, true);
135ec57f119SLarsDW223    if ($data == NULL) {
136ec57f119SLarsDW223        return;
13706917fceSMichael Große    }
138ec57f119SLarsDW223    $data ['target'] = strtolower($data['target']);
139ec57f119SLarsDW223    $data ['hid'] = strtolower($data['hid']);
14040868f2fSAdrian Lang
141cbb44eabSAndreas Gohr    return Event::createAndTrigger('HTML_SECEDIT_BUTTON', $data,
14240868f2fSAdrian Lang                         'html_secedit_get_button');
14340868f2fSAdrian Lang}
14440868f2fSAdrian Lang
14540868f2fSAdrian Lang/**
14640868f2fSAdrian Lang * prints a section editing button
14740868f2fSAdrian Lang * used as default action form HTML_SECEDIT_BUTTON
14840868f2fSAdrian Lang *
14940868f2fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de>
15042ea7f44SGerrit Uitslag *
15142ea7f44SGerrit Uitslag * @param array $data name, section id and target
15242ea7f44SGerrit Uitslag * @return string html
15340868f2fSAdrian Lang */
15440868f2fSAdrian Langfunction html_secedit_get_button($data) {
15540868f2fSAdrian Lang    global $ID;
15640868f2fSAdrian Lang    global $INFO;
15740868f2fSAdrian Lang
1586d9eab4dSMichael Hamann    if (!isset($data['name']) || $data['name'] === '') return '';
15940868f2fSAdrian Lang
16040868f2fSAdrian Lang    $name = $data['name'];
16140868f2fSAdrian Lang    unset($data['name']);
16240868f2fSAdrian Lang
163905fa971SAdrian Lang    $secid = $data['secid'];
164905fa971SAdrian Lang    unset($data['secid']);
165905fa971SAdrian Lang
16640868f2fSAdrian Lang    return "<div class='secedit editbutton_" . $data['target'] .
167defa93a1SAdrian Lang                       " editbutton_" . $secid . "'>" .
16840868f2fSAdrian Lang           html_btn('secedit', $ID, '',
16940868f2fSAdrian Lang                    array_merge(array('do'  => 'edit',
170b150cd2cSGina Haeussge                                      'rev' => $INFO['lastmod'],
171b150cd2cSGina Haeussge                                      'summary' => '['.$name.'] '), $data),
17240868f2fSAdrian Lang                    'post', $name) . '</div>';
173f3f0262cSandi}
174f3f0262cSandi
175f3f0262cSandi/**
176d6c9c552Smatthiasgrimm * Just the back to top button (in its own form)
1776b13307fSandi *
1786b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
17942ea7f44SGerrit Uitslag *
18042ea7f44SGerrit Uitslag * @return string html
1816b13307fSandi */
1826b13307fSandifunction html_topbtn(){
1836b13307fSandi    global $lang;
1846b13307fSandi
18564159a61SAndreas Gohr    $ret = '<a class="nolink" href="#dokuwiki__top">' .
18664159a61SAndreas Gohr        '<button class="button" onclick="window.scrollTo(0, 0)" title="' . $lang['btn_top'] . '">' .
18764159a61SAndreas Gohr        $lang['btn_top'] .
18864159a61SAndreas Gohr        '</button></a>';
189df7b6005Sandi
1906b13307fSandi    return $ret;
1916b13307fSandi}
1926b13307fSandi
1936b13307fSandi/**
194d67ca2c0Smatthiasgrimm * Displays a button (using its own form)
19535dae8b0SBen Coburn * If tooltip exists, the access key tooltip is replaced.
19615fae107Sandi *
19715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
19842ea7f44SGerrit Uitslag *
19942ea7f44SGerrit Uitslag * @param string         $name
20042ea7f44SGerrit Uitslag * @param string         $id
20142ea7f44SGerrit Uitslag * @param string         $akey   access key
202e3710957SGerrit Uitslag * @param string[] $params key-value pairs added as hidden inputs
20342ea7f44SGerrit Uitslag * @param string         $method
20442ea7f44SGerrit Uitslag * @param string         $tooltip
20542ea7f44SGerrit Uitslag * @param bool|string    $label  label text, false: lookup btn_$name in localization
206e824d633SMichael Große * @param string         $svg (optional) svg code, inserted into the button
20742ea7f44SGerrit Uitslag * @return string
208f3f0262cSandi */
209e824d633SMichael Großefunction html_btn($name, $id, $akey, $params, $method='get', $tooltip='', $label=false, $svg=null){
210f3f0262cSandi    global $conf;
211f3f0262cSandi    global $lang;
212f3f0262cSandi
213f5baf821SAnika Henke    if (!$label)
214f3f0262cSandi        $label = $lang['btn_'.$name];
215f3f0262cSandi
216f3f0262cSandi    $ret = '';
217f3f0262cSandi
21849c713a3Sandi    //filter id (without urlencoding)
21949c713a3Sandi    $id = idfilter($id,false);
220f3f0262cSandi
221f3f0262cSandi    //make nice URLs even for buttons
2226c7843b5Sandi    if($conf['userewrite'] == 2){
2236c7843b5Sandi        $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
2246c7843b5Sandi    }elseif($conf['userewrite']){
2256c7843b5Sandi        $script = DOKU_BASE.$id;
2266c7843b5Sandi    }else{
2278b00ebcfSandi        $script = DOKU_BASE.DOKU_SCRIPT;
228f3f0262cSandi        $params['id'] = $id;
229f3f0262cSandi    }
230f3f0262cSandi
231b278f2deSAndreas Gohr    $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
232f3f0262cSandi
23306a4bf8fSAndreas Gohr    if(is_array($params)){
2349e491c01SAndreas Gohr        foreach($params as $key => $val) {
235f3f0262cSandi            $ret .= '<input type="hidden" name="'.$key.'" ';
23665cc1598SPhy            $ret .= 'value="'.hsc($val).'" />';
237f3f0262cSandi        }
23806a4bf8fSAndreas Gohr    }
239f3f0262cSandi
24035dae8b0SBen Coburn    if ($tooltip!='') {
24165cc1598SPhy        $tip = hsc($tooltip);
24211ea018fSAndreas Gohr    }else{
24365cc1598SPhy        $tip = hsc($label);
24411ea018fSAndreas Gohr    }
24511ea018fSAndreas Gohr
246ae614416SAnika Henke    $ret .= '<button type="submit" ';
24711ea018fSAndreas Gohr    if($akey){
24807493d05SAnika Henke        $tip .= ' ['.strtoupper($akey).']';
24987cb01b7SAnika Henke        $ret .= 'accesskey="'.$akey.'" ';
25035dae8b0SBen Coburn    }
2519c65e2a9SAndreas Gohr    $ret .= 'title="'.$tip.'">';
252e824d633SMichael Große    if ($svg) {
253679dba01SMichael Große        $ret .= '<span>' . hsc($label) . '</span>';
254e824d633SMichael Große        $ret .= inlineSVG($svg);
255679dba01SMichael Große    } else {
256ae614416SAnika Henke        $ret .= hsc($label);
257679dba01SMichael Große    }
258ae614416SAnika Henke    $ret .= '</button>';
2594beabca9SAnika Henke    $ret .= '</div></form>';
260f3f0262cSandi
261f3f0262cSandi    return $ret;
262f3f0262cSandi}
2630747f5d7Sghi/**
2640747f5d7Sghi * show a revision warning
2650747f5d7Sghi *
2660747f5d7Sghi * @author Szymon Olewniczak <dokuwiki@imz.re>
2670747f5d7Sghi */
268c8556525Sghifunction html_showrev() {
269c8556525Sghi    print p_locale_xhtml('showrev');
2700747f5d7Sghi}
271f3f0262cSandi
272f3f0262cSandi/**
27342ea7f44SGerrit Uitslag * Show a wiki page
27415fae107Sandi *
27515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
27642ea7f44SGerrit Uitslag *
27742ea7f44SGerrit Uitslag * @param null|string $txt wiki text or null for showing $ID
27815fae107Sandi */
27911c78c94SAndreas Gohrfunction html_show($txt=null){
280f3f0262cSandi    global $ID;
281f3f0262cSandi    global $REV;
282f3f0262cSandi    global $HIGH;
283b8595a66SAndreas Gohr    global $INFO;
2845c2eed9aSlisps    global $DATE_AT;
285f3f0262cSandi    //disable section editing for old revisions or in preview
2865400331dSandi    if($txt || $REV){
2876bbae538Sandi        $secedit = false;
2886bbae538Sandi    }else{
2896bbae538Sandi        $secedit = true;
290f3f0262cSandi    }
291f3f0262cSandi
29211c78c94SAndreas Gohr    if (!is_null($txt)){
293f3f0262cSandi        //PreviewHeader
294e0959e88SDeathCamel57        echo '<br id="scroll__here" />';
295b8595a66SAndreas Gohr        echo p_locale_xhtml('preview');
296fc8dc822SAnika Henke        echo '<div class="preview"><div class="pad">';
297b8595a66SAndreas Gohr        $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
298b8595a66SAndreas Gohr        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
299b8595a66SAndreas Gohr        echo $html;
300b8595a66SAndreas Gohr        echo '<div class="clearer"></div>';
301fc8dc822SAnika Henke        echo '</div></div>';
3026bbae538Sandi
303f3f0262cSandi    }else{
3040747f5d7Sghi        if ($REV||$DATE_AT){
305c8556525Sghi            $data = array('rev' => &$REV, 'date_at' => &$DATE_AT);
306cbb44eabSAndreas Gohr            Event::createAndTrigger('HTML_SHOWREV_OUTPUT', $data, 'html_showrev');
3070747f5d7Sghi        }
3085c2eed9aSlisps        $html = p_wiki_xhtml($ID,$REV,true,$DATE_AT);
3096bbae538Sandi        $html = html_secedit($html,$secedit);
310b8595a66SAndreas Gohr        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
311b8595a66SAndreas Gohr        $html = html_hilight($html,$HIGH);
312b8595a66SAndreas Gohr        echo $html;
313f3f0262cSandi    }
314f3f0262cSandi}
315f3f0262cSandi
316f3f0262cSandi/**
317ee4c4a1bSAndreas Gohr * ask the user about how to handle an exisiting draft
318ee4c4a1bSAndreas Gohr *
319ee4c4a1bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
320ee4c4a1bSAndreas Gohr */
321ee4c4a1bSAndreas Gohrfunction html_draft(){
322ee4c4a1bSAndreas Gohr    global $INFO;
323ee4c4a1bSAndreas Gohr    global $ID;
324ee4c4a1bSAndreas Gohr    global $lang;
3250aabe6f8SMichael Große    $draft = new \dokuwiki\Draft($ID, $INFO['client']);
3260aabe6f8SMichael Große    $text  = $draft->getDraftText();
327ee4c4a1bSAndreas Gohr
328fdb8d77bSTom N Harris    print p_locale_xhtml('draft');
32937816f76SLukas Rademacher    html_diff($text, false);
330e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
331fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
332520438b3SMichael Große    $form->addHidden('date', $draft->getDraftDate());
3331362c8afSAndreas Gohr    $form->addHidden('wikitext', $text);
334fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
335520438b3SMichael Große    $form->addElement($draft->getDraftMessage());
336fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
337fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
338fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
339fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3')));
340fdb8d77bSTom N Harris    html_form('draft', $form);
341ee4c4a1bSAndreas Gohr}
342ee4c4a1bSAndreas Gohr
343ee4c4a1bSAndreas Gohr/**
344f3f0262cSandi * Highlights searchqueries in HTML code
34515fae107Sandi *
34615fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
3477209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
34842ea7f44SGerrit Uitslag *
34942ea7f44SGerrit Uitslag * @param string $html
35042ea7f44SGerrit Uitslag * @param array|string $phrases
35142ea7f44SGerrit Uitslag * @return string html
352f3f0262cSandi */
353546d3a99SAndreas Gohrfunction html_hilight($html, $phrases) {
354*cc3a3cdeSSatoshi Sahara    $FulltextSearch = new FulltextSearch();
3558a803caeSAndreas Gohr    $phrases = (array) $phrases;
3568a803caeSAndreas Gohr    $phrases = array_map('preg_quote_cb', $phrases);
3579329b002SSatoshi Sahara    $phrases = array_map([$FulltextSearch, 'snippetRePreprocess'], $phrases);
3588a803caeSAndreas Gohr    $phrases = array_filter($phrases);
3590cba610bSSatoshi Sahara    $regex = implode('|', $phrases);
36060c15d7dSAndreas Gohr
36160c15d7dSAndreas Gohr    if ($regex === '') return $html;
362efe70805SSatoshi Sahara    if (!Utf8\Clean::isUtf8($regex)) return $html;
36324a6c235SAndreas Gohr    $html = @preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback', $html);
364f3f0262cSandi    return $html;
365f3f0262cSandi}
366f3f0262cSandi
367f3f0262cSandi/**
3687209be23SAndreas Gohr * Callback used by html_hilight()
3697209be23SAndreas Gohr *
3707209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
37142ea7f44SGerrit Uitslag *
37242ea7f44SGerrit Uitslag * @param array $m matches
37342ea7f44SGerrit Uitslag * @return string html
3747209be23SAndreas Gohr */
3757209be23SAndreas Gohrfunction html_hilight_callback($m) {
3767209be23SAndreas Gohr    $hlight = unslash($m[0]);
3777209be23SAndreas Gohr    if ( !isset($m[2])) {
378688774a0SAnika Henke        $hlight = '<span class="search_hit">'.$hlight.'</span>';
3797209be23SAndreas Gohr    }
3807209be23SAndreas Gohr    return $hlight;
3817209be23SAndreas Gohr}
3827209be23SAndreas Gohr
3837209be23SAndreas Gohr/**
38415fae107Sandi * Display error on locked pages
38515fae107Sandi *
38615fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
38715fae107Sandi */
388ee20e7d1Sandifunction html_locked(){
389f3f0262cSandi    global $ID;
390f3f0262cSandi    global $conf;
391f3f0262cSandi    global $lang;
39288f522e9Sandi    global $INFO;
393f3f0262cSandi
394c9b4bd1eSBen Coburn    $locktime = filemtime(wikiLockFN($ID));
395f2263577SAndreas Gohr    $expire = dformat($locktime + $conf['locktime']);
396f3f0262cSandi    $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
397f3f0262cSandi
398c112d578Sandi    print p_locale_xhtml('locked');
399f3f0262cSandi    print '<ul>';
400fde860beSGerrit Uitslag    print '<li><div class="li"><strong>'.$lang['lockedby'].'</strong> '.editorinfo($INFO['locked']).'</div></li>';
401fde860beSGerrit Uitslag    print '<li><div class="li"><strong>'.$lang['lockexpire'].'</strong> '.$expire.' ('.$min.' min)</div></li>';
402f3f0262cSandi    print '</ul>';
403f3f0262cSandi}
404f3f0262cSandi
40515fae107Sandi/**
40615fae107Sandi * list old revisions
40715fae107Sandi *
40815fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
40971726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
4108e69fd30SKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
411e0c26282SGerrit Uitslag *
412e0c26282SGerrit Uitslag * @param int $first skip the first n changelog lines
413e0c26282SGerrit Uitslag * @param bool|string $media_id id of media, or false for current page
41415fae107Sandi */
4158e69fd30SKate Arzamastsevafunction html_revisions($first=0, $media_id = false){
416f3f0262cSandi    global $ID;
417f3f0262cSandi    global $INFO;
418f3f0262cSandi    global $conf;
419f3f0262cSandi    global $lang;
4208e69fd30SKate Arzamastseva    $id = $ID;
421047bad06SGerrit Uitslag    if ($media_id) {
422047bad06SGerrit Uitslag        $id = $media_id;
423047bad06SGerrit Uitslag        $changelog = new MediaChangeLog($id);
424047bad06SGerrit Uitslag    } else {
425047bad06SGerrit Uitslag        $changelog = new PageChangeLog($id);
426047bad06SGerrit Uitslag    }
427f523c971SGerrit Uitslag
42861e0b2f8SChristopher Smith    /* we need to get one additional log entry to be able to
42971726d78SBen Coburn     * decide if this is the last page or is there another one.
43071726d78SBen Coburn     * see html_recent()
43171726d78SBen Coburn     */
432047bad06SGerrit Uitslag
433047bad06SGerrit Uitslag    $revisions = $changelog->getRevisions($first, $conf['recent']+1);
4348e69fd30SKate Arzamastseva
43571726d78SBen Coburn    if(count($revisions)==0 && $first!=0){
43671726d78SBen Coburn        $first=0;
437047bad06SGerrit Uitslag        $revisions = $changelog->getRevisions($first, $conf['recent']+1);
43871726d78SBen Coburn    }
43971726d78SBen Coburn    $hasNext = false;
44071726d78SBen Coburn    if (count($revisions)>$conf['recent']) {
44171726d78SBen Coburn        $hasNext = true;
44271726d78SBen Coburn        array_pop($revisions); // remove extra log entry
44371726d78SBen Coburn    }
44471726d78SBen Coburn
4458e69fd30SKate Arzamastseva    if (!$media_id) print p_locale_xhtml('revisions');
44637a1dc12Smichael
4470607bfeeSAnika Henke    $params = array('id' => 'page__revisions', 'class' => 'changes');
448551be3f9SGerrit Uitslag    if($media_id) {
449551be3f9SGerrit Uitslag        $params['action'] = media_managerURL(array('image' => $media_id), '&');
450551be3f9SGerrit Uitslag    }
451551be3f9SGerrit Uitslag
452551be3f9SGerrit Uitslag    if(!$media_id) {
453551be3f9SGerrit Uitslag        $exists = $INFO['exists'];
454551be3f9SGerrit Uitslag        $display_name = useHeading('navigation') ? hsc(p_get_first_heading($id)) : $id;
455551be3f9SGerrit Uitslag        if(!$display_name) {
456551be3f9SGerrit Uitslag            $display_name = $id;
457551be3f9SGerrit Uitslag        }
458551be3f9SGerrit Uitslag    } else {
459551be3f9SGerrit Uitslag        $exists = file_exists(mediaFN($id));
460551be3f9SGerrit Uitslag        $display_name = $id;
461551be3f9SGerrit Uitslag    }
4627d7ab775SKate Arzamastseva
4637d7ab775SKate Arzamastseva    $form = new Doku_Form($params);
46437a1dc12Smichael    $form->addElement(form_makeOpenTag('ul'));
4658e69fd30SKate Arzamastseva
4668e69fd30SKate Arzamastseva    if($exists && $first == 0) {
467551be3f9SGerrit Uitslag        $minor = false;
468551be3f9SGerrit Uitslag        if($media_id) {
469551be3f9SGerrit Uitslag            $date = dformat(@filemtime(mediaFN($id)));
470551be3f9SGerrit Uitslag            $href = media_managerURL(array('image' => $id, 'tab_details' => 'view'), '&');
471551be3f9SGerrit Uitslag
472551be3f9SGerrit Uitslag            $changelog->setChunkSize(1024);
473551be3f9SGerrit Uitslag            $revinfo = $changelog->getRevisionInfo(@filemtime(fullpath(mediaFN($id))));
474551be3f9SGerrit Uitslag
475551be3f9SGerrit Uitslag            $summary = $revinfo['sum'];
476551be3f9SGerrit Uitslag            if($revinfo['user']) {
477551be3f9SGerrit Uitslag                $editor = $revinfo['user'];
478551be3f9SGerrit Uitslag            } else {
479551be3f9SGerrit Uitslag                $editor = $revinfo['ip'];
480551be3f9SGerrit Uitslag            }
481551be3f9SGerrit Uitslag            $sizechange = $revinfo['sizechange'];
482551be3f9SGerrit Uitslag        } else {
483551be3f9SGerrit Uitslag            $date = dformat($INFO['lastmod']);
484551be3f9SGerrit Uitslag            if(isset($INFO['meta']) && isset($INFO['meta']['last_change'])) {
485551be3f9SGerrit Uitslag                if($INFO['meta']['last_change']['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) {
486551be3f9SGerrit Uitslag                    $minor = true;
487551be3f9SGerrit Uitslag                }
488551be3f9SGerrit Uitslag                if(isset($INFO['meta']['last_change']['sizechange'])) {
489551be3f9SGerrit Uitslag                    $sizechange = $INFO['meta']['last_change']['sizechange'];
490551be3f9SGerrit Uitslag                } else {
491551be3f9SGerrit Uitslag                    $sizechange = null;
492551be3f9SGerrit Uitslag                }
493551be3f9SGerrit Uitslag            }
494fe101f30SMetin Güler            $pagelog = new PageChangeLog($ID);
49570635395SAndreas Gohr            $latestrev = $pagelog->getRevisions(-1, 1);
49670635395SAndreas Gohr            $latestrev = array_pop($latestrev);
497fe101f30SMetin Güler            $href = wl($id,"rev=$latestrev",false,'&');
498551be3f9SGerrit Uitslag            $summary = $INFO['sum'];
499551be3f9SGerrit Uitslag            $editor = $INFO['editor'];
500551be3f9SGerrit Uitslag        }
501551be3f9SGerrit Uitslag
502551be3f9SGerrit Uitslag        $form->addElement(form_makeOpenTag('li', array('class' => ($minor ? 'minor' : ''))));
50337a1dc12Smichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
50437a1dc12Smichael        $form->addElement(form_makeTag('input', array(
50537a1dc12Smichael                        'type' => 'checkbox',
50637a1dc12Smichael                        'name' => 'rev2[]',
50737a1dc12Smichael                        'value' => 'current')));
508f9b2fe70Sandi
50937a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
51037a1dc12Smichael        $form->addElement($date);
51137a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
512f9b2fe70Sandi
513c2e73886SAnika Henke        $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
514cffcc403Sandi
51537a1dc12Smichael        $form->addElement(form_makeOpenTag('a', array(
51637a1dc12Smichael                        'class' => 'wikilink1',
517dad6764eSKate Arzamastseva                        'href'  => $href)));
51890658f38SMichael Hamann        $form->addElement($display_name);
51937a1dc12Smichael        $form->addElement(form_makeCloseTag('a'));
520652610a2Sandi
52167c8cda1SKate Arzamastseva        if ($media_id) $form->addElement(form_makeOpenTag('div'));
52267c8cda1SKate Arzamastseva
523551be3f9SGerrit Uitslag        if($summary) {
52437a1dc12Smichael            $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
525551be3f9SGerrit Uitslag            if(!$media_id) $form->addElement(' – ');
52665cc1598SPhy            $form->addElement('<bdi>' . hsc($summary) . '</bdi>');
52737a1dc12Smichael            $form->addElement(form_makeCloseTag('span'));
528035e07f1SKate Arzamastseva        }
529652610a2Sandi
53037a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
531551be3f9SGerrit Uitslag        $form->addElement((empty($editor))?('('.$lang['external_edit'].')'):'<bdi>'.editorinfo($editor).'</bdi>');
53237a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
53337a1dc12Smichael
534cd2a4cfdSAnika Henke        html_sizechange($sizechange, $form);
535551be3f9SGerrit Uitslag
53637a1dc12Smichael        $form->addElement('('.$lang['current'].')');
53767c8cda1SKate Arzamastseva
53867c8cda1SKate Arzamastseva        if ($media_id) $form->addElement(form_makeCloseTag('div'));
53967c8cda1SKate Arzamastseva
54037a1dc12Smichael        $form->addElement(form_makeCloseTag('div'));
54137a1dc12Smichael        $form->addElement(form_makeCloseTag('li'));
542f3f0262cSandi    }
543f3f0262cSandi
544f3f0262cSandi    foreach($revisions as $rev) {
545f2263577SAndreas Gohr        $date = dformat($rev);
546047bad06SGerrit Uitslag        $info = $changelog->getRevisionInfo($rev);
547047bad06SGerrit Uitslag        if($media_id) {
54879e79377SAndreas Gohr            $exists = file_exists(mediaFN($id, $rev));
549047bad06SGerrit Uitslag        } else {
550047bad06SGerrit Uitslag            $exists = page_exists($id, $rev);
551dad6764eSKate Arzamastseva        }
552652610a2Sandi
553551be3f9SGerrit Uitslag        $class = '';
554551be3f9SGerrit Uitslag        if($info['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) {
555551be3f9SGerrit Uitslag            $class = 'minor';
556551be3f9SGerrit Uitslag        }
557551be3f9SGerrit Uitslag        $form->addElement(form_makeOpenTag('li', array('class' => $class)));
55837a1dc12Smichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
55977707b04SAndreas Gohr        if($exists){
56037a1dc12Smichael            $form->addElement(form_makeTag('input', array(
56137a1dc12Smichael                            'type' => 'checkbox',
56237a1dc12Smichael                            'name' => 'rev2[]',
56337a1dc12Smichael                            'value' => $rev)));
56477707b04SAndreas Gohr        }else{
565c2e73886SAnika Henke            $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
56641396b71SAndreas Gohr        }
567f9b2fe70Sandi
56837a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
56937a1dc12Smichael        $form->addElement($date);
57037a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
57137a1dc12Smichael
57237a1dc12Smichael        if($exists){
573551be3f9SGerrit Uitslag            if (!$media_id) {
574551be3f9SGerrit Uitslag                $href = wl($id,"rev=$rev,do=diff", false, '&');
575551be3f9SGerrit Uitslag            } else {
576551be3f9SGerrit Uitslag                $href = media_managerURL(array('image' => $id, 'rev' => $rev, 'mediado' => 'diff'), '&');
577551be3f9SGerrit Uitslag            }
578551be3f9SGerrit Uitslag            $form->addElement(form_makeOpenTag('a', array(
579551be3f9SGerrit Uitslag                            'class' => 'diff_link',
580551be3f9SGerrit Uitslag                            'href' => $href)));
58137a1dc12Smichael            $form->addElement(form_makeTag('img', array(
58237a1dc12Smichael                            'src'    => DOKU_BASE.'lib/images/diff.png',
58337a1dc12Smichael                            'width'  => 15,
58437a1dc12Smichael                            'height' => 11,
58537a1dc12Smichael                            'title'  => $lang['diff'],
58637a1dc12Smichael                            'alt'    => $lang['diff'])));
58737a1dc12Smichael            $form->addElement(form_makeCloseTag('a'));
588551be3f9SGerrit Uitslag
589551be3f9SGerrit Uitslag            if (!$media_id) {
590551be3f9SGerrit Uitslag                $href = wl($id,"rev=$rev",false,'&');
591551be3f9SGerrit Uitslag            } else {
592551be3f9SGerrit Uitslag                $href = media_managerURL(array('image' => $id, 'tab_details' => 'view', 'rev' => $rev), '&');
593551be3f9SGerrit Uitslag            }
594551be3f9SGerrit Uitslag            $form->addElement(form_makeOpenTag('a', array(
595551be3f9SGerrit Uitslag                            'class' => 'wikilink1',
596551be3f9SGerrit Uitslag                            'href' => $href)));
59790658f38SMichael Hamann            $form->addElement($display_name);
59837a1dc12Smichael            $form->addElement(form_makeCloseTag('a'));
59937a1dc12Smichael        }else{
600c2e73886SAnika Henke            $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
60190658f38SMichael Hamann            $form->addElement($display_name);
60237a1dc12Smichael        }
60337a1dc12Smichael
60467c8cda1SKate Arzamastseva        if ($media_id) $form->addElement(form_makeOpenTag('div'));
60567c8cda1SKate Arzamastseva
606035e07f1SKate Arzamastseva        if ($info['sum']) {
60737a1dc12Smichael            $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
608e260f93bSAnika Henke            if(!$media_id) $form->addElement(' – ');
60965cc1598SPhy            $form->addElement('<bdi>'.hsc($info['sum']).'</bdi>');
61037a1dc12Smichael            $form->addElement(form_makeCloseTag('span'));
611035e07f1SKate Arzamastseva        }
61237a1dc12Smichael
61337a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
61488f522e9Sandi        if($info['user']){
615d317fb5dSAnika Henke            $form->addElement('<bdi>'.editorinfo($info['user']).'</bdi>');
616433efb25SAndreas Gohr            if(auth_ismanager()){
617d317fb5dSAnika Henke                $form->addElement(' <bdo dir="ltr">('.$info['ip'].')</bdo>');
618433efb25SAndreas Gohr            }
61988f522e9Sandi        }else{
620d317fb5dSAnika Henke            $form->addElement('<bdo dir="ltr">'.$info['ip'].'</bdo>');
62188f522e9Sandi        }
62237a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
623652610a2Sandi
624cd2a4cfdSAnika Henke        html_sizechange($info['sizechange'], $form);
625551be3f9SGerrit Uitslag
62667c8cda1SKate Arzamastseva        if ($media_id) $form->addElement(form_makeCloseTag('div'));
62767c8cda1SKate Arzamastseva
62837a1dc12Smichael        $form->addElement(form_makeCloseTag('div'));
62937a1dc12Smichael        $form->addElement(form_makeCloseTag('li'));
630f3f0262cSandi    }
63137a1dc12Smichael    $form->addElement(form_makeCloseTag('ul'));
6322e55802cSKate Arzamastseva    if (!$media_id) {
6332e55802cSKate Arzamastseva        $form->addElement(form_makeButton('submit', 'diff', $lang['diff2']));
6342e55802cSKate Arzamastseva    } else {
6352e55802cSKate Arzamastseva        $form->addHidden('mediado', 'diff');
6362e55802cSKate Arzamastseva        $form->addElement(form_makeButton('submit', '', $lang['diff2']));
6372e55802cSKate Arzamastseva    }
63837a1dc12Smichael    html_form('revisions', $form);
63971726d78SBen Coburn
64071726d78SBen Coburn    print '<div class="pagenav">';
64171726d78SBen Coburn    $last = $first + $conf['recent'];
64271726d78SBen Coburn    if ($first > 0) {
64371726d78SBen Coburn        $first -= $conf['recent'];
64471726d78SBen Coburn        if ($first < 0) $first = 0;
64571726d78SBen Coburn        print '<div class="pagenav-prev">';
6467e6b49bbSKate Arzamastseva        if ($media_id) {
647035e07f1SKate Arzamastseva            print html_btn('newer',$media_id,"p",media_managerURL(array('first' => $first), '&amp;', false, true));
6487e6b49bbSKate Arzamastseva        } else {
6498e69fd30SKate Arzamastseva            print html_btn('newer',$id,"p",array('do' => 'revisions', 'first' => $first));
6507e6b49bbSKate Arzamastseva        }
65171726d78SBen Coburn        print '</div>';
65271726d78SBen Coburn    }
65371726d78SBen Coburn    if ($hasNext) {
65471726d78SBen Coburn        print '<div class="pagenav-next">';
6557e6b49bbSKate Arzamastseva        if ($media_id) {
656035e07f1SKate Arzamastseva            print html_btn('older',$media_id,"n",media_managerURL(array('first' => $last), '&amp;', false, true));
6577e6b49bbSKate Arzamastseva        } else {
6588e69fd30SKate Arzamastseva            print html_btn('older',$id,"n",array('do' => 'revisions', 'first' => $last));
6597e6b49bbSKate Arzamastseva        }
66071726d78SBen Coburn        print '</div>';
66171726d78SBen Coburn    }
66271726d78SBen Coburn    print '</div>';
66371726d78SBen Coburn
664f3f0262cSandi}
665f3f0262cSandi
66615fae107Sandi/**
66715fae107Sandi * display recent changes
66815fae107Sandi *
66915fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
6705749f1ceSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
67171726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
6728d40b4b6SKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
67342ea7f44SGerrit Uitslag *
67442ea7f44SGerrit Uitslag * @param int $first
67542ea7f44SGerrit Uitslag * @param string $show_changes
67615fae107Sandi */
6770739a638SKate Arzamastsevafunction html_recent($first = 0, $show_changes = 'both') {
678f3f0262cSandi    global $conf;
679cffcc403Sandi    global $lang;
680dbb00abcSEsther Brunner    global $ID;
6815749f1ceSmatthiasgrimm    /* we need to get one additionally log entry to be able to
6825749f1ceSmatthiasgrimm     * decide if this is the last page or is there another one.
6835749f1ceSmatthiasgrimm     * This is the cheapest solution to get this information.
6845749f1ceSmatthiasgrimm     */
685e5d185e1SKate Arzamastseva    $flags = 0;
686e5d185e1SKate Arzamastseva    if($show_changes == 'mediafiles' && $conf['mediarevisions']) {
687b5941dfaSKate Arzamastseva        $flags = RECENTS_MEDIA_CHANGES;
688b5941dfaSKate Arzamastseva    } elseif($show_changes == 'pages') {
689b5941dfaSKate Arzamastseva        $flags = 0;
690e5d185e1SKate Arzamastseva    } elseif($conf['mediarevisions']) {
691b5941dfaSKate Arzamastseva        $show_changes = 'both';
692b5941dfaSKate Arzamastseva        $flags = RECENTS_MEDIA_PAGES_MIXED;
693b5941dfaSKate Arzamastseva    }
6948d40b4b6SKate Arzamastseva
6958d40b4b6SKate Arzamastseva    $recents = getRecents($first, $conf['recent'] + 1, getNS($ID), $flags);
6965749f1ceSmatthiasgrimm    if(count($recents) == 0 && $first != 0) {
6975749f1ceSmatthiasgrimm        $first = 0;
6988d40b4b6SKate Arzamastseva        $recents = getRecents($first, $conf['recent'] + 1, getNS($ID), $flags);
6995749f1ceSmatthiasgrimm    }
70071726d78SBen Coburn    $hasNext = false;
70171726d78SBen Coburn    if(count($recents) > $conf['recent']) {
70271726d78SBen Coburn        $hasNext = true;
70371726d78SBen Coburn        array_pop($recents); // remove extra log entry
70471726d78SBen Coburn    }
705f3f0262cSandi
706c112d578Sandi    print p_locale_xhtml('recent');
707e83cef14SGina Haeussge
708a023425bSGerrit Uitslag    if(getNS($ID) != '') {
70964159a61SAndreas Gohr        print '<div class="level1"><p>' .
71064159a61SAndreas Gohr            sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) .
71164159a61SAndreas Gohr            '</p></div>';
712a023425bSGerrit Uitslag    }
713e83cef14SGina Haeussge
714d1264ecfSAndreas Gohr    $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET', 'class' => 'changes', 'action'=>wl($ID)));
715abdcc39fSmichael    $form->addHidden('sectok', null);
716abdcc39fSmichael    $form->addHidden('do', 'recent');
717abdcc39fSmichael    $form->addHidden('id', $ID);
7188d40b4b6SKate Arzamastseva
719e5d185e1SKate Arzamastseva    if($conf['mediarevisions']) {
7200607bfeeSAnika Henke        $form->addElement('<div class="changeType">');
721b5941dfaSKate Arzamastseva        $form->addElement(form_makeListboxField(
722b5941dfaSKate Arzamastseva                    'show_changes',
723b5941dfaSKate Arzamastseva                    array(
724b5941dfaSKate Arzamastseva                        'pages'      => $lang['pages_changes'],
725b5941dfaSKate Arzamastseva                        'mediafiles' => $lang['media_changes'],
72653cba3d0SGerrit Uitslag                        'both'       => $lang['both_changes']
72753cba3d0SGerrit Uitslag                    ),
728b5941dfaSKate Arzamastseva                    $show_changes,
729b5941dfaSKate Arzamastseva                    $lang['changes_type'],
730b5941dfaSKate Arzamastseva                    '', '',
731b5941dfaSKate Arzamastseva                    array('class' => 'quickselect')));
732b5941dfaSKate Arzamastseva
733b5941dfaSKate Arzamastseva        $form->addElement(form_makeButton('submit', 'recent', $lang['btn_apply']));
7340607bfeeSAnika Henke        $form->addElement('</div>');
735e5d185e1SKate Arzamastseva    }
7368d40b4b6SKate Arzamastseva
737abdcc39fSmichael    $form->addElement(form_makeOpenTag('ul'));
738a39955b0Smatthiasgrimm
739d437bcc4SAndreas Gohr    foreach($recents as $recent) {
740f2263577SAndreas Gohr        $date = dformat($recent['date']);
741cffcc403Sandi
742a023425bSGerrit Uitslag        $class = '';
743a023425bSGerrit Uitslag        if($recent['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) {
744a023425bSGerrit Uitslag            $class = 'minor';
745a023425bSGerrit Uitslag        }
746a023425bSGerrit Uitslag        $form->addElement(form_makeOpenTag('li', array('class' => $class)));
747abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
748f9b2fe70Sandi
7490e80bb5eSChristopher Smith        if(!empty($recent['media'])) {
750421ec38eSKate Arzamastseva            $form->addElement(media_printicon($recent['id']));
751421ec38eSKate Arzamastseva        } else {
752421ec38eSKate Arzamastseva            $icon = DOKU_BASE . 'lib/images/fileicons/file.png';
7530686da46SMichael Hamann            $form->addElement('<img src="' . $icon . '" alt="' . $recent['id'] . '" class="icon" />');
754421ec38eSKate Arzamastseva        }
755421ec38eSKate Arzamastseva
756abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
757abdcc39fSmichael        $form->addElement($date);
758abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
759cffcc403Sandi
7606d9eab4dSMichael Hamann        $diff = false;
7616d9eab4dSMichael Hamann        $href = '';
7626d9eab4dSMichael Hamann
7630e80bb5eSChristopher Smith        if(!empty($recent['media'])) {
76468921571SGerrit Uitslag            $changelog = new MediaChangeLog($recent['id']);
76568921571SGerrit Uitslag            $revs = $changelog->getRevisions(0, 1);
76668921571SGerrit Uitslag            $diff = (count($revs) && file_exists(mediaFN($recent['id'])));
76792cac9a9SKate Arzamastseva            if($diff) {
76868921571SGerrit Uitslag                $href = media_managerURL(array(
76968921571SGerrit Uitslag                                            'tab_details' => 'history',
77068921571SGerrit Uitslag                                            'mediado' => 'diff',
77168921571SGerrit Uitslag                                            'image' => $recent['id'],
77268921571SGerrit Uitslag                                            'ns' => getNS($recent['id'])
77368921571SGerrit Uitslag                                        ), '&');
77492cac9a9SKate Arzamastseva            }
775b5941dfaSKate Arzamastseva        } else {
776b5941dfaSKate Arzamastseva            $href = wl($recent['id'], "do=diff", false, '&');
777b5941dfaSKate Arzamastseva        }
77892cac9a9SKate Arzamastseva
7790e80bb5eSChristopher Smith        if(!empty($recent['media']) && !$diff) {
78092cac9a9SKate Arzamastseva            $form->addElement('<img src="' . DOKU_BASE . 'lib/images/blank.gif" width="15" height="11" alt="" />');
78192cac9a9SKate Arzamastseva        } else {
782b5941dfaSKate Arzamastseva            $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => $href)));
783abdcc39fSmichael            $form->addElement(form_makeTag('img', array(
784abdcc39fSmichael                            'src'    => DOKU_BASE . 'lib/images/diff.png',
785abdcc39fSmichael                            'width'  => 15,
786abdcc39fSmichael                            'height' => 11,
787abdcc39fSmichael                            'title'  => $lang['diff'],
788abdcc39fSmichael                            'alt'    => $lang['diff']
789abdcc39fSmichael                        )));
790abdcc39fSmichael            $form->addElement(form_makeCloseTag('a'));
79192cac9a9SKate Arzamastseva        }
792cffcc403Sandi
7930e80bb5eSChristopher Smith        if(!empty($recent['media'])) {
79464159a61SAndreas Gohr            $href = media_managerURL(
79564159a61SAndreas Gohr                array(
79664159a61SAndreas Gohr                    'tab_details' => 'history',
79764159a61SAndreas Gohr                    'image' => $recent['id'],
79864159a61SAndreas Gohr                    'ns' => getNS($recent['id'])
79964159a61SAndreas Gohr                ),
80064159a61SAndreas Gohr                '&'
80164159a61SAndreas Gohr            );
802b5941dfaSKate Arzamastseva        } else {
803b5941dfaSKate Arzamastseva            $href = wl($recent['id'], "do=revisions", false, '&');
804b5941dfaSKate Arzamastseva        }
805a023425bSGerrit Uitslag        $form->addElement(form_makeOpenTag('a', array(
806a023425bSGerrit Uitslag                        'class' => 'revisions_link',
807a023425bSGerrit Uitslag                        'href'  => $href)));
808abdcc39fSmichael        $form->addElement(form_makeTag('img', array(
809abdcc39fSmichael                        'src'    => DOKU_BASE . 'lib/images/history.png',
810abdcc39fSmichael                        'width'  => 12,
811abdcc39fSmichael                        'height' => 14,
812abdcc39fSmichael                        'title'  => $lang['btn_revs'],
813abdcc39fSmichael                        'alt'    => $lang['btn_revs']
814abdcc39fSmichael                    )));
815abdcc39fSmichael        $form->addElement(form_makeCloseTag('a'));
816b6912aeaSAndreas Gohr
8170e80bb5eSChristopher Smith        if(!empty($recent['media'])) {
81864159a61SAndreas Gohr            $href = media_managerURL(
81964159a61SAndreas Gohr                array(
82064159a61SAndreas Gohr                    'tab_details' => 'view',
82164159a61SAndreas Gohr                    'image' => $recent['id'],
82264159a61SAndreas Gohr                    'ns' => getNS($recent['id'])
82364159a61SAndreas Gohr                ),
82464159a61SAndreas Gohr                '&'
82564159a61SAndreas Gohr            );
826a023425bSGerrit Uitslag            $class = file_exists(mediaFN($recent['id'])) ? 'wikilink1' : 'wikilink2';
827a023425bSGerrit Uitslag            $form->addElement(form_makeOpenTag('a', array(
828a023425bSGerrit Uitslag                        'class' => $class,
829a023425bSGerrit Uitslag                        'href'  => $href)));
830b5941dfaSKate Arzamastseva            $form->addElement($recent['id']);
831b5941dfaSKate Arzamastseva            $form->addElement(form_makeCloseTag('a'));
832b5941dfaSKate Arzamastseva        } else {
833b5941dfaSKate Arzamastseva            $form->addElement(html_wikilink(':' . $recent['id'], useHeading('navigation') ? null : $recent['id']));
834b5941dfaSKate Arzamastseva        }
835abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
83665cc1598SPhy        $form->addElement(' – ' . hsc($recent['sum']));
837abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
838abdcc39fSmichael
839abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
840d437bcc4SAndreas Gohr        if($recent['user']) {
841d317fb5dSAnika Henke            $form->addElement('<bdi>' . editorinfo($recent['user']) . '</bdi>');
842433efb25SAndreas Gohr            if(auth_ismanager()) {
843d317fb5dSAnika Henke                $form->addElement(' <bdo dir="ltr">(' . $recent['ip'] . ')</bdo>');
844433efb25SAndreas Gohr            }
84588f522e9Sandi        } else {
846d317fb5dSAnika Henke            $form->addElement('<bdo dir="ltr">' . $recent['ip'] . '</bdo>');
84788f522e9Sandi        }
848abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
849cffcc403Sandi
850cd2a4cfdSAnika Henke        html_sizechange($recent['sizechange'], $form);
851976b572aSGerrit Uitslag
852abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
853abdcc39fSmichael        $form->addElement(form_makeCloseTag('li'));
854f3f0262cSandi    }
855abdcc39fSmichael    $form->addElement(form_makeCloseTag('ul'));
856a39955b0Smatthiasgrimm
857abdcc39fSmichael    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
8585749f1ceSmatthiasgrimm    $last = $first + $conf['recent'];
859a39955b0Smatthiasgrimm    if($first > 0) {
860a39955b0Smatthiasgrimm        $first -= $conf['recent'];
861a39955b0Smatthiasgrimm        if($first < 0) $first = 0;
862abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
863ae614416SAnika Henke        $form->addElement(form_makeOpenTag('button', array(
864abdcc39fSmichael                        'type'      => 'submit',
865abdcc39fSmichael                        'name'      => 'first[' . $first . ']',
866cddd152cSmichael                        'accesskey' => 'n',
867f948eeabSMichael Klier                        'title'     => $lang['btn_newer'] . ' [N]',
868d5daba10SKate Arzamastseva                        'class'     => 'button show'
869abdcc39fSmichael                    )));
870ae614416SAnika Henke        $form->addElement($lang['btn_newer']);
871ae614416SAnika Henke        $form->addElement(form_makeCloseTag('button'));
872abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
873a39955b0Smatthiasgrimm    }
87471726d78SBen Coburn    if($hasNext) {
875abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
876ae614416SAnika Henke        $form->addElement(form_makeOpenTag('button', array(
877abdcc39fSmichael                        'type'      => 'submit',
878abdcc39fSmichael                        'name'      => 'first[' . $last . ']',
879cddd152cSmichael                        'accesskey' => 'p',
880f948eeabSMichael Klier                        'title'     => $lang['btn_older'] . ' [P]',
881d5daba10SKate Arzamastseva                        'class'     => 'button show'
882abdcc39fSmichael                    )));
883ae614416SAnika Henke        $form->addElement($lang['btn_older']);
884ae614416SAnika Henke        $form->addElement(form_makeCloseTag('button'));
885abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
886a39955b0Smatthiasgrimm    }
887abdcc39fSmichael    $form->addElement(form_makeCloseTag('div'));
888abdcc39fSmichael    html_form('recent', $form);
889f3f0262cSandi}
890f3f0262cSandi
89115fae107Sandi/**
89215fae107Sandi * Display page index
89315fae107Sandi *
89415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
89542ea7f44SGerrit Uitslag *
89642ea7f44SGerrit Uitslag * @param string $ns
89715fae107Sandi */
898f3f0262cSandifunction html_index($ns){
899f3f0262cSandi    global $conf;
900f3f0262cSandi    global $ID;
901f3f0262cSandi    $ns  = cleanID($ns);
902f3f0262cSandi    if(empty($ns)){
90382f5f399SSatoshi Sahara        $ns = getNS($ID);
904dab290efSSatoshi Sahara        if($ns === false) $ns ='';
905f3f0262cSandi    }
90688d3a917Sandi    $ns  = utf8_encodeFN(str_replace(':','/',$ns));
907f3f0262cSandi
908a06884abSAndreas Gohr    echo p_locale_xhtml('index');
909158a5bffSDeathCamel57    echo '<div id="index__tree" class="index__tree">';
910f3f0262cSandi
911f3f0262cSandi    $data = array();
912f3f0262cSandi    search($data,$conf['datadir'],'search_index',array('ns' => $ns));
913a06884abSAndreas Gohr    echo html_buildlist($data,'idx','html_list_index','html_li_index');
914a06884abSAndreas Gohr
915a06884abSAndreas Gohr    echo '</div>';
916f3f0262cSandi}
917f3f0262cSandi
918f3f0262cSandi/**
91915fae107Sandi * Index item formatter
92015fae107Sandi *
921f3f0262cSandi * User function for html_buildlist()
92215fae107Sandi *
92315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
92442ea7f44SGerrit Uitslag *
92542ea7f44SGerrit Uitslag * @param array $item
92642ea7f44SGerrit Uitslag * @return string
927f3f0262cSandi */
928f3f0262cSandifunction html_list_index($item){
92974ef1778SChristopher Smith    global $ID, $conf;
93074ef1778SChristopher Smith
931b8bc53ceSChristopher Smith    // prevent searchbots needlessly following links
93274ef1778SChristopher Smith    $nofollow = ($ID != $conf['start'] || $conf['sitemap']) ? 'rel="nofollow"' : '';
93374ef1778SChristopher Smith
934f3f0262cSandi    $ret = '';
935f3f0262cSandi    $base = ':'.$item['id'];
936f3f0262cSandi    $base = substr($base,strrpos($base,':')+1);
937f3f0262cSandi    if($item['type']=='d'){
938b1af9014SChristopher Smith        // FS#2766, no need for search bots to follow namespace links in the index
93964159a61SAndreas Gohr        $link = wl($ID, 'idx=' . rawurlencode($item['id']));
94064159a61SAndreas Gohr        $ret .= '<a href="' . $link . '" title="' . $item['id'] . '" class="idx_dir" ' . $nofollow . '><strong>';
941f3f0262cSandi        $ret .= $base;
942ed7ecb79SAnika Henke        $ret .= '</strong></a>';
943f3f0262cSandi    }else{
9449aa38483SMichael Hamann        // default is noNSorNS($id), but we want noNS($id) when useheading is off FS#2605
9459aa38483SMichael Hamann        $ret .= html_wikilink(':'.$item['id'], useHeading('navigation') ? null : noNS($item['id']));
946f3f0262cSandi    }
947f3f0262cSandi    return $ret;
948f3f0262cSandi}
949f3f0262cSandi
950f3f0262cSandi/**
951cb70c441Sandi * Index List item
952cb70c441Sandi *
953a1dee2b9SAdrian Lang * This user function is used in html_buildlist to build the
954cb70c441Sandi * <li> tags for namespaces when displaying the page index
955cb70c441Sandi * it gives different classes to opened or closed "folders"
956cb70c441Sandi *
957cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
95842ea7f44SGerrit Uitslag *
95942ea7f44SGerrit Uitslag * @param array $item
96042ea7f44SGerrit Uitslag * @return string html
961cb70c441Sandi */
962cb70c441Sandifunction html_li_index($item){
963f7dbf175SAndreas Gohr    global $INFO;
96421b07cb4SAndreas Gohr    global $ACT;
965f7dbf175SAndreas Gohr
9666fa4721aSAndreas Gohr    $class = '';
9676fa4721aSAndreas Gohr    $id = '';
9686fa4721aSAndreas Gohr
969cb70c441Sandi    if($item['type'] == "f"){
970f7dbf175SAndreas Gohr        // scroll to the current item
971aac83cd4SPhy        if(isset($INFO) && $item['id'] == $INFO['id'] && $ACT == 'index') {
972f7dbf175SAndreas Gohr            $id = ' id="scroll__here"';
973772f3c51SDeathCamel57            $class = ' bounce';
974f7dbf175SAndreas Gohr        }
9756fa4721aSAndreas Gohr        return '<li class="level'.$item['level'].$class.'" '.$id.'>';
976cb70c441Sandi    }elseif($item['open']){
977cb70c441Sandi        return '<li class="open">';
978cb70c441Sandi    }else{
979cb70c441Sandi        return '<li class="closed">';
980cb70c441Sandi    }
981cb70c441Sandi}
982cb70c441Sandi
983cb70c441Sandi/**
984cb70c441Sandi * Default List item
985cb70c441Sandi *
986cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
98742ea7f44SGerrit Uitslag *
98842ea7f44SGerrit Uitslag * @param array $item
98942ea7f44SGerrit Uitslag * @return string html
990cb70c441Sandi */
991cb70c441Sandifunction html_li_default($item){
992cb70c441Sandi    return '<li class="level'.$item['level'].'">';
993cb70c441Sandi}
994cb70c441Sandi
995cb70c441Sandi/**
99615fae107Sandi * Build an unordered list
99715fae107Sandi *
998f3f0262cSandi * Build an unordered list from the given $data array
999f3f0262cSandi * Each item in the array has to have a 'level' property
1000f3f0262cSandi * the item itself gets printed by the given $func user
1001cb70c441Sandi * function. The second and optional function is used to
1002cb70c441Sandi * print the <li> tag. Both user function need to accept
1003cb70c441Sandi * a single item.
100415fae107Sandi *
1005c5a8fd96SAndreas Gohr * Both user functions can be given as array to point to
1006c5a8fd96SAndreas Gohr * a member of an object.
1007c5a8fd96SAndreas Gohr *
100815fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
100980679bafSGerrit Uitslag *
101080679bafSGerrit Uitslag * @param array    $data  array with item arrays
101180679bafSGerrit Uitslag * @param string   $class class of ul wrapper
101280679bafSGerrit Uitslag * @param callable $func  callback to print an list item
10135a9597bbSTakamura * @param callable $lifunc callback to the opening li tag
101480679bafSGerrit Uitslag * @param bool     $forcewrapper Trigger building a wrapper ul if the first level is
1015ae614416SAnika Henke *                               0 (we have a root object) or 1 (just the root content)
101680679bafSGerrit Uitslag * @return string html of an unordered list
1017f3f0262cSandi */
101887671313SHakan Sandellfunction html_buildlist($data,$class,$func,$lifunc='html_li_default',$forcewrapper=false){
1019a1dee2b9SAdrian Lang    if (count($data) === 0) {
1020a1dee2b9SAdrian Lang        return '';
1021a1dee2b9SAdrian Lang    }
1022a1dee2b9SAdrian Lang
10232689c55fSMichael Große    $firstElement = reset($data);
10242689c55fSMichael Große    $start_level = $firstElement['level'];
10259e4f7880SAdrian Lang    $level = $start_level;
1026434f5921SHakan Sandell    $ret   = '';
1027434f5921SHakan Sandell    $open  = 0;
10289e4f7880SAdrian Lang
1029f3f0262cSandi    foreach ($data as $item){
1030f3f0262cSandi
1031f3f0262cSandi        if( $item['level'] > $level ){
1032f3f0262cSandi            //open new list
1033df52d0feSandi            for($i=0; $i<($item['level'] - $level); $i++){
1034434f5921SHakan Sandell                if ($i) $ret .= "<li class=\"clear\">";
1035f3f0262cSandi                $ret .= "\n<ul class=\"$class\">\n";
1036434f5921SHakan Sandell                $open++;
1037df52d0feSandi            }
1038434f5921SHakan Sandell            $level = $item['level'];
1039434f5921SHakan Sandell
1040f3f0262cSandi        }elseif( $item['level'] < $level ){
1041f3f0262cSandi            //close last item
1042f3f0262cSandi            $ret .= "</li>\n";
1043434f5921SHakan Sandell            while( $level > $item['level'] && $open > 0 ){
1044f3f0262cSandi                //close higher lists
1045f3f0262cSandi                $ret .= "</ul>\n</li>\n";
1046434f5921SHakan Sandell                $level--;
1047434f5921SHakan Sandell                $open--;
1048f3f0262cSandi            }
1049a1dee2b9SAdrian Lang        } elseif ($ret !== '') {
105087671313SHakan Sandell            //close previous item
1051f3f0262cSandi            $ret .= "</li>\n";
1052f3f0262cSandi        }
1053f3f0262cSandi
1054f3f0262cSandi        //print item
105534dbe711Schris        $ret .= call_user_func($lifunc,$item);
10560c6b58a8SAndreas Gohr        $ret .= '<div class="li">';
105734dbe711Schris
105834dbe711Schris        $ret .= call_user_func($func,$item);
10590c6b58a8SAndreas Gohr        $ret .= '</div>';
1060f3f0262cSandi    }
1061f3f0262cSandi
1062f3f0262cSandi    //close remaining items and lists
1063434f5921SHakan Sandell    $ret .= "</li>\n";
1064434f5921SHakan Sandell    while($open-- > 0) {
1065434f5921SHakan Sandell        $ret .= "</ul></li>\n";
1066434f5921SHakan Sandell    }
1067434f5921SHakan Sandell
1068434f5921SHakan Sandell    if ($forcewrapper || $start_level < 2) {
1069434f5921SHakan Sandell        // Trigger building a wrapper ul if the first level is
1070434f5921SHakan Sandell        // 0 (we have a root object) or 1 (just the root content)
1071434f5921SHakan Sandell        $ret = "\n<ul class=\"$class\">\n".$ret."</ul>\n";
1072f3f0262cSandi    }
1073f3f0262cSandi
1074f3f0262cSandi    return $ret;
1075f3f0262cSandi}
1076f3f0262cSandi
107715fae107Sandi/**
107815fae107Sandi * display backlinks
107915fae107Sandi *
108015fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
108111df47ecSMichael Klier * @author Michael Klier <chi@chimeric.de>
108215fae107Sandi */
1083f3f0262cSandifunction html_backlinks(){
1084f3f0262cSandi    global $ID;
108511df47ecSMichael Klier    global $lang;
1086f3f0262cSandi
1087c112d578Sandi    print p_locale_xhtml('backlinks');
1088f3f0262cSandi
1089a32da6ddSSatoshi Sahara    $data = (new MetadataIndex())->backlinks($ID);
1090f3f0262cSandi
109111df47ecSMichael Klier    if(!empty($data)) {
1092f3f0262cSandi        print '<ul class="idx">';
109354f4c056SAndreas Gohr        foreach($data as $blink){
10940c6b58a8SAndreas Gohr            print '<li><div class="li">';
1095db959ae3SAndreas Gohr            print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink);
10960c6b58a8SAndreas Gohr            print '</div></li>';
1097f3f0262cSandi        }
1098f3f0262cSandi        print '</ul>';
109911df47ecSMichael Klier    } else {
110011df47ecSMichael Klier        print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
110111df47ecSMichael Klier    }
1102f3f0262cSandi}
1103f3f0262cSandi
11048d5e837eSMichael Hamann/**
11058d5e837eSMichael Hamann * Get header of diff HTML
110642ea7f44SGerrit Uitslag *
11078d5e837eSMichael Hamann * @param string $l_rev   Left revisions
11088d5e837eSMichael Hamann * @param string $r_rev   Right revision
11098d5e837eSMichael Hamann * @param string $id      Page id, if null $ID is used
11108d5e837eSMichael Hamann * @param bool   $media   If it is for media files
1111f76724a4STom N Harris * @param bool   $inline  Return the header on a single line
111242ea7f44SGerrit Uitslag * @return string[] HTML snippets for diff header
11138d5e837eSMichael Hamann */
1114f76724a4STom N Harrisfunction html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = false) {
111595b451bcSAdrian Lang    global $lang;
111695b451bcSAdrian Lang    if ($id === null) {
111795b451bcSAdrian Lang        global $ID;
111895b451bcSAdrian Lang        $id = $ID;
111995b451bcSAdrian Lang    }
1120f76724a4STom N Harris    $head_separator = $inline ? ' ' : '<br />';
112195b451bcSAdrian Lang    $media_or_wikiFN = $media ? 'mediaFN' : 'wikiFN';
112295b451bcSAdrian Lang    $ml_or_wl = $media ? 'ml' : 'wl';
112395b451bcSAdrian Lang    $l_minor = $r_minor = '';
112495b451bcSAdrian Lang
1125047bad06SGerrit Uitslag    if($media) {
11264f6e20c7SGerrit Uitslag        $changelog = new MediaChangeLog($id);
1127047bad06SGerrit Uitslag    } else {
11284f6e20c7SGerrit Uitslag        $changelog = new PageChangeLog($id);
1129047bad06SGerrit Uitslag    }
113095b451bcSAdrian Lang    if(!$l_rev){
113195b451bcSAdrian Lang        $l_head = '&mdash;';
113295b451bcSAdrian Lang    }else{
11334f6e20c7SGerrit Uitslag        $l_info   = $changelog->getRevisionInfo($l_rev);
113495b451bcSAdrian Lang        if($l_info['user']){
1135d317fb5dSAnika Henke            $l_user = '<bdi>'.editorinfo($l_info['user']).'</bdi>';
1136d317fb5dSAnika Henke            if(auth_ismanager()) $l_user .= ' <bdo dir="ltr">('.$l_info['ip'].')</bdo>';
113795b451bcSAdrian Lang        } else {
1138d317fb5dSAnika Henke            $l_user = '<bdo dir="ltr">'.$l_info['ip'].'</bdo>';
113995b451bcSAdrian Lang        }
114095b451bcSAdrian Lang        $l_user  = '<span class="user">'.$l_user.'</span>';
1141d317fb5dSAnika Henke        $l_sum   = ($l_info['sum']) ? '<span class="sum"><bdi>'.hsc($l_info['sum']).'</bdi></span>' : '';
114295b451bcSAdrian Lang        if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
114395b451bcSAdrian Lang
1144699c5072SAnika Henke        $l_head_title = ($media) ? dformat($l_rev) : $id.' ['.dformat($l_rev).']';
1145d317fb5dSAnika Henke        $l_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$l_rev").'">'.
1146d317fb5dSAnika Henke        $l_head_title.'</a></bdi>'.
1147f76724a4STom N Harris        $head_separator.$l_user.' '.$l_sum;
114895b451bcSAdrian Lang    }
114995b451bcSAdrian Lang
115095b451bcSAdrian Lang    if($r_rev){
11514f6e20c7SGerrit Uitslag        $r_info   = $changelog->getRevisionInfo($r_rev);
115295b451bcSAdrian Lang        if($r_info['user']){
1153d317fb5dSAnika Henke            $r_user = '<bdi>'.editorinfo($r_info['user']).'</bdi>';
1154d317fb5dSAnika Henke            if(auth_ismanager()) $r_user .= ' <bdo dir="ltr">('.$r_info['ip'].')</bdo>';
115595b451bcSAdrian Lang        } else {
1156d317fb5dSAnika Henke            $r_user = '<bdo dir="ltr">'.$r_info['ip'].'</bdo>';
115795b451bcSAdrian Lang        }
115895b451bcSAdrian Lang        $r_user = '<span class="user">'.$r_user.'</span>';
1159d317fb5dSAnika Henke        $r_sum  = ($r_info['sum']) ? '<span class="sum"><bdi>'.hsc($r_info['sum']).'</bdi></span>' : '';
116095b451bcSAdrian Lang        if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
116195b451bcSAdrian Lang
1162699c5072SAnika Henke        $r_head_title = ($media) ? dformat($r_rev) : $id.' ['.dformat($r_rev).']';
1163d317fb5dSAnika Henke        $r_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$r_rev").'">'.
1164d317fb5dSAnika Henke        $r_head_title.'</a></bdi>'.
1165f76724a4STom N Harris        $head_separator.$r_user.' '.$r_sum;
116695b451bcSAdrian Lang    }elseif($_rev = @filemtime($media_or_wikiFN($id))){
11674f6e20c7SGerrit Uitslag        $_info   = $changelog->getRevisionInfo($_rev);
116895b451bcSAdrian Lang        if($_info['user']){
1169d317fb5dSAnika Henke            $_user = '<bdi>'.editorinfo($_info['user']).'</bdi>';
1170d317fb5dSAnika Henke            if(auth_ismanager()) $_user .= ' <bdo dir="ltr">('.$_info['ip'].')</bdo>';
117195b451bcSAdrian Lang        } else {
1172d317fb5dSAnika Henke            $_user = '<bdo dir="ltr">'.$_info['ip'].'</bdo>';
117395b451bcSAdrian Lang        }
117495b451bcSAdrian Lang        $_user = '<span class="user">'.$_user.'</span>';
1175d317fb5dSAnika Henke        $_sum  = ($_info['sum']) ? '<span class="sum"><bdi>'.hsc($_info['sum']).'</span></bdi>' : '';
117695b451bcSAdrian Lang        if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
117795b451bcSAdrian Lang
1178699c5072SAnika Henke        $r_head_title = ($media) ? dformat($_rev) : $id.' ['.dformat($_rev).']';
1179d317fb5dSAnika Henke        $r_head  = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id).'">'.
1180d317fb5dSAnika Henke        $r_head_title.'</a></bdi> '.
118195b451bcSAdrian Lang        '('.$lang['current'].')'.
1182f76724a4STom N Harris        $head_separator.$_user.' '.$_sum;
118395b451bcSAdrian Lang    }else{
118495b451bcSAdrian Lang        $r_head = '&mdash; ('.$lang['current'].')';
118595b451bcSAdrian Lang    }
118695b451bcSAdrian Lang
118795b451bcSAdrian Lang    return array($l_head, $r_head, $l_minor, $r_minor);
118895b451bcSAdrian Lang}
118995b451bcSAdrian Lang
119015fae107Sandi/**
119104e99fe1SGerrit Uitslag * Show diff
1192baf0c3e5SGerrit Uitslag * between current page version and provided $text
1193baf0c3e5SGerrit Uitslag * or between the revisions provided via GET or POST
119415fae107Sandi *
119515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1196baf0c3e5SGerrit Uitslag * @param  string $text  when non-empty: compare with this text with most current version
119704e99fe1SGerrit Uitslag * @param  bool   $intro display the intro text
11988d5e837eSMichael Hamann * @param  string $type  type of the diff (inline or sidebyside)
119915fae107Sandi */
120072165381SAndreas Gohrfunction html_diff($text = '', $intro = true, $type = null) {
1201f3f0262cSandi    global $ID;
1202f3f0262cSandi    global $REV;
1203f3f0262cSandi    global $lang;
1204f0859d4bSTom N Harris    global $INPUT;
12053c94d07bSAnika Henke    global $INFO;
1206047bad06SGerrit Uitslag    $pagelog = new PageChangeLog($ID);
1207e1bd90ffSAndreas Gohr
1208c7686ac1SGerrit Uitslag    /*
1209c7686ac1SGerrit Uitslag     * Determine diff type
1210c7686ac1SGerrit Uitslag     */
12113c94d07bSAnika Henke    if(!$type) {
12123c94d07bSAnika Henke        $type = $INPUT->str('difftype');
12133c94d07bSAnika Henke        if(empty($type)) {
12143c94d07bSAnika Henke            $type = get_doku_pref('difftype', $type);
12153c94d07bSAnika Henke            if(empty($type) && $INFO['ismobile']) {
12163c94d07bSAnika Henke                $type = 'inline';
12173c94d07bSAnika Henke            }
12183c94d07bSAnika Henke        }
12193c94d07bSAnika Henke    }
122072165381SAndreas Gohr    if($type != 'inline') $type = 'sidebyside';
122172165381SAndreas Gohr
1222c7686ac1SGerrit Uitslag    /*
1223c7686ac1SGerrit Uitslag     * Determine requested revision(s)
1224c7686ac1SGerrit Uitslag     */
122577707b04SAndreas Gohr    // we're trying to be clever here, revisions to compare can be either
122677707b04SAndreas Gohr    // given as rev and rev2 parameters, with rev2 being optional. Or in an
122777707b04SAndreas Gohr    // array in rev2.
122877707b04SAndreas Gohr    $rev1 = $REV;
12297b3f8b16SAndreas Gohr
1230f1d7655bSAndreas Gohr    $rev2 = $INPUT->ref('rev2');
1231f1d7655bSAndreas Gohr    if(is_array($rev2)) {
1232f1d7655bSAndreas Gohr        $rev1 = (int) $rev2[0];
1233f1d7655bSAndreas Gohr        $rev2 = (int) $rev2[1];
123454041c77SAndreas Gohr
123554041c77SAndreas Gohr        if(!$rev1) {
123654041c77SAndreas Gohr            $rev1 = $rev2;
123754041c77SAndreas Gohr            unset($rev2);
123854041c77SAndreas Gohr        }
1239f3f0262cSandi    } else {
1240f0859d4bSTom N Harris        $rev2 = $INPUT->int('rev2');
12414d58bd99Sandi    }
12424d58bd99Sandi
1243c7686ac1SGerrit Uitslag    /*
1244c7686ac1SGerrit Uitslag     * Determine left and right revision, its texts and the header
1245c7686ac1SGerrit Uitslag     */
12463733161eSAdrian Lang    $r_minor = '';
12473733161eSAdrian Lang    $l_minor = '';
12483733161eSAdrian Lang
124977707b04SAndreas Gohr    if($text) { // compare text to the most current revision
125077707b04SAndreas Gohr        $l_rev = '';
125177707b04SAndreas Gohr        $l_text = rawWiki($ID, '');
125277707b04SAndreas Gohr        $l_head = '<a class="wikilink1" href="' . wl($ID) . '">' .
1253f2263577SAndreas Gohr            $ID . ' ' . dformat((int) @filemtime(wikiFN($ID))) . '</a> ' .
125477707b04SAndreas Gohr            $lang['current'];
125577707b04SAndreas Gohr
125677707b04SAndreas Gohr        $r_rev = '';
125777707b04SAndreas Gohr        $r_text = cleanText($text);
125877707b04SAndreas Gohr        $r_head = $lang['yours'];
1259e1bd90ffSAndreas Gohr    } else {
12606d9eab4dSMichael Hamann        if($rev1 && isset($rev2) && $rev2) { // two specific revisions wanted
126154041c77SAndreas Gohr            // make sure order is correct (older on the left)
126277707b04SAndreas Gohr            if($rev1 < $rev2) {
126377707b04SAndreas Gohr                $l_rev = $rev1;
126477707b04SAndreas Gohr                $r_rev = $rev2;
126577707b04SAndreas Gohr            } else {
126677707b04SAndreas Gohr                $l_rev = $rev2;
126777707b04SAndreas Gohr                $r_rev = $rev1;
1268e1bd90ffSAndreas Gohr            }
126977707b04SAndreas Gohr        } elseif($rev1) { // single revision given, compare to current
127077707b04SAndreas Gohr            $r_rev = '';
127177707b04SAndreas Gohr            $l_rev = $rev1;
127277707b04SAndreas Gohr        } else { // no revision was given, compare previous to current
127377707b04SAndreas Gohr            $r_rev = '';
1274f523c971SGerrit Uitslag            $revs = $pagelog->getRevisions(0, 1);
127577707b04SAndreas Gohr            $l_rev = $revs[0];
12766f8e9f59SAndreas Gohr            $REV = $l_rev; // store revision back in $REV
127777707b04SAndreas Gohr        }
127877707b04SAndreas Gohr
12797b3f8b16SAndreas Gohr        // when both revisions are empty then the page was created just now
12807b3f8b16SAndreas Gohr        if(!$l_rev && !$r_rev) {
12817b3f8b16SAndreas Gohr            $l_text = '';
12827b3f8b16SAndreas Gohr        } else {
128377707b04SAndreas Gohr            $l_text = rawWiki($ID, $l_rev);
12847b3f8b16SAndreas Gohr        }
128577707b04SAndreas Gohr        $r_text = rawWiki($ID, $r_rev);
128677707b04SAndreas Gohr
1287f76724a4STom N Harris        list($l_head, $r_head, $l_minor, $r_minor) = html_diff_head($l_rev, $r_rev, null, false, $type == 'inline');
128877707b04SAndreas Gohr    }
128977707b04SAndreas Gohr
1290c7686ac1SGerrit Uitslag    /*
1291c7686ac1SGerrit Uitslag     * Build navigation
1292c7686ac1SGerrit Uitslag     */
1293c7686ac1SGerrit Uitslag    $l_nav = '';
1294c7686ac1SGerrit Uitslag    $r_nav = '';
1295c7686ac1SGerrit Uitslag    if(!$text) {
1296baf0c3e5SGerrit Uitslag        list($l_nav, $r_nav) = html_diff_navigation($pagelog, $type, $l_rev, $r_rev);
1297c7686ac1SGerrit Uitslag    }
1298c7686ac1SGerrit Uitslag    /*
1299c7686ac1SGerrit Uitslag     * Create diff object and the formatter
1300c7686ac1SGerrit Uitslag     */
130104e99fe1SGerrit Uitslag    $diff = new Diff(explode("\n", $l_text), explode("\n", $r_text));
130277707b04SAndreas Gohr
130372165381SAndreas Gohr    if($type == 'inline') {
130404e99fe1SGerrit Uitslag        $diffformatter = new InlineDiffFormatter();
130572165381SAndreas Gohr    } else {
130604e99fe1SGerrit Uitslag        $diffformatter = new TableDiffFormatter();
130772165381SAndreas Gohr    }
1308c7686ac1SGerrit Uitslag    /*
1309c7686ac1SGerrit Uitslag     * Display intro
1310c7686ac1SGerrit Uitslag     */
1311c112d578Sandi    if($intro) print p_locale_xhtml('diff');
1312226bf2dcSGina Haeussge
1313c7686ac1SGerrit Uitslag    /*
1314c7686ac1SGerrit Uitslag     * Display type and exact reference
1315c7686ac1SGerrit Uitslag     */
1316226bf2dcSGina Haeussge    if(!$text) {
1317c130b0f8SAnika Henke        ptln('<div class="diffoptions group">');
131872165381SAndreas Gohr
1319c7686ac1SGerrit Uitslag
132072165381SAndreas Gohr        $form = new Doku_Form(array('action' => wl()));
13211b885c58SAndreas Gohr        $form->addHidden('id', $ID);
132272165381SAndreas Gohr        $form->addHidden('rev2[0]', $l_rev);
132372165381SAndreas Gohr        $form->addHidden('rev2[1]', $r_rev);
132472165381SAndreas Gohr        $form->addHidden('do', 'diff');
132504e99fe1SGerrit Uitslag        $form->addElement(
132604e99fe1SGerrit Uitslag             form_makeListboxField(
132772165381SAndreas Gohr                 'difftype',
132872165381SAndreas Gohr                 array(
132972165381SAndreas Gohr                     'sidebyside' => $lang['diff_side'],
133004e99fe1SGerrit Uitslag                     'inline' => $lang['diff_inline']
133104e99fe1SGerrit Uitslag                 ),
133272165381SAndreas Gohr                 $type,
133372165381SAndreas Gohr                 $lang['diff_type'],
133472165381SAndreas Gohr                 '', '',
133504e99fe1SGerrit Uitslag                 array('class' => 'quickselect')
133604e99fe1SGerrit Uitslag             )
133704e99fe1SGerrit Uitslag        );
133872165381SAndreas Gohr        $form->addElement(form_makeButton('submit', 'diff', 'Go'));
133972165381SAndreas Gohr        $form->printForm();
134072165381SAndreas Gohr
13414fc1354aSGerrit Uitslag        ptln('<p>');
13424fc1354aSGerrit Uitslag        // link to exactly this view FS#2835
13438fcb305dSGerrit Uitslag        echo html_diff_navigationlink($type, 'difflink', $l_rev, $r_rev ? $r_rev : $INFO['currentrev']);
134498a6b214SAnika Henke        ptln('</p>');
1345cfe2f202SGerrit Uitslag
1346cfe2f202SGerrit Uitslag        ptln('</div>'); // .diffoptions
134704e99fe1SGerrit Uitslag    }
1348f1f2f711SGerrit Uitslag
134951684808SGerrit Uitslag    /*
1350c7686ac1SGerrit Uitslag     * Display diff view table
135151684808SGerrit Uitslag     */
1352f3f0262cSandi    ?>
1353c7b28ffdSAnika Henke    <div class="table">
135472165381SAndreas Gohr    <table class="diff diff_<?php echo $type ?>">
1355c7686ac1SGerrit Uitslag
135604e99fe1SGerrit Uitslag        <?php
1357c7686ac1SGerrit Uitslag        //navigation and header
1358cfe2f202SGerrit Uitslag        if($type == 'inline') {
1359cfe2f202SGerrit Uitslag            if(!$text) { ?>
1360cfe2f202SGerrit Uitslag                <tr>
1361cfe2f202SGerrit Uitslag                    <td class="diff-lineheader">-</td>
1362cfe2f202SGerrit Uitslag                    <td class="diffnav"><?php echo $l_nav ?></td>
1363cfe2f202SGerrit Uitslag                </tr>
1364f76724a4STom N Harris                <tr>
136504e99fe1SGerrit Uitslag                    <th class="diff-lineheader">-</th>
136604e99fe1SGerrit Uitslag                    <th <?php echo $l_minor ?>>
1367f76724a4STom N Harris                        <?php echo $l_head ?>
1368f76724a4STom N Harris                    </th>
1369f76724a4STom N Harris                </tr>
1370cfe2f202SGerrit Uitslag            <?php } ?>
1371cfe2f202SGerrit Uitslag            <tr>
1372cfe2f202SGerrit Uitslag                <td class="diff-lineheader">+</td>
1373cfe2f202SGerrit Uitslag                <td class="diffnav"><?php echo $r_nav ?></td>
1374cfe2f202SGerrit Uitslag            </tr>
1375f76724a4STom N Harris            <tr>
137604e99fe1SGerrit Uitslag                <th class="diff-lineheader">+</th>
137704e99fe1SGerrit Uitslag                <th <?php echo $r_minor ?>>
1378f76724a4STom N Harris                    <?php echo $r_head ?>
1379f76724a4STom N Harris                </th>
1380f76724a4STom N Harris            </tr>
1381cfe2f202SGerrit Uitslag        <?php } else {
1382cfe2f202SGerrit Uitslag            if(!$text) { ?>
1383cfe2f202SGerrit Uitslag                <tr>
1384cfe2f202SGerrit Uitslag                    <td colspan="2" class="diffnav"><?php echo $l_nav ?></td>
1385cfe2f202SGerrit Uitslag                    <td colspan="2" class="diffnav"><?php echo $r_nav ?></td>
1386cfe2f202SGerrit Uitslag                </tr>
1387cfe2f202SGerrit Uitslag            <?php } ?>
1388f3f0262cSandi            <tr>
1389e5e61eb0SAnika Henke                <th colspan="2" <?php echo $l_minor ?>>
139077707b04SAndreas Gohr                    <?php echo $l_head ?>
1391daf4ca4eSAnika Henke                </th>
1392e5e61eb0SAnika Henke                <th colspan="2" <?php echo $r_minor ?>>
139377707b04SAndreas Gohr                    <?php echo $r_head ?>
1394daf4ca4eSAnika Henke                </th>
1395f3f0262cSandi            </tr>
1396f76724a4STom N Harris        <?php }
1397c7686ac1SGerrit Uitslag
1398c7686ac1SGerrit Uitslag        //diff view
139904e99fe1SGerrit Uitslag        echo html_insert_softbreaks($diffformatter->format($diff)); ?>
1400c7686ac1SGerrit Uitslag
1401f3f0262cSandi    </table>
1402c7b28ffdSAnika Henke    </div>
14034da078a3Smatthiasgrimm<?php
1404f3f0262cSandi}
1405f3f0262cSandi
14064fc1354aSGerrit Uitslag/**
1407baf0c3e5SGerrit Uitslag * Create html for revision navigation
1408baf0c3e5SGerrit Uitslag *
1409baf0c3e5SGerrit Uitslag * @param PageChangeLog $pagelog changelog object of current page
1410baf0c3e5SGerrit Uitslag * @param string        $type    inline vs sidebyside
1411baf0c3e5SGerrit Uitslag * @param int           $l_rev   left revision timestamp
1412baf0c3e5SGerrit Uitslag * @param int           $r_rev   right revision timestamp
1413baf0c3e5SGerrit Uitslag * @return string[] html of left and right navigation elements
1414baf0c3e5SGerrit Uitslag */
1415baf0c3e5SGerrit Uitslagfunction html_diff_navigation($pagelog, $type, $l_rev, $r_rev) {
1416baf0c3e5SGerrit Uitslag    global $INFO, $ID;
1417baf0c3e5SGerrit Uitslag
14184d5954c8SGerrit Uitslag    // last timestamp is not in changelog, retrieve timestamp from metadata
14194d5954c8SGerrit Uitslag    // note: when page is removed, the metadata timestamp is zero
1420bdca103aSAndreas Gohr    if(!$r_rev) {
1421bdca103aSAndreas Gohr        if(isset($INFO['meta']['last_change']['date'])) {
1422bdca103aSAndreas Gohr            $r_rev = $INFO['meta']['last_change']['date'];
1423bdca103aSAndreas Gohr        } else {
1424bdca103aSAndreas Gohr            $r_rev = 0;
1425bdca103aSAndreas Gohr        }
1426bdca103aSAndreas Gohr    }
1427baf0c3e5SGerrit Uitslag
1428baf0c3e5SGerrit Uitslag    //retrieve revisions with additional info
1429baf0c3e5SGerrit Uitslag    list($l_revs, $r_revs) = $pagelog->getRevisionsAround($l_rev, $r_rev);
1430baf0c3e5SGerrit Uitslag    $l_revisions = array();
1431621bbd2aSGerrit Uitslag    if(!$l_rev) {
1432621bbd2aSGerrit Uitslag        $l_revisions[0] = array(0, "", false); //no left revision given, add dummy
1433621bbd2aSGerrit Uitslag    }
1434baf0c3e5SGerrit Uitslag    foreach($l_revs as $rev) {
1435baf0c3e5SGerrit Uitslag        $info = $pagelog->getRevisionInfo($rev);
1436baf0c3e5SGerrit Uitslag        $l_revisions[$rev] = array(
1437baf0c3e5SGerrit Uitslag            $rev,
1438c006b6aaSGerrit Uitslag            dformat($info['date']) . ' ' . editorinfo($info['user'], true) . ' ' . $info['sum'],
1439621bbd2aSGerrit Uitslag            $r_rev ? $rev >= $r_rev : false //disable?
1440baf0c3e5SGerrit Uitslag        );
1441baf0c3e5SGerrit Uitslag    }
1442baf0c3e5SGerrit Uitslag    $r_revisions = array();
1443621bbd2aSGerrit Uitslag    if(!$r_rev) {
1444621bbd2aSGerrit Uitslag        $r_revisions[0] = array(0, "", false); //no right revision given, add dummy
1445621bbd2aSGerrit Uitslag    }
1446baf0c3e5SGerrit Uitslag    foreach($r_revs as $rev) {
1447baf0c3e5SGerrit Uitslag        $info = $pagelog->getRevisionInfo($rev);
1448baf0c3e5SGerrit Uitslag        $r_revisions[$rev] = array(
1449baf0c3e5SGerrit Uitslag            $rev,
1450c006b6aaSGerrit Uitslag            dformat($info['date']) . ' ' . editorinfo($info['user'], true) . ' ' . $info['sum'],
1451baf0c3e5SGerrit Uitslag            $rev <= $l_rev //disable?
1452baf0c3e5SGerrit Uitslag        );
1453baf0c3e5SGerrit Uitslag    }
1454621bbd2aSGerrit Uitslag
1455baf0c3e5SGerrit Uitslag    //determine previous/next revisions
1456baf0c3e5SGerrit Uitslag    $l_index = array_search($l_rev, $l_revs);
1457baf0c3e5SGerrit Uitslag    $l_prev = $l_revs[$l_index + 1];
1458baf0c3e5SGerrit Uitslag    $l_next = $l_revs[$l_index - 1];
1459621bbd2aSGerrit Uitslag    if($r_rev) {
1460baf0c3e5SGerrit Uitslag        $r_index = array_search($r_rev, $r_revs);
1461baf0c3e5SGerrit Uitslag        $r_prev = $r_revs[$r_index + 1];
1462baf0c3e5SGerrit Uitslag        $r_next = $r_revs[$r_index - 1];
1463621bbd2aSGerrit Uitslag    } else {
1464621bbd2aSGerrit Uitslag        //removed page
1465621bbd2aSGerrit Uitslag        if($l_next) {
1466621bbd2aSGerrit Uitslag            $r_prev = $r_revs[0];
1467621bbd2aSGerrit Uitslag        } else {
1468621bbd2aSGerrit Uitslag            $r_prev = null;
1469621bbd2aSGerrit Uitslag        }
1470621bbd2aSGerrit Uitslag        $r_next = null;
1471621bbd2aSGerrit Uitslag    }
1472baf0c3e5SGerrit Uitslag
1473baf0c3e5SGerrit Uitslag    /*
1474baf0c3e5SGerrit Uitslag     * Left side:
1475baf0c3e5SGerrit Uitslag     */
1476baf0c3e5SGerrit Uitslag    $l_nav = '';
1477baf0c3e5SGerrit Uitslag    //move back
1478baf0c3e5SGerrit Uitslag    if($l_prev) {
1479baf0c3e5SGerrit Uitslag        $l_nav .= html_diff_navigationlink($type, 'diffbothprevrev', $l_prev, $r_prev);
1480baf0c3e5SGerrit Uitslag        $l_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_prev, $r_rev);
1481baf0c3e5SGerrit Uitslag    }
1482baf0c3e5SGerrit Uitslag    //dropdown
1483baf0c3e5SGerrit Uitslag    $form = new Doku_Form(array('action' => wl()));
1484baf0c3e5SGerrit Uitslag    $form->addHidden('id', $ID);
1485baf0c3e5SGerrit Uitslag    $form->addHidden('difftype', $type);
1486baf0c3e5SGerrit Uitslag    $form->addHidden('rev2[1]', $r_rev);
1487baf0c3e5SGerrit Uitslag    $form->addHidden('do', 'diff');
1488baf0c3e5SGerrit Uitslag    $form->addElement(
1489baf0c3e5SGerrit Uitslag         form_makeListboxField(
1490baf0c3e5SGerrit Uitslag             'rev2[0]',
1491baf0c3e5SGerrit Uitslag             $l_revisions,
1492baf0c3e5SGerrit Uitslag             $l_rev,
1493baf0c3e5SGerrit Uitslag             '', '', '',
1494baf0c3e5SGerrit Uitslag             array('class' => 'quickselect')
1495baf0c3e5SGerrit Uitslag         )
1496baf0c3e5SGerrit Uitslag    );
1497baf0c3e5SGerrit Uitslag    $form->addElement(form_makeButton('submit', 'diff', 'Go'));
1498baf0c3e5SGerrit Uitslag    $l_nav .= $form->getForm();
1499baf0c3e5SGerrit Uitslag    //move forward
1500621bbd2aSGerrit Uitslag    if($l_next && ($l_next < $r_rev || !$r_rev)) {
1501baf0c3e5SGerrit Uitslag        $l_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_next, $r_rev);
1502baf0c3e5SGerrit Uitslag    }
1503baf0c3e5SGerrit Uitslag
1504baf0c3e5SGerrit Uitslag    /*
1505baf0c3e5SGerrit Uitslag     * Right side:
1506baf0c3e5SGerrit Uitslag     */
1507baf0c3e5SGerrit Uitslag    $r_nav = '';
1508baf0c3e5SGerrit Uitslag    //move back
1509baf0c3e5SGerrit Uitslag    if($l_rev < $r_prev) {
1510baf0c3e5SGerrit Uitslag        $r_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_rev, $r_prev);
1511baf0c3e5SGerrit Uitslag    }
1512baf0c3e5SGerrit Uitslag    //dropdown
1513baf0c3e5SGerrit Uitslag    $form = new Doku_Form(array('action' => wl()));
1514baf0c3e5SGerrit Uitslag    $form->addHidden('id', $ID);
1515baf0c3e5SGerrit Uitslag    $form->addHidden('rev2[0]', $l_rev);
1516baf0c3e5SGerrit Uitslag    $form->addHidden('difftype', $type);
1517baf0c3e5SGerrit Uitslag    $form->addHidden('do', 'diff');
1518baf0c3e5SGerrit Uitslag    $form->addElement(
1519baf0c3e5SGerrit Uitslag         form_makeListboxField(
1520baf0c3e5SGerrit Uitslag             'rev2[1]',
1521baf0c3e5SGerrit Uitslag             $r_revisions,
1522baf0c3e5SGerrit Uitslag             $r_rev,
1523baf0c3e5SGerrit Uitslag             '', '', '',
1524baf0c3e5SGerrit Uitslag             array('class' => 'quickselect')
1525baf0c3e5SGerrit Uitslag         )
1526baf0c3e5SGerrit Uitslag    );
1527baf0c3e5SGerrit Uitslag    $form->addElement(form_makeButton('submit', 'diff', 'Go'));
1528baf0c3e5SGerrit Uitslag    $r_nav .= $form->getForm();
1529baf0c3e5SGerrit Uitslag    //move forward
1530baf0c3e5SGerrit Uitslag    if($r_next) {
1531baf0c3e5SGerrit Uitslag        if($pagelog->isCurrentRevision($r_next)) {
1532baf0c3e5SGerrit Uitslag            $r_nav .= html_diff_navigationlink($type, 'difflastrev', $l_rev); //last revision is diff with current page
1533baf0c3e5SGerrit Uitslag        } else {
1534baf0c3e5SGerrit Uitslag            $r_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_rev, $r_next);
1535baf0c3e5SGerrit Uitslag        }
1536baf0c3e5SGerrit Uitslag        $r_nav .= html_diff_navigationlink($type, 'diffbothnextrev', $l_next, $r_next);
1537baf0c3e5SGerrit Uitslag    }
1538baf0c3e5SGerrit Uitslag    return array($l_nav, $r_nav);
1539baf0c3e5SGerrit Uitslag}
1540baf0c3e5SGerrit Uitslag
1541baf0c3e5SGerrit Uitslag/**
15424fc1354aSGerrit Uitslag * Create html link to a diff defined by two revisions
15434fc1354aSGerrit Uitslag *
154498a6b214SAnika Henke * @param string $difftype display type
154598a6b214SAnika Henke * @param string $linktype
15464fc1354aSGerrit Uitslag * @param int $lrev oldest revision
15474fc1354aSGerrit Uitslag * @param int $rrev newest revision or null for diff with current revision
15484fc1354aSGerrit Uitslag * @return string html of link to a diff
15494fc1354aSGerrit Uitslag */
155098a6b214SAnika Henkefunction html_diff_navigationlink($difftype, $linktype, $lrev, $rrev = null) {
155198a6b214SAnika Henke    global $ID, $lang;
1552621bbd2aSGerrit Uitslag    if(!$rrev) {
15534fc1354aSGerrit Uitslag        $urlparam = array(
15544fc1354aSGerrit Uitslag            'do' => 'diff',
15554fc1354aSGerrit Uitslag            'rev' => $lrev,
155698a6b214SAnika Henke            'difftype' => $difftype,
15574fc1354aSGerrit Uitslag        );
15584fc1354aSGerrit Uitslag    } else {
15594fc1354aSGerrit Uitslag        $urlparam = array(
15604fc1354aSGerrit Uitslag            'do' => 'diff',
15614fc1354aSGerrit Uitslag            'rev2[0]' => $lrev,
15624fc1354aSGerrit Uitslag            'rev2[1]' => $rrev,
156398a6b214SAnika Henke            'difftype' => $difftype,
15644fc1354aSGerrit Uitslag        );
15654fc1354aSGerrit Uitslag    }
1566cfe2f202SGerrit Uitslag    return  '<a class="' . $linktype . '" href="' . wl($ID, $urlparam) . '" title="' . $lang[$linktype] . '">' .
1567cfe2f202SGerrit Uitslag                '<span>' . $lang[$linktype] . '</span>' .
1568cfe2f202SGerrit Uitslag            '</a>' . "\n";
15694fc1354aSGerrit Uitslag}
15704fc1354aSGerrit Uitslag
1571a8397511SGerrit Uitslag/**
1572a8397511SGerrit Uitslag * Insert soft breaks in diff html
1573a8397511SGerrit Uitslag *
157442ea7f44SGerrit Uitslag * @param string $diffhtml
1575a8397511SGerrit Uitslag * @return string
1576a8397511SGerrit Uitslag */
1577fcfecb69SChristopher Smithfunction html_insert_softbreaks($diffhtml) {
1578fcfecb69SChristopher Smith    // search the diff html string for both:
1579fcfecb69SChristopher Smith    // - html tags, so these can be ignored
1580fcfecb69SChristopher Smith    // - long strings of characters without breaking characters
1581fcfecb69SChristopher Smith    return preg_replace_callback('/<[^>]*>|[^<> ]{12,}/','html_softbreak_callback',$diffhtml);
1582fcfecb69SChristopher Smith}
1583fcfecb69SChristopher Smith
1584a8397511SGerrit Uitslag/**
1585a8397511SGerrit Uitslag * callback which adds softbreaks
1586a8397511SGerrit Uitslag *
1587a8397511SGerrit Uitslag * @param array $match array with first the complete match
1588a8397511SGerrit Uitslag * @return string the replacement
1589a8397511SGerrit Uitslag */
1590fcfecb69SChristopher Smithfunction html_softbreak_callback($match){
1591fcfecb69SChristopher Smith    // if match is an html tag, return it intact
15922401f18dSSyntaxseed    if ($match[0][0] == '<') return $match[0];
1593fcfecb69SChristopher Smith
1594fcfecb69SChristopher Smith    // its a long string without a breaking character,
1595fcfecb69SChristopher Smith    // make certain characters into breaking characters by inserting a
159654436b19Sbleistivt    // word break opportunity (<wbr> tag) in front of them.
1597fcfecb69SChristopher Smith    $regex = <<< REGEX
1598fcfecb69SChristopher Smith(?(?=              # start a conditional expression with a positive look ahead ...
1599298a7e08SChristopher Smith&\#?\\w{1,6};)     # ... for html entities - we don't want to split them (ok to catch some invalid combinations)
1600298a7e08SChristopher Smith&\#?\\w{1,6};      # yes pattern - a quicker match for the html entity, since we know we have one
1601fcfecb69SChristopher Smith|
160207a7d21aSChristopher Smith[?/,&\#;:]         # no pattern - any other group of 'special' characters to insert a breaking character after
160307a7d21aSChristopher Smith)+                 # end conditional expression
1604fcfecb69SChristopher SmithREGEX;
1605fcfecb69SChristopher Smith
160654436b19Sbleistivt    return preg_replace('<'.$regex.'>xu','\0<wbr>',$match[0]);
1607fcfecb69SChristopher Smith}
1608fcfecb69SChristopher Smith
160915fae107Sandi/**
161015fae107Sandi * show warning on conflict detection
161115fae107Sandi *
161215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
161342ea7f44SGerrit Uitslag *
161442ea7f44SGerrit Uitslag * @param string $text
161542ea7f44SGerrit Uitslag * @param string $summary
161615fae107Sandi */
1617f3f0262cSandifunction html_conflict($text,$summary){
1618f3f0262cSandi    global $ID;
1619f3f0262cSandi    global $lang;
1620f3f0262cSandi
1621c112d578Sandi    print p_locale_xhtml('conflict');
1622e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
1623fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
1624fdb8d77bSTom N Harris    $form->addHidden('wikitext', $text);
1625fdb8d77bSTom N Harris    $form->addHidden('summary', $summary);
1626fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
1627fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
1628fdb8d77bSTom N Harris    html_form('conflict', $form);
1629fdb8d77bSTom N Harris    print '<br /><br /><br /><br />'.NL;
1630f3f0262cSandi}
1631f3f0262cSandi
1632f3f0262cSandi/**
163315fae107Sandi * Prints the global message array
163415fae107Sandi *
163515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1636f3f0262cSandi */
1637f3f0262cSandifunction html_msgarea(){
1638cc58224cSMichael Hamann    global $MSG, $MSG_shown;
16398d5e837eSMichael Hamann    /** @var array $MSG */
1640cc58224cSMichael Hamann    // store if the global $MSG has already been shown and thus HTML output has been started
1641cc58224cSMichael Hamann    $MSG_shown = true;
1642cc58224cSMichael Hamann
1643f3f0262cSandi    if(!isset($MSG)) return;
1644f3f0262cSandi
16454af9f0d4SAndreas Gohr    $shown = array();
1646f3f0262cSandi    foreach($MSG as $msg){
16474af9f0d4SAndreas Gohr        $hash = md5($msg['msg']);
16484af9f0d4SAndreas Gohr        if(isset($shown[$hash])) continue; // skip double messages
1649f755f9abSChristopher Smith        if(info_msg_allowed($msg)){
1650f3f0262cSandi            print '<div class="'.$msg['lvl'].'">';
1651f3f0262cSandi            print $msg['msg'];
1652f3f0262cSandi            print '</div>';
1653d3bae478SChristopher Smith        }
16544af9f0d4SAndreas Gohr        $shown[$hash] = 1;
1655f3f0262cSandi    }
1656cc58224cSMichael Hamann
1657cc58224cSMichael Hamann    unset($GLOBALS['MSG']);
1658f3f0262cSandi}
1659f3f0262cSandi
1660f3f0262cSandi/**
1661f3f0262cSandi * Prints the registration form
166215fae107Sandi *
166315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1664f3f0262cSandi */
1665f3f0262cSandifunction html_register(){
1666f3f0262cSandi    global $lang;
1667cab2716aSmatthias.grimm    global $conf;
1668f0859d4bSTom N Harris    global $INPUT;
1669f3f0262cSandi
1670a669bfe0SChristopher Smith    $base_attrs = array('size'=>50,'required'=>'required');
1671a669bfe0SChristopher Smith    $email_attrs = $base_attrs + array('type'=>'email','class'=>'edit');
1672a669bfe0SChristopher Smith
1673c112d578Sandi    print p_locale_xhtml('register');
1674fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1675e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__register'));
1676bf413a4eSAnika Henke    $form->startFieldset($lang['btn_register']);
1677fdb8d77bSTom N Harris    $form->addHidden('do', 'register');
1678fdb8d77bSTom N Harris    $form->addHidden('save', '1');
167964159a61SAndreas Gohr    $form->addElement(
168064159a61SAndreas Gohr        form_makeTextField(
168164159a61SAndreas Gohr            'login',
168264159a61SAndreas Gohr            $INPUT->post->str('login'),
168364159a61SAndreas Gohr            $lang['user'],
168464159a61SAndreas Gohr            '',
168564159a61SAndreas Gohr            'block',
168664159a61SAndreas Gohr            $base_attrs
168764159a61SAndreas Gohr        )
168864159a61SAndreas Gohr    );
1689cab2716aSmatthias.grimm    if (!$conf['autopasswd']) {
1690a669bfe0SChristopher Smith        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', $base_attrs));
1691a669bfe0SChristopher Smith        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', $base_attrs));
1692cab2716aSmatthias.grimm    }
169364159a61SAndreas Gohr    $form->addElement(
169464159a61SAndreas Gohr        form_makeTextField(
169564159a61SAndreas Gohr            'fullname',
169664159a61SAndreas Gohr            $INPUT->post->str('fullname'),
169764159a61SAndreas Gohr            $lang['fullname'],
169864159a61SAndreas Gohr            '',
169964159a61SAndreas Gohr            'block',
170064159a61SAndreas Gohr            $base_attrs
170164159a61SAndreas Gohr        )
170264159a61SAndreas Gohr    );
170364159a61SAndreas Gohr    $form->addElement(
170464159a61SAndreas Gohr        form_makeField(
170564159a61SAndreas Gohr            'email',
170664159a61SAndreas Gohr            'email',
170764159a61SAndreas Gohr            $INPUT->post->str('email'),
170864159a61SAndreas Gohr            $lang['email'],
170964159a61SAndreas Gohr            '',
171064159a61SAndreas Gohr            'block',
171164159a61SAndreas Gohr            $email_attrs
171264159a61SAndreas Gohr        )
171364159a61SAndreas Gohr    );
1714bf413a4eSAnika Henke    $form->addElement(form_makeButton('submit', '', $lang['btn_register']));
1715fdb8d77bSTom N Harris    $form->endFieldset();
1716fdb8d77bSTom N Harris    html_form('register', $form);
1717cab2716aSmatthias.grimm
1718fdb8d77bSTom N Harris    print '</div>'.NL;
1719f3f0262cSandi}
1720f3f0262cSandi
1721f3f0262cSandi/**
17228b06d178Schris * Print the update profile form
17238b06d178Schris *
17248b06d178Schris * @author Christopher Smith <chris@jalakai.co.uk>
17258b06d178Schris * @author Andreas Gohr <andi@splitbrain.org>
17268b06d178Schris */
17278b06d178Schrisfunction html_updateprofile(){
17288b06d178Schris    global $lang;
17298b06d178Schris    global $conf;
1730f0859d4bSTom N Harris    global $INPUT;
17318b06d178Schris    global $INFO;
1732e1d9dcc8SAndreas Gohr    /** @var AuthPlugin $auth */
173382fd59b6SAndreas Gohr    global $auth;
17348b06d178Schris
17358b06d178Schris    print p_locale_xhtml('updateprofile');
17363b1338ffSChristopher Smith    print '<div class="centeralign">'.NL;
17378b06d178Schris
1738f0859d4bSTom N Harris    $fullname = $INPUT->post->str('fullname', $INFO['userinfo']['name'], true);
1739f0859d4bSTom N Harris    $email = $INPUT->post->str('email', $INFO['userinfo']['mail'], true);
1740e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__register'));
1741fdb8d77bSTom N Harris    $form->startFieldset($lang['profile']);
1742fdb8d77bSTom N Harris    $form->addHidden('do', 'profile');
1743fdb8d77bSTom N Harris    $form->addHidden('save', '1');
174464159a61SAndreas Gohr    $form->addElement(
174564159a61SAndreas Gohr        form_makeTextField(
174664159a61SAndreas Gohr            'login',
174764159a61SAndreas Gohr            $_SERVER['REMOTE_USER'],
174864159a61SAndreas Gohr            $lang['user'],
174964159a61SAndreas Gohr            '',
175064159a61SAndreas Gohr            'block',
175164159a61SAndreas Gohr            array('size' => '50', 'disabled' => 'disabled')
175264159a61SAndreas Gohr        )
175364159a61SAndreas Gohr    );
1754fdb8d77bSTom N Harris    $attr = array('size'=>'50');
1755fdb8d77bSTom N Harris    if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1756f0859d4bSTom N Harris    $form->addElement(form_makeTextField('fullname', $fullname, $lang['fullname'], '', 'block', $attr));
17573b1338ffSChristopher Smith    $attr = array('size'=>'50', 'class'=>'edit');
175839ba8890SAndreas Gohr    if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
17593b1338ffSChristopher Smith    $form->addElement(form_makeField('email','email', $email, $lang['email'], '', 'block', $attr));
1760fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1761fdb8d77bSTom N Harris    if ($auth->canDo('modPass')) {
1762fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1763fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1764fdb8d77bSTom N Harris    }
1765fdb8d77bSTom N Harris    if ($conf['profileconfirm']) {
1766fdb8d77bSTom N Harris        $form->addElement(form_makeTag('br'));
176764159a61SAndreas Gohr        $form->addElement(
176864159a61SAndreas Gohr            form_makePasswordField(
176964159a61SAndreas Gohr                'oldpass',
177064159a61SAndreas Gohr                $lang['oldpass'],
177164159a61SAndreas Gohr                '',
177264159a61SAndreas Gohr                'block',
177364159a61SAndreas Gohr                array('size' => '50', 'required' => 'required')
177464159a61SAndreas Gohr            )
177564159a61SAndreas Gohr        );
1776fdb8d77bSTom N Harris    }
1777fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1778fdb8d77bSTom N Harris    $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
17793b1338ffSChristopher Smith
1780fdb8d77bSTom N Harris    $form->endFieldset();
1781fdb8d77bSTom N Harris    html_form('updateprofile', $form);
17822a7abf2dSChristopher Smith
17832a7abf2dSChristopher Smith    if ($auth->canDo('delUser') && actionOK('profile_delete')) {
17842a7abf2dSChristopher Smith        $form_profiledelete = new Doku_Form(array('id' => 'dw__profiledelete'));
17852a7abf2dSChristopher Smith        $form_profiledelete->startFieldset($lang['profdeleteuser']);
17862a7abf2dSChristopher Smith        $form_profiledelete->addHidden('do', 'profile_delete');
17872a7abf2dSChristopher Smith        $form_profiledelete->addHidden('delete', '1');
178864159a61SAndreas Gohr        $form_profiledelete->addElement(
178964159a61SAndreas Gohr            form_makeCheckboxField(
179064159a61SAndreas Gohr                'confirm_delete',
179164159a61SAndreas Gohr                '1',
179264159a61SAndreas Gohr                $lang['profconfdelete'],
179364159a61SAndreas Gohr                'dw__confirmdelete',
179464159a61SAndreas Gohr                '',
179564159a61SAndreas Gohr                array('required' => 'required')
179664159a61SAndreas Gohr            )
179764159a61SAndreas Gohr        );
17982a7abf2dSChristopher Smith        if ($conf['profileconfirm']) {
17992a7abf2dSChristopher Smith            $form_profiledelete->addElement(form_makeTag('br'));
180064159a61SAndreas Gohr            $form_profiledelete->addElement(
180164159a61SAndreas Gohr                form_makePasswordField(
180264159a61SAndreas Gohr                    'oldpass',
180364159a61SAndreas Gohr                    $lang['oldpass'],
180464159a61SAndreas Gohr                    '',
180564159a61SAndreas Gohr                    'block',
180664159a61SAndreas Gohr                    array('size' => '50', 'required' => 'required')
180764159a61SAndreas Gohr                )
180864159a61SAndreas Gohr            );
18092a7abf2dSChristopher Smith        }
18102a7abf2dSChristopher Smith        $form_profiledelete->addElement(form_makeButton('submit', '', $lang['btn_deleteuser']));
18112a7abf2dSChristopher Smith        $form_profiledelete->endFieldset();
18122a7abf2dSChristopher Smith
18132a7abf2dSChristopher Smith        html_form('profiledelete', $form_profiledelete);
18142a7abf2dSChristopher Smith    }
18152a7abf2dSChristopher Smith
1816fdb8d77bSTom N Harris    print '</div>'.NL;
18178b06d178Schris}
18188b06d178Schris
18198b06d178Schris/**
18207c4635c4SAdrian Lang * Preprocess edit form data
182115fae107Sandi *
182215fae107Sandi * @author   Andreas Gohr <andi@splitbrain.org>
18232ffea8f2SAdrian Lang *
18242ffea8f2SAdrian Lang * @triggers HTML_EDITFORM_OUTPUT
1825f3f0262cSandi */
18265a932e77SAdrian Langfunction html_edit(){
1827f0859d4bSTom N Harris    global $INPUT;
1828f3f0262cSandi    global $ID;
1829f3f0262cSandi    global $REV;
1830f3f0262cSandi    global $DATE;
1831f3f0262cSandi    global $PRE;
1832f3f0262cSandi    global $SUF;
1833f3f0262cSandi    global $INFO;
1834f3f0262cSandi    global $SUM;
1835f3f0262cSandi    global $lang;
1836f3f0262cSandi    global $conf;
183745a99335SAdrian Lang    global $TEXT;
1838f3f0262cSandi
1839f0859d4bSTom N Harris    if ($INPUT->has('changecheck')) {
1840f0859d4bSTom N Harris        $check = $INPUT->str('changecheck');
184145a99335SAdrian Lang    } elseif(!$INFO['exists']){
184245a99335SAdrian Lang        // $TEXT has been loaded from page template
184345a99335SAdrian Lang        $check = md5('');
18448fe3bb00STom N Harris    } else {
184545a99335SAdrian Lang        $check = md5($TEXT);
18468fe3bb00STom N Harris    }
184745a99335SAdrian Lang    $mod = md5($TEXT) !== $check;
1848f3f0262cSandi
184927eb9321SAnika Henke    $wr = $INFO['writable'] && !$INFO['locked'];
185045a99335SAdrian Lang    $include = 'edit';
1851f3f0262cSandi    if($wr){
1852ffde0ac9SAdrian Lang        if ($REV) $include = 'editrev';
1853f3f0262cSandi    }else{
1854409d7af7SAndreas Gohr        // check pseudo action 'source'
1855409d7af7SAndreas Gohr        if(!actionOK('source')){
1856409d7af7SAndreas Gohr            msg('Command disabled: source',-1);
1857409d7af7SAndreas Gohr            return;
1858409d7af7SAndreas Gohr        }
1859ffde0ac9SAdrian Lang        $include = 'read';
1860f3f0262cSandi    }
18617c4635c4SAdrian Lang
18627c4635c4SAdrian Lang    global $license;
186342c7abd6SAndreas Gohr
1864e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
1865fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
1866fdb8d77bSTom N Harris    $form->addHidden('rev', $REV);
1867fdb8d77bSTom N Harris    $form->addHidden('date', $DATE);
186842de51b1SAdrian Lang    $form->addHidden('prefix', $PRE . '.');
1869fdb8d77bSTom N Harris    $form->addHidden('suffix', $SUF);
1870fdb8d77bSTom N Harris    $form->addHidden('changecheck', $check);
18718e4da260SAdrian Lang
18722ffea8f2SAdrian Lang    $data = array('form' => $form,
18732ffea8f2SAdrian Lang                  'wr'   => $wr,
18742ffea8f2SAdrian Lang                  'media_manager' => true,
1875182ac905SAndreas Gohr                  'target' => ($INPUT->has('target') && $wr) ? $INPUT->str('target') : 'section',
18762ffea8f2SAdrian Lang                  'intro_locale' => $include);
187712c96aceSAdrian Lang
187812c96aceSAdrian Lang    if ($data['target'] !== 'section') {
187912c96aceSAdrian Lang        // Only emit event if page is writable, section edit data is valid and
188012c96aceSAdrian Lang        // edit target is not section.
1881cbb44eabSAndreas Gohr        Event::createAndTrigger('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true);
18822ffea8f2SAdrian Lang    } else {
18832ffea8f2SAdrian Lang        html_edit_form($data);
18842ffea8f2SAdrian Lang    }
1885ffde0ac9SAdrian Lang    if (isset($data['intro_locale'])) {
1886ffde0ac9SAdrian Lang        echo p_locale_xhtml($data['intro_locale']);
1887ffde0ac9SAdrian Lang    }
18888e4da260SAdrian Lang
1889b7eccc60SAdrian Lang    $form->addHidden('target', $data['target']);
18902571786cSLarsDW223    if ($INPUT->has('hid')) {
18912571786cSLarsDW223        $form->addHidden('hid', $INPUT->str('hid'));
18922571786cSLarsDW223    }
1893ec57f119SLarsDW223    if ($INPUT->has('codeblockOffset')) {
1894ec57f119SLarsDW223        $form->addHidden('codeblockOffset', $INPUT->str('codeblockOffset'));
1895ec57f119SLarsDW223    }
18960607bfeeSAnika Henke    $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar', 'class'=>'editBar')));
1897fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1898fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
1899fdb8d77bSTom N Harris    if ($wr) {
1900fdb8d77bSTom N Harris        $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
190164159a61SAndreas Gohr        $form->addElement(
190264159a61SAndreas Gohr            form_makeButton(
190364159a61SAndreas Gohr                'submit',
190464159a61SAndreas Gohr                'save',
190564159a61SAndreas Gohr                $lang['btn_save'],
190664159a61SAndreas Gohr                array('id' => 'edbtn__save', 'accesskey' => 's', 'tabindex' => '4')
190764159a61SAndreas Gohr            )
190864159a61SAndreas Gohr        );
190964159a61SAndreas Gohr        $form->addElement(
191064159a61SAndreas Gohr            form_makeButton(
191164159a61SAndreas Gohr                'submit',
191264159a61SAndreas Gohr                'preview',
191364159a61SAndreas Gohr                $lang['btn_preview'],
191464159a61SAndreas Gohr                array('id' => 'edbtn__preview', 'accesskey' => 'p', 'tabindex' => '5')
191564159a61SAndreas Gohr            )
191664159a61SAndreas Gohr        );
19173f5c3c1eSAndreas Gohr        $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel'], array('tabindex'=>'6')));
1918fdb8d77bSTom N Harris        $form->addElement(form_makeCloseTag('div'));
1919fdb8d77bSTom N Harris        $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
192064159a61SAndreas Gohr        $form->addElement(
192164159a61SAndreas Gohr            form_makeTextField(
192264159a61SAndreas Gohr                'summary',
192364159a61SAndreas Gohr                $SUM,
192464159a61SAndreas Gohr                $lang['summary'],
192564159a61SAndreas Gohr                'edit__summary',
192664159a61SAndreas Gohr                'nowrap',
192764159a61SAndreas Gohr                array('size' => '50', 'tabindex' => '2')
192864159a61SAndreas Gohr            )
192964159a61SAndreas Gohr        );
1930fdb8d77bSTom N Harris        $elem = html_minoredit();
1931fdb8d77bSTom N Harris        if ($elem) $form->addElement($elem);
1932fdb8d77bSTom N Harris        $form->addElement(form_makeCloseTag('div'));
1933fdb8d77bSTom N Harris    }
1934fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
19355808bc54SAndreas Gohr    if($wr && $conf['license']){
1936066fee30SAndreas Gohr        $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1937066fee30SAndreas Gohr        $out  = $lang['licenseok'];
1938066fee30SAndreas Gohr        $out .= ' <a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
1939507a2aebSAnika Henke        if($conf['target']['extern']) $out .= ' target="'.$conf['target']['extern'].'"';
1940066fee30SAndreas Gohr        $out .= '>'.$license[$conf['license']]['name'].'</a>';
1941066fee30SAndreas Gohr        $form->addElement($out);
1942066fee30SAndreas Gohr        $form->addElement(form_makeCloseTag('div'));
1943066fee30SAndreas Gohr    }
19448e4da260SAdrian Lang
19458e4da260SAdrian Lang    if ($wr) {
19468e4da260SAdrian Lang        // sets changed to true when previewed
194759305168SPhy        echo '<script>/*<![CDATA[*/'. NL;
19488e4da260SAdrian Lang        echo 'textChanged = ' . ($mod ? 'true' : 'false');
1949677d2785SDominik Eckelmann        echo '/*!]]>*/</script>' . NL;
19508e4da260SAdrian Lang    } ?>
19515a99d25bSAnika Henke    <div class="editBox" role="application">
19528e4da260SAdrian Lang
19538a65ef2eSAnika Henke    <div class="toolbar group">
195464159a61SAndreas Gohr        <div id="tool__bar" class="tool__bar"><?php
195564159a61SAndreas Gohr            if ($wr && $data['media_manager']){
195664159a61SAndreas Gohr                ?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
195764159a61SAndreas Gohr                target="_blank"><?php echo $lang['mediaselect'] ?></a><?php
19589ddafcedSAndreas Gohr            }?>
19599ddafcedSAndreas Gohr        </div>
1960c49e647bSMichael Große    </div>
19610aabe6f8SMichael Große    <div id="draft__status" class="draft__status">
19620aabe6f8SMichael Große        <?php
19630aabe6f8SMichael Große        $draft = new \dokuwiki\Draft($ID, $INFO['client']);
19640aabe6f8SMichael Große        if ($draft->isDraftAvailable()) {
19650aabe6f8SMichael Große            echo $draft->getDraftMessage();
19660aabe6f8SMichael Große        }
19670aabe6f8SMichael Große        ?>
19688e4da260SAdrian Lang    </div>
19698e4da260SAdrian Lang    <?php
19708e4da260SAdrian Lang
1971fdb8d77bSTom N Harris    html_form('edit', $form);
1972fdb8d77bSTom N Harris    print '</div>'.NL;
1973f3f0262cSandi}
1974f3f0262cSandi
1975f3f0262cSandi/**
19768e4da260SAdrian Lang * Display the default edit form
19778e4da260SAdrian Lang *
19788e4da260SAdrian Lang * Is the default action for HTML_EDIT_FORMSELECTION.
197942ea7f44SGerrit Uitslag *
1980baf0c3e5SGerrit Uitslag * @param mixed[] $param
19818e4da260SAdrian Lang */
19828e4da260SAdrian Langfunction html_edit_form($param) {
198345a99335SAdrian Lang    global $TEXT;
198412c96aceSAdrian Lang
198512c96aceSAdrian Lang    if ($param['target'] !== 'section') {
1986ff711734SAndreas Gohr        msg('No editor for edit target ' . hsc($param['target']) . ' found.', -1);
198712c96aceSAdrian Lang    }
198812c96aceSAdrian Lang
19898e4da260SAdrian Lang    $attr = array('tabindex'=>'1');
199012c96aceSAdrian Lang    if (!$param['wr']) $attr['readonly'] = 'readonly';
199112c96aceSAdrian Lang
199212c96aceSAdrian Lang    $param['form']->addElement(form_makeWikiText($TEXT, $attr));
19938e4da260SAdrian Lang}
19948e4da260SAdrian Lang
19958e4da260SAdrian Lang/**
1996b6912aeaSAndreas Gohr * Adds a checkbox for minor edits for logged in users
1997b6912aeaSAndreas Gohr *
1998b1f92db2SAdrian Lang * @author Andreas Gohr <andi@splitbrain.org>
199942ea7f44SGerrit Uitslag *
200042ea7f44SGerrit Uitslag * @return array|bool
2001b6912aeaSAndreas Gohr */
2002b6912aeaSAndreas Gohrfunction html_minoredit(){
2003b6912aeaSAndreas Gohr    global $conf;
2004b6912aeaSAndreas Gohr    global $lang;
2005f0859d4bSTom N Harris    global $INPUT;
2006b6912aeaSAndreas Gohr    // minor edits are for logged in users only
2007b6912aeaSAndreas Gohr    if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
2008fdb8d77bSTom N Harris        return false;
2009b6912aeaSAndreas Gohr    }
2010b6912aeaSAndreas Gohr
2011b6912aeaSAndreas Gohr    $p = array();
2012b6912aeaSAndreas Gohr    $p['tabindex'] = 3;
2013f0859d4bSTom N Harris    if($INPUT->bool('minor')) $p['checked']='checked';
2014fdb8d77bSTom N Harris    return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
2015b6912aeaSAndreas Gohr}
2016b6912aeaSAndreas Gohr
2017b6912aeaSAndreas Gohr/**
2018f3f0262cSandi * prints some debug info
201915fae107Sandi *
202015fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
2021f3f0262cSandi */
2022f3f0262cSandifunction html_debug(){
2023f3f0262cSandi    global $conf;
2024d16a4edaSandi    global $lang;
2025e1d9dcc8SAndreas Gohr    /** @var AuthPlugin $auth */
20265298a619SAndreas Gohr    global $auth;
2027100a97e3SAndreas Gohr    global $INFO;
2028100a97e3SAndreas Gohr
202928fb55ffSandi    //remove sensitive data
203028fb55ffSandi    $cnf = $conf;
203124297a69SAndreas Gohr    debug_guard($cnf);
2032100a97e3SAndreas Gohr    $nfo = $INFO;
203324297a69SAndreas Gohr    debug_guard($nfo);
2034100a97e3SAndreas Gohr    $ses = $_SESSION;
203524297a69SAndreas Gohr    debug_guard($ses);
2036f3f0262cSandi
2037f3f0262cSandi    print '<html><body>';
2038f3f0262cSandi
2039f3f0262cSandi    print '<p>When reporting bugs please send all the following ';
2040f3f0262cSandi    print 'output as a mail to andi@splitbrain.org ';
2041f3f0262cSandi    print 'The best way to do this is to save this page in your browser</p>';
2042f3f0262cSandi
2043100a97e3SAndreas Gohr    print '<b>$INFO:</b><pre>';
2044100a97e3SAndreas Gohr    print_r($nfo);
2045100a97e3SAndreas Gohr    print '</pre>';
2046100a97e3SAndreas Gohr
2047f3f0262cSandi    print '<b>$_SERVER:</b><pre>';
2048f3f0262cSandi    print_r($_SERVER);
2049f3f0262cSandi    print '</pre>';
2050f3f0262cSandi
2051f3f0262cSandi    print '<b>$conf:</b><pre>';
205228fb55ffSandi    print_r($cnf);
2053f3f0262cSandi    print '</pre>';
2054f3f0262cSandi
2055ed7b5f09Sandi    print '<b>DOKU_BASE:</b><pre>';
2056ed7b5f09Sandi    print DOKU_BASE;
2057f3f0262cSandi    print '</pre>';
2058f3f0262cSandi
2059ed7b5f09Sandi    print '<b>abs DOKU_BASE:</b><pre>';
2060ed7b5f09Sandi    print DOKU_URL;
2061ed7b5f09Sandi    print '</pre>';
2062ed7b5f09Sandi
2063ed7b5f09Sandi    print '<b>rel DOKU_BASE:</b><pre>';
2064f3f0262cSandi    print dirname($_SERVER['PHP_SELF']).'/';
2065f3f0262cSandi    print '</pre>';
2066f3f0262cSandi
2067f3f0262cSandi    print '<b>PHP Version:</b><pre>';
2068f3f0262cSandi    print phpversion();
2069f3f0262cSandi    print '</pre>';
2070f3f0262cSandi
2071f3f0262cSandi    print '<b>locale:</b><pre>';
2072f3f0262cSandi    print setlocale(LC_ALL,0);
2073f3f0262cSandi    print '</pre>';
2074f3f0262cSandi
2075d16a4edaSandi    print '<b>encoding:</b><pre>';
2076d16a4edaSandi    print $lang['encoding'];
2077d16a4edaSandi    print '</pre>';
2078d16a4edaSandi
20795298a619SAndreas Gohr    if($auth){
20805298a619SAndreas Gohr        print '<b>Auth backend capabilities:</b><pre>';
20812f46ade0SChristopher Smith        foreach ($auth->getCapabilities() as $cando){
20822f46ade0SChristopher Smith            print '   '.str_pad($cando,16) . ' => ' . (int)$auth->canDo($cando) . NL;
20832f46ade0SChristopher Smith        }
20845298a619SAndreas Gohr        print '</pre>';
20855298a619SAndreas Gohr    }
20865298a619SAndreas Gohr
20873aa54d7cSAndreas Gohr    print '<b>$_SESSION:</b><pre>';
2088100a97e3SAndreas Gohr    print_r($ses);
20893aa54d7cSAndreas Gohr    print '</pre>';
20903aa54d7cSAndreas Gohr
2091f3f0262cSandi    print '<b>Environment:</b><pre>';
2092f3f0262cSandi    print_r($_ENV);
2093f3f0262cSandi    print '</pre>';
2094f3f0262cSandi
2095f3f0262cSandi    print '<b>PHP settings:</b><pre>';
2096f3f0262cSandi    $inis = ini_get_all();
2097f3f0262cSandi    print_r($inis);
2098f3f0262cSandi    print '</pre>';
2099f3f0262cSandi
2100e89b7c1eSChristopher Smith    if (function_exists('apache_get_version')) {
210159bc3b48SGerrit Uitslag        $apache = array();
2102e89b7c1eSChristopher Smith        $apache['version'] = apache_get_version();
2103e89b7c1eSChristopher Smith
2104e89b7c1eSChristopher Smith        if (function_exists('apache_get_modules')) {
2105e89b7c1eSChristopher Smith            $apache['modules'] = apache_get_modules();
2106e89b7c1eSChristopher Smith        }
2107e89b7c1eSChristopher Smith        print '<b>Apache</b><pre>';
2108e89b7c1eSChristopher Smith        print_r($apache);
2109e89b7c1eSChristopher Smith        print '</pre>';
2110e89b7c1eSChristopher Smith    }
2111e89b7c1eSChristopher Smith
2112f3f0262cSandi    print '</body></html>';
2113f3f0262cSandi}
2114f3f0262cSandi
211510271ce4SAndreas Gohr/**
21168b06d178Schris * Form to request a new password for an existing account
21178b06d178Schris *
21188b06d178Schris * @author Benoit Chesneau <benoit@bchesneau.info>
2119cc204bbdSAndreas Gohr * @author Andreas Gohr <gohr@cosmocode.de>
212011e2ce22Schris */
21218b06d178Schrisfunction html_resendpwd() {
21228b06d178Schris    global $lang;
21238b06d178Schris    global $conf;
2124f0859d4bSTom N Harris    global $INPUT;
2125c19fe9c0Sandi
2126f0859d4bSTom N Harris    $token = preg_replace('/[^a-f0-9]+/','',$INPUT->str('pwauth'));
2127cc204bbdSAndreas Gohr
2128cc204bbdSAndreas Gohr    if(!$conf['autopasswd'] && $token){
2129cc204bbdSAndreas Gohr        print p_locale_xhtml('resetpwd');
2130cc204bbdSAndreas Gohr        print '<div class="centeralign">'.NL;
2131cc204bbdSAndreas Gohr        $form = new Doku_Form(array('id' => 'dw__resendpwd'));
2132cc204bbdSAndreas Gohr        $form->startFieldset($lang['btn_resendpwd']);
2133cc204bbdSAndreas Gohr        $form->addHidden('token', $token);
2134cc204bbdSAndreas Gohr        $form->addHidden('do', 'resendpwd');
2135cc204bbdSAndreas Gohr
2136cc204bbdSAndreas Gohr        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
2137cc204bbdSAndreas Gohr        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
2138cc204bbdSAndreas Gohr
2139cc204bbdSAndreas Gohr        $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
2140cc204bbdSAndreas Gohr        $form->endFieldset();
2141cc204bbdSAndreas Gohr        html_form('resendpwd', $form);
2142cc204bbdSAndreas Gohr        print '</div>'.NL;
2143cc204bbdSAndreas Gohr    }else{
21448b06d178Schris        print p_locale_xhtml('resendpwd');
2145fdb8d77bSTom N Harris        print '<div class="centeralign">'.NL;
2146e351c80dSAdrian Lang        $form = new Doku_Form(array('id' => 'dw__resendpwd'));
2147fdb8d77bSTom N Harris        $form->startFieldset($lang['resendpwd']);
2148fdb8d77bSTom N Harris        $form->addHidden('do', 'resendpwd');
2149fdb8d77bSTom N Harris        $form->addHidden('save', '1');
2150fdb8d77bSTom N Harris        $form->addElement(form_makeTag('br'));
2151f0859d4bSTom N Harris        $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block'));
2152fdb8d77bSTom N Harris        $form->addElement(form_makeTag('br'));
2153fdb8d77bSTom N Harris        $form->addElement(form_makeTag('br'));
2154fdb8d77bSTom N Harris        $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
2155fdb8d77bSTom N Harris        $form->endFieldset();
2156fdb8d77bSTom N Harris        html_form('resendpwd', $form);
2157fdb8d77bSTom N Harris        print '</div>'.NL;
2158fdb8d77bSTom N Harris    }
2159cc204bbdSAndreas Gohr}
2160cc204bbdSAndreas Gohr
2161fdb8d77bSTom N Harris/**
2162b8595a66SAndreas Gohr * Return the TOC rendered to XHTML
2163b8595a66SAndreas Gohr *
2164b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
216542ea7f44SGerrit Uitslag *
216642ea7f44SGerrit Uitslag * @param array $toc
216742ea7f44SGerrit Uitslag * @return string html
2168b8595a66SAndreas Gohr */
2169b8595a66SAndreas Gohrfunction html_TOC($toc){
2170b8595a66SAndreas Gohr    if(!count($toc)) return '';
2171b8595a66SAndreas Gohr    global $lang;
2172b8595a66SAndreas Gohr    $out  = '<!-- TOC START -->'.DOKU_LF;
2173158a5bffSDeathCamel57    $out .= '<div id="dw__toc" class="dw__toc">'.DOKU_LF;
217448722ac8SAnika Henke    $out .= '<h3 class="toggle">';
2175b8595a66SAndreas Gohr    $out .= $lang['toc'];
2176d5acc30dSAnika Henke    $out .= '</h3>'.DOKU_LF;
2177d5acc30dSAnika Henke    $out .= '<div>'.DOKU_LF;
217887671313SHakan Sandell    $out .= html_buildlist($toc,'toc','html_list_toc','html_li_default',true);
2179b8595a66SAndreas Gohr    $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
2180b8595a66SAndreas Gohr    $out .= '<!-- TOC END -->'.DOKU_LF;
2181db959ae3SAndreas Gohr    return $out;
2182db959ae3SAndreas Gohr}
2183b8595a66SAndreas Gohr
2184b8595a66SAndreas Gohr/**
2185b8595a66SAndreas Gohr * Callback for html_buildlist
218642ea7f44SGerrit Uitslag *
218742ea7f44SGerrit Uitslag * @param array $item
218842ea7f44SGerrit Uitslag * @return string html
2189b8595a66SAndreas Gohr */
2190b8595a66SAndreas Gohrfunction html_list_toc($item){
2191c66972f2SAdrian Lang    if(isset($item['hid'])){
21927d91652aSAndreas Gohr        $link = '#'.$item['hid'];
21937d91652aSAndreas Gohr    }else{
21947d91652aSAndreas Gohr        $link = $item['link'];
21957d91652aSAndreas Gohr    }
21967d91652aSAndreas Gohr
2197d5acc30dSAnika Henke    return '<a href="'.$link.'">'.hsc($item['title']).'</a>';
2198b8595a66SAndreas Gohr}
2199b8595a66SAndreas Gohr
2200b8595a66SAndreas Gohr/**
2201b8595a66SAndreas Gohr * Helper function to build TOC items
2202b8595a66SAndreas Gohr *
2203b8595a66SAndreas Gohr * Returns an array ready to be added to a TOC array
2204b8595a66SAndreas Gohr *
2205b8595a66SAndreas Gohr * @param string $link  - where to link (if $hash set to '#' it's a local anchor)
2206b8595a66SAndreas Gohr * @param string $text  - what to display in the TOC
2207b8595a66SAndreas Gohr * @param int    $level - nesting level
2208b8595a66SAndreas Gohr * @param string $hash  - is prepended to the given $link, set blank if you want full links
22098d5e837eSMichael Hamann * @return array the toc item
2210b8595a66SAndreas Gohr */
2211b8595a66SAndreas Gohrfunction html_mktocitem($link, $text, $level, $hash='#'){
2212b8595a66SAndreas Gohr    return  array( 'link'  => $hash.$link,
2213b8595a66SAndreas Gohr            'title' => $text,
2214b8595a66SAndreas Gohr            'type'  => 'ul',
22152bb0d541Schris            'level' => $level);
2216b8595a66SAndreas Gohr}
2217b8595a66SAndreas Gohr
2218b8595a66SAndreas Gohr/**
2219fdb8d77bSTom N Harris * Output a Doku_Form object.
2220fdb8d77bSTom N Harris * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
2221fdb8d77bSTom N Harris *
2222fdb8d77bSTom N Harris * @author Tom N Harris <tnharris@whoopdedo.org>
222342ea7f44SGerrit Uitslag *
22248d5e837eSMichael Hamann * @param string     $name The name of the form
22258d5e837eSMichael Hamann * @param Doku_Form  $form The form
2226fdb8d77bSTom N Harris */
2227fdb8d77bSTom N Harrisfunction html_form($name, &$form) {
2228fdb8d77bSTom N Harris    // Safety check in case the caller forgets.
2229fdb8d77bSTom N Harris    $form->endFieldset();
2230cbb44eabSAndreas Gohr    Event::createAndTrigger('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
2231fdb8d77bSTom N Harris}
2232fdb8d77bSTom N Harris
2233fdb8d77bSTom N Harris/**
2234fdb8d77bSTom N Harris * Form print function.
2235fdb8d77bSTom N Harris * Just calls printForm() on the data object.
223642ea7f44SGerrit Uitslag *
22378d5e837eSMichael Hamann * @param Doku_Form $data The form
2238fdb8d77bSTom N Harris */
2239fdb8d77bSTom N Harrisfunction html_form_output($data) {
2240fdb8d77bSTom N Harris    $data->printForm();
22418b06d178Schris}
2242340756e4Sandi
224307bf32b2SAndreas Gohr/**
224407bf32b2SAndreas Gohr * Embed a flash object in HTML
224507bf32b2SAndreas Gohr *
224607bf32b2SAndreas Gohr * This will create the needed HTML to embed a flash movie in a cross browser
224707bf32b2SAndreas Gohr * compatble way using valid XHTML
224807bf32b2SAndreas Gohr *
224907bf32b2SAndreas Gohr * The parameters $params, $flashvars and $atts need to be associative arrays.
225007bf32b2SAndreas Gohr * No escaping needs to be done for them. The alternative content *has* to be
225107bf32b2SAndreas Gohr * escaped because it is used as is. If no alternative content is given
225207bf32b2SAndreas Gohr * $lang['noflash'] is used.
225307bf32b2SAndreas Gohr *
225407bf32b2SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
225507bf32b2SAndreas Gohr * @link   http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
225607bf32b2SAndreas Gohr *
225707bf32b2SAndreas Gohr * @param string $swf      - the SWF movie to embed
225807bf32b2SAndreas Gohr * @param int $width       - width of the flash movie in pixels
225907bf32b2SAndreas Gohr * @param int $height      - height of the flash movie in pixels
226007bf32b2SAndreas Gohr * @param array $params    - additional parameters (<param>)
226107bf32b2SAndreas Gohr * @param array $flashvars - parameters to be passed in the flashvar parameter
226207bf32b2SAndreas Gohr * @param array $atts      - additional attributes for the <object> tag
226307bf32b2SAndreas Gohr * @param string $alt      - alternative content (is NOT automatically escaped!)
2264b3d1090eSMichael Hamann * @return string         - the XHTML markup
226507bf32b2SAndreas Gohr */
226607bf32b2SAndreas Gohrfunction html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
226707bf32b2SAndreas Gohr    global $lang;
226807bf32b2SAndreas Gohr
226907bf32b2SAndreas Gohr    $out = '';
227007bf32b2SAndreas Gohr
227107bf32b2SAndreas Gohr    // prepare the object attributes
227207bf32b2SAndreas Gohr    if(is_null($atts)) $atts = array();
227307bf32b2SAndreas Gohr    $atts['width']  = (int) $width;
2274d4c61e61SAndreas Gohr    $atts['height'] = (int) $height;
227507bf32b2SAndreas Gohr    if(!$atts['width'])  $atts['width']  = 425;
227607bf32b2SAndreas Gohr    if(!$atts['height']) $atts['height'] = 350;
227707bf32b2SAndreas Gohr
227807bf32b2SAndreas Gohr    // add object attributes for standard compliant browsers
227907bf32b2SAndreas Gohr    $std = $atts;
228007bf32b2SAndreas Gohr    $std['type'] = 'application/x-shockwave-flash';
228107bf32b2SAndreas Gohr    $std['data'] = $swf;
228207bf32b2SAndreas Gohr
228307bf32b2SAndreas Gohr    // add object attributes for IE
228407bf32b2SAndreas Gohr    $ie  = $atts;
228507bf32b2SAndreas Gohr    $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
228607bf32b2SAndreas Gohr
228707bf32b2SAndreas Gohr    // open object (with conditional comments)
228807bf32b2SAndreas Gohr    $out .= '<!--[if !IE]> -->'.NL;
228907bf32b2SAndreas Gohr    $out .= '<object '.buildAttributes($std).'>'.NL;
229007bf32b2SAndreas Gohr    $out .= '<!-- <![endif]-->'.NL;
229107bf32b2SAndreas Gohr    $out .= '<!--[if IE]>'.NL;
229207bf32b2SAndreas Gohr    $out .= '<object '.buildAttributes($ie).'>'.NL;
229307bf32b2SAndreas Gohr    $out .= '    <param name="movie" value="'.hsc($swf).'" />'.NL;
22949ae41cdcSAndreas Gohr    $out .= '<!--><!-- -->'.NL;
229507bf32b2SAndreas Gohr
229607bf32b2SAndreas Gohr    // print params
229707bf32b2SAndreas Gohr    if(is_array($params)) foreach($params as $key => $val){
229807bf32b2SAndreas Gohr        $out .= '  <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
229907bf32b2SAndreas Gohr    }
230007bf32b2SAndreas Gohr
230107bf32b2SAndreas Gohr    // add flashvars
230207bf32b2SAndreas Gohr    if(is_array($flashvars)){
2303d4c61e61SAndreas Gohr        $out .= '  <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
230407bf32b2SAndreas Gohr    }
230507bf32b2SAndreas Gohr
230607bf32b2SAndreas Gohr    // alternative content
230707bf32b2SAndreas Gohr    if($alt){
230807bf32b2SAndreas Gohr        $out .= $alt.NL;
230907bf32b2SAndreas Gohr    }else{
231007bf32b2SAndreas Gohr        $out .= $lang['noflash'].NL;
231107bf32b2SAndreas Gohr    }
231207bf32b2SAndreas Gohr
231307bf32b2SAndreas Gohr    // finish
231407bf32b2SAndreas Gohr    $out .= '</object>'.NL;
231507bf32b2SAndreas Gohr    $out .= '<!-- <![endif]-->'.NL;
231607bf32b2SAndreas Gohr
231707bf32b2SAndreas Gohr    return $out;
231807bf32b2SAndreas Gohr}
231907bf32b2SAndreas Gohr
23208d5e837eSMichael Hamann/**
23218d5e837eSMichael Hamann * Prints HTML code for the given tab structure
23228d5e837eSMichael Hamann *
23238d5e837eSMichael Hamann * @param array  $tabs        tab structure
23248d5e837eSMichael Hamann * @param string $current_tab the current tab id
23258d5e837eSMichael Hamann */
232695b451bcSAdrian Langfunction html_tabs($tabs, $current_tab = null) {
232794add303SAnika Henke    echo '<ul class="tabs">'.NL;
232895b451bcSAdrian Lang
232995b451bcSAdrian Lang    foreach($tabs as $id => $tab) {
233095b451bcSAdrian Lang        html_tab($tab['href'], $tab['caption'], $id === $current_tab);
233195b451bcSAdrian Lang    }
233295b451bcSAdrian Lang
233394add303SAnika Henke    echo '</ul>'.NL;
233495b451bcSAdrian Lang}
2335cd2a4cfdSAnika Henke
233695b451bcSAdrian Lang/**
233795b451bcSAdrian Lang * Prints a single tab
233895b451bcSAdrian Lang *
233995b451bcSAdrian Lang * @author Kate Arzamastseva <pshns@ukr.net>
234095b451bcSAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
234195b451bcSAdrian Lang *
234295b451bcSAdrian Lang * @param string $href - tab href
234395b451bcSAdrian Lang * @param string $caption - tab caption
234495b451bcSAdrian Lang * @param boolean $selected - is tab selected
234595b451bcSAdrian Lang */
234695b451bcSAdrian Lang
234795b451bcSAdrian Langfunction html_tab($href, $caption, $selected=false) {
234895b451bcSAdrian Lang    $tab = '<li>';
234995b451bcSAdrian Lang    if ($selected) {
235095b451bcSAdrian Lang        $tab .= '<strong>';
235195b451bcSAdrian Lang    } else {
235295b451bcSAdrian Lang        $tab .= '<a href="' . hsc($href) . '">';
235395b451bcSAdrian Lang    }
235495b451bcSAdrian Lang    $tab .= hsc($caption)
235595b451bcSAdrian Lang         .  '</' . ($selected ? 'strong' : 'a') . '>'
235694add303SAnika Henke         .  '</li>'.NL;
235795b451bcSAdrian Lang    echo $tab;
235895b451bcSAdrian Lang}
235995b451bcSAdrian Lang
2360cd2a4cfdSAnika Henke/**
2361cd2a4cfdSAnika Henke * Display size change
2362cd2a4cfdSAnika Henke *
2363cd2a4cfdSAnika Henke * @param int $sizechange - size of change in Bytes
2364cd2a4cfdSAnika Henke * @param Doku_Form $form - form to add elements to
2365cd2a4cfdSAnika Henke */
2366cd2a4cfdSAnika Henke
2367cd2a4cfdSAnika Henkefunction html_sizechange($sizechange, Doku_Form $form) {
2368cd2a4cfdSAnika Henke    if(isset($sizechange)) {
2369cd2a4cfdSAnika Henke        $class = 'sizechange';
2370cd2a4cfdSAnika Henke        $value = filesize_h(abs($sizechange));
2371cd2a4cfdSAnika Henke        if($sizechange > 0) {
2372cd2a4cfdSAnika Henke            $class .= ' positive';
2373cd2a4cfdSAnika Henke            $value = '+' . $value;
2374cd2a4cfdSAnika Henke        } elseif($sizechange < 0) {
2375cd2a4cfdSAnika Henke            $class .= ' negative';
2376cd2a4cfdSAnika Henke            $value = '-' . $value;
23770b78a6edSAnika Henke        } else {
23780b78a6edSAnika Henke            $value = '±' . $value;
2379cd2a4cfdSAnika Henke        }
2380cd2a4cfdSAnika Henke        $form->addElement(form_makeOpenTag('span', array('class' => $class)));
2381cd2a4cfdSAnika Henke        $form->addElement($value);
2382cd2a4cfdSAnika Henke        $form->addElement(form_makeCloseTag('span'));
2383cd2a4cfdSAnika Henke    }
2384cd2a4cfdSAnika Henke}
2385