1<?php 2/** 3 * HTML output functions 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Andreas Gohr <andi@splitbrain.org> 7 */ 8 9if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/'); 10if(!defined('NL')) define('NL',"\n"); 11require_once(DOKU_INC.'inc/parserutils.php'); 12require_once(DOKU_INC.'inc/form.php'); 13 14/** 15 * Convenience function to quickly build a wikilink 16 * 17 * @author Andreas Gohr <andi@splitbrain.org> 18 */ 19function html_wikilink($id,$name=NULL,$search=''){ 20 static $xhtml_renderer = NULL; 21 if(is_null($xhtml_renderer)){ 22 require_once(DOKU_INC.'inc/parser/xhtml.php'); 23 $xhtml_renderer = new Doku_Renderer_xhtml(); 24 } 25 26 return $xhtml_renderer->internallink($id,$name,$search,true); 27} 28 29/** 30 * Helps building long attribute lists 31 * 32 * @author Andreas Gohr <andi@splitbrain.org> 33 */ 34function html_attbuild($attributes){ 35 $ret = ''; 36 foreach ( $attributes as $key => $value ) { 37 $ret .= $key.'="'.formtext($value).'" '; 38 } 39 return trim($ret); 40} 41 42/** 43 * The loginform 44 * 45 * @author Andreas Gohr <andi@splitbrain.org> 46 */ 47function html_login(){ 48 global $lang; 49 global $conf; 50 global $ID; 51 global $auth; 52 53 print p_locale_xhtml('login'); 54 print '<div class="centeralign">'.NL; 55 $form = new Doku_Form('dw__login'); 56 $form->startFieldset($lang['btn_login']); 57 $form->addHidden('id', $ID); 58 $form->addHidden('do', 'login'); 59 $form->addElement(form_makeTextField('u', $_REQUEST['u'], $lang['user'], 'focus__this', 'block')); 60 $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block')); 61 $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple')); 62 $form->addElement(form_makeButton('submit', '', $lang['btn_login'])); 63 $form->endFieldset(); 64 html_form('login', $form); 65 66 if($auth && $auth->canDo('addUser') && actionOK('register')){ 67 print '<p>'; 68 print $lang['reghere']; 69 print ': <a href="'.wl($ID,'do=register').'" rel="nofollow" class="wikilink1">'.$lang['register'].'</a>'; 70 print '</p>'; 71 } 72 73 if ($auth && $auth->canDo('modPass') && actionOK('resendpwd')) { 74 print '<p>'; 75 print $lang['pwdforget']; 76 print ': <a href="'.wl($ID,'do=resendpwd').'" rel="nofollow" class="wikilink1">'.$lang['btn_resendpwd'].'</a>'; 77 print '</p>'; 78 } 79 print '</div>'.NL; 80} 81 82/** 83 * prints a section editing button 84 * used as a callback in html_secedit 85 * 86 * @author Andreas Gohr <andi@splitbrain.org> 87 */ 88function html_secedit_button($matches){ 89 global $ID; 90 global $INFO; 91 92 $section = $matches[2]; 93 $name = $matches[1]; 94 95 $secedit = ''; 96 $secedit .= '<div class="secedit">'; 97 $secedit .= html_btn('secedit',$ID,'', 98 array('do' => 'edit', 99 'lines' => "$section", 100 'rev' => $INFO['lastmod']), 101 'post', $name); 102 $secedit .= '</div>'; 103 return $secedit; 104} 105 106/** 107 * inserts section edit buttons if wanted or removes the markers 108 * 109 * @author Andreas Gohr <andi@splitbrain.org> 110 */ 111function html_secedit($text,$show=true){ 112 global $INFO; 113 114 if($INFO['writable'] && $show && !$INFO['rev']){ 115 $text = preg_replace_callback('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#', 116 'html_secedit_button', $text); 117 }else{ 118 $text = preg_replace('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#','',$text); 119 } 120 121 return $text; 122} 123 124/** 125 * Just the back to top button (in its own form) 126 * 127 * @author Andreas Gohr <andi@splitbrain.org> 128 */ 129function html_topbtn(){ 130 global $lang; 131 132 $ret = ''; 133 $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>'; 134 135 return $ret; 136} 137 138/** 139 * Displays a button (using its own form) 140 * If tooltip exists, the access key tooltip is replaced. 141 * 142 * @author Andreas Gohr <andi@splitbrain.org> 143 */ 144function html_btn($name,$id,$akey,$params,$method='get',$tooltip=''){ 145 global $conf; 146 global $lang; 147 148 $label = $lang['btn_'.$name]; 149 150 $ret = ''; 151 $tip = ''; 152 153 //filter id (without urlencoding) 154 $id = idfilter($id,false); 155 156 //make nice URLs even for buttons 157 if($conf['userewrite'] == 2){ 158 $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id; 159 }elseif($conf['userewrite']){ 160 $script = DOKU_BASE.$id; 161 }else{ 162 $script = DOKU_BASE.DOKU_SCRIPT; 163 $params['id'] = $id; 164 } 165 166 $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">'; 167 168 if(is_array($params)){ 169 reset($params); 170 while (list($key, $val) = each($params)) { 171 $ret .= '<input type="hidden" name="'.$key.'" '; 172 $ret .= 'value="'.htmlspecialchars($val).'" />'; 173 } 174 } 175 176 if ($tooltip!='') { 177 $tip = htmlspecialchars($tooltip); 178 }else{ 179 $tip = htmlspecialchars($label); 180 } 181 182 $ret .= '<input type="submit" value="'.htmlspecialchars($label).'" class="button" '; 183 if($akey){ 184 $tip .= ' [ALT+'.strtoupper($akey).']'; 185 $ret .= 'accesskey="'.$akey.'" '; 186 } 187 $ret .= 'title="'.$tip.'" '; 188 $ret .= '/>'; 189 $ret .= '</div></form>'; 190 191 return $ret; 192} 193 194/** 195 * show a wiki page 196 * 197 * @author Andreas Gohr <andi@splitbrain.org> 198 */ 199function html_show($txt=''){ 200 global $ID; 201 global $REV; 202 global $HIGH; 203 global $INFO; 204 //disable section editing for old revisions or in preview 205 if($txt || $REV){ 206 $secedit = false; 207 }else{ 208 $secedit = true; 209 } 210 211 if ($txt){ 212 //PreviewHeader 213 echo '<br id="scroll__here" />'; 214 echo p_locale_xhtml('preview'); 215 echo '<div class="preview">'; 216 $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit); 217 if($INFO['prependTOC']) $html = tpl_toc(true).$html; 218 echo $html; 219 echo '<div class="clearer"></div>'; 220 echo '</div>'; 221 222 }else{ 223 if ($REV) print p_locale_xhtml('showrev'); 224 $html = p_wiki_xhtml($ID,$REV,true); 225 $html = html_secedit($html,$secedit); 226 if($INFO['prependTOC']) $html = tpl_toc(true).$html; 227 $html = html_hilight($html,$HIGH); 228 echo $html; 229 } 230} 231 232/** 233 * ask the user about how to handle an exisiting draft 234 * 235 * @author Andreas Gohr <andi@splitbrain.org> 236 */ 237function html_draft(){ 238 global $INFO; 239 global $ID; 240 global $lang; 241 global $conf; 242 $draft = unserialize(io_readFile($INFO['draft'],false)); 243 $text = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true)); 244 245 print p_locale_xhtml('draft'); 246 $form = new Doku_Form('dw__editform'); 247 $form->addHidden('id', $ID); 248 $form->addHidden('date', $draft['date']); 249 $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly'))); 250 $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status'))); 251 $form->addElement($lang['draftdate'].' '. strftime($conf['dformat'],filemtime($INFO['draft']))); 252 $form->addElement(form_makeCloseTag('div')); 253 $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1'))); 254 $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2'))); 255 $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3'))); 256 html_form('draft', $form); 257} 258 259/** 260 * Highlights searchqueries in HTML code 261 * 262 * @author Andreas Gohr <andi@splitbrain.org> 263 * @author Harry Fuecks <hfuecks@gmail.com> 264 */ 265function html_hilight($html,$phrases){ 266 $regex = join('|',array_map('preg_quote_cb',array_filter((array) $phrases))); 267 268 if ($regex === '') return $html; 269 $html = preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html); 270 return $html; 271} 272 273/** 274 * Callback used by html_hilight() 275 * 276 * @author Harry Fuecks <hfuecks@gmail.com> 277 */ 278function html_hilight_callback($m) { 279 $hlight = unslash($m[0]); 280 if ( !isset($m[2])) { 281 $hlight = '<span class="search_hit">'.$hlight.'</span>'; 282 } 283 return $hlight; 284} 285 286/** 287 * Run a search and display the result 288 * 289 * @author Andreas Gohr <andi@splitbrain.org> 290 */ 291function html_search(){ 292 require_once(DOKU_INC.'inc/search.php'); 293 require_once(DOKU_INC.'inc/fulltext.php'); 294 global $conf; 295 global $QUERY; 296 global $ID; 297 global $lang; 298 299 print p_locale_xhtml('searchpage'); 300 flush(); 301 302 //check if search is restricted to namespace 303 if(preg_match('/([^@]*)@([^@]*)/',$QUERY,$match)) { 304 $id = cleanID($match[1]); 305 if(empty($id)) { 306 print '<div class="nothing">'.$lang['nothingfound'].'</div>'; 307 flush(); 308 return; 309 } 310 } else { 311 $id = cleanID($QUERY); 312 } 313 314 //show progressbar 315 print '<div class="centeralign" id="dw__loading">'.NL; 316 print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL; 317 print 'showLoadBar();'.NL; 318 print '//--><!]]></script>'.NL; 319 print '<br /></div>'.NL; 320 flush(); 321 322 //do quick pagesearch 323 $data = array(); 324 325 $data = ft_pageLookup($id); 326 if(count($data)){ 327 print '<div class="search_quickresult">'; 328 print '<h3>'.$lang['quickhits'].':</h3>'; 329 print '<ul class="search_quickhits">'; 330 foreach($data as $id){ 331 print '<li> '; 332 print html_wikilink(':'.$id,noNS($id)); 333 print '</li> '; 334 } 335 print '</ul> '; 336 //clear float (see http://www.complexspiral.com/publications/containing-floats/) 337 print '<div class="clearer"> </div>'; 338 print '</div>'; 339 } 340 flush(); 341 342 //do fulltext search 343 $data = ft_pageSearch($QUERY,$regex); 344 if(count($data)){ 345 $num = 1; 346 foreach($data as $id => $cnt){ 347 print '<div class="search_result">'; 348 print html_wikilink(':'.$id,$conf['useheading']?NULL:$id,$regex); 349 print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />'; 350 if($num < 15){ // create snippets for the first number of matches only #FIXME add to conf ? 351 print '<div class="search_snippet">'.ft_snippet($id,$regex).'</div>'; 352 } 353 print '</div>'; 354 flush(); 355 $num++; 356 } 357 }else{ 358 print '<div class="nothing">'.$lang['nothingfound'].'</div>'; 359 } 360 361 //hide progressbar 362 print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL; 363 print 'hideLoadBar("dw__loading");'.NL; 364 print '//--><!]]></script>'.NL; 365 flush(); 366} 367 368/** 369 * Display error on locked pages 370 * 371 * @author Andreas Gohr <andi@splitbrain.org> 372 */ 373function html_locked(){ 374 global $ID; 375 global $conf; 376 global $lang; 377 global $INFO; 378 379 $locktime = filemtime(wikiLockFN($ID)); 380 $expire = @strftime($conf['dformat'], $locktime + $conf['locktime'] ); 381 $min = round(($conf['locktime'] - (time() - $locktime) )/60); 382 383 print p_locale_xhtml('locked'); 384 print '<ul>'; 385 print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.$INFO['locked'].'</li>'; 386 print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>'; 387 print '</ul>'; 388} 389 390/** 391 * list old revisions 392 * 393 * @author Andreas Gohr <andi@splitbrain.org> 394 * @author Ben Coburn <btcoburn@silicodon.net> 395 */ 396function html_revisions($first=0){ 397 global $ID; 398 global $INFO; 399 global $conf; 400 global $lang; 401 /* we need to get one additionally log entry to be able to 402 * decide if this is the last page or is there another one. 403 * see html_recent() 404 */ 405 $revisions = getRevisions($ID, $first, $conf['recent']+1); 406 if(count($revisions)==0 && $first!=0){ 407 $first=0; 408 $revisions = getRevisions($ID, $first, $conf['recent']+1);; 409 } 410 $hasNext = false; 411 if (count($revisions)>$conf['recent']) { 412 $hasNext = true; 413 array_pop($revisions); // remove extra log entry 414 } 415 416 $date = @strftime($conf['dformat'],$INFO['lastmod']); 417 418 print p_locale_xhtml('revisions'); 419 print '<form action="'.wl($ID).'" method="post" id="page__revisions">'; 420 print '<ul>'; 421 if($INFO['exists'] && $first==0){ 422 print (isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>'; 423 print '<div class="li">'; 424 print '<input type="checkbox" name="rev2[]" value="current" /> '; 425 426 print $date; 427 428 print ' <img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" /> '; 429 430 print '<a class="wikilink1" href="'.wl($ID).'">'.$ID.'</a> '; 431 432 print ' – '; 433 print htmlspecialchars($INFO['sum']); 434 print ' <span class="user">'; 435 print (empty($INFO['editor']))?('('.$lang['external_edit'].')'):htmlspecialchars($INFO['editor']); 436 print '</span> '; 437 438 print '('.$lang['current'].')'; 439 print '</div>'; 440 print '</li>'; 441 } 442 443 foreach($revisions as $rev){ 444 $date = strftime($conf['dformat'],$rev); 445 $info = getRevisionInfo($ID,$rev,true); 446 $exists = page_exists($ID,$rev); 447 448 print ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>'; 449 print '<div class="li">'; 450 if($exists){ 451 print '<input type="checkbox" name="rev2[]" value="'.$rev.'" /> '; 452 }else{ 453 print '<img src="'.DOKU_BASE.'lib/images/blank.gif" width="14" height="11" alt="" /> '; 454 } 455 print $date; 456 457 if($exists){ 458 print ' <a href="'.wl($ID,"rev=$rev,do=diff").'">'; 459 $p = array(); 460 $p['src'] = DOKU_BASE.'lib/images/diff.png'; 461 $p['width'] = 15; 462 $p['height'] = 11; 463 $p['title'] = $lang['diff']; 464 $p['alt'] = $lang['diff']; 465 $att = buildAttributes($p); 466 print "<img $att />"; 467 print '</a> '; 468 469 print '<a class="wikilink1" href="'.wl($ID,"rev=$rev").'">'.$ID.'</a>'; 470 }else{ 471 print ' <img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" /> '; 472 print $ID; 473 } 474 475 print ' – '; 476 print htmlspecialchars($info['sum']); 477 print ' <span class="user">'; 478 if($info['user']){ 479 print htmlspecialchars($info['user']); 480 }else{ 481 print $info['ip']; 482 } 483 print '</span>'; 484 485 print '</div>'; 486 print '</li>'; 487 } 488 print '</ul>'; 489 print '<input name="do[diff]" type="submit" value="'.$lang['diff2'].'" class="button" />'; 490 print '</form>'; 491 492 print '<div class="pagenav">'; 493 $last = $first + $conf['recent']; 494 if ($first > 0) { 495 $first -= $conf['recent']; 496 if ($first < 0) $first = 0; 497 print '<div class="pagenav-prev">'; 498 print html_btn('newer',$ID,"p",array('do' => 'revisions', 'first' => $first)); 499 print '</div>'; 500 } 501 if ($hasNext) { 502 print '<div class="pagenav-next">'; 503 print html_btn('older',$ID,"n",array('do' => 'revisions', 'first' => $last)); 504 print '</div>'; 505 } 506 print '</div>'; 507 508} 509 510/** 511 * display recent changes 512 * 513 * @author Andreas Gohr <andi@splitbrain.org> 514 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 515 * @author Ben Coburn <btcoburn@silicodon.net> 516 */ 517function html_recent($first=0){ 518 global $conf; 519 global $lang; 520 global $ID; 521 /* we need to get one additionally log entry to be able to 522 * decide if this is the last page or is there another one. 523 * This is the cheapest solution to get this information. 524 */ 525 $recents = getRecents($first,$conf['recent'] + 1,getNS($ID)); 526 if(count($recents) == 0 && $first != 0){ 527 $first=0; 528 $recents = getRecents($first,$conf['recent'] + 1,getNS($ID)); 529 } 530 $hasNext = false; 531 if (count($recents)>$conf['recent']) { 532 $hasNext = true; 533 array_pop($recents); // remove extra log entry 534 } 535 536 print p_locale_xhtml('recent'); 537 print '<ul>'; 538 539 foreach($recents as $recent){ 540 $date = strftime($conf['dformat'],$recent['date']); 541 print ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>'; 542 print '<div class="li">'; 543 544 print $date.' '; 545 546 print '<a href="'.wl($recent['id'],"do=diff").'">'; 547 $p = array(); 548 $p['src'] = DOKU_BASE.'lib/images/diff.png'; 549 $p['width'] = 15; 550 $p['height'] = 11; 551 $p['title'] = $lang['diff']; 552 $p['alt'] = $lang['diff']; 553 $att = buildAttributes($p); 554 print "<img $att />"; 555 print '</a> '; 556 557 print '<a href="'.wl($recent['id'],"do=revisions").'">'; 558 $p = array(); 559 $p['src'] = DOKU_BASE.'lib/images/history.png'; 560 $p['width'] = 12; 561 $p['height'] = 14; 562 $p['title'] = $lang['btn_revs']; 563 $p['alt'] = $lang['btn_revs']; 564 $att = buildAttributes($p); 565 print "<img $att />"; 566 print '</a> '; 567 568 print html_wikilink(':'.$recent['id'],$conf['useheading']?NULL:$recent['id']); 569 print ' – '.htmlspecialchars($recent['sum']); 570 571 print ' <span class="user">'; 572 if($recent['user']){ 573 print htmlspecialchars($recent['user']); 574 }else{ 575 print $recent['ip']; 576 } 577 print '</span>'; 578 579 print '</div>'; 580 print '</li>'; 581 } 582 print '</ul>'; 583 584 print '<div class="pagenav">'; 585 $last = $first + $conf['recent']; 586 if ($first > 0) { 587 $first -= $conf['recent']; 588 if ($first < 0) $first = 0; 589 print '<div class="pagenav-prev">'; 590 print html_btn('newer','',"p",array('do' => 'recent', 'first' => $first)); 591 print '</div>'; 592 } 593 if ($hasNext) { 594 print '<div class="pagenav-next">'; 595 print html_btn('older','',"n",array('do' => 'recent', 'first' => $last)); 596 print '</div>'; 597 } 598 print '</div>'; 599} 600 601/** 602 * Display page index 603 * 604 * @author Andreas Gohr <andi@splitbrain.org> 605 */ 606function html_index($ns){ 607 require_once(DOKU_INC.'inc/search.php'); 608 global $conf; 609 global $ID; 610 $dir = $conf['datadir']; 611 $ns = cleanID($ns); 612 #fixme use appropriate function 613 if(empty($ns)){ 614 $ns = dirname(str_replace(':','/',$ID)); 615 if($ns == '.') $ns =''; 616 } 617 $ns = utf8_encodeFN(str_replace(':','/',$ns)); 618 619 echo p_locale_xhtml('index'); 620 echo '<div id="index__tree">'; 621 622 $data = array(); 623 search($data,$conf['datadir'],'search_index',array('ns' => $ns)); 624 echo html_buildlist($data,'idx','html_list_index','html_li_index'); 625 626 echo '</div>'; 627} 628 629/** 630 * Index item formatter 631 * 632 * User function for html_buildlist() 633 * 634 * @author Andreas Gohr <andi@splitbrain.org> 635 */ 636function html_list_index($item){ 637 global $ID; 638 $ret = ''; 639 $base = ':'.$item['id']; 640 $base = substr($base,strrpos($base,':')+1); 641 if($item['type']=='d'){ 642 $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" class="idx_dir"><strong>'; 643 $ret .= $base; 644 $ret .= '</strong></a>'; 645 }else{ 646 $ret .= html_wikilink(':'.$item['id']); 647 } 648 return $ret; 649} 650 651/** 652 * Index List item 653 * 654 * This user function is used in html_build_lidt to build the 655 * <li> tags for namespaces when displaying the page index 656 * it gives different classes to opened or closed "folders" 657 * 658 * @author Andreas Gohr <andi@splitbrain.org> 659 */ 660function html_li_index($item){ 661 if($item['type'] == "f"){ 662 return '<li class="level'.$item['level'].'">'; 663 }elseif($item['open']){ 664 return '<li class="open">'; 665 }else{ 666 return '<li class="closed">'; 667 } 668} 669 670/** 671 * Default List item 672 * 673 * @author Andreas Gohr <andi@splitbrain.org> 674 */ 675function html_li_default($item){ 676 return '<li class="level'.$item['level'].'">'; 677} 678 679/** 680 * Build an unordered list 681 * 682 * Build an unordered list from the given $data array 683 * Each item in the array has to have a 'level' property 684 * the item itself gets printed by the given $func user 685 * function. The second and optional function is used to 686 * print the <li> tag. Both user function need to accept 687 * a single item. 688 * 689 * Both user functions can be given as array to point to 690 * a member of an object. 691 * 692 * @author Andreas Gohr <andi@splitbrain.org> 693 */ 694function html_buildlist($data,$class,$func,$lifunc='html_li_default'){ 695 $level = 0; 696 $opens = 0; 697 $ret = ''; 698 699 foreach ($data as $item){ 700 701 if( $item['level'] > $level ){ 702 //open new list 703 for($i=0; $i<($item['level'] - $level); $i++){ 704 if ($i) $ret .= "<li class=\"clear\">\n"; 705 $ret .= "\n<ul class=\"$class\">\n"; 706 } 707 }elseif( $item['level'] < $level ){ 708 //close last item 709 $ret .= "</li>\n"; 710 for ($i=0; $i<($level - $item['level']); $i++){ 711 //close higher lists 712 $ret .= "</ul>\n</li>\n"; 713 } 714 }else{ 715 //close last item 716 $ret .= "</li>\n"; 717 } 718 719 //remember current level 720 $level = $item['level']; 721 722 //print item 723 $ret .= call_user_func($lifunc,$item); 724 $ret .= '<div class="li">'; 725 726 $ret .= call_user_func($func,$item); 727 $ret .= '</div>'; 728 } 729 730 //close remaining items and lists 731 for ($i=0; $i < $level; $i++){ 732 $ret .= "</li></ul>\n"; 733 } 734 735 return $ret; 736} 737 738/** 739 * display backlinks 740 * 741 * @author Andreas Gohr <andi@splitbrain.org> 742 * @author Michael Klier <chi@chimeric.de> 743 */ 744function html_backlinks(){ 745 require_once(DOKU_INC.'inc/fulltext.php'); 746 global $ID; 747 global $conf; 748 global $lang; 749 750 print p_locale_xhtml('backlinks'); 751 752 $data = ft_backlinks($ID); 753 754 if(!empty($data)) { 755 print '<ul class="idx">'; 756 foreach($data as $blink){ 757 print '<li><div class="li">'; 758 print html_wikilink(':'.$blink,$conf['useheading']?NULL:$blink); 759 print '</div></li>'; 760 } 761 print '</ul>'; 762 } else { 763 print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>'; 764 } 765} 766 767/** 768 * show diff 769 * 770 * @author Andreas Gohr <andi@splitbrain.org> 771 */ 772function html_diff($text='',$intro=true){ 773 require_once(DOKU_INC.'inc/DifferenceEngine.php'); 774 global $ID; 775 global $REV; 776 global $lang; 777 global $conf; 778 779 // we're trying to be clever here, revisions to compare can be either 780 // given as rev and rev2 parameters, with rev2 being optional. Or in an 781 // array in rev2. 782 $rev1 = $REV; 783 784 if(is_array($_REQUEST['rev2'])){ 785 $rev1 = (int) $_REQUEST['rev2'][0]; 786 $rev2 = (int) $_REQUEST['rev2'][1]; 787 788 if(!$rev1){ 789 $rev1 = $rev2; 790 unset($rev2); 791 } 792 }else{ 793 $rev2 = (int) $_REQUEST['rev2']; 794 } 795 796 if($text){ // compare text to the most current revision 797 $l_rev = ''; 798 $l_text = rawWiki($ID,''); 799 $l_head = '<a class="wikilink1" href="'.wl($ID).'">'. 800 $ID.' '.strftime($conf['dformat'],@filemtime(wikiFN($ID))).'</a> '. 801 $lang['current']; 802 803 $r_rev = ''; 804 $r_text = cleanText($text); 805 $r_head = $lang['yours']; 806 }else{ 807 if($rev1 && $rev2){ // two specific revisions wanted 808 // make sure order is correct (older on the left) 809 if($rev1 < $rev2){ 810 $l_rev = $rev1; 811 $r_rev = $rev2; 812 }else{ 813 $l_rev = $rev2; 814 $r_rev = $rev1; 815 } 816 }elseif($rev1){ // single revision given, compare to current 817 $r_rev = ''; 818 $l_rev = $rev1; 819 }else{ // no revision was given, compare previous to current 820 $r_rev = ''; 821 $revs = getRevisions($ID, 0, 1); 822 $l_rev = $revs[0]; 823 } 824 825 // when both revisions are empty then the page was created just now 826 if(!$l_rev && !$r_rev){ 827 $l_text = ''; 828 }else{ 829 $l_text = rawWiki($ID,$l_rev); 830 } 831 $r_text = rawWiki($ID,$r_rev); 832 833 834 if(!$l_rev){ 835 $l_head = '—'; 836 }else{ 837 $l_head = '<a class="wikilink1" href="'.wl($ID,"rev=$l_rev").'">'. 838 $ID.' '.strftime($conf['dformat'],$l_rev).'</a>'; 839 } 840 841 if($r_rev){ 842 $r_head = '<a class="wikilink1" href="'.wl($ID,"rev=$r_rev").'">'. 843 $ID.' '.strftime($conf['dformat'],$r_rev).'</a>'; 844 }elseif($_rev = @filemtime(wikiFN($ID))){ 845 $r_head = '<a class="wikilink1" href="'.wl($ID).'">'. 846 $ID.' '.strftime($conf['dformat'],$_rev).'</a> '. 847 $lang['current']; 848 }else{ 849 $r_head = '— '.$lang['current']; 850 } 851 } 852 853 $df = new Diff(explode("\n",htmlspecialchars($l_text)), 854 explode("\n",htmlspecialchars($r_text))); 855 856 $tdf = new TableDiffFormatter(); 857 if($intro) print p_locale_xhtml('diff'); 858 ?> 859 <table class="diff"> 860 <tr> 861 <th colspan="2"> 862 <?php echo $l_head?> 863 </th> 864 <th colspan="2"> 865 <?php echo $r_head?> 866 </th> 867 </tr> 868 <?php echo $tdf->format($df)?> 869 </table> 870 <?php 871} 872 873/** 874 * show warning on conflict detection 875 * 876 * @author Andreas Gohr <andi@splitbrain.org> 877 */ 878function html_conflict($text,$summary){ 879 global $ID; 880 global $lang; 881 882 print p_locale_xhtml('conflict'); 883 $form = new Doku_Form('dw__editform'); 884 $form->addHidden('id', $ID); 885 $form->addHidden('wikitext', $text); 886 $form->addHidden('summary', $summary); 887 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s'))); 888 $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel'])); 889 html_form('conflict', $form); 890 print '<br /><br /><br /><br />'.NL; 891} 892 893/** 894 * Prints the global message array 895 * 896 * @author Andreas Gohr <andi@splitbrain.org> 897 */ 898function html_msgarea(){ 899 global $MSG; 900 901 if(!isset($MSG)) return; 902 903 foreach($MSG as $msg){ 904 print '<div class="'.$msg['lvl'].'">'; 905 print $msg['msg']; 906 print '</div>'; 907 } 908} 909 910/** 911 * Prints the registration form 912 * 913 * @author Andreas Gohr <andi@splitbrain.org> 914 */ 915function html_register(){ 916 global $lang; 917 global $conf; 918 global $ID; 919 920 print p_locale_xhtml('register'); 921 print '<div class="centeralign">'.NL; 922 $form = new Doku_Form('dw__register', wl($ID)); 923 $form->startFieldset($lang['register']); 924 $form->addHidden('do', 'register'); 925 $form->addHidden('save', '1'); 926 $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], null, 'block', array('size'=>'50'))); 927 if (!$conf['autopasswd']) { 928 $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50'))); 929 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50'))); 930 } 931 $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', array('size'=>'50'))); 932 $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', array('size'=>'50'))); 933 $form->addElement(form_makeButton('submit', '', $lang['register'])); 934 $form->endFieldset(); 935 html_form('register', $form); 936 937 print '</div>'.NL; 938} 939 940/** 941 * Print the update profile form 942 * 943 * @author Christopher Smith <chris@jalakai.co.uk> 944 * @author Andreas Gohr <andi@splitbrain.org> 945 */ 946function html_updateprofile(){ 947 global $lang; 948 global $conf; 949 global $ID; 950 global $INFO; 951 global $auth; 952 953 print p_locale_xhtml('updateprofile'); 954 955 if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name']; 956 if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail']; 957 print '<div class="centeralign">'.NL; 958 $form = new Doku_Form('dw__register', wl($ID)); 959 $form->startFieldset($lang['profile']); 960 $form->addHidden('do', 'profile'); 961 $form->addHidden('save', '1'); 962 $form->addElement(form_makeTextField('fullname', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled'))); 963 $attr = array('size'=>'50'); 964 if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled'; 965 $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', $attr)); 966 $attr = array('size'=>'50'); 967 if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled'; 968 $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', $attr)); 969 $form->addElement(form_makeTag('br')); 970 if ($auth->canDo('modPass')) { 971 $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50'))); 972 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50'))); 973 } 974 if ($conf['profileconfirm']) { 975 $form->addElement(form_makeTag('br')); 976 $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50'))); 977 } 978 $form->addElement(form_makeButton('submit', '', $lang['btn_save'])); 979 $form->addElement(form_makeButton('reset', '', $lang['btn_reset'])); 980 $form->endFieldset(); 981 html_form('updateprofile', $form); 982 print '</div>'.NL; 983} 984 985/** 986 * This displays the edit form (lots of logic included) 987 * 988 * @fixme this is a huge lump of code and should be modularized 989 * @triggers HTML_PAGE_FROMTEMPLATE 990 * @triggers HTML_EDITFORM_INJECTION 991 * @author Andreas Gohr <andi@splitbrain.org> 992 */ 993function html_edit($text=null,$include='edit'){ //FIXME: include needed? 994 global $ID; 995 global $REV; 996 global $DATE; 997 global $RANGE; 998 global $PRE; 999 global $SUF; 1000 global $INFO; 1001 global $SUM; 1002 global $lang; 1003 global $conf; 1004 1005 //set summary default 1006 if(!$SUM){ 1007 if($REV){ 1008 $SUM = $lang['restored']; 1009 }elseif(!$INFO['exists']){ 1010 $SUM = $lang['created']; 1011 } 1012 } 1013 1014 //no text? Load it! 1015 if(!isset($text)){ 1016 $pr = false; //no preview mode 1017 if($INFO['exists']){ 1018 if($RANGE){ 1019 list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV); 1020 }else{ 1021 $text = rawWiki($ID,$REV); 1022 } 1023 $check = md5($text); 1024 $mod = false; 1025 }else{ 1026 //try to load a pagetemplate 1027 $data = array($ID); 1028 $text = trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true); 1029 $check = md5(''); 1030 $mod = $text!==''; 1031 } 1032 }else{ 1033 $pr = true; //preview mode 1034 if (isset($_REQUEST['changecheck'])) { 1035 $check = $_REQUEST['changecheck']; 1036 $mod = md5($text)!==$check; 1037 } else { 1038 // Why? Assume default text is unmodified. 1039 $check = md5($text); 1040 $mod = false; 1041 } 1042 } 1043 1044 $wr = $INFO['writable']; 1045 if($wr){ 1046 if ($REV) print p_locale_xhtml('editrev'); 1047 print p_locale_xhtml($include); 1048 }else{ 1049 // check pseudo action 'source' 1050 if(!actionOK('source')){ 1051 msg('Command disabled: source',-1); 1052 return; 1053 } 1054 print p_locale_xhtml('read'); 1055 } 1056 if(!$DATE) $DATE = $INFO['lastmod']; 1057 1058 1059?> 1060 <div style="width:99%;"> 1061 1062 <div class="toolbar"> 1063 <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.strftime($conf['dformat']);?></div> 1064 <div id="tool__bar"><?php if($wr){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>" 1065 target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div> 1066 1067 <?php if($wr){?> 1068 <script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!-- 1069 <?php /* sets changed to true when previewed */?> 1070 textChanged = <?php ($mod) ? print 'true' : print 'false' ?>; 1071 //--><!]]></script> 1072 <span id="spell__action"></span> 1073 <div id="spell__suggest"></div> 1074 <?php } ?> 1075 </div> 1076 <div id="spell__result"></div> 1077<?php 1078 $form = new Doku_Form('dw__editform'); 1079 $form->addHidden('id', $ID); 1080 $form->addHidden('rev', $REV); 1081 $form->addHidden('date', $DATE); 1082 $form->addHidden('prefix', $PRE); 1083 $form->addHidden('suffix', $SUF); 1084 $form->addHidden('changecheck', $check); 1085 $attr = array('tabindex'=>'1'); 1086 if (!$wr) $attr['readonly'] = 'readonly'; 1087 $form->addElement(form_makeWikiText($text, $attr)); 1088 $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar'))); 1089 $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl'))); 1090 $form->addElement(form_makeCloseTag('div')); 1091 if ($wr) { 1092 $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons'))); 1093 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4'))); 1094 $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5'))); 1095 $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6'))); 1096 $form->addElement(form_makeCloseTag('div')); 1097 $form->addElement(form_makeOpenTag('div', array('class'=>'summary'))); 1098 $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2'))); 1099 $elem = html_minoredit(); 1100 if ($elem) $form->addElement($elem); 1101 $form->addElement(form_makeCloseTag('div')); 1102 } 1103 $form->addElement(form_makeCloseTag('div')); 1104 html_form('edit', $form); 1105 print '</div>'.NL; 1106} 1107 1108/** 1109 * Adds a checkbox for minor edits for logged in users 1110 * 1111 * @author Andrea Gohr <andi@splitbrain.org> 1112 */ 1113function html_minoredit(){ 1114 global $conf; 1115 global $lang; 1116 // minor edits are for logged in users only 1117 if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){ 1118 return false; 1119 } 1120 1121 $p = array(); 1122 $p['tabindex'] = 3; 1123 if(!empty($_REQUEST['minor'])) $p['checked']='checked'; 1124 return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p); 1125} 1126 1127/** 1128 * prints some debug info 1129 * 1130 * @author Andreas Gohr <andi@splitbrain.org> 1131 */ 1132function html_debug(){ 1133 global $conf; 1134 global $lang; 1135 global $auth; 1136 global $INFO; 1137 1138 //remove sensitive data 1139 $cnf = $conf; 1140 debug_guard($cnf); 1141 $nfo = $INFO; 1142 debug_guard($nfo); 1143 $ses = $_SESSION; 1144 debug_guard($ses); 1145 1146 print '<html><body>'; 1147 1148 print '<p>When reporting bugs please send all the following '; 1149 print 'output as a mail to andi@splitbrain.org '; 1150 print 'The best way to do this is to save this page in your browser</p>'; 1151 1152 print '<b>$INFO:</b><pre>'; 1153 print_r($nfo); 1154 print '</pre>'; 1155 1156 print '<b>$_SERVER:</b><pre>'; 1157 print_r($_SERVER); 1158 print '</pre>'; 1159 1160 print '<b>$conf:</b><pre>'; 1161 print_r($cnf); 1162 print '</pre>'; 1163 1164 print '<b>DOKU_BASE:</b><pre>'; 1165 print DOKU_BASE; 1166 print '</pre>'; 1167 1168 print '<b>abs DOKU_BASE:</b><pre>'; 1169 print DOKU_URL; 1170 print '</pre>'; 1171 1172 print '<b>rel DOKU_BASE:</b><pre>'; 1173 print dirname($_SERVER['PHP_SELF']).'/'; 1174 print '</pre>'; 1175 1176 print '<b>PHP Version:</b><pre>'; 1177 print phpversion(); 1178 print '</pre>'; 1179 1180 print '<b>locale:</b><pre>'; 1181 print setlocale(LC_ALL,0); 1182 print '</pre>'; 1183 1184 print '<b>encoding:</b><pre>'; 1185 print $lang['encoding']; 1186 print '</pre>'; 1187 1188 if($auth){ 1189 print '<b>Auth backend capabilities:</b><pre>'; 1190 print_r($auth->cando); 1191 print '</pre>'; 1192 } 1193 1194 print '<b>$_SESSION:</b><pre>'; 1195 print_r($ses); 1196 print '</pre>'; 1197 1198 print '<b>Environment:</b><pre>'; 1199 print_r($_ENV); 1200 print '</pre>'; 1201 1202 print '<b>PHP settings:</b><pre>'; 1203 $inis = ini_get_all(); 1204 print_r($inis); 1205 print '</pre>'; 1206 1207 print '</body></html>'; 1208} 1209 1210function html_admin(){ 1211 global $ID; 1212 global $INFO; 1213 global $lang; 1214 global $conf; 1215 1216 print p_locale_xhtml('admin'); 1217 1218 // build menu of admin functions from the plugins that handle them 1219 $pluginlist = plugin_list('admin'); 1220 $menu = array(); 1221 foreach ($pluginlist as $p) { 1222 if($obj =& plugin_load('admin',$p) === NULL) continue; 1223 1224 // check permissions 1225 if($obj->forAdminOnly() && !$INFO['isadmin']) continue; 1226 1227 $menu[] = array('plugin' => $p, 1228 'prompt' => $obj->getMenuText($conf['lang']), 1229 'sort' => $obj->getMenuSort() 1230 ); 1231 } 1232 1233 usort($menu, 'p_sort_modes'); 1234 1235 // output the menu 1236 ptln('<ul>'); 1237 1238 foreach ($menu as $item) { 1239 if (!$item['prompt']) continue; 1240 ptln(' <li><div class="li"><a href="'.wl($ID, 'do=admin&page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>'); 1241 } 1242 1243 ptln('</ul>'); 1244} 1245 1246/** 1247 * Form to request a new password for an existing account 1248 * 1249 * @author Benoit Chesneau <benoit@bchesneau.info> 1250 */ 1251function html_resendpwd() { 1252 global $lang; 1253 global $conf; 1254 global $ID; 1255 1256 print p_locale_xhtml('resendpwd'); 1257 print '<div class="centeralign">'.NL; 1258 $form = new Doku_Form('dw__resendpwd', wl($ID)); 1259 $form->startFieldset($lang['resendpwd']); 1260 $form->addHidden('do', 'resendpwd'); 1261 $form->addHidden('save', '1'); 1262 $form->addElement(form_makeTag('br')); 1263 $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block')); 1264 $form->addElement(form_makeTag('br')); 1265 $form->addElement(form_makeTag('br')); 1266 $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd'])); 1267 $form->endFieldset(); 1268 html_form('resendpwd', $form); 1269 print '</div>'.NL; 1270} 1271 1272/** 1273 * Return the TOC rendered to XHTML 1274 * 1275 * @author Andreas Gohr <andi@splitbrain.org> 1276 */ 1277function html_TOC($toc){ 1278 if(!count($toc)) return ''; 1279 global $lang; 1280 $out = '<!-- TOC START -->'.DOKU_LF; 1281 $out .= '<div class="toc">'.DOKU_LF; 1282 $out .= '<div class="tocheader toctoggle" id="toc__header">'; 1283 $out .= $lang['toc']; 1284 $out .= '</div>'.DOKU_LF; 1285 $out .= '<div id="toc__inside">'.DOKU_LF; 1286 $out .= html_buildlist($toc,'toc','html_list_toc'); 1287 $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF; 1288 $out .= '<!-- TOC END -->'.DOKU_LF; 1289 return $out; } 1290 1291/** 1292 * Callback for html_buildlist 1293 */ 1294function html_list_toc($item){ 1295 if($item['hid']){ 1296 $link = '#'.$item['hid']; 1297 }else{ 1298 $link = $item['link']; 1299 } 1300 1301 return '<span class="li"><a href="'.$link.'" class="toc">'. 1302 hsc($item['title']).'</a></span>'; 1303} 1304 1305/** 1306 * Helper function to build TOC items 1307 * 1308 * Returns an array ready to be added to a TOC array 1309 * 1310 * @param string $link - where to link (if $hash set to '#' it's a local anchor) 1311 * @param string $text - what to display in the TOC 1312 * @param int $level - nesting level 1313 * @param string $hash - is prepended to the given $link, set blank if you want full links 1314 */ 1315function html_mktocitem($link, $text, $level, $hash='#'){ 1316 global $conf; 1317 return array( 'link' => $hash.$link, 1318 'title' => $text, 1319 'type' => 'ul', 1320 'level' => $level); 1321} 1322 1323/** 1324 * Output a Doku_Form object. 1325 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT 1326 * 1327 * @author Tom N Harris <tnharris@whoopdedo.org> 1328 */ 1329function html_form($name, &$form) { 1330 // Safety check in case the caller forgets. 1331 $form->endFieldset(); 1332 trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false); 1333} 1334 1335/** 1336 * Form print function. 1337 * Just calls printForm() on the data object. 1338 */ 1339function html_form_output($data) { 1340 $data->printForm(); 1341} 1342 1343//Setup VIM: ex: et ts=2 enc=utf-8 : 1344