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