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 * 926 * @param array $data array with item arrays 927 * @param string $class class of ul wrapper 928 * @param callable $func callback to print an list item 929 * @param string $lifunc callback to the opening li tag 930 * @param bool $forcewrapper Trigger building a wrapper ul if the first level is 931 0 (we have a root object) or 1 (just the root content) 932 * @return string html of an unordered list 933 */ 934function html_buildlist($data,$class,$func,$lifunc='html_li_default',$forcewrapper=false){ 935 if (count($data) === 0) { 936 return ''; 937 } 938 939 $start_level = $data[0]['level']; 940 $level = $start_level; 941 $ret = ''; 942 $open = 0; 943 944 foreach ($data as $item){ 945 946 if( $item['level'] > $level ){ 947 //open new list 948 for($i=0; $i<($item['level'] - $level); $i++){ 949 if ($i) $ret .= "<li class=\"clear\">"; 950 $ret .= "\n<ul class=\"$class\">\n"; 951 $open++; 952 } 953 $level = $item['level']; 954 955 }elseif( $item['level'] < $level ){ 956 //close last item 957 $ret .= "</li>\n"; 958 while( $level > $item['level'] && $open > 0 ){ 959 //close higher lists 960 $ret .= "</ul>\n</li>\n"; 961 $level--; 962 $open--; 963 } 964 } elseif ($ret !== '') { 965 //close previous item 966 $ret .= "</li>\n"; 967 } 968 969 //print item 970 $ret .= call_user_func($lifunc,$item); 971 $ret .= '<div class="li">'; 972 973 $ret .= call_user_func($func,$item); 974 $ret .= '</div>'; 975 } 976 977 //close remaining items and lists 978 $ret .= "</li>\n"; 979 while($open-- > 0) { 980 $ret .= "</ul></li>\n"; 981 } 982 983 if ($forcewrapper || $start_level < 2) { 984 // Trigger building a wrapper ul if the first level is 985 // 0 (we have a root object) or 1 (just the root content) 986 $ret = "\n<ul class=\"$class\">\n".$ret."</ul>\n"; 987 } 988 989 return $ret; 990} 991 992/** 993 * display backlinks 994 * 995 * @author Andreas Gohr <andi@splitbrain.org> 996 * @author Michael Klier <chi@chimeric.de> 997 */ 998function html_backlinks(){ 999 global $ID; 1000 global $lang; 1001 1002 print p_locale_xhtml('backlinks'); 1003 1004 $data = ft_backlinks($ID); 1005 1006 if(!empty($data)) { 1007 print '<ul class="idx">'; 1008 foreach($data as $blink){ 1009 print '<li><div class="li">'; 1010 print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink); 1011 print '</div></li>'; 1012 } 1013 print '</ul>'; 1014 } else { 1015 print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>'; 1016 } 1017} 1018 1019/** 1020 * Get header of diff HTML 1021 * @param string $l_rev Left revisions 1022 * @param string $r_rev Right revision 1023 * @param string $id Page id, if null $ID is used 1024 * @param bool $media If it is for media files 1025 * @param bool $inline Return the header on a single line 1026 * @return array HTML snippets for diff header 1027 */ 1028function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = false) { 1029 global $lang; 1030 if ($id === null) { 1031 global $ID; 1032 $id = $ID; 1033 } 1034 $head_separator = $inline ? ' ' : '<br />'; 1035 $media_or_wikiFN = $media ? 'mediaFN' : 'wikiFN'; 1036 $ml_or_wl = $media ? 'ml' : 'wl'; 1037 $l_minor = $r_minor = ''; 1038 1039 if($media) { 1040 $changelog = new MediaChangeLog($id); 1041 } else { 1042 $changelog = new PageChangeLog($id); 1043 } 1044 if(!$l_rev){ 1045 $l_head = '—'; 1046 }else{ 1047 $l_info = $changelog->getRevisionInfo($l_rev); 1048 if($l_info['user']){ 1049 $l_user = '<bdi>'.editorinfo($l_info['user']).'</bdi>'; 1050 if(auth_ismanager()) $l_user .= ' <bdo dir="ltr">('.$l_info['ip'].')</bdo>'; 1051 } else { 1052 $l_user = '<bdo dir="ltr">'.$l_info['ip'].'</bdo>'; 1053 } 1054 $l_user = '<span class="user">'.$l_user.'</span>'; 1055 $l_sum = ($l_info['sum']) ? '<span class="sum"><bdi>'.hsc($l_info['sum']).'</bdi></span>' : ''; 1056 if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"'; 1057 1058 $l_head_title = ($media) ? dformat($l_rev) : $id.' ['.dformat($l_rev).']'; 1059 $l_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$l_rev").'">'. 1060 $l_head_title.'</a></bdi>'. 1061 $head_separator.$l_user.' '.$l_sum; 1062 } 1063 1064 if($r_rev){ 1065 $r_info = $changelog->getRevisionInfo($r_rev); 1066 if($r_info['user']){ 1067 $r_user = '<bdi>'.editorinfo($r_info['user']).'</bdi>'; 1068 if(auth_ismanager()) $r_user .= ' <bdo dir="ltr">('.$r_info['ip'].')</bdo>'; 1069 } else { 1070 $r_user = '<bdo dir="ltr">'.$r_info['ip'].'</bdo>'; 1071 } 1072 $r_user = '<span class="user">'.$r_user.'</span>'; 1073 $r_sum = ($r_info['sum']) ? '<span class="sum"><bdi>'.hsc($r_info['sum']).'</bdi></span>' : ''; 1074 if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"'; 1075 1076 $r_head_title = ($media) ? dformat($r_rev) : $id.' ['.dformat($r_rev).']'; 1077 $r_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$r_rev").'">'. 1078 $r_head_title.'</a></bdi>'. 1079 $head_separator.$r_user.' '.$r_sum; 1080 }elseif($_rev = @filemtime($media_or_wikiFN($id))){ 1081 $_info = $changelog->getRevisionInfo($_rev); 1082 if($_info['user']){ 1083 $_user = '<bdi>'.editorinfo($_info['user']).'</bdi>'; 1084 if(auth_ismanager()) $_user .= ' <bdo dir="ltr">('.$_info['ip'].')</bdo>'; 1085 } else { 1086 $_user = '<bdo dir="ltr">'.$_info['ip'].'</bdo>'; 1087 } 1088 $_user = '<span class="user">'.$_user.'</span>'; 1089 $_sum = ($_info['sum']) ? '<span class="sum"><bdi>'.hsc($_info['sum']).'</span></bdi>' : ''; 1090 if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"'; 1091 1092 $r_head_title = ($media) ? dformat($_rev) : $id.' ['.dformat($_rev).']'; 1093 $r_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id).'">'. 1094 $r_head_title.'</a></bdi> '. 1095 '('.$lang['current'].')'. 1096 $head_separator.$_user.' '.$_sum; 1097 }else{ 1098 $r_head = '— ('.$lang['current'].')'; 1099 } 1100 1101 return array($l_head, $r_head, $l_minor, $r_minor); 1102} 1103 1104/** 1105 * Show diff 1106 * between current page version and provided $text 1107 * or between the revisions provided via GET or POST 1108 * 1109 * @author Andreas Gohr <andi@splitbrain.org> 1110 * @param string $text when non-empty: compare with this text with most current version 1111 * @param bool $intro display the intro text 1112 * @param string $type type of the diff (inline or sidebyside) 1113 */ 1114function html_diff($text = '', $intro = true, $type = null) { 1115 global $ID; 1116 global $REV; 1117 global $lang; 1118 global $INPUT; 1119 global $INFO; 1120 $pagelog = new PageChangeLog($ID); 1121 1122 /* 1123 * Determine diff type 1124 */ 1125 if(!$type) { 1126 $type = $INPUT->str('difftype'); 1127 if(empty($type)) { 1128 $type = get_doku_pref('difftype', $type); 1129 if(empty($type) && $INFO['ismobile']) { 1130 $type = 'inline'; 1131 } 1132 } 1133 } 1134 if($type != 'inline') $type = 'sidebyside'; 1135 1136 /* 1137 * Determine requested revision(s) 1138 */ 1139 // we're trying to be clever here, revisions to compare can be either 1140 // given as rev and rev2 parameters, with rev2 being optional. Or in an 1141 // array in rev2. 1142 $rev1 = $REV; 1143 1144 $rev2 = $INPUT->ref('rev2'); 1145 if(is_array($rev2)) { 1146 $rev1 = (int) $rev2[0]; 1147 $rev2 = (int) $rev2[1]; 1148 1149 if(!$rev1) { 1150 $rev1 = $rev2; 1151 unset($rev2); 1152 } 1153 } else { 1154 $rev2 = $INPUT->int('rev2'); 1155 } 1156 1157 /* 1158 * Determine left and right revision, its texts and the header 1159 */ 1160 $r_minor = ''; 1161 $l_minor = ''; 1162 1163 if($text) { // compare text to the most current revision 1164 $l_rev = ''; 1165 $l_text = rawWiki($ID, ''); 1166 $l_head = '<a class="wikilink1" href="' . wl($ID) . '">' . 1167 $ID . ' ' . dformat((int) @filemtime(wikiFN($ID))) . '</a> ' . 1168 $lang['current']; 1169 1170 $r_rev = ''; 1171 $r_text = cleanText($text); 1172 $r_head = $lang['yours']; 1173 } else { 1174 if($rev1 && isset($rev2) && $rev2) { // two specific revisions wanted 1175 // make sure order is correct (older on the left) 1176 if($rev1 < $rev2) { 1177 $l_rev = $rev1; 1178 $r_rev = $rev2; 1179 } else { 1180 $l_rev = $rev2; 1181 $r_rev = $rev1; 1182 } 1183 } elseif($rev1) { // single revision given, compare to current 1184 $r_rev = ''; 1185 $l_rev = $rev1; 1186 } else { // no revision was given, compare previous to current 1187 $r_rev = ''; 1188 $revs = $pagelog->getRevisions(0, 1); 1189 $l_rev = $revs[0]; 1190 $REV = $l_rev; // store revision back in $REV 1191 } 1192 1193 // when both revisions are empty then the page was created just now 1194 if(!$l_rev && !$r_rev) { 1195 $l_text = ''; 1196 } else { 1197 $l_text = rawWiki($ID, $l_rev); 1198 } 1199 $r_text = rawWiki($ID, $r_rev); 1200 1201 list($l_head, $r_head, $l_minor, $r_minor) = html_diff_head($l_rev, $r_rev, null, false, $type == 'inline'); 1202 } 1203 1204 /* 1205 * Build navigation 1206 */ 1207 $l_nav = ''; 1208 $r_nav = ''; 1209 if(!$text) { 1210 list($l_nav, $r_nav) = html_diff_navigation($pagelog, $type, $l_rev, $r_rev); 1211 } 1212 /* 1213 * Create diff object and the formatter 1214 */ 1215 $diff = new Diff(explode("\n", $l_text), explode("\n", $r_text)); 1216 1217 if($type == 'inline') { 1218 $diffformatter = new InlineDiffFormatter(); 1219 } else { 1220 $diffformatter = new TableDiffFormatter(); 1221 } 1222 /* 1223 * Display intro 1224 */ 1225 if($intro) print p_locale_xhtml('diff'); 1226 1227 /* 1228 * Display type and exact reference 1229 */ 1230 if(!$text) { 1231 ptln('<div class="diffoptions group">'); 1232 1233 1234 $form = new Doku_Form(array('action' => wl())); 1235 $form->addHidden('id', $ID); 1236 $form->addHidden('rev2[0]', $l_rev); 1237 $form->addHidden('rev2[1]', $r_rev); 1238 $form->addHidden('do', 'diff'); 1239 $form->addElement( 1240 form_makeListboxField( 1241 'difftype', 1242 array( 1243 'sidebyside' => $lang['diff_side'], 1244 'inline' => $lang['diff_inline'] 1245 ), 1246 $type, 1247 $lang['diff_type'], 1248 '', '', 1249 array('class' => 'quickselect') 1250 ) 1251 ); 1252 $form->addElement(form_makeButton('submit', 'diff', 'Go')); 1253 $form->printForm(); 1254 1255 ptln('<p>'); 1256 // link to exactly this view FS#2835 1257 echo html_diff_navigationlink($type, 'difflink', $l_rev, $r_rev ? $r_rev : $INFO['currentrev']); 1258 ptln('</p>'); 1259 1260 ptln('</div>'); // .diffoptions 1261 } 1262 1263 /* 1264 * Display diff view table 1265 */ 1266 ?> 1267 <div class="table"> 1268 <table class="diff diff_<?php echo $type ?>"> 1269 1270 <?php 1271 //navigation and header 1272 if($type == 'inline') { 1273 if(!$text) { ?> 1274 <tr> 1275 <td class="diff-lineheader">-</td> 1276 <td class="diffnav"><?php echo $l_nav ?></td> 1277 </tr> 1278 <tr> 1279 <th class="diff-lineheader">-</th> 1280 <th <?php echo $l_minor ?>> 1281 <?php echo $l_head ?> 1282 </th> 1283 </tr> 1284 <?php } ?> 1285 <tr> 1286 <td class="diff-lineheader">+</td> 1287 <td class="diffnav"><?php echo $r_nav ?></td> 1288 </tr> 1289 <tr> 1290 <th class="diff-lineheader">+</th> 1291 <th <?php echo $r_minor ?>> 1292 <?php echo $r_head ?> 1293 </th> 1294 </tr> 1295 <?php } else { 1296 if(!$text) { ?> 1297 <tr> 1298 <td colspan="2" class="diffnav"><?php echo $l_nav ?></td> 1299 <td colspan="2" class="diffnav"><?php echo $r_nav ?></td> 1300 </tr> 1301 <?php } ?> 1302 <tr> 1303 <th colspan="2" <?php echo $l_minor ?>> 1304 <?php echo $l_head ?> 1305 </th> 1306 <th colspan="2" <?php echo $r_minor ?>> 1307 <?php echo $r_head ?> 1308 </th> 1309 </tr> 1310 <?php } 1311 1312 //diff view 1313 echo html_insert_softbreaks($diffformatter->format($diff)); ?> 1314 1315 </table> 1316 </div> 1317<?php 1318} 1319 1320/** 1321 * Create html for revision navigation 1322 * 1323 * @param PageChangeLog $pagelog changelog object of current page 1324 * @param string $type inline vs sidebyside 1325 * @param int $l_rev left revision timestamp 1326 * @param int $r_rev right revision timestamp 1327 * @return string[] html of left and right navigation elements 1328 */ 1329function html_diff_navigation($pagelog, $type, $l_rev, $r_rev) { 1330 global $INFO, $ID; 1331 1332 // last timestamp is not in changelog, retrieve timestamp from metadata 1333 // note: when page is removed, the metadata timestamp is zero 1334 $r_rev = $r_rev ? $r_rev : $INFO['meta']['last_change']['date']; 1335 1336 //retrieve revisions with additional info 1337 list($l_revs, $r_revs) = $pagelog->getRevisionsAround($l_rev, $r_rev); 1338 $l_revisions = array(); 1339 if(!$l_rev) { 1340 $l_revisions[0] = array(0, "", false); //no left revision given, add dummy 1341 } 1342 foreach($l_revs as $rev) { 1343 $info = $pagelog->getRevisionInfo($rev); 1344 $l_revisions[$rev] = array( 1345 $rev, 1346 dformat($info['date']) . ' ' . editorinfo($info['user'], true) . ' ' . $info['sum'], 1347 $r_rev ? $rev >= $r_rev : false //disable? 1348 ); 1349 } 1350 $r_revisions = array(); 1351 if(!$r_rev) { 1352 $r_revisions[0] = array(0, "", false); //no right revision given, add dummy 1353 } 1354 foreach($r_revs as $rev) { 1355 $info = $pagelog->getRevisionInfo($rev); 1356 $r_revisions[$rev] = array( 1357 $rev, 1358 dformat($info['date']) . ' ' . editorinfo($info['user'], true) . ' ' . $info['sum'], 1359 $rev <= $l_rev //disable? 1360 ); 1361 } 1362 1363 //determine previous/next revisions 1364 $l_index = array_search($l_rev, $l_revs); 1365 $l_prev = $l_revs[$l_index + 1]; 1366 $l_next = $l_revs[$l_index - 1]; 1367 if($r_rev) { 1368 $r_index = array_search($r_rev, $r_revs); 1369 $r_prev = $r_revs[$r_index + 1]; 1370 $r_next = $r_revs[$r_index - 1]; 1371 } else { 1372 //removed page 1373 if($l_next) { 1374 $r_prev = $r_revs[0]; 1375 } else { 1376 $r_prev = null; 1377 } 1378 $r_next = null; 1379 } 1380 1381 /* 1382 * Left side: 1383 */ 1384 $l_nav = ''; 1385 //move back 1386 if($l_prev) { 1387 $l_nav .= html_diff_navigationlink($type, 'diffbothprevrev', $l_prev, $r_prev); 1388 $l_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_prev, $r_rev); 1389 } 1390 //dropdown 1391 $form = new Doku_Form(array('action' => wl())); 1392 $form->addHidden('id', $ID); 1393 $form->addHidden('difftype', $type); 1394 $form->addHidden('rev2[1]', $r_rev); 1395 $form->addHidden('do', 'diff'); 1396 $form->addElement( 1397 form_makeListboxField( 1398 'rev2[0]', 1399 $l_revisions, 1400 $l_rev, 1401 '', '', '', 1402 array('class' => 'quickselect') 1403 ) 1404 ); 1405 $form->addElement(form_makeButton('submit', 'diff', 'Go')); 1406 $l_nav .= $form->getForm(); 1407 //move forward 1408 if($l_next && ($l_next < $r_rev || !$r_rev)) { 1409 $l_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_next, $r_rev); 1410 } 1411 1412 /* 1413 * Right side: 1414 */ 1415 $r_nav = ''; 1416 //move back 1417 if($l_rev < $r_prev) { 1418 $r_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_rev, $r_prev); 1419 } 1420 //dropdown 1421 $form = new Doku_Form(array('action' => wl())); 1422 $form->addHidden('id', $ID); 1423 $form->addHidden('rev2[0]', $l_rev); 1424 $form->addHidden('difftype', $type); 1425 $form->addHidden('do', 'diff'); 1426 $form->addElement( 1427 form_makeListboxField( 1428 'rev2[1]', 1429 $r_revisions, 1430 $r_rev, 1431 '', '', '', 1432 array('class' => 'quickselect') 1433 ) 1434 ); 1435 $form->addElement(form_makeButton('submit', 'diff', 'Go')); 1436 $r_nav .= $form->getForm(); 1437 //move forward 1438 if($r_next) { 1439 if($pagelog->isCurrentRevision($r_next)) { 1440 $r_nav .= html_diff_navigationlink($type, 'difflastrev', $l_rev); //last revision is diff with current page 1441 } else { 1442 $r_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_rev, $r_next); 1443 } 1444 $r_nav .= html_diff_navigationlink($type, 'diffbothnextrev', $l_next, $r_next); 1445 } 1446 return array($l_nav, $r_nav); 1447} 1448 1449/** 1450 * Create html link to a diff defined by two revisions 1451 * 1452 * @param string $difftype display type 1453 * @param string $linktype 1454 * @param int $lrev oldest revision 1455 * @param int $rrev newest revision or null for diff with current revision 1456 * @return string html of link to a diff 1457 */ 1458function html_diff_navigationlink($difftype, $linktype, $lrev, $rrev = null) { 1459 global $ID, $lang; 1460 if(!$rrev) { 1461 $urlparam = array( 1462 'do' => 'diff', 1463 'rev' => $lrev, 1464 'difftype' => $difftype, 1465 ); 1466 } else { 1467 $urlparam = array( 1468 'do' => 'diff', 1469 'rev2[0]' => $lrev, 1470 'rev2[1]' => $rrev, 1471 'difftype' => $difftype, 1472 ); 1473 } 1474 return '<a class="' . $linktype . '" href="' . wl($ID, $urlparam) . '" title="' . $lang[$linktype] . '">' . 1475 '<span>' . $lang[$linktype] . '</span>' . 1476 '</a>' . "\n"; 1477} 1478 1479/** 1480 * Insert soft breaks in diff html 1481 * 1482 * @param $diffhtml 1483 * @return string 1484 */ 1485function html_insert_softbreaks($diffhtml) { 1486 // search the diff html string for both: 1487 // - html tags, so these can be ignored 1488 // - long strings of characters without breaking characters 1489 return preg_replace_callback('/<[^>]*>|[^<> ]{12,}/','html_softbreak_callback',$diffhtml); 1490} 1491 1492/** 1493 * callback which adds softbreaks 1494 * 1495 * @param array $match array with first the complete match 1496 * @return string the replacement 1497 */ 1498function html_softbreak_callback($match){ 1499 // if match is an html tag, return it intact 1500 if ($match[0]{0} == '<') return $match[0]; 1501 1502 // its a long string without a breaking character, 1503 // make certain characters into breaking characters by inserting a 1504 // breaking character (zero length space, U+200B / #8203) in front them. 1505 $regex = <<< REGEX 1506(?(?= # start a conditional expression with a positive look ahead ... 1507&\#?\\w{1,6};) # ... for html entities - we don't want to split them (ok to catch some invalid combinations) 1508&\#?\\w{1,6}; # yes pattern - a quicker match for the html entity, since we know we have one 1509| 1510[?/,&\#;:] # no pattern - any other group of 'special' characters to insert a breaking character after 1511)+ # end conditional expression 1512REGEX; 1513 1514 return preg_replace('<'.$regex.'>xu','\0​',$match[0]); 1515} 1516 1517/** 1518 * show warning on conflict detection 1519 * 1520 * @author Andreas Gohr <andi@splitbrain.org> 1521 */ 1522function html_conflict($text,$summary){ 1523 global $ID; 1524 global $lang; 1525 1526 print p_locale_xhtml('conflict'); 1527 $form = new Doku_Form(array('id' => 'dw__editform')); 1528 $form->addHidden('id', $ID); 1529 $form->addHidden('wikitext', $text); 1530 $form->addHidden('summary', $summary); 1531 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s'))); 1532 $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel'])); 1533 html_form('conflict', $form); 1534 print '<br /><br /><br /><br />'.NL; 1535} 1536 1537/** 1538 * Prints the global message array 1539 * 1540 * @author Andreas Gohr <andi@splitbrain.org> 1541 */ 1542function html_msgarea(){ 1543 global $MSG, $MSG_shown; 1544 /** @var array $MSG */ 1545 // store if the global $MSG has already been shown and thus HTML output has been started 1546 $MSG_shown = true; 1547 1548 if(!isset($MSG)) return; 1549 1550 $shown = array(); 1551 foreach($MSG as $msg){ 1552 $hash = md5($msg['msg']); 1553 if(isset($shown[$hash])) continue; // skip double messages 1554 if(info_msg_allowed($msg)){ 1555 print '<div class="'.$msg['lvl'].'">'; 1556 print $msg['msg']; 1557 print '</div>'; 1558 } 1559 $shown[$hash] = 1; 1560 } 1561 1562 unset($GLOBALS['MSG']); 1563} 1564 1565/** 1566 * Prints the registration form 1567 * 1568 * @author Andreas Gohr <andi@splitbrain.org> 1569 */ 1570function html_register(){ 1571 global $lang; 1572 global $conf; 1573 global $INPUT; 1574 1575 $base_attrs = array('size'=>50,'required'=>'required'); 1576 $email_attrs = $base_attrs + array('type'=>'email','class'=>'edit'); 1577 1578 print p_locale_xhtml('register'); 1579 print '<div class="centeralign">'.NL; 1580 $form = new Doku_Form(array('id' => 'dw__register')); 1581 $form->startFieldset($lang['btn_register']); 1582 $form->addHidden('do', 'register'); 1583 $form->addHidden('save', '1'); 1584 $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block', $base_attrs)); 1585 if (!$conf['autopasswd']) { 1586 $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', $base_attrs)); 1587 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', $base_attrs)); 1588 } 1589 $form->addElement(form_makeTextField('fullname', $INPUT->post->str('fullname'), $lang['fullname'], '', 'block', $base_attrs)); 1590 $form->addElement(form_makeField('email','email', $INPUT->post->str('email'), $lang['email'], '', 'block', $email_attrs)); 1591 $form->addElement(form_makeButton('submit', '', $lang['btn_register'])); 1592 $form->endFieldset(); 1593 html_form('register', $form); 1594 1595 print '</div>'.NL; 1596} 1597 1598/** 1599 * Print the update profile form 1600 * 1601 * @author Christopher Smith <chris@jalakai.co.uk> 1602 * @author Andreas Gohr <andi@splitbrain.org> 1603 */ 1604function html_updateprofile(){ 1605 global $lang; 1606 global $conf; 1607 global $INPUT; 1608 global $INFO; 1609 /** @var DokuWiki_Auth_Plugin $auth */ 1610 global $auth; 1611 1612 print p_locale_xhtml('updateprofile'); 1613 print '<div class="centeralign">'.NL; 1614 1615 $fullname = $INPUT->post->str('fullname', $INFO['userinfo']['name'], true); 1616 $email = $INPUT->post->str('email', $INFO['userinfo']['mail'], true); 1617 $form = new Doku_Form(array('id' => 'dw__register')); 1618 $form->startFieldset($lang['profile']); 1619 $form->addHidden('do', 'profile'); 1620 $form->addHidden('save', '1'); 1621 $form->addElement(form_makeTextField('login', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled'))); 1622 $attr = array('size'=>'50'); 1623 if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled'; 1624 $form->addElement(form_makeTextField('fullname', $fullname, $lang['fullname'], '', 'block', $attr)); 1625 $attr = array('size'=>'50', 'class'=>'edit'); 1626 if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled'; 1627 $form->addElement(form_makeField('email','email', $email, $lang['email'], '', 'block', $attr)); 1628 $form->addElement(form_makeTag('br')); 1629 if ($auth->canDo('modPass')) { 1630 $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50'))); 1631 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50'))); 1632 } 1633 if ($conf['profileconfirm']) { 1634 $form->addElement(form_makeTag('br')); 1635 $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50', 'required' => 'required'))); 1636 } 1637 $form->addElement(form_makeButton('submit', '', $lang['btn_save'])); 1638 $form->addElement(form_makeButton('reset', '', $lang['btn_reset'])); 1639 1640 $form->endFieldset(); 1641 html_form('updateprofile', $form); 1642 1643 if ($auth->canDo('delUser') && actionOK('profile_delete')) { 1644 $form_profiledelete = new Doku_Form(array('id' => 'dw__profiledelete')); 1645 $form_profiledelete->startFieldset($lang['profdeleteuser']); 1646 $form_profiledelete->addHidden('do', 'profile_delete'); 1647 $form_profiledelete->addHidden('delete', '1'); 1648 $form_profiledelete->addElement(form_makeCheckboxField('confirm_delete', '1', $lang['profconfdelete'],'dw__confirmdelete','', array('required' => 'required'))); 1649 if ($conf['profileconfirm']) { 1650 $form_profiledelete->addElement(form_makeTag('br')); 1651 $form_profiledelete->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50', 'required' => 'required'))); 1652 } 1653 $form_profiledelete->addElement(form_makeButton('submit', '', $lang['btn_deleteuser'])); 1654 $form_profiledelete->endFieldset(); 1655 1656 html_form('profiledelete', $form_profiledelete); 1657 } 1658 1659 print '</div>'.NL; 1660} 1661 1662/** 1663 * Preprocess edit form data 1664 * 1665 * @author Andreas Gohr <andi@splitbrain.org> 1666 * 1667 * @triggers HTML_EDITFORM_OUTPUT 1668 */ 1669function html_edit(){ 1670 global $INPUT; 1671 global $ID; 1672 global $REV; 1673 global $DATE; 1674 global $PRE; 1675 global $SUF; 1676 global $INFO; 1677 global $SUM; 1678 global $lang; 1679 global $conf; 1680 global $TEXT; 1681 global $RANGE; 1682 1683 if ($INPUT->has('changecheck')) { 1684 $check = $INPUT->str('changecheck'); 1685 } elseif(!$INFO['exists']){ 1686 // $TEXT has been loaded from page template 1687 $check = md5(''); 1688 } else { 1689 $check = md5($TEXT); 1690 } 1691 $mod = md5($TEXT) !== $check; 1692 1693 $wr = $INFO['writable'] && !$INFO['locked']; 1694 $include = 'edit'; 1695 if($wr){ 1696 if ($REV) $include = 'editrev'; 1697 }else{ 1698 // check pseudo action 'source' 1699 if(!actionOK('source')){ 1700 msg('Command disabled: source',-1); 1701 return; 1702 } 1703 $include = 'read'; 1704 } 1705 1706 global $license; 1707 1708 $form = new Doku_Form(array('id' => 'dw__editform')); 1709 $form->addHidden('id', $ID); 1710 $form->addHidden('rev', $REV); 1711 $form->addHidden('date', $DATE); 1712 $form->addHidden('prefix', $PRE . '.'); 1713 $form->addHidden('suffix', $SUF); 1714 $form->addHidden('changecheck', $check); 1715 1716 $data = array('form' => $form, 1717 'wr' => $wr, 1718 'media_manager' => true, 1719 'target' => ($INPUT->has('target') && $wr) ? $INPUT->str('target') : 'section', 1720 'intro_locale' => $include); 1721 1722 if ($data['target'] !== 'section') { 1723 // Only emit event if page is writable, section edit data is valid and 1724 // edit target is not section. 1725 trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true); 1726 } else { 1727 html_edit_form($data); 1728 } 1729 if (isset($data['intro_locale'])) { 1730 echo p_locale_xhtml($data['intro_locale']); 1731 } 1732 1733 $form->addHidden('target', $data['target']); 1734 $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar', 'class'=>'editBar'))); 1735 $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl'))); 1736 $form->addElement(form_makeCloseTag('div')); 1737 if ($wr) { 1738 $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons'))); 1739 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4'))); 1740 $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5'))); 1741 $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6'))); 1742 $form->addElement(form_makeCloseTag('div')); 1743 $form->addElement(form_makeOpenTag('div', array('class'=>'summary'))); 1744 $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2'))); 1745 $elem = html_minoredit(); 1746 if ($elem) $form->addElement($elem); 1747 $form->addElement(form_makeCloseTag('div')); 1748 } 1749 $form->addElement(form_makeCloseTag('div')); 1750 if($wr && $conf['license']){ 1751 $form->addElement(form_makeOpenTag('div', array('class'=>'license'))); 1752 $out = $lang['licenseok']; 1753 $out .= ' <a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"'; 1754 if($conf['target']['extern']) $out .= ' target="'.$conf['target']['extern'].'"'; 1755 $out .= '>'.$license[$conf['license']]['name'].'</a>'; 1756 $form->addElement($out); 1757 $form->addElement(form_makeCloseTag('div')); 1758 } 1759 1760 if ($wr) { 1761 // sets changed to true when previewed 1762 echo '<script type="text/javascript">/*<![CDATA[*/'. NL; 1763 echo 'textChanged = ' . ($mod ? 'true' : 'false'); 1764 echo '/*!]]>*/</script>' . NL; 1765 } ?> 1766 <div class="editBox" role="application"> 1767 1768 <div class="toolbar group"> 1769 <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div> 1770 <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']?>" 1771 target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div> 1772 </div> 1773 <?php 1774 1775 html_form('edit', $form); 1776 print '</div>'.NL; 1777} 1778 1779/** 1780 * Display the default edit form 1781 * 1782 * Is the default action for HTML_EDIT_FORMSELECTION. 1783 * @param mixed[] $param 1784 */ 1785function html_edit_form($param) { 1786 global $TEXT; 1787 1788 if ($param['target'] !== 'section') { 1789 msg('No editor for edit target ' . hsc($param['target']) . ' found.', -1); 1790 } 1791 1792 $attr = array('tabindex'=>'1'); 1793 if (!$param['wr']) $attr['readonly'] = 'readonly'; 1794 1795 $param['form']->addElement(form_makeWikiText($TEXT, $attr)); 1796} 1797 1798/** 1799 * Adds a checkbox for minor edits for logged in users 1800 * 1801 * @author Andreas Gohr <andi@splitbrain.org> 1802 */ 1803function html_minoredit(){ 1804 global $conf; 1805 global $lang; 1806 global $INPUT; 1807 // minor edits are for logged in users only 1808 if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){ 1809 return false; 1810 } 1811 1812 $p = array(); 1813 $p['tabindex'] = 3; 1814 if($INPUT->bool('minor')) $p['checked']='checked'; 1815 return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p); 1816} 1817 1818/** 1819 * prints some debug info 1820 * 1821 * @author Andreas Gohr <andi@splitbrain.org> 1822 */ 1823function html_debug(){ 1824 global $conf; 1825 global $lang; 1826 /** @var DokuWiki_Auth_Plugin $auth */ 1827 global $auth; 1828 global $INFO; 1829 1830 //remove sensitive data 1831 $cnf = $conf; 1832 debug_guard($cnf); 1833 $nfo = $INFO; 1834 debug_guard($nfo); 1835 $ses = $_SESSION; 1836 debug_guard($ses); 1837 1838 print '<html><body>'; 1839 1840 print '<p>When reporting bugs please send all the following '; 1841 print 'output as a mail to andi@splitbrain.org '; 1842 print 'The best way to do this is to save this page in your browser</p>'; 1843 1844 print '<b>$INFO:</b><pre>'; 1845 print_r($nfo); 1846 print '</pre>'; 1847 1848 print '<b>$_SERVER:</b><pre>'; 1849 print_r($_SERVER); 1850 print '</pre>'; 1851 1852 print '<b>$conf:</b><pre>'; 1853 print_r($cnf); 1854 print '</pre>'; 1855 1856 print '<b>DOKU_BASE:</b><pre>'; 1857 print DOKU_BASE; 1858 print '</pre>'; 1859 1860 print '<b>abs DOKU_BASE:</b><pre>'; 1861 print DOKU_URL; 1862 print '</pre>'; 1863 1864 print '<b>rel DOKU_BASE:</b><pre>'; 1865 print dirname($_SERVER['PHP_SELF']).'/'; 1866 print '</pre>'; 1867 1868 print '<b>PHP Version:</b><pre>'; 1869 print phpversion(); 1870 print '</pre>'; 1871 1872 print '<b>locale:</b><pre>'; 1873 print setlocale(LC_ALL,0); 1874 print '</pre>'; 1875 1876 print '<b>encoding:</b><pre>'; 1877 print $lang['encoding']; 1878 print '</pre>'; 1879 1880 if($auth){ 1881 print '<b>Auth backend capabilities:</b><pre>'; 1882 foreach ($auth->getCapabilities() as $cando){ 1883 print ' '.str_pad($cando,16) . ' => ' . (int)$auth->canDo($cando) . NL; 1884 } 1885 print '</pre>'; 1886 } 1887 1888 print '<b>$_SESSION:</b><pre>'; 1889 print_r($ses); 1890 print '</pre>'; 1891 1892 print '<b>Environment:</b><pre>'; 1893 print_r($_ENV); 1894 print '</pre>'; 1895 1896 print '<b>PHP settings:</b><pre>'; 1897 $inis = ini_get_all(); 1898 print_r($inis); 1899 print '</pre>'; 1900 1901 if (function_exists('apache_get_version')) { 1902 $apache['version'] = apache_get_version(); 1903 1904 if (function_exists('apache_get_modules')) { 1905 $apache['modules'] = apache_get_modules(); 1906 } 1907 print '<b>Apache</b><pre>'; 1908 print_r($apache); 1909 print '</pre>'; 1910 } 1911 1912 print '</body></html>'; 1913} 1914 1915/** 1916 * List available Administration Tasks 1917 * 1918 * @author Andreas Gohr <andi@splitbrain.org> 1919 * @author Håkan Sandell <hakan.sandell@home.se> 1920 */ 1921function html_admin(){ 1922 global $ID; 1923 global $INFO; 1924 global $conf; 1925 /** @var DokuWiki_Auth_Plugin $auth */ 1926 global $auth; 1927 1928 // build menu of admin functions from the plugins that handle them 1929 $pluginlist = plugin_list('admin'); 1930 $menu = array(); 1931 foreach ($pluginlist as $p) { 1932 /** @var DokuWiki_Admin_Plugin $obj */ 1933 if(($obj = plugin_load('admin',$p)) === null) continue; 1934 1935 // check permissions 1936 if($obj->forAdminOnly() && !$INFO['isadmin']) continue; 1937 1938 $menu[$p] = array('plugin' => $p, 1939 'prompt' => $obj->getMenuText($conf['lang']), 1940 'sort' => $obj->getMenuSort() 1941 ); 1942 } 1943 1944 // data security check 1945 // simple check if the 'savedir' is relative and accessible when appended to DOKU_URL 1946 // it verifies either: 1947 // 'savedir' has been moved elsewhere, or 1948 // has protection to prevent the webserver serving files from it 1949 if (substr($conf['savedir'],0,2) == './'){ 1950 echo '<a style="border:none; float:right;" 1951 href="http://www.dokuwiki.org/security#web_access_security"> 1952 <img src="'.DOKU_URL.$conf['savedir'].'/security.png" alt="Your data directory seems to be protected properly." 1953 onerror="this.parentNode.style.display=\'none\'" /></a>'; 1954 } 1955 1956 print p_locale_xhtml('admin'); 1957 1958 // Admin Tasks 1959 if($INFO['isadmin']){ 1960 ptln('<ul class="admin_tasks">'); 1961 1962 if($menu['usermanager'] && $auth && $auth->canDo('getUsers')){ 1963 ptln(' <li class="admin_usermanager"><div class="li">'. 1964 '<a href="'.wl($ID, array('do' => 'admin','page' => 'usermanager')).'">'. 1965 $menu['usermanager']['prompt'].'</a></div></li>'); 1966 } 1967 unset($menu['usermanager']); 1968 1969 if($menu['acl']){ 1970 ptln(' <li class="admin_acl"><div class="li">'. 1971 '<a href="'.wl($ID, array('do' => 'admin','page' => 'acl')).'">'. 1972 $menu['acl']['prompt'].'</a></div></li>'); 1973 } 1974 unset($menu['acl']); 1975 1976 if($menu['extension']){ 1977 ptln(' <li class="admin_plugin"><div class="li">'. 1978 '<a href="'.wl($ID, array('do' => 'admin','page' => 'extension')).'">'. 1979 $menu['extension']['prompt'].'</a></div></li>'); 1980 } 1981 unset($menu['extension']); 1982 1983 if($menu['config']){ 1984 ptln(' <li class="admin_config"><div class="li">'. 1985 '<a href="'.wl($ID, array('do' => 'admin','page' => 'config')).'">'. 1986 $menu['config']['prompt'].'</a></div></li>'); 1987 } 1988 unset($menu['config']); 1989 } 1990 ptln('</ul>'); 1991 1992 // Manager Tasks 1993 ptln('<ul class="admin_tasks">'); 1994 1995 if($menu['revert']){ 1996 ptln(' <li class="admin_revert"><div class="li">'. 1997 '<a href="'.wl($ID, array('do' => 'admin','page' => 'revert')).'">'. 1998 $menu['revert']['prompt'].'</a></div></li>'); 1999 } 2000 unset($menu['revert']); 2001 2002 if($menu['popularity']){ 2003 ptln(' <li class="admin_popularity"><div class="li">'. 2004 '<a href="'.wl($ID, array('do' => 'admin','page' => 'popularity')).'">'. 2005 $menu['popularity']['prompt'].'</a></div></li>'); 2006 } 2007 unset($menu['popularity']); 2008 2009 // print DokuWiki version: 2010 ptln('</ul>'); 2011 echo '<div id="admin__version">'; 2012 echo getVersion(); 2013 echo '</div>'; 2014 2015 // print the rest as sorted list 2016 if(count($menu)){ 2017 usort($menu, 'p_sort_modes'); 2018 // output the menu 2019 ptln('<div class="clearer"></div>'); 2020 print p_locale_xhtml('adminplugins'); 2021 ptln('<ul>'); 2022 foreach ($menu as $item) { 2023 if (!$item['prompt']) continue; 2024 ptln(' <li><div class="li"><a href="'.wl($ID, 'do=admin&page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>'); 2025 } 2026 ptln('</ul>'); 2027 } 2028} 2029 2030/** 2031 * Form to request a new password for an existing account 2032 * 2033 * @author Benoit Chesneau <benoit@bchesneau.info> 2034 * @author Andreas Gohr <gohr@cosmocode.de> 2035 */ 2036function html_resendpwd() { 2037 global $lang; 2038 global $conf; 2039 global $INPUT; 2040 2041 $token = preg_replace('/[^a-f0-9]+/','',$INPUT->str('pwauth')); 2042 2043 if(!$conf['autopasswd'] && $token){ 2044 print p_locale_xhtml('resetpwd'); 2045 print '<div class="centeralign">'.NL; 2046 $form = new Doku_Form(array('id' => 'dw__resendpwd')); 2047 $form->startFieldset($lang['btn_resendpwd']); 2048 $form->addHidden('token', $token); 2049 $form->addHidden('do', 'resendpwd'); 2050 2051 $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50'))); 2052 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50'))); 2053 2054 $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd'])); 2055 $form->endFieldset(); 2056 html_form('resendpwd', $form); 2057 print '</div>'.NL; 2058 }else{ 2059 print p_locale_xhtml('resendpwd'); 2060 print '<div class="centeralign">'.NL; 2061 $form = new Doku_Form(array('id' => 'dw__resendpwd')); 2062 $form->startFieldset($lang['resendpwd']); 2063 $form->addHidden('do', 'resendpwd'); 2064 $form->addHidden('save', '1'); 2065 $form->addElement(form_makeTag('br')); 2066 $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block')); 2067 $form->addElement(form_makeTag('br')); 2068 $form->addElement(form_makeTag('br')); 2069 $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd'])); 2070 $form->endFieldset(); 2071 html_form('resendpwd', $form); 2072 print '</div>'.NL; 2073 } 2074} 2075 2076/** 2077 * Return the TOC rendered to XHTML 2078 * 2079 * @author Andreas Gohr <andi@splitbrain.org> 2080 */ 2081function html_TOC($toc){ 2082 if(!count($toc)) return ''; 2083 global $lang; 2084 $out = '<!-- TOC START -->'.DOKU_LF; 2085 $out .= '<div id="dw__toc">'.DOKU_LF; 2086 $out .= '<h3 class="toggle">'; 2087 $out .= $lang['toc']; 2088 $out .= '</h3>'.DOKU_LF; 2089 $out .= '<div>'.DOKU_LF; 2090 $out .= html_buildlist($toc,'toc','html_list_toc','html_li_default',true); 2091 $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF; 2092 $out .= '<!-- TOC END -->'.DOKU_LF; 2093 return $out; 2094} 2095 2096/** 2097 * Callback for html_buildlist 2098 */ 2099function html_list_toc($item){ 2100 if(isset($item['hid'])){ 2101 $link = '#'.$item['hid']; 2102 }else{ 2103 $link = $item['link']; 2104 } 2105 2106 return '<a href="'.$link.'">'.hsc($item['title']).'</a>'; 2107} 2108 2109/** 2110 * Helper function to build TOC items 2111 * 2112 * Returns an array ready to be added to a TOC array 2113 * 2114 * @param string $link - where to link (if $hash set to '#' it's a local anchor) 2115 * @param string $text - what to display in the TOC 2116 * @param int $level - nesting level 2117 * @param string $hash - is prepended to the given $link, set blank if you want full links 2118 * @return array the toc item 2119 */ 2120function html_mktocitem($link, $text, $level, $hash='#'){ 2121 return array( 'link' => $hash.$link, 2122 'title' => $text, 2123 'type' => 'ul', 2124 'level' => $level); 2125} 2126 2127/** 2128 * Output a Doku_Form object. 2129 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT 2130 * 2131 * @author Tom N Harris <tnharris@whoopdedo.org> 2132 * @param string $name The name of the form 2133 * @param Doku_Form $form The form 2134 */ 2135function html_form($name, &$form) { 2136 // Safety check in case the caller forgets. 2137 $form->endFieldset(); 2138 trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false); 2139} 2140 2141/** 2142 * Form print function. 2143 * Just calls printForm() on the data object. 2144 * @param Doku_Form $data The form 2145 */ 2146function html_form_output($data) { 2147 $data->printForm(); 2148} 2149 2150/** 2151 * Embed a flash object in HTML 2152 * 2153 * This will create the needed HTML to embed a flash movie in a cross browser 2154 * compatble way using valid XHTML 2155 * 2156 * The parameters $params, $flashvars and $atts need to be associative arrays. 2157 * No escaping needs to be done for them. The alternative content *has* to be 2158 * escaped because it is used as is. If no alternative content is given 2159 * $lang['noflash'] is used. 2160 * 2161 * @author Andreas Gohr <andi@splitbrain.org> 2162 * @link http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml 2163 * 2164 * @param string $swf - the SWF movie to embed 2165 * @param int $width - width of the flash movie in pixels 2166 * @param int $height - height of the flash movie in pixels 2167 * @param array $params - additional parameters (<param>) 2168 * @param array $flashvars - parameters to be passed in the flashvar parameter 2169 * @param array $atts - additional attributes for the <object> tag 2170 * @param string $alt - alternative content (is NOT automatically escaped!) 2171 * @return string - the XHTML markup 2172 */ 2173function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){ 2174 global $lang; 2175 2176 $out = ''; 2177 2178 // prepare the object attributes 2179 if(is_null($atts)) $atts = array(); 2180 $atts['width'] = (int) $width; 2181 $atts['height'] = (int) $height; 2182 if(!$atts['width']) $atts['width'] = 425; 2183 if(!$atts['height']) $atts['height'] = 350; 2184 2185 // add object attributes for standard compliant browsers 2186 $std = $atts; 2187 $std['type'] = 'application/x-shockwave-flash'; 2188 $std['data'] = $swf; 2189 2190 // add object attributes for IE 2191 $ie = $atts; 2192 $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'; 2193 2194 // open object (with conditional comments) 2195 $out .= '<!--[if !IE]> -->'.NL; 2196 $out .= '<object '.buildAttributes($std).'>'.NL; 2197 $out .= '<!-- <![endif]-->'.NL; 2198 $out .= '<!--[if IE]>'.NL; 2199 $out .= '<object '.buildAttributes($ie).'>'.NL; 2200 $out .= ' <param name="movie" value="'.hsc($swf).'" />'.NL; 2201 $out .= '<!--><!-- -->'.NL; 2202 2203 // print params 2204 if(is_array($params)) foreach($params as $key => $val){ 2205 $out .= ' <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL; 2206 } 2207 2208 // add flashvars 2209 if(is_array($flashvars)){ 2210 $out .= ' <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL; 2211 } 2212 2213 // alternative content 2214 if($alt){ 2215 $out .= $alt.NL; 2216 }else{ 2217 $out .= $lang['noflash'].NL; 2218 } 2219 2220 // finish 2221 $out .= '</object>'.NL; 2222 $out .= '<!-- <![endif]-->'.NL; 2223 2224 return $out; 2225} 2226 2227/** 2228 * Prints HTML code for the given tab structure 2229 * 2230 * @param array $tabs tab structure 2231 * @param string $current_tab the current tab id 2232 */ 2233function html_tabs($tabs, $current_tab = null) { 2234 echo '<ul class="tabs">'.NL; 2235 2236 foreach($tabs as $id => $tab) { 2237 html_tab($tab['href'], $tab['caption'], $id === $current_tab); 2238 } 2239 2240 echo '</ul>'.NL; 2241} 2242/** 2243 * Prints a single tab 2244 * 2245 * @author Kate Arzamastseva <pshns@ukr.net> 2246 * @author Adrian Lang <mail@adrianlang.de> 2247 * 2248 * @param string $href - tab href 2249 * @param string $caption - tab caption 2250 * @param boolean $selected - is tab selected 2251 */ 2252 2253function html_tab($href, $caption, $selected=false) { 2254 $tab = '<li>'; 2255 if ($selected) { 2256 $tab .= '<strong>'; 2257 } else { 2258 $tab .= '<a href="' . hsc($href) . '">'; 2259 } 2260 $tab .= hsc($caption) 2261 . '</' . ($selected ? 'strong' : 'a') . '>' 2262 . '</li>'.NL; 2263 echo $tab; 2264} 2265 2266