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