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