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