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