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