xref: /dokuwiki/inc/html.php (revision aac83cd489f4efc0477170dd0ffac70c3c22fcd1)
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;
130c3a5702SAndreas Gohr
142d3b082eSMichael Großeif (!defined('SEC_EDIT_PATTERN')) {
1537c80e0eSLarsDW223    define('SEC_EDIT_PATTERN', '#<!-- EDIT({.*?}) -->#');
162d3b082eSMichael Große}
172d3b082eSMichael Große
186bbae538Sandi
19f3f0262cSandi/**
20f3f0262cSandi * Convenience function to quickly build a wikilink
2115fae107Sandi *
2215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
238d5e837eSMichael Hamann * @param string  $id      id of the target page
248d5e837eSMichael Hamann * @param string  $name    the name of the link, i.e. the text that is displayed
258d5e837eSMichael Hamann * @param string|array  $search  search string(s) that shall be highlighted in the target page
268d5e837eSMichael Hamann * @return string the HTML code of the link
27f3f0262cSandi */
28db959ae3SAndreas Gohrfunction html_wikilink($id,$name=null,$search=''){
29a8397511SGerrit Uitslag    /** @var Doku_Renderer_xhtml $xhtml_renderer */
30db959ae3SAndreas Gohr    static $xhtml_renderer = null;
31723d78dbSandi    if(is_null($xhtml_renderer)){
327aea91afSChris Smith        $xhtml_renderer = p_get_renderer('xhtml');
33f3f0262cSandi    }
34f3f0262cSandi
35fe9ec250SChris Smith    return $xhtml_renderer->internallink($id,$name,$search,true,'navigation');
36f3f0262cSandi}
37f3f0262cSandi
38f3f0262cSandi/**
39f3f0262cSandi * The loginform
4015fae107Sandi *
4115fae107Sandi * @author   Andreas Gohr <andi@splitbrain.org>
42d1d904bbSMichael Große *
43d1d904bbSMichael Große * @param bool $svg Whether to show svg icons in the register and resendpwd links or not
44f3f0262cSandi */
45d1d904bbSMichael Großefunction html_login($svg = false){
46f3f0262cSandi    global $lang;
47f3f0262cSandi    global $conf;
48f3f0262cSandi    global $ID;
49f0859d4bSTom N Harris    global $INPUT;
50f3f0262cSandi
51c112d578Sandi    print p_locale_xhtml('login');
52fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
533f552e56SAndreas Gohr    $form = new Doku_Form(array('id' => 'dw__login', 'action'=>wl($ID)));
54fdb8d77bSTom N Harris    $form->startFieldset($lang['btn_login']);
55fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
56fdb8d77bSTom N Harris    $form->addHidden('do', 'login');
5764159a61SAndreas Gohr    $form->addElement(form_makeTextField(
5864159a61SAndreas Gohr        'u',
5964159a61SAndreas Gohr        ((!$INPUT->bool('http_credentials')) ? $INPUT->str('u') : ''),
6064159a61SAndreas Gohr        $lang['user'],
6164159a61SAndreas Gohr        'focus__this',
6264159a61SAndreas Gohr        'block')
6364159a61SAndreas Gohr    );
64fdb8d77bSTom N Harris    $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block'));
6517f89d7eSMichael Klier    if($conf['rememberme']) {
66fdb8d77bSTom N Harris        $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple'));
6717f89d7eSMichael Klier    }
68fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['btn_login']));
69fdb8d77bSTom N Harris    $form->endFieldset();
705b62573aSAndreas Gohr
71de4d479aSAdrian Lang    if(actionOK('register')){
72d1d904bbSMichael Große        $registerLink = (new \dokuwiki\Menu\Item\Register())->asHtmlLink('', $svg);
73d1d904bbSMichael Große        $form->addElement('<p>'.$lang['reghere'].': '. $registerLink .'</p>');
74f3f0262cSandi    }
758b06d178Schris
76de4d479aSAdrian Lang    if (actionOK('resendpwd')) {
77d1d904bbSMichael Große        $resendPwLink = (new \dokuwiki\Menu\Item\Resendpwd())->asHtmlLink('', $svg);
78d1d904bbSMichael Große        $form->addElement('<p>'.$lang['pwdforget'].': '. $resendPwLink .'</p>');
798b06d178Schris    }
8076ec5467SMichael Klier
8176ec5467SMichael Klier    html_form('login', $form);
82fdb8d77bSTom N Harris    print '</div>'.NL;
83f3f0262cSandi}
84f3f0262cSandi
85d59dea9fSGerrit Uitslag
86d59dea9fSGerrit Uitslag/**
87d59dea9fSGerrit Uitslag * Denied page content
88d59dea9fSGerrit Uitslag *
89d59dea9fSGerrit Uitslag * @return string html
90d59dea9fSGerrit Uitslag */
91d59dea9fSGerrit Uitslagfunction html_denied() {
92d1e9181eSGerrit Uitslag    print p_locale_xhtml('denied');
93f019ab46SGerrit Uitslag
940db7a50dSThammi    if(empty($_SERVER['REMOTE_USER']) && actionOK('login')){
95f019ab46SGerrit Uitslag        html_login();
96f019ab46SGerrit Uitslag    }
97d59dea9fSGerrit Uitslag}
98d59dea9fSGerrit Uitslag
99f3f0262cSandi/**
10015fae107Sandi * inserts section edit buttons if wanted or removes the markers
10115fae107Sandi *
10215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
10342ea7f44SGerrit Uitslag *
10442ea7f44SGerrit Uitslag * @param string $text
10542ea7f44SGerrit Uitslag * @param bool   $show show section edit buttons?
10642ea7f44SGerrit Uitslag * @return string
10715fae107Sandi */
108f3f0262cSandifunction html_secedit($text,$show=true){
109f3f0262cSandi    global $INFO;
11035dae8b0SBen Coburn
111*aac83cd4SPhy    if((isset($INFO) && !$INFO['writable']) || !$show || (isset($INFO) && $INFO['rev'])){
1122d3b082eSMichael Große        return preg_replace(SEC_EDIT_PATTERN,'',$text);
113f3f0262cSandi    }
11435dae8b0SBen Coburn
1152d3b082eSMichael Große    return preg_replace_callback(SEC_EDIT_PATTERN,
11640868f2fSAdrian Lang                'html_secedit_button', $text);
11740868f2fSAdrian Lang}
11840868f2fSAdrian Lang
11940868f2fSAdrian Lang/**
12040868f2fSAdrian Lang * prepares section edit button data for event triggering
12140868f2fSAdrian Lang * used as a callback in html_secedit
12240868f2fSAdrian Lang *
12340868f2fSAdrian Lang * @author Andreas Gohr <andi@splitbrain.org>
12442ea7f44SGerrit Uitslag *
12542ea7f44SGerrit Uitslag * @param array $matches matches with regexp
12642ea7f44SGerrit Uitslag * @return string
12742ea7f44SGerrit Uitslag * @triggers HTML_SECEDIT_BUTTON
12840868f2fSAdrian Lang */
12940868f2fSAdrian Langfunction html_secedit_button($matches){
130ada0d779SMichael Hamann    $json = htmlspecialchars_decode($matches[1], ENT_QUOTES);
131ada0d779SMichael Hamann    $data = json_decode($json, true);
132ec57f119SLarsDW223    if ($data == NULL) {
133ec57f119SLarsDW223        return;
13406917fceSMichael Große    }
135ec57f119SLarsDW223    $data ['target'] = strtolower($data['target']);
136ec57f119SLarsDW223    $data ['hid'] = strtolower($data['hid']);
13740868f2fSAdrian Lang
138cbb44eabSAndreas Gohr    return Event::createAndTrigger('HTML_SECEDIT_BUTTON', $data,
13940868f2fSAdrian Lang                         'html_secedit_get_button');
14040868f2fSAdrian Lang}
14140868f2fSAdrian Lang
14240868f2fSAdrian Lang/**
14340868f2fSAdrian Lang * prints a section editing button
14440868f2fSAdrian Lang * used as default action form HTML_SECEDIT_BUTTON
14540868f2fSAdrian Lang *
14640868f2fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de>
14742ea7f44SGerrit Uitslag *
14842ea7f44SGerrit Uitslag * @param array $data name, section id and target
14942ea7f44SGerrit Uitslag * @return string html
15040868f2fSAdrian Lang */
15140868f2fSAdrian Langfunction html_secedit_get_button($data) {
15240868f2fSAdrian Lang    global $ID;
15340868f2fSAdrian Lang    global $INFO;
15440868f2fSAdrian Lang
1556d9eab4dSMichael Hamann    if (!isset($data['name']) || $data['name'] === '') return '';
15640868f2fSAdrian Lang
15740868f2fSAdrian Lang    $name = $data['name'];
15840868f2fSAdrian Lang    unset($data['name']);
15940868f2fSAdrian Lang
160905fa971SAdrian Lang    $secid = $data['secid'];
161905fa971SAdrian Lang    unset($data['secid']);
162905fa971SAdrian Lang
16340868f2fSAdrian Lang    return "<div class='secedit editbutton_" . $data['target'] .
164defa93a1SAdrian Lang                       " editbutton_" . $secid . "'>" .
16540868f2fSAdrian Lang           html_btn('secedit', $ID, '',
16640868f2fSAdrian Lang                    array_merge(array('do'  => 'edit',
167b150cd2cSGina Haeussge                                      'rev' => $INFO['lastmod'],
168b150cd2cSGina Haeussge                                      'summary' => '['.$name.'] '), $data),
16940868f2fSAdrian Lang                    'post', $name) . '</div>';
170f3f0262cSandi}
171f3f0262cSandi
172f3f0262cSandi/**
173d6c9c552Smatthiasgrimm * Just the back to top button (in its own form)
1746b13307fSandi *
1756b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
17642ea7f44SGerrit Uitslag *
17742ea7f44SGerrit Uitslag * @return string html
1786b13307fSandi */
1796b13307fSandifunction html_topbtn(){
1806b13307fSandi    global $lang;
1816b13307fSandi
18264159a61SAndreas Gohr    $ret = '<a class="nolink" href="#dokuwiki__top">' .
18364159a61SAndreas Gohr        '<button class="button" onclick="window.scrollTo(0, 0)" title="' . $lang['btn_top'] . '">' .
18464159a61SAndreas Gohr        $lang['btn_top'] .
18564159a61SAndreas Gohr        '</button></a>';
186df7b6005Sandi
1876b13307fSandi    return $ret;
1886b13307fSandi}
1896b13307fSandi
1906b13307fSandi/**
191d67ca2c0Smatthiasgrimm * Displays a button (using its own form)
19235dae8b0SBen Coburn * If tooltip exists, the access key tooltip is replaced.
19315fae107Sandi *
19415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
19542ea7f44SGerrit Uitslag *
19642ea7f44SGerrit Uitslag * @param string         $name
19742ea7f44SGerrit Uitslag * @param string         $id
19842ea7f44SGerrit Uitslag * @param string         $akey   access key
199e3710957SGerrit Uitslag * @param string[] $params key-value pairs added as hidden inputs
20042ea7f44SGerrit Uitslag * @param string         $method
20142ea7f44SGerrit Uitslag * @param string         $tooltip
20242ea7f44SGerrit Uitslag * @param bool|string    $label  label text, false: lookup btn_$name in localization
203e824d633SMichael Große * @param string         $svg (optional) svg code, inserted into the button
20442ea7f44SGerrit Uitslag * @return string
205f3f0262cSandi */
206e824d633SMichael Großefunction html_btn($name, $id, $akey, $params, $method='get', $tooltip='', $label=false, $svg=null){
207f3f0262cSandi    global $conf;
208f3f0262cSandi    global $lang;
209f3f0262cSandi
210f5baf821SAnika Henke    if (!$label)
211f3f0262cSandi        $label = $lang['btn_'.$name];
212f3f0262cSandi
213f3f0262cSandi    $ret = '';
214f3f0262cSandi
21549c713a3Sandi    //filter id (without urlencoding)
21649c713a3Sandi    $id = idfilter($id,false);
217f3f0262cSandi
218f3f0262cSandi    //make nice URLs even for buttons
2196c7843b5Sandi    if($conf['userewrite'] == 2){
2206c7843b5Sandi        $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
2216c7843b5Sandi    }elseif($conf['userewrite']){
2226c7843b5Sandi        $script = DOKU_BASE.$id;
2236c7843b5Sandi    }else{
2248b00ebcfSandi        $script = DOKU_BASE.DOKU_SCRIPT;
225f3f0262cSandi        $params['id'] = $id;
226f3f0262cSandi    }
227f3f0262cSandi
228b278f2deSAndreas Gohr    $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
229f3f0262cSandi
23006a4bf8fSAndreas Gohr    if(is_array($params)){
2319e491c01SAndreas Gohr        foreach($params as $key => $val) {
232f3f0262cSandi            $ret .= '<input type="hidden" name="'.$key.'" ';
23365cc1598SPhy            $ret .= 'value="'.hsc($val).'" />';
234f3f0262cSandi        }
23506a4bf8fSAndreas Gohr    }
236f3f0262cSandi
23735dae8b0SBen Coburn    if ($tooltip!='') {
23865cc1598SPhy        $tip = hsc($tooltip);
23911ea018fSAndreas Gohr    }else{
24065cc1598SPhy        $tip = hsc($label);
24111ea018fSAndreas Gohr    }
24211ea018fSAndreas Gohr
243ae614416SAnika Henke    $ret .= '<button type="submit" ';
24411ea018fSAndreas Gohr    if($akey){
24507493d05SAnika Henke        $tip .= ' ['.strtoupper($akey).']';
24687cb01b7SAnika Henke        $ret .= 'accesskey="'.$akey.'" ';
24735dae8b0SBen Coburn    }
2489c65e2a9SAndreas Gohr    $ret .= 'title="'.$tip.'">';
249e824d633SMichael Große    if ($svg) {
250679dba01SMichael Große        $ret .= '<span>' . hsc($label) . '</span>';
251e824d633SMichael Große        $ret .= inlineSVG($svg);
252679dba01SMichael Große    } else {
253ae614416SAnika Henke        $ret .= hsc($label);
254679dba01SMichael Große    }
255ae614416SAnika Henke    $ret .= '</button>';
2564beabca9SAnika Henke    $ret .= '</div></form>';
257f3f0262cSandi
258f3f0262cSandi    return $ret;
259f3f0262cSandi}
2600747f5d7Sghi/**
2610747f5d7Sghi * show a revision warning
2620747f5d7Sghi *
2630747f5d7Sghi * @author Szymon Olewniczak <dokuwiki@imz.re>
2640747f5d7Sghi */
265c8556525Sghifunction html_showrev() {
266c8556525Sghi    print p_locale_xhtml('showrev');
2670747f5d7Sghi}
268f3f0262cSandi
269f3f0262cSandi/**
27042ea7f44SGerrit Uitslag * Show a wiki page
27115fae107Sandi *
27215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
27342ea7f44SGerrit Uitslag *
27442ea7f44SGerrit Uitslag * @param null|string $txt wiki text or null for showing $ID
27515fae107Sandi */
27611c78c94SAndreas Gohrfunction html_show($txt=null){
277f3f0262cSandi    global $ID;
278f3f0262cSandi    global $REV;
279f3f0262cSandi    global $HIGH;
280b8595a66SAndreas Gohr    global $INFO;
2815c2eed9aSlisps    global $DATE_AT;
282f3f0262cSandi    //disable section editing for old revisions or in preview
2835400331dSandi    if($txt || $REV){
2846bbae538Sandi        $secedit = false;
2856bbae538Sandi    }else{
2866bbae538Sandi        $secedit = true;
287f3f0262cSandi    }
288f3f0262cSandi
28911c78c94SAndreas Gohr    if (!is_null($txt)){
290f3f0262cSandi        //PreviewHeader
291e0959e88SDeathCamel57        echo '<br id="scroll__here" />';
292b8595a66SAndreas Gohr        echo p_locale_xhtml('preview');
293fc8dc822SAnika Henke        echo '<div class="preview"><div class="pad">';
294b8595a66SAndreas Gohr        $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
295b8595a66SAndreas Gohr        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
296b8595a66SAndreas Gohr        echo $html;
297b8595a66SAndreas Gohr        echo '<div class="clearer"></div>';
298fc8dc822SAnika Henke        echo '</div></div>';
2996bbae538Sandi
300f3f0262cSandi    }else{
3010747f5d7Sghi        if ($REV||$DATE_AT){
302c8556525Sghi            $data = array('rev' => &$REV, 'date_at' => &$DATE_AT);
303cbb44eabSAndreas Gohr            Event::createAndTrigger('HTML_SHOWREV_OUTPUT', $data, 'html_showrev');
3040747f5d7Sghi        }
3055c2eed9aSlisps        $html = p_wiki_xhtml($ID,$REV,true,$DATE_AT);
3066bbae538Sandi        $html = html_secedit($html,$secedit);
307b8595a66SAndreas Gohr        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
308b8595a66SAndreas Gohr        $html = html_hilight($html,$HIGH);
309b8595a66SAndreas Gohr        echo $html;
310f3f0262cSandi    }
311f3f0262cSandi}
312f3f0262cSandi
313f3f0262cSandi/**
314ee4c4a1bSAndreas Gohr * ask the user about how to handle an exisiting draft
315ee4c4a1bSAndreas Gohr *
316ee4c4a1bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
317ee4c4a1bSAndreas Gohr */
318ee4c4a1bSAndreas Gohrfunction html_draft(){
319ee4c4a1bSAndreas Gohr    global $INFO;
320ee4c4a1bSAndreas Gohr    global $ID;
321ee4c4a1bSAndreas Gohr    global $lang;
3220aabe6f8SMichael Große    $draft = new \dokuwiki\Draft($ID, $INFO['client']);
3230aabe6f8SMichael Große    $text  = $draft->getDraftText();
324ee4c4a1bSAndreas Gohr
325fdb8d77bSTom N Harris    print p_locale_xhtml('draft');
32637816f76SLukas Rademacher    html_diff($text, false);
327e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
328fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
329520438b3SMichael Große    $form->addHidden('date', $draft->getDraftDate());
3301362c8afSAndreas Gohr    $form->addHidden('wikitext', $text);
331fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
332520438b3SMichael Große    $form->addElement($draft->getDraftMessage());
333fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
334fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
335fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
336fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3')));
337fdb8d77bSTom N Harris    html_form('draft', $form);
338ee4c4a1bSAndreas Gohr}
339ee4c4a1bSAndreas Gohr
340ee4c4a1bSAndreas Gohr/**
341f3f0262cSandi * Highlights searchqueries in HTML code
34215fae107Sandi *
34315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
3447209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
34542ea7f44SGerrit Uitslag *
34642ea7f44SGerrit Uitslag * @param string $html
34742ea7f44SGerrit Uitslag * @param array|string $phrases
34842ea7f44SGerrit Uitslag * @return string html
349f3f0262cSandi */
350546d3a99SAndreas Gohrfunction html_hilight($html,$phrases){
3518a803caeSAndreas Gohr    $phrases = (array) $phrases;
3528a803caeSAndreas Gohr    $phrases = array_map('preg_quote_cb', $phrases);
3538a803caeSAndreas Gohr    $phrases = array_map('ft_snippet_re_preprocess', $phrases);
3548a803caeSAndreas Gohr    $phrases = array_filter($phrases);
3558a803caeSAndreas Gohr    $regex = join('|',$phrases);
35660c15d7dSAndreas Gohr
35760c15d7dSAndreas Gohr    if ($regex === '') return $html;
3588cbc5ee8SAndreas Gohr    if (!\dokuwiki\Utf8\Clean::isUtf8($regex)) return $html;
35924a6c235SAndreas Gohr    $html = @preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
360f3f0262cSandi    return $html;
361f3f0262cSandi}
362f3f0262cSandi
363f3f0262cSandi/**
3647209be23SAndreas Gohr * Callback used by html_hilight()
3657209be23SAndreas Gohr *
3667209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
36742ea7f44SGerrit Uitslag *
36842ea7f44SGerrit Uitslag * @param array $m matches
36942ea7f44SGerrit Uitslag * @return string html
3707209be23SAndreas Gohr */
3717209be23SAndreas Gohrfunction html_hilight_callback($m) {
3727209be23SAndreas Gohr    $hlight = unslash($m[0]);
3737209be23SAndreas Gohr    if ( !isset($m[2])) {
374688774a0SAnika Henke        $hlight = '<span class="search_hit">'.$hlight.'</span>';
3757209be23SAndreas Gohr    }
3767209be23SAndreas Gohr    return $hlight;
3777209be23SAndreas Gohr}
3787209be23SAndreas Gohr
3797209be23SAndreas Gohr/**
38015fae107Sandi * Display error on locked pages
38115fae107Sandi *
38215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
38315fae107Sandi */
384ee20e7d1Sandifunction html_locked(){
385f3f0262cSandi    global $ID;
386f3f0262cSandi    global $conf;
387f3f0262cSandi    global $lang;
38888f522e9Sandi    global $INFO;
389f3f0262cSandi
390c9b4bd1eSBen Coburn    $locktime = filemtime(wikiLockFN($ID));
391f2263577SAndreas Gohr    $expire = dformat($locktime + $conf['locktime']);
392f3f0262cSandi    $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
393f3f0262cSandi
394c112d578Sandi    print p_locale_xhtml('locked');
395f3f0262cSandi    print '<ul>';
396fde860beSGerrit Uitslag    print '<li><div class="li"><strong>'.$lang['lockedby'].'</strong> '.editorinfo($INFO['locked']).'</div></li>';
397fde860beSGerrit Uitslag    print '<li><div class="li"><strong>'.$lang['lockexpire'].'</strong> '.$expire.' ('.$min.' min)</div></li>';
398f3f0262cSandi    print '</ul>';
399f3f0262cSandi}
400f3f0262cSandi
40115fae107Sandi/**
40215fae107Sandi * list old revisions
40315fae107Sandi *
40415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
40571726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
4068e69fd30SKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
407e0c26282SGerrit Uitslag *
408e0c26282SGerrit Uitslag * @param int $first skip the first n changelog lines
409e0c26282SGerrit Uitslag * @param bool|string $media_id id of media, or false for current page
41015fae107Sandi */
4118e69fd30SKate Arzamastsevafunction html_revisions($first=0, $media_id = false){
412f3f0262cSandi    global $ID;
413f3f0262cSandi    global $INFO;
414f3f0262cSandi    global $conf;
415f3f0262cSandi    global $lang;
4168e69fd30SKate Arzamastseva    $id = $ID;
417047bad06SGerrit Uitslag    if ($media_id) {
418047bad06SGerrit Uitslag        $id = $media_id;
419047bad06SGerrit Uitslag        $changelog = new MediaChangeLog($id);
420047bad06SGerrit Uitslag    } else {
421047bad06SGerrit Uitslag        $changelog = new PageChangeLog($id);
422047bad06SGerrit Uitslag    }
423f523c971SGerrit Uitslag
42461e0b2f8SChristopher Smith    /* we need to get one additional log entry to be able to
42571726d78SBen Coburn     * decide if this is the last page or is there another one.
42671726d78SBen Coburn     * see html_recent()
42771726d78SBen Coburn     */
428047bad06SGerrit Uitslag
429047bad06SGerrit Uitslag    $revisions = $changelog->getRevisions($first, $conf['recent']+1);
4308e69fd30SKate Arzamastseva
43171726d78SBen Coburn    if(count($revisions)==0 && $first!=0){
43271726d78SBen Coburn        $first=0;
433047bad06SGerrit Uitslag        $revisions = $changelog->getRevisions($first, $conf['recent']+1);
43471726d78SBen Coburn    }
43571726d78SBen Coburn    $hasNext = false;
43671726d78SBen Coburn    if (count($revisions)>$conf['recent']) {
43771726d78SBen Coburn        $hasNext = true;
43871726d78SBen Coburn        array_pop($revisions); // remove extra log entry
43971726d78SBen Coburn    }
44071726d78SBen Coburn
4418e69fd30SKate Arzamastseva    if (!$media_id) print p_locale_xhtml('revisions');
44237a1dc12Smichael
4430607bfeeSAnika Henke    $params = array('id' => 'page__revisions', 'class' => 'changes');
444551be3f9SGerrit Uitslag    if($media_id) {
445551be3f9SGerrit Uitslag        $params['action'] = media_managerURL(array('image' => $media_id), '&');
446551be3f9SGerrit Uitslag    }
447551be3f9SGerrit Uitslag
448551be3f9SGerrit Uitslag    if(!$media_id) {
449551be3f9SGerrit Uitslag        $exists = $INFO['exists'];
450551be3f9SGerrit Uitslag        $display_name = useHeading('navigation') ? hsc(p_get_first_heading($id)) : $id;
451551be3f9SGerrit Uitslag        if(!$display_name) {
452551be3f9SGerrit Uitslag            $display_name = $id;
453551be3f9SGerrit Uitslag        }
454551be3f9SGerrit Uitslag    } else {
455551be3f9SGerrit Uitslag        $exists = file_exists(mediaFN($id));
456551be3f9SGerrit Uitslag        $display_name = $id;
457551be3f9SGerrit Uitslag    }
4587d7ab775SKate Arzamastseva
4597d7ab775SKate Arzamastseva    $form = new Doku_Form($params);
46037a1dc12Smichael    $form->addElement(form_makeOpenTag('ul'));
4618e69fd30SKate Arzamastseva
4628e69fd30SKate Arzamastseva    if($exists && $first == 0) {
463551be3f9SGerrit Uitslag        $minor = false;
464551be3f9SGerrit Uitslag        if($media_id) {
465551be3f9SGerrit Uitslag            $date = dformat(@filemtime(mediaFN($id)));
466551be3f9SGerrit Uitslag            $href = media_managerURL(array('image' => $id, 'tab_details' => 'view'), '&');
467551be3f9SGerrit Uitslag
468551be3f9SGerrit Uitslag            $changelog->setChunkSize(1024);
469551be3f9SGerrit Uitslag            $revinfo = $changelog->getRevisionInfo(@filemtime(fullpath(mediaFN($id))));
470551be3f9SGerrit Uitslag
471551be3f9SGerrit Uitslag            $summary = $revinfo['sum'];
472551be3f9SGerrit Uitslag            if($revinfo['user']) {
473551be3f9SGerrit Uitslag                $editor = $revinfo['user'];
474551be3f9SGerrit Uitslag            } else {
475551be3f9SGerrit Uitslag                $editor = $revinfo['ip'];
476551be3f9SGerrit Uitslag            }
477551be3f9SGerrit Uitslag            $sizechange = $revinfo['sizechange'];
478551be3f9SGerrit Uitslag        } else {
479551be3f9SGerrit Uitslag            $date = dformat($INFO['lastmod']);
480551be3f9SGerrit Uitslag            if(isset($INFO['meta']) && isset($INFO['meta']['last_change'])) {
481551be3f9SGerrit Uitslag                if($INFO['meta']['last_change']['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) {
482551be3f9SGerrit Uitslag                    $minor = true;
483551be3f9SGerrit Uitslag                }
484551be3f9SGerrit Uitslag                if(isset($INFO['meta']['last_change']['sizechange'])) {
485551be3f9SGerrit Uitslag                    $sizechange = $INFO['meta']['last_change']['sizechange'];
486551be3f9SGerrit Uitslag                } else {
487551be3f9SGerrit Uitslag                    $sizechange = null;
488551be3f9SGerrit Uitslag                }
489551be3f9SGerrit Uitslag            }
490fe101f30SMetin Güler            $pagelog = new PageChangeLog($ID);
49170635395SAndreas Gohr            $latestrev = $pagelog->getRevisions(-1, 1);
49270635395SAndreas Gohr            $latestrev = array_pop($latestrev);
493fe101f30SMetin Güler            $href = wl($id,"rev=$latestrev",false,'&');
494551be3f9SGerrit Uitslag            $summary = $INFO['sum'];
495551be3f9SGerrit Uitslag            $editor = $INFO['editor'];
496551be3f9SGerrit Uitslag        }
497551be3f9SGerrit Uitslag
498551be3f9SGerrit Uitslag        $form->addElement(form_makeOpenTag('li', array('class' => ($minor ? 'minor' : ''))));
49937a1dc12Smichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
50037a1dc12Smichael        $form->addElement(form_makeTag('input', array(
50137a1dc12Smichael                        'type' => 'checkbox',
50237a1dc12Smichael                        'name' => 'rev2[]',
50337a1dc12Smichael                        'value' => 'current')));
504f9b2fe70Sandi
50537a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
50637a1dc12Smichael        $form->addElement($date);
50737a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
508f9b2fe70Sandi
509c2e73886SAnika Henke        $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
510cffcc403Sandi
51137a1dc12Smichael        $form->addElement(form_makeOpenTag('a', array(
51237a1dc12Smichael                        'class' => 'wikilink1',
513dad6764eSKate Arzamastseva                        'href'  => $href)));
51490658f38SMichael Hamann        $form->addElement($display_name);
51537a1dc12Smichael        $form->addElement(form_makeCloseTag('a'));
516652610a2Sandi
51767c8cda1SKate Arzamastseva        if ($media_id) $form->addElement(form_makeOpenTag('div'));
51867c8cda1SKate Arzamastseva
519551be3f9SGerrit Uitslag        if($summary) {
52037a1dc12Smichael            $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
521551be3f9SGerrit Uitslag            if(!$media_id) $form->addElement(' – ');
52265cc1598SPhy            $form->addElement('<bdi>' . hsc($summary) . '</bdi>');
52337a1dc12Smichael            $form->addElement(form_makeCloseTag('span'));
524035e07f1SKate Arzamastseva        }
525652610a2Sandi
52637a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
527551be3f9SGerrit Uitslag        $form->addElement((empty($editor))?('('.$lang['external_edit'].')'):'<bdi>'.editorinfo($editor).'</bdi>');
52837a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
52937a1dc12Smichael
530cd2a4cfdSAnika Henke        html_sizechange($sizechange, $form);
531551be3f9SGerrit Uitslag
53237a1dc12Smichael        $form->addElement('('.$lang['current'].')');
53367c8cda1SKate Arzamastseva
53467c8cda1SKate Arzamastseva        if ($media_id) $form->addElement(form_makeCloseTag('div'));
53567c8cda1SKate Arzamastseva
53637a1dc12Smichael        $form->addElement(form_makeCloseTag('div'));
53737a1dc12Smichael        $form->addElement(form_makeCloseTag('li'));
538f3f0262cSandi    }
539f3f0262cSandi
540f3f0262cSandi    foreach($revisions as $rev) {
541f2263577SAndreas Gohr        $date = dformat($rev);
542047bad06SGerrit Uitslag        $info = $changelog->getRevisionInfo($rev);
543047bad06SGerrit Uitslag        if($media_id) {
54479e79377SAndreas Gohr            $exists = file_exists(mediaFN($id, $rev));
545047bad06SGerrit Uitslag        } else {
546047bad06SGerrit Uitslag            $exists = page_exists($id, $rev);
547dad6764eSKate Arzamastseva        }
548652610a2Sandi
549551be3f9SGerrit Uitslag        $class = '';
550551be3f9SGerrit Uitslag        if($info['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) {
551551be3f9SGerrit Uitslag            $class = 'minor';
552551be3f9SGerrit Uitslag        }
553551be3f9SGerrit Uitslag        $form->addElement(form_makeOpenTag('li', array('class' => $class)));
55437a1dc12Smichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
55577707b04SAndreas Gohr        if($exists){
55637a1dc12Smichael            $form->addElement(form_makeTag('input', array(
55737a1dc12Smichael                            'type' => 'checkbox',
55837a1dc12Smichael                            'name' => 'rev2[]',
55937a1dc12Smichael                            'value' => $rev)));
56077707b04SAndreas Gohr        }else{
561c2e73886SAnika Henke            $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
56241396b71SAndreas Gohr        }
563f9b2fe70Sandi
56437a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
56537a1dc12Smichael        $form->addElement($date);
56637a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
56737a1dc12Smichael
56837a1dc12Smichael        if($exists){
569551be3f9SGerrit Uitslag            if (!$media_id) {
570551be3f9SGerrit Uitslag                $href = wl($id,"rev=$rev,do=diff", false, '&');
571551be3f9SGerrit Uitslag            } else {
572551be3f9SGerrit Uitslag                $href = media_managerURL(array('image' => $id, 'rev' => $rev, 'mediado' => 'diff'), '&');
573551be3f9SGerrit Uitslag            }
574551be3f9SGerrit Uitslag            $form->addElement(form_makeOpenTag('a', array(
575551be3f9SGerrit Uitslag                            'class' => 'diff_link',
576551be3f9SGerrit Uitslag                            'href' => $href)));
57737a1dc12Smichael            $form->addElement(form_makeTag('img', array(
57837a1dc12Smichael                            'src'    => DOKU_BASE.'lib/images/diff.png',
57937a1dc12Smichael                            'width'  => 15,
58037a1dc12Smichael                            'height' => 11,
58137a1dc12Smichael                            'title'  => $lang['diff'],
58237a1dc12Smichael                            'alt'    => $lang['diff'])));
58337a1dc12Smichael            $form->addElement(form_makeCloseTag('a'));
584551be3f9SGerrit Uitslag
585551be3f9SGerrit Uitslag            if (!$media_id) {
586551be3f9SGerrit Uitslag                $href = wl($id,"rev=$rev",false,'&');
587551be3f9SGerrit Uitslag            } else {
588551be3f9SGerrit Uitslag                $href = media_managerURL(array('image' => $id, 'tab_details' => 'view', 'rev' => $rev), '&');
589551be3f9SGerrit Uitslag            }
590551be3f9SGerrit Uitslag            $form->addElement(form_makeOpenTag('a', array(
591551be3f9SGerrit Uitslag                            'class' => 'wikilink1',
592551be3f9SGerrit Uitslag                            'href' => $href)));
59390658f38SMichael Hamann            $form->addElement($display_name);
59437a1dc12Smichael            $form->addElement(form_makeCloseTag('a'));
59537a1dc12Smichael        }else{
596c2e73886SAnika Henke            $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
59790658f38SMichael Hamann            $form->addElement($display_name);
59837a1dc12Smichael        }
59937a1dc12Smichael
60067c8cda1SKate Arzamastseva        if ($media_id) $form->addElement(form_makeOpenTag('div'));
60167c8cda1SKate Arzamastseva
602035e07f1SKate Arzamastseva        if ($info['sum']) {
60337a1dc12Smichael            $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
604e260f93bSAnika Henke            if(!$media_id) $form->addElement(' – ');
60565cc1598SPhy            $form->addElement('<bdi>'.hsc($info['sum']).'</bdi>');
60637a1dc12Smichael            $form->addElement(form_makeCloseTag('span'));
607035e07f1SKate Arzamastseva        }
60837a1dc12Smichael
60937a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
61088f522e9Sandi        if($info['user']){
611d317fb5dSAnika Henke            $form->addElement('<bdi>'.editorinfo($info['user']).'</bdi>');
612433efb25SAndreas Gohr            if(auth_ismanager()){
613d317fb5dSAnika Henke                $form->addElement(' <bdo dir="ltr">('.$info['ip'].')</bdo>');
614433efb25SAndreas Gohr            }
61588f522e9Sandi        }else{
616d317fb5dSAnika Henke            $form->addElement('<bdo dir="ltr">'.$info['ip'].'</bdo>');
61788f522e9Sandi        }
61837a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
619652610a2Sandi
620cd2a4cfdSAnika Henke        html_sizechange($info['sizechange'], $form);
621551be3f9SGerrit Uitslag
62267c8cda1SKate Arzamastseva        if ($media_id) $form->addElement(form_makeCloseTag('div'));
62367c8cda1SKate Arzamastseva
62437a1dc12Smichael        $form->addElement(form_makeCloseTag('div'));
62537a1dc12Smichael        $form->addElement(form_makeCloseTag('li'));
626f3f0262cSandi    }
62737a1dc12Smichael    $form->addElement(form_makeCloseTag('ul'));
6282e55802cSKate Arzamastseva    if (!$media_id) {
6292e55802cSKate Arzamastseva        $form->addElement(form_makeButton('submit', 'diff', $lang['diff2']));
6302e55802cSKate Arzamastseva    } else {
6312e55802cSKate Arzamastseva        $form->addHidden('mediado', 'diff');
6322e55802cSKate Arzamastseva        $form->addElement(form_makeButton('submit', '', $lang['diff2']));
6332e55802cSKate Arzamastseva    }
63437a1dc12Smichael    html_form('revisions', $form);
63571726d78SBen Coburn
63671726d78SBen Coburn    print '<div class="pagenav">';
63771726d78SBen Coburn    $last = $first + $conf['recent'];
63871726d78SBen Coburn    if ($first > 0) {
63971726d78SBen Coburn        $first -= $conf['recent'];
64071726d78SBen Coburn        if ($first < 0) $first = 0;
64171726d78SBen Coburn        print '<div class="pagenav-prev">';
6427e6b49bbSKate Arzamastseva        if ($media_id) {
643035e07f1SKate Arzamastseva            print html_btn('newer',$media_id,"p",media_managerURL(array('first' => $first), '&amp;', false, true));
6447e6b49bbSKate Arzamastseva        } else {
6458e69fd30SKate Arzamastseva            print html_btn('newer',$id,"p",array('do' => 'revisions', 'first' => $first));
6467e6b49bbSKate Arzamastseva        }
64771726d78SBen Coburn        print '</div>';
64871726d78SBen Coburn    }
64971726d78SBen Coburn    if ($hasNext) {
65071726d78SBen Coburn        print '<div class="pagenav-next">';
6517e6b49bbSKate Arzamastseva        if ($media_id) {
652035e07f1SKate Arzamastseva            print html_btn('older',$media_id,"n",media_managerURL(array('first' => $last), '&amp;', false, true));
6537e6b49bbSKate Arzamastseva        } else {
6548e69fd30SKate Arzamastseva            print html_btn('older',$id,"n",array('do' => 'revisions', 'first' => $last));
6557e6b49bbSKate Arzamastseva        }
65671726d78SBen Coburn        print '</div>';
65771726d78SBen Coburn    }
65871726d78SBen Coburn    print '</div>';
65971726d78SBen Coburn
660f3f0262cSandi}
661f3f0262cSandi
66215fae107Sandi/**
66315fae107Sandi * display recent changes
66415fae107Sandi *
66515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
6665749f1ceSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
66771726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
6688d40b4b6SKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
66942ea7f44SGerrit Uitslag *
67042ea7f44SGerrit Uitslag * @param int $first
67142ea7f44SGerrit Uitslag * @param string $show_changes
67215fae107Sandi */
6730739a638SKate Arzamastsevafunction html_recent($first = 0, $show_changes = 'both') {
674f3f0262cSandi    global $conf;
675cffcc403Sandi    global $lang;
676dbb00abcSEsther Brunner    global $ID;
6775749f1ceSmatthiasgrimm    /* we need to get one additionally log entry to be able to
6785749f1ceSmatthiasgrimm     * decide if this is the last page or is there another one.
6795749f1ceSmatthiasgrimm     * This is the cheapest solution to get this information.
6805749f1ceSmatthiasgrimm     */
681e5d185e1SKate Arzamastseva    $flags = 0;
682e5d185e1SKate Arzamastseva    if($show_changes == 'mediafiles' && $conf['mediarevisions']) {
683b5941dfaSKate Arzamastseva        $flags = RECENTS_MEDIA_CHANGES;
684b5941dfaSKate Arzamastseva    } elseif($show_changes == 'pages') {
685b5941dfaSKate Arzamastseva        $flags = 0;
686e5d185e1SKate Arzamastseva    } elseif($conf['mediarevisions']) {
687b5941dfaSKate Arzamastseva        $show_changes = 'both';
688b5941dfaSKate Arzamastseva        $flags = RECENTS_MEDIA_PAGES_MIXED;
689b5941dfaSKate Arzamastseva    }
6908d40b4b6SKate Arzamastseva
6918d40b4b6SKate Arzamastseva    $recents = getRecents($first, $conf['recent'] + 1, getNS($ID), $flags);
6925749f1ceSmatthiasgrimm    if(count($recents) == 0 && $first != 0) {
6935749f1ceSmatthiasgrimm        $first = 0;
6948d40b4b6SKate Arzamastseva        $recents = getRecents($first, $conf['recent'] + 1, getNS($ID), $flags);
6955749f1ceSmatthiasgrimm    }
69671726d78SBen Coburn    $hasNext = false;
69771726d78SBen Coburn    if(count($recents) > $conf['recent']) {
69871726d78SBen Coburn        $hasNext = true;
69971726d78SBen Coburn        array_pop($recents); // remove extra log entry
70071726d78SBen Coburn    }
701f3f0262cSandi
702c112d578Sandi    print p_locale_xhtml('recent');
703e83cef14SGina Haeussge
704a023425bSGerrit Uitslag    if(getNS($ID) != '') {
70564159a61SAndreas Gohr        print '<div class="level1"><p>' .
70664159a61SAndreas Gohr            sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) .
70764159a61SAndreas Gohr            '</p></div>';
708a023425bSGerrit Uitslag    }
709e83cef14SGina Haeussge
710d1264ecfSAndreas Gohr    $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET', 'class' => 'changes', 'action'=>wl($ID)));
711abdcc39fSmichael    $form->addHidden('sectok', null);
712abdcc39fSmichael    $form->addHidden('do', 'recent');
713abdcc39fSmichael    $form->addHidden('id', $ID);
7148d40b4b6SKate Arzamastseva
715e5d185e1SKate Arzamastseva    if($conf['mediarevisions']) {
7160607bfeeSAnika Henke        $form->addElement('<div class="changeType">');
717b5941dfaSKate Arzamastseva        $form->addElement(form_makeListboxField(
718b5941dfaSKate Arzamastseva                    'show_changes',
719b5941dfaSKate Arzamastseva                    array(
720b5941dfaSKate Arzamastseva                        'pages'      => $lang['pages_changes'],
721b5941dfaSKate Arzamastseva                        'mediafiles' => $lang['media_changes'],
72253cba3d0SGerrit Uitslag                        'both'       => $lang['both_changes']
72353cba3d0SGerrit Uitslag                    ),
724b5941dfaSKate Arzamastseva                    $show_changes,
725b5941dfaSKate Arzamastseva                    $lang['changes_type'],
726b5941dfaSKate Arzamastseva                    '', '',
727b5941dfaSKate Arzamastseva                    array('class' => 'quickselect')));
728b5941dfaSKate Arzamastseva
729b5941dfaSKate Arzamastseva        $form->addElement(form_makeButton('submit', 'recent', $lang['btn_apply']));
7300607bfeeSAnika Henke        $form->addElement('</div>');
731e5d185e1SKate Arzamastseva    }
7328d40b4b6SKate Arzamastseva
733abdcc39fSmichael    $form->addElement(form_makeOpenTag('ul'));
734a39955b0Smatthiasgrimm
735d437bcc4SAndreas Gohr    foreach($recents as $recent) {
736f2263577SAndreas Gohr        $date = dformat($recent['date']);
737cffcc403Sandi
738a023425bSGerrit Uitslag        $class = '';
739a023425bSGerrit Uitslag        if($recent['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) {
740a023425bSGerrit Uitslag            $class = 'minor';
741a023425bSGerrit Uitslag        }
742a023425bSGerrit Uitslag        $form->addElement(form_makeOpenTag('li', array('class' => $class)));
743abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
744f9b2fe70Sandi
7450e80bb5eSChristopher Smith        if(!empty($recent['media'])) {
746421ec38eSKate Arzamastseva            $form->addElement(media_printicon($recent['id']));
747421ec38eSKate Arzamastseva        } else {
748421ec38eSKate Arzamastseva            $icon = DOKU_BASE . 'lib/images/fileicons/file.png';
7490686da46SMichael Hamann            $form->addElement('<img src="' . $icon . '" alt="' . $recent['id'] . '" class="icon" />');
750421ec38eSKate Arzamastseva        }
751421ec38eSKate Arzamastseva
752abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
753abdcc39fSmichael        $form->addElement($date);
754abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
755cffcc403Sandi
7566d9eab4dSMichael Hamann        $diff = false;
7576d9eab4dSMichael Hamann        $href = '';
7586d9eab4dSMichael Hamann
7590e80bb5eSChristopher Smith        if(!empty($recent['media'])) {
76068921571SGerrit Uitslag            $changelog = new MediaChangeLog($recent['id']);
76168921571SGerrit Uitslag            $revs = $changelog->getRevisions(0, 1);
76268921571SGerrit Uitslag            $diff = (count($revs) && file_exists(mediaFN($recent['id'])));
76392cac9a9SKate Arzamastseva            if($diff) {
76468921571SGerrit Uitslag                $href = media_managerURL(array(
76568921571SGerrit Uitslag                                            'tab_details' => 'history',
76668921571SGerrit Uitslag                                            'mediado' => 'diff',
76768921571SGerrit Uitslag                                            'image' => $recent['id'],
76868921571SGerrit Uitslag                                            'ns' => getNS($recent['id'])
76968921571SGerrit Uitslag                                        ), '&');
77092cac9a9SKate Arzamastseva            }
771b5941dfaSKate Arzamastseva        } else {
772b5941dfaSKate Arzamastseva            $href = wl($recent['id'], "do=diff", false, '&');
773b5941dfaSKate Arzamastseva        }
77492cac9a9SKate Arzamastseva
7750e80bb5eSChristopher Smith        if(!empty($recent['media']) && !$diff) {
77692cac9a9SKate Arzamastseva            $form->addElement('<img src="' . DOKU_BASE . 'lib/images/blank.gif" width="15" height="11" alt="" />');
77792cac9a9SKate Arzamastseva        } else {
778b5941dfaSKate Arzamastseva            $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => $href)));
779abdcc39fSmichael            $form->addElement(form_makeTag('img', array(
780abdcc39fSmichael                            'src'    => DOKU_BASE . 'lib/images/diff.png',
781abdcc39fSmichael                            'width'  => 15,
782abdcc39fSmichael                            'height' => 11,
783abdcc39fSmichael                            'title'  => $lang['diff'],
784abdcc39fSmichael                            'alt'    => $lang['diff']
785abdcc39fSmichael                        )));
786abdcc39fSmichael            $form->addElement(form_makeCloseTag('a'));
78792cac9a9SKate Arzamastseva        }
788cffcc403Sandi
7890e80bb5eSChristopher Smith        if(!empty($recent['media'])) {
79064159a61SAndreas Gohr            $href = media_managerURL(
79164159a61SAndreas Gohr                array(
79264159a61SAndreas Gohr                    'tab_details' => 'history',
79364159a61SAndreas Gohr                    'image' => $recent['id'],
79464159a61SAndreas Gohr                    'ns' => getNS($recent['id'])
79564159a61SAndreas Gohr                ),
79664159a61SAndreas Gohr                '&'
79764159a61SAndreas Gohr            );
798b5941dfaSKate Arzamastseva        } else {
799b5941dfaSKate Arzamastseva            $href = wl($recent['id'], "do=revisions", false, '&');
800b5941dfaSKate Arzamastseva        }
801a023425bSGerrit Uitslag        $form->addElement(form_makeOpenTag('a', array(
802a023425bSGerrit Uitslag                        'class' => 'revisions_link',
803a023425bSGerrit Uitslag                        'href'  => $href)));
804abdcc39fSmichael        $form->addElement(form_makeTag('img', array(
805abdcc39fSmichael                        'src'    => DOKU_BASE . 'lib/images/history.png',
806abdcc39fSmichael                        'width'  => 12,
807abdcc39fSmichael                        'height' => 14,
808abdcc39fSmichael                        'title'  => $lang['btn_revs'],
809abdcc39fSmichael                        'alt'    => $lang['btn_revs']
810abdcc39fSmichael                    )));
811abdcc39fSmichael        $form->addElement(form_makeCloseTag('a'));
812b6912aeaSAndreas Gohr
8130e80bb5eSChristopher Smith        if(!empty($recent['media'])) {
81464159a61SAndreas Gohr            $href = media_managerURL(
81564159a61SAndreas Gohr                array(
81664159a61SAndreas Gohr                    'tab_details' => 'view',
81764159a61SAndreas Gohr                    'image' => $recent['id'],
81864159a61SAndreas Gohr                    'ns' => getNS($recent['id'])
81964159a61SAndreas Gohr                ),
82064159a61SAndreas Gohr                '&'
82164159a61SAndreas Gohr            );
822a023425bSGerrit Uitslag            $class = file_exists(mediaFN($recent['id'])) ? 'wikilink1' : 'wikilink2';
823a023425bSGerrit Uitslag            $form->addElement(form_makeOpenTag('a', array(
824a023425bSGerrit Uitslag                        'class' => $class,
825a023425bSGerrit Uitslag                        'href'  => $href)));
826b5941dfaSKate Arzamastseva            $form->addElement($recent['id']);
827b5941dfaSKate Arzamastseva            $form->addElement(form_makeCloseTag('a'));
828b5941dfaSKate Arzamastseva        } else {
829b5941dfaSKate Arzamastseva            $form->addElement(html_wikilink(':' . $recent['id'], useHeading('navigation') ? null : $recent['id']));
830b5941dfaSKate Arzamastseva        }
831abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
83265cc1598SPhy        $form->addElement(' – ' . hsc($recent['sum']));
833abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
834abdcc39fSmichael
835abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
836d437bcc4SAndreas Gohr        if($recent['user']) {
837d317fb5dSAnika Henke            $form->addElement('<bdi>' . editorinfo($recent['user']) . '</bdi>');
838433efb25SAndreas Gohr            if(auth_ismanager()) {
839d317fb5dSAnika Henke                $form->addElement(' <bdo dir="ltr">(' . $recent['ip'] . ')</bdo>');
840433efb25SAndreas Gohr            }
84188f522e9Sandi        } else {
842d317fb5dSAnika Henke            $form->addElement('<bdo dir="ltr">' . $recent['ip'] . '</bdo>');
84388f522e9Sandi        }
844abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
845cffcc403Sandi
846cd2a4cfdSAnika Henke        html_sizechange($recent['sizechange'], $form);
847976b572aSGerrit Uitslag
848abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
849abdcc39fSmichael        $form->addElement(form_makeCloseTag('li'));
850f3f0262cSandi    }
851abdcc39fSmichael    $form->addElement(form_makeCloseTag('ul'));
852a39955b0Smatthiasgrimm
853abdcc39fSmichael    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
8545749f1ceSmatthiasgrimm    $last = $first + $conf['recent'];
855a39955b0Smatthiasgrimm    if($first > 0) {
856a39955b0Smatthiasgrimm        $first -= $conf['recent'];
857a39955b0Smatthiasgrimm        if($first < 0) $first = 0;
858abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
859ae614416SAnika Henke        $form->addElement(form_makeOpenTag('button', array(
860abdcc39fSmichael                        'type'      => 'submit',
861abdcc39fSmichael                        'name'      => 'first[' . $first . ']',
862cddd152cSmichael                        'accesskey' => 'n',
863f948eeabSMichael Klier                        'title'     => $lang['btn_newer'] . ' [N]',
864d5daba10SKate Arzamastseva                        'class'     => 'button show'
865abdcc39fSmichael                    )));
866ae614416SAnika Henke        $form->addElement($lang['btn_newer']);
867ae614416SAnika Henke        $form->addElement(form_makeCloseTag('button'));
868abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
869a39955b0Smatthiasgrimm    }
87071726d78SBen Coburn    if($hasNext) {
871abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
872ae614416SAnika Henke        $form->addElement(form_makeOpenTag('button', array(
873abdcc39fSmichael                        'type'      => 'submit',
874abdcc39fSmichael                        'name'      => 'first[' . $last . ']',
875cddd152cSmichael                        'accesskey' => 'p',
876f948eeabSMichael Klier                        'title'     => $lang['btn_older'] . ' [P]',
877d5daba10SKate Arzamastseva                        'class'     => 'button show'
878abdcc39fSmichael                    )));
879ae614416SAnika Henke        $form->addElement($lang['btn_older']);
880ae614416SAnika Henke        $form->addElement(form_makeCloseTag('button'));
881abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
882a39955b0Smatthiasgrimm    }
883abdcc39fSmichael    $form->addElement(form_makeCloseTag('div'));
884abdcc39fSmichael    html_form('recent', $form);
885f3f0262cSandi}
886f3f0262cSandi
88715fae107Sandi/**
88815fae107Sandi * Display page index
88915fae107Sandi *
89015fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
89142ea7f44SGerrit Uitslag *
89242ea7f44SGerrit Uitslag * @param string $ns
89315fae107Sandi */
894f3f0262cSandifunction html_index($ns){
895f3f0262cSandi    global $conf;
896f3f0262cSandi    global $ID;
897f3f0262cSandi    $ns  = cleanID($ns);
898f3f0262cSandi    if(empty($ns)){
89982f5f399SSatoshi Sahara        $ns = getNS($ID);
900dab290efSSatoshi Sahara        if($ns === false) $ns ='';
901f3f0262cSandi    }
90288d3a917Sandi    $ns  = utf8_encodeFN(str_replace(':','/',$ns));
903f3f0262cSandi
904a06884abSAndreas Gohr    echo p_locale_xhtml('index');
905158a5bffSDeathCamel57    echo '<div id="index__tree" class="index__tree">';
906f3f0262cSandi
907f3f0262cSandi    $data = array();
908f3f0262cSandi    search($data,$conf['datadir'],'search_index',array('ns' => $ns));
909a06884abSAndreas Gohr    echo html_buildlist($data,'idx','html_list_index','html_li_index');
910a06884abSAndreas Gohr
911a06884abSAndreas Gohr    echo '</div>';
912f3f0262cSandi}
913f3f0262cSandi
914f3f0262cSandi/**
91515fae107Sandi * Index item formatter
91615fae107Sandi *
917f3f0262cSandi * User function for html_buildlist()
91815fae107Sandi *
91915fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
92042ea7f44SGerrit Uitslag *
92142ea7f44SGerrit Uitslag * @param array $item
92242ea7f44SGerrit Uitslag * @return string
923f3f0262cSandi */
924f3f0262cSandifunction html_list_index($item){
92574ef1778SChristopher Smith    global $ID, $conf;
92674ef1778SChristopher Smith
927b8bc53ceSChristopher Smith    // prevent searchbots needlessly following links
92874ef1778SChristopher Smith    $nofollow = ($ID != $conf['start'] || $conf['sitemap']) ? 'rel="nofollow"' : '';
92974ef1778SChristopher Smith
930f3f0262cSandi    $ret = '';
931f3f0262cSandi    $base = ':'.$item['id'];
932f3f0262cSandi    $base = substr($base,strrpos($base,':')+1);
933f3f0262cSandi    if($item['type']=='d'){
934b1af9014SChristopher Smith        // FS#2766, no need for search bots to follow namespace links in the index
93564159a61SAndreas Gohr        $link = wl($ID, 'idx=' . rawurlencode($item['id']));
93664159a61SAndreas Gohr        $ret .= '<a href="' . $link . '" title="' . $item['id'] . '" class="idx_dir" ' . $nofollow . '><strong>';
937f3f0262cSandi        $ret .= $base;
938ed7ecb79SAnika Henke        $ret .= '</strong></a>';
939f3f0262cSandi    }else{
9409aa38483SMichael Hamann        // default is noNSorNS($id), but we want noNS($id) when useheading is off FS#2605
9419aa38483SMichael Hamann        $ret .= html_wikilink(':'.$item['id'], useHeading('navigation') ? null : noNS($item['id']));
942f3f0262cSandi    }
943f3f0262cSandi    return $ret;
944f3f0262cSandi}
945f3f0262cSandi
946f3f0262cSandi/**
947cb70c441Sandi * Index List item
948cb70c441Sandi *
949a1dee2b9SAdrian Lang * This user function is used in html_buildlist to build the
950cb70c441Sandi * <li> tags for namespaces when displaying the page index
951cb70c441Sandi * it gives different classes to opened or closed "folders"
952cb70c441Sandi *
953cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
95442ea7f44SGerrit Uitslag *
95542ea7f44SGerrit Uitslag * @param array $item
95642ea7f44SGerrit Uitslag * @return string html
957cb70c441Sandi */
958cb70c441Sandifunction html_li_index($item){
959f7dbf175SAndreas Gohr    global $INFO;
96021b07cb4SAndreas Gohr    global $ACT;
961f7dbf175SAndreas Gohr
9626fa4721aSAndreas Gohr    $class = '';
9636fa4721aSAndreas Gohr    $id = '';
9646fa4721aSAndreas Gohr
965cb70c441Sandi    if($item['type'] == "f"){
966f7dbf175SAndreas Gohr        // scroll to the current item
967*aac83cd4SPhy        if(isset($INFO) && $item['id'] == $INFO['id'] && $ACT == 'index') {
968f7dbf175SAndreas Gohr            $id = ' id="scroll__here"';
969772f3c51SDeathCamel57            $class = ' bounce';
970f7dbf175SAndreas Gohr        }
9716fa4721aSAndreas Gohr        return '<li class="level'.$item['level'].$class.'" '.$id.'>';
972cb70c441Sandi    }elseif($item['open']){
973cb70c441Sandi        return '<li class="open">';
974cb70c441Sandi    }else{
975cb70c441Sandi        return '<li class="closed">';
976cb70c441Sandi    }
977cb70c441Sandi}
978cb70c441Sandi
979cb70c441Sandi/**
980cb70c441Sandi * Default List item
981cb70c441Sandi *
982cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
98342ea7f44SGerrit Uitslag *
98442ea7f44SGerrit Uitslag * @param array $item
98542ea7f44SGerrit Uitslag * @return string html
986cb70c441Sandi */
987cb70c441Sandifunction html_li_default($item){
988cb70c441Sandi    return '<li class="level'.$item['level'].'">';
989cb70c441Sandi}
990cb70c441Sandi
991cb70c441Sandi/**
99215fae107Sandi * Build an unordered list
99315fae107Sandi *
994f3f0262cSandi * Build an unordered list from the given $data array
995f3f0262cSandi * Each item in the array has to have a 'level' property
996f3f0262cSandi * the item itself gets printed by the given $func user
997cb70c441Sandi * function. The second and optional function is used to
998cb70c441Sandi * print the <li> tag. Both user function need to accept
999cb70c441Sandi * a single item.
100015fae107Sandi *
1001c5a8fd96SAndreas Gohr * Both user functions can be given as array to point to
1002c5a8fd96SAndreas Gohr * a member of an object.
1003c5a8fd96SAndreas Gohr *
100415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
100580679bafSGerrit Uitslag *
100680679bafSGerrit Uitslag * @param array    $data  array with item arrays
100780679bafSGerrit Uitslag * @param string   $class class of ul wrapper
100880679bafSGerrit Uitslag * @param callable $func  callback to print an list item
10095a9597bbSTakamura * @param callable $lifunc callback to the opening li tag
101080679bafSGerrit Uitslag * @param bool     $forcewrapper Trigger building a wrapper ul if the first level is
1011ae614416SAnika Henke *                               0 (we have a root object) or 1 (just the root content)
101280679bafSGerrit Uitslag * @return string html of an unordered list
1013f3f0262cSandi */
101487671313SHakan Sandellfunction html_buildlist($data,$class,$func,$lifunc='html_li_default',$forcewrapper=false){
1015a1dee2b9SAdrian Lang    if (count($data) === 0) {
1016a1dee2b9SAdrian Lang        return '';
1017a1dee2b9SAdrian Lang    }
1018a1dee2b9SAdrian Lang
10192689c55fSMichael Große    $firstElement = reset($data);
10202689c55fSMichael Große    $start_level = $firstElement['level'];
10219e4f7880SAdrian Lang    $level = $start_level;
1022434f5921SHakan Sandell    $ret   = '';
1023434f5921SHakan Sandell    $open  = 0;
10249e4f7880SAdrian Lang
1025f3f0262cSandi    foreach ($data as $item){
1026f3f0262cSandi
1027f3f0262cSandi        if( $item['level'] > $level ){
1028f3f0262cSandi            //open new list
1029df52d0feSandi            for($i=0; $i<($item['level'] - $level); $i++){
1030434f5921SHakan Sandell                if ($i) $ret .= "<li class=\"clear\">";
1031f3f0262cSandi                $ret .= "\n<ul class=\"$class\">\n";
1032434f5921SHakan Sandell                $open++;
1033df52d0feSandi            }
1034434f5921SHakan Sandell            $level = $item['level'];
1035434f5921SHakan Sandell
1036f3f0262cSandi        }elseif( $item['level'] < $level ){
1037f3f0262cSandi            //close last item
1038f3f0262cSandi            $ret .= "</li>\n";
1039434f5921SHakan Sandell            while( $level > $item['level'] && $open > 0 ){
1040f3f0262cSandi                //close higher lists
1041f3f0262cSandi                $ret .= "</ul>\n</li>\n";
1042434f5921SHakan Sandell                $level--;
1043434f5921SHakan Sandell                $open--;
1044f3f0262cSandi            }
1045a1dee2b9SAdrian Lang        } elseif ($ret !== '') {
104687671313SHakan Sandell            //close previous item
1047f3f0262cSandi            $ret .= "</li>\n";
1048f3f0262cSandi        }
1049f3f0262cSandi
1050f3f0262cSandi        //print item
105134dbe711Schris        $ret .= call_user_func($lifunc,$item);
10520c6b58a8SAndreas Gohr        $ret .= '<div class="li">';
105334dbe711Schris
105434dbe711Schris        $ret .= call_user_func($func,$item);
10550c6b58a8SAndreas Gohr        $ret .= '</div>';
1056f3f0262cSandi    }
1057f3f0262cSandi
1058f3f0262cSandi    //close remaining items and lists
1059434f5921SHakan Sandell    $ret .= "</li>\n";
1060434f5921SHakan Sandell    while($open-- > 0) {
1061434f5921SHakan Sandell        $ret .= "</ul></li>\n";
1062434f5921SHakan Sandell    }
1063434f5921SHakan Sandell
1064434f5921SHakan Sandell    if ($forcewrapper || $start_level < 2) {
1065434f5921SHakan Sandell        // Trigger building a wrapper ul if the first level is
1066434f5921SHakan Sandell        // 0 (we have a root object) or 1 (just the root content)
1067434f5921SHakan Sandell        $ret = "\n<ul class=\"$class\">\n".$ret."</ul>\n";
1068f3f0262cSandi    }
1069f3f0262cSandi
1070f3f0262cSandi    return $ret;
1071f3f0262cSandi}
1072f3f0262cSandi
107315fae107Sandi/**
107415fae107Sandi * display backlinks
107515fae107Sandi *
107615fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
107711df47ecSMichael Klier * @author Michael Klier <chi@chimeric.de>
107815fae107Sandi */
1079f3f0262cSandifunction html_backlinks(){
1080f3f0262cSandi    global $ID;
108111df47ecSMichael Klier    global $lang;
1082f3f0262cSandi
1083c112d578Sandi    print p_locale_xhtml('backlinks');
1084f3f0262cSandi
108554f4c056SAndreas Gohr    $data = ft_backlinks($ID);
1086f3f0262cSandi
108711df47ecSMichael Klier    if(!empty($data)) {
1088f3f0262cSandi        print '<ul class="idx">';
108954f4c056SAndreas Gohr        foreach($data as $blink){
10900c6b58a8SAndreas Gohr            print '<li><div class="li">';
1091db959ae3SAndreas Gohr            print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink);
10920c6b58a8SAndreas Gohr            print '</div></li>';
1093f3f0262cSandi        }
1094f3f0262cSandi        print '</ul>';
109511df47ecSMichael Klier    } else {
109611df47ecSMichael Klier        print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
109711df47ecSMichael Klier    }
1098f3f0262cSandi}
1099f3f0262cSandi
11008d5e837eSMichael Hamann/**
11018d5e837eSMichael Hamann * Get header of diff HTML
110242ea7f44SGerrit Uitslag *
11038d5e837eSMichael Hamann * @param string $l_rev   Left revisions
11048d5e837eSMichael Hamann * @param string $r_rev   Right revision
11058d5e837eSMichael Hamann * @param string $id      Page id, if null $ID is used
11068d5e837eSMichael Hamann * @param bool   $media   If it is for media files
1107f76724a4STom N Harris * @param bool   $inline  Return the header on a single line
110842ea7f44SGerrit Uitslag * @return string[] HTML snippets for diff header
11098d5e837eSMichael Hamann */
1110f76724a4STom N Harrisfunction html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = false) {
111195b451bcSAdrian Lang    global $lang;
111295b451bcSAdrian Lang    if ($id === null) {
111395b451bcSAdrian Lang        global $ID;
111495b451bcSAdrian Lang        $id = $ID;
111595b451bcSAdrian Lang    }
1116f76724a4STom N Harris    $head_separator = $inline ? ' ' : '<br />';
111795b451bcSAdrian Lang    $media_or_wikiFN = $media ? 'mediaFN' : 'wikiFN';
111895b451bcSAdrian Lang    $ml_or_wl = $media ? 'ml' : 'wl';
111995b451bcSAdrian Lang    $l_minor = $r_minor = '';
112095b451bcSAdrian Lang
1121047bad06SGerrit Uitslag    if($media) {
11224f6e20c7SGerrit Uitslag        $changelog = new MediaChangeLog($id);
1123047bad06SGerrit Uitslag    } else {
11244f6e20c7SGerrit Uitslag        $changelog = new PageChangeLog($id);
1125047bad06SGerrit Uitslag    }
112695b451bcSAdrian Lang    if(!$l_rev){
112795b451bcSAdrian Lang        $l_head = '&mdash;';
112895b451bcSAdrian Lang    }else{
11294f6e20c7SGerrit Uitslag        $l_info   = $changelog->getRevisionInfo($l_rev);
113095b451bcSAdrian Lang        if($l_info['user']){
1131d317fb5dSAnika Henke            $l_user = '<bdi>'.editorinfo($l_info['user']).'</bdi>';
1132d317fb5dSAnika Henke            if(auth_ismanager()) $l_user .= ' <bdo dir="ltr">('.$l_info['ip'].')</bdo>';
113395b451bcSAdrian Lang        } else {
1134d317fb5dSAnika Henke            $l_user = '<bdo dir="ltr">'.$l_info['ip'].'</bdo>';
113595b451bcSAdrian Lang        }
113695b451bcSAdrian Lang        $l_user  = '<span class="user">'.$l_user.'</span>';
1137d317fb5dSAnika Henke        $l_sum   = ($l_info['sum']) ? '<span class="sum"><bdi>'.hsc($l_info['sum']).'</bdi></span>' : '';
113895b451bcSAdrian Lang        if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
113995b451bcSAdrian Lang
1140699c5072SAnika Henke        $l_head_title = ($media) ? dformat($l_rev) : $id.' ['.dformat($l_rev).']';
1141d317fb5dSAnika Henke        $l_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$l_rev").'">'.
1142d317fb5dSAnika Henke        $l_head_title.'</a></bdi>'.
1143f76724a4STom N Harris        $head_separator.$l_user.' '.$l_sum;
114495b451bcSAdrian Lang    }
114595b451bcSAdrian Lang
114695b451bcSAdrian Lang    if($r_rev){
11474f6e20c7SGerrit Uitslag        $r_info   = $changelog->getRevisionInfo($r_rev);
114895b451bcSAdrian Lang        if($r_info['user']){
1149d317fb5dSAnika Henke            $r_user = '<bdi>'.editorinfo($r_info['user']).'</bdi>';
1150d317fb5dSAnika Henke            if(auth_ismanager()) $r_user .= ' <bdo dir="ltr">('.$r_info['ip'].')</bdo>';
115195b451bcSAdrian Lang        } else {
1152d317fb5dSAnika Henke            $r_user = '<bdo dir="ltr">'.$r_info['ip'].'</bdo>';
115395b451bcSAdrian Lang        }
115495b451bcSAdrian Lang        $r_user = '<span class="user">'.$r_user.'</span>';
1155d317fb5dSAnika Henke        $r_sum  = ($r_info['sum']) ? '<span class="sum"><bdi>'.hsc($r_info['sum']).'</bdi></span>' : '';
115695b451bcSAdrian Lang        if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
115795b451bcSAdrian Lang
1158699c5072SAnika Henke        $r_head_title = ($media) ? dformat($r_rev) : $id.' ['.dformat($r_rev).']';
1159d317fb5dSAnika Henke        $r_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$r_rev").'">'.
1160d317fb5dSAnika Henke        $r_head_title.'</a></bdi>'.
1161f76724a4STom N Harris        $head_separator.$r_user.' '.$r_sum;
116295b451bcSAdrian Lang    }elseif($_rev = @filemtime($media_or_wikiFN($id))){
11634f6e20c7SGerrit Uitslag        $_info   = $changelog->getRevisionInfo($_rev);
116495b451bcSAdrian Lang        if($_info['user']){
1165d317fb5dSAnika Henke            $_user = '<bdi>'.editorinfo($_info['user']).'</bdi>';
1166d317fb5dSAnika Henke            if(auth_ismanager()) $_user .= ' <bdo dir="ltr">('.$_info['ip'].')</bdo>';
116795b451bcSAdrian Lang        } else {
1168d317fb5dSAnika Henke            $_user = '<bdo dir="ltr">'.$_info['ip'].'</bdo>';
116995b451bcSAdrian Lang        }
117095b451bcSAdrian Lang        $_user = '<span class="user">'.$_user.'</span>';
1171d317fb5dSAnika Henke        $_sum  = ($_info['sum']) ? '<span class="sum"><bdi>'.hsc($_info['sum']).'</span></bdi>' : '';
117295b451bcSAdrian Lang        if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
117395b451bcSAdrian Lang
1174699c5072SAnika Henke        $r_head_title = ($media) ? dformat($_rev) : $id.' ['.dformat($_rev).']';
1175d317fb5dSAnika Henke        $r_head  = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id).'">'.
1176d317fb5dSAnika Henke        $r_head_title.'</a></bdi> '.
117795b451bcSAdrian Lang        '('.$lang['current'].')'.
1178f76724a4STom N Harris        $head_separator.$_user.' '.$_sum;
117995b451bcSAdrian Lang    }else{
118095b451bcSAdrian Lang        $r_head = '&mdash; ('.$lang['current'].')';
118195b451bcSAdrian Lang    }
118295b451bcSAdrian Lang
118395b451bcSAdrian Lang    return array($l_head, $r_head, $l_minor, $r_minor);
118495b451bcSAdrian Lang}
118595b451bcSAdrian Lang
118615fae107Sandi/**
118704e99fe1SGerrit Uitslag * Show diff
1188baf0c3e5SGerrit Uitslag * between current page version and provided $text
1189baf0c3e5SGerrit Uitslag * or between the revisions provided via GET or POST
119015fae107Sandi *
119115fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1192baf0c3e5SGerrit Uitslag * @param  string $text  when non-empty: compare with this text with most current version
119304e99fe1SGerrit Uitslag * @param  bool   $intro display the intro text
11948d5e837eSMichael Hamann * @param  string $type  type of the diff (inline or sidebyside)
119515fae107Sandi */
119672165381SAndreas Gohrfunction html_diff($text = '', $intro = true, $type = null) {
1197f3f0262cSandi    global $ID;
1198f3f0262cSandi    global $REV;
1199f3f0262cSandi    global $lang;
1200f0859d4bSTom N Harris    global $INPUT;
12013c94d07bSAnika Henke    global $INFO;
1202047bad06SGerrit Uitslag    $pagelog = new PageChangeLog($ID);
1203e1bd90ffSAndreas Gohr
1204c7686ac1SGerrit Uitslag    /*
1205c7686ac1SGerrit Uitslag     * Determine diff type
1206c7686ac1SGerrit Uitslag     */
12073c94d07bSAnika Henke    if(!$type) {
12083c94d07bSAnika Henke        $type = $INPUT->str('difftype');
12093c94d07bSAnika Henke        if(empty($type)) {
12103c94d07bSAnika Henke            $type = get_doku_pref('difftype', $type);
12113c94d07bSAnika Henke            if(empty($type) && $INFO['ismobile']) {
12123c94d07bSAnika Henke                $type = 'inline';
12133c94d07bSAnika Henke            }
12143c94d07bSAnika Henke        }
12153c94d07bSAnika Henke    }
121672165381SAndreas Gohr    if($type != 'inline') $type = 'sidebyside';
121772165381SAndreas Gohr
1218c7686ac1SGerrit Uitslag    /*
1219c7686ac1SGerrit Uitslag     * Determine requested revision(s)
1220c7686ac1SGerrit Uitslag     */
122177707b04SAndreas Gohr    // we're trying to be clever here, revisions to compare can be either
122277707b04SAndreas Gohr    // given as rev and rev2 parameters, with rev2 being optional. Or in an
122377707b04SAndreas Gohr    // array in rev2.
122477707b04SAndreas Gohr    $rev1 = $REV;
12257b3f8b16SAndreas Gohr
1226f1d7655bSAndreas Gohr    $rev2 = $INPUT->ref('rev2');
1227f1d7655bSAndreas Gohr    if(is_array($rev2)) {
1228f1d7655bSAndreas Gohr        $rev1 = (int) $rev2[0];
1229f1d7655bSAndreas Gohr        $rev2 = (int) $rev2[1];
123054041c77SAndreas Gohr
123154041c77SAndreas Gohr        if(!$rev1) {
123254041c77SAndreas Gohr            $rev1 = $rev2;
123354041c77SAndreas Gohr            unset($rev2);
123454041c77SAndreas Gohr        }
1235f3f0262cSandi    } else {
1236f0859d4bSTom N Harris        $rev2 = $INPUT->int('rev2');
12374d58bd99Sandi    }
12384d58bd99Sandi
1239c7686ac1SGerrit Uitslag    /*
1240c7686ac1SGerrit Uitslag     * Determine left and right revision, its texts and the header
1241c7686ac1SGerrit Uitslag     */
12423733161eSAdrian Lang    $r_minor = '';
12433733161eSAdrian Lang    $l_minor = '';
12443733161eSAdrian Lang
124577707b04SAndreas Gohr    if($text) { // compare text to the most current revision
124677707b04SAndreas Gohr        $l_rev = '';
124777707b04SAndreas Gohr        $l_text = rawWiki($ID, '');
124877707b04SAndreas Gohr        $l_head = '<a class="wikilink1" href="' . wl($ID) . '">' .
1249f2263577SAndreas Gohr            $ID . ' ' . dformat((int) @filemtime(wikiFN($ID))) . '</a> ' .
125077707b04SAndreas Gohr            $lang['current'];
125177707b04SAndreas Gohr
125277707b04SAndreas Gohr        $r_rev = '';
125377707b04SAndreas Gohr        $r_text = cleanText($text);
125477707b04SAndreas Gohr        $r_head = $lang['yours'];
1255e1bd90ffSAndreas Gohr    } else {
12566d9eab4dSMichael Hamann        if($rev1 && isset($rev2) && $rev2) { // two specific revisions wanted
125754041c77SAndreas Gohr            // make sure order is correct (older on the left)
125877707b04SAndreas Gohr            if($rev1 < $rev2) {
125977707b04SAndreas Gohr                $l_rev = $rev1;
126077707b04SAndreas Gohr                $r_rev = $rev2;
126177707b04SAndreas Gohr            } else {
126277707b04SAndreas Gohr                $l_rev = $rev2;
126377707b04SAndreas Gohr                $r_rev = $rev1;
1264e1bd90ffSAndreas Gohr            }
126577707b04SAndreas Gohr        } elseif($rev1) { // single revision given, compare to current
126677707b04SAndreas Gohr            $r_rev = '';
126777707b04SAndreas Gohr            $l_rev = $rev1;
126877707b04SAndreas Gohr        } else { // no revision was given, compare previous to current
126977707b04SAndreas Gohr            $r_rev = '';
1270f523c971SGerrit Uitslag            $revs = $pagelog->getRevisions(0, 1);
127177707b04SAndreas Gohr            $l_rev = $revs[0];
12726f8e9f59SAndreas Gohr            $REV = $l_rev; // store revision back in $REV
127377707b04SAndreas Gohr        }
127477707b04SAndreas Gohr
12757b3f8b16SAndreas Gohr        // when both revisions are empty then the page was created just now
12767b3f8b16SAndreas Gohr        if(!$l_rev && !$r_rev) {
12777b3f8b16SAndreas Gohr            $l_text = '';
12787b3f8b16SAndreas Gohr        } else {
127977707b04SAndreas Gohr            $l_text = rawWiki($ID, $l_rev);
12807b3f8b16SAndreas Gohr        }
128177707b04SAndreas Gohr        $r_text = rawWiki($ID, $r_rev);
128277707b04SAndreas Gohr
1283f76724a4STom N Harris        list($l_head, $r_head, $l_minor, $r_minor) = html_diff_head($l_rev, $r_rev, null, false, $type == 'inline');
128477707b04SAndreas Gohr    }
128577707b04SAndreas Gohr
1286c7686ac1SGerrit Uitslag    /*
1287c7686ac1SGerrit Uitslag     * Build navigation
1288c7686ac1SGerrit Uitslag     */
1289c7686ac1SGerrit Uitslag    $l_nav = '';
1290c7686ac1SGerrit Uitslag    $r_nav = '';
1291c7686ac1SGerrit Uitslag    if(!$text) {
1292baf0c3e5SGerrit Uitslag        list($l_nav, $r_nav) = html_diff_navigation($pagelog, $type, $l_rev, $r_rev);
1293c7686ac1SGerrit Uitslag    }
1294c7686ac1SGerrit Uitslag    /*
1295c7686ac1SGerrit Uitslag     * Create diff object and the formatter
1296c7686ac1SGerrit Uitslag     */
129704e99fe1SGerrit Uitslag    $diff = new Diff(explode("\n", $l_text), explode("\n", $r_text));
129877707b04SAndreas Gohr
129972165381SAndreas Gohr    if($type == 'inline') {
130004e99fe1SGerrit Uitslag        $diffformatter = new InlineDiffFormatter();
130172165381SAndreas Gohr    } else {
130204e99fe1SGerrit Uitslag        $diffformatter = new TableDiffFormatter();
130372165381SAndreas Gohr    }
1304c7686ac1SGerrit Uitslag    /*
1305c7686ac1SGerrit Uitslag     * Display intro
1306c7686ac1SGerrit Uitslag     */
1307c112d578Sandi    if($intro) print p_locale_xhtml('diff');
1308226bf2dcSGina Haeussge
1309c7686ac1SGerrit Uitslag    /*
1310c7686ac1SGerrit Uitslag     * Display type and exact reference
1311c7686ac1SGerrit Uitslag     */
1312226bf2dcSGina Haeussge    if(!$text) {
1313c130b0f8SAnika Henke        ptln('<div class="diffoptions group">');
131472165381SAndreas Gohr
1315c7686ac1SGerrit Uitslag
131672165381SAndreas Gohr        $form = new Doku_Form(array('action' => wl()));
13171b885c58SAndreas Gohr        $form->addHidden('id', $ID);
131872165381SAndreas Gohr        $form->addHidden('rev2[0]', $l_rev);
131972165381SAndreas Gohr        $form->addHidden('rev2[1]', $r_rev);
132072165381SAndreas Gohr        $form->addHidden('do', 'diff');
132104e99fe1SGerrit Uitslag        $form->addElement(
132204e99fe1SGerrit Uitslag             form_makeListboxField(
132372165381SAndreas Gohr                 'difftype',
132472165381SAndreas Gohr                 array(
132572165381SAndreas Gohr                     'sidebyside' => $lang['diff_side'],
132604e99fe1SGerrit Uitslag                     'inline' => $lang['diff_inline']
132704e99fe1SGerrit Uitslag                 ),
132872165381SAndreas Gohr                 $type,
132972165381SAndreas Gohr                 $lang['diff_type'],
133072165381SAndreas Gohr                 '', '',
133104e99fe1SGerrit Uitslag                 array('class' => 'quickselect')
133204e99fe1SGerrit Uitslag             )
133304e99fe1SGerrit Uitslag        );
133472165381SAndreas Gohr        $form->addElement(form_makeButton('submit', 'diff', 'Go'));
133572165381SAndreas Gohr        $form->printForm();
133672165381SAndreas Gohr
13374fc1354aSGerrit Uitslag        ptln('<p>');
13384fc1354aSGerrit Uitslag        // link to exactly this view FS#2835
13398fcb305dSGerrit Uitslag        echo html_diff_navigationlink($type, 'difflink', $l_rev, $r_rev ? $r_rev : $INFO['currentrev']);
134098a6b214SAnika Henke        ptln('</p>');
1341cfe2f202SGerrit Uitslag
1342cfe2f202SGerrit Uitslag        ptln('</div>'); // .diffoptions
134304e99fe1SGerrit Uitslag    }
1344f1f2f711SGerrit Uitslag
134551684808SGerrit Uitslag    /*
1346c7686ac1SGerrit Uitslag     * Display diff view table
134751684808SGerrit Uitslag     */
1348f3f0262cSandi    ?>
1349c7b28ffdSAnika Henke    <div class="table">
135072165381SAndreas Gohr    <table class="diff diff_<?php echo $type ?>">
1351c7686ac1SGerrit Uitslag
135204e99fe1SGerrit Uitslag        <?php
1353c7686ac1SGerrit Uitslag        //navigation and header
1354cfe2f202SGerrit Uitslag        if($type == 'inline') {
1355cfe2f202SGerrit Uitslag            if(!$text) { ?>
1356cfe2f202SGerrit Uitslag                <tr>
1357cfe2f202SGerrit Uitslag                    <td class="diff-lineheader">-</td>
1358cfe2f202SGerrit Uitslag                    <td class="diffnav"><?php echo $l_nav ?></td>
1359cfe2f202SGerrit Uitslag                </tr>
1360f76724a4STom N Harris                <tr>
136104e99fe1SGerrit Uitslag                    <th class="diff-lineheader">-</th>
136204e99fe1SGerrit Uitslag                    <th <?php echo $l_minor ?>>
1363f76724a4STom N Harris                        <?php echo $l_head ?>
1364f76724a4STom N Harris                    </th>
1365f76724a4STom N Harris                </tr>
1366cfe2f202SGerrit Uitslag            <?php } ?>
1367cfe2f202SGerrit Uitslag            <tr>
1368cfe2f202SGerrit Uitslag                <td class="diff-lineheader">+</td>
1369cfe2f202SGerrit Uitslag                <td class="diffnav"><?php echo $r_nav ?></td>
1370cfe2f202SGerrit Uitslag            </tr>
1371f76724a4STom N Harris            <tr>
137204e99fe1SGerrit Uitslag                <th class="diff-lineheader">+</th>
137304e99fe1SGerrit Uitslag                <th <?php echo $r_minor ?>>
1374f76724a4STom N Harris                    <?php echo $r_head ?>
1375f76724a4STom N Harris                </th>
1376f76724a4STom N Harris            </tr>
1377cfe2f202SGerrit Uitslag        <?php } else {
1378cfe2f202SGerrit Uitslag            if(!$text) { ?>
1379cfe2f202SGerrit Uitslag                <tr>
1380cfe2f202SGerrit Uitslag                    <td colspan="2" class="diffnav"><?php echo $l_nav ?></td>
1381cfe2f202SGerrit Uitslag                    <td colspan="2" class="diffnav"><?php echo $r_nav ?></td>
1382cfe2f202SGerrit Uitslag                </tr>
1383cfe2f202SGerrit Uitslag            <?php } ?>
1384f3f0262cSandi            <tr>
1385e5e61eb0SAnika Henke                <th colspan="2" <?php echo $l_minor ?>>
138677707b04SAndreas Gohr                    <?php echo $l_head ?>
1387daf4ca4eSAnika Henke                </th>
1388e5e61eb0SAnika Henke                <th colspan="2" <?php echo $r_minor ?>>
138977707b04SAndreas Gohr                    <?php echo $r_head ?>
1390daf4ca4eSAnika Henke                </th>
1391f3f0262cSandi            </tr>
1392f76724a4STom N Harris        <?php }
1393c7686ac1SGerrit Uitslag
1394c7686ac1SGerrit Uitslag        //diff view
139504e99fe1SGerrit Uitslag        echo html_insert_softbreaks($diffformatter->format($diff)); ?>
1396c7686ac1SGerrit Uitslag
1397f3f0262cSandi    </table>
1398c7b28ffdSAnika Henke    </div>
13994da078a3Smatthiasgrimm<?php
1400f3f0262cSandi}
1401f3f0262cSandi
14024fc1354aSGerrit Uitslag/**
1403baf0c3e5SGerrit Uitslag * Create html for revision navigation
1404baf0c3e5SGerrit Uitslag *
1405baf0c3e5SGerrit Uitslag * @param PageChangeLog $pagelog changelog object of current page
1406baf0c3e5SGerrit Uitslag * @param string        $type    inline vs sidebyside
1407baf0c3e5SGerrit Uitslag * @param int           $l_rev   left revision timestamp
1408baf0c3e5SGerrit Uitslag * @param int           $r_rev   right revision timestamp
1409baf0c3e5SGerrit Uitslag * @return string[] html of left and right navigation elements
1410baf0c3e5SGerrit Uitslag */
1411baf0c3e5SGerrit Uitslagfunction html_diff_navigation($pagelog, $type, $l_rev, $r_rev) {
1412baf0c3e5SGerrit Uitslag    global $INFO, $ID;
1413baf0c3e5SGerrit Uitslag
14144d5954c8SGerrit Uitslag    // last timestamp is not in changelog, retrieve timestamp from metadata
14154d5954c8SGerrit Uitslag    // note: when page is removed, the metadata timestamp is zero
1416bdca103aSAndreas Gohr    if(!$r_rev) {
1417bdca103aSAndreas Gohr        if(isset($INFO['meta']['last_change']['date'])) {
1418bdca103aSAndreas Gohr            $r_rev = $INFO['meta']['last_change']['date'];
1419bdca103aSAndreas Gohr        } else {
1420bdca103aSAndreas Gohr            $r_rev = 0;
1421bdca103aSAndreas Gohr        }
1422bdca103aSAndreas Gohr    }
1423baf0c3e5SGerrit Uitslag
1424baf0c3e5SGerrit Uitslag    //retrieve revisions with additional info
1425baf0c3e5SGerrit Uitslag    list($l_revs, $r_revs) = $pagelog->getRevisionsAround($l_rev, $r_rev);
1426baf0c3e5SGerrit Uitslag    $l_revisions = array();
1427621bbd2aSGerrit Uitslag    if(!$l_rev) {
1428621bbd2aSGerrit Uitslag        $l_revisions[0] = array(0, "", false); //no left revision given, add dummy
1429621bbd2aSGerrit Uitslag    }
1430baf0c3e5SGerrit Uitslag    foreach($l_revs as $rev) {
1431baf0c3e5SGerrit Uitslag        $info = $pagelog->getRevisionInfo($rev);
1432baf0c3e5SGerrit Uitslag        $l_revisions[$rev] = array(
1433baf0c3e5SGerrit Uitslag            $rev,
1434c006b6aaSGerrit Uitslag            dformat($info['date']) . ' ' . editorinfo($info['user'], true) . ' ' . $info['sum'],
1435621bbd2aSGerrit Uitslag            $r_rev ? $rev >= $r_rev : false //disable?
1436baf0c3e5SGerrit Uitslag        );
1437baf0c3e5SGerrit Uitslag    }
1438baf0c3e5SGerrit Uitslag    $r_revisions = array();
1439621bbd2aSGerrit Uitslag    if(!$r_rev) {
1440621bbd2aSGerrit Uitslag        $r_revisions[0] = array(0, "", false); //no right revision given, add dummy
1441621bbd2aSGerrit Uitslag    }
1442baf0c3e5SGerrit Uitslag    foreach($r_revs as $rev) {
1443baf0c3e5SGerrit Uitslag        $info = $pagelog->getRevisionInfo($rev);
1444baf0c3e5SGerrit Uitslag        $r_revisions[$rev] = array(
1445baf0c3e5SGerrit Uitslag            $rev,
1446c006b6aaSGerrit Uitslag            dformat($info['date']) . ' ' . editorinfo($info['user'], true) . ' ' . $info['sum'],
1447baf0c3e5SGerrit Uitslag            $rev <= $l_rev //disable?
1448baf0c3e5SGerrit Uitslag        );
1449baf0c3e5SGerrit Uitslag    }
1450621bbd2aSGerrit Uitslag
1451baf0c3e5SGerrit Uitslag    //determine previous/next revisions
1452baf0c3e5SGerrit Uitslag    $l_index = array_search($l_rev, $l_revs);
1453baf0c3e5SGerrit Uitslag    $l_prev = $l_revs[$l_index + 1];
1454baf0c3e5SGerrit Uitslag    $l_next = $l_revs[$l_index - 1];
1455621bbd2aSGerrit Uitslag    if($r_rev) {
1456baf0c3e5SGerrit Uitslag        $r_index = array_search($r_rev, $r_revs);
1457baf0c3e5SGerrit Uitslag        $r_prev = $r_revs[$r_index + 1];
1458baf0c3e5SGerrit Uitslag        $r_next = $r_revs[$r_index - 1];
1459621bbd2aSGerrit Uitslag    } else {
1460621bbd2aSGerrit Uitslag        //removed page
1461621bbd2aSGerrit Uitslag        if($l_next) {
1462621bbd2aSGerrit Uitslag            $r_prev = $r_revs[0];
1463621bbd2aSGerrit Uitslag        } else {
1464621bbd2aSGerrit Uitslag            $r_prev = null;
1465621bbd2aSGerrit Uitslag        }
1466621bbd2aSGerrit Uitslag        $r_next = null;
1467621bbd2aSGerrit Uitslag    }
1468baf0c3e5SGerrit Uitslag
1469baf0c3e5SGerrit Uitslag    /*
1470baf0c3e5SGerrit Uitslag     * Left side:
1471baf0c3e5SGerrit Uitslag     */
1472baf0c3e5SGerrit Uitslag    $l_nav = '';
1473baf0c3e5SGerrit Uitslag    //move back
1474baf0c3e5SGerrit Uitslag    if($l_prev) {
1475baf0c3e5SGerrit Uitslag        $l_nav .= html_diff_navigationlink($type, 'diffbothprevrev', $l_prev, $r_prev);
1476baf0c3e5SGerrit Uitslag        $l_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_prev, $r_rev);
1477baf0c3e5SGerrit Uitslag    }
1478baf0c3e5SGerrit Uitslag    //dropdown
1479baf0c3e5SGerrit Uitslag    $form = new Doku_Form(array('action' => wl()));
1480baf0c3e5SGerrit Uitslag    $form->addHidden('id', $ID);
1481baf0c3e5SGerrit Uitslag    $form->addHidden('difftype', $type);
1482baf0c3e5SGerrit Uitslag    $form->addHidden('rev2[1]', $r_rev);
1483baf0c3e5SGerrit Uitslag    $form->addHidden('do', 'diff');
1484baf0c3e5SGerrit Uitslag    $form->addElement(
1485baf0c3e5SGerrit Uitslag         form_makeListboxField(
1486baf0c3e5SGerrit Uitslag             'rev2[0]',
1487baf0c3e5SGerrit Uitslag             $l_revisions,
1488baf0c3e5SGerrit Uitslag             $l_rev,
1489baf0c3e5SGerrit Uitslag             '', '', '',
1490baf0c3e5SGerrit Uitslag             array('class' => 'quickselect')
1491baf0c3e5SGerrit Uitslag         )
1492baf0c3e5SGerrit Uitslag    );
1493baf0c3e5SGerrit Uitslag    $form->addElement(form_makeButton('submit', 'diff', 'Go'));
1494baf0c3e5SGerrit Uitslag    $l_nav .= $form->getForm();
1495baf0c3e5SGerrit Uitslag    //move forward
1496621bbd2aSGerrit Uitslag    if($l_next && ($l_next < $r_rev || !$r_rev)) {
1497baf0c3e5SGerrit Uitslag        $l_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_next, $r_rev);
1498baf0c3e5SGerrit Uitslag    }
1499baf0c3e5SGerrit Uitslag
1500baf0c3e5SGerrit Uitslag    /*
1501baf0c3e5SGerrit Uitslag     * Right side:
1502baf0c3e5SGerrit Uitslag     */
1503baf0c3e5SGerrit Uitslag    $r_nav = '';
1504baf0c3e5SGerrit Uitslag    //move back
1505baf0c3e5SGerrit Uitslag    if($l_rev < $r_prev) {
1506baf0c3e5SGerrit Uitslag        $r_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_rev, $r_prev);
1507baf0c3e5SGerrit Uitslag    }
1508baf0c3e5SGerrit Uitslag    //dropdown
1509baf0c3e5SGerrit Uitslag    $form = new Doku_Form(array('action' => wl()));
1510baf0c3e5SGerrit Uitslag    $form->addHidden('id', $ID);
1511baf0c3e5SGerrit Uitslag    $form->addHidden('rev2[0]', $l_rev);
1512baf0c3e5SGerrit Uitslag    $form->addHidden('difftype', $type);
1513baf0c3e5SGerrit Uitslag    $form->addHidden('do', 'diff');
1514baf0c3e5SGerrit Uitslag    $form->addElement(
1515baf0c3e5SGerrit Uitslag         form_makeListboxField(
1516baf0c3e5SGerrit Uitslag             'rev2[1]',
1517baf0c3e5SGerrit Uitslag             $r_revisions,
1518baf0c3e5SGerrit Uitslag             $r_rev,
1519baf0c3e5SGerrit Uitslag             '', '', '',
1520baf0c3e5SGerrit Uitslag             array('class' => 'quickselect')
1521baf0c3e5SGerrit Uitslag         )
1522baf0c3e5SGerrit Uitslag    );
1523baf0c3e5SGerrit Uitslag    $form->addElement(form_makeButton('submit', 'diff', 'Go'));
1524baf0c3e5SGerrit Uitslag    $r_nav .= $form->getForm();
1525baf0c3e5SGerrit Uitslag    //move forward
1526baf0c3e5SGerrit Uitslag    if($r_next) {
1527baf0c3e5SGerrit Uitslag        if($pagelog->isCurrentRevision($r_next)) {
1528baf0c3e5SGerrit Uitslag            $r_nav .= html_diff_navigationlink($type, 'difflastrev', $l_rev); //last revision is diff with current page
1529baf0c3e5SGerrit Uitslag        } else {
1530baf0c3e5SGerrit Uitslag            $r_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_rev, $r_next);
1531baf0c3e5SGerrit Uitslag        }
1532baf0c3e5SGerrit Uitslag        $r_nav .= html_diff_navigationlink($type, 'diffbothnextrev', $l_next, $r_next);
1533baf0c3e5SGerrit Uitslag    }
1534baf0c3e5SGerrit Uitslag    return array($l_nav, $r_nav);
1535baf0c3e5SGerrit Uitslag}
1536baf0c3e5SGerrit Uitslag
1537baf0c3e5SGerrit Uitslag/**
15384fc1354aSGerrit Uitslag * Create html link to a diff defined by two revisions
15394fc1354aSGerrit Uitslag *
154098a6b214SAnika Henke * @param string $difftype display type
154198a6b214SAnika Henke * @param string $linktype
15424fc1354aSGerrit Uitslag * @param int $lrev oldest revision
15434fc1354aSGerrit Uitslag * @param int $rrev newest revision or null for diff with current revision
15444fc1354aSGerrit Uitslag * @return string html of link to a diff
15454fc1354aSGerrit Uitslag */
154698a6b214SAnika Henkefunction html_diff_navigationlink($difftype, $linktype, $lrev, $rrev = null) {
154798a6b214SAnika Henke    global $ID, $lang;
1548621bbd2aSGerrit Uitslag    if(!$rrev) {
15494fc1354aSGerrit Uitslag        $urlparam = array(
15504fc1354aSGerrit Uitslag            'do' => 'diff',
15514fc1354aSGerrit Uitslag            'rev' => $lrev,
155298a6b214SAnika Henke            'difftype' => $difftype,
15534fc1354aSGerrit Uitslag        );
15544fc1354aSGerrit Uitslag    } else {
15554fc1354aSGerrit Uitslag        $urlparam = array(
15564fc1354aSGerrit Uitslag            'do' => 'diff',
15574fc1354aSGerrit Uitslag            'rev2[0]' => $lrev,
15584fc1354aSGerrit Uitslag            'rev2[1]' => $rrev,
155998a6b214SAnika Henke            'difftype' => $difftype,
15604fc1354aSGerrit Uitslag        );
15614fc1354aSGerrit Uitslag    }
1562cfe2f202SGerrit Uitslag    return  '<a class="' . $linktype . '" href="' . wl($ID, $urlparam) . '" title="' . $lang[$linktype] . '">' .
1563cfe2f202SGerrit Uitslag                '<span>' . $lang[$linktype] . '</span>' .
1564cfe2f202SGerrit Uitslag            '</a>' . "\n";
15654fc1354aSGerrit Uitslag}
15664fc1354aSGerrit Uitslag
1567a8397511SGerrit Uitslag/**
1568a8397511SGerrit Uitslag * Insert soft breaks in diff html
1569a8397511SGerrit Uitslag *
157042ea7f44SGerrit Uitslag * @param string $diffhtml
1571a8397511SGerrit Uitslag * @return string
1572a8397511SGerrit Uitslag */
1573fcfecb69SChristopher Smithfunction html_insert_softbreaks($diffhtml) {
1574fcfecb69SChristopher Smith    // search the diff html string for both:
1575fcfecb69SChristopher Smith    // - html tags, so these can be ignored
1576fcfecb69SChristopher Smith    // - long strings of characters without breaking characters
1577fcfecb69SChristopher Smith    return preg_replace_callback('/<[^>]*>|[^<> ]{12,}/','html_softbreak_callback',$diffhtml);
1578fcfecb69SChristopher Smith}
1579fcfecb69SChristopher Smith
1580a8397511SGerrit Uitslag/**
1581a8397511SGerrit Uitslag * callback which adds softbreaks
1582a8397511SGerrit Uitslag *
1583a8397511SGerrit Uitslag * @param array $match array with first the complete match
1584a8397511SGerrit Uitslag * @return string the replacement
1585a8397511SGerrit Uitslag */
1586fcfecb69SChristopher Smithfunction html_softbreak_callback($match){
1587fcfecb69SChristopher Smith    // if match is an html tag, return it intact
15882401f18dSSyntaxseed    if ($match[0][0] == '<') return $match[0];
1589fcfecb69SChristopher Smith
1590fcfecb69SChristopher Smith    // its a long string without a breaking character,
1591fcfecb69SChristopher Smith    // make certain characters into breaking characters by inserting a
159254436b19Sbleistivt    // word break opportunity (<wbr> tag) in front of them.
1593fcfecb69SChristopher Smith    $regex = <<< REGEX
1594fcfecb69SChristopher Smith(?(?=              # start a conditional expression with a positive look ahead ...
1595298a7e08SChristopher Smith&\#?\\w{1,6};)     # ... for html entities - we don't want to split them (ok to catch some invalid combinations)
1596298a7e08SChristopher Smith&\#?\\w{1,6};      # yes pattern - a quicker match for the html entity, since we know we have one
1597fcfecb69SChristopher Smith|
159807a7d21aSChristopher Smith[?/,&\#;:]         # no pattern - any other group of 'special' characters to insert a breaking character after
159907a7d21aSChristopher Smith)+                 # end conditional expression
1600fcfecb69SChristopher SmithREGEX;
1601fcfecb69SChristopher Smith
160254436b19Sbleistivt    return preg_replace('<'.$regex.'>xu','\0<wbr>',$match[0]);
1603fcfecb69SChristopher Smith}
1604fcfecb69SChristopher Smith
160515fae107Sandi/**
160615fae107Sandi * show warning on conflict detection
160715fae107Sandi *
160815fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
160942ea7f44SGerrit Uitslag *
161042ea7f44SGerrit Uitslag * @param string $text
161142ea7f44SGerrit Uitslag * @param string $summary
161215fae107Sandi */
1613f3f0262cSandifunction html_conflict($text,$summary){
1614f3f0262cSandi    global $ID;
1615f3f0262cSandi    global $lang;
1616f3f0262cSandi
1617c112d578Sandi    print p_locale_xhtml('conflict');
1618e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
1619fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
1620fdb8d77bSTom N Harris    $form->addHidden('wikitext', $text);
1621fdb8d77bSTom N Harris    $form->addHidden('summary', $summary);
1622fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
1623fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
1624fdb8d77bSTom N Harris    html_form('conflict', $form);
1625fdb8d77bSTom N Harris    print '<br /><br /><br /><br />'.NL;
1626f3f0262cSandi}
1627f3f0262cSandi
1628f3f0262cSandi/**
162915fae107Sandi * Prints the global message array
163015fae107Sandi *
163115fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1632f3f0262cSandi */
1633f3f0262cSandifunction html_msgarea(){
1634cc58224cSMichael Hamann    global $MSG, $MSG_shown;
16358d5e837eSMichael Hamann    /** @var array $MSG */
1636cc58224cSMichael Hamann    // store if the global $MSG has already been shown and thus HTML output has been started
1637cc58224cSMichael Hamann    $MSG_shown = true;
1638cc58224cSMichael Hamann
1639f3f0262cSandi    if(!isset($MSG)) return;
1640f3f0262cSandi
16414af9f0d4SAndreas Gohr    $shown = array();
1642f3f0262cSandi    foreach($MSG as $msg){
16434af9f0d4SAndreas Gohr        $hash = md5($msg['msg']);
16444af9f0d4SAndreas Gohr        if(isset($shown[$hash])) continue; // skip double messages
1645f755f9abSChristopher Smith        if(info_msg_allowed($msg)){
1646f3f0262cSandi            print '<div class="'.$msg['lvl'].'">';
1647f3f0262cSandi            print $msg['msg'];
1648f3f0262cSandi            print '</div>';
1649d3bae478SChristopher Smith        }
16504af9f0d4SAndreas Gohr        $shown[$hash] = 1;
1651f3f0262cSandi    }
1652cc58224cSMichael Hamann
1653cc58224cSMichael Hamann    unset($GLOBALS['MSG']);
1654f3f0262cSandi}
1655f3f0262cSandi
1656f3f0262cSandi/**
1657f3f0262cSandi * Prints the registration form
165815fae107Sandi *
165915fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1660f3f0262cSandi */
1661f3f0262cSandifunction html_register(){
1662f3f0262cSandi    global $lang;
1663cab2716aSmatthias.grimm    global $conf;
1664f0859d4bSTom N Harris    global $INPUT;
1665f3f0262cSandi
1666a669bfe0SChristopher Smith    $base_attrs = array('size'=>50,'required'=>'required');
1667a669bfe0SChristopher Smith    $email_attrs = $base_attrs + array('type'=>'email','class'=>'edit');
1668a669bfe0SChristopher Smith
1669c112d578Sandi    print p_locale_xhtml('register');
1670fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1671e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__register'));
1672bf413a4eSAnika Henke    $form->startFieldset($lang['btn_register']);
1673fdb8d77bSTom N Harris    $form->addHidden('do', 'register');
1674fdb8d77bSTom N Harris    $form->addHidden('save', '1');
167564159a61SAndreas Gohr    $form->addElement(
167664159a61SAndreas Gohr        form_makeTextField(
167764159a61SAndreas Gohr            'login',
167864159a61SAndreas Gohr            $INPUT->post->str('login'),
167964159a61SAndreas Gohr            $lang['user'],
168064159a61SAndreas Gohr            '',
168164159a61SAndreas Gohr            'block',
168264159a61SAndreas Gohr            $base_attrs
168364159a61SAndreas Gohr        )
168464159a61SAndreas Gohr    );
1685cab2716aSmatthias.grimm    if (!$conf['autopasswd']) {
1686a669bfe0SChristopher Smith        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', $base_attrs));
1687a669bfe0SChristopher Smith        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', $base_attrs));
1688cab2716aSmatthias.grimm    }
168964159a61SAndreas Gohr    $form->addElement(
169064159a61SAndreas Gohr        form_makeTextField(
169164159a61SAndreas Gohr            'fullname',
169264159a61SAndreas Gohr            $INPUT->post->str('fullname'),
169364159a61SAndreas Gohr            $lang['fullname'],
169464159a61SAndreas Gohr            '',
169564159a61SAndreas Gohr            'block',
169664159a61SAndreas Gohr            $base_attrs
169764159a61SAndreas Gohr        )
169864159a61SAndreas Gohr    );
169964159a61SAndreas Gohr    $form->addElement(
170064159a61SAndreas Gohr        form_makeField(
170164159a61SAndreas Gohr            'email',
170264159a61SAndreas Gohr            'email',
170364159a61SAndreas Gohr            $INPUT->post->str('email'),
170464159a61SAndreas Gohr            $lang['email'],
170564159a61SAndreas Gohr            '',
170664159a61SAndreas Gohr            'block',
170764159a61SAndreas Gohr            $email_attrs
170864159a61SAndreas Gohr        )
170964159a61SAndreas Gohr    );
1710bf413a4eSAnika Henke    $form->addElement(form_makeButton('submit', '', $lang['btn_register']));
1711fdb8d77bSTom N Harris    $form->endFieldset();
1712fdb8d77bSTom N Harris    html_form('register', $form);
1713cab2716aSmatthias.grimm
1714fdb8d77bSTom N Harris    print '</div>'.NL;
1715f3f0262cSandi}
1716f3f0262cSandi
1717f3f0262cSandi/**
17188b06d178Schris * Print the update profile form
17198b06d178Schris *
17208b06d178Schris * @author Christopher Smith <chris@jalakai.co.uk>
17218b06d178Schris * @author Andreas Gohr <andi@splitbrain.org>
17228b06d178Schris */
17238b06d178Schrisfunction html_updateprofile(){
17248b06d178Schris    global $lang;
17258b06d178Schris    global $conf;
1726f0859d4bSTom N Harris    global $INPUT;
17278b06d178Schris    global $INFO;
1728e1d9dcc8SAndreas Gohr    /** @var AuthPlugin $auth */
172982fd59b6SAndreas Gohr    global $auth;
17308b06d178Schris
17318b06d178Schris    print p_locale_xhtml('updateprofile');
17323b1338ffSChristopher Smith    print '<div class="centeralign">'.NL;
17338b06d178Schris
1734f0859d4bSTom N Harris    $fullname = $INPUT->post->str('fullname', $INFO['userinfo']['name'], true);
1735f0859d4bSTom N Harris    $email = $INPUT->post->str('email', $INFO['userinfo']['mail'], true);
1736e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__register'));
1737fdb8d77bSTom N Harris    $form->startFieldset($lang['profile']);
1738fdb8d77bSTom N Harris    $form->addHidden('do', 'profile');
1739fdb8d77bSTom N Harris    $form->addHidden('save', '1');
174064159a61SAndreas Gohr    $form->addElement(
174164159a61SAndreas Gohr        form_makeTextField(
174264159a61SAndreas Gohr            'login',
174364159a61SAndreas Gohr            $_SERVER['REMOTE_USER'],
174464159a61SAndreas Gohr            $lang['user'],
174564159a61SAndreas Gohr            '',
174664159a61SAndreas Gohr            'block',
174764159a61SAndreas Gohr            array('size' => '50', 'disabled' => 'disabled')
174864159a61SAndreas Gohr        )
174964159a61SAndreas Gohr    );
1750fdb8d77bSTom N Harris    $attr = array('size'=>'50');
1751fdb8d77bSTom N Harris    if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1752f0859d4bSTom N Harris    $form->addElement(form_makeTextField('fullname', $fullname, $lang['fullname'], '', 'block', $attr));
17533b1338ffSChristopher Smith    $attr = array('size'=>'50', 'class'=>'edit');
175439ba8890SAndreas Gohr    if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
17553b1338ffSChristopher Smith    $form->addElement(form_makeField('email','email', $email, $lang['email'], '', 'block', $attr));
1756fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1757fdb8d77bSTom N Harris    if ($auth->canDo('modPass')) {
1758fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1759fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1760fdb8d77bSTom N Harris    }
1761fdb8d77bSTom N Harris    if ($conf['profileconfirm']) {
1762fdb8d77bSTom N Harris        $form->addElement(form_makeTag('br'));
176364159a61SAndreas Gohr        $form->addElement(
176464159a61SAndreas Gohr            form_makePasswordField(
176564159a61SAndreas Gohr                'oldpass',
176664159a61SAndreas Gohr                $lang['oldpass'],
176764159a61SAndreas Gohr                '',
176864159a61SAndreas Gohr                'block',
176964159a61SAndreas Gohr                array('size' => '50', 'required' => 'required')
177064159a61SAndreas Gohr            )
177164159a61SAndreas Gohr        );
1772fdb8d77bSTom N Harris    }
1773fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1774fdb8d77bSTom N Harris    $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
17753b1338ffSChristopher Smith
1776fdb8d77bSTom N Harris    $form->endFieldset();
1777fdb8d77bSTom N Harris    html_form('updateprofile', $form);
17782a7abf2dSChristopher Smith
17792a7abf2dSChristopher Smith    if ($auth->canDo('delUser') && actionOK('profile_delete')) {
17802a7abf2dSChristopher Smith        $form_profiledelete = new Doku_Form(array('id' => 'dw__profiledelete'));
17812a7abf2dSChristopher Smith        $form_profiledelete->startFieldset($lang['profdeleteuser']);
17822a7abf2dSChristopher Smith        $form_profiledelete->addHidden('do', 'profile_delete');
17832a7abf2dSChristopher Smith        $form_profiledelete->addHidden('delete', '1');
178464159a61SAndreas Gohr        $form_profiledelete->addElement(
178564159a61SAndreas Gohr            form_makeCheckboxField(
178664159a61SAndreas Gohr                'confirm_delete',
178764159a61SAndreas Gohr                '1',
178864159a61SAndreas Gohr                $lang['profconfdelete'],
178964159a61SAndreas Gohr                'dw__confirmdelete',
179064159a61SAndreas Gohr                '',
179164159a61SAndreas Gohr                array('required' => 'required')
179264159a61SAndreas Gohr            )
179364159a61SAndreas Gohr        );
17942a7abf2dSChristopher Smith        if ($conf['profileconfirm']) {
17952a7abf2dSChristopher Smith            $form_profiledelete->addElement(form_makeTag('br'));
179664159a61SAndreas Gohr            $form_profiledelete->addElement(
179764159a61SAndreas Gohr                form_makePasswordField(
179864159a61SAndreas Gohr                    'oldpass',
179964159a61SAndreas Gohr                    $lang['oldpass'],
180064159a61SAndreas Gohr                    '',
180164159a61SAndreas Gohr                    'block',
180264159a61SAndreas Gohr                    array('size' => '50', 'required' => 'required')
180364159a61SAndreas Gohr                )
180464159a61SAndreas Gohr            );
18052a7abf2dSChristopher Smith        }
18062a7abf2dSChristopher Smith        $form_profiledelete->addElement(form_makeButton('submit', '', $lang['btn_deleteuser']));
18072a7abf2dSChristopher Smith        $form_profiledelete->endFieldset();
18082a7abf2dSChristopher Smith
18092a7abf2dSChristopher Smith        html_form('profiledelete', $form_profiledelete);
18102a7abf2dSChristopher Smith    }
18112a7abf2dSChristopher Smith
1812fdb8d77bSTom N Harris    print '</div>'.NL;
18138b06d178Schris}
18148b06d178Schris
18158b06d178Schris/**
18167c4635c4SAdrian Lang * Preprocess edit form data
181715fae107Sandi *
181815fae107Sandi * @author   Andreas Gohr <andi@splitbrain.org>
18192ffea8f2SAdrian Lang *
18202ffea8f2SAdrian Lang * @triggers HTML_EDITFORM_OUTPUT
1821f3f0262cSandi */
18225a932e77SAdrian Langfunction html_edit(){
1823f0859d4bSTom N Harris    global $INPUT;
1824f3f0262cSandi    global $ID;
1825f3f0262cSandi    global $REV;
1826f3f0262cSandi    global $DATE;
1827f3f0262cSandi    global $PRE;
1828f3f0262cSandi    global $SUF;
1829f3f0262cSandi    global $INFO;
1830f3f0262cSandi    global $SUM;
1831f3f0262cSandi    global $lang;
1832f3f0262cSandi    global $conf;
183345a99335SAdrian Lang    global $TEXT;
1834f3f0262cSandi
1835f0859d4bSTom N Harris    if ($INPUT->has('changecheck')) {
1836f0859d4bSTom N Harris        $check = $INPUT->str('changecheck');
183745a99335SAdrian Lang    } elseif(!$INFO['exists']){
183845a99335SAdrian Lang        // $TEXT has been loaded from page template
183945a99335SAdrian Lang        $check = md5('');
18408fe3bb00STom N Harris    } else {
184145a99335SAdrian Lang        $check = md5($TEXT);
18428fe3bb00STom N Harris    }
184345a99335SAdrian Lang    $mod = md5($TEXT) !== $check;
1844f3f0262cSandi
184527eb9321SAnika Henke    $wr = $INFO['writable'] && !$INFO['locked'];
184645a99335SAdrian Lang    $include = 'edit';
1847f3f0262cSandi    if($wr){
1848ffde0ac9SAdrian Lang        if ($REV) $include = 'editrev';
1849f3f0262cSandi    }else{
1850409d7af7SAndreas Gohr        // check pseudo action 'source'
1851409d7af7SAndreas Gohr        if(!actionOK('source')){
1852409d7af7SAndreas Gohr            msg('Command disabled: source',-1);
1853409d7af7SAndreas Gohr            return;
1854409d7af7SAndreas Gohr        }
1855ffde0ac9SAdrian Lang        $include = 'read';
1856f3f0262cSandi    }
18577c4635c4SAdrian Lang
18587c4635c4SAdrian Lang    global $license;
185942c7abd6SAndreas Gohr
1860e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
1861fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
1862fdb8d77bSTom N Harris    $form->addHidden('rev', $REV);
1863fdb8d77bSTom N Harris    $form->addHidden('date', $DATE);
186442de51b1SAdrian Lang    $form->addHidden('prefix', $PRE . '.');
1865fdb8d77bSTom N Harris    $form->addHidden('suffix', $SUF);
1866fdb8d77bSTom N Harris    $form->addHidden('changecheck', $check);
18678e4da260SAdrian Lang
18682ffea8f2SAdrian Lang    $data = array('form' => $form,
18692ffea8f2SAdrian Lang                  'wr'   => $wr,
18702ffea8f2SAdrian Lang                  'media_manager' => true,
1871182ac905SAndreas Gohr                  'target' => ($INPUT->has('target') && $wr) ? $INPUT->str('target') : 'section',
18722ffea8f2SAdrian Lang                  'intro_locale' => $include);
187312c96aceSAdrian Lang
187412c96aceSAdrian Lang    if ($data['target'] !== 'section') {
187512c96aceSAdrian Lang        // Only emit event if page is writable, section edit data is valid and
187612c96aceSAdrian Lang        // edit target is not section.
1877cbb44eabSAndreas Gohr        Event::createAndTrigger('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true);
18782ffea8f2SAdrian Lang    } else {
18792ffea8f2SAdrian Lang        html_edit_form($data);
18802ffea8f2SAdrian Lang    }
1881ffde0ac9SAdrian Lang    if (isset($data['intro_locale'])) {
1882ffde0ac9SAdrian Lang        echo p_locale_xhtml($data['intro_locale']);
1883ffde0ac9SAdrian Lang    }
18848e4da260SAdrian Lang
1885b7eccc60SAdrian Lang    $form->addHidden('target', $data['target']);
18862571786cSLarsDW223    if ($INPUT->has('hid')) {
18872571786cSLarsDW223        $form->addHidden('hid', $INPUT->str('hid'));
18882571786cSLarsDW223    }
1889ec57f119SLarsDW223    if ($INPUT->has('codeblockOffset')) {
1890ec57f119SLarsDW223        $form->addHidden('codeblockOffset', $INPUT->str('codeblockOffset'));
1891ec57f119SLarsDW223    }
18920607bfeeSAnika Henke    $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar', 'class'=>'editBar')));
1893fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1894fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
1895fdb8d77bSTom N Harris    if ($wr) {
1896fdb8d77bSTom N Harris        $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
189764159a61SAndreas Gohr        $form->addElement(
189864159a61SAndreas Gohr            form_makeButton(
189964159a61SAndreas Gohr                'submit',
190064159a61SAndreas Gohr                'save',
190164159a61SAndreas Gohr                $lang['btn_save'],
190264159a61SAndreas Gohr                array('id' => 'edbtn__save', 'accesskey' => 's', 'tabindex' => '4')
190364159a61SAndreas Gohr            )
190464159a61SAndreas Gohr        );
190564159a61SAndreas Gohr        $form->addElement(
190664159a61SAndreas Gohr            form_makeButton(
190764159a61SAndreas Gohr                'submit',
190864159a61SAndreas Gohr                'preview',
190964159a61SAndreas Gohr                $lang['btn_preview'],
191064159a61SAndreas Gohr                array('id' => 'edbtn__preview', 'accesskey' => 'p', 'tabindex' => '5')
191164159a61SAndreas Gohr            )
191264159a61SAndreas Gohr        );
19133f5c3c1eSAndreas Gohr        $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel'], array('tabindex'=>'6')));
1914fdb8d77bSTom N Harris        $form->addElement(form_makeCloseTag('div'));
1915fdb8d77bSTom N Harris        $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
191664159a61SAndreas Gohr        $form->addElement(
191764159a61SAndreas Gohr            form_makeTextField(
191864159a61SAndreas Gohr                'summary',
191964159a61SAndreas Gohr                $SUM,
192064159a61SAndreas Gohr                $lang['summary'],
192164159a61SAndreas Gohr                'edit__summary',
192264159a61SAndreas Gohr                'nowrap',
192364159a61SAndreas Gohr                array('size' => '50', 'tabindex' => '2')
192464159a61SAndreas Gohr            )
192564159a61SAndreas Gohr        );
1926fdb8d77bSTom N Harris        $elem = html_minoredit();
1927fdb8d77bSTom N Harris        if ($elem) $form->addElement($elem);
1928fdb8d77bSTom N Harris        $form->addElement(form_makeCloseTag('div'));
1929fdb8d77bSTom N Harris    }
1930fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
19315808bc54SAndreas Gohr    if($wr && $conf['license']){
1932066fee30SAndreas Gohr        $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1933066fee30SAndreas Gohr        $out  = $lang['licenseok'];
1934066fee30SAndreas Gohr        $out .= ' <a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
1935507a2aebSAnika Henke        if($conf['target']['extern']) $out .= ' target="'.$conf['target']['extern'].'"';
1936066fee30SAndreas Gohr        $out .= '>'.$license[$conf['license']]['name'].'</a>';
1937066fee30SAndreas Gohr        $form->addElement($out);
1938066fee30SAndreas Gohr        $form->addElement(form_makeCloseTag('div'));
1939066fee30SAndreas Gohr    }
19408e4da260SAdrian Lang
19418e4da260SAdrian Lang    if ($wr) {
19428e4da260SAdrian Lang        // sets changed to true when previewed
1943677d2785SDominik Eckelmann        echo '<script type="text/javascript">/*<![CDATA[*/'. NL;
19448e4da260SAdrian Lang        echo 'textChanged = ' . ($mod ? 'true' : 'false');
1945677d2785SDominik Eckelmann        echo '/*!]]>*/</script>' . NL;
19468e4da260SAdrian Lang    } ?>
19475a99d25bSAnika Henke    <div class="editBox" role="application">
19488e4da260SAdrian Lang
19498a65ef2eSAnika Henke    <div class="toolbar group">
195064159a61SAndreas Gohr        <div id="tool__bar" class="tool__bar"><?php
195164159a61SAndreas Gohr            if ($wr && $data['media_manager']){
195264159a61SAndreas Gohr                ?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
195364159a61SAndreas Gohr                target="_blank"><?php echo $lang['mediaselect'] ?></a><?php
19549ddafcedSAndreas Gohr            }?>
19559ddafcedSAndreas Gohr        </div>
1956c49e647bSMichael Große    </div>
19570aabe6f8SMichael Große    <div id="draft__status" class="draft__status">
19580aabe6f8SMichael Große        <?php
19590aabe6f8SMichael Große        $draft = new \dokuwiki\Draft($ID, $INFO['client']);
19600aabe6f8SMichael Große        if ($draft->isDraftAvailable()) {
19610aabe6f8SMichael Große            echo $draft->getDraftMessage();
19620aabe6f8SMichael Große        }
19630aabe6f8SMichael Große        ?>
19648e4da260SAdrian Lang    </div>
19658e4da260SAdrian Lang    <?php
19668e4da260SAdrian Lang
1967fdb8d77bSTom N Harris    html_form('edit', $form);
1968fdb8d77bSTom N Harris    print '</div>'.NL;
1969f3f0262cSandi}
1970f3f0262cSandi
1971f3f0262cSandi/**
19728e4da260SAdrian Lang * Display the default edit form
19738e4da260SAdrian Lang *
19748e4da260SAdrian Lang * Is the default action for HTML_EDIT_FORMSELECTION.
197542ea7f44SGerrit Uitslag *
1976baf0c3e5SGerrit Uitslag * @param mixed[] $param
19778e4da260SAdrian Lang */
19788e4da260SAdrian Langfunction html_edit_form($param) {
197945a99335SAdrian Lang    global $TEXT;
198012c96aceSAdrian Lang
198112c96aceSAdrian Lang    if ($param['target'] !== 'section') {
1982ff711734SAndreas Gohr        msg('No editor for edit target ' . hsc($param['target']) . ' found.', -1);
198312c96aceSAdrian Lang    }
198412c96aceSAdrian Lang
19858e4da260SAdrian Lang    $attr = array('tabindex'=>'1');
198612c96aceSAdrian Lang    if (!$param['wr']) $attr['readonly'] = 'readonly';
198712c96aceSAdrian Lang
198812c96aceSAdrian Lang    $param['form']->addElement(form_makeWikiText($TEXT, $attr));
19898e4da260SAdrian Lang}
19908e4da260SAdrian Lang
19918e4da260SAdrian Lang/**
1992b6912aeaSAndreas Gohr * Adds a checkbox for minor edits for logged in users
1993b6912aeaSAndreas Gohr *
1994b1f92db2SAdrian Lang * @author Andreas Gohr <andi@splitbrain.org>
199542ea7f44SGerrit Uitslag *
199642ea7f44SGerrit Uitslag * @return array|bool
1997b6912aeaSAndreas Gohr */
1998b6912aeaSAndreas Gohrfunction html_minoredit(){
1999b6912aeaSAndreas Gohr    global $conf;
2000b6912aeaSAndreas Gohr    global $lang;
2001f0859d4bSTom N Harris    global $INPUT;
2002b6912aeaSAndreas Gohr    // minor edits are for logged in users only
2003b6912aeaSAndreas Gohr    if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
2004fdb8d77bSTom N Harris        return false;
2005b6912aeaSAndreas Gohr    }
2006b6912aeaSAndreas Gohr
2007b6912aeaSAndreas Gohr    $p = array();
2008b6912aeaSAndreas Gohr    $p['tabindex'] = 3;
2009f0859d4bSTom N Harris    if($INPUT->bool('minor')) $p['checked']='checked';
2010fdb8d77bSTom N Harris    return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
2011b6912aeaSAndreas Gohr}
2012b6912aeaSAndreas Gohr
2013b6912aeaSAndreas Gohr/**
2014f3f0262cSandi * prints some debug info
201515fae107Sandi *
201615fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
2017f3f0262cSandi */
2018f3f0262cSandifunction html_debug(){
2019f3f0262cSandi    global $conf;
2020d16a4edaSandi    global $lang;
2021e1d9dcc8SAndreas Gohr    /** @var AuthPlugin $auth */
20225298a619SAndreas Gohr    global $auth;
2023100a97e3SAndreas Gohr    global $INFO;
2024100a97e3SAndreas Gohr
202528fb55ffSandi    //remove sensitive data
202628fb55ffSandi    $cnf = $conf;
202724297a69SAndreas Gohr    debug_guard($cnf);
2028100a97e3SAndreas Gohr    $nfo = $INFO;
202924297a69SAndreas Gohr    debug_guard($nfo);
2030100a97e3SAndreas Gohr    $ses = $_SESSION;
203124297a69SAndreas Gohr    debug_guard($ses);
2032f3f0262cSandi
2033f3f0262cSandi    print '<html><body>';
2034f3f0262cSandi
2035f3f0262cSandi    print '<p>When reporting bugs please send all the following ';
2036f3f0262cSandi    print 'output as a mail to andi@splitbrain.org ';
2037f3f0262cSandi    print 'The best way to do this is to save this page in your browser</p>';
2038f3f0262cSandi
2039100a97e3SAndreas Gohr    print '<b>$INFO:</b><pre>';
2040100a97e3SAndreas Gohr    print_r($nfo);
2041100a97e3SAndreas Gohr    print '</pre>';
2042100a97e3SAndreas Gohr
2043f3f0262cSandi    print '<b>$_SERVER:</b><pre>';
2044f3f0262cSandi    print_r($_SERVER);
2045f3f0262cSandi    print '</pre>';
2046f3f0262cSandi
2047f3f0262cSandi    print '<b>$conf:</b><pre>';
204828fb55ffSandi    print_r($cnf);
2049f3f0262cSandi    print '</pre>';
2050f3f0262cSandi
2051ed7b5f09Sandi    print '<b>DOKU_BASE:</b><pre>';
2052ed7b5f09Sandi    print DOKU_BASE;
2053f3f0262cSandi    print '</pre>';
2054f3f0262cSandi
2055ed7b5f09Sandi    print '<b>abs DOKU_BASE:</b><pre>';
2056ed7b5f09Sandi    print DOKU_URL;
2057ed7b5f09Sandi    print '</pre>';
2058ed7b5f09Sandi
2059ed7b5f09Sandi    print '<b>rel DOKU_BASE:</b><pre>';
2060f3f0262cSandi    print dirname($_SERVER['PHP_SELF']).'/';
2061f3f0262cSandi    print '</pre>';
2062f3f0262cSandi
2063f3f0262cSandi    print '<b>PHP Version:</b><pre>';
2064f3f0262cSandi    print phpversion();
2065f3f0262cSandi    print '</pre>';
2066f3f0262cSandi
2067f3f0262cSandi    print '<b>locale:</b><pre>';
2068f3f0262cSandi    print setlocale(LC_ALL,0);
2069f3f0262cSandi    print '</pre>';
2070f3f0262cSandi
2071d16a4edaSandi    print '<b>encoding:</b><pre>';
2072d16a4edaSandi    print $lang['encoding'];
2073d16a4edaSandi    print '</pre>';
2074d16a4edaSandi
20755298a619SAndreas Gohr    if($auth){
20765298a619SAndreas Gohr        print '<b>Auth backend capabilities:</b><pre>';
20772f46ade0SChristopher Smith        foreach ($auth->getCapabilities() as $cando){
20782f46ade0SChristopher Smith            print '   '.str_pad($cando,16) . ' => ' . (int)$auth->canDo($cando) . NL;
20792f46ade0SChristopher Smith        }
20805298a619SAndreas Gohr        print '</pre>';
20815298a619SAndreas Gohr    }
20825298a619SAndreas Gohr
20833aa54d7cSAndreas Gohr    print '<b>$_SESSION:</b><pre>';
2084100a97e3SAndreas Gohr    print_r($ses);
20853aa54d7cSAndreas Gohr    print '</pre>';
20863aa54d7cSAndreas Gohr
2087f3f0262cSandi    print '<b>Environment:</b><pre>';
2088f3f0262cSandi    print_r($_ENV);
2089f3f0262cSandi    print '</pre>';
2090f3f0262cSandi
2091f3f0262cSandi    print '<b>PHP settings:</b><pre>';
2092f3f0262cSandi    $inis = ini_get_all();
2093f3f0262cSandi    print_r($inis);
2094f3f0262cSandi    print '</pre>';
2095f3f0262cSandi
2096e89b7c1eSChristopher Smith    if (function_exists('apache_get_version')) {
209759bc3b48SGerrit Uitslag        $apache = array();
2098e89b7c1eSChristopher Smith        $apache['version'] = apache_get_version();
2099e89b7c1eSChristopher Smith
2100e89b7c1eSChristopher Smith        if (function_exists('apache_get_modules')) {
2101e89b7c1eSChristopher Smith            $apache['modules'] = apache_get_modules();
2102e89b7c1eSChristopher Smith        }
2103e89b7c1eSChristopher Smith        print '<b>Apache</b><pre>';
2104e89b7c1eSChristopher Smith        print_r($apache);
2105e89b7c1eSChristopher Smith        print '</pre>';
2106e89b7c1eSChristopher Smith    }
2107e89b7c1eSChristopher Smith
2108f3f0262cSandi    print '</body></html>';
2109f3f0262cSandi}
2110f3f0262cSandi
211110271ce4SAndreas Gohr/**
21128b06d178Schris * Form to request a new password for an existing account
21138b06d178Schris *
21148b06d178Schris * @author Benoit Chesneau <benoit@bchesneau.info>
2115cc204bbdSAndreas Gohr * @author Andreas Gohr <gohr@cosmocode.de>
211611e2ce22Schris */
21178b06d178Schrisfunction html_resendpwd() {
21188b06d178Schris    global $lang;
21198b06d178Schris    global $conf;
2120f0859d4bSTom N Harris    global $INPUT;
2121c19fe9c0Sandi
2122f0859d4bSTom N Harris    $token = preg_replace('/[^a-f0-9]+/','',$INPUT->str('pwauth'));
2123cc204bbdSAndreas Gohr
2124cc204bbdSAndreas Gohr    if(!$conf['autopasswd'] && $token){
2125cc204bbdSAndreas Gohr        print p_locale_xhtml('resetpwd');
2126cc204bbdSAndreas Gohr        print '<div class="centeralign">'.NL;
2127cc204bbdSAndreas Gohr        $form = new Doku_Form(array('id' => 'dw__resendpwd'));
2128cc204bbdSAndreas Gohr        $form->startFieldset($lang['btn_resendpwd']);
2129cc204bbdSAndreas Gohr        $form->addHidden('token', $token);
2130cc204bbdSAndreas Gohr        $form->addHidden('do', 'resendpwd');
2131cc204bbdSAndreas Gohr
2132cc204bbdSAndreas Gohr        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
2133cc204bbdSAndreas Gohr        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
2134cc204bbdSAndreas Gohr
2135cc204bbdSAndreas Gohr        $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
2136cc204bbdSAndreas Gohr        $form->endFieldset();
2137cc204bbdSAndreas Gohr        html_form('resendpwd', $form);
2138cc204bbdSAndreas Gohr        print '</div>'.NL;
2139cc204bbdSAndreas Gohr    }else{
21408b06d178Schris        print p_locale_xhtml('resendpwd');
2141fdb8d77bSTom N Harris        print '<div class="centeralign">'.NL;
2142e351c80dSAdrian Lang        $form = new Doku_Form(array('id' => 'dw__resendpwd'));
2143fdb8d77bSTom N Harris        $form->startFieldset($lang['resendpwd']);
2144fdb8d77bSTom N Harris        $form->addHidden('do', 'resendpwd');
2145fdb8d77bSTom N Harris        $form->addHidden('save', '1');
2146fdb8d77bSTom N Harris        $form->addElement(form_makeTag('br'));
2147f0859d4bSTom N Harris        $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block'));
2148fdb8d77bSTom N Harris        $form->addElement(form_makeTag('br'));
2149fdb8d77bSTom N Harris        $form->addElement(form_makeTag('br'));
2150fdb8d77bSTom N Harris        $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
2151fdb8d77bSTom N Harris        $form->endFieldset();
2152fdb8d77bSTom N Harris        html_form('resendpwd', $form);
2153fdb8d77bSTom N Harris        print '</div>'.NL;
2154fdb8d77bSTom N Harris    }
2155cc204bbdSAndreas Gohr}
2156cc204bbdSAndreas Gohr
2157fdb8d77bSTom N Harris/**
2158b8595a66SAndreas Gohr * Return the TOC rendered to XHTML
2159b8595a66SAndreas Gohr *
2160b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
216142ea7f44SGerrit Uitslag *
216242ea7f44SGerrit Uitslag * @param array $toc
216342ea7f44SGerrit Uitslag * @return string html
2164b8595a66SAndreas Gohr */
2165b8595a66SAndreas Gohrfunction html_TOC($toc){
2166b8595a66SAndreas Gohr    if(!count($toc)) return '';
2167b8595a66SAndreas Gohr    global $lang;
2168b8595a66SAndreas Gohr    $out  = '<!-- TOC START -->'.DOKU_LF;
2169158a5bffSDeathCamel57    $out .= '<div id="dw__toc" class="dw__toc">'.DOKU_LF;
217048722ac8SAnika Henke    $out .= '<h3 class="toggle">';
2171b8595a66SAndreas Gohr    $out .= $lang['toc'];
2172d5acc30dSAnika Henke    $out .= '</h3>'.DOKU_LF;
2173d5acc30dSAnika Henke    $out .= '<div>'.DOKU_LF;
217487671313SHakan Sandell    $out .= html_buildlist($toc,'toc','html_list_toc','html_li_default',true);
2175b8595a66SAndreas Gohr    $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
2176b8595a66SAndreas Gohr    $out .= '<!-- TOC END -->'.DOKU_LF;
2177db959ae3SAndreas Gohr    return $out;
2178db959ae3SAndreas Gohr}
2179b8595a66SAndreas Gohr
2180b8595a66SAndreas Gohr/**
2181b8595a66SAndreas Gohr * Callback for html_buildlist
218242ea7f44SGerrit Uitslag *
218342ea7f44SGerrit Uitslag * @param array $item
218442ea7f44SGerrit Uitslag * @return string html
2185b8595a66SAndreas Gohr */
2186b8595a66SAndreas Gohrfunction html_list_toc($item){
2187c66972f2SAdrian Lang    if(isset($item['hid'])){
21887d91652aSAndreas Gohr        $link = '#'.$item['hid'];
21897d91652aSAndreas Gohr    }else{
21907d91652aSAndreas Gohr        $link = $item['link'];
21917d91652aSAndreas Gohr    }
21927d91652aSAndreas Gohr
2193d5acc30dSAnika Henke    return '<a href="'.$link.'">'.hsc($item['title']).'</a>';
2194b8595a66SAndreas Gohr}
2195b8595a66SAndreas Gohr
2196b8595a66SAndreas Gohr/**
2197b8595a66SAndreas Gohr * Helper function to build TOC items
2198b8595a66SAndreas Gohr *
2199b8595a66SAndreas Gohr * Returns an array ready to be added to a TOC array
2200b8595a66SAndreas Gohr *
2201b8595a66SAndreas Gohr * @param string $link  - where to link (if $hash set to '#' it's a local anchor)
2202b8595a66SAndreas Gohr * @param string $text  - what to display in the TOC
2203b8595a66SAndreas Gohr * @param int    $level - nesting level
2204b8595a66SAndreas Gohr * @param string $hash  - is prepended to the given $link, set blank if you want full links
22058d5e837eSMichael Hamann * @return array the toc item
2206b8595a66SAndreas Gohr */
2207b8595a66SAndreas Gohrfunction html_mktocitem($link, $text, $level, $hash='#'){
2208b8595a66SAndreas Gohr    return  array( 'link'  => $hash.$link,
2209b8595a66SAndreas Gohr            'title' => $text,
2210b8595a66SAndreas Gohr            'type'  => 'ul',
22112bb0d541Schris            'level' => $level);
2212b8595a66SAndreas Gohr}
2213b8595a66SAndreas Gohr
2214b8595a66SAndreas Gohr/**
2215fdb8d77bSTom N Harris * Output a Doku_Form object.
2216fdb8d77bSTom N Harris * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
2217fdb8d77bSTom N Harris *
2218fdb8d77bSTom N Harris * @author Tom N Harris <tnharris@whoopdedo.org>
221942ea7f44SGerrit Uitslag *
22208d5e837eSMichael Hamann * @param string     $name The name of the form
22218d5e837eSMichael Hamann * @param Doku_Form  $form The form
2222fdb8d77bSTom N Harris */
2223fdb8d77bSTom N Harrisfunction html_form($name, &$form) {
2224fdb8d77bSTom N Harris    // Safety check in case the caller forgets.
2225fdb8d77bSTom N Harris    $form->endFieldset();
2226cbb44eabSAndreas Gohr    Event::createAndTrigger('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
2227fdb8d77bSTom N Harris}
2228fdb8d77bSTom N Harris
2229fdb8d77bSTom N Harris/**
2230fdb8d77bSTom N Harris * Form print function.
2231fdb8d77bSTom N Harris * Just calls printForm() on the data object.
223242ea7f44SGerrit Uitslag *
22338d5e837eSMichael Hamann * @param Doku_Form $data The form
2234fdb8d77bSTom N Harris */
2235fdb8d77bSTom N Harrisfunction html_form_output($data) {
2236fdb8d77bSTom N Harris    $data->printForm();
22378b06d178Schris}
2238340756e4Sandi
223907bf32b2SAndreas Gohr/**
224007bf32b2SAndreas Gohr * Embed a flash object in HTML
224107bf32b2SAndreas Gohr *
224207bf32b2SAndreas Gohr * This will create the needed HTML to embed a flash movie in a cross browser
224307bf32b2SAndreas Gohr * compatble way using valid XHTML
224407bf32b2SAndreas Gohr *
224507bf32b2SAndreas Gohr * The parameters $params, $flashvars and $atts need to be associative arrays.
224607bf32b2SAndreas Gohr * No escaping needs to be done for them. The alternative content *has* to be
224707bf32b2SAndreas Gohr * escaped because it is used as is. If no alternative content is given
224807bf32b2SAndreas Gohr * $lang['noflash'] is used.
224907bf32b2SAndreas Gohr *
225007bf32b2SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
225107bf32b2SAndreas Gohr * @link   http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
225207bf32b2SAndreas Gohr *
225307bf32b2SAndreas Gohr * @param string $swf      - the SWF movie to embed
225407bf32b2SAndreas Gohr * @param int $width       - width of the flash movie in pixels
225507bf32b2SAndreas Gohr * @param int $height      - height of the flash movie in pixels
225607bf32b2SAndreas Gohr * @param array $params    - additional parameters (<param>)
225707bf32b2SAndreas Gohr * @param array $flashvars - parameters to be passed in the flashvar parameter
225807bf32b2SAndreas Gohr * @param array $atts      - additional attributes for the <object> tag
225907bf32b2SAndreas Gohr * @param string $alt      - alternative content (is NOT automatically escaped!)
2260b3d1090eSMichael Hamann * @return string         - the XHTML markup
226107bf32b2SAndreas Gohr */
226207bf32b2SAndreas Gohrfunction html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
226307bf32b2SAndreas Gohr    global $lang;
226407bf32b2SAndreas Gohr
226507bf32b2SAndreas Gohr    $out = '';
226607bf32b2SAndreas Gohr
226707bf32b2SAndreas Gohr    // prepare the object attributes
226807bf32b2SAndreas Gohr    if(is_null($atts)) $atts = array();
226907bf32b2SAndreas Gohr    $atts['width']  = (int) $width;
2270d4c61e61SAndreas Gohr    $atts['height'] = (int) $height;
227107bf32b2SAndreas Gohr    if(!$atts['width'])  $atts['width']  = 425;
227207bf32b2SAndreas Gohr    if(!$atts['height']) $atts['height'] = 350;
227307bf32b2SAndreas Gohr
227407bf32b2SAndreas Gohr    // add object attributes for standard compliant browsers
227507bf32b2SAndreas Gohr    $std = $atts;
227607bf32b2SAndreas Gohr    $std['type'] = 'application/x-shockwave-flash';
227707bf32b2SAndreas Gohr    $std['data'] = $swf;
227807bf32b2SAndreas Gohr
227907bf32b2SAndreas Gohr    // add object attributes for IE
228007bf32b2SAndreas Gohr    $ie  = $atts;
228107bf32b2SAndreas Gohr    $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
228207bf32b2SAndreas Gohr
228307bf32b2SAndreas Gohr    // open object (with conditional comments)
228407bf32b2SAndreas Gohr    $out .= '<!--[if !IE]> -->'.NL;
228507bf32b2SAndreas Gohr    $out .= '<object '.buildAttributes($std).'>'.NL;
228607bf32b2SAndreas Gohr    $out .= '<!-- <![endif]-->'.NL;
228707bf32b2SAndreas Gohr    $out .= '<!--[if IE]>'.NL;
228807bf32b2SAndreas Gohr    $out .= '<object '.buildAttributes($ie).'>'.NL;
228907bf32b2SAndreas Gohr    $out .= '    <param name="movie" value="'.hsc($swf).'" />'.NL;
22909ae41cdcSAndreas Gohr    $out .= '<!--><!-- -->'.NL;
229107bf32b2SAndreas Gohr
229207bf32b2SAndreas Gohr    // print params
229307bf32b2SAndreas Gohr    if(is_array($params)) foreach($params as $key => $val){
229407bf32b2SAndreas Gohr        $out .= '  <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
229507bf32b2SAndreas Gohr    }
229607bf32b2SAndreas Gohr
229707bf32b2SAndreas Gohr    // add flashvars
229807bf32b2SAndreas Gohr    if(is_array($flashvars)){
2299d4c61e61SAndreas Gohr        $out .= '  <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
230007bf32b2SAndreas Gohr    }
230107bf32b2SAndreas Gohr
230207bf32b2SAndreas Gohr    // alternative content
230307bf32b2SAndreas Gohr    if($alt){
230407bf32b2SAndreas Gohr        $out .= $alt.NL;
230507bf32b2SAndreas Gohr    }else{
230607bf32b2SAndreas Gohr        $out .= $lang['noflash'].NL;
230707bf32b2SAndreas Gohr    }
230807bf32b2SAndreas Gohr
230907bf32b2SAndreas Gohr    // finish
231007bf32b2SAndreas Gohr    $out .= '</object>'.NL;
231107bf32b2SAndreas Gohr    $out .= '<!-- <![endif]-->'.NL;
231207bf32b2SAndreas Gohr
231307bf32b2SAndreas Gohr    return $out;
231407bf32b2SAndreas Gohr}
231507bf32b2SAndreas Gohr
23168d5e837eSMichael Hamann/**
23178d5e837eSMichael Hamann * Prints HTML code for the given tab structure
23188d5e837eSMichael Hamann *
23198d5e837eSMichael Hamann * @param array  $tabs        tab structure
23208d5e837eSMichael Hamann * @param string $current_tab the current tab id
23218d5e837eSMichael Hamann */
232295b451bcSAdrian Langfunction html_tabs($tabs, $current_tab = null) {
232394add303SAnika Henke    echo '<ul class="tabs">'.NL;
232495b451bcSAdrian Lang
232595b451bcSAdrian Lang    foreach($tabs as $id => $tab) {
232695b451bcSAdrian Lang        html_tab($tab['href'], $tab['caption'], $id === $current_tab);
232795b451bcSAdrian Lang    }
232895b451bcSAdrian Lang
232994add303SAnika Henke    echo '</ul>'.NL;
233095b451bcSAdrian Lang}
2331cd2a4cfdSAnika Henke
233295b451bcSAdrian Lang/**
233395b451bcSAdrian Lang * Prints a single tab
233495b451bcSAdrian Lang *
233595b451bcSAdrian Lang * @author Kate Arzamastseva <pshns@ukr.net>
233695b451bcSAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
233795b451bcSAdrian Lang *
233895b451bcSAdrian Lang * @param string $href - tab href
233995b451bcSAdrian Lang * @param string $caption - tab caption
234095b451bcSAdrian Lang * @param boolean $selected - is tab selected
234195b451bcSAdrian Lang */
234295b451bcSAdrian Lang
234395b451bcSAdrian Langfunction html_tab($href, $caption, $selected=false) {
234495b451bcSAdrian Lang    $tab = '<li>';
234595b451bcSAdrian Lang    if ($selected) {
234695b451bcSAdrian Lang        $tab .= '<strong>';
234795b451bcSAdrian Lang    } else {
234895b451bcSAdrian Lang        $tab .= '<a href="' . hsc($href) . '">';
234995b451bcSAdrian Lang    }
235095b451bcSAdrian Lang    $tab .= hsc($caption)
235195b451bcSAdrian Lang         .  '</' . ($selected ? 'strong' : 'a') . '>'
235294add303SAnika Henke         .  '</li>'.NL;
235395b451bcSAdrian Lang    echo $tab;
235495b451bcSAdrian Lang}
235595b451bcSAdrian Lang
2356cd2a4cfdSAnika Henke/**
2357cd2a4cfdSAnika Henke * Display size change
2358cd2a4cfdSAnika Henke *
2359cd2a4cfdSAnika Henke * @param int $sizechange - size of change in Bytes
2360cd2a4cfdSAnika Henke * @param Doku_Form $form - form to add elements to
2361cd2a4cfdSAnika Henke */
2362cd2a4cfdSAnika Henke
2363cd2a4cfdSAnika Henkefunction html_sizechange($sizechange, Doku_Form $form) {
2364cd2a4cfdSAnika Henke    if(isset($sizechange)) {
2365cd2a4cfdSAnika Henke        $class = 'sizechange';
2366cd2a4cfdSAnika Henke        $value = filesize_h(abs($sizechange));
2367cd2a4cfdSAnika Henke        if($sizechange > 0) {
2368cd2a4cfdSAnika Henke            $class .= ' positive';
2369cd2a4cfdSAnika Henke            $value = '+' . $value;
2370cd2a4cfdSAnika Henke        } elseif($sizechange < 0) {
2371cd2a4cfdSAnika Henke            $class .= ' negative';
2372cd2a4cfdSAnika Henke            $value = '-' . $value;
23730b78a6edSAnika Henke        } else {
23740b78a6edSAnika Henke            $value = '±' . $value;
2375cd2a4cfdSAnika Henke        }
2376cd2a4cfdSAnika Henke        $form->addElement(form_makeOpenTag('span', array('class' => $class)));
2377cd2a4cfdSAnika Henke        $form->addElement($value);
2378cd2a4cfdSAnika Henke        $form->addElement(form_makeCloseTag('span'));
2379cd2a4cfdSAnika Henke    }
2380cd2a4cfdSAnika Henke}
2381