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 class="centeralign" 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 '<br /></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 $num = 1; 367 foreach($data as $id => $cnt){ 368 print '<div class="search_result">'; 369 print html_wikilink(':'.$id,useHeading('navigation')?null:$id,$regex); 370 if($cnt !== 0){ 371 print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />'; 372 if($num < FT_SNIPPET_NUMBER){ // create snippets for the first number of matches only 373 print '<div class="search_snippet">'.ft_snippet($id,$regex).'</div>'; 374 } 375 $num++; 376 } 377 print '</div>'; 378 flush(); 379 } 380 }else{ 381 print '<div class="nothing">'.$lang['nothingfound'].'</div>'; 382 } 383 384 //hide progressbar 385 print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL; 386 print 'hideLoadBar("dw__loading");'.NL; 387 print '//--><!]]></script>'.NL; 388 flush(); 389} 390 391/** 392 * Display error on locked pages 393 * 394 * @author Andreas Gohr <andi@splitbrain.org> 395 */ 396function html_locked(){ 397 global $ID; 398 global $conf; 399 global $lang; 400 global $INFO; 401 402 $locktime = filemtime(wikiLockFN($ID)); 403 $expire = dformat($locktime + $conf['locktime']); 404 $min = round(($conf['locktime'] - (time() - $locktime) )/60); 405 406 print p_locale_xhtml('locked'); 407 print '<ul>'; 408 print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.editorinfo($INFO['locked']).'</div></li>'; 409 print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>'; 410 print '</ul>'; 411} 412 413/** 414 * list old revisions 415 * 416 * @author Andreas Gohr <andi@splitbrain.org> 417 * @author Ben Coburn <btcoburn@silicodon.net> 418 * @author Kate Arzamastseva <pshns@ukr.net> 419 */ 420function html_revisions($first=0, $media_id = false){ 421 global $ID; 422 global $INFO; 423 global $conf; 424 global $lang; 425 $id = $ID; 426 /* we need to get one additionally log entry to be able to 427 * decide if this is the last page or is there another one. 428 * see html_recent() 429 */ 430 if (!$media_id) $revisions = getRevisions($ID, $first, $conf['recent']+1); 431 else { 432 $revisions = getRevisions($media_id, $first, $conf['recent']+1, 8192, true); 433 $id = $media_id; 434 } 435 436 if(count($revisions)==0 && $first!=0){ 437 $first=0; 438 if (!$media_id) $revisions = getRevisions($ID, $first, $conf['recent']+1); 439 else $revisions = getRevisions($media_id, $first, $conf['recent']+1, 8192, true); 440 } 441 $hasNext = false; 442 if (count($revisions)>$conf['recent']) { 443 $hasNext = true; 444 array_pop($revisions); // remove extra log entry 445 } 446 447 if (!$media_id) $date = dformat($INFO['lastmod']); 448 else $date = dformat(@filemtime(mediaFN($id))); 449 450 if (!$media_id) print p_locale_xhtml('revisions'); 451 452 $params = array('id' => 'page__revisions'); 453 if ($media_id) $params['action'] = media_managerURL(array('image' => $media_id), '&'); 454 455 $form = new Doku_Form($params); 456 $form->addElement(form_makeOpenTag('ul')); 457 458 if (!$media_id) $exists = $INFO['exists']; 459 else $exists = @file_exists(mediaFN($id)); 460 461 if($exists && $first==0){ 462 if (!$media_id && isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) 463 $form->addElement(form_makeOpenTag('li', array('class' => 'minor'))); 464 else 465 $form->addElement(form_makeOpenTag('li')); 466 $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); 467 $form->addElement(form_makeTag('input', array( 468 'type' => 'checkbox', 469 'name' => 'rev2[]', 470 'value' => 'current'))); 471 472 $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); 473 $form->addElement($date); 474 $form->addElement(form_makeCloseTag('span')); 475 476 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />'); 477 478 if (!$media_id) $href = wl($id); 479 else $href = media_managerURL(array('image' => $id, 'tab_details' => 'view'), '&'); 480 $form->addElement(form_makeOpenTag('a', array( 481 'class' => 'wikilink1', 482 'href' => $href))); 483 $form->addElement($id); 484 $form->addElement(form_makeCloseTag('a')); 485 486 $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); 487 $form->addElement(' – '); 488 if (!$media_id) $form->addElement(htmlspecialchars($INFO['sum'])); 489 $form->addElement(form_makeCloseTag('span')); 490 491 $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); 492 if (!$media_id) $editor = $INFO['editor']; 493 else { 494 $revinfo = getRevisionInfo($id, @filemtime(fullpath(mediaFN($id))), 1024, true); 495 if($revinfo['user']){ 496 $editor = $revinfo['user']; 497 }else{ 498 $editor = $revinfo['ip']; 499 } 500 } 501 $form->addElement((empty($editor))?('('.$lang['external_edit'].')'):editorinfo($editor)); 502 $form->addElement(form_makeCloseTag('span')); 503 504 $form->addElement('('.$lang['current'].')'); 505 $form->addElement(form_makeCloseTag('div')); 506 $form->addElement(form_makeCloseTag('li')); 507 } 508 509 foreach($revisions as $rev){ 510 $date = dformat($rev); 511 if (!$media_id) { 512 $info = getRevisionInfo($id,$rev,true); 513 $exists = page_exists($id,$rev); 514 } else { 515 $info = getRevisionInfo($id,$rev,true,true); 516 $exists = @file_exists(mediaFN($id,$rev)); 517 } 518 519 if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) 520 $form->addElement(form_makeOpenTag('li', array('class' => 'minor'))); 521 else 522 $form->addElement(form_makeOpenTag('li')); 523 $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); 524 if($exists){ 525 $form->addElement(form_makeTag('input', array( 526 'type' => 'checkbox', 527 'name' => 'rev2[]', 528 'value' => $rev))); 529 }else{ 530 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />'); 531 } 532 533 $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); 534 $form->addElement($date); 535 $form->addElement(form_makeCloseTag('span')); 536 537 if($exists){ 538 if (!$media_id) $href = wl($id,"rev=$rev,do=diff", false, '&'); 539 else $href = media_managerURL(array('image' => $id, 'rev' => $rev, 'mediado' => 'diff'), '&'); 540 $form->addElement(form_makeOpenTag('a', array('href' => $href, 'class' => 'diff_link'))); 541 $form->addElement(form_makeTag('img', array( 542 'src' => DOKU_BASE.'lib/images/diff.png', 543 'width' => 15, 544 'height' => 11, 545 'title' => $lang['diff'], 546 'alt' => $lang['diff']))); 547 $form->addElement(form_makeCloseTag('a')); 548 if (!$media_id) $href = wl($id,"rev=$rev",false,'&'); 549 else $href = media_managerURL(array('image' => $id, 'tab_details' => 'view', 'rev' => $rev), '&'); 550 $form->addElement(form_makeOpenTag('a', array('href' => $href, 'class' => 'wikilink1'))); 551 $form->addElement($id); 552 $form->addElement(form_makeCloseTag('a')); 553 }else{ 554 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />'); 555 $form->addElement($id); 556 } 557 558 $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); 559 $form->addElement(' – '); 560 $form->addElement(htmlspecialchars($info['sum'])); 561 $form->addElement(form_makeCloseTag('span')); 562 563 $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); 564 if($info['user']){ 565 $form->addElement(editorinfo($info['user'])); 566 if(auth_ismanager()){ 567 $form->addElement(' ('.$info['ip'].')'); 568 } 569 }else{ 570 $form->addElement($info['ip']); 571 } 572 $form->addElement(form_makeCloseTag('span')); 573 574 $form->addElement(form_makeCloseTag('div')); 575 $form->addElement(form_makeCloseTag('li')); 576 } 577 $form->addElement(form_makeCloseTag('ul')); 578 if (!$media_id) { 579 $form->addElement(form_makeButton('submit', 'diff', $lang['diff2'])); 580 } else { 581 $form->addHidden('mediado', 'diff'); 582 $form->addElement(form_makeButton('submit', '', $lang['diff2'])); 583 } 584 html_form('revisions', $form); 585 586 print '<div class="pagenav">'; 587 $last = $first + $conf['recent']; 588 if ($first > 0) { 589 $first -= $conf['recent']; 590 if ($first < 0) $first = 0; 591 print '<div class="pagenav-prev">'; 592 print html_btn('newer',$id,"p",array('do' => 'revisions', 'first' => $first)); 593 print '</div>'; 594 } 595 if ($hasNext) { 596 print '<div class="pagenav-next">'; 597 print html_btn('older',$id,"n",array('do' => 'revisions', 'first' => $last)); 598 print '</div>'; 599 } 600 print '</div>'; 601 602} 603 604/** 605 * display recent changes 606 * 607 * @author Andreas Gohr <andi@splitbrain.org> 608 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 609 * @author Ben Coburn <btcoburn@silicodon.net> 610 * @author Kate Arzamastseva <pshns@ukr.net> 611 */ 612function html_recent($first=0, $show_changes='both'){ 613 global $conf; 614 global $lang; 615 global $ID; 616 /* we need to get one additionally log entry to be able to 617 * decide if this is the last page or is there another one. 618 * This is the cheapest solution to get this information. 619 */ 620 if (!$show_changes || $show_changes == 'both') $flags = RECENTS_MEDIA_PAGES_MIXED; 621 if ($show_changes == 'mediafiles') $flags = RECENTS_MEDIA_CHANGES; 622 if ($show_changes == 'pages') $flags = 0; 623 624 $recents = getRecents($first,$conf['recent'] + 1,getNS($ID),$flags); 625 if(count($recents) == 0 && $first != 0){ 626 $first=0; 627 $recents = getRecents($first,$conf['recent'] + 1,getNS($ID),$flags); 628 } 629 $hasNext = false; 630 if (count($recents)>$conf['recent']) { 631 $hasNext = true; 632 array_pop($recents); // remove extra log entry 633 } 634 635 print p_locale_xhtml('recent'); 636 637 if (getNS($ID) != '') 638 print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>'; 639 640 $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET')); 641 $form->addHidden('sectok', null); 642 $form->addHidden('do', 'recent'); 643 $form->addHidden('id', $ID); 644 645 $form->addElement(form_makeOpenTag('div', array('class' => 'changestypenav'))); 646 $attrs = array('name' => 'show_changes', 647 'value' => 'pages', 648 '_text' => $lang['pages_changes']); 649 if ($show_changes == 'pages') $attrs['checked'] = 'checked'; 650 $form->addElement(form_radiofield($attrs)); 651 $attrs = array('name' => 'show_changes', 652 'value' => 'mediafiles', 653 '_text' => $lang['media_changes']); 654 if ($show_changes == 'mediafiles') $attrs['checked'] = 'checked'; 655 $form->addElement(form_radiofield($attrs)); 656 $attrs = array('name' => 'show_changes', 657 'value' => 'both', 658 '_text' => $lang['both_changes'] ); 659 if (empty($show_changes) || $show_changes == 'both') $attrs['checked'] = 'checked'; 660 $form->addElement(form_radiofield($attrs)); 661 $form->addElement(form_makeTag('input', array( 662 'type' => 'submit', 663 'value' => $lang['btn_apply'], 664 'title' => $lang['btn_apply'], 665 'class' => 'button' 666 ))); 667 $form->addElement(form_makeCloseTag('div')); 668 669 $form->addElement(form_makeOpenTag('ul')); 670 671 foreach($recents as $recent){ 672 $date = dformat($recent['date']); 673 if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) 674 $form->addElement(form_makeOpenTag('li', array('class' => 'minor'))); 675 else 676 $form->addElement(form_makeOpenTag('li')); 677 678 $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); 679 680 $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); 681 $form->addElement($date); 682 $form->addElement(form_makeCloseTag('span')); 683 684 $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => wl($recent['id'],"do=diff", false, '&')))); 685 $form->addElement(form_makeTag('img', array( 686 'src' => DOKU_BASE.'lib/images/diff.png', 687 'width' => 15, 688 'height'=> 11, 689 'title' => $lang['diff'], 690 'alt' => $lang['diff'] 691 ))); 692 $form->addElement(form_makeCloseTag('a')); 693 694 $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => wl($recent['id'],"do=revisions",false,'&')))); 695 $form->addElement(form_makeTag('img', array( 696 'src' => DOKU_BASE.'lib/images/history.png', 697 'width' => 12, 698 'height'=> 14, 699 'title' => $lang['btn_revs'], 700 'alt' => $lang['btn_revs'] 701 ))); 702 $form->addElement(form_makeCloseTag('a')); 703 704 $form->addElement(html_wikilink(':'.$recent['id'],useHeading('navigation')?null:$recent['id'])); 705 706 $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); 707 $form->addElement(' – '.htmlspecialchars($recent['sum'])); 708 $form->addElement(form_makeCloseTag('span')); 709 710 $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); 711 if($recent['user']){ 712 $form->addElement(editorinfo($recent['user'])); 713 if(auth_ismanager()){ 714 $form->addElement(' ('.$recent['ip'].')'); 715 } 716 }else{ 717 $form->addElement($recent['ip']); 718 } 719 $form->addElement(form_makeCloseTag('span')); 720 721 $form->addElement(form_makeCloseTag('div')); 722 $form->addElement(form_makeCloseTag('li')); 723 } 724 $form->addElement(form_makeCloseTag('ul')); 725 726 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav'))); 727 $last = $first + $conf['recent']; 728 if ($first > 0) { 729 $first -= $conf['recent']; 730 if ($first < 0) $first = 0; 731 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev'))); 732 $form->addElement(form_makeTag('input', array( 733 'type' => 'submit', 734 'name' => 'first['.$first.']', 735 'value' => $lang['btn_newer'], 736 'accesskey' => 'n', 737 'title' => $lang['btn_newer'].' [N]', 738 'class' => 'button' 739 ))); 740 $form->addElement(form_makeCloseTag('div')); 741 } 742 if ($hasNext) { 743 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next'))); 744 $form->addElement(form_makeTag('input', array( 745 'type' => 'submit', 746 'name' => 'first['.$last.']', 747 'value' => $lang['btn_older'], 748 'accesskey' => 'p', 749 'title' => $lang['btn_older'].' [P]', 750 'class' => 'button' 751 ))); 752 $form->addElement(form_makeCloseTag('div')); 753 } 754 $form->addElement(form_makeCloseTag('div')); 755 html_form('recent', $form); 756} 757 758/** 759 * Display page index 760 * 761 * @author Andreas Gohr <andi@splitbrain.org> 762 */ 763function html_index($ns){ 764 global $conf; 765 global $ID; 766 $dir = $conf['datadir']; 767 $ns = cleanID($ns); 768 #fixme use appropriate function 769 if(empty($ns)){ 770 $ns = dirname(str_replace(':','/',$ID)); 771 if($ns == '.') $ns =''; 772 } 773 $ns = utf8_encodeFN(str_replace(':','/',$ns)); 774 775 echo p_locale_xhtml('index'); 776 echo '<div id="index__tree">'; 777 778 $data = array(); 779 search($data,$conf['datadir'],'search_index',array('ns' => $ns)); 780 echo html_buildlist($data,'idx','html_list_index','html_li_index'); 781 782 echo '</div>'; 783} 784 785/** 786 * Index item formatter 787 * 788 * User function for html_buildlist() 789 * 790 * @author Andreas Gohr <andi@splitbrain.org> 791 */ 792function html_list_index($item){ 793 global $ID; 794 $ret = ''; 795 $base = ':'.$item['id']; 796 $base = substr($base,strrpos($base,':')+1); 797 if($item['type']=='d'){ 798 $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" class="idx_dir"><strong>'; 799 $ret .= $base; 800 $ret .= '</strong></a>'; 801 }else{ 802 $ret .= html_wikilink(':'.$item['id']); 803 } 804 return $ret; 805} 806 807/** 808 * Index List item 809 * 810 * This user function is used in html_buildlist to build the 811 * <li> tags for namespaces when displaying the page index 812 * it gives different classes to opened or closed "folders" 813 * 814 * @author Andreas Gohr <andi@splitbrain.org> 815 */ 816function html_li_index($item){ 817 if($item['type'] == "f"){ 818 return '<li class="level'.$item['level'].'">'; 819 }elseif($item['open']){ 820 return '<li class="open">'; 821 }else{ 822 return '<li class="closed">'; 823 } 824} 825 826/** 827 * Default List item 828 * 829 * @author Andreas Gohr <andi@splitbrain.org> 830 */ 831function html_li_default($item){ 832 return '<li class="level'.$item['level'].'">'; 833} 834 835/** 836 * Build an unordered list 837 * 838 * Build an unordered list from the given $data array 839 * Each item in the array has to have a 'level' property 840 * the item itself gets printed by the given $func user 841 * function. The second and optional function is used to 842 * print the <li> tag. Both user function need to accept 843 * a single item. 844 * 845 * Both user functions can be given as array to point to 846 * a member of an object. 847 * 848 * @author Andreas Gohr <andi@splitbrain.org> 849 */ 850function html_buildlist($data,$class,$func,$lifunc='html_li_default'){ 851 if (count($data) === 0) { 852 return ''; 853 } 854 855 $level = $data[0]['level']; 856 $opens = 0; 857 $ret = ''; 858 859 if ($level < 2) { 860 // Trigger building a wrapper ul if the first level is 861 // 0 (we have a root object) or 1 (just the root content) 862 --$level; 863 } 864 865 foreach ($data as $item){ 866 867 if( $item['level'] > $level ){ 868 //open new list 869 for($i=0; $i<($item['level'] - $level); $i++){ 870 if ($i) $ret .= "<li class=\"clear\">\n"; 871 $ret .= "\n<ul class=\"$class\">\n"; 872 } 873 }elseif( $item['level'] < $level ){ 874 //close last item 875 $ret .= "</li>\n"; 876 for ($i=0; $i<($level - $item['level']); $i++){ 877 //close higher lists 878 $ret .= "</ul>\n</li>\n"; 879 } 880 } elseif ($ret !== '') { 881 //close last item 882 $ret .= "</li>\n"; 883 } 884 885 //remember current level 886 $level = $item['level']; 887 888 //print item 889 $ret .= call_user_func($lifunc,$item); 890 $ret .= '<div class="li">'; 891 892 $ret .= call_user_func($func,$item); 893 $ret .= '</div>'; 894 } 895 896 //close remaining items and lists 897 for ($i=0; $i < $level; $i++){ 898 $ret .= "</li></ul>\n"; 899 } 900 901 return $ret; 902} 903 904/** 905 * display backlinks 906 * 907 * @author Andreas Gohr <andi@splitbrain.org> 908 * @author Michael Klier <chi@chimeric.de> 909 */ 910function html_backlinks(){ 911 global $ID; 912 global $conf; 913 global $lang; 914 915 print p_locale_xhtml('backlinks'); 916 917 $data = ft_backlinks($ID); 918 919 if(!empty($data)) { 920 print '<ul class="idx">'; 921 foreach($data as $blink){ 922 print '<li><div class="li">'; 923 print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink); 924 print '</div></li>'; 925 } 926 print '</ul>'; 927 } else { 928 print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>'; 929 } 930} 931 932/** 933 * show diff 934 * 935 * @author Andreas Gohr <andi@splitbrain.org> 936 * @param string $text - compare with this text with most current version 937 * @param bool $intr - display the intro text 938 */ 939function html_diff($text='',$intro=true,$type=null){ 940 global $ID; 941 global $REV; 942 global $lang; 943 global $conf; 944 945 if(!$type) $type = $_REQUEST['difftype']; 946 if($type != 'inline') $type = 'sidebyside'; 947 948 // we're trying to be clever here, revisions to compare can be either 949 // given as rev and rev2 parameters, with rev2 being optional. Or in an 950 // array in rev2. 951 $rev1 = $REV; 952 953 if(is_array($_REQUEST['rev2'])){ 954 $rev1 = (int) $_REQUEST['rev2'][0]; 955 $rev2 = (int) $_REQUEST['rev2'][1]; 956 957 if(!$rev1){ 958 $rev1 = $rev2; 959 unset($rev2); 960 } 961 }else{ 962 $rev2 = (int) $_REQUEST['rev2']; 963 } 964 965 $r_minor = ''; 966 $l_minor = ''; 967 968 if($text){ // compare text to the most current revision 969 $l_rev = ''; 970 $l_text = rawWiki($ID,''); 971 $l_head = '<a class="wikilink1" href="'.wl($ID).'">'. 972 $ID.' '.dformat((int) @filemtime(wikiFN($ID))).'</a> '. 973 $lang['current']; 974 975 $r_rev = ''; 976 $r_text = cleanText($text); 977 $r_head = $lang['yours']; 978 }else{ 979 if($rev1 && $rev2){ // two specific revisions wanted 980 // make sure order is correct (older on the left) 981 if($rev1 < $rev2){ 982 $l_rev = $rev1; 983 $r_rev = $rev2; 984 }else{ 985 $l_rev = $rev2; 986 $r_rev = $rev1; 987 } 988 }elseif($rev1){ // single revision given, compare to current 989 $r_rev = ''; 990 $l_rev = $rev1; 991 }else{ // no revision was given, compare previous to current 992 $r_rev = ''; 993 $revs = getRevisions($ID, 0, 1); 994 $l_rev = $revs[0]; 995 $REV = $l_rev; // store revision back in $REV 996 } 997 998 // when both revisions are empty then the page was created just now 999 if(!$l_rev && !$r_rev){ 1000 $l_text = ''; 1001 }else{ 1002 $l_text = rawWiki($ID,$l_rev); 1003 } 1004 $r_text = rawWiki($ID,$r_rev); 1005 1006 if(!$l_rev){ 1007 $l_head = '—'; 1008 }else{ 1009 $l_info = getRevisionInfo($ID,$l_rev,true); 1010 if($l_info['user']){ 1011 $l_user = editorinfo($l_info['user']); 1012 if(auth_ismanager()) $l_user .= ' ('.$l_info['ip'].')'; 1013 } else { 1014 $l_user = $l_info['ip']; 1015 } 1016 $l_user = '<span class="user">'.$l_user.'</span>'; 1017 $l_sum = ($l_info['sum']) ? '<span class="sum">'.hsc($l_info['sum']).'</span>' : ''; 1018 if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"'; 1019 1020 $l_head = '<a class="wikilink1" href="'.wl($ID,"rev=$l_rev").'">'. 1021 $ID.' ['.dformat($l_rev).']</a>'. 1022 '<br />'.$l_user.' '.$l_sum; 1023 } 1024 1025 if($r_rev){ 1026 $r_info = getRevisionInfo($ID,$r_rev,true); 1027 if($r_info['user']){ 1028 $r_user = editorinfo($r_info['user']); 1029 if(auth_ismanager()) $r_user .= ' ('.$r_info['ip'].')'; 1030 } else { 1031 $r_user = $r_info['ip']; 1032 } 1033 $r_user = '<span class="user">'.$r_user.'</span>'; 1034 $r_sum = ($r_info['sum']) ? '<span class="sum">'.hsc($r_info['sum']).'</span>' : ''; 1035 if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"'; 1036 1037 $r_head = '<a class="wikilink1" href="'.wl($ID,"rev=$r_rev").'">'. 1038 $ID.' ['.dformat($r_rev).']</a>'. 1039 '<br />'.$r_user.' '.$r_sum; 1040 }elseif($_rev = @filemtime(wikiFN($ID))){ 1041 $_info = getRevisionInfo($ID,$_rev,true); 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 = '<a class="wikilink1" href="'.wl($ID).'">'. 1053 $ID.' ['.dformat($_rev).']</a> '. 1054 '('.$lang['current'].')'. 1055 '<br />'.$_user.' '.$_sum; 1056 }else{ 1057 $r_head = '— ('.$lang['current'].')'; 1058 } 1059 } 1060 1061 $df = new Diff(explode("\n",htmlspecialchars($l_text)), 1062 explode("\n",htmlspecialchars($r_text))); 1063 1064 if($type == 'inline'){ 1065 $tdf = new InlineDiffFormatter(); 1066 } else { 1067 $tdf = new TableDiffFormatter(); 1068 } 1069 1070 1071 1072 if($intro) print p_locale_xhtml('diff'); 1073 1074 if (!$text) { 1075 ptln('<div class="diffoptions">'); 1076 1077 $form = new Doku_Form(array('action'=>wl())); 1078 $form->addHidden('id',$ID); 1079 $form->addHidden('rev2[0]',$l_rev); 1080 $form->addHidden('rev2[1]',$r_rev); 1081 $form->addHidden('do','diff'); 1082 $form->addElement(form_makeListboxField( 1083 'difftype', 1084 array( 1085 'sidebyside' => $lang['diff_side'], 1086 'inline' => $lang['diff_inline']), 1087 $type, 1088 $lang['diff_type'], 1089 '','', 1090 array('class'=>'quickselect'))); 1091 $form->addElement(form_makeButton('submit', 'diff','Go')); 1092 $form->printForm(); 1093 1094 1095 $diffurl = wl($ID, array( 1096 'do' => 'diff', 1097 'rev2[0]' => $l_rev, 1098 'rev2[1]' => $r_rev, 1099 'difftype' => $type, 1100 )); 1101 ptln('<p><a class="wikilink1" href="'.$diffurl.'">'.$lang['difflink'].'</a></p>'); 1102 ptln('</div>'); 1103 } 1104 ?> 1105 <table class="diff diff_<?php echo $type?>"> 1106 <tr> 1107 <th colspan="2" <?php echo $l_minor?>> 1108 <?php echo $l_head?> 1109 </th> 1110 <th colspan="2" <?php echo $r_minor?>> 1111 <?php echo $r_head?> 1112 </th> 1113 </tr> 1114 <?php echo $tdf->format($df)?> 1115 </table> 1116 <?php 1117} 1118 1119/** 1120 * show warning on conflict detection 1121 * 1122 * @author Andreas Gohr <andi@splitbrain.org> 1123 */ 1124function html_conflict($text,$summary){ 1125 global $ID; 1126 global $lang; 1127 1128 print p_locale_xhtml('conflict'); 1129 $form = new Doku_Form(array('id' => 'dw__editform')); 1130 $form->addHidden('id', $ID); 1131 $form->addHidden('wikitext', $text); 1132 $form->addHidden('summary', $summary); 1133 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s'))); 1134 $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel'])); 1135 html_form('conflict', $form); 1136 print '<br /><br /><br /><br />'.NL; 1137} 1138 1139/** 1140 * Prints the global message array 1141 * 1142 * @author Andreas Gohr <andi@splitbrain.org> 1143 */ 1144function html_msgarea(){ 1145 global $MSG, $MSG_shown; 1146 // store if the global $MSG has already been shown and thus HTML output has been started 1147 $MSG_shown = true; 1148 1149 if(!isset($MSG)) return; 1150 1151 $shown = array(); 1152 foreach($MSG as $msg){ 1153 $hash = md5($msg['msg']); 1154 if(isset($shown[$hash])) continue; // skip double messages 1155 print '<div class="'.$msg['lvl'].'">'; 1156 print $msg['msg']; 1157 print '</div>'; 1158 $shown[$hash] = 1; 1159 } 1160 1161 unset($GLOBALS['MSG']); 1162} 1163 1164/** 1165 * Prints the registration form 1166 * 1167 * @author Andreas Gohr <andi@splitbrain.org> 1168 */ 1169function html_register(){ 1170 global $lang; 1171 global $conf; 1172 global $ID; 1173 1174 print p_locale_xhtml('register'); 1175 print '<div class="centeralign">'.NL; 1176 $form = new Doku_Form(array('id' => 'dw__register')); 1177 $form->startFieldset($lang['btn_register']); 1178 $form->addHidden('do', 'register'); 1179 $form->addHidden('save', '1'); 1180 $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block', array('size'=>'50'))); 1181 if (!$conf['autopasswd']) { 1182 $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50'))); 1183 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50'))); 1184 } 1185 $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', array('size'=>'50'))); 1186 $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', array('size'=>'50'))); 1187 $form->addElement(form_makeButton('submit', '', $lang['btn_register'])); 1188 $form->endFieldset(); 1189 html_form('register', $form); 1190 1191 print '</div>'.NL; 1192} 1193 1194/** 1195 * Print the update profile form 1196 * 1197 * @author Christopher Smith <chris@jalakai.co.uk> 1198 * @author Andreas Gohr <andi@splitbrain.org> 1199 */ 1200function html_updateprofile(){ 1201 global $lang; 1202 global $conf; 1203 global $ID; 1204 global $INFO; 1205 global $auth; 1206 1207 print p_locale_xhtml('updateprofile'); 1208 1209 if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name']; 1210 if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail']; 1211 print '<div class="centeralign">'.NL; 1212 $form = new Doku_Form(array('id' => 'dw__register')); 1213 $form->startFieldset($lang['profile']); 1214 $form->addHidden('do', 'profile'); 1215 $form->addHidden('save', '1'); 1216 $form->addElement(form_makeTextField('fullname', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled'))); 1217 $attr = array('size'=>'50'); 1218 if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled'; 1219 $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', $attr)); 1220 $attr = array('size'=>'50'); 1221 if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled'; 1222 $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', $attr)); 1223 $form->addElement(form_makeTag('br')); 1224 if ($auth->canDo('modPass')) { 1225 $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50'))); 1226 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50'))); 1227 } 1228 if ($conf['profileconfirm']) { 1229 $form->addElement(form_makeTag('br')); 1230 $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50'))); 1231 } 1232 $form->addElement(form_makeButton('submit', '', $lang['btn_save'])); 1233 $form->addElement(form_makeButton('reset', '', $lang['btn_reset'])); 1234 $form->endFieldset(); 1235 html_form('updateprofile', $form); 1236 print '</div>'.NL; 1237} 1238 1239/** 1240 * Preprocess edit form data 1241 * 1242 * @author Andreas Gohr <andi@splitbrain.org> 1243 * 1244 * @triggers HTML_EDITFORM_OUTPUT 1245 */ 1246function html_edit(){ 1247 global $ID; 1248 global $REV; 1249 global $DATE; 1250 global $PRE; 1251 global $SUF; 1252 global $INFO; 1253 global $SUM; 1254 global $lang; 1255 global $conf; 1256 global $TEXT; 1257 global $RANGE; 1258 1259 if (isset($_REQUEST['changecheck'])) { 1260 $check = $_REQUEST['changecheck']; 1261 } elseif(!$INFO['exists']){ 1262 // $TEXT has been loaded from page template 1263 $check = md5(''); 1264 } else { 1265 $check = md5($TEXT); 1266 } 1267 $mod = md5($TEXT) !== $check; 1268 1269 $wr = $INFO['writable'] && !$INFO['locked']; 1270 $include = 'edit'; 1271 if($wr){ 1272 if ($REV) $include = 'editrev'; 1273 }else{ 1274 // check pseudo action 'source' 1275 if(!actionOK('source')){ 1276 msg('Command disabled: source',-1); 1277 return; 1278 } 1279 $include = 'read'; 1280 } 1281 1282 global $license; 1283 1284 $form = new Doku_Form(array('id' => 'dw__editform')); 1285 $form->addHidden('id', $ID); 1286 $form->addHidden('rev', $REV); 1287 $form->addHidden('date', $DATE); 1288 $form->addHidden('prefix', $PRE . '.'); 1289 $form->addHidden('suffix', $SUF); 1290 $form->addHidden('changecheck', $check); 1291 1292 $data = array('form' => $form, 1293 'wr' => $wr, 1294 'media_manager' => true, 1295 'target' => (isset($_REQUEST['target']) && $wr && 1296 $RANGE !== '') ? $_REQUEST['target'] : 'section', 1297 'intro_locale' => $include); 1298 1299 if ($data['target'] !== 'section') { 1300 // Only emit event if page is writable, section edit data is valid and 1301 // edit target is not section. 1302 trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true); 1303 } else { 1304 html_edit_form($data); 1305 } 1306 if (isset($data['intro_locale'])) { 1307 echo p_locale_xhtml($data['intro_locale']); 1308 } 1309 1310 $form->addHidden('target', $data['target']); 1311 $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar'))); 1312 $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl'))); 1313 $form->addElement(form_makeCloseTag('div')); 1314 if ($wr) { 1315 $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons'))); 1316 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4'))); 1317 $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5'))); 1318 $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6'))); 1319 $form->addElement(form_makeCloseTag('div')); 1320 $form->addElement(form_makeOpenTag('div', array('class'=>'summary'))); 1321 $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2'))); 1322 $elem = html_minoredit(); 1323 if ($elem) $form->addElement($elem); 1324 $form->addElement(form_makeCloseTag('div')); 1325 } 1326 $form->addElement(form_makeCloseTag('div')); 1327 if($wr && $conf['license']){ 1328 $form->addElement(form_makeOpenTag('div', array('class'=>'license'))); 1329 $out = $lang['licenseok']; 1330 $out .= ' <a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"'; 1331 if(isset($conf['target']['extern'])) $out .= ' target="'.$conf['target']['extern'].'"'; 1332 $out .= '>'.$license[$conf['license']]['name'].'</a>'; 1333 $form->addElement($out); 1334 $form->addElement(form_makeCloseTag('div')); 1335 } 1336 1337 if ($wr) { 1338 // sets changed to true when previewed 1339 echo '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'. NL; 1340 echo 'textChanged = ' . ($mod ? 'true' : 'false'); 1341 echo '//--><!]]></script>' . NL; 1342 } ?> 1343 <div style="width:99%;"> 1344 1345 <div class="toolbar"> 1346 <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div> 1347 <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']?>" 1348 target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div> 1349 1350 </div> 1351 <?php 1352 1353 html_form('edit', $form); 1354 print '</div>'.NL; 1355} 1356 1357/** 1358 * Display the default edit form 1359 * 1360 * Is the default action for HTML_EDIT_FORMSELECTION. 1361 */ 1362function html_edit_form($param) { 1363 global $TEXT; 1364 1365 if ($param['target'] !== 'section') { 1366 msg('No editor for edit target ' . $param['target'] . ' found.', -1); 1367 } 1368 1369 $attr = array('tabindex'=>'1'); 1370 if (!$param['wr']) $attr['readonly'] = 'readonly'; 1371 1372 $param['form']->addElement(form_makeWikiText($TEXT, $attr)); 1373} 1374 1375/** 1376 * Adds a checkbox for minor edits for logged in users 1377 * 1378 * @author Andreas Gohr <andi@splitbrain.org> 1379 */ 1380function html_minoredit(){ 1381 global $conf; 1382 global $lang; 1383 // minor edits are for logged in users only 1384 if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){ 1385 return false; 1386 } 1387 1388 $p = array(); 1389 $p['tabindex'] = 3; 1390 if(!empty($_REQUEST['minor'])) $p['checked']='checked'; 1391 return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p); 1392} 1393 1394/** 1395 * prints some debug info 1396 * 1397 * @author Andreas Gohr <andi@splitbrain.org> 1398 */ 1399function html_debug(){ 1400 global $conf; 1401 global $lang; 1402 global $auth; 1403 global $INFO; 1404 1405 //remove sensitive data 1406 $cnf = $conf; 1407 debug_guard($cnf); 1408 $nfo = $INFO; 1409 debug_guard($nfo); 1410 $ses = $_SESSION; 1411 debug_guard($ses); 1412 1413 print '<html><body>'; 1414 1415 print '<p>When reporting bugs please send all the following '; 1416 print 'output as a mail to andi@splitbrain.org '; 1417 print 'The best way to do this is to save this page in your browser</p>'; 1418 1419 print '<b>$INFO:</b><pre>'; 1420 print_r($nfo); 1421 print '</pre>'; 1422 1423 print '<b>$_SERVER:</b><pre>'; 1424 print_r($_SERVER); 1425 print '</pre>'; 1426 1427 print '<b>$conf:</b><pre>'; 1428 print_r($cnf); 1429 print '</pre>'; 1430 1431 print '<b>DOKU_BASE:</b><pre>'; 1432 print DOKU_BASE; 1433 print '</pre>'; 1434 1435 print '<b>abs DOKU_BASE:</b><pre>'; 1436 print DOKU_URL; 1437 print '</pre>'; 1438 1439 print '<b>rel DOKU_BASE:</b><pre>'; 1440 print dirname($_SERVER['PHP_SELF']).'/'; 1441 print '</pre>'; 1442 1443 print '<b>PHP Version:</b><pre>'; 1444 print phpversion(); 1445 print '</pre>'; 1446 1447 print '<b>locale:</b><pre>'; 1448 print setlocale(LC_ALL,0); 1449 print '</pre>'; 1450 1451 print '<b>encoding:</b><pre>'; 1452 print $lang['encoding']; 1453 print '</pre>'; 1454 1455 if($auth){ 1456 print '<b>Auth backend capabilities:</b><pre>'; 1457 print_r($auth->cando); 1458 print '</pre>'; 1459 } 1460 1461 print '<b>$_SESSION:</b><pre>'; 1462 print_r($ses); 1463 print '</pre>'; 1464 1465 print '<b>Environment:</b><pre>'; 1466 print_r($_ENV); 1467 print '</pre>'; 1468 1469 print '<b>PHP settings:</b><pre>'; 1470 $inis = ini_get_all(); 1471 print_r($inis); 1472 print '</pre>'; 1473 1474 print '</body></html>'; 1475} 1476 1477/** 1478 * List available Administration Tasks 1479 * 1480 * @author Andreas Gohr <andi@splitbrain.org> 1481 * @author Håkan Sandell <hakan.sandell@home.se> 1482 */ 1483function html_admin(){ 1484 global $ID; 1485 global $INFO; 1486 global $lang; 1487 global $conf; 1488 global $auth; 1489 1490 // build menu of admin functions from the plugins that handle them 1491 $pluginlist = plugin_list('admin'); 1492 $menu = array(); 1493 foreach ($pluginlist as $p) { 1494 if($obj =& plugin_load('admin',$p) === null) continue; 1495 1496 // check permissions 1497 if($obj->forAdminOnly() && !$INFO['isadmin']) continue; 1498 1499 $menu[$p] = array('plugin' => $p, 1500 'prompt' => $obj->getMenuText($conf['lang']), 1501 'sort' => $obj->getMenuSort() 1502 ); 1503 } 1504 1505 // data security check 1506 // @todo: could be checked and only displayed if $conf['savedir'] is under the web root 1507 echo '<a style="border:none; float:right;" 1508 href="http://www.dokuwiki.org/security#web_access_security"> 1509 <img src="data/security.png" alt="Your data directory seems to be protected properly." 1510 onerror="this.parentNode.style.display=\'none\'" /></a>'; 1511 1512 print p_locale_xhtml('admin'); 1513 1514 // Admin Tasks 1515 if($INFO['isadmin']){ 1516 ptln('<ul class="admin_tasks">'); 1517 1518 if($menu['usermanager'] && $auth && $auth->canDo('getUsers')){ 1519 ptln(' <li class="admin_usermanager"><div class="li">'. 1520 '<a href="'.wl($ID, array('do' => 'admin','page' => 'usermanager')).'">'. 1521 $menu['usermanager']['prompt'].'</a></div></li>'); 1522 } 1523 unset($menu['usermanager']); 1524 1525 if($menu['acl']){ 1526 ptln(' <li class="admin_acl"><div class="li">'. 1527 '<a href="'.wl($ID, array('do' => 'admin','page' => 'acl')).'">'. 1528 $menu['acl']['prompt'].'</a></div></li>'); 1529 } 1530 unset($menu['acl']); 1531 1532 if($menu['plugin']){ 1533 ptln(' <li class="admin_plugin"><div class="li">'. 1534 '<a href="'.wl($ID, array('do' => 'admin','page' => 'plugin')).'">'. 1535 $menu['plugin']['prompt'].'</a></div></li>'); 1536 } 1537 unset($menu['plugin']); 1538 1539 if($menu['config']){ 1540 ptln(' <li class="admin_config"><div class="li">'. 1541 '<a href="'.wl($ID, array('do' => 'admin','page' => 'config')).'">'. 1542 $menu['config']['prompt'].'</a></div></li>'); 1543 } 1544 unset($menu['config']); 1545 } 1546 ptln('</ul>'); 1547 1548 // Manager Tasks 1549 ptln('<ul class="admin_tasks">'); 1550 1551 if($menu['revert']){ 1552 ptln(' <li class="admin_revert"><div class="li">'. 1553 '<a href="'.wl($ID, array('do' => 'admin','page' => 'revert')).'">'. 1554 $menu['revert']['prompt'].'</a></div></li>'); 1555 } 1556 unset($menu['revert']); 1557 1558 if($menu['popularity']){ 1559 ptln(' <li class="admin_popularity"><div class="li">'. 1560 '<a href="'.wl($ID, array('do' => 'admin','page' => 'popularity')).'">'. 1561 $menu['popularity']['prompt'].'</a></div></li>'); 1562 } 1563 unset($menu['popularity']); 1564 1565 // print DokuWiki version: 1566 ptln('</ul>'); 1567 echo '<div id="admin__version">'; 1568 echo getVersion(); 1569 echo '</div>'; 1570 1571 // print the rest as sorted list 1572 if(count($menu)){ 1573 usort($menu, 'p_sort_modes'); 1574 // output the menu 1575 ptln('<div class="clearer"></div>'); 1576 print p_locale_xhtml('adminplugins'); 1577 ptln('<ul>'); 1578 foreach ($menu as $item) { 1579 if (!$item['prompt']) continue; 1580 ptln(' <li><div class="li"><a href="'.wl($ID, 'do=admin&page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>'); 1581 } 1582 ptln('</ul>'); 1583 } 1584} 1585 1586/** 1587 * Form to request a new password for an existing account 1588 * 1589 * @author Benoit Chesneau <benoit@bchesneau.info> 1590 */ 1591function html_resendpwd() { 1592 global $lang; 1593 global $conf; 1594 global $ID; 1595 1596 print p_locale_xhtml('resendpwd'); 1597 print '<div class="centeralign">'.NL; 1598 $form = new Doku_Form(array('id' => 'dw__resendpwd')); 1599 $form->startFieldset($lang['resendpwd']); 1600 $form->addHidden('do', 'resendpwd'); 1601 $form->addHidden('save', '1'); 1602 $form->addElement(form_makeTag('br')); 1603 $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block')); 1604 $form->addElement(form_makeTag('br')); 1605 $form->addElement(form_makeTag('br')); 1606 $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd'])); 1607 $form->endFieldset(); 1608 html_form('resendpwd', $form); 1609 print '</div>'.NL; 1610} 1611 1612/** 1613 * Return the TOC rendered to XHTML 1614 * 1615 * @author Andreas Gohr <andi@splitbrain.org> 1616 */ 1617function html_TOC($toc){ 1618 if(!count($toc)) return ''; 1619 global $lang; 1620 $out = '<!-- TOC START -->'.DOKU_LF; 1621 $out .= '<div class="toc">'.DOKU_LF; 1622 $out .= '<div class="tocheader toctoggle" id="toc__header">'; 1623 $out .= $lang['toc']; 1624 $out .= '</div>'.DOKU_LF; 1625 $out .= '<div id="toc__inside">'.DOKU_LF; 1626 $out .= html_buildlist($toc,'toc','html_list_toc'); 1627 $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF; 1628 $out .= '<!-- TOC END -->'.DOKU_LF; 1629 return $out; 1630} 1631 1632/** 1633 * Callback for html_buildlist 1634 */ 1635function html_list_toc($item){ 1636 if(isset($item['hid'])){ 1637 $link = '#'.$item['hid']; 1638 }else{ 1639 $link = $item['link']; 1640 } 1641 1642 return '<span class="li"><a href="'.$link.'" class="toc">'. 1643 hsc($item['title']).'</a></span>'; 1644} 1645 1646/** 1647 * Helper function to build TOC items 1648 * 1649 * Returns an array ready to be added to a TOC array 1650 * 1651 * @param string $link - where to link (if $hash set to '#' it's a local anchor) 1652 * @param string $text - what to display in the TOC 1653 * @param int $level - nesting level 1654 * @param string $hash - is prepended to the given $link, set blank if you want full links 1655 */ 1656function html_mktocitem($link, $text, $level, $hash='#'){ 1657 global $conf; 1658 return array( 'link' => $hash.$link, 1659 'title' => $text, 1660 'type' => 'ul', 1661 'level' => $level); 1662} 1663 1664/** 1665 * Output a Doku_Form object. 1666 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT 1667 * 1668 * @author Tom N Harris <tnharris@whoopdedo.org> 1669 */ 1670function html_form($name, &$form) { 1671 // Safety check in case the caller forgets. 1672 $form->endFieldset(); 1673 trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false); 1674} 1675 1676/** 1677 * Form print function. 1678 * Just calls printForm() on the data object. 1679 */ 1680function html_form_output($data) { 1681 $data->printForm(); 1682} 1683 1684/** 1685 * Embed a flash object in HTML 1686 * 1687 * This will create the needed HTML to embed a flash movie in a cross browser 1688 * compatble way using valid XHTML 1689 * 1690 * The parameters $params, $flashvars and $atts need to be associative arrays. 1691 * No escaping needs to be done for them. The alternative content *has* to be 1692 * escaped because it is used as is. If no alternative content is given 1693 * $lang['noflash'] is used. 1694 * 1695 * @author Andreas Gohr <andi@splitbrain.org> 1696 * @link http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml 1697 * 1698 * @param string $swf - the SWF movie to embed 1699 * @param int $width - width of the flash movie in pixels 1700 * @param int $height - height of the flash movie in pixels 1701 * @param array $params - additional parameters (<param>) 1702 * @param array $flashvars - parameters to be passed in the flashvar parameter 1703 * @param array $atts - additional attributes for the <object> tag 1704 * @param string $alt - alternative content (is NOT automatically escaped!) 1705 * @returns string - the XHTML markup 1706 */ 1707function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){ 1708 global $lang; 1709 1710 $out = ''; 1711 1712 // prepare the object attributes 1713 if(is_null($atts)) $atts = array(); 1714 $atts['width'] = (int) $width; 1715 $atts['height'] = (int) $height; 1716 if(!$atts['width']) $atts['width'] = 425; 1717 if(!$atts['height']) $atts['height'] = 350; 1718 1719 // add object attributes for standard compliant browsers 1720 $std = $atts; 1721 $std['type'] = 'application/x-shockwave-flash'; 1722 $std['data'] = $swf; 1723 1724 // add object attributes for IE 1725 $ie = $atts; 1726 $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'; 1727 1728 // open object (with conditional comments) 1729 $out .= '<!--[if !IE]> -->'.NL; 1730 $out .= '<object '.buildAttributes($std).'>'.NL; 1731 $out .= '<!-- <![endif]-->'.NL; 1732 $out .= '<!--[if IE]>'.NL; 1733 $out .= '<object '.buildAttributes($ie).'>'.NL; 1734 $out .= ' <param name="movie" value="'.hsc($swf).'" />'.NL; 1735 $out .= '<!--><!-- -->'.NL; 1736 1737 // print params 1738 if(is_array($params)) foreach($params as $key => $val){ 1739 $out .= ' <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL; 1740 } 1741 1742 // add flashvars 1743 if(is_array($flashvars)){ 1744 $out .= ' <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL; 1745 } 1746 1747 // alternative content 1748 if($alt){ 1749 $out .= $alt.NL; 1750 }else{ 1751 $out .= $lang['noflash'].NL; 1752 } 1753 1754 // finish 1755 $out .= '</object>'.NL; 1756 $out .= '<!-- <![endif]-->'.NL; 1757 1758 return $out; 1759} 1760 1761