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 static $xhtml_renderer = null; 23 if(is_null($xhtml_renderer)){ 24 $xhtml_renderer = p_get_renderer('xhtml'); 25 } 26 27 return $xhtml_renderer->internallink($id,$name,$search,true,'navigation'); 28} 29 30/** 31 * Helps building long attribute lists 32 * 33 * @deprecated Use buildAttributes instead 34 * @author Andreas Gohr <andi@splitbrain.org> 35 */ 36function html_attbuild($attributes){ 37 $ret = ''; 38 foreach ( $attributes as $key => $value ) { 39 $ret .= $key.'="'.formText($value).'" '; 40 } 41 return trim($ret); 42} 43 44/** 45 * The loginform 46 * 47 * @author Andreas Gohr <andi@splitbrain.org> 48 */ 49function html_login(){ 50 global $lang; 51 global $conf; 52 global $ID; 53 global $INPUT; 54 55 print p_locale_xhtml('login'); 56 print '<div class="centeralign">'.NL; 57 $form = new Doku_Form(array('id' => 'dw__login')); 58 $form->startFieldset($lang['btn_login']); 59 $form->addHidden('id', $ID); 60 $form->addHidden('do', 'login'); 61 $form->addElement(form_makeTextField('u', ((!$INPUT->bool('http_credentials')) ? $INPUT->str('u') : ''), $lang['user'], 'focus__this', 'block')); 62 $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block')); 63 if($conf['rememberme']) { 64 $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple')); 65 } 66 $form->addElement(form_makeButton('submit', '', $lang['btn_login'])); 67 $form->endFieldset(); 68 69 if(actionOK('register')){ 70 $form->addElement('<p>'.$lang['reghere'].': '.tpl_actionlink('register','','','',true).'</p>'); 71 } 72 73 if (actionOK('resendpwd')) { 74 $form->addElement('<p>'.$lang['pwdforget'].': '.tpl_actionlink('resendpwd','','','',true).'</p>'); 75 } 76 77 html_form('login', $form); 78 print '</div>'.NL; 79} 80 81/** 82 * inserts section edit buttons if wanted or removes the markers 83 * 84 * @author Andreas Gohr <andi@splitbrain.org> 85 */ 86function html_secedit($text,$show=true){ 87 global $INFO; 88 89 $regexp = '#<!-- EDIT(\d+) ([A-Z_]+) (?:"([^"]*)" )?\[(\d+-\d*)\] -->#'; 90 91 if(!$INFO['writable'] || !$show || $INFO['rev']){ 92 return preg_replace($regexp,'',$text); 93 } 94 95 return preg_replace_callback($regexp, 96 'html_secedit_button', $text); 97} 98 99/** 100 * prepares section edit button data for event triggering 101 * used as a callback in html_secedit 102 * 103 * @triggers HTML_SECEDIT_BUTTON 104 * @author Andreas Gohr <andi@splitbrain.org> 105 */ 106function html_secedit_button($matches){ 107 $data = array('secid' => $matches[1], 108 'target' => strtolower($matches[2]), 109 'range' => $matches[count($matches) - 1]); 110 if (count($matches) === 5) { 111 $data['name'] = $matches[3]; 112 } 113 114 return trigger_event('HTML_SECEDIT_BUTTON', $data, 115 'html_secedit_get_button'); 116} 117 118/** 119 * prints a section editing button 120 * used as default action form HTML_SECEDIT_BUTTON 121 * 122 * @author Adrian Lang <lang@cosmocode.de> 123 */ 124function html_secedit_get_button($data) { 125 global $ID; 126 global $INFO; 127 128 if (!isset($data['name']) || $data['name'] === '') return ''; 129 130 $name = $data['name']; 131 unset($data['name']); 132 133 $secid = $data['secid']; 134 unset($data['secid']); 135 136 return "<div class='secedit editbutton_" . $data['target'] . 137 " editbutton_" . $secid . "'>" . 138 html_btn('secedit', $ID, '', 139 array_merge(array('do' => 'edit', 140 'rev' => $INFO['lastmod'], 141 'summary' => '['.$name.'] '), $data), 142 'post', $name) . '</div>'; 143} 144 145/** 146 * Just the back to top button (in its own form) 147 * 148 * @author Andreas Gohr <andi@splitbrain.org> 149 */ 150function html_topbtn(){ 151 global $lang; 152 153 $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>'; 154 155 return $ret; 156} 157 158/** 159 * Displays a button (using its own form) 160 * If tooltip exists, the access key tooltip is replaced. 161 * 162 * @author Andreas Gohr <andi@splitbrain.org> 163 */ 164function html_btn($name,$id,$akey,$params,$method='get',$tooltip='',$label=false){ 165 global $conf; 166 global $lang; 167 168 if (!$label) 169 $label = $lang['btn_'.$name]; 170 171 $ret = ''; 172 173 //filter id (without urlencoding) 174 $id = idfilter($id,false); 175 176 //make nice URLs even for buttons 177 if($conf['userewrite'] == 2){ 178 $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id; 179 }elseif($conf['userewrite']){ 180 $script = DOKU_BASE.$id; 181 }else{ 182 $script = DOKU_BASE.DOKU_SCRIPT; 183 $params['id'] = $id; 184 } 185 186 $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">'; 187 188 if(is_array($params)){ 189 reset($params); 190 while (list($key, $val) = each($params)) { 191 $ret .= '<input type="hidden" name="'.$key.'" '; 192 $ret .= 'value="'.htmlspecialchars($val).'" />'; 193 } 194 } 195 196 if ($tooltip!='') { 197 $tip = htmlspecialchars($tooltip); 198 }else{ 199 $tip = htmlspecialchars($label); 200 } 201 202 $ret .= '<input type="submit" value="'.hsc($label).'" class="button" '; 203 if($akey){ 204 $tip .= ' ['.strtoupper($akey).']'; 205 $ret .= 'accesskey="'.$akey.'" '; 206 } 207 $ret .= 'title="'.$tip.'" '; 208 $ret .= '/>'; 209 $ret .= '</div></form>'; 210 211 return $ret; 212} 213 214/** 215 * show a wiki page 216 * 217 * @author Andreas Gohr <andi@splitbrain.org> 218 */ 219function html_show($txt=null){ 220 global $ID; 221 global $REV; 222 global $HIGH; 223 global $INFO; 224 //disable section editing for old revisions or in preview 225 if($txt || $REV){ 226 $secedit = false; 227 }else{ 228 $secedit = true; 229 } 230 231 if (!is_null($txt)){ 232 //PreviewHeader 233 echo '<br id="scroll__here" />'; 234 echo p_locale_xhtml('preview'); 235 echo '<div class="preview"><div class="pad">'; 236 $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit); 237 if($INFO['prependTOC']) $html = tpl_toc(true).$html; 238 echo $html; 239 echo '<div class="clearer"></div>'; 240 echo '</div></div>'; 241 242 }else{ 243 if ($REV) print p_locale_xhtml('showrev'); 244 $html = p_wiki_xhtml($ID,$REV,true); 245 $html = html_secedit($html,$secedit); 246 if($INFO['prependTOC']) $html = tpl_toc(true).$html; 247 $html = html_hilight($html,$HIGH); 248 echo $html; 249 } 250} 251 252/** 253 * ask the user about how to handle an exisiting draft 254 * 255 * @author Andreas Gohr <andi@splitbrain.org> 256 */ 257function html_draft(){ 258 global $INFO; 259 global $ID; 260 global $lang; 261 $draft = unserialize(io_readFile($INFO['draft'],false)); 262 $text = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true)); 263 264 print p_locale_xhtml('draft'); 265 $form = new Doku_Form(array('id' => 'dw__editform')); 266 $form->addHidden('id', $ID); 267 $form->addHidden('date', $draft['date']); 268 $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly'))); 269 $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status'))); 270 $form->addElement($lang['draftdate'].' '. dformat(filemtime($INFO['draft']))); 271 $form->addElement(form_makeCloseTag('div')); 272 $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1'))); 273 $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2'))); 274 $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3'))); 275 html_form('draft', $form); 276} 277 278/** 279 * Highlights searchqueries in HTML code 280 * 281 * @author Andreas Gohr <andi@splitbrain.org> 282 * @author Harry Fuecks <hfuecks@gmail.com> 283 */ 284function html_hilight($html,$phrases){ 285 $phrases = (array) $phrases; 286 $phrases = array_map('preg_quote_cb', $phrases); 287 $phrases = array_map('ft_snippet_re_preprocess', $phrases); 288 $phrases = array_filter($phrases); 289 $regex = join('|',$phrases); 290 291 if ($regex === '') return $html; 292 if (!utf8_check($regex)) return $html; 293 $html = @preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html); 294 return $html; 295} 296 297/** 298 * Callback used by html_hilight() 299 * 300 * @author Harry Fuecks <hfuecks@gmail.com> 301 */ 302function html_hilight_callback($m) { 303 $hlight = unslash($m[0]); 304 if ( !isset($m[2])) { 305 $hlight = '<span class="search_hit">'.$hlight.'</span>'; 306 } 307 return $hlight; 308} 309 310/** 311 * Run a search and display the result 312 * 313 * @author Andreas Gohr <andi@splitbrain.org> 314 */ 315function html_search(){ 316 global $QUERY; 317 global $lang; 318 319 $intro = p_locale_xhtml('searchpage'); 320 // allow use of placeholder in search intro 321 $intro = str_replace( 322 array('@QUERY@','@SEARCH@'), 323 array(hsc(rawurlencode($QUERY)),hsc($QUERY)), 324 $intro); 325 echo $intro; 326 flush(); 327 328 //show progressbar 329 print '<div id="dw__loading">'.NL; 330 print '<script type="text/javascript">/*<![CDATA[*/'.NL; 331 print 'showLoadBar();'.NL; 332 print '/*!]]>*/</script>'.NL; 333 print '</div>'.NL; 334 flush(); 335 336 //do quick pagesearch 337 $data = ft_pageLookup($QUERY,true,useHeading('navigation')); 338 if(count($data)){ 339 print '<div class="search_quickresult">'; 340 print '<h3>'.$lang['quickhits'].':</h3>'; 341 print '<ul class="search_quickhits">'; 342 foreach($data as $id => $title){ 343 print '<li> '; 344 if (useHeading('navigation')) { 345 $name = $title; 346 }else{ 347 $ns = getNS($id); 348 if($ns){ 349 $name = shorten(noNS($id), ' ('.$ns.')',30); 350 }else{ 351 $name = $id; 352 } 353 } 354 print html_wikilink(':'.$id,$name); 355 print '</li> '; 356 } 357 print '</ul> '; 358 //clear float (see http://www.complexspiral.com/publications/containing-floats/) 359 print '<div class="clearer"></div>'; 360 print '</div>'; 361 } 362 flush(); 363 364 //do fulltext search 365 $data = ft_pageSearch($QUERY,$regex); 366 if(count($data)){ 367 print '<dl class="search_results">'; 368 $num = 1; 369 foreach($data as $id => $cnt){ 370 print '<dt>'; 371 print html_wikilink(':'.$id,useHeading('navigation')?null:$id,$regex); 372 if($cnt !== 0){ 373 print ': '.$cnt.' '.$lang['hits'].''; 374 } 375 print '</dt>'; 376 if($cnt !== 0){ 377 if($num < FT_SNIPPET_NUMBER){ // create snippets for the first number of matches only 378 print '<dd>'.ft_snippet($id,$regex).'</dd>'; 379 } 380 $num++; 381 } 382 flush(); 383 } 384 print '</dl>'; 385 }else{ 386 print '<div class="nothing">'.$lang['nothingfound'].'</div>'; 387 } 388 389 //hide progressbar 390 print '<script type="text/javascript">/*<![CDATA[*/'.NL; 391 print 'hideLoadBar("dw__loading");'.NL; 392 print '/*!]]>*/</script>'.NL; 393 flush(); 394} 395 396/** 397 * Display error on locked pages 398 * 399 * @author Andreas Gohr <andi@splitbrain.org> 400 */ 401function html_locked(){ 402 global $ID; 403 global $conf; 404 global $lang; 405 global $INFO; 406 407 $locktime = filemtime(wikiLockFN($ID)); 408 $expire = dformat($locktime + $conf['locktime']); 409 $min = round(($conf['locktime'] - (time() - $locktime) )/60); 410 411 print p_locale_xhtml('locked'); 412 print '<ul>'; 413 print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.editorinfo($INFO['locked']).'</div></li>'; 414 print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>'; 415 print '</ul>'; 416} 417 418/** 419 * list old revisions 420 * 421 * @author Andreas Gohr <andi@splitbrain.org> 422 * @author Ben Coburn <btcoburn@silicodon.net> 423 * @author Kate Arzamastseva <pshns@ukr.net> 424 */ 425function html_revisions($first=0, $media_id = false){ 426 global $ID; 427 global $INFO; 428 global $conf; 429 global $lang; 430 $id = $ID; 431 /* we need to get one additionally log entry to be able to 432 * decide if this is the last page or is there another one. 433 * see html_recent() 434 */ 435 if (!$media_id) $revisions = getRevisions($ID, $first, $conf['recent']+1); 436 else { 437 $revisions = getRevisions($media_id, $first, $conf['recent']+1, 8192, true); 438 $id = $media_id; 439 } 440 441 if(count($revisions)==0 && $first!=0){ 442 $first=0; 443 if (!$media_id) $revisions = getRevisions($ID, $first, $conf['recent']+1); 444 else $revisions = getRevisions($media_id, $first, $conf['recent']+1, 8192, true); 445 } 446 $hasNext = false; 447 if (count($revisions)>$conf['recent']) { 448 $hasNext = true; 449 array_pop($revisions); // remove extra log entry 450 } 451 452 if (!$media_id) $date = dformat($INFO['lastmod']); 453 else $date = dformat(@filemtime(mediaFN($id))); 454 455 if (!$media_id) print p_locale_xhtml('revisions'); 456 457 $params = array('id' => 'page__revisions', 'class' => 'changes'); 458 if ($media_id) $params['action'] = media_managerURL(array('image' => $media_id), '&'); 459 460 $form = new Doku_Form($params); 461 $form->addElement(form_makeOpenTag('ul')); 462 463 if (!$media_id) $exists = $INFO['exists']; 464 else $exists = @file_exists(mediaFN($id)); 465 466 $display_name = (!$media_id && useHeading('navigation')) ? hsc(p_get_first_heading($id)) : $id; 467 468 if($exists && $first==0){ 469 if (!$media_id && isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) 470 $form->addElement(form_makeOpenTag('li', array('class' => 'minor'))); 471 else 472 $form->addElement(form_makeOpenTag('li')); 473 $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); 474 $form->addElement(form_makeTag('input', array( 475 'type' => 'checkbox', 476 'name' => 'rev2[]', 477 'value' => 'current'))); 478 479 $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); 480 $form->addElement($date); 481 $form->addElement(form_makeCloseTag('span')); 482 483 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />'); 484 485 if (!$media_id) $href = wl($id); 486 else $href = media_managerURL(array('image' => $id, 'tab_details' => 'view'), '&'); 487 $form->addElement(form_makeOpenTag('a', array( 488 'class' => 'wikilink1', 489 'href' => $href))); 490 $form->addElement($display_name); 491 $form->addElement(form_makeCloseTag('a')); 492 493 if ($media_id) $form->addElement(form_makeOpenTag('div')); 494 495 if (!$media_id) { 496 $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); 497 $form->addElement(' – '); 498 $form->addElement(htmlspecialchars($INFO['sum'])); 499 $form->addElement(form_makeCloseTag('span')); 500 } 501 502 $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); 503 if (!$media_id) $editor = $INFO['editor']; 504 else { 505 $revinfo = getRevisionInfo($id, @filemtime(fullpath(mediaFN($id))), 1024, true); 506 if($revinfo['user']){ 507 $editor = $revinfo['user']; 508 }else{ 509 $editor = $revinfo['ip']; 510 } 511 } 512 $form->addElement((empty($editor))?('('.$lang['external_edit'].')'):editorinfo($editor)); 513 $form->addElement(form_makeCloseTag('span')); 514 515 $form->addElement('('.$lang['current'].')'); 516 517 if ($media_id) $form->addElement(form_makeCloseTag('div')); 518 519 $form->addElement(form_makeCloseTag('div')); 520 $form->addElement(form_makeCloseTag('li')); 521 } 522 523 foreach($revisions as $rev){ 524 $date = dformat($rev); 525 if (!$media_id) { 526 $info = getRevisionInfo($id,$rev,true); 527 $exists = page_exists($id,$rev); 528 } else { 529 $info = getRevisionInfo($id,$rev,true,true); 530 $exists = @file_exists(mediaFN($id,$rev)); 531 } 532 533 if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) 534 $form->addElement(form_makeOpenTag('li', array('class' => 'minor'))); 535 else 536 $form->addElement(form_makeOpenTag('li')); 537 $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); 538 if($exists){ 539 $form->addElement(form_makeTag('input', array( 540 'type' => 'checkbox', 541 'name' => 'rev2[]', 542 'value' => $rev))); 543 }else{ 544 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />'); 545 } 546 547 $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); 548 $form->addElement($date); 549 $form->addElement(form_makeCloseTag('span')); 550 551 if($exists){ 552 if (!$media_id) $href = wl($id,"rev=$rev,do=diff", false, '&'); 553 else $href = media_managerURL(array('image' => $id, 'rev' => $rev, 'mediado' => 'diff'), '&'); 554 $form->addElement(form_makeOpenTag('a', array('href' => $href, 'class' => 'diff_link'))); 555 $form->addElement(form_makeTag('img', array( 556 'src' => DOKU_BASE.'lib/images/diff.png', 557 'width' => 15, 558 'height' => 11, 559 'title' => $lang['diff'], 560 'alt' => $lang['diff']))); 561 $form->addElement(form_makeCloseTag('a')); 562 if (!$media_id) $href = wl($id,"rev=$rev",false,'&'); 563 else $href = media_managerURL(array('image' => $id, 'tab_details' => 'view', 'rev' => $rev), '&'); 564 $form->addElement(form_makeOpenTag('a', array('href' => $href, 'class' => 'wikilink1'))); 565 $form->addElement($display_name); 566 $form->addElement(form_makeCloseTag('a')); 567 }else{ 568 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />'); 569 $form->addElement($display_name); 570 } 571 572 if ($media_id) $form->addElement(form_makeOpenTag('div')); 573 574 if ($info['sum']) { 575 $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); 576 if (!$media_id) $form->addElement(' – '); 577 $form->addElement(htmlspecialchars($info['sum'])); 578 $form->addElement(form_makeCloseTag('span')); 579 } 580 581 $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); 582 if($info['user']){ 583 $form->addElement(editorinfo($info['user'])); 584 if(auth_ismanager()){ 585 $form->addElement(' ('.$info['ip'].')'); 586 } 587 }else{ 588 $form->addElement($info['ip']); 589 } 590 $form->addElement(form_makeCloseTag('span')); 591 592 if ($media_id) $form->addElement(form_makeCloseTag('div')); 593 594 $form->addElement(form_makeCloseTag('div')); 595 $form->addElement(form_makeCloseTag('li')); 596 } 597 $form->addElement(form_makeCloseTag('ul')); 598 if (!$media_id) { 599 $form->addElement(form_makeButton('submit', 'diff', $lang['diff2'])); 600 } else { 601 $form->addHidden('mediado', 'diff'); 602 $form->addElement(form_makeButton('submit', '', $lang['diff2'])); 603 } 604 html_form('revisions', $form); 605 606 print '<div class="pagenav">'; 607 $last = $first + $conf['recent']; 608 if ($first > 0) { 609 $first -= $conf['recent']; 610 if ($first < 0) $first = 0; 611 print '<div class="pagenav-prev">'; 612 if ($media_id) { 613 print html_btn('newer',$media_id,"p",media_managerURL(array('first' => $first), '&', false, true)); 614 } else { 615 print html_btn('newer',$id,"p",array('do' => 'revisions', 'first' => $first)); 616 } 617 print '</div>'; 618 } 619 if ($hasNext) { 620 print '<div class="pagenav-next">'; 621 if ($media_id) { 622 print html_btn('older',$media_id,"n",media_managerURL(array('first' => $last), '&', false, true)); 623 } else { 624 print html_btn('older',$id,"n",array('do' => 'revisions', 'first' => $last)); 625 } 626 print '</div>'; 627 } 628 print '</div>'; 629 630} 631 632/** 633 * display recent changes 634 * 635 * @author Andreas Gohr <andi@splitbrain.org> 636 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 637 * @author Ben Coburn <btcoburn@silicodon.net> 638 * @author Kate Arzamastseva <pshns@ukr.net> 639 */ 640function html_recent($first=0, $show_changes='both'){ 641 global $conf; 642 global $lang; 643 global $ID; 644 /* we need to get one additionally log entry to be able to 645 * decide if this is the last page or is there another one. 646 * This is the cheapest solution to get this information. 647 */ 648 $flags = 0; 649 if ($show_changes == 'mediafiles' && $conf['mediarevisions']) { 650 $flags = RECENTS_MEDIA_CHANGES; 651 } elseif ($show_changes == 'pages') { 652 $flags = 0; 653 } elseif ($conf['mediarevisions']) { 654 $show_changes = 'both'; 655 $flags = RECENTS_MEDIA_PAGES_MIXED; 656 } 657 658 $recents = getRecents($first,$conf['recent'] + 1,getNS($ID),$flags); 659 if(count($recents) == 0 && $first != 0){ 660 $first=0; 661 $recents = getRecents($first,$conf['recent'] + 1,getNS($ID),$flags); 662 } 663 $hasNext = false; 664 if (count($recents)>$conf['recent']) { 665 $hasNext = true; 666 array_pop($recents); // remove extra log entry 667 } 668 669 print p_locale_xhtml('recent'); 670 671 if (getNS($ID) != '') 672 print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>'; 673 674 $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET', 'class' => 'changes')); 675 $form->addHidden('sectok', null); 676 $form->addHidden('do', 'recent'); 677 $form->addHidden('id', $ID); 678 679 if ($conf['mediarevisions']) { 680 $form->addElement('<div class="changeType">'); 681 $form->addElement(form_makeListboxField( 682 'show_changes', 683 array( 684 'pages' => $lang['pages_changes'], 685 'mediafiles' => $lang['media_changes'], 686 'both' => $lang['both_changes']), 687 $show_changes, 688 $lang['changes_type'], 689 '','', 690 array('class'=>'quickselect'))); 691 692 $form->addElement(form_makeButton('submit', 'recent', $lang['btn_apply'])); 693 $form->addElement('</div>'); 694 } 695 696 $form->addElement(form_makeOpenTag('ul')); 697 698 foreach($recents as $recent){ 699 $date = dformat($recent['date']); 700 if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) 701 $form->addElement(form_makeOpenTag('li', array('class' => 'minor'))); 702 else 703 $form->addElement(form_makeOpenTag('li')); 704 705 $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); 706 707 if ($recent['media']) { 708 $form->addElement(media_printicon($recent['id'])); 709 } else { 710 $icon = DOKU_BASE.'lib/images/fileicons/file.png'; 711 $form->addElement('<img src="'.$icon.'" alt="'.$recent['id'].'" class="icon" />'); 712 } 713 714 $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); 715 $form->addElement($date); 716 $form->addElement(form_makeCloseTag('span')); 717 718 $diff = false; 719 $href = ''; 720 721 if ($recent['media']) { 722 $diff = (count(getRevisions($recent['id'], 0, 1, 8192, true)) && @file_exists(mediaFN($recent['id']))); 723 if ($diff) { 724 $href = media_managerURL(array('tab_details' => 'history', 725 'mediado' => 'diff', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&'); 726 } 727 } else { 728 $href = wl($recent['id'],"do=diff", false, '&'); 729 } 730 731 if ($recent['media'] && !$diff) { 732 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />'); 733 } else { 734 $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => $href))); 735 $form->addElement(form_makeTag('img', array( 736 'src' => DOKU_BASE.'lib/images/diff.png', 737 'width' => 15, 738 'height'=> 11, 739 'title' => $lang['diff'], 740 'alt' => $lang['diff'] 741 ))); 742 $form->addElement(form_makeCloseTag('a')); 743 } 744 745 if ($recent['media']) { 746 $href = media_managerURL(array('tab_details' => 'history', 747 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&'); 748 } else { 749 $href = wl($recent['id'],"do=revisions",false,'&'); 750 } 751 $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => $href))); 752 $form->addElement(form_makeTag('img', array( 753 'src' => DOKU_BASE.'lib/images/history.png', 754 'width' => 12, 755 'height'=> 14, 756 'title' => $lang['btn_revs'], 757 'alt' => $lang['btn_revs'] 758 ))); 759 $form->addElement(form_makeCloseTag('a')); 760 761 if ($recent['media']) { 762 $href = media_managerURL(array('tab_details' => 'view', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&'); 763 $class = (file_exists(mediaFN($recent['id']))) ? 'wikilink1' : $class = 'wikilink2'; 764 $form->addElement(form_makeOpenTag('a', array('class' => $class, 'href' => $href))); 765 $form->addElement($recent['id']); 766 $form->addElement(form_makeCloseTag('a')); 767 } else { 768 $form->addElement(html_wikilink(':'.$recent['id'],useHeading('navigation')?null:$recent['id'])); 769 } 770 $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); 771 $form->addElement(' – '.htmlspecialchars($recent['sum'])); 772 $form->addElement(form_makeCloseTag('span')); 773 774 $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); 775 if($recent['user']){ 776 $form->addElement(editorinfo($recent['user'])); 777 if(auth_ismanager()){ 778 $form->addElement(' ('.$recent['ip'].')'); 779 } 780 }else{ 781 $form->addElement($recent['ip']); 782 } 783 $form->addElement(form_makeCloseTag('span')); 784 785 $form->addElement(form_makeCloseTag('div')); 786 $form->addElement(form_makeCloseTag('li')); 787 } 788 $form->addElement(form_makeCloseTag('ul')); 789 790 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav'))); 791 $last = $first + $conf['recent']; 792 if ($first > 0) { 793 $first -= $conf['recent']; 794 if ($first < 0) $first = 0; 795 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev'))); 796 $form->addElement(form_makeTag('input', array( 797 'type' => 'submit', 798 'name' => 'first['.$first.']', 799 'value' => $lang['btn_newer'], 800 'accesskey' => 'n', 801 'title' => $lang['btn_newer'].' [N]', 802 'class' => 'button show' 803 ))); 804 $form->addElement(form_makeCloseTag('div')); 805 } 806 if ($hasNext) { 807 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next'))); 808 $form->addElement(form_makeTag('input', array( 809 'type' => 'submit', 810 'name' => 'first['.$last.']', 811 'value' => $lang['btn_older'], 812 'accesskey' => 'p', 813 'title' => $lang['btn_older'].' [P]', 814 'class' => 'button show' 815 ))); 816 $form->addElement(form_makeCloseTag('div')); 817 } 818 $form->addElement(form_makeCloseTag('div')); 819 html_form('recent', $form); 820} 821 822/** 823 * Display page index 824 * 825 * @author Andreas Gohr <andi@splitbrain.org> 826 */ 827function html_index($ns){ 828 global $conf; 829 global $ID; 830 $ns = cleanID($ns); 831 #fixme use appropriate function 832 if(empty($ns)){ 833 $ns = dirname(str_replace(':','/',$ID)); 834 if($ns == '.') $ns =''; 835 } 836 $ns = utf8_encodeFN(str_replace(':','/',$ns)); 837 838 echo p_locale_xhtml('index'); 839 echo '<div id="index__tree">'; 840 841 $data = array(); 842 search($data,$conf['datadir'],'search_index',array('ns' => $ns)); 843 echo html_buildlist($data,'idx','html_list_index','html_li_index'); 844 845 echo '</div>'; 846} 847 848/** 849 * Index item formatter 850 * 851 * User function for html_buildlist() 852 * 853 * @author Andreas Gohr <andi@splitbrain.org> 854 */ 855function html_list_index($item){ 856 global $ID; 857 $ret = ''; 858 $base = ':'.$item['id']; 859 $base = substr($base,strrpos($base,':')+1); 860 if($item['type']=='d'){ 861 $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" class="idx_dir"><strong>'; 862 $ret .= $base; 863 $ret .= '</strong></a>'; 864 }else{ 865 $ret .= html_wikilink(':'.$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 * @return array HTML snippets for diff header 1005 */ 1006function html_diff_head($l_rev, $r_rev, $id = null, $media = false) { 1007 global $lang; 1008 if ($id === null) { 1009 global $ID; 1010 $id = $ID; 1011 } 1012 $media_or_wikiFN = $media ? 'mediaFN' : 'wikiFN'; 1013 $ml_or_wl = $media ? 'ml' : 'wl'; 1014 $l_minor = $r_minor = ''; 1015 1016 if(!$l_rev){ 1017 $l_head = '—'; 1018 }else{ 1019 $l_info = getRevisionInfo($id,$l_rev,true, $media); 1020 if($l_info['user']){ 1021 $l_user = editorinfo($l_info['user']); 1022 if(auth_ismanager()) $l_user .= ' ('.$l_info['ip'].')'; 1023 } else { 1024 $l_user = $l_info['ip']; 1025 } 1026 $l_user = '<span class="user">'.$l_user.'</span>'; 1027 $l_sum = ($l_info['sum']) ? '<span class="sum">'.hsc($l_info['sum']).'</span>' : ''; 1028 if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"'; 1029 1030 $l_head_title = ($media) ? dformat($l_rev) : $id.' ['.dformat($l_rev).']'; 1031 $l_head = '<a class="wikilink1" href="'.$ml_or_wl($id,"rev=$l_rev").'">'. 1032 $l_head_title.'</a>'. 1033 '<br />'.$l_user.' '.$l_sum; 1034 } 1035 1036 if($r_rev){ 1037 $r_info = getRevisionInfo($id,$r_rev,true, $media); 1038 if($r_info['user']){ 1039 $r_user = editorinfo($r_info['user']); 1040 if(auth_ismanager()) $r_user .= ' ('.$r_info['ip'].')'; 1041 } else { 1042 $r_user = $r_info['ip']; 1043 } 1044 $r_user = '<span class="user">'.$r_user.'</span>'; 1045 $r_sum = ($r_info['sum']) ? '<span class="sum">'.hsc($r_info['sum']).'</span>' : ''; 1046 if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"'; 1047 1048 $r_head_title = ($media) ? dformat($r_rev) : $id.' ['.dformat($r_rev).']'; 1049 $r_head = '<a class="wikilink1" href="'.$ml_or_wl($id,"rev=$r_rev").'">'. 1050 $r_head_title.'</a>'. 1051 '<br />'.$r_user.' '.$r_sum; 1052 }elseif($_rev = @filemtime($media_or_wikiFN($id))){ 1053 $_info = getRevisionInfo($id,$_rev,true, $media); 1054 if($_info['user']){ 1055 $_user = editorinfo($_info['user']); 1056 if(auth_ismanager()) $_user .= ' ('.$_info['ip'].')'; 1057 } else { 1058 $_user = $_info['ip']; 1059 } 1060 $_user = '<span class="user">'.$_user.'</span>'; 1061 $_sum = ($_info['sum']) ? '<span class="sum">'.hsc($_info['sum']).'</span>' : ''; 1062 if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"'; 1063 1064 $r_head_title = ($media) ? dformat($_rev) : $id.' ['.dformat($_rev).']'; 1065 $r_head = '<a class="wikilink1" href="'.$ml_or_wl($id).'">'. 1066 $r_head_title.'</a> '. 1067 '('.$lang['current'].')'. 1068 '<br />'.$_user.' '.$_sum; 1069 }else{ 1070 $r_head = '— ('.$lang['current'].')'; 1071 } 1072 1073 return array($l_head, $r_head, $l_minor, $r_minor); 1074} 1075 1076/** 1077 * show diff 1078 * 1079 * @author Andreas Gohr <andi@splitbrain.org> 1080 * @param string $text - compare with this text with most current version 1081 * @param bool $intro - display the intro text 1082 * @param string $type type of the diff (inline or sidebyside) 1083 */ 1084function html_diff($text='',$intro=true,$type=null){ 1085 global $ID; 1086 global $REV; 1087 global $lang; 1088 global $INPUT; 1089 1090 if(!$type) $type = $INPUT->str('difftype'); 1091 if($type != 'inline') $type = 'sidebyside'; 1092 1093 // we're trying to be clever here, revisions to compare can be either 1094 // given as rev and rev2 parameters, with rev2 being optional. Or in an 1095 // array in rev2. 1096 $rev1 = $REV; 1097 1098 $rev2 = $INPUT->ref('rev2'); 1099 if(is_array($rev2)){ 1100 $rev1 = (int) $rev2[0]; 1101 $rev2 = (int) $rev2[1]; 1102 1103 if(!$rev1){ 1104 $rev1 = $rev2; 1105 unset($rev2); 1106 } 1107 }else{ 1108 $rev2 = $INPUT->int('rev2'); 1109 } 1110 1111 $r_minor = ''; 1112 $l_minor = ''; 1113 1114 if($text){ // compare text to the most current revision 1115 $l_rev = ''; 1116 $l_text = rawWiki($ID,''); 1117 $l_head = '<a class="wikilink1" href="'.wl($ID).'">'. 1118 $ID.' '.dformat((int) @filemtime(wikiFN($ID))).'</a> '. 1119 $lang['current']; 1120 1121 $r_rev = ''; 1122 $r_text = cleanText($text); 1123 $r_head = $lang['yours']; 1124 }else{ 1125 if($rev1 && isset($rev2) && $rev2){ // two specific revisions wanted 1126 // make sure order is correct (older on the left) 1127 if($rev1 < $rev2){ 1128 $l_rev = $rev1; 1129 $r_rev = $rev2; 1130 }else{ 1131 $l_rev = $rev2; 1132 $r_rev = $rev1; 1133 } 1134 }elseif($rev1){ // single revision given, compare to current 1135 $r_rev = ''; 1136 $l_rev = $rev1; 1137 }else{ // no revision was given, compare previous to current 1138 $r_rev = ''; 1139 $revs = getRevisions($ID, 0, 1); 1140 $l_rev = $revs[0]; 1141 $REV = $l_rev; // store revision back in $REV 1142 } 1143 1144 // when both revisions are empty then the page was created just now 1145 if(!$l_rev && !$r_rev){ 1146 $l_text = ''; 1147 }else{ 1148 $l_text = rawWiki($ID,$l_rev); 1149 } 1150 $r_text = rawWiki($ID,$r_rev); 1151 1152 list($l_head, $r_head, $l_minor, $r_minor) = html_diff_head($l_rev, $r_rev); 1153 } 1154 1155 $df = new Diff(explode("\n",htmlspecialchars($l_text)), 1156 explode("\n",htmlspecialchars($r_text))); 1157 1158 if($type == 'inline'){ 1159 $tdf = new InlineDiffFormatter(); 1160 } else { 1161 $tdf = new TableDiffFormatter(); 1162 } 1163 1164 if($intro) print p_locale_xhtml('diff'); 1165 1166 if (!$text) { 1167 ptln('<div class="diffoptions">'); 1168 1169 $form = new Doku_Form(array('action'=>wl())); 1170 $form->addHidden('id',$ID); 1171 $form->addHidden('rev2[0]',$l_rev); 1172 $form->addHidden('rev2[1]',$r_rev); 1173 $form->addHidden('do','diff'); 1174 $form->addElement(form_makeListboxField( 1175 'difftype', 1176 array( 1177 'sidebyside' => $lang['diff_side'], 1178 'inline' => $lang['diff_inline']), 1179 $type, 1180 $lang['diff_type'], 1181 '','', 1182 array('class'=>'quickselect'))); 1183 $form->addElement(form_makeButton('submit', 'diff','Go')); 1184 $form->printForm(); 1185 1186 $diffurl = wl($ID, array( 1187 'do' => 'diff', 1188 'rev2[0]' => $l_rev, 1189 'rev2[1]' => $r_rev, 1190 'difftype' => $type, 1191 )); 1192 ptln('<p><a class="wikilink1" href="'.$diffurl.'">'.$lang['difflink'].'</a></p>'); 1193 ptln('</div>'); 1194 } 1195 ?> 1196 <div class="table"> 1197 <table class="diff diff_<?php echo $type?>"> 1198 <tr> 1199 <th colspan="2" <?php echo $l_minor?>> 1200 <?php echo $l_head?> 1201 </th> 1202 <th colspan="2" <?php echo $r_minor?>> 1203 <?php echo $r_head?> 1204 </th> 1205 </tr> 1206 <?php echo $tdf->format($df)?> 1207 </table> 1208 </div> 1209 <?php 1210} 1211 1212/** 1213 * show warning on conflict detection 1214 * 1215 * @author Andreas Gohr <andi@splitbrain.org> 1216 */ 1217function html_conflict($text,$summary){ 1218 global $ID; 1219 global $lang; 1220 1221 print p_locale_xhtml('conflict'); 1222 $form = new Doku_Form(array('id' => 'dw__editform')); 1223 $form->addHidden('id', $ID); 1224 $form->addHidden('wikitext', $text); 1225 $form->addHidden('summary', $summary); 1226 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s'))); 1227 $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel'])); 1228 html_form('conflict', $form); 1229 print '<br /><br /><br /><br />'.NL; 1230} 1231 1232/** 1233 * Prints the global message array 1234 * 1235 * @author Andreas Gohr <andi@splitbrain.org> 1236 */ 1237function html_msgarea(){ 1238 global $MSG, $MSG_shown; 1239 /** @var array $MSG */ 1240 // store if the global $MSG has already been shown and thus HTML output has been started 1241 $MSG_shown = true; 1242 1243 if(!isset($MSG)) return; 1244 1245 $shown = array(); 1246 foreach($MSG as $msg){ 1247 $hash = md5($msg['msg']); 1248 if(isset($shown[$hash])) continue; // skip double messages 1249 print '<div class="'.$msg['lvl'].'">'; 1250 print $msg['msg']; 1251 print '</div>'; 1252 $shown[$hash] = 1; 1253 } 1254 1255 unset($GLOBALS['MSG']); 1256} 1257 1258/** 1259 * Prints the registration form 1260 * 1261 * @author Andreas Gohr <andi@splitbrain.org> 1262 */ 1263function html_register(){ 1264 global $lang; 1265 global $conf; 1266 global $INPUT; 1267 1268 print p_locale_xhtml('register'); 1269 print '<div class="centeralign">'.NL; 1270 $form = new Doku_Form(array('id' => 'dw__register')); 1271 $form->startFieldset($lang['btn_register']); 1272 $form->addHidden('do', 'register'); 1273 $form->addHidden('save', '1'); 1274 $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block', array('size'=>'50'))); 1275 if (!$conf['autopasswd']) { 1276 $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50'))); 1277 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50'))); 1278 } 1279 $form->addElement(form_makeTextField('fullname', $INPUT->post->str('fullname'), $lang['fullname'], '', 'block', array('size'=>'50'))); 1280 $form->addElement(form_makeTextField('email', $INPUT->post->str('email'), $lang['email'], '', 'block', array('size'=>'50'))); 1281 $form->addElement(form_makeButton('submit', '', $lang['btn_register'])); 1282 $form->endFieldset(); 1283 html_form('register', $form); 1284 1285 print '</div>'.NL; 1286} 1287 1288/** 1289 * Print the update profile form 1290 * 1291 * @author Christopher Smith <chris@jalakai.co.uk> 1292 * @author Andreas Gohr <andi@splitbrain.org> 1293 */ 1294function html_updateprofile(){ 1295 global $lang; 1296 global $conf; 1297 global $INPUT; 1298 global $INFO; 1299 /** @var auth_basic $auth */ 1300 global $auth; 1301 1302 print p_locale_xhtml('updateprofile'); 1303 1304 $fullname = $INPUT->post->str('fullname', $INFO['userinfo']['name'], true); 1305 $email = $INPUT->post->str('email', $INFO['userinfo']['mail'], true); 1306 print '<div class="centeralign">'.NL; 1307 $form = new Doku_Form(array('id' => 'dw__register')); 1308 $form->startFieldset($lang['profile']); 1309 $form->addHidden('do', 'profile'); 1310 $form->addHidden('save', '1'); 1311 $form->addElement(form_makeTextField('login', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled'))); 1312 $attr = array('size'=>'50'); 1313 if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled'; 1314 $form->addElement(form_makeTextField('fullname', $fullname, $lang['fullname'], '', 'block', $attr)); 1315 $attr = array('size'=>'50'); 1316 if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled'; 1317 $form->addElement(form_makeTextField('email', $email, $lang['email'], '', 'block', $attr)); 1318 $form->addElement(form_makeTag('br')); 1319 if ($auth->canDo('modPass')) { 1320 $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50'))); 1321 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50'))); 1322 } 1323 if ($conf['profileconfirm']) { 1324 $form->addElement(form_makeTag('br')); 1325 $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50'))); 1326 } 1327 $form->addElement(form_makeButton('submit', '', $lang['btn_save'])); 1328 $form->addElement(form_makeButton('reset', '', $lang['btn_reset'])); 1329 $form->endFieldset(); 1330 html_form('updateprofile', $form); 1331 print '</div>'.NL; 1332} 1333 1334/** 1335 * Preprocess edit form data 1336 * 1337 * @author Andreas Gohr <andi@splitbrain.org> 1338 * 1339 * @triggers HTML_EDITFORM_OUTPUT 1340 */ 1341function html_edit(){ 1342 global $INPUT; 1343 global $ID; 1344 global $REV; 1345 global $DATE; 1346 global $PRE; 1347 global $SUF; 1348 global $INFO; 1349 global $SUM; 1350 global $lang; 1351 global $conf; 1352 global $TEXT; 1353 global $RANGE; 1354 1355 if ($INPUT->has('changecheck')) { 1356 $check = $INPUT->str('changecheck'); 1357 } elseif(!$INFO['exists']){ 1358 // $TEXT has been loaded from page template 1359 $check = md5(''); 1360 } else { 1361 $check = md5($TEXT); 1362 } 1363 $mod = md5($TEXT) !== $check; 1364 1365 $wr = $INFO['writable'] && !$INFO['locked']; 1366 $include = 'edit'; 1367 if($wr){ 1368 if ($REV) $include = 'editrev'; 1369 }else{ 1370 // check pseudo action 'source' 1371 if(!actionOK('source')){ 1372 msg('Command disabled: source',-1); 1373 return; 1374 } 1375 $include = 'read'; 1376 } 1377 1378 global $license; 1379 1380 $form = new Doku_Form(array('id' => 'dw__editform')); 1381 $form->addHidden('id', $ID); 1382 $form->addHidden('rev', $REV); 1383 $form->addHidden('date', $DATE); 1384 $form->addHidden('prefix', $PRE . '.'); 1385 $form->addHidden('suffix', $SUF); 1386 $form->addHidden('changecheck', $check); 1387 1388 $data = array('form' => $form, 1389 'wr' => $wr, 1390 'media_manager' => true, 1391 'target' => ($INPUT->has('target') && $wr && 1392 $RANGE !== '') ? $INPUT->str('target') : 'section', 1393 'intro_locale' => $include); 1394 1395 if ($data['target'] !== 'section') { 1396 // Only emit event if page is writable, section edit data is valid and 1397 // edit target is not section. 1398 trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true); 1399 } else { 1400 html_edit_form($data); 1401 } 1402 if (isset($data['intro_locale'])) { 1403 echo p_locale_xhtml($data['intro_locale']); 1404 } 1405 1406 $form->addHidden('target', $data['target']); 1407 $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar', 'class'=>'editBar'))); 1408 $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl'))); 1409 $form->addElement(form_makeCloseTag('div')); 1410 if ($wr) { 1411 $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons'))); 1412 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4'))); 1413 $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5'))); 1414 $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6'))); 1415 $form->addElement(form_makeCloseTag('div')); 1416 $form->addElement(form_makeOpenTag('div', array('class'=>'summary'))); 1417 $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2'))); 1418 $elem = html_minoredit(); 1419 if ($elem) $form->addElement($elem); 1420 $form->addElement(form_makeCloseTag('div')); 1421 } 1422 $form->addElement(form_makeCloseTag('div')); 1423 if($wr && $conf['license']){ 1424 $form->addElement(form_makeOpenTag('div', array('class'=>'license'))); 1425 $out = $lang['licenseok']; 1426 $out .= ' <a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"'; 1427 if($conf['target']['extern']) $out .= ' target="'.$conf['target']['extern'].'"'; 1428 $out .= '>'.$license[$conf['license']]['name'].'</a>'; 1429 $form->addElement($out); 1430 $form->addElement(form_makeCloseTag('div')); 1431 } 1432 1433 if ($wr) { 1434 // sets changed to true when previewed 1435 echo '<script type="text/javascript">/*<![CDATA[*/'. NL; 1436 echo 'textChanged = ' . ($mod ? 'true' : 'false'); 1437 echo '/*!]]>*/</script>' . NL; 1438 } ?> 1439 <div class="editBox"> 1440 1441 <div class="toolbar"> 1442 <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div> 1443 <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']?>" 1444 target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div> 1445 </div> 1446 <?php 1447 1448 html_form('edit', $form); 1449 print '</div>'.NL; 1450} 1451 1452/** 1453 * Display the default edit form 1454 * 1455 * Is the default action for HTML_EDIT_FORMSELECTION. 1456 */ 1457function html_edit_form($param) { 1458 global $TEXT; 1459 1460 if ($param['target'] !== 'section') { 1461 msg('No editor for edit target ' . hsc($param['target']) . ' found.', -1); 1462 } 1463 1464 $attr = array('tabindex'=>'1'); 1465 if (!$param['wr']) $attr['readonly'] = 'readonly'; 1466 1467 $param['form']->addElement(form_makeWikiText($TEXT, $attr)); 1468} 1469 1470/** 1471 * Adds a checkbox for minor edits for logged in users 1472 * 1473 * @author Andreas Gohr <andi@splitbrain.org> 1474 */ 1475function html_minoredit(){ 1476 global $conf; 1477 global $lang; 1478 global $INPUT; 1479 // minor edits are for logged in users only 1480 if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){ 1481 return false; 1482 } 1483 1484 $p = array(); 1485 $p['tabindex'] = 3; 1486 if($INPUT->bool('minor')) $p['checked']='checked'; 1487 return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p); 1488} 1489 1490/** 1491 * prints some debug info 1492 * 1493 * @author Andreas Gohr <andi@splitbrain.org> 1494 */ 1495function html_debug(){ 1496 global $conf; 1497 global $lang; 1498 /** @var auth_basic $auth */ 1499 global $auth; 1500 global $INFO; 1501 1502 //remove sensitive data 1503 $cnf = $conf; 1504 debug_guard($cnf); 1505 $nfo = $INFO; 1506 debug_guard($nfo); 1507 $ses = $_SESSION; 1508 debug_guard($ses); 1509 1510 print '<html><body>'; 1511 1512 print '<p>When reporting bugs please send all the following '; 1513 print 'output as a mail to andi@splitbrain.org '; 1514 print 'The best way to do this is to save this page in your browser</p>'; 1515 1516 print '<b>$INFO:</b><pre>'; 1517 print_r($nfo); 1518 print '</pre>'; 1519 1520 print '<b>$_SERVER:</b><pre>'; 1521 print_r($_SERVER); 1522 print '</pre>'; 1523 1524 print '<b>$conf:</b><pre>'; 1525 print_r($cnf); 1526 print '</pre>'; 1527 1528 print '<b>DOKU_BASE:</b><pre>'; 1529 print DOKU_BASE; 1530 print '</pre>'; 1531 1532 print '<b>abs DOKU_BASE:</b><pre>'; 1533 print DOKU_URL; 1534 print '</pre>'; 1535 1536 print '<b>rel DOKU_BASE:</b><pre>'; 1537 print dirname($_SERVER['PHP_SELF']).'/'; 1538 print '</pre>'; 1539 1540 print '<b>PHP Version:</b><pre>'; 1541 print phpversion(); 1542 print '</pre>'; 1543 1544 print '<b>locale:</b><pre>'; 1545 print setlocale(LC_ALL,0); 1546 print '</pre>'; 1547 1548 print '<b>encoding:</b><pre>'; 1549 print $lang['encoding']; 1550 print '</pre>'; 1551 1552 if($auth){ 1553 print '<b>Auth backend capabilities:</b><pre>'; 1554 print_r($auth->cando); 1555 print '</pre>'; 1556 } 1557 1558 print '<b>$_SESSION:</b><pre>'; 1559 print_r($ses); 1560 print '</pre>'; 1561 1562 print '<b>Environment:</b><pre>'; 1563 print_r($_ENV); 1564 print '</pre>'; 1565 1566 print '<b>PHP settings:</b><pre>'; 1567 $inis = ini_get_all(); 1568 print_r($inis); 1569 print '</pre>'; 1570 1571 print '</body></html>'; 1572} 1573 1574/** 1575 * List available Administration Tasks 1576 * 1577 * @author Andreas Gohr <andi@splitbrain.org> 1578 * @author Håkan Sandell <hakan.sandell@home.se> 1579 */ 1580function html_admin(){ 1581 global $ID; 1582 global $INFO; 1583 global $conf; 1584 /** @var auth_basic $auth */ 1585 global $auth; 1586 1587 // build menu of admin functions from the plugins that handle them 1588 $pluginlist = plugin_list('admin'); 1589 $menu = array(); 1590 foreach ($pluginlist as $p) { 1591 /** @var DokuWiki_Admin_Plugin $obj */ 1592 if($obj =& plugin_load('admin',$p) === null) continue; 1593 1594 // check permissions 1595 if($obj->forAdminOnly() && !$INFO['isadmin']) continue; 1596 1597 $menu[$p] = array('plugin' => $p, 1598 'prompt' => $obj->getMenuText($conf['lang']), 1599 'sort' => $obj->getMenuSort() 1600 ); 1601 } 1602 1603 // data security check 1604 // @todo: could be checked and only displayed if $conf['savedir'] is under the web root 1605 echo '<a style="border:none; float:right;" 1606 href="http://www.dokuwiki.org/security#web_access_security"> 1607 <img src="data/security.png" alt="Your data directory seems to be protected properly." 1608 onerror="this.parentNode.style.display=\'none\'" /></a>'; 1609 1610 print p_locale_xhtml('admin'); 1611 1612 // Admin Tasks 1613 if($INFO['isadmin']){ 1614 ptln('<ul class="admin_tasks">'); 1615 1616 if($menu['usermanager'] && $auth && $auth->canDo('getUsers')){ 1617 ptln(' <li class="admin_usermanager"><div class="li">'. 1618 '<a href="'.wl($ID, array('do' => 'admin','page' => 'usermanager')).'">'. 1619 $menu['usermanager']['prompt'].'</a></div></li>'); 1620 } 1621 unset($menu['usermanager']); 1622 1623 if($menu['acl']){ 1624 ptln(' <li class="admin_acl"><div class="li">'. 1625 '<a href="'.wl($ID, array('do' => 'admin','page' => 'acl')).'">'. 1626 $menu['acl']['prompt'].'</a></div></li>'); 1627 } 1628 unset($menu['acl']); 1629 1630 if($menu['plugin']){ 1631 ptln(' <li class="admin_plugin"><div class="li">'. 1632 '<a href="'.wl($ID, array('do' => 'admin','page' => 'plugin')).'">'. 1633 $menu['plugin']['prompt'].'</a></div></li>'); 1634 } 1635 unset($menu['plugin']); 1636 1637 if($menu['config']){ 1638 ptln(' <li class="admin_config"><div class="li">'. 1639 '<a href="'.wl($ID, array('do' => 'admin','page' => 'config')).'">'. 1640 $menu['config']['prompt'].'</a></div></li>'); 1641 } 1642 unset($menu['config']); 1643 } 1644 ptln('</ul>'); 1645 1646 // Manager Tasks 1647 ptln('<ul class="admin_tasks">'); 1648 1649 if($menu['revert']){ 1650 ptln(' <li class="admin_revert"><div class="li">'. 1651 '<a href="'.wl($ID, array('do' => 'admin','page' => 'revert')).'">'. 1652 $menu['revert']['prompt'].'</a></div></li>'); 1653 } 1654 unset($menu['revert']); 1655 1656 if($menu['popularity']){ 1657 ptln(' <li class="admin_popularity"><div class="li">'. 1658 '<a href="'.wl($ID, array('do' => 'admin','page' => 'popularity')).'">'. 1659 $menu['popularity']['prompt'].'</a></div></li>'); 1660 } 1661 unset($menu['popularity']); 1662 1663 // print DokuWiki version: 1664 ptln('</ul>'); 1665 echo '<div id="admin__version">'; 1666 echo getVersion(); 1667 echo '</div>'; 1668 1669 // print the rest as sorted list 1670 if(count($menu)){ 1671 usort($menu, 'p_sort_modes'); 1672 // output the menu 1673 ptln('<div class="clearer"></div>'); 1674 print p_locale_xhtml('adminplugins'); 1675 ptln('<ul>'); 1676 foreach ($menu as $item) { 1677 if (!$item['prompt']) continue; 1678 ptln(' <li><div class="li"><a href="'.wl($ID, 'do=admin&page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>'); 1679 } 1680 ptln('</ul>'); 1681 } 1682} 1683 1684/** 1685 * Form to request a new password for an existing account 1686 * 1687 * @author Benoit Chesneau <benoit@bchesneau.info> 1688 * @author Andreas Gohr <gohr@cosmocode.de> 1689 */ 1690function html_resendpwd() { 1691 global $lang; 1692 global $conf; 1693 global $INPUT; 1694 1695 $token = preg_replace('/[^a-f0-9]+/','',$INPUT->str('pwauth')); 1696 1697 if(!$conf['autopasswd'] && $token){ 1698 print p_locale_xhtml('resetpwd'); 1699 print '<div class="centeralign">'.NL; 1700 $form = new Doku_Form(array('id' => 'dw__resendpwd')); 1701 $form->startFieldset($lang['btn_resendpwd']); 1702 $form->addHidden('token', $token); 1703 $form->addHidden('do', 'resendpwd'); 1704 1705 $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50'))); 1706 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50'))); 1707 1708 $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd'])); 1709 $form->endFieldset(); 1710 html_form('resendpwd', $form); 1711 print '</div>'.NL; 1712 }else{ 1713 print p_locale_xhtml('resendpwd'); 1714 print '<div class="centeralign">'.NL; 1715 $form = new Doku_Form(array('id' => 'dw__resendpwd')); 1716 $form->startFieldset($lang['resendpwd']); 1717 $form->addHidden('do', 'resendpwd'); 1718 $form->addHidden('save', '1'); 1719 $form->addElement(form_makeTag('br')); 1720 $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block')); 1721 $form->addElement(form_makeTag('br')); 1722 $form->addElement(form_makeTag('br')); 1723 $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd'])); 1724 $form->endFieldset(); 1725 html_form('resendpwd', $form); 1726 print '</div>'.NL; 1727 } 1728} 1729 1730/** 1731 * Return the TOC rendered to XHTML 1732 * 1733 * @author Andreas Gohr <andi@splitbrain.org> 1734 */ 1735function html_TOC($toc){ 1736 if(!count($toc)) return ''; 1737 global $lang; 1738 $out = '<!-- TOC START -->'.DOKU_LF; 1739 $out .= '<div id="dw__toc">'.DOKU_LF; 1740 $out .= '<h3 class="toggle">'; 1741 $out .= $lang['toc']; 1742 $out .= '</h3>'.DOKU_LF; 1743 $out .= '<div>'.DOKU_LF; 1744 $out .= html_buildlist($toc,'toc','html_list_toc','html_li_default',true); 1745 $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF; 1746 $out .= '<!-- TOC END -->'.DOKU_LF; 1747 return $out; 1748} 1749 1750/** 1751 * Callback for html_buildlist 1752 */ 1753function html_list_toc($item){ 1754 if(isset($item['hid'])){ 1755 $link = '#'.$item['hid']; 1756 }else{ 1757 $link = $item['link']; 1758 } 1759 1760 return '<a href="'.$link.'">'.hsc($item['title']).'</a>'; 1761} 1762 1763/** 1764 * Helper function to build TOC items 1765 * 1766 * Returns an array ready to be added to a TOC array 1767 * 1768 * @param string $link - where to link (if $hash set to '#' it's a local anchor) 1769 * @param string $text - what to display in the TOC 1770 * @param int $level - nesting level 1771 * @param string $hash - is prepended to the given $link, set blank if you want full links 1772 * @return array the toc item 1773 */ 1774function html_mktocitem($link, $text, $level, $hash='#'){ 1775 return array( 'link' => $hash.$link, 1776 'title' => $text, 1777 'type' => 'ul', 1778 'level' => $level); 1779} 1780 1781/** 1782 * Output a Doku_Form object. 1783 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT 1784 * 1785 * @author Tom N Harris <tnharris@whoopdedo.org> 1786 * @param string $name The name of the form 1787 * @param Doku_Form $form The form 1788 */ 1789function html_form($name, &$form) { 1790 // Safety check in case the caller forgets. 1791 $form->endFieldset(); 1792 trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false); 1793} 1794 1795/** 1796 * Form print function. 1797 * Just calls printForm() on the data object. 1798 * @param Doku_Form $data The form 1799 */ 1800function html_form_output($data) { 1801 $data->printForm(); 1802} 1803 1804/** 1805 * Embed a flash object in HTML 1806 * 1807 * This will create the needed HTML to embed a flash movie in a cross browser 1808 * compatble way using valid XHTML 1809 * 1810 * The parameters $params, $flashvars and $atts need to be associative arrays. 1811 * No escaping needs to be done for them. The alternative content *has* to be 1812 * escaped because it is used as is. If no alternative content is given 1813 * $lang['noflash'] is used. 1814 * 1815 * @author Andreas Gohr <andi@splitbrain.org> 1816 * @link http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml 1817 * 1818 * @param string $swf - the SWF movie to embed 1819 * @param int $width - width of the flash movie in pixels 1820 * @param int $height - height of the flash movie in pixels 1821 * @param array $params - additional parameters (<param>) 1822 * @param array $flashvars - parameters to be passed in the flashvar parameter 1823 * @param array $atts - additional attributes for the <object> tag 1824 * @param string $alt - alternative content (is NOT automatically escaped!) 1825 * @return string - the XHTML markup 1826 */ 1827function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){ 1828 global $lang; 1829 1830 $out = ''; 1831 1832 // prepare the object attributes 1833 if(is_null($atts)) $atts = array(); 1834 $atts['width'] = (int) $width; 1835 $atts['height'] = (int) $height; 1836 if(!$atts['width']) $atts['width'] = 425; 1837 if(!$atts['height']) $atts['height'] = 350; 1838 1839 // add object attributes for standard compliant browsers 1840 $std = $atts; 1841 $std['type'] = 'application/x-shockwave-flash'; 1842 $std['data'] = $swf; 1843 1844 // add object attributes for IE 1845 $ie = $atts; 1846 $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'; 1847 1848 // open object (with conditional comments) 1849 $out .= '<!--[if !IE]> -->'.NL; 1850 $out .= '<object '.buildAttributes($std).'>'.NL; 1851 $out .= '<!-- <![endif]-->'.NL; 1852 $out .= '<!--[if IE]>'.NL; 1853 $out .= '<object '.buildAttributes($ie).'>'.NL; 1854 $out .= ' <param name="movie" value="'.hsc($swf).'" />'.NL; 1855 $out .= '<!--><!-- -->'.NL; 1856 1857 // print params 1858 if(is_array($params)) foreach($params as $key => $val){ 1859 $out .= ' <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL; 1860 } 1861 1862 // add flashvars 1863 if(is_array($flashvars)){ 1864 $out .= ' <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL; 1865 } 1866 1867 // alternative content 1868 if($alt){ 1869 $out .= $alt.NL; 1870 }else{ 1871 $out .= $lang['noflash'].NL; 1872 } 1873 1874 // finish 1875 $out .= '</object>'.NL; 1876 $out .= '<!-- <![endif]-->'.NL; 1877 1878 return $out; 1879} 1880 1881/** 1882 * Prints HTML code for the given tab structure 1883 * 1884 * @param array $tabs tab structure 1885 * @param string $current_tab the current tab id 1886 */ 1887function html_tabs($tabs, $current_tab = null) { 1888 echo '<ul class="tabs">'.NL; 1889 1890 foreach($tabs as $id => $tab) { 1891 html_tab($tab['href'], $tab['caption'], $id === $current_tab); 1892 } 1893 1894 echo '</ul>'.NL; 1895} 1896/** 1897 * Prints a single tab 1898 * 1899 * @author Kate Arzamastseva <pshns@ukr.net> 1900 * @author Adrian Lang <mail@adrianlang.de> 1901 * 1902 * @param string $href - tab href 1903 * @param string $caption - tab caption 1904 * @param boolean $selected - is tab selected 1905 */ 1906 1907function html_tab($href, $caption, $selected=false) { 1908 $tab = '<li>'; 1909 if ($selected) { 1910 $tab .= '<strong>'; 1911 } else { 1912 $tab .= '<a href="' . hsc($href) . '">'; 1913 } 1914 $tab .= hsc($caption) 1915 . '</' . ($selected ? 'strong' : 'a') . '>' 1916 . '</li>'.NL; 1917 echo $tab; 1918} 1919 1920