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