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