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