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