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