Newer
Older
/**
* HTML output functions
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Andreas Gohr <andi@splitbrain.org>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
function html_wikilink($id,$name=NULL,$search=''){
static $xhtml_renderer = NULL;
if(is_null($xhtml_renderer)){
require_once(DOKU_INC.'inc/parser/xhtml.php');
return $xhtml_renderer->internallink($id,$name,$search,true);
/**
* Helps building long attribute lists
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function html_attbuild($attributes){
$ret = '';
foreach ( $attributes as $key => $value ) {
$ret .= $key.'="'.formtext($value).'" ';
}
return trim($ret);
}
*/
function html_login(){
global $lang;
global $conf;
global $ID;
<form action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>" method="post">
<legend><?php echo $lang['btn_login']?></legend>
<input type="hidden" name="id" value="<?php echo $ID?>" />
<span><?php echo $lang['user']?></span>
<input type="text" name="u" value="<?php echo formText($_REQUEST['u'])?>" class="edit" />
<input type="password" name="p" class="edit" />
</label><br />
<input type="submit" value="<?php echo $lang['btn_login']?>" class="button" />
<input type="checkbox" name="r" id="remember__me" value="1" />
if($auth->canDo('addUser') && $conf['openregister']){
print '<p>';
print $lang['reghere'];
print ': <a href="'.wl($ID,'do=register').'" class="wikilink1">'.$lang['register'].'</a>';
print '</p>';
}
chris
committed
if ($auth->canDo('modPass') && $conf['resendpasswd']) {
chris
committed
print '<p>';
print $lang['pwdforget'];
print ': <a href="'.wl($ID,'do=resendpwd').'" class="wikilink1">'.$lang['btn_resendpwd'].'</a>';
chris
committed
print '</p>';
}
if(@file_exists('includes/login.txt')){
print io_cacheParse('includes/login.txt');
}
}
/**
* shows the edit/source/show button dependent on current mode
*/
function html_editbutton(){
global $ID;
global $REV;
global $ACT;
global $INFO;
if($ACT == 'show' || $ACT == 'search'){
if($INFO['writable']){
if($INFO['exists']){
$r = html_btn('edit',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
}else{
$r = html_btn('create',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
}
}else{
$r = html_btn('source',$ID,'v',array('do' => 'edit','rev' => $REV),'post');
}
}else{
$r = html_btn('show',$ID,'v',array('do' => 'show'));
}
return $r;
}
/**
* prints a section editing button
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function html_secedit_button($section,$p){
global $ID;
global $lang;
$secedit = '';
$secedit .= '<div class="secedit">';
$secedit .= html_btn('secedit',$ID,'',
array('do' => 'edit',
'lines' => "$section"),
'post');
$secedit .= '</div>';
/**
* inserts section edit buttons if wanted or removes the markers
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
if($INFO['writable'] && $show && !$INFO['rev']){
$text = preg_replace('#<!-- SECTION \[(\d+-\d+)\] -->#e',
"html_secedit_button('\\1',true)",
$text);
$text = preg_replace('#<!-- SECTION \[(\d+-)\] -->#e',
"html_secedit_button('\\1',false)",
$text);
}else{
$text = preg_replace('#<!-- SECTION \[(\d*-\d*)\] -->#e','',$text);
}
return $text;
}
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function html_topbtn(){
global $lang;
$ret = '';
$ret = '<a href="#dokuwiki__top"><input type="button" class="button" value="'.$lang['btn_top'].'" onclick="window.scrollTo(0, 0)" /></a>';
* Just the back to media window button in its own form
*
* @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
*/
function html_backtomedia_button($params,$akey=''){
global $conf;
global $lang;
$ret = '<form class="button" method="get" action="'.DOKU_BASE.'lib/exe/media.php"><div class="no">';
reset($params);
while (list($key, $val) = each($params)) {
$ret .= '<input type="hidden" name="'.$key.'" ';
$ret .= 'value="'.htmlspecialchars($val).'" />';
}
$ret .= '<input type="submit" value="'.htmlspecialchars($lang['btn_backtomedia']).'" class="button" ';
if($akey){
$ret .= 'title="ALT+'.strtoupper($akey).'" ';
$ret .= 'accesskey="'.$akey.'" ';
}
$ret .= '/>';
return $ret;
}
/**
* Displays a button (using its own form)
*/
function html_btn($name,$id,$akey,$params,$method='get'){
global $conf;
global $lang;
//filter id (without urlencoding)
$id = idfilter($id,false);
if($conf['userewrite'] == 2){
$script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
}elseif($conf['userewrite']){
$script = DOKU_BASE.$id;
}else{
$ret .= '<form class="button" method="'.$method.'" action="'.$script.'"><div class="no">';
if(is_array($params)){
reset($params);
while (list($key, $val) = each($params)) {
$ret .= '<input type="hidden" name="'.$key.'" ';
$ret .= 'value="'.htmlspecialchars($val).'" />';
}
$ret .= '<input type="submit" value="'.htmlspecialchars($label).'" class="button" ';
if($akey){
$ret .= 'title="ALT+'.strtoupper($akey).'" ';
$ret .= 'accesskey="'.$akey.'" ';
}
$ret .= '/>';
/**
* show a wiki page
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
global $ID;
global $REV;
global $HIGH;
//disable section editing for old revisions or in preview
print html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
if ($REV) print p_locale_xhtml('showrev');
$html = p_wiki_xhtml($ID,$REV,true);
print html_hilight($html,$HIGH);
}
}
/**
* Highlights searchqueries in HTML code
* @author Harry Fuecks <hfuecks@gmail.com>
$queries = preg_split ('/[\s\'"\\\\`()\]\[?:!\.{};,#+*<>\\/]+/',$query,-1,PREG_SPLIT_NO_EMPTY);
$q = preg_quote($q,'/');
$html = preg_replace_callback("/((<[^>]*)|$q)/i",'html_hilight_callback',$html);
* Callback used by html_hilight()
*
* @author Harry Fuecks <hfuecks@gmail.com>
function html_hilight_callback($m) {
$hlight = unslash($m[0]);
if ( !isset($m[2])) {
$hlight = '<span class="search_hit">'.$hlight.'</span>';
}
return $hlight;
}
* Run a search and display the result
*
* @author Andreas Gohr <andi@splitbrain.org>
require_once(DOKU_INC.'inc/search.php');
global $conf;
global $QUERY;
global $ID;
global $lang;
print '<div class="centeralign" id="dw__loading">';
print '<br /></div>';
print '<script type="text/javascript" charset="utf-8">';
print 'showLoadBar("dw__loading");';
if(count($data)){
sort($data);
print '<div class="search_quickresult">';
print '<h3>'.$lang[quickhits].':</h3>';
print html_wikilink(':'.$id,$conf['useheading']?NULL:$id);
//clear float (see http://www.complexspiral.com/publications/containing-floats/)
print '<div class="clearer"> </div>';
print '</div>';
}
flush();
//do fulltext search
$num = 1;
foreach($data as $id => $cnt){
print html_wikilink(':'.$id,$conf['useheading']?NULL:$id,$poswords);
print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />';
if($num < 15){ // create snippets for the first number of matches only #FIXME add to conf ?
print '<div class="search_snippet">'.ft_snippet($id,$poswords).'</div>';
}
print '<div class="nothing">'.$lang['nothingfound'].'</div>';
print '<script type="text/javascript" charset="utf-8">';
print 'hideLoadBar("dw__loading");';
/**
* Display error on locked pages
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
$locktime = filemtime(wikiFN($ID).'.lock');
$expire = @date($conf['dformat'], $locktime + $conf['locktime'] );
$min = round(($conf['locktime'] - (time() - $locktime) )/60);
print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.$INFO['locked'].'</li>';
print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>';
/**
* list old revisions
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function html_revisions(){
global $ID;
global $INFO;
global $conf;
global $lang;
print ($INFO['minor']) ? '<li class="minor">' : '<li>';
print ' <img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" /> ';
print '<a class="wikilink1" href="'.wl($ID).'">'.$ID.'</a> ';
print ' <span class="user">';
print $INFO['editor'];
print '</span> ';
}
foreach($revisions as $rev){
$date = date($conf['dformat'],$rev);
print ($info['minor']) ? '<li class="minor">' : '<li>';
print $date;
print ' <a href="'.wl($ID,"rev=$rev,do=diff").'">';
$p = array();
$p['src'] = DOKU_BASE.'lib/images/diff.png';
$p['width'] = 15;
$p['height'] = 11;
$p['title'] = $lang['diff'];
$p['alt'] = $lang['diff'];
$att = buildAttributes($p);
print "<img $att />";
print '<a class="wikilink1" href="'.wl($ID,"rev=$rev").'">'.$ID.'</a> ';
print ' <span class="user">';
if($info['user']){
print $info['user'];
}else{
print $info['ip'];
}
print '</span>';
/**
* display recent changes
*
* @author Andreas Gohr <andi@splitbrain.org>
* @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
/* we need to get one additionally log entry to be able to
* decide if this is the last page or is there another one.
* This is the cheapest solution to get this information.
*/
$recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
if(count($recents) == 0 && $first != 0){
$first=0;
$recents = getRecents(0,$conf['recent'] + 1,getNS($ID));
$cnt = count($recents) <= $conf['recent'] ? count($recents) : $conf['recent'];
foreach($recents as $recent){
$date = date($conf['dformat'],$recent['date']);
print ($recent['minor']) ? '<li class="minor">' : '<li>';
print '<a href="'.wl($recent['id'],"do=diff").'">';
$p = array();
$p['src'] = DOKU_BASE.'lib/images/diff.png';
$p['width'] = 15;
$p['height'] = 11;
$p['title'] = $lang['diff'];
$p['alt'] = $lang['diff'];
$att = buildAttributes($p);
print "<img $att />";
print '<a href="'.wl($recent['id'],"do=revisions").'">';
$p = array();
$p['src'] = DOKU_BASE.'lib/images/history.png';
$p['width'] = 12;
$p['height'] = 14;
$p['title'] = $lang['btn_revs'];
$p['alt'] = $lang['btn_revs'];
$att = buildAttributes($p);
print "<img $att />";
print html_wikilink(':'.$recent['id'],$conf['useheading']?NULL:$recent['id']);
print ' '.htmlspecialchars($recent['sum']);
if($recent['user']){
print $recent['user'];
if ($first < 0) $first = 0;
print '<div class="pagenav-prev">';
print html_btn('newer','',"p",array('do' => 'recent', 'first' => $first));
if ($conf['recent'] < count($recents)) {
print html_btn('older','',"n",array('do' => 'recent', 'first' => $last));
/**
* Display page index
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
require_once(DOKU_INC.'inc/search.php');
global $conf;
global $ID;
$dir = $conf['datadir'];
$ns = cleanID($ns);
if(empty($ns)){
$ns = dirname(str_replace(':','/',$ID));
if($ns == '.') $ns ='';
}
$ns = utf8_encodeFN(str_replace(':','/',$ns));
$data = array();
search($data,$conf['datadir'],'search_index',array('ns' => $ns));
*/
function html_list_index($item){
$ret = '';
$base = ':'.$item['id'];
$base = substr($base,strrpos($base,':')+1);
if($item['type']=='d'){
$ret .= '<a href="'.wl($ID,'idx='.$item['id']).'" class="idx_dir">';
$ret .= $base;
$ret .= '</a>';
}else{
$ret .= html_wikilink(':'.$item['id']);
}
return $ret;
}
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
/**
* Index List item
*
* This user function is used in html_build_lidt to build the
* <li> tags for namespaces when displaying the page index
* it gives different classes to opened or closed "folders"
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function html_li_index($item){
if($item['type'] == "f"){
return '<li class="level'.$item['level'].'">';
}elseif($item['open']){
return '<li class="open">';
}else{
return '<li class="closed">';
}
}
/**
* Default List item
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function html_li_default($item){
return '<li class="level'.$item['level'].'">';
}
* Build an unordered list from the given $data array
* Each item in the array has to have a 'level' property
* the item itself gets printed by the given $func user
* function. The second and optional function is used to
* print the <li> tag. Both user function need to accept
* a single item.
* Both user functions can be given as array to point to
* a member of an object.
*
function html_buildlist($data,$class,$func,$lifunc='html_li_default'){
$level = 0;
$opens = 0;
$ret = '';
foreach ($data as $item){
if( $item['level'] > $level ){
//open new list
for($i=0; $i<($item['level'] - $level); $i++){
if ($i) $ret .= "<li class=\"clear\">\n";
$ret .= "\n<ul class=\"$class\">\n";
}
}elseif( $item['level'] < $level ){
//close last item
$ret .= "</li>\n";
for ($i=0; $i<($level - $item['level']); $i++){
//close higher lists
$ret .= "</ul>\n</li>\n";
}
}else{
//close last item
$ret .= "</li>\n";
}
if(is_array($lifunc)){
$ret .= $lifunc[0]->$lifunc[1]($item); //user object method
}else{
$ret .= $lifunc($item); //user function
}
if(is_array($func)){
$ret .= $func[0]->$func[1]($item); //user object method
}else{
}
//close remaining items and lists
for ($i=0; $i < $level; $i++){
$ret .= "</li></ul>\n";
}
return $ret;
}
/**
* display backlinks
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
require_once(DOKU_INC.'inc/fulltext.php');
print html_wikilink(':'.$blink,$conf['useheading']?NULL:$blink);
/**
* show diff
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
require_once(DOKU_INC.'inc/DifferenceEngine.php');
global $ID;
global $REV;
global $lang;
global $conf;
if($text){
$df = new Diff(split("\n",htmlspecialchars(rawWiki($ID,''))),
split("\n",htmlspecialchars(cleanText($text))));
$left = '<a class="wikilink1" href="'.wl($ID).'">'.
$ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a>'.
$lang['current'];
$right = $lang['yours'];
}else{
if($REV){
$r = $REV;
}else{
//use last revision if none given
$revs = getRevisions($ID);
$r = $revs[0];
}
$df = new Diff(split("\n",htmlspecialchars(rawWiki($ID,$r))),
$left = '<a class="wikilink1" href="'.wl($ID,"rev=$r").'">'.
$ID.' '.date($conf['dformat'],$r).'</a>';
$right = '<a class="wikilink1" href="'.wl($ID).'">'.
$ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a> '.
$lang['current'];
}
$tdf = new TableDiffFormatter();
<table class="diff">
</th>
<th colspan="2">
/**
* show warning on conflict detection
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function html_conflict($text,$summary){
global $ID;
global $lang;
Anika Henke
committed
<form id="dw__editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>">
<div class="centeralign">
<input type="hidden" name="id" value="<?php echo $ID?>" />
<input type="hidden" name="wikitext" value="<?php echo formText($text)?>" />
<input type="hidden" name="summary" value="<?php echo formText($summary)?>" />
<input class="button" type="submit" name="do" value="<?php echo $lang['btn_save']?>" accesskey="s" title="[ALT+S]" />
<input class="button" type="submit" name="do" value="<?php echo $lang['btn_cancel']?>" />
* Prints the global message array
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function html_msgarea(){
global $MSG;
if(!isset($MSG)) return;
foreach($MSG as $msg){
print '<div class="'.$msg['lvl'].'">';
print $msg['msg'];
print '</div>';
}
}
/**
* Prints the registration form
Anika Henke
committed
<form id="dw__register" method="post" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>">
<input type="hidden" name="do" value="register" />
<input type="hidden" name="save" value="1" />
<?php echo $lang['user']?>
<input type="text" name="login" class="edit" size="50" value="<?php echo formText($_POST['login'])?>" />
<?php
if (!$conf['autopasswd']) {
?>
<input type="password" name="pass" class="edit" size="50" />
</label><br />
<input type="password" name="passchk" class="edit" size="50" />
</label><br />
<?php
}
?>
<?php echo $lang['fullname']?>
<input type="text" name="fullname" class="edit" size="50" value="<?php echo formText($_POST['fullname'])?>" />
<?php echo $lang['email']?>
<input type="text" name="email" class="edit" size="50" value="<?php echo formText($_POST['email'])?>" />
<input type="submit" class="button" value="<?php echo $lang['register']?>" />
chris
committed
/**
* Print the update profile form
*
* @author Christopher Smith <chris@jalakai.co.uk>
* @author Andreas Gohr <andi@splitbrain.org>
*/
function html_updateprofile(){
global $lang;
global $conf;
global $ID;
global $INFO;
chris
committed
print p_locale_xhtml('updateprofile');
chris
committed
if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
?>
Anika Henke
committed
<form id="dw__register" method="post" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>">
chris
committed
<fieldset style="width: 80%;">
<input type="hidden" name="do" value="profile" />
<input type="hidden" name="save" value="1" />
chris
committed
<legend><?php echo $lang['profile']?></legend>
<label class="block">
<?php echo $lang['user']?>
<input type="text" name="fullname" disabled="disabled" class="edit" size="50" value="<?php echo formText($_SERVER['REMOTE_USER'])?>" />
chris
committed
<label class="block">
<?php echo $lang['fullname']?>
<input type="text" name="fullname" <?php if(!$auth->canDo('modName')) echo 'disabled="disabled"'?> class="edit" size="50" value="<?php echo formText($_POST['fullname'])?>" />
chris
committed
</label><br />
<label class="block">
<?php echo $lang['email']?>
<input type="text" name="email" <?php if(!$auth->canDo('modName')) echo 'disabled="disabled"'?> class="edit" size="50" value="<?php echo formText($_POST['email'])?>" />
chris
committed
</label><br /><br />
<?php if($auth->canDo('modPass')) { ?>
chris
committed
<label class="block">
<?php echo $lang['newpass']?>
<input type="password" name="newpass" class="edit" size="50" />
</label><br />
<label class="block">
<?php echo $lang['passchk']?>
<input type="password" name="passchk" class="edit" size="50" />
</label><br />
chris
committed
<?php if ($conf['profileconfirm']) { ?>
<br />
<label class="block">
<?php echo $lang['oldpass']?>
<input type="password" name="oldpass" class="edit" size="50" />
chris
committed
</label><br />
<?php } ?>
<input type="submit" class="button" value="<?php echo $lang['btn_save']?>" />
chris
committed
<input type="reset" class="button" value="<?php echo $lang['btn_reset']?>" />
</fieldset>
</form>
</div>
<?php
}
* @fixme this is a huge lump of code and should be modularized
*/
function html_edit($text=null,$include='edit'){ //FIXME: include needed?
global $ID;
global $REV;
global $DATE;
global $RANGE;
global $PRE;
global $SUF;
global $INFO;
global $SUM;
global $lang;
global $conf;
//set summary default
if(!$SUM){
if($REV){
$SUM = $lang['restored'];
}elseif(!$INFO['exists']){
$SUM = $lang['created'];
}
}
//no text? Load it!
if(!isset($text)){
$pr = false; //no preview mode
if($INFO['exists']){
if($RANGE){
list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
}else{
$text = rawWiki($ID,$REV);
}
//try to load a pagetemplate
$text = pageTemplate($ID);
}
}else{
$pr = true; //preview mode
}
$wr = $INFO['writable'];
if($wr){
if ($REV) print p_locale_xhtml('editrev');
print p_locale_xhtml($include);
$ro='readonly="readonly"';
}
if(!$DATE) $DATE = $INFO['lastmod'];
<div style="width:99%;">
<form id="dw__editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>"><div class="no">