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')) die('meh.'); 10if(!defined('NL')) define('NL',"\n"); 11 12/** 13 * Convenience function to quickly build a wikilink 14 * 15 * @author Andreas Gohr <andi@splitbrain.org> 16 * @param string $id id of the target page 17 * @param string $name the name of the link, i.e. the text that is displayed 18 * @param string|array $search search string(s) that shall be highlighted in the target page 19 * @return string the HTML code of the link 20 */ 21function html_wikilink($id,$name=null,$search=''){ 22 /** @var Doku_Renderer_xhtml $xhtml_renderer */ 23 static $xhtml_renderer = null; 24 if(is_null($xhtml_renderer)){ 25 $xhtml_renderer = p_get_renderer('xhtml'); 26 } 27 28 return $xhtml_renderer->internallink($id,$name,$search,true,'navigation'); 29} 30 31/** 32 * The loginform 33 * 34 * @author Andreas Gohr <andi@splitbrain.org> 35 */ 36function html_login(){ 37 global $lang; 38 global $conf; 39 global $ID; 40 global $INPUT; 41 42 print p_locale_xhtml('login'); 43 print '<div class="centeralign">'.NL; 44 $form = new Doku_Form(array('id' => 'dw__login')); 45 $form->startFieldset($lang['btn_login']); 46 $form->addHidden('id', $ID); 47 $form->addHidden('do', 'login'); 48 $form->addElement(form_makeTextField('u', ((!$INPUT->bool('http_credentials')) ? $INPUT->str('u') : ''), $lang['user'], 'focus__this', 'block')); 49 $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block')); 50 if($conf['rememberme']) { 51 $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple')); 52 } 53 $form->addElement(form_makeButton('submit', '', $lang['btn_login'])); 54 $form->endFieldset(); 55 56 if(actionOK('register')){ 57 $form->addElement('<p>'.$lang['reghere'].': '.tpl_actionlink('register','','','',true).'</p>'); 58 } 59 60 if (actionOK('resendpwd')) { 61 $form->addElement('<p>'.$lang['pwdforget'].': '.tpl_actionlink('resendpwd','','','',true).'</p>'); 62 } 63 64 html_form('login', $form); 65 print '</div>'.NL; 66} 67 68 69/** 70 * Denied page content 71 * 72 * @return string html 73 */ 74function html_denied() { 75 print p_locale_xhtml('denied'); 76 77 if(empty($_SERVER['REMOTE_USER'])){ 78 html_login(); 79 } 80} 81 82/** 83 * inserts section edit buttons if wanted or removes the markers 84 * 85 * @author Andreas Gohr <andi@splitbrain.org> 86 * 87 * @param string $text 88 * @param bool $show show section edit buttons? 89 * @return string 90 */ 91function html_secedit($text,$show=true){ 92 global $INFO; 93 94 $regexp = '#<!-- EDIT(\d+) ([A-Z_]+) (?:"([^"]*)" )?\[(\d+-\d*)\] -->#'; 95 96 if(!$INFO['writable'] || !$show || $INFO['rev']){ 97 return preg_replace($regexp,'',$text); 98 } 99 100 return preg_replace_callback($regexp, 101 'html_secedit_button', $text); 102} 103 104/** 105 * prepares section edit button data for event triggering 106 * used as a callback in html_secedit 107 * 108 * @author Andreas Gohr <andi@splitbrain.org> 109 * 110 * @param array $matches matches with regexp 111 * @return string 112 * @triggers HTML_SECEDIT_BUTTON 113 */ 114function html_secedit_button($matches){ 115 $data = array('secid' => $matches[1], 116 'target' => strtolower($matches[2]), 117 'range' => $matches[count($matches) - 1]); 118 if (count($matches) === 5) { 119 $data['name'] = $matches[3]; 120 } 121 122 return trigger_event('HTML_SECEDIT_BUTTON', $data, 123 'html_secedit_get_button'); 124} 125 126/** 127 * prints a section editing button 128 * used as default action form HTML_SECEDIT_BUTTON 129 * 130 * @author Adrian Lang <lang@cosmocode.de> 131 * 132 * @param array $data name, section id and target 133 * @return string html 134 */ 135function html_secedit_get_button($data) { 136 global $ID; 137 global $INFO; 138 139 if (!isset($data['name']) || $data['name'] === '') return ''; 140 141 $name = $data['name']; 142 unset($data['name']); 143 144 $secid = $data['secid']; 145 unset($data['secid']); 146 147 return "<div class='secedit editbutton_" . $data['target'] . 148 " editbutton_" . $secid . "'>" . 149 html_btn('secedit', $ID, '', 150 array_merge(array('do' => 'edit', 151 'rev' => $INFO['lastmod'], 152 'summary' => '['.$name.'] '), $data), 153 'post', $name) . '</div>'; 154} 155 156/** 157 * Just the back to top button (in its own form) 158 * 159 * @author Andreas Gohr <andi@splitbrain.org> 160 * 161 * @return string html 162 */ 163function html_topbtn(){ 164 global $lang; 165 166 $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>'; 167 168 return $ret; 169} 170 171/** 172 * Displays a button (using its own form) 173 * If tooltip exists, the access key tooltip is replaced. 174 * 175 * @author Andreas Gohr <andi@splitbrain.org> 176 * 177 * @param string $name 178 * @param string $id 179 * @param string $akey access key 180 * @param string[] $params key-value pairs added as hidden inputs 181 * @param string $method 182 * @param string $tooltip 183 * @param bool|string $label label text, false: lookup btn_$name in localization 184 * @return string 185 */ 186function html_btn($name, $id, $akey, $params, $method='get', $tooltip='', $label=false){ 187 global $conf; 188 global $lang; 189 190 if (!$label) 191 $label = $lang['btn_'.$name]; 192 193 $ret = ''; 194 195 //filter id (without urlencoding) 196 $id = idfilter($id,false); 197 198 //make nice URLs even for buttons 199 if($conf['userewrite'] == 2){ 200 $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id; 201 }elseif($conf['userewrite']){ 202 $script = DOKU_BASE.$id; 203 }else{ 204 $script = DOKU_BASE.DOKU_SCRIPT; 205 $params['id'] = $id; 206 } 207 208 $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">'; 209 210 if(is_array($params)){ 211 foreach($params as $key => $val) { 212 $ret .= '<input type="hidden" name="'.$key.'" '; 213 $ret .= 'value="'.hsc($val).'" />'; 214 } 215 } 216 217 if ($tooltip!='') { 218 $tip = hsc($tooltip); 219 }else{ 220 $tip = hsc($label); 221 } 222 223 $ret .= '<button type="submit" '; 224 if($akey){ 225 $tip .= ' ['.strtoupper($akey).']'; 226 $ret .= 'accesskey="'.$akey.'" '; 227 } 228 $ret .= 'title="'.$tip.'">'; 229 $ret .= hsc($label); 230 $ret .= '</button>'; 231 $ret .= '</div></form>'; 232 233 return $ret; 234} 235/** 236 * show a revision warning 237 * 238 * @author Szymon Olewniczak <dokuwiki@imz.re> 239 */ 240function html_showrev() { 241 print p_locale_xhtml('showrev'); 242} 243 244/** 245 * Show a wiki page 246 * 247 * @author Andreas Gohr <andi@splitbrain.org> 248 * 249 * @param null|string $txt wiki text or null for showing $ID 250 */ 251function html_show($txt=null){ 252 global $ID; 253 global $REV; 254 global $HIGH; 255 global $INFO; 256 global $DATE_AT; 257 //disable section editing for old revisions or in preview 258 if($txt || $REV){ 259 $secedit = false; 260 }else{ 261 $secedit = true; 262 } 263 264 if (!is_null($txt)){ 265 //PreviewHeader 266 echo '<br id="scroll__here" />'; 267 echo p_locale_xhtml('preview'); 268 echo '<div class="preview"><div class="pad">'; 269 $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit); 270 if($INFO['prependTOC']) $html = tpl_toc(true).$html; 271 echo $html; 272 echo '<div class="clearer"></div>'; 273 echo '</div></div>'; 274 275 }else{ 276 if ($REV||$DATE_AT){ 277 $data = array('rev' => &$REV, 'date_at' => &$DATE_AT); 278 trigger_event('HTML_SHOWREV_OUTPUT', $data, 'html_showrev'); 279 } 280 $html = p_wiki_xhtml($ID,$REV,true,$DATE_AT); 281 $html = html_secedit($html,$secedit); 282 if($INFO['prependTOC']) $html = tpl_toc(true).$html; 283 $html = html_hilight($html,$HIGH); 284 echo $html; 285 } 286} 287 288/** 289 * ask the user about how to handle an exisiting draft 290 * 291 * @author Andreas Gohr <andi@splitbrain.org> 292 */ 293function html_draft(){ 294 global $INFO; 295 global $ID; 296 global $lang; 297 $draft = unserialize(io_readFile($INFO['draft'],false)); 298 $text = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true)); 299 300 print p_locale_xhtml('draft'); 301 $form = new Doku_Form(array('id' => 'dw__editform')); 302 $form->addHidden('id', $ID); 303 $form->addHidden('date', $draft['date']); 304 $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly'))); 305 $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status'))); 306 $form->addElement($lang['draftdate'].' '. dformat(filemtime($INFO['draft']))); 307 $form->addElement(form_makeCloseTag('div')); 308 $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1'))); 309 $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2'))); 310 $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3'))); 311 html_form('draft', $form); 312} 313 314/** 315 * Highlights searchqueries in HTML code 316 * 317 * @author Andreas Gohr <andi@splitbrain.org> 318 * @author Harry Fuecks <hfuecks@gmail.com> 319 * 320 * @param string $html 321 * @param array|string $phrases 322 * @return string html 323 */ 324function html_hilight($html,$phrases){ 325 $phrases = (array) $phrases; 326 $phrases = array_map('preg_quote_cb', $phrases); 327 $phrases = array_map('ft_snippet_re_preprocess', $phrases); 328 $phrases = array_filter($phrases); 329 $regex = join('|',$phrases); 330 331 if ($regex === '') return $html; 332 if (!utf8_check($regex)) return $html; 333 $html = @preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html); 334 return $html; 335} 336 337/** 338 * Callback used by html_hilight() 339 * 340 * @author Harry Fuecks <hfuecks@gmail.com> 341 * 342 * @param array $m matches 343 * @return string html 344 */ 345function html_hilight_callback($m) { 346 $hlight = unslash($m[0]); 347 if ( !isset($m[2])) { 348 $hlight = '<span class="search_hit">'.$hlight.'</span>'; 349 } 350 return $hlight; 351} 352 353/** 354 * Run a search and display the result 355 * 356 * @author Andreas Gohr <andi@splitbrain.org> 357 */ 358function html_search(){ 359 global $QUERY, $ID; 360 global $lang; 361 362 $intro = p_locale_xhtml('searchpage'); 363 // allow use of placeholder in search intro 364 $pagecreateinfo = (auth_quickaclcheck($ID) >= AUTH_CREATE) ? $lang['searchcreatepage'] : ''; 365 $intro = str_replace( 366 array('@QUERY@', '@SEARCH@', '@CREATEPAGEINFO@'), 367 array(hsc(rawurlencode($QUERY)), hsc($QUERY), $pagecreateinfo), 368 $intro 369 ); 370 echo $intro; 371 372 //do quick pagesearch 373 $data = ft_pageLookup($QUERY,true,useHeading('navigation')); 374 if(count($data)){ 375 print '<div class="search_quickresult">'; 376 print '<h3>'.$lang['quickhits'].':</h3>'; 377 print '<ul class="search_quickhits">'; 378 foreach($data as $id => $title){ 379 print '<li> '; 380 if (useHeading('navigation')) { 381 $name = $title; 382 }else{ 383 $ns = getNS($id); 384 if($ns){ 385 $name = shorten(noNS($id), ' ('.$ns.')',30); 386 }else{ 387 $name = $id; 388 } 389 } 390 print html_wikilink(':'.$id,$name); 391 print '</li> '; 392 } 393 print '</ul> '; 394 //clear float (see http://www.complexspiral.com/publications/containing-floats/) 395 print '<div class="clearer"></div>'; 396 print '</div>'; 397 } 398 399 //do fulltext search 400 $regex = array(); 401 $data = ft_pageSearch($QUERY,$regex); 402 if(count($data)){ 403 print '<dl class="search_results">'; 404 $num = 1; 405 foreach($data as $id => $cnt){ 406 print '<dt>'; 407 print html_wikilink(':'.$id,useHeading('navigation')?null:$id,$regex); 408 if($cnt !== 0){ 409 print ': '.$cnt.' '.$lang['hits'].''; 410 } 411 print '</dt>'; 412 if($cnt !== 0){ 413 if($num < FT_SNIPPET_NUMBER){ // create snippets for the first number of matches only 414 print '<dd>'.ft_snippet($id,$regex).'</dd>'; 415 } 416 $num++; 417 } 418 } 419 print '</dl>'; 420 }else{ 421 print '<div class="nothing">'.$lang['nothingfound'].'</div>'; 422 } 423} 424 425/** 426 * Display error on locked pages 427 * 428 * @author Andreas Gohr <andi@splitbrain.org> 429 */ 430function html_locked(){ 431 global $ID; 432 global $conf; 433 global $lang; 434 global $INFO; 435 436 $locktime = filemtime(wikiLockFN($ID)); 437 $expire = dformat($locktime + $conf['locktime']); 438 $min = round(($conf['locktime'] - (time() - $locktime) )/60); 439 440 print p_locale_xhtml('locked'); 441 print '<ul>'; 442 print '<li><div class="li"><strong>'.$lang['lockedby'].'</strong> '.editorinfo($INFO['locked']).'</div></li>'; 443 print '<li><div class="li"><strong>'.$lang['lockexpire'].'</strong> '.$expire.' ('.$min.' min)</div></li>'; 444 print '</ul>'; 445} 446 447/** 448 * list old revisions 449 * 450 * @author Andreas Gohr <andi@splitbrain.org> 451 * @author Ben Coburn <btcoburn@silicodon.net> 452 * @author Kate Arzamastseva <pshns@ukr.net> 453 * 454 * @param int $first skip the first n changelog lines 455 * @param bool|string $media_id id of media, or false for current page 456 */ 457function html_revisions($first=0, $media_id = false){ 458 global $ID; 459 global $INFO; 460 global $conf; 461 global $lang; 462 $id = $ID; 463 if ($media_id) { 464 $id = $media_id; 465 $changelog = new MediaChangeLog($id); 466 } else { 467 $changelog = new PageChangeLog($id); 468 } 469 470 /* we need to get one additional log entry to be able to 471 * decide if this is the last page or is there another one. 472 * see html_recent() 473 */ 474 475 $revisions = $changelog->getRevisions($first, $conf['recent']+1); 476 477 if(count($revisions)==0 && $first!=0){ 478 $first=0; 479 $revisions = $changelog->getRevisions($first, $conf['recent']+1); 480 } 481 $hasNext = false; 482 if (count($revisions)>$conf['recent']) { 483 $hasNext = true; 484 array_pop($revisions); // remove extra log entry 485 } 486 487 if (!$media_id) print p_locale_xhtml('revisions'); 488 489 $params = array('id' => 'page__revisions', 'class' => 'changes'); 490 if($media_id) { 491 $params['action'] = media_managerURL(array('image' => $media_id), '&'); 492 } 493 494 if(!$media_id) { 495 $exists = $INFO['exists']; 496 $display_name = useHeading('navigation') ? hsc(p_get_first_heading($id)) : $id; 497 if(!$display_name) { 498 $display_name = $id; 499 } 500 } else { 501 $exists = file_exists(mediaFN($id)); 502 $display_name = $id; 503 } 504 505 $form = new Doku_Form($params); 506 $form->addElement(form_makeOpenTag('ul')); 507 508 if($exists && $first == 0) { 509 $minor = false; 510 if($media_id) { 511 $date = dformat(@filemtime(mediaFN($id))); 512 $href = media_managerURL(array('image' => $id, 'tab_details' => 'view'), '&'); 513 514 $changelog->setChunkSize(1024); 515 $revinfo = $changelog->getRevisionInfo(@filemtime(fullpath(mediaFN($id)))); 516 517 $summary = $revinfo['sum']; 518 if($revinfo['user']) { 519 $editor = $revinfo['user']; 520 } else { 521 $editor = $revinfo['ip']; 522 } 523 $sizechange = $revinfo['sizechange']; 524 } else { 525 $date = dformat($INFO['lastmod']); 526 if(isset($INFO['meta']) && isset($INFO['meta']['last_change'])) { 527 if($INFO['meta']['last_change']['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) { 528 $minor = true; 529 } 530 if(isset($INFO['meta']['last_change']['sizechange'])) { 531 $sizechange = $INFO['meta']['last_change']['sizechange']; 532 } else { 533 $sizechange = null; 534 } 535 } 536 $pagelog = new PageChangeLog($ID); 537 $latestrev = $pagelog->getRevisions(-1, 1); 538 $latestrev = array_pop($latestrev); 539 $href = wl($id,"rev=$latestrev",false,'&'); 540 $summary = $INFO['sum']; 541 $editor = $INFO['editor']; 542 } 543 544 $form->addElement(form_makeOpenTag('li', array('class' => ($minor ? 'minor' : '')))); 545 $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); 546 $form->addElement(form_makeTag('input', array( 547 'type' => 'checkbox', 548 'name' => 'rev2[]', 549 'value' => 'current'))); 550 551 $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); 552 $form->addElement($date); 553 $form->addElement(form_makeCloseTag('span')); 554 555 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />'); 556 557 $form->addElement(form_makeOpenTag('a', array( 558 'class' => 'wikilink1', 559 'href' => $href))); 560 $form->addElement($display_name); 561 $form->addElement(form_makeCloseTag('a')); 562 563 if ($media_id) $form->addElement(form_makeOpenTag('div')); 564 565 if($summary) { 566 $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); 567 if(!$media_id) $form->addElement(' – '); 568 $form->addElement('<bdi>' . hsc($summary) . '</bdi>'); 569 $form->addElement(form_makeCloseTag('span')); 570 } 571 572 $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); 573 $form->addElement((empty($editor))?('('.$lang['external_edit'].')'):'<bdi>'.editorinfo($editor).'</bdi>'); 574 $form->addElement(form_makeCloseTag('span')); 575 576 html_sizechange($sizechange, $form); 577 578 $form->addElement('('.$lang['current'].')'); 579 580 if ($media_id) $form->addElement(form_makeCloseTag('div')); 581 582 $form->addElement(form_makeCloseTag('div')); 583 $form->addElement(form_makeCloseTag('li')); 584 } 585 586 foreach($revisions as $rev) { 587 $date = dformat($rev); 588 $info = $changelog->getRevisionInfo($rev); 589 if($media_id) { 590 $exists = file_exists(mediaFN($id, $rev)); 591 } else { 592 $exists = page_exists($id, $rev); 593 } 594 595 $class = ''; 596 if($info['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) { 597 $class = 'minor'; 598 } 599 $form->addElement(form_makeOpenTag('li', array('class' => $class))); 600 $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); 601 if($exists){ 602 $form->addElement(form_makeTag('input', array( 603 'type' => 'checkbox', 604 'name' => 'rev2[]', 605 'value' => $rev))); 606 }else{ 607 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />'); 608 } 609 610 $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); 611 $form->addElement($date); 612 $form->addElement(form_makeCloseTag('span')); 613 614 if($exists){ 615 if (!$media_id) { 616 $href = wl($id,"rev=$rev,do=diff", false, '&'); 617 } else { 618 $href = media_managerURL(array('image' => $id, 'rev' => $rev, 'mediado' => 'diff'), '&'); 619 } 620 $form->addElement(form_makeOpenTag('a', array( 621 'class' => 'diff_link', 622 'href' => $href))); 623 $form->addElement(form_makeTag('img', array( 624 'src' => DOKU_BASE.'lib/images/diff.png', 625 'width' => 15, 626 'height' => 11, 627 'title' => $lang['diff'], 628 'alt' => $lang['diff']))); 629 $form->addElement(form_makeCloseTag('a')); 630 631 if (!$media_id) { 632 $href = wl($id,"rev=$rev",false,'&'); 633 } else { 634 $href = media_managerURL(array('image' => $id, 'tab_details' => 'view', 'rev' => $rev), '&'); 635 } 636 $form->addElement(form_makeOpenTag('a', array( 637 'class' => 'wikilink1', 638 'href' => $href))); 639 $form->addElement($display_name); 640 $form->addElement(form_makeCloseTag('a')); 641 }else{ 642 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />'); 643 $form->addElement($display_name); 644 } 645 646 if ($media_id) $form->addElement(form_makeOpenTag('div')); 647 648 if ($info['sum']) { 649 $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); 650 if(!$media_id) $form->addElement(' – '); 651 $form->addElement('<bdi>'.hsc($info['sum']).'</bdi>'); 652 $form->addElement(form_makeCloseTag('span')); 653 } 654 655 $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); 656 if($info['user']){ 657 $form->addElement('<bdi>'.editorinfo($info['user']).'</bdi>'); 658 if(auth_ismanager()){ 659 $form->addElement(' <bdo dir="ltr">('.$info['ip'].')</bdo>'); 660 } 661 }else{ 662 $form->addElement('<bdo dir="ltr">'.$info['ip'].'</bdo>'); 663 } 664 $form->addElement(form_makeCloseTag('span')); 665 666 html_sizechange($info['sizechange'], $form); 667 668 if ($media_id) $form->addElement(form_makeCloseTag('div')); 669 670 $form->addElement(form_makeCloseTag('div')); 671 $form->addElement(form_makeCloseTag('li')); 672 } 673 $form->addElement(form_makeCloseTag('ul')); 674 if (!$media_id) { 675 $form->addElement(form_makeButton('submit', 'diff', $lang['diff2'])); 676 } else { 677 $form->addHidden('mediado', 'diff'); 678 $form->addElement(form_makeButton('submit', '', $lang['diff2'])); 679 } 680 html_form('revisions', $form); 681 682 print '<div class="pagenav">'; 683 $last = $first + $conf['recent']; 684 if ($first > 0) { 685 $first -= $conf['recent']; 686 if ($first < 0) $first = 0; 687 print '<div class="pagenav-prev">'; 688 if ($media_id) { 689 print html_btn('newer',$media_id,"p",media_managerURL(array('first' => $first), '&', false, true)); 690 } else { 691 print html_btn('newer',$id,"p",array('do' => 'revisions', 'first' => $first)); 692 } 693 print '</div>'; 694 } 695 if ($hasNext) { 696 print '<div class="pagenav-next">'; 697 if ($media_id) { 698 print html_btn('older',$media_id,"n",media_managerURL(array('first' => $last), '&', false, true)); 699 } else { 700 print html_btn('older',$id,"n",array('do' => 'revisions', 'first' => $last)); 701 } 702 print '</div>'; 703 } 704 print '</div>'; 705 706} 707 708/** 709 * display recent changes 710 * 711 * @author Andreas Gohr <andi@splitbrain.org> 712 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 713 * @author Ben Coburn <btcoburn@silicodon.net> 714 * @author Kate Arzamastseva <pshns@ukr.net> 715 * 716 * @param int $first 717 * @param string $show_changes 718 */ 719function html_recent($first = 0, $show_changes = 'both') { 720 global $conf; 721 global $lang; 722 global $ID; 723 /* we need to get one additionally log entry to be able to 724 * decide if this is the last page or is there another one. 725 * This is the cheapest solution to get this information. 726 */ 727 $flags = 0; 728 if($show_changes == 'mediafiles' && $conf['mediarevisions']) { 729 $flags = RECENTS_MEDIA_CHANGES; 730 } elseif($show_changes == 'pages') { 731 $flags = 0; 732 } elseif($conf['mediarevisions']) { 733 $show_changes = 'both'; 734 $flags = RECENTS_MEDIA_PAGES_MIXED; 735 } 736 737 $recents = getRecents($first, $conf['recent'] + 1, getNS($ID), $flags); 738 if(count($recents) == 0 && $first != 0) { 739 $first = 0; 740 $recents = getRecents($first, $conf['recent'] + 1, getNS($ID), $flags); 741 } 742 $hasNext = false; 743 if(count($recents) > $conf['recent']) { 744 $hasNext = true; 745 array_pop($recents); // remove extra log entry 746 } 747 748 print p_locale_xhtml('recent'); 749 750 if(getNS($ID) != '') { 751 print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>'; 752 } 753 754 $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET', 'class' => 'changes')); 755 $form->addHidden('sectok', null); 756 $form->addHidden('do', 'recent'); 757 $form->addHidden('id', $ID); 758 759 if($conf['mediarevisions']) { 760 $form->addElement('<div class="changeType">'); 761 $form->addElement(form_makeListboxField( 762 'show_changes', 763 array( 764 'pages' => $lang['pages_changes'], 765 'mediafiles' => $lang['media_changes'], 766 'both' => $lang['both_changes'] 767 ), 768 $show_changes, 769 $lang['changes_type'], 770 '', '', 771 array('class' => 'quickselect'))); 772 773 $form->addElement(form_makeButton('submit', 'recent', $lang['btn_apply'])); 774 $form->addElement('</div>'); 775 } 776 777 $form->addElement(form_makeOpenTag('ul')); 778 779 foreach($recents as $recent) { 780 $date = dformat($recent['date']); 781 782 $class = ''; 783 if($recent['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) { 784 $class = 'minor'; 785 } 786 $form->addElement(form_makeOpenTag('li', array('class' => $class))); 787 $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); 788 789 if(!empty($recent['media'])) { 790 $form->addElement(media_printicon($recent['id'])); 791 } else { 792 $icon = DOKU_BASE . 'lib/images/fileicons/file.png'; 793 $form->addElement('<img src="' . $icon . '" alt="' . $recent['id'] . '" class="icon" />'); 794 } 795 796 $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); 797 $form->addElement($date); 798 $form->addElement(form_makeCloseTag('span')); 799 800 $diff = false; 801 $href = ''; 802 803 if(!empty($recent['media'])) { 804 $changelog = new MediaChangeLog($recent['id']); 805 $revs = $changelog->getRevisions(0, 1); 806 $diff = (count($revs) && file_exists(mediaFN($recent['id']))); 807 if($diff) { 808 $href = media_managerURL(array( 809 'tab_details' => 'history', 810 'mediado' => 'diff', 811 'image' => $recent['id'], 812 'ns' => getNS($recent['id']) 813 ), '&'); 814 } 815 } else { 816 $href = wl($recent['id'], "do=diff", false, '&'); 817 } 818 819 if(!empty($recent['media']) && !$diff) { 820 $form->addElement('<img src="' . DOKU_BASE . 'lib/images/blank.gif" width="15" height="11" alt="" />'); 821 } else { 822 $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => $href))); 823 $form->addElement(form_makeTag('img', array( 824 'src' => DOKU_BASE . 'lib/images/diff.png', 825 'width' => 15, 826 'height' => 11, 827 'title' => $lang['diff'], 828 'alt' => $lang['diff'] 829 ))); 830 $form->addElement(form_makeCloseTag('a')); 831 } 832 833 if(!empty($recent['media'])) { 834 $href = media_managerURL(array('tab_details' => 'history', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&'); 835 } else { 836 $href = wl($recent['id'], "do=revisions", false, '&'); 837 } 838 $form->addElement(form_makeOpenTag('a', array( 839 'class' => 'revisions_link', 840 'href' => $href))); 841 $form->addElement(form_makeTag('img', array( 842 'src' => DOKU_BASE . 'lib/images/history.png', 843 'width' => 12, 844 'height' => 14, 845 'title' => $lang['btn_revs'], 846 'alt' => $lang['btn_revs'] 847 ))); 848 $form->addElement(form_makeCloseTag('a')); 849 850 if(!empty($recent['media'])) { 851 $href = media_managerURL(array('tab_details' => 'view', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&'); 852 $class = file_exists(mediaFN($recent['id'])) ? 'wikilink1' : 'wikilink2'; 853 $form->addElement(form_makeOpenTag('a', array( 854 'class' => $class, 855 'href' => $href))); 856 $form->addElement($recent['id']); 857 $form->addElement(form_makeCloseTag('a')); 858 } else { 859 $form->addElement(html_wikilink(':' . $recent['id'], useHeading('navigation') ? null : $recent['id'])); 860 } 861 $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); 862 $form->addElement(' – ' . hsc($recent['sum'])); 863 $form->addElement(form_makeCloseTag('span')); 864 865 $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); 866 if($recent['user']) { 867 $form->addElement('<bdi>' . editorinfo($recent['user']) . '</bdi>'); 868 if(auth_ismanager()) { 869 $form->addElement(' <bdo dir="ltr">(' . $recent['ip'] . ')</bdo>'); 870 } 871 } else { 872 $form->addElement('<bdo dir="ltr">' . $recent['ip'] . '</bdo>'); 873 } 874 $form->addElement(form_makeCloseTag('span')); 875 876 html_sizechange($recent['sizechange'], $form); 877 878 $form->addElement(form_makeCloseTag('div')); 879 $form->addElement(form_makeCloseTag('li')); 880 } 881 $form->addElement(form_makeCloseTag('ul')); 882 883 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav'))); 884 $last = $first + $conf['recent']; 885 if($first > 0) { 886 $first -= $conf['recent']; 887 if($first < 0) $first = 0; 888 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev'))); 889 $form->addElement(form_makeOpenTag('button', array( 890 'type' => 'submit', 891 'name' => 'first[' . $first . ']', 892 'accesskey' => 'n', 893 'title' => $lang['btn_newer'] . ' [N]', 894 'class' => 'button show' 895 ))); 896 $form->addElement($lang['btn_newer']); 897 $form->addElement(form_makeCloseTag('button')); 898 $form->addElement(form_makeCloseTag('div')); 899 } 900 if($hasNext) { 901 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next'))); 902 $form->addElement(form_makeOpenTag('button', array( 903 'type' => 'submit', 904 'name' => 'first[' . $last . ']', 905 'accesskey' => 'p', 906 'title' => $lang['btn_older'] . ' [P]', 907 'class' => 'button show' 908 ))); 909 $form->addElement($lang['btn_older']); 910 $form->addElement(form_makeCloseTag('button')); 911 $form->addElement(form_makeCloseTag('div')); 912 } 913 $form->addElement(form_makeCloseTag('div')); 914 html_form('recent', $form); 915} 916 917/** 918 * Display page index 919 * 920 * @author Andreas Gohr <andi@splitbrain.org> 921 * 922 * @param string $ns 923 */ 924function html_index($ns){ 925 global $conf; 926 global $ID; 927 $ns = cleanID($ns); 928 if(empty($ns)){ 929 $ns = getNS($ID); 930 if($ns === false) $ns =''; 931 } 932 $ns = utf8_encodeFN(str_replace(':','/',$ns)); 933 934 echo p_locale_xhtml('index'); 935 echo '<div id="index__tree">'; 936 937 $data = array(); 938 search($data,$conf['datadir'],'search_index',array('ns' => $ns)); 939 echo html_buildlist($data,'idx','html_list_index','html_li_index'); 940 941 echo '</div>'; 942} 943 944/** 945 * Index item formatter 946 * 947 * User function for html_buildlist() 948 * 949 * @author Andreas Gohr <andi@splitbrain.org> 950 * 951 * @param array $item 952 * @return string 953 */ 954function html_list_index($item){ 955 global $ID, $conf; 956 957 // prevent searchbots needlessly following links 958 $nofollow = ($ID != $conf['start'] || $conf['sitemap']) ? ' rel="nofollow"' : ''; 959 960 $ret = ''; 961 $base = ':'.$item['id']; 962 $base = substr($base,strrpos($base,':')+1); 963 if($item['type']=='d'){ 964 // FS#2766, no need for search bots to follow namespace links in the index 965 $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" title="' . $item['id'] . '" class="idx_dir"' . $nofollow . '><strong>'; 966 $ret .= $base; 967 $ret .= '</strong></a>'; 968 }else{ 969 // default is noNSorNS($id), but we want noNS($id) when useheading is off FS#2605 970 $ret .= html_wikilink(':'.$item['id'], useHeading('navigation') ? null : noNS($item['id'])); 971 } 972 return $ret; 973} 974 975/** 976 * Index List item 977 * 978 * This user function is used in html_buildlist to build the 979 * <li> tags for namespaces when displaying the page index 980 * it gives different classes to opened or closed "folders" 981 * 982 * @author Andreas Gohr <andi@splitbrain.org> 983 * 984 * @param array $item 985 * @return string html 986 */ 987function html_li_index($item){ 988 global $INFO; 989 global $ACT; 990 991 $class = ''; 992 $id = ''; 993 994 if($item['type'] == "f"){ 995 // scroll to the current item 996 if($item['id'] == $INFO['id'] && $ACT == 'index') { 997 $id = ' id="scroll__here"'; 998 $class = ' bounce'; 999 } 1000 return '<li class="level'.$item['level'].$class.'" '.$id.'>'; 1001 }elseif($item['open']){ 1002 return '<li class="open">'; 1003 }else{ 1004 return '<li class="closed">'; 1005 } 1006} 1007 1008/** 1009 * Default List item 1010 * 1011 * @author Andreas Gohr <andi@splitbrain.org> 1012 * 1013 * @param array $item 1014 * @return string html 1015 */ 1016function html_li_default($item){ 1017 return '<li class="level'.$item['level'].'">'; 1018} 1019 1020/** 1021 * Build an unordered list 1022 * 1023 * Build an unordered list from the given $data array 1024 * Each item in the array has to have a 'level' property 1025 * the item itself gets printed by the given $func user 1026 * function. The second and optional function is used to 1027 * print the <li> tag. Both user function need to accept 1028 * a single item. 1029 * 1030 * Both user functions can be given as array to point to 1031 * a member of an object. 1032 * 1033 * @author Andreas Gohr <andi@splitbrain.org> 1034 * 1035 * @param array $data array with item arrays 1036 * @param string $class class of ul wrapper 1037 * @param callable $func callback to print an list item 1038 * @param callable $lifunc callback to the opening li tag 1039 * @param bool $forcewrapper Trigger building a wrapper ul if the first level is 1040 * 0 (we have a root object) or 1 (just the root content) 1041 * @return string html of an unordered list 1042 */ 1043function html_buildlist($data,$class,$func,$lifunc='html_li_default',$forcewrapper=false){ 1044 if (count($data) === 0) { 1045 return ''; 1046 } 1047 1048 $start_level = $data[0]['level']; 1049 $level = $start_level; 1050 $ret = ''; 1051 $open = 0; 1052 1053 foreach ($data as $item){ 1054 1055 if( $item['level'] > $level ){ 1056 //open new list 1057 for($i=0; $i<($item['level'] - $level); $i++){ 1058 if ($i) $ret .= "<li class=\"clear\">"; 1059 $ret .= "\n<ul class=\"$class\">\n"; 1060 $open++; 1061 } 1062 $level = $item['level']; 1063 1064 }elseif( $item['level'] < $level ){ 1065 //close last item 1066 $ret .= "</li>\n"; 1067 while( $level > $item['level'] && $open > 0 ){ 1068 //close higher lists 1069 $ret .= "</ul>\n</li>\n"; 1070 $level--; 1071 $open--; 1072 } 1073 } elseif ($ret !== '') { 1074 //close previous item 1075 $ret .= "</li>\n"; 1076 } 1077 1078 //print item 1079 $ret .= call_user_func($lifunc,$item); 1080 $ret .= '<div class="li">'; 1081 1082 $ret .= call_user_func($func,$item); 1083 $ret .= '</div>'; 1084 } 1085 1086 //close remaining items and lists 1087 $ret .= "</li>\n"; 1088 while($open-- > 0) { 1089 $ret .= "</ul></li>\n"; 1090 } 1091 1092 if ($forcewrapper || $start_level < 2) { 1093 // Trigger building a wrapper ul if the first level is 1094 // 0 (we have a root object) or 1 (just the root content) 1095 $ret = "\n<ul class=\"$class\">\n".$ret."</ul>\n"; 1096 } 1097 1098 return $ret; 1099} 1100 1101/** 1102 * display backlinks 1103 * 1104 * @author Andreas Gohr <andi@splitbrain.org> 1105 * @author Michael Klier <chi@chimeric.de> 1106 */ 1107function html_backlinks(){ 1108 global $ID; 1109 global $lang; 1110 1111 print p_locale_xhtml('backlinks'); 1112 1113 $data = ft_backlinks($ID); 1114 1115 if(!empty($data)) { 1116 print '<ul class="idx">'; 1117 foreach($data as $blink){ 1118 print '<li><div class="li">'; 1119 print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink); 1120 print '</div></li>'; 1121 } 1122 print '</ul>'; 1123 } else { 1124 print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>'; 1125 } 1126} 1127 1128/** 1129 * Get header of diff HTML 1130 * 1131 * @param string $l_rev Left revisions 1132 * @param string $r_rev Right revision 1133 * @param string $id Page id, if null $ID is used 1134 * @param bool $media If it is for media files 1135 * @param bool $inline Return the header on a single line 1136 * @return string[] HTML snippets for diff header 1137 */ 1138function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = false) { 1139 global $lang; 1140 if ($id === null) { 1141 global $ID; 1142 $id = $ID; 1143 } 1144 $head_separator = $inline ? ' ' : '<br />'; 1145 $media_or_wikiFN = $media ? 'mediaFN' : 'wikiFN'; 1146 $ml_or_wl = $media ? 'ml' : 'wl'; 1147 $l_minor = $r_minor = ''; 1148 1149 if($media) { 1150 $changelog = new MediaChangeLog($id); 1151 } else { 1152 $changelog = new PageChangeLog($id); 1153 } 1154 if(!$l_rev){ 1155 $l_head = '—'; 1156 }else{ 1157 $l_info = $changelog->getRevisionInfo($l_rev); 1158 if($l_info['user']){ 1159 $l_user = '<bdi>'.editorinfo($l_info['user']).'</bdi>'; 1160 if(auth_ismanager()) $l_user .= ' <bdo dir="ltr">('.$l_info['ip'].')</bdo>'; 1161 } else { 1162 $l_user = '<bdo dir="ltr">'.$l_info['ip'].'</bdo>'; 1163 } 1164 $l_user = '<span class="user">'.$l_user.'</span>'; 1165 $l_sum = ($l_info['sum']) ? '<span class="sum"><bdi>'.hsc($l_info['sum']).'</bdi></span>' : ''; 1166 if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"'; 1167 1168 $l_head_title = ($media) ? dformat($l_rev) : $id.' ['.dformat($l_rev).']'; 1169 $l_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$l_rev").'">'. 1170 $l_head_title.'</a></bdi>'. 1171 $head_separator.$l_user.' '.$l_sum; 1172 } 1173 1174 if($r_rev){ 1175 $r_info = $changelog->getRevisionInfo($r_rev); 1176 if($r_info['user']){ 1177 $r_user = '<bdi>'.editorinfo($r_info['user']).'</bdi>'; 1178 if(auth_ismanager()) $r_user .= ' <bdo dir="ltr">('.$r_info['ip'].')</bdo>'; 1179 } else { 1180 $r_user = '<bdo dir="ltr">'.$r_info['ip'].'</bdo>'; 1181 } 1182 $r_user = '<span class="user">'.$r_user.'</span>'; 1183 $r_sum = ($r_info['sum']) ? '<span class="sum"><bdi>'.hsc($r_info['sum']).'</bdi></span>' : ''; 1184 if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"'; 1185 1186 $r_head_title = ($media) ? dformat($r_rev) : $id.' ['.dformat($r_rev).']'; 1187 $r_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$r_rev").'">'. 1188 $r_head_title.'</a></bdi>'. 1189 $head_separator.$r_user.' '.$r_sum; 1190 }elseif($_rev = @filemtime($media_or_wikiFN($id))){ 1191 $_info = $changelog->getRevisionInfo($_rev); 1192 if($_info['user']){ 1193 $_user = '<bdi>'.editorinfo($_info['user']).'</bdi>'; 1194 if(auth_ismanager()) $_user .= ' <bdo dir="ltr">('.$_info['ip'].')</bdo>'; 1195 } else { 1196 $_user = '<bdo dir="ltr">'.$_info['ip'].'</bdo>'; 1197 } 1198 $_user = '<span class="user">'.$_user.'</span>'; 1199 $_sum = ($_info['sum']) ? '<span class="sum"><bdi>'.hsc($_info['sum']).'</span></bdi>' : ''; 1200 if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"'; 1201 1202 $r_head_title = ($media) ? dformat($_rev) : $id.' ['.dformat($_rev).']'; 1203 $r_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id).'">'. 1204 $r_head_title.'</a></bdi> '. 1205 '('.$lang['current'].')'. 1206 $head_separator.$_user.' '.$_sum; 1207 }else{ 1208 $r_head = '— ('.$lang['current'].')'; 1209 } 1210 1211 return array($l_head, $r_head, $l_minor, $r_minor); 1212} 1213 1214/** 1215 * Show diff 1216 * between current page version and provided $text 1217 * or between the revisions provided via GET or POST 1218 * 1219 * @author Andreas Gohr <andi@splitbrain.org> 1220 * @param string $text when non-empty: compare with this text with most current version 1221 * @param bool $intro display the intro text 1222 * @param string $type type of the diff (inline or sidebyside) 1223 */ 1224function html_diff($text = '', $intro = true, $type = null) { 1225 global $ID; 1226 global $REV; 1227 global $lang; 1228 global $INPUT; 1229 global $INFO; 1230 $pagelog = new PageChangeLog($ID); 1231 1232 /* 1233 * Determine diff type 1234 */ 1235 if(!$type) { 1236 $type = $INPUT->str('difftype'); 1237 if(empty($type)) { 1238 $type = get_doku_pref('difftype', $type); 1239 if(empty($type) && $INFO['ismobile']) { 1240 $type = 'inline'; 1241 } 1242 } 1243 } 1244 if($type != 'inline') $type = 'sidebyside'; 1245 1246 /* 1247 * Determine requested revision(s) 1248 */ 1249 // we're trying to be clever here, revisions to compare can be either 1250 // given as rev and rev2 parameters, with rev2 being optional. Or in an 1251 // array in rev2. 1252 $rev1 = $REV; 1253 1254 $rev2 = $INPUT->ref('rev2'); 1255 if(is_array($rev2)) { 1256 $rev1 = (int) $rev2[0]; 1257 $rev2 = (int) $rev2[1]; 1258 1259 if(!$rev1) { 1260 $rev1 = $rev2; 1261 unset($rev2); 1262 } 1263 } else { 1264 $rev2 = $INPUT->int('rev2'); 1265 } 1266 1267 /* 1268 * Determine left and right revision, its texts and the header 1269 */ 1270 $r_minor = ''; 1271 $l_minor = ''; 1272 1273 if($text) { // compare text to the most current revision 1274 $l_rev = ''; 1275 $l_text = rawWiki($ID, ''); 1276 $l_head = '<a class="wikilink1" href="' . wl($ID) . '">' . 1277 $ID . ' ' . dformat((int) @filemtime(wikiFN($ID))) . '</a> ' . 1278 $lang['current']; 1279 1280 $r_rev = ''; 1281 $r_text = cleanText($text); 1282 $r_head = $lang['yours']; 1283 } else { 1284 if($rev1 && isset($rev2) && $rev2) { // two specific revisions wanted 1285 // make sure order is correct (older on the left) 1286 if($rev1 < $rev2) { 1287 $l_rev = $rev1; 1288 $r_rev = $rev2; 1289 } else { 1290 $l_rev = $rev2; 1291 $r_rev = $rev1; 1292 } 1293 } elseif($rev1) { // single revision given, compare to current 1294 $r_rev = ''; 1295 $l_rev = $rev1; 1296 } else { // no revision was given, compare previous to current 1297 $r_rev = ''; 1298 $revs = $pagelog->getRevisions(0, 1); 1299 $l_rev = $revs[0]; 1300 $REV = $l_rev; // store revision back in $REV 1301 } 1302 1303 // when both revisions are empty then the page was created just now 1304 if(!$l_rev && !$r_rev) { 1305 $l_text = ''; 1306 } else { 1307 $l_text = rawWiki($ID, $l_rev); 1308 } 1309 $r_text = rawWiki($ID, $r_rev); 1310 1311 list($l_head, $r_head, $l_minor, $r_minor) = html_diff_head($l_rev, $r_rev, null, false, $type == 'inline'); 1312 } 1313 1314 /* 1315 * Build navigation 1316 */ 1317 $l_nav = ''; 1318 $r_nav = ''; 1319 if(!$text) { 1320 list($l_nav, $r_nav) = html_diff_navigation($pagelog, $type, $l_rev, $r_rev); 1321 } 1322 /* 1323 * Create diff object and the formatter 1324 */ 1325 $diff = new Diff(explode("\n", $l_text), explode("\n", $r_text)); 1326 1327 if($type == 'inline') { 1328 $diffformatter = new InlineDiffFormatter(); 1329 } else { 1330 $diffformatter = new TableDiffFormatter(); 1331 } 1332 /* 1333 * Display intro 1334 */ 1335 if($intro) print p_locale_xhtml('diff'); 1336 1337 /* 1338 * Display type and exact reference 1339 */ 1340 if(!$text) { 1341 ptln('<div class="diffoptions group">'); 1342 1343 1344 $form = new Doku_Form(array('action' => wl())); 1345 $form->addHidden('id', $ID); 1346 $form->addHidden('rev2[0]', $l_rev); 1347 $form->addHidden('rev2[1]', $r_rev); 1348 $form->addHidden('do', 'diff'); 1349 $form->addElement( 1350 form_makeListboxField( 1351 'difftype', 1352 array( 1353 'sidebyside' => $lang['diff_side'], 1354 'inline' => $lang['diff_inline'] 1355 ), 1356 $type, 1357 $lang['diff_type'], 1358 '', '', 1359 array('class' => 'quickselect') 1360 ) 1361 ); 1362 $form->addElement(form_makeButton('submit', 'diff', 'Go')); 1363 $form->printForm(); 1364 1365 ptln('<p>'); 1366 // link to exactly this view FS#2835 1367 echo html_diff_navigationlink($type, 'difflink', $l_rev, $r_rev ? $r_rev : $INFO['currentrev']); 1368 ptln('</p>'); 1369 1370 ptln('</div>'); // .diffoptions 1371 } 1372 1373 /* 1374 * Display diff view table 1375 */ 1376 ?> 1377 <div class="table"> 1378 <table class="diff diff_<?php echo $type ?>"> 1379 1380 <?php 1381 //navigation and header 1382 if($type == 'inline') { 1383 if(!$text) { ?> 1384 <tr> 1385 <td class="diff-lineheader">-</td> 1386 <td class="diffnav"><?php echo $l_nav ?></td> 1387 </tr> 1388 <tr> 1389 <th class="diff-lineheader">-</th> 1390 <th <?php echo $l_minor ?>> 1391 <?php echo $l_head ?> 1392 </th> 1393 </tr> 1394 <?php } ?> 1395 <tr> 1396 <td class="diff-lineheader">+</td> 1397 <td class="diffnav"><?php echo $r_nav ?></td> 1398 </tr> 1399 <tr> 1400 <th class="diff-lineheader">+</th> 1401 <th <?php echo $r_minor ?>> 1402 <?php echo $r_head ?> 1403 </th> 1404 </tr> 1405 <?php } else { 1406 if(!$text) { ?> 1407 <tr> 1408 <td colspan="2" class="diffnav"><?php echo $l_nav ?></td> 1409 <td colspan="2" class="diffnav"><?php echo $r_nav ?></td> 1410 </tr> 1411 <?php } ?> 1412 <tr> 1413 <th colspan="2" <?php echo $l_minor ?>> 1414 <?php echo $l_head ?> 1415 </th> 1416 <th colspan="2" <?php echo $r_minor ?>> 1417 <?php echo $r_head ?> 1418 </th> 1419 </tr> 1420 <?php } 1421 1422 //diff view 1423 echo html_insert_softbreaks($diffformatter->format($diff)); ?> 1424 1425 </table> 1426 </div> 1427<?php 1428} 1429 1430/** 1431 * Create html for revision navigation 1432 * 1433 * @param PageChangeLog $pagelog changelog object of current page 1434 * @param string $type inline vs sidebyside 1435 * @param int $l_rev left revision timestamp 1436 * @param int $r_rev right revision timestamp 1437 * @return string[] html of left and right navigation elements 1438 */ 1439function html_diff_navigation($pagelog, $type, $l_rev, $r_rev) { 1440 global $INFO, $ID; 1441 1442 // last timestamp is not in changelog, retrieve timestamp from metadata 1443 // note: when page is removed, the metadata timestamp is zero 1444 if(!$r_rev) { 1445 if(isset($INFO['meta']['last_change']['date'])) { 1446 $r_rev = $INFO['meta']['last_change']['date']; 1447 } else { 1448 $r_rev = 0; 1449 } 1450 } 1451 1452 //retrieve revisions with additional info 1453 list($l_revs, $r_revs) = $pagelog->getRevisionsAround($l_rev, $r_rev); 1454 $l_revisions = array(); 1455 if(!$l_rev) { 1456 $l_revisions[0] = array(0, "", false); //no left revision given, add dummy 1457 } 1458 foreach($l_revs as $rev) { 1459 $info = $pagelog->getRevisionInfo($rev); 1460 $l_revisions[$rev] = array( 1461 $rev, 1462 dformat($info['date']) . ' ' . editorinfo($info['user'], true) . ' ' . $info['sum'], 1463 $r_rev ? $rev >= $r_rev : false //disable? 1464 ); 1465 } 1466 $r_revisions = array(); 1467 if(!$r_rev) { 1468 $r_revisions[0] = array(0, "", false); //no right revision given, add dummy 1469 } 1470 foreach($r_revs as $rev) { 1471 $info = $pagelog->getRevisionInfo($rev); 1472 $r_revisions[$rev] = array( 1473 $rev, 1474 dformat($info['date']) . ' ' . editorinfo($info['user'], true) . ' ' . $info['sum'], 1475 $rev <= $l_rev //disable? 1476 ); 1477 } 1478 1479 //determine previous/next revisions 1480 $l_index = array_search($l_rev, $l_revs); 1481 $l_prev = $l_revs[$l_index + 1]; 1482 $l_next = $l_revs[$l_index - 1]; 1483 if($r_rev) { 1484 $r_index = array_search($r_rev, $r_revs); 1485 $r_prev = $r_revs[$r_index + 1]; 1486 $r_next = $r_revs[$r_index - 1]; 1487 } else { 1488 //removed page 1489 if($l_next) { 1490 $r_prev = $r_revs[0]; 1491 } else { 1492 $r_prev = null; 1493 } 1494 $r_next = null; 1495 } 1496 1497 /* 1498 * Left side: 1499 */ 1500 $l_nav = ''; 1501 //move back 1502 if($l_prev) { 1503 $l_nav .= html_diff_navigationlink($type, 'diffbothprevrev', $l_prev, $r_prev); 1504 $l_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_prev, $r_rev); 1505 } 1506 //dropdown 1507 $form = new Doku_Form(array('action' => wl())); 1508 $form->addHidden('id', $ID); 1509 $form->addHidden('difftype', $type); 1510 $form->addHidden('rev2[1]', $r_rev); 1511 $form->addHidden('do', 'diff'); 1512 $form->addElement( 1513 form_makeListboxField( 1514 'rev2[0]', 1515 $l_revisions, 1516 $l_rev, 1517 '', '', '', 1518 array('class' => 'quickselect') 1519 ) 1520 ); 1521 $form->addElement(form_makeButton('submit', 'diff', 'Go')); 1522 $l_nav .= $form->getForm(); 1523 //move forward 1524 if($l_next && ($l_next < $r_rev || !$r_rev)) { 1525 $l_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_next, $r_rev); 1526 } 1527 1528 /* 1529 * Right side: 1530 */ 1531 $r_nav = ''; 1532 //move back 1533 if($l_rev < $r_prev) { 1534 $r_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_rev, $r_prev); 1535 } 1536 //dropdown 1537 $form = new Doku_Form(array('action' => wl())); 1538 $form->addHidden('id', $ID); 1539 $form->addHidden('rev2[0]', $l_rev); 1540 $form->addHidden('difftype', $type); 1541 $form->addHidden('do', 'diff'); 1542 $form->addElement( 1543 form_makeListboxField( 1544 'rev2[1]', 1545 $r_revisions, 1546 $r_rev, 1547 '', '', '', 1548 array('class' => 'quickselect') 1549 ) 1550 ); 1551 $form->addElement(form_makeButton('submit', 'diff', 'Go')); 1552 $r_nav .= $form->getForm(); 1553 //move forward 1554 if($r_next) { 1555 if($pagelog->isCurrentRevision($r_next)) { 1556 $r_nav .= html_diff_navigationlink($type, 'difflastrev', $l_rev); //last revision is diff with current page 1557 } else { 1558 $r_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_rev, $r_next); 1559 } 1560 $r_nav .= html_diff_navigationlink($type, 'diffbothnextrev', $l_next, $r_next); 1561 } 1562 return array($l_nav, $r_nav); 1563} 1564 1565/** 1566 * Create html link to a diff defined by two revisions 1567 * 1568 * @param string $difftype display type 1569 * @param string $linktype 1570 * @param int $lrev oldest revision 1571 * @param int $rrev newest revision or null for diff with current revision 1572 * @return string html of link to a diff 1573 */ 1574function html_diff_navigationlink($difftype, $linktype, $lrev, $rrev = null) { 1575 global $ID, $lang; 1576 if(!$rrev) { 1577 $urlparam = array( 1578 'do' => 'diff', 1579 'rev' => $lrev, 1580 'difftype' => $difftype, 1581 ); 1582 } else { 1583 $urlparam = array( 1584 'do' => 'diff', 1585 'rev2[0]' => $lrev, 1586 'rev2[1]' => $rrev, 1587 'difftype' => $difftype, 1588 ); 1589 } 1590 return '<a class="' . $linktype . '" href="' . wl($ID, $urlparam) . '" title="' . $lang[$linktype] . '">' . 1591 '<span>' . $lang[$linktype] . '</span>' . 1592 '</a>' . "\n"; 1593} 1594 1595/** 1596 * Insert soft breaks in diff html 1597 * 1598 * @param string $diffhtml 1599 * @return string 1600 */ 1601function html_insert_softbreaks($diffhtml) { 1602 // search the diff html string for both: 1603 // - html tags, so these can be ignored 1604 // - long strings of characters without breaking characters 1605 return preg_replace_callback('/<[^>]*>|[^<> ]{12,}/','html_softbreak_callback',$diffhtml); 1606} 1607 1608/** 1609 * callback which adds softbreaks 1610 * 1611 * @param array $match array with first the complete match 1612 * @return string the replacement 1613 */ 1614function html_softbreak_callback($match){ 1615 // if match is an html tag, return it intact 1616 if ($match[0]{0} == '<') return $match[0]; 1617 1618 // its a long string without a breaking character, 1619 // make certain characters into breaking characters by inserting a 1620 // breaking character (zero length space, U+200B / #8203) in front them. 1621 $regex = <<< REGEX 1622(?(?= # start a conditional expression with a positive look ahead ... 1623&\#?\\w{1,6};) # ... for html entities - we don't want to split them (ok to catch some invalid combinations) 1624&\#?\\w{1,6}; # yes pattern - a quicker match for the html entity, since we know we have one 1625| 1626[?/,&\#;:] # no pattern - any other group of 'special' characters to insert a breaking character after 1627)+ # end conditional expression 1628REGEX; 1629 1630 return preg_replace('<'.$regex.'>xu','\0​',$match[0]); 1631} 1632 1633/** 1634 * show warning on conflict detection 1635 * 1636 * @author Andreas Gohr <andi@splitbrain.org> 1637 * 1638 * @param string $text 1639 * @param string $summary 1640 */ 1641function html_conflict($text,$summary){ 1642 global $ID; 1643 global $lang; 1644 1645 print p_locale_xhtml('conflict'); 1646 $form = new Doku_Form(array('id' => 'dw__editform')); 1647 $form->addHidden('id', $ID); 1648 $form->addHidden('wikitext', $text); 1649 $form->addHidden('summary', $summary); 1650 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s'))); 1651 $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel'])); 1652 html_form('conflict', $form); 1653 print '<br /><br /><br /><br />'.NL; 1654} 1655 1656/** 1657 * Prints the global message array 1658 * 1659 * @author Andreas Gohr <andi@splitbrain.org> 1660 */ 1661function html_msgarea(){ 1662 global $MSG, $MSG_shown; 1663 /** @var array $MSG */ 1664 // store if the global $MSG has already been shown and thus HTML output has been started 1665 $MSG_shown = true; 1666 1667 if(!isset($MSG)) return; 1668 1669 $shown = array(); 1670 foreach($MSG as $msg){ 1671 $hash = md5($msg['msg']); 1672 if(isset($shown[$hash])) continue; // skip double messages 1673 if(info_msg_allowed($msg)){ 1674 print '<div class="'.$msg['lvl'].'">'; 1675 print $msg['msg']; 1676 print '</div>'; 1677 } 1678 $shown[$hash] = 1; 1679 } 1680 1681 unset($GLOBALS['MSG']); 1682} 1683 1684/** 1685 * Prints the registration form 1686 * 1687 * @author Andreas Gohr <andi@splitbrain.org> 1688 */ 1689function html_register(){ 1690 global $lang; 1691 global $conf; 1692 global $INPUT; 1693 1694 $base_attrs = array('size'=>50,'required'=>'required'); 1695 $email_attrs = $base_attrs + array('type'=>'email','class'=>'edit'); 1696 1697 print p_locale_xhtml('register'); 1698 print '<div class="centeralign">'.NL; 1699 $form = new Doku_Form(array('id' => 'dw__register')); 1700 $form->startFieldset($lang['btn_register']); 1701 $form->addHidden('do', 'register'); 1702 $form->addHidden('save', '1'); 1703 $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block', $base_attrs)); 1704 if (!$conf['autopasswd']) { 1705 $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', $base_attrs)); 1706 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', $base_attrs)); 1707 } 1708 $form->addElement(form_makeTextField('fullname', $INPUT->post->str('fullname'), $lang['fullname'], '', 'block', $base_attrs)); 1709 $form->addElement(form_makeField('email','email', $INPUT->post->str('email'), $lang['email'], '', 'block', $email_attrs)); 1710 $form->addElement(form_makeButton('submit', '', $lang['btn_register'])); 1711 $form->endFieldset(); 1712 html_form('register', $form); 1713 1714 print '</div>'.NL; 1715} 1716 1717/** 1718 * Print the update profile form 1719 * 1720 * @author Christopher Smith <chris@jalakai.co.uk> 1721 * @author Andreas Gohr <andi@splitbrain.org> 1722 */ 1723function html_updateprofile(){ 1724 global $lang; 1725 global $conf; 1726 global $INPUT; 1727 global $INFO; 1728 /** @var DokuWiki_Auth_Plugin $auth */ 1729 global $auth; 1730 1731 print p_locale_xhtml('updateprofile'); 1732 print '<div class="centeralign">'.NL; 1733 1734 $fullname = $INPUT->post->str('fullname', $INFO['userinfo']['name'], true); 1735 $email = $INPUT->post->str('email', $INFO['userinfo']['mail'], true); 1736 $form = new Doku_Form(array('id' => 'dw__register')); 1737 $form->startFieldset($lang['profile']); 1738 $form->addHidden('do', 'profile'); 1739 $form->addHidden('save', '1'); 1740 $form->addElement(form_makeTextField('login', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled'))); 1741 $attr = array('size'=>'50'); 1742 if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled'; 1743 $form->addElement(form_makeTextField('fullname', $fullname, $lang['fullname'], '', 'block', $attr)); 1744 $attr = array('size'=>'50', 'class'=>'edit'); 1745 if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled'; 1746 $form->addElement(form_makeField('email','email', $email, $lang['email'], '', 'block', $attr)); 1747 $form->addElement(form_makeTag('br')); 1748 if ($auth->canDo('modPass')) { 1749 $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50'))); 1750 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50'))); 1751 } 1752 if ($conf['profileconfirm']) { 1753 $form->addElement(form_makeTag('br')); 1754 $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50', 'required' => 'required'))); 1755 } 1756 $form->addElement(form_makeButton('submit', '', $lang['btn_save'])); 1757 $form->addElement(form_makeButton('reset', '', $lang['btn_reset'])); 1758 1759 $form->endFieldset(); 1760 html_form('updateprofile', $form); 1761 1762 if ($auth->canDo('delUser') && actionOK('profile_delete')) { 1763 $form_profiledelete = new Doku_Form(array('id' => 'dw__profiledelete')); 1764 $form_profiledelete->startFieldset($lang['profdeleteuser']); 1765 $form_profiledelete->addHidden('do', 'profile_delete'); 1766 $form_profiledelete->addHidden('delete', '1'); 1767 $form_profiledelete->addElement(form_makeCheckboxField('confirm_delete', '1', $lang['profconfdelete'],'dw__confirmdelete','', array('required' => 'required'))); 1768 if ($conf['profileconfirm']) { 1769 $form_profiledelete->addElement(form_makeTag('br')); 1770 $form_profiledelete->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50', 'required' => 'required'))); 1771 } 1772 $form_profiledelete->addElement(form_makeButton('submit', '', $lang['btn_deleteuser'])); 1773 $form_profiledelete->endFieldset(); 1774 1775 html_form('profiledelete', $form_profiledelete); 1776 } 1777 1778 print '</div>'.NL; 1779} 1780 1781/** 1782 * Preprocess edit form data 1783 * 1784 * @author Andreas Gohr <andi@splitbrain.org> 1785 * 1786 * @triggers HTML_EDITFORM_OUTPUT 1787 */ 1788function html_edit(){ 1789 global $INPUT; 1790 global $ID; 1791 global $REV; 1792 global $DATE; 1793 global $PRE; 1794 global $SUF; 1795 global $INFO; 1796 global $SUM; 1797 global $lang; 1798 global $conf; 1799 global $TEXT; 1800 1801 if ($INPUT->has('changecheck')) { 1802 $check = $INPUT->str('changecheck'); 1803 } elseif(!$INFO['exists']){ 1804 // $TEXT has been loaded from page template 1805 $check = md5(''); 1806 } else { 1807 $check = md5($TEXT); 1808 } 1809 $mod = md5($TEXT) !== $check; 1810 1811 $wr = $INFO['writable'] && !$INFO['locked']; 1812 $include = 'edit'; 1813 if($wr){ 1814 if ($REV) $include = 'editrev'; 1815 }else{ 1816 // check pseudo action 'source' 1817 if(!actionOK('source')){ 1818 msg('Command disabled: source',-1); 1819 return; 1820 } 1821 $include = 'read'; 1822 } 1823 1824 global $license; 1825 1826 $form = new Doku_Form(array('id' => 'dw__editform')); 1827 $form->addHidden('id', $ID); 1828 $form->addHidden('rev', $REV); 1829 $form->addHidden('date', $DATE); 1830 $form->addHidden('prefix', $PRE . '.'); 1831 $form->addHidden('suffix', $SUF); 1832 $form->addHidden('changecheck', $check); 1833 1834 $data = array('form' => $form, 1835 'wr' => $wr, 1836 'media_manager' => true, 1837 'target' => ($INPUT->has('target') && $wr) ? $INPUT->str('target') : 'section', 1838 'intro_locale' => $include); 1839 1840 if ($data['target'] !== 'section') { 1841 // Only emit event if page is writable, section edit data is valid and 1842 // edit target is not section. 1843 trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true); 1844 } else { 1845 html_edit_form($data); 1846 } 1847 if (isset($data['intro_locale'])) { 1848 echo p_locale_xhtml($data['intro_locale']); 1849 } 1850 1851 $form->addHidden('target', $data['target']); 1852 $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar', 'class'=>'editBar'))); 1853 $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl'))); 1854 $form->addElement(form_makeCloseTag('div')); 1855 if ($wr) { 1856 $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons'))); 1857 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4'))); 1858 $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5'))); 1859 $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6'))); 1860 $form->addElement(form_makeCloseTag('div')); 1861 $form->addElement(form_makeOpenTag('div', array('class'=>'summary'))); 1862 $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2'))); 1863 $elem = html_minoredit(); 1864 if ($elem) $form->addElement($elem); 1865 $form->addElement(form_makeCloseTag('div')); 1866 } 1867 $form->addElement(form_makeCloseTag('div')); 1868 if($wr && $conf['license']){ 1869 $form->addElement(form_makeOpenTag('div', array('class'=>'license'))); 1870 $out = $lang['licenseok']; 1871 $out .= ' <a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"'; 1872 if($conf['target']['extern']) $out .= ' target="'.$conf['target']['extern'].'"'; 1873 $out .= '>'.$license[$conf['license']]['name'].'</a>'; 1874 $form->addElement($out); 1875 $form->addElement(form_makeCloseTag('div')); 1876 } 1877 1878 if ($wr) { 1879 // sets changed to true when previewed 1880 echo '<script type="text/javascript">/*<![CDATA[*/'. NL; 1881 echo 'textChanged = ' . ($mod ? 'true' : 'false'); 1882 echo '/*!]]>*/</script>' . NL; 1883 } ?> 1884 <div class="editBox" role="application"> 1885 1886 <div class="toolbar group"> 1887 <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div> 1888 <div id="tool__bar"><?php if ($wr && $data['media_manager']){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>" 1889 target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div> 1890 </div> 1891 <?php 1892 1893 html_form('edit', $form); 1894 print '</div>'.NL; 1895} 1896 1897/** 1898 * Display the default edit form 1899 * 1900 * Is the default action for HTML_EDIT_FORMSELECTION. 1901 * 1902 * @param mixed[] $param 1903 */ 1904function html_edit_form($param) { 1905 global $TEXT; 1906 1907 if ($param['target'] !== 'section') { 1908 msg('No editor for edit target ' . hsc($param['target']) . ' found.', -1); 1909 } 1910 1911 $attr = array('tabindex'=>'1'); 1912 if (!$param['wr']) $attr['readonly'] = 'readonly'; 1913 1914 $param['form']->addElement(form_makeWikiText($TEXT, $attr)); 1915} 1916 1917/** 1918 * Adds a checkbox for minor edits for logged in users 1919 * 1920 * @author Andreas Gohr <andi@splitbrain.org> 1921 * 1922 * @return array|bool 1923 */ 1924function html_minoredit(){ 1925 global $conf; 1926 global $lang; 1927 global $INPUT; 1928 // minor edits are for logged in users only 1929 if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){ 1930 return false; 1931 } 1932 1933 $p = array(); 1934 $p['tabindex'] = 3; 1935 if($INPUT->bool('minor')) $p['checked']='checked'; 1936 return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p); 1937} 1938 1939/** 1940 * prints some debug info 1941 * 1942 * @author Andreas Gohr <andi@splitbrain.org> 1943 */ 1944function html_debug(){ 1945 global $conf; 1946 global $lang; 1947 /** @var DokuWiki_Auth_Plugin $auth */ 1948 global $auth; 1949 global $INFO; 1950 1951 //remove sensitive data 1952 $cnf = $conf; 1953 debug_guard($cnf); 1954 $nfo = $INFO; 1955 debug_guard($nfo); 1956 $ses = $_SESSION; 1957 debug_guard($ses); 1958 1959 print '<html><body>'; 1960 1961 print '<p>When reporting bugs please send all the following '; 1962 print 'output as a mail to andi@splitbrain.org '; 1963 print 'The best way to do this is to save this page in your browser</p>'; 1964 1965 print '<b>$INFO:</b><pre>'; 1966 print_r($nfo); 1967 print '</pre>'; 1968 1969 print '<b>$_SERVER:</b><pre>'; 1970 print_r($_SERVER); 1971 print '</pre>'; 1972 1973 print '<b>$conf:</b><pre>'; 1974 print_r($cnf); 1975 print '</pre>'; 1976 1977 print '<b>DOKU_BASE:</b><pre>'; 1978 print DOKU_BASE; 1979 print '</pre>'; 1980 1981 print '<b>abs DOKU_BASE:</b><pre>'; 1982 print DOKU_URL; 1983 print '</pre>'; 1984 1985 print '<b>rel DOKU_BASE:</b><pre>'; 1986 print dirname($_SERVER['PHP_SELF']).'/'; 1987 print '</pre>'; 1988 1989 print '<b>PHP Version:</b><pre>'; 1990 print phpversion(); 1991 print '</pre>'; 1992 1993 print '<b>locale:</b><pre>'; 1994 print setlocale(LC_ALL,0); 1995 print '</pre>'; 1996 1997 print '<b>encoding:</b><pre>'; 1998 print $lang['encoding']; 1999 print '</pre>'; 2000 2001 if($auth){ 2002 print '<b>Auth backend capabilities:</b><pre>'; 2003 foreach ($auth->getCapabilities() as $cando){ 2004 print ' '.str_pad($cando,16) . ' => ' . (int)$auth->canDo($cando) . NL; 2005 } 2006 print '</pre>'; 2007 } 2008 2009 print '<b>$_SESSION:</b><pre>'; 2010 print_r($ses); 2011 print '</pre>'; 2012 2013 print '<b>Environment:</b><pre>'; 2014 print_r($_ENV); 2015 print '</pre>'; 2016 2017 print '<b>PHP settings:</b><pre>'; 2018 $inis = ini_get_all(); 2019 print_r($inis); 2020 print '</pre>'; 2021 2022 if (function_exists('apache_get_version')) { 2023 $apache = array(); 2024 $apache['version'] = apache_get_version(); 2025 2026 if (function_exists('apache_get_modules')) { 2027 $apache['modules'] = apache_get_modules(); 2028 } 2029 print '<b>Apache</b><pre>'; 2030 print_r($apache); 2031 print '</pre>'; 2032 } 2033 2034 print '</body></html>'; 2035} 2036 2037/** 2038 * Form to request a new password for an existing account 2039 * 2040 * @author Benoit Chesneau <benoit@bchesneau.info> 2041 * @author Andreas Gohr <gohr@cosmocode.de> 2042 */ 2043function html_resendpwd() { 2044 global $lang; 2045 global $conf; 2046 global $INPUT; 2047 2048 $token = preg_replace('/[^a-f0-9]+/','',$INPUT->str('pwauth')); 2049 2050 if(!$conf['autopasswd'] && $token){ 2051 print p_locale_xhtml('resetpwd'); 2052 print '<div class="centeralign">'.NL; 2053 $form = new Doku_Form(array('id' => 'dw__resendpwd')); 2054 $form->startFieldset($lang['btn_resendpwd']); 2055 $form->addHidden('token', $token); 2056 $form->addHidden('do', 'resendpwd'); 2057 2058 $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50'))); 2059 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50'))); 2060 2061 $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd'])); 2062 $form->endFieldset(); 2063 html_form('resendpwd', $form); 2064 print '</div>'.NL; 2065 }else{ 2066 print p_locale_xhtml('resendpwd'); 2067 print '<div class="centeralign">'.NL; 2068 $form = new Doku_Form(array('id' => 'dw__resendpwd')); 2069 $form->startFieldset($lang['resendpwd']); 2070 $form->addHidden('do', 'resendpwd'); 2071 $form->addHidden('save', '1'); 2072 $form->addElement(form_makeTag('br')); 2073 $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block')); 2074 $form->addElement(form_makeTag('br')); 2075 $form->addElement(form_makeTag('br')); 2076 $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd'])); 2077 $form->endFieldset(); 2078 html_form('resendpwd', $form); 2079 print '</div>'.NL; 2080 } 2081} 2082 2083/** 2084 * Return the TOC rendered to XHTML 2085 * 2086 * @author Andreas Gohr <andi@splitbrain.org> 2087 * 2088 * @param array $toc 2089 * @return string html 2090 */ 2091function html_TOC($toc){ 2092 if(!count($toc)) return ''; 2093 global $lang; 2094 $out = '<!-- TOC START -->'.DOKU_LF; 2095 $out .= '<div id="dw__toc">'.DOKU_LF; 2096 $out .= '<h3 class="toggle">'; 2097 $out .= $lang['toc']; 2098 $out .= '</h3>'.DOKU_LF; 2099 $out .= '<div>'.DOKU_LF; 2100 $out .= html_buildlist($toc,'toc','html_list_toc','html_li_default',true); 2101 $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF; 2102 $out .= '<!-- TOC END -->'.DOKU_LF; 2103 return $out; 2104} 2105 2106/** 2107 * Callback for html_buildlist 2108 * 2109 * @param array $item 2110 * @return string html 2111 */ 2112function html_list_toc($item){ 2113 if(isset($item['hid'])){ 2114 $link = '#'.$item['hid']; 2115 }else{ 2116 $link = $item['link']; 2117 } 2118 2119 return '<a href="'.$link.'">'.hsc($item['title']).'</a>'; 2120} 2121 2122/** 2123 * Helper function to build TOC items 2124 * 2125 * Returns an array ready to be added to a TOC array 2126 * 2127 * @param string $link - where to link (if $hash set to '#' it's a local anchor) 2128 * @param string $text - what to display in the TOC 2129 * @param int $level - nesting level 2130 * @param string $hash - is prepended to the given $link, set blank if you want full links 2131 * @return array the toc item 2132 */ 2133function html_mktocitem($link, $text, $level, $hash='#'){ 2134 return array( 'link' => $hash.$link, 2135 'title' => $text, 2136 'type' => 'ul', 2137 'level' => $level); 2138} 2139 2140/** 2141 * Output a Doku_Form object. 2142 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT 2143 * 2144 * @author Tom N Harris <tnharris@whoopdedo.org> 2145 * 2146 * @param string $name The name of the form 2147 * @param Doku_Form $form The form 2148 */ 2149function html_form($name, &$form) { 2150 // Safety check in case the caller forgets. 2151 $form->endFieldset(); 2152 trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false); 2153} 2154 2155/** 2156 * Form print function. 2157 * Just calls printForm() on the data object. 2158 * 2159 * @param Doku_Form $data The form 2160 */ 2161function html_form_output($data) { 2162 $data->printForm(); 2163} 2164 2165/** 2166 * Embed a flash object in HTML 2167 * 2168 * This will create the needed HTML to embed a flash movie in a cross browser 2169 * compatble way using valid XHTML 2170 * 2171 * The parameters $params, $flashvars and $atts need to be associative arrays. 2172 * No escaping needs to be done for them. The alternative content *has* to be 2173 * escaped because it is used as is. If no alternative content is given 2174 * $lang['noflash'] is used. 2175 * 2176 * @author Andreas Gohr <andi@splitbrain.org> 2177 * @link http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml 2178 * 2179 * @param string $swf - the SWF movie to embed 2180 * @param int $width - width of the flash movie in pixels 2181 * @param int $height - height of the flash movie in pixels 2182 * @param array $params - additional parameters (<param>) 2183 * @param array $flashvars - parameters to be passed in the flashvar parameter 2184 * @param array $atts - additional attributes for the <object> tag 2185 * @param string $alt - alternative content (is NOT automatically escaped!) 2186 * @return string - the XHTML markup 2187 */ 2188function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){ 2189 global $lang; 2190 2191 $out = ''; 2192 2193 // prepare the object attributes 2194 if(is_null($atts)) $atts = array(); 2195 $atts['width'] = (int) $width; 2196 $atts['height'] = (int) $height; 2197 if(!$atts['width']) $atts['width'] = 425; 2198 if(!$atts['height']) $atts['height'] = 350; 2199 2200 // add object attributes for standard compliant browsers 2201 $std = $atts; 2202 $std['type'] = 'application/x-shockwave-flash'; 2203 $std['data'] = $swf; 2204 2205 // add object attributes for IE 2206 $ie = $atts; 2207 $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'; 2208 2209 // open object (with conditional comments) 2210 $out .= '<!--[if !IE]> -->'.NL; 2211 $out .= '<object '.buildAttributes($std).'>'.NL; 2212 $out .= '<!-- <![endif]-->'.NL; 2213 $out .= '<!--[if IE]>'.NL; 2214 $out .= '<object '.buildAttributes($ie).'>'.NL; 2215 $out .= ' <param name="movie" value="'.hsc($swf).'" />'.NL; 2216 $out .= '<!--><!-- -->'.NL; 2217 2218 // print params 2219 if(is_array($params)) foreach($params as $key => $val){ 2220 $out .= ' <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL; 2221 } 2222 2223 // add flashvars 2224 if(is_array($flashvars)){ 2225 $out .= ' <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL; 2226 } 2227 2228 // alternative content 2229 if($alt){ 2230 $out .= $alt.NL; 2231 }else{ 2232 $out .= $lang['noflash'].NL; 2233 } 2234 2235 // finish 2236 $out .= '</object>'.NL; 2237 $out .= '<!-- <![endif]-->'.NL; 2238 2239 return $out; 2240} 2241 2242/** 2243 * Prints HTML code for the given tab structure 2244 * 2245 * @param array $tabs tab structure 2246 * @param string $current_tab the current tab id 2247 */ 2248function html_tabs($tabs, $current_tab = null) { 2249 echo '<ul class="tabs">'.NL; 2250 2251 foreach($tabs as $id => $tab) { 2252 html_tab($tab['href'], $tab['caption'], $id === $current_tab); 2253 } 2254 2255 echo '</ul>'.NL; 2256} 2257 2258/** 2259 * Prints a single tab 2260 * 2261 * @author Kate Arzamastseva <pshns@ukr.net> 2262 * @author Adrian Lang <mail@adrianlang.de> 2263 * 2264 * @param string $href - tab href 2265 * @param string $caption - tab caption 2266 * @param boolean $selected - is tab selected 2267 */ 2268 2269function html_tab($href, $caption, $selected=false) { 2270 $tab = '<li>'; 2271 if ($selected) { 2272 $tab .= '<strong>'; 2273 } else { 2274 $tab .= '<a href="' . hsc($href) . '">'; 2275 } 2276 $tab .= hsc($caption) 2277 . '</' . ($selected ? 'strong' : 'a') . '>' 2278 . '</li>'.NL; 2279 echo $tab; 2280} 2281 2282/** 2283 * Display size change 2284 * 2285 * @param int $sizechange - size of change in Bytes 2286 * @param Doku_Form $form - form to add elements to 2287 */ 2288 2289function html_sizechange($sizechange, Doku_Form $form) { 2290 if(isset($sizechange)) { 2291 $class = 'sizechange'; 2292 $value = filesize_h(abs($sizechange)); 2293 if($sizechange > 0) { 2294 $class .= ' positive'; 2295 $value = '+' . $value; 2296 } elseif($sizechange < 0) { 2297 $class .= ' negative'; 2298 $value = '-' . $value; 2299 } else { 2300 $value = '±' . $value; 2301 } 2302 $form->addElement(form_makeOpenTag('span', array('class' => $class))); 2303 $form->addElement($value); 2304 $form->addElement(form_makeCloseTag('span')); 2305 } 2306} 2307