3 * HTML output functions
5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author Andreas Gohr <andi@splitbrain.org>
9 if(!defined('DOKU_INC')) die('meh.');
10 if(!defined('NL')) define('NL',"\n");
11 require_once(DOKU_INC
.'inc/parserutils.php');
12 require_once(DOKU_INC
.'inc/form.php');
15 * Convenience function to quickly build a wikilink
17 * @author Andreas Gohr <andi@splitbrain.org>
19 function html_wikilink($id,$name=null,$search=''){
20 static $xhtml_renderer = null;
21 if(is_null($xhtml_renderer)){
22 $xhtml_renderer = p_get_renderer('xhtml');
25 return $xhtml_renderer->internallink($id,$name,$search,true,'navigation');
29 * Helps building long attribute lists
31 * @author Andreas Gohr <andi@splitbrain.org>
33 function html_attbuild($attributes){
35 foreach ( $attributes as $key => $value ) {
36 $ret .= $key.'="'.formText($value).'" ';
44 * @author Andreas Gohr <andi@splitbrain.org>
46 function html_login(){
52 print p_locale_xhtml('login');
53 print '<div class="centeralign">'.NL
;
54 $form = new Doku_Form(array('id' => 'dw__login'));
55 $form->startFieldset($lang['btn_login']);
56 $form->addHidden('id', $ID);
57 $form->addHidden('do', 'login');
58 $form->addElement(form_makeTextField('u', ((!$_REQUEST['http_credentials']) ?
$_REQUEST['u'] : ''), $lang['user'], 'focus__this', 'block'));
59 $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block'));
60 if($conf['rememberme']) {
61 $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple'));
63 $form->addElement(form_makeButton('submit', '', $lang['btn_login']));
66 if($auth && $auth->canDo('addUser') && actionOK('register')){
67 $form->addElement('<p>'
69 . ': <a href="'.wl($ID,'do=register').'" rel="nofollow" class="wikilink1">'.$lang['register'].'</a>'
73 if ($auth && $auth->canDo('modPass') && actionOK('resendpwd')) {
74 $form->addElement('<p>'
76 . ': <a href="'.wl($ID,'do=resendpwd').'" rel="nofollow" class="wikilink1">'.$lang['btn_resendpwd'].'</a>'
80 html_form('login', $form);
85 * inserts section edit buttons if wanted or removes the markers
87 * @author Andreas Gohr <andi@splitbrain.org>
89 function html_secedit($text,$show=true){
92 $regexp = '#<!-- EDIT(\d+) ([A-Z]+) (?:"([^"]*)" )?\[(\d+-\d*)\] -->#';
94 if(!$INFO['writable'] ||
!$show ||
$INFO['rev']){
95 return preg_replace($regexp,'',$text);
98 return preg_replace_callback($regexp,
99 'html_secedit_button', $text);
103 * prepares section edit button data for event triggering
104 * used as a callback in html_secedit
106 * @triggers HTML_SECEDIT_BUTTON
107 * @author Andreas Gohr <andi@splitbrain.org>
109 function html_secedit_button($matches){
110 $data = array('secid' => $matches[1],
111 'target' => strtolower($matches[2]),
112 'range' => $matches[count($matches) - 1]);
113 if (count($matches) === 5) {
114 $data['name'] = $matches[3];
117 return trigger_event('HTML_SECEDIT_BUTTON', $data,
118 'html_secedit_get_button');
122 * prints a section editing button
123 * used as default action form HTML_SECEDIT_BUTTON
125 * @author Adrian Lang <lang@cosmocode.de>
127 function html_secedit_get_button($data) {
131 if (!isset($data['name']) ||
$data['name'] === '') return;
133 $name = $data['name'];
134 unset($data['name']);
136 $secid = $data['secid'];
137 unset($data['secid']);
139 return "<div class='secedit editbutton_" . $data['target'] .
140 " editbutton_" . $secid . "'>" .
141 html_btn('secedit', $ID, '',
142 array_merge(array('do' => 'edit',
143 'rev' => $INFO['lastmod']), $data),
144 'post', $name) . '</div>';
148 * Just the back to top button (in its own form)
150 * @author Andreas Gohr <andi@splitbrain.org>
152 function html_topbtn(){
156 $ret = '<a class="nolink" href="#dokuwiki__top"><input type="button" class="button" value="'.$lang['btn_top'].'" onclick="window.scrollTo(0, 0)" title="'.$lang['btn_top'].'" /></a>';
162 * Displays a button (using its own form)
163 * If tooltip exists, the access key tooltip is replaced.
165 * @author Andreas Gohr <andi@splitbrain.org>
167 function html_btn($name,$id,$akey,$params,$method='get',$tooltip=''){
171 $label = $lang['btn_'.$name];
176 //filter id (without urlencoding)
177 $id = idfilter($id,false);
179 //make nice URLs even for buttons
180 if($conf['userewrite'] == 2){
181 $script = DOKU_BASE
.DOKU_SCRIPT
.'/'.$id;
182 }elseif($conf['userewrite']){
183 $script = DOKU_BASE
.$id;
185 $script = DOKU_BASE
.DOKU_SCRIPT
;
189 $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
191 if(is_array($params)){
193 while (list($key, $val) = each($params)) {
194 $ret .= '<input type="hidden" name="'.$key.'" ';
195 $ret .= 'value="'.htmlspecialchars($val).'" />';
200 $tip = htmlspecialchars($tooltip);
202 $tip = htmlspecialchars($label);
205 $ret .= '<input type="submit" value="'.hsc($label).'" class="button" ';
207 $tip .= ' ['.strtoupper($akey).']';
208 $ret .= 'accesskey="'.$akey.'" ';
210 $ret .= 'title="'.$tip.'" ';
212 $ret .= '</div></form>';
220 * @author Andreas Gohr <andi@splitbrain.org>
222 function html_show($txt=''){
227 //disable section editing for old revisions or in preview
236 echo '<br id="scroll__here" />';
237 echo p_locale_xhtml('preview');
238 echo '<div class="preview">';
239 $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
240 if($INFO['prependTOC']) $html = tpl_toc(true).$html;
242 echo '<div class="clearer"></div>';
246 if ($REV) print p_locale_xhtml('showrev');
247 $html = p_wiki_xhtml($ID,$REV,true);
248 $html = html_secedit($html,$secedit);
249 if($INFO['prependTOC']) $html = tpl_toc(true).$html;
250 $html = html_hilight($html,$HIGH);
256 * ask the user about how to handle an exisiting draft
258 * @author Andreas Gohr <andi@splitbrain.org>
260 function html_draft(){
265 $draft = unserialize(io_readFile($INFO['draft'],false));
266 $text = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
268 print p_locale_xhtml('draft');
269 $form = new Doku_Form(array('id' => 'dw__editform'));
270 $form->addHidden('id', $ID);
271 $form->addHidden('date', $draft['date']);
272 $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly')));
273 $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
274 $form->addElement($lang['draftdate'].' '. dformat(filemtime($INFO['draft'])));
275 $form->addElement(form_makeCloseTag('div'));
276 $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
277 $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
278 $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3')));
279 html_form('draft', $form);
283 * Highlights searchqueries in HTML code
285 * @author Andreas Gohr <andi@splitbrain.org>
286 * @author Harry Fuecks <hfuecks@gmail.com>
288 function html_hilight($html,$phrases){
289 $phrases = array_filter((array) $phrases);
290 $regex = join('|',array_map('preg_quote_cb',$phrases));
292 if ($regex === '') return $html;
293 $html = preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
298 * Callback used by html_hilight()
300 * @author Harry Fuecks <hfuecks@gmail.com>
302 function html_hilight_callback($m) {
303 $hlight = unslash($m[0]);
304 if ( !isset($m[2])) {
305 $hlight = '<span class="search_hit">'.$hlight.'</span>';
311 * Run a search and display the result
313 * @author Andreas Gohr <andi@splitbrain.org>
315 function html_search(){
316 require_once(DOKU_INC
.'inc/search.php');
317 require_once(DOKU_INC
.'inc/fulltext.php');
323 print p_locale_xhtml('searchpage');
326 //check if search is restricted to namespace
327 if(preg_match('/@([^@]*)/',$QUERY,$match)) {
328 $id = cleanID($match[1]);
330 $id = cleanID($QUERY);
334 print '<div class="centeralign" id="dw__loading">'.NL
;
335 print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL
;
336 print 'showLoadBar();'.NL
;
337 print '//--><!]]></script>'.NL
;
338 print '<br /></div>'.NL
;
341 //do quick pagesearch
344 if($id) $data = ft_pageLookup($id);
346 print '<div class="search_quickresult">';
347 print '<h3>'.$lang['quickhits'].':</h3>';
348 print '<ul class="search_quickhits">';
349 foreach($data as $id){
353 $name = shorten(noNS($id), ' ('.$ns.')',30);
357 print html_wikilink(':'.$id,$name);
361 //clear float (see http://www.complexspiral.com/publications/containing-floats/)
362 print '<div class="clearer"> </div>';
368 $data = ft_pageSearch($QUERY,$regex);
371 foreach($data as $id => $cnt){
372 print '<div class="search_result">';
373 print html_wikilink(':'.$id,useHeading('navigation')?
null:$id,$regex);
375 print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />';
376 if($num < 15){ // create snippets for the first number of matches only #FIXME add to conf ?
377 print '<div class="search_snippet">'.ft_snippet($id,$regex).'</div>';
385 print '<div class="nothing">'.$lang['nothingfound'].'</div>';
389 print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL
;
390 print 'hideLoadBar("dw__loading");'.NL
;
391 print '//--><!]]></script>'.NL
;
396 * Display error on locked pages
398 * @author Andreas Gohr <andi@splitbrain.org>
400 function html_locked(){
406 $locktime = filemtime(wikiLockFN($ID));
407 $expire = dformat($locktime +
$conf['locktime']);
408 $min = round(($conf['locktime'] - (time() - $locktime) )/60);
410 print p_locale_xhtml('locked');
412 print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.editorinfo($INFO['locked']).'</div></li>';
413 print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>';
420 * @author Andreas Gohr <andi@splitbrain.org>
421 * @author Ben Coburn <btcoburn@silicodon.net>
423 function html_revisions($first=0){
428 /* we need to get one additionally log entry to be able to
429 * decide if this is the last page or is there another one.
432 $revisions = getRevisions($ID, $first, $conf['recent']+
1);
433 if(count($revisions)==0 && $first!=0){
435 $revisions = getRevisions($ID, $first, $conf['recent']+
1);;
438 if (count($revisions)>$conf['recent']) {
440 array_pop($revisions); // remove extra log entry
443 $date = dformat($INFO['lastmod']);
445 print p_locale_xhtml('revisions');
447 $form = new Doku_Form(array('id' => 'page__revisions'));
448 $form->addElement(form_makeOpenTag('ul'));
449 if($INFO['exists'] && $first==0){
450 if (isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT
)
451 $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
453 $form->addElement(form_makeOpenTag('li'));
454 $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
455 $form->addElement(form_makeTag('input', array(
456 'type' => 'checkbox',
458 'value' => 'current')));
460 $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
461 $form->addElement($date);
462 $form->addElement(form_makeCloseTag('span'));
464 $form->addElement(form_makeTag('img', array(
465 'src' => DOKU_BASE
.'lib/images/blank.gif',
470 $form->addElement(form_makeOpenTag('a', array(
471 'class' => 'wikilink1',
472 'href' => wl($ID))));
473 $form->addElement($ID);
474 $form->addElement(form_makeCloseTag('a'));
476 $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
477 $form->addElement(' – ');
478 $form->addElement(htmlspecialchars($INFO['sum']));
479 $form->addElement(form_makeCloseTag('span'));
481 $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
482 $form->addElement((empty($INFO['editor']))?
('('.$lang['external_edit'].')'):editorinfo($INFO['editor']));
483 $form->addElement(form_makeCloseTag('span'));
485 $form->addElement('('.$lang['current'].')');
486 $form->addElement(form_makeCloseTag('div'));
487 $form->addElement(form_makeCloseTag('li'));
490 foreach($revisions as $rev){
491 $date = dformat($rev);
492 $info = getRevisionInfo($ID,$rev,true);
493 $exists = page_exists($ID,$rev);
495 if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT
)
496 $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
498 $form->addElement(form_makeOpenTag('li'));
499 $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
501 $form->addElement(form_makeTag('input', array(
502 'type' => 'checkbox',
506 $form->addElement(form_makeTag('img', array(
507 'src' => DOKU_BASE
.'lib/images/blank.gif',
513 $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
514 $form->addElement($date);
515 $form->addElement(form_makeCloseTag('span'));
518 $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev,do=diff", false, '&'), 'class' => 'diff_link')));
519 $form->addElement(form_makeTag('img', array(
520 'src' => DOKU_BASE
.'lib/images/diff.png',
523 'title' => $lang['diff'],
524 'alt' => $lang['diff'])));
525 $form->addElement(form_makeCloseTag('a'));
527 $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev",false,'&'), 'class' => 'wikilink1')));
528 $form->addElement($ID);
529 $form->addElement(form_makeCloseTag('a'));
531 $form->addElement(form_makeTag('img', array(
532 'src' => DOKU_BASE
.'lib/images/blank.gif',
536 $form->addElement($ID);
539 $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
540 $form->addElement(' – ');
541 $form->addElement(htmlspecialchars($info['sum']));
542 $form->addElement(form_makeCloseTag('span'));
544 $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
546 $form->addElement(editorinfo($info['user']));
547 if(auth_ismanager()){
548 $form->addElement(' ('.$info['ip'].')');
551 $form->addElement($info['ip']);
553 $form->addElement(form_makeCloseTag('span'));
555 $form->addElement(form_makeCloseTag('div'));
556 $form->addElement(form_makeCloseTag('li'));
558 $form->addElement(form_makeCloseTag('ul'));
559 $form->addElement(form_makeButton('submit', 'diff', $lang['diff2']));
560 html_form('revisions', $form);
562 print '<div class="pagenav">';
563 $last = $first +
$conf['recent'];
565 $first -= $conf['recent'];
566 if ($first < 0) $first = 0;
567 print '<div class="pagenav-prev">';
568 print html_btn('newer',$ID,"p",array('do' => 'revisions', 'first' => $first));
572 print '<div class="pagenav-next">';
573 print html_btn('older',$ID,"n",array('do' => 'revisions', 'first' => $last));
581 * display recent changes
583 * @author Andreas Gohr <andi@splitbrain.org>
584 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
585 * @author Ben Coburn <btcoburn@silicodon.net>
587 function html_recent($first=0){
591 /* we need to get one additionally log entry to be able to
592 * decide if this is the last page or is there another one.
593 * This is the cheapest solution to get this information.
595 $recents = getRecents($first,$conf['recent'] +
1,getNS($ID));
596 if(count($recents) == 0 && $first != 0){
598 $recents = getRecents($first,$conf['recent'] +
1,getNS($ID));
601 if (count($recents)>$conf['recent']) {
603 array_pop($recents); // remove extra log entry
606 print p_locale_xhtml('recent');
608 if (getNS($ID) != '')
609 print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>';
611 $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET'));
612 $form->addHidden('sectok', null);
613 $form->addHidden('do', 'recent');
614 $form->addHidden('id', $ID);
615 $form->addElement(form_makeOpenTag('ul'));
617 foreach($recents as $recent){
618 $date = dformat($recent['date']);
619 if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT
)
620 $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
622 $form->addElement(form_makeOpenTag('li'));
624 $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
626 $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
627 $form->addElement($date);
628 $form->addElement(form_makeCloseTag('span'));
630 $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => wl($recent['id'],"do=diff", false, '&'))));
631 $form->addElement(form_makeTag('img', array(
632 'src' => DOKU_BASE
.'lib/images/diff.png',
635 'title' => $lang['diff'],
636 'alt' => $lang['diff']
638 $form->addElement(form_makeCloseTag('a'));
640 $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => wl($recent['id'],"do=revisions",false,'&'))));
641 $form->addElement(form_makeTag('img', array(
642 'src' => DOKU_BASE
.'lib/images/history.png',
645 'title' => $lang['btn_revs'],
646 'alt' => $lang['btn_revs']
648 $form->addElement(form_makeCloseTag('a'));
650 $form->addElement(html_wikilink(':'.$recent['id'],useHeading('navigation')?
null:$recent['id']));
652 $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
653 $form->addElement(' – '.htmlspecialchars($recent['sum']));
654 $form->addElement(form_makeCloseTag('span'));
656 $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
658 $form->addElement(editorinfo($recent['user']));
659 if(auth_ismanager()){
660 $form->addElement(' ('.$recent['ip'].')');
663 $form->addElement($recent['ip']);
665 $form->addElement(form_makeCloseTag('span'));
667 $form->addElement(form_makeCloseTag('div'));
668 $form->addElement(form_makeCloseTag('li'));
670 $form->addElement(form_makeCloseTag('ul'));
672 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
673 $last = $first +
$conf['recent'];
675 $first -= $conf['recent'];
676 if ($first < 0) $first = 0;
677 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
678 $form->addElement(form_makeTag('input', array(
680 'name' => 'first['.$first.']',
681 'value' => $lang['btn_newer'],
683 'title' => $lang['btn_newer'].' [N]',
686 $form->addElement(form_makeCloseTag('div'));
689 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
690 $form->addElement(form_makeTag('input', array(
692 'name' => 'first['.$last.']',
693 'value' => $lang['btn_older'],
695 'title' => $lang['btn_older'].' [P]',
698 $form->addElement(form_makeCloseTag('div'));
700 $form->addElement(form_makeCloseTag('div'));
701 html_form('recent', $form);
707 * @author Andreas Gohr <andi@splitbrain.org>
709 function html_index($ns){
710 require_once(DOKU_INC
.'inc/search.php');
713 $dir = $conf['datadir'];
715 #fixme use appropriate function
717 $ns = dirname(str_replace(':','/',$ID));
718 if($ns == '.') $ns ='';
720 $ns = utf8_encodeFN(str_replace(':','/',$ns));
722 echo p_locale_xhtml('index');
723 echo '<div id="index__tree">';
726 search($data,$conf['datadir'],'search_index',array('ns' => $ns));
727 echo html_buildlist($data,'idx','html_list_index','html_li_index');
733 * Index item formatter
735 * User function for html_buildlist()
737 * @author Andreas Gohr <andi@splitbrain.org>
739 function html_list_index($item){
742 $base = ':'.$item['id'];
743 $base = substr($base,strrpos($base,':')+
1);
744 if($item['type']=='d'){
745 $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" class="idx_dir"><strong>';
747 $ret .= '</strong></a>';
749 $ret .= html_wikilink(':'.$item['id']);
757 * This user function is used in html_build_lidt to build the
758 * <li> tags for namespaces when displaying the page index
759 * it gives different classes to opened or closed "folders"
761 * @author Andreas Gohr <andi@splitbrain.org>
763 function html_li_index($item){
764 if($item['type'] == "f"){
765 return '<li class="level'.$item['level'].'">';
766 }elseif($item['open']){
767 return '<li class="open">';
769 return '<li class="closed">';
776 * @author Andreas Gohr <andi@splitbrain.org>
778 function html_li_default($item){
779 return '<li class="level'.$item['level'].'">';
783 * Build an unordered list
785 * Build an unordered list from the given $data array
786 * Each item in the array has to have a 'level' property
787 * the item itself gets printed by the given $func user
788 * function. The second and optional function is used to
789 * print the <li> tag. Both user function need to accept
792 * Both user functions can be given as array to point to
793 * a member of an object.
795 * @author Andreas Gohr <andi@splitbrain.org>
797 function html_buildlist($data,$class,$func,$lifunc='html_li_default'){
802 foreach ($data as $item){
804 if( $item['level'] > $level ){
806 for($i=0; $i<($item['level'] - $level); $i++
){
807 if ($i) $ret .= "<li class=\"clear\">\n";
808 $ret .= "\n<ul class=\"$class\">\n";
810 }elseif( $item['level'] < $level ){
813 for ($i=0; $i<($level - $item['level']); $i++
){
815 $ret .= "</ul>\n</li>\n";
822 //remember current level
823 $level = $item['level'];
826 $ret .= call_user_func($lifunc,$item);
827 $ret .= '<div class="li">';
829 $ret .= call_user_func($func,$item);
833 //close remaining items and lists
834 for ($i=0; $i < $level; $i++
){
835 $ret .= "</li></ul>\n";
844 * @author Andreas Gohr <andi@splitbrain.org>
845 * @author Michael Klier <chi@chimeric.de>
847 function html_backlinks(){
848 require_once(DOKU_INC
.'inc/fulltext.php');
853 print p_locale_xhtml('backlinks');
855 $data = ft_backlinks($ID);
858 print '<ul class="idx">';
859 foreach($data as $blink){
860 print '<li><div class="li">';
861 print html_wikilink(':'.$blink,useHeading('navigation')?
null:$blink);
866 print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
873 * @author Andreas Gohr <andi@splitbrain.org>
875 function html_diff($text='',$intro=true){
876 require_once(DOKU_INC
.'inc/DifferenceEngine.php');
882 // we're trying to be clever here, revisions to compare can be either
883 // given as rev and rev2 parameters, with rev2 being optional. Or in an
887 if(is_array($_REQUEST['rev2'])){
888 $rev1 = (int) $_REQUEST['rev2'][0];
889 $rev2 = (int) $_REQUEST['rev2'][1];
896 $rev2 = (int) $_REQUEST['rev2'];
899 if($text){ // compare text to the most current revision
901 $l_text = rawWiki($ID,'');
902 $l_head = '<a class="wikilink1" href="'.wl($ID).'">'.
903 $ID.' '.dformat((int) @filemtime
(wikiFN($ID))).'</a> '.
907 $r_text = cleanText($text);
908 $r_head = $lang['yours'];
910 if($rev1 && $rev2){ // two specific revisions wanted
911 // make sure order is correct (older on the left)
919 }elseif($rev1){ // single revision given, compare to current
922 }else{ // no revision was given, compare previous to current
924 $revs = getRevisions($ID, 0, 1);
926 $REV = $l_rev; // store revision back in $REV
929 // when both revisions are empty then the page was created just now
930 if(!$l_rev && !$r_rev){
933 $l_text = rawWiki($ID,$l_rev);
935 $r_text = rawWiki($ID,$r_rev);
940 $l_info = getRevisionInfo($ID,$l_rev,true);
942 $l_user = editorinfo($l_info['user']);
943 if(auth_ismanager()) $l_user .= ' ('.$l_info['ip'].')';
945 $l_user = $l_info['ip'];
947 $l_user = '<span class="user">'.$l_user.'</span>';
948 $l_sum = ($l_info['sum']) ?
'<span class="sum">'.hsc($l_info['sum']).'</span>' : '';
949 if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT
) $l_minor = 'class="minor"';
951 $l_head = '<a class="wikilink1" href="'.wl($ID,"rev=$l_rev").'">'.
952 $ID.' ['.dformat($l_rev).']</a>'.
953 '<br />'.$l_user.' '.$l_sum;
957 $r_info = getRevisionInfo($ID,$r_rev,true);
959 $r_user = editorinfo($r_info['user']);
960 if(auth_ismanager()) $r_user .= ' ('.$r_info['ip'].')';
962 $r_user = $r_info['ip'];
964 $r_user = '<span class="user">'.$r_user.'</span>';
965 $r_sum = ($r_info['sum']) ?
'<span class="sum">'.hsc($r_info['sum']).'</span>' : '';
966 if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT
) $r_minor = 'class="minor"';
968 $r_head = '<a class="wikilink1" href="'.wl($ID,"rev=$r_rev").'">'.
969 $ID.' ['.dformat($r_rev).']</a>'.
970 '<br />'.$r_user.' '.$r_sum;
971 }elseif($_rev = @filemtime
(wikiFN($ID))){
972 $_info = getRevisionInfo($ID,$_rev,true);
974 $_user = editorinfo($_info['user']);
975 if(auth_ismanager()) $_user .= ' ('.$_info['ip'].')';
977 $_user = $_info['ip'];
979 $_user = '<span class="user">'.$_user.'</span>';
980 $_sum = ($_info['sum']) ?
'<span class="sum">'.hsc($_info['sum']).'</span>' : '';
981 if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT
) $r_minor = 'class="minor"';
983 $r_head = '<a class="wikilink1" href="'.wl($ID).'">'.
984 $ID.' ['.dformat($_rev).']</a> '.
985 '('.$lang['current'].')'.
986 '<br />'.$_user.' '.$_sum;
988 $r_head = '— ('.$lang['current'].')';
992 $df = new Diff(explode("\n",htmlspecialchars($l_text)),
993 explode("\n",htmlspecialchars($r_text)));
995 $tdf = new TableDiffFormatter();
996 if($intro) print p_locale_xhtml('diff');
1000 <th colspan
="2" <?php
echo $l_minor?
>>
1001 <?php
echo $l_head?
>
1003 <th colspan
="2" <?php
echo $r_minor?
>>
1004 <?php
echo $r_head?
>
1007 <?php
echo $tdf->format($df)?
>
1013 * show warning on conflict detection
1015 * @author Andreas Gohr <andi@splitbrain.org>
1017 function html_conflict($text,$summary){
1021 print p_locale_xhtml('conflict');
1022 $form = new Doku_Form(array('id' => 'dw__editform'));
1023 $form->addHidden('id', $ID);
1024 $form->addHidden('wikitext', $text);
1025 $form->addHidden('summary', $summary);
1026 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
1027 $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
1028 html_form('conflict', $form);
1029 print '<br /><br /><br /><br />'.NL
;
1033 * Prints the global message array
1035 * @author Andreas Gohr <andi@splitbrain.org>
1037 function html_msgarea(){
1039 if(!isset($MSG)) return;
1042 foreach($MSG as $msg){
1043 $hash = md5($msg['msg']);
1044 if(isset($shown[$hash])) continue; // skip double messages
1045 print '<div class="'.$msg['lvl'].'">';
1053 * Prints the registration form
1055 * @author Andreas Gohr <andi@splitbrain.org>
1057 function html_register(){
1062 print p_locale_xhtml('register');
1063 print '<div class="centeralign">'.NL
;
1064 $form = new Doku_Form(array('id' => 'dw__register'));
1065 $form->startFieldset($lang['register']);
1066 $form->addHidden('do', 'register');
1067 $form->addHidden('save', '1');
1068 $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], null, 'block', array('size'=>'50')));
1069 if (!$conf['autopasswd']) {
1070 $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
1071 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1073 $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', array('size'=>'50')));
1074 $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', array('size'=>'50')));
1075 $form->addElement(form_makeButton('submit', '', $lang['register']));
1076 $form->endFieldset();
1077 html_form('register', $form);
1083 * Print the update profile form
1085 * @author Christopher Smith <chris@jalakai.co.uk>
1086 * @author Andreas Gohr <andi@splitbrain.org>
1088 function html_updateprofile(){
1095 print p_locale_xhtml('updateprofile');
1097 if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
1098 if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
1099 print '<div class="centeralign">'.NL
;
1100 $form = new Doku_Form(array('id' => 'dw__register'));
1101 $form->startFieldset($lang['profile']);
1102 $form->addHidden('do', 'profile');
1103 $form->addHidden('save', '1');
1104 $form->addElement(form_makeTextField('fullname', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
1105 $attr = array('size'=>'50');
1106 if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1107 $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', $attr));
1108 $attr = array('size'=>'50');
1109 if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
1110 $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', $attr));
1111 $form->addElement(form_makeTag('br'));
1112 if ($auth->canDo('modPass')) {
1113 $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1114 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1116 if ($conf['profileconfirm']) {
1117 $form->addElement(form_makeTag('br'));
1118 $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50')));
1120 $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1121 $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
1122 $form->endFieldset();
1123 html_form('updateprofile', $form);
1128 * Preprocess edit form data
1130 * @triggers HTML_PAGE_FROMTEMPLATE
1131 * @author Andreas Gohr <andi@splitbrain.org>
1133 function html_edit($text=null,$include='edit'){ //FIXME: include needed?
1145 //set summary default
1148 $SUM = $lang['restored'];
1149 }elseif(!$INFO['exists']){
1150 $SUM = $lang['created'];
1156 $pr = false; //no preview mode
1157 if($INFO['exists']){
1159 list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
1161 $text = rawWiki($ID,$REV);
1163 $check = md5($text);
1166 //try to load a pagetemplate
1168 $text = trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true);
1173 $pr = true; //preview mode
1174 if (isset($_REQUEST['changecheck'])) {
1175 $check = $_REQUEST['changecheck'];
1176 $mod = md5($text)!==$check;
1178 // Why? Assume default text is unmodified.
1179 $check = md5($text);
1184 $wr = $INFO['writable'] && !$INFO['locked'];
1186 if ($REV) print p_locale_xhtml('editrev');
1187 print p_locale_xhtml($include);
1189 // check pseudo action 'source'
1190 if(!actionOK('source')){
1191 msg('Command disabled: source',-1);
1194 print p_locale_xhtml('read');
1196 if(!$DATE) $DATE = $INFO['lastmod'];
1198 $data = compact('wr', 'text', 'mod', 'check');
1199 trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true);
1203 * Display the default edit form
1205 * Is the default action for HTML_EDIT_FORMSELECTION.
1207 * @triggers HTML_EDITFORM_OUTPUT
1209 function html_edit_form($param) {
1223 <script type
="text/javascript" charset
="utf-8"><!--//--><![CDATA[//><!--
1224 <?php
/* sets changed to true when previewed */?
>
1225 textChanged
= <?
php ($mod) ?
print 'true' : print 'false' ?
>;
1228 <div style
="width:99%;">
1230 <div
class="toolbar">
1231 <div id
="draft__status"><?php
if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?
></div
>
1232 <div id
="tool__bar"><?php
if($wr){?
><a href
="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
1233 target
="_blank"><?php
echo $lang['mediaselect'] ?
></a
><?php
}?
></div
>
1237 $form = new Doku_Form(array('id' => 'dw__editform'));
1238 $form->addHidden('id', $ID);
1239 $form->addHidden('rev', $REV);
1240 $form->addHidden('date', $DATE);
1241 $form->addHidden('prefix', $PRE);
1242 $form->addHidden('suffix', $SUF);
1243 $form->addHidden('changecheck', $check);
1244 $attr = array('tabindex'=>'1');
1245 if (!$wr) $attr['readonly'] = 'readonly';
1246 $form->addElement(form_makeWikiText($text, $attr));
1247 $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar')));
1248 $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1249 $form->addElement(form_makeCloseTag('div'));
1251 $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
1252 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
1253 $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
1254 $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
1255 $form->addElement(form_makeCloseTag('div'));
1256 $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
1257 $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
1258 $elem = html_minoredit();
1259 if ($elem) $form->addElement($elem);
1260 $form->addElement(form_makeCloseTag('div'));
1262 $form->addElement(form_makeCloseTag('div'));
1263 if($wr && $conf['license']){
1264 $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1265 $out = $lang['licenseok'];
1266 $out .= '<a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
1267 if(isset($conf['target']['external'])) $out .= ' target="'.$conf['target']['external'].'"';
1268 $out .= '> '.$license[$conf['license']]['name'].'</a>';
1269 $form->addElement($out);
1270 $form->addElement(form_makeCloseTag('div'));
1272 html_form('edit', $form);
1277 * Adds a checkbox for minor edits for logged in users
1279 * @author Andreas Gohr <andi@splitbrain.org>
1281 function html_minoredit(){
1284 // minor edits are for logged in users only
1285 if(!$conf['useacl'] ||
!$_SERVER['REMOTE_USER']){
1291 if(!empty($_REQUEST['minor'])) $p['checked']='checked';
1292 return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
1296 * prints some debug info
1298 * @author Andreas Gohr <andi@splitbrain.org>
1300 function html_debug(){
1306 //remove sensitive data
1314 print '<html><body>';
1316 print '<p>When reporting bugs please send all the following ';
1317 print 'output as a mail to andi@splitbrain.org ';
1318 print 'The best way to do this is to save this page in your browser</p>';
1320 print '<b>$INFO:</b><pre>';
1324 print '<b>$_SERVER:</b><pre>';
1328 print '<b>$conf:</b><pre>';
1332 print '<b>DOKU_BASE:</b><pre>';
1336 print '<b>abs DOKU_BASE:</b><pre>';
1340 print '<b>rel DOKU_BASE:</b><pre>';
1341 print dirname($_SERVER['PHP_SELF']).'/';
1344 print '<b>PHP Version:</b><pre>';
1348 print '<b>locale:</b><pre>';
1349 print setlocale(LC_ALL
,0);
1352 print '<b>encoding:</b><pre>';
1353 print $lang['encoding'];
1357 print '<b>Auth backend capabilities:</b><pre>';
1358 print_r($auth->cando
);
1362 print '<b>$_SESSION:</b><pre>';
1366 print '<b>Environment:</b><pre>';
1370 print '<b>PHP settings:</b><pre>';
1371 $inis = ini_get_all();
1375 print '</body></html>';
1379 * List available Administration Tasks
1381 * @author Andreas Gohr <andi@splitbrain.org>
1382 * @author HÃ¥kan Sandell <hakan.sandell@home.se>
1384 function html_admin(){
1391 // build menu of admin functions from the plugins that handle them
1392 $pluginlist = plugin_list('admin');
1394 foreach ($pluginlist as $p) {
1395 if($obj =& plugin_load('admin',$p) === null) continue;
1397 // check permissions
1398 if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
1400 $menu[$p] = array('plugin' => $p,
1401 'prompt' => $obj->getMenuText($conf['lang']),
1402 'sort' => $obj->getMenuSort()
1406 print p_locale_xhtml('admin');
1409 if($INFO['isadmin']){
1410 ptln('<ul class="admin_tasks">');
1412 if($menu['usermanager'] && $auth && $auth->canDo('getUsers')){
1413 ptln(' <li class="admin_usermanager"><div class="li">'.
1414 '<a href="'.wl($ID, array('do' => 'admin','page' => 'usermanager')).'">'.
1415 $menu['usermanager']['prompt'].'</a></div></li>');
1417 unset($menu['usermanager']);
1420 ptln(' <li class="admin_acl"><div class="li">'.
1421 '<a href="'.wl($ID, array('do' => 'admin','page' => 'acl')).'">'.
1422 $menu['acl']['prompt'].'</a></div></li>');
1424 unset($menu['acl']);
1426 if($menu['plugin']){
1427 ptln(' <li class="admin_plugin"><div class="li">'.
1428 '<a href="'.wl($ID, array('do' => 'admin','page' => 'plugin')).'">'.
1429 $menu['plugin']['prompt'].'</a></div></li>');
1431 unset($menu['plugin']);
1433 if($menu['config']){
1434 ptln(' <li class="admin_config"><div class="li">'.
1435 '<a href="'.wl($ID, array('do' => 'admin','page' => 'config')).'">'.
1436 $menu['config']['prompt'].'</a></div></li>');
1438 unset($menu['config']);
1443 ptln('<ul class="admin_tasks">');
1445 if($menu['revert']){
1446 ptln(' <li class="admin_revert"><div class="li">'.
1447 '<a href="'.wl($ID, array('do' => 'admin','page' => 'revert')).'">'.
1448 $menu['revert']['prompt'].'</a></div></li>');
1450 unset($menu['revert']);
1452 if($menu['popularity']){
1453 ptln(' <li class="admin_popularity"><div class="li">'.
1454 '<a href="'.wl($ID, array('do' => 'admin','page' => 'popularity')).'">'.
1455 $menu['popularity']['prompt'].'</a></div></li>');
1457 unset($menu['popularity']);
1461 // print the rest as sorted list
1463 usort($menu, 'p_sort_modes');
1465 ptln('<div class="clearer"></div>');
1466 print p_locale_xhtml('adminplugins');
1468 foreach ($menu as $item) {
1469 if (!$item['prompt']) continue;
1470 ptln(' <li><div class="li"><a href="'.wl($ID, 'do=admin&page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
1477 * Form to request a new password for an existing account
1479 * @author Benoit Chesneau <benoit@bchesneau.info>
1481 function html_resendpwd() {
1486 print p_locale_xhtml('resendpwd');
1487 print '<div class="centeralign">'.NL
;
1488 $form = new Doku_Form(array('id' => 'dw__resendpwd'));
1489 $form->startFieldset($lang['resendpwd']);
1490 $form->addHidden('do', 'resendpwd');
1491 $form->addHidden('save', '1');
1492 $form->addElement(form_makeTag('br'));
1493 $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block'));
1494 $form->addElement(form_makeTag('br'));
1495 $form->addElement(form_makeTag('br'));
1496 $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
1497 $form->endFieldset();
1498 html_form('resendpwd', $form);
1503 * Return the TOC rendered to XHTML
1505 * @author Andreas Gohr <andi@splitbrain.org>
1507 function html_TOC($toc){
1508 if(!count($toc)) return '';
1510 $out = '<!-- TOC START -->'.DOKU_LF
;
1511 $out .= '<div class="toc">'.DOKU_LF
;
1512 $out .= '<div class="tocheader toctoggle" id="toc__header">';
1513 $out .= $lang['toc'];
1514 $out .= '</div>'.DOKU_LF
;
1515 $out .= '<div id="toc__inside">'.DOKU_LF
;
1516 $out .= html_buildlist($toc,'toc','html_list_toc');
1517 $out .= '</div>'.DOKU_LF
.'</div>'.DOKU_LF
;
1518 $out .= '<!-- TOC END -->'.DOKU_LF
;
1523 * Callback for html_buildlist
1525 function html_list_toc($item){
1526 if(isset($item['hid'])){
1527 $link = '#'.$item['hid'];
1529 $link = $item['link'];
1532 return '<span class="li"><a href="'.$link.'" class="toc">'.
1533 hsc($item['title']).'</a></span>';
1537 * Helper function to build TOC items
1539 * Returns an array ready to be added to a TOC array
1541 * @param string $link - where to link (if $hash set to '#' it's a local anchor)
1542 * @param string $text - what to display in the TOC
1543 * @param int $level - nesting level
1544 * @param string $hash - is prepended to the given $link, set blank if you want full links
1546 function html_mktocitem($link, $text, $level, $hash='#'){
1548 return array( 'link' => $hash.$link,
1555 * Output a Doku_Form object.
1556 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
1558 * @author Tom N Harris <tnharris@whoopdedo.org>
1560 function html_form($name, &$form) {
1561 // Safety check in case the caller forgets.
1562 $form->endFieldset();
1563 trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
1567 * Form print function.
1568 * Just calls printForm() on the data object.
1570 function html_form_output($data) {
1575 * Embed a flash object in HTML
1577 * This will create the needed HTML to embed a flash movie in a cross browser
1578 * compatble way using valid XHTML
1580 * The parameters $params, $flashvars and $atts need to be associative arrays.
1581 * No escaping needs to be done for them. The alternative content *has* to be
1582 * escaped because it is used as is. If no alternative content is given
1583 * $lang['noflash'] is used.
1585 * @author Andreas Gohr <andi@splitbrain.org>
1586 * @link http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
1588 * @param string $swf - the SWF movie to embed
1589 * @param int $width - width of the flash movie in pixels
1590 * @param int $height - height of the flash movie in pixels
1591 * @param array $params - additional parameters (<param>)
1592 * @param array $flashvars - parameters to be passed in the flashvar parameter
1593 * @param array $atts - additional attributes for the <object> tag
1594 * @param string $alt - alternative content (is NOT automatically escaped!)
1595 * @returns string - the XHTML markup
1597 function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
1602 // prepare the object attributes
1603 if(is_null($atts)) $atts = array();
1604 $atts['width'] = (int) $width;
1605 $atts['height'] = (int) $height;
1606 if(!$atts['width']) $atts['width'] = 425;
1607 if(!$atts['height']) $atts['height'] = 350;
1609 // add object attributes for standard compliant browsers
1611 $std['type'] = 'application/x-shockwave-flash';
1612 $std['data'] = $swf;
1614 // add object attributes for IE
1616 $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
1618 // open object (with conditional comments)
1619 $out .= '<!--[if !IE]> -->'.NL
;
1620 $out .= '<object '.buildAttributes($std).'>'.NL
;
1621 $out .= '<!-- <![endif]-->'.NL
;
1622 $out .= '<!--[if IE]>'.NL
;
1623 $out .= '<object '.buildAttributes($ie).'>'.NL
;
1624 $out .= ' <param name="movie" value="'.hsc($swf).'" />'.NL
;
1625 $out .= '<!--><!-- -->'.NL
;
1628 if(is_array($params)) foreach($params as $key => $val){
1629 $out .= ' <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL
;
1633 if(is_array($flashvars)){
1634 $out .= ' <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL
;
1637 // alternative content
1641 $out .= $lang['noflash'].NL
;
1645 $out .= '</object>'.NL
;
1646 $out .= '<!-- <![endif]-->'.NL
;