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