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