diff options
Diffstat (limited to 'inc')
-rw-r--r-- | inc/actions.php | 192 | ||||
-rw-r--r-- | inc/common.php | 2 | ||||
-rw-r--r-- | inc/html.php | 17 | ||||
-rw-r--r-- | inc/init.php | 6 | ||||
-rw-r--r-- | inc/template.php | 314 |
5 files changed, 529 insertions, 2 deletions
diff --git a/inc/actions.php b/inc/actions.php new file mode 100644 index 000000000..345ef8e37 --- /dev/null +++ b/inc/actions.php @@ -0,0 +1,192 @@ +<?php +/** + * DokuWiki Actions + * + * @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__).'/../').'/'); + require_once(DOKU_INC.'inc/template.php'); + +/** + * Call the needed action handlers + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function act_dispatch(){ + global $INFO; + global $ACT; + global $ID; + global $QUERY; + global $lang; + global $conf; + + //check permissions + $ACT = act_permcheck($ACT); + + //login stuff + if(in_array($ACT,array('login','logout','register'))) + $ACT = act_login($ACT); + + //save + if($ACT == 'save') + $ACT = act_save($ACT); + + //edit + if(($ACT == 'edit' || $ACT == $lang['btn_preview']) && $INFO['editable']){ + $ACT = act_save($ACT); + }else{ + unlock($ID); //try to unlock + } + + //handle export + if(substr($ACT,0,6) == 'export') + $ACT = act_export($ACT); + + //display some infos + if($ACT == 'check'){ + check(); + $ACT = 'show'; + } + + //check if searchword was given - else just show + if($ACT == 'search' && empty($QUERY)){ + $ACT = 'show'; + } + + //fixme sanitize $ACT + + //call template FIXME: all needed vars available? + header('Content-Type: text/html; charset=utf-8'); + include(DOKU_INC.'tpl/'.$conf['template'].'/main.php'); +} + +/** + * Run permissionchecks + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function act_permcheck($act){ + if(in_array($act,array('save','preview','edit'))){ + if($INFO['exists']){ + $permneed = AUTH_EDIT; + }else{ + $permneed = AUTH_CREATE; + } + }elseif(in_array($act,array('login','register','search','recent'))){ + $permneed = AUTH_NONE; + }else{ + $permneed = AUTH_READ; + } + if(! auth_quickaclcheck($ID) >= $permneed){ + return 'denied'; + } + + return $act; +} + +/** + * Handle 'save' + * + * Checks for spam and conflicts and saves the page. + * Does a redirect to show the page afterwards or + * returns a new action. + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function act_save($act){ + global $ID; + global $DATE; + global $PRE; + global $TEXT; + global $SUF; + global $SUM; + + //spam check + if(checkwordblock()) + return 'wordblock'; + //conflict check //FIXME use INFO + if($DATE != 0 && @filemtime(wikiFN($ID)) > $DATE ) + return 'conflict'; + + //save it + saveWikiText($ID,con($PRE,$TEXT,$SUF,1),$SUM); //use pretty mode for con + //unlock it + unlock($ID); + + //show it + session_write_close(); + header("Location: ".wl($ID,'',true)); + exit(); +} + +/** + * Handle 'login', 'logout', 'register' + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function act_auth($act){ + //already logged in? + if($_SERVER['REMOTE_USER'] && $act=='login') + return 'show'; + + //handle logout + if($act=='logout'){ + auth_logoff(); + return 'login'; + } + + //handle register + if($act=='register' && register()){ + $act='login'; + } + + return $act; +} + +/** + * Handle 'edit', 'preview' + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function act_edit($act){ + //check if locked by anyone - if not lock for my self + $lockedby = checklock($ID); + if($lockedby) return 'locked'; + + lock($ID); + return $act; +} + +/** + * Handle 'edit', 'preview' + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function act_export($act){ + global $ID; + global $REV; + + if($act == 'export_html'){ + header('Content-Type: text/html; charset=utf-8'); + ptln('<html>'); + ptln('<head>'); + tpl_metaheaders(); + ptln('</head>'); + ptln('<body>'); + print parsedWiki($ID,$REV,false); + ptln('</body>'); + ptln('</html>'); + exit; + } + + if($act == 'export_raw'){ + header('Content-Type: text/plain; charset=utf-8'); + print rawWiki($ID,$REV); + exit; + } + + return 'show'; +} +?> diff --git a/inc/common.php b/inc/common.php index b06896f4d..482bb1e2d 100644 --- a/inc/common.php +++ b/inc/common.php @@ -369,7 +369,6 @@ function cleanID($id){ if($conf['deaccent']) $id = utf8_deaccent($id,-1); //remove specials - //$id = preg_replace('#[\x00-\x20 ¡!"§$%&()\[\]{}¿\\?`\'\#~*+=,<>\|^°@µ¹²³¼½¬]#u','_',$id); $id = utf8_stripspecials($id,'_','_:.-'); //clean up @@ -815,6 +814,7 @@ function download($url,$file){ /** * extracts the query from a google referer * + * @todo should be more generic and support yahoo et al * @author Andreas Gohr <andi@splitbrain.org> */ function getGoogleQuery(){ diff --git a/inc/html.php b/inc/html.php index 36bd25e2f..85e3189ea 100644 --- a/inc/html.php +++ b/inc/html.php @@ -147,6 +147,7 @@ function html_secedit($text,$show=true){ /** * displays the breadcrumbs trace * + * @deprecated * @author Andreas Gohr <andi@splitbrain.org> */ function html_breadcrumbs(){ @@ -169,6 +170,7 @@ function html_breadcrumbs(){ /** * display the HTML head and metadata * + * @deprecated -> tpl_metaheaders() * @author Andreas Gohr <andi@splitbrain.org> */ function html_head(){ @@ -231,6 +233,21 @@ function html_head(){ } /** + * Just the back to top button (in it's own form) + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function html_topbtn(){ + global $lang; + + $ret = ''; + $ret .= '<form class="button" method="get" action="#top" onsubmit="return svchk()">'; + $ret .= '<input type="submit" value="'.htmlspecialchars($lang['btn_top']).'" class="button" '; + $ret .= '</form>'; + return $ret; +} + +/** * Displays a button (using it's own form) * * @author Andreas Gohr <andi@splitbrain.org> diff --git a/inc/init.php b/inc/init.php index 46046ab29..abedbfbbf 100644 --- a/inc/init.php +++ b/inc/init.php @@ -20,6 +20,10 @@ // define main script if(!defined('DOKU_SCRIPT')) define('DOKU_SCRIPT','doku.php'); + // define Template baseURL + if(!defined('DOKU_TPL')) define('DOKU_TPL', + DOKU_BASE.'tpl/'.$conf['template'].'/'); + // set up error reporting to sane values error_reporting(E_ALL ^ E_NOTICE); @@ -28,7 +32,7 @@ // init session session_name("DokuWiki"); - session_start(); + if (!headers_sent()) session_start(); // kill magic quotes if (get_magic_quotes_gpc()) { diff --git a/inc/template.php b/inc/template.php new file mode 100644 index 000000000..00de7ad67 --- /dev/null +++ b/inc/template.php @@ -0,0 +1,314 @@ +<?php +/** + * DokuWiki template 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__).'/../').'/'); + require_once(DOKU_INC.'conf/dokuwiki.php'); + +/** + * Wrapper around htmlspecialchars() + * + * @author Andreas Gohr <andi@splitbrain.org> + * @see htmlspecialchars() + */ +function hsc($string){ + return htmlspecialchars($string); +} + +/** + * print a newline terminated string + * + * You can give an indention as optional parameter + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function ptln($string,$intend=0){ + for($i=0; $i<$intend; $i++) print ' '; + print"$string\n"; +} + +/** + * Print the content + * + * This function is used for printing all the usual content + * (defined by the global $ACT var) by calling the appropriate + * outputfunction(s) from html.php + * + * Everything that doesn't use the default template isn't + * handled by this function. ACL stuff is not done either. + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function tpl_content(){ + global $ACT; + global $TEXT; + global $PRE; + global $SUF; + global $SUM; + global $IDX; + global $lang; + + switch($ACT){ + case 'show': + html_show(); + break; + case $lang['btn_preview']: + html_edit($TEXT); + html_show($TEXT); + break; + case 'edit': + html_edit(); + break; + case 'wordblock': + html_edit($TEXT,'wordblock'); + break; + case 'search': + html_search(); + break; + case 'revisions': + html_revisions(); + break; + case 'diff': + html_diff(); + break; + case 'recent': + html_recent(); + break; + case 'index': + html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly? + break; + case 'backlink': + html_backlinks(); + break; + case 'conflict': + html_conflict(con($PRE,$TEXT,$SUF),$SUM); + html_diff(con($PRE,$TEXT,$SUF),false); + break; + case 'locked': + html_locked($lockedby); + break; + case 'login': + html_login(); + break; + case 'register': + #FIXME check for $conf['openregister']) needs to be done first!! + html_register(); + break; + default: + print "Uhm... Where am I? This shouldn't happen"; + } +} + + + +/** + * Print the correct HTML meta headers + * + * This has to go into the head section of your template. + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function tpl_metaheaders(){ + global $ID; + global $INFO; + global $ACT; + global $lang; + $it=2; + + // the usual stuff + ptln('<meta name="generator" content="DokuWiki '.getVersion().'" />',$it); + ptln('<link rel="start" href="'.DOKU_BASE.'" />',$it); + ptln('<link rel="contents" href="'.wl($ID,'do=index').'" title="'.$lang['index'].'" />',$it); + ptln('<link rel="alternate" type="application/rss+xml" title="Recent Changes" href="'.DOKU_BASE.'feed.php" />',$it); + ptln('<link rel="alternate" type="application/rss+xml" title="Current Namespace" href="'.DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace'].'" />',$it); + ptln('<link rel="alternate" type="text/html" title="Plain HTML" href="'.wl($ID,'do=export_html').'" />',$it); + ptln('<link rel="alternate" type="text/plain" title="Wiki Markup" href="'.wl($ID, 'do=export_raw').'" />',$it); + ptln('<link rel="stylesheet" media="screen" type="text/css" href="'.DOKU_BASE.'style.css" />',$it); + + // setup robot tags apropriate for different modes + if( ($ACT=='show' || $ACT=='export_html') && !$REV){ + if($INFO['exists']){ + ptln('<meta name="date" content="'.date('Y-m-d\TH:i:sO',$INFO['lastmod']).'" />',$it); + //delay indexing: + if((time() - $INFO['lastmod']) >= $conf['indexdelay']){ + ptln('<meta name="robots" content="index,follow" />',$it); + }else{ + ptln('<meta name="robots" content="noindex,nofollow" />',$it); + } + }else{ + ptln('<meta name="robots" content="noindex,follow" />',$it); + } + }else{ + ptln('<meta name="robots" content="noindex,nofollow" />',$it); + } + + // include some JavaScript language strings + ptln('<script language="JavaScript" type="text/javascript">',$it); + ptln(" var alertText = '".$lang['qb_alert']."'",$it); + ptln(" var notSavedYet = '".$lang['notsavedyet']."'",$it); + ptln(" var DOKU_BASE = '".DOKU_BASE."'",$it); + ptln('</script>',$it); + + // load the default JavaScript file + ptln('<script language="JavaScript" type="text/javascript" src="'.DOKU_BASE.'script.js"></script>',$it); + + + //FIXME include some default CSS ? IE FIX? +} + +/** + * Print a link + * + * Just builds a link but adds additional JavaScript needed for + * the unsaved data check needed in the edit form. + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function tpl_link($url,$name,$more=''){ + print '<a href="'.$url.'" onclick="return svchk()" onkeypress="return svchk()"'; + if ($more) print ' '.$more; + print ">$name</a>"; +} + +/** + * Print one of the buttons + * + * Available Buttons are + * + * edit - edit/create/show button + * history - old revisions + * recent - recent changes + * login - login/logout button - if ACL enabled + * index - The index + * top - a back to top button + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function tpl_button($type){ + global $ID; + global $conf; + + switch($type){ + case 'edit': + print html_editbutton(); + break; + case 'history': + print html_btn(revs,$ID,'o',array('do' => 'revisions')); + break; + case 'recent': + print html_btn(recent,'','r',array('do' => 'recent')); + break; + case 'index': + print html_btn(index,$ID,'x',array('do' => 'index')); + break; + case 'top': + print html_topbtn(); + break; + case 'login': + if($conf['useacl']){ + if($_SERVER['REMOTE_USER']){ + print html_btn('logout',$ID,'',array('do' => 'logout',)); + }else{ + print html_btn('login',$ID,'',array('do' => 'login')); + } + } + break; + } +} + +/** + * Print the search form + * + * @todo svcheck missing + * @author Andreas Gohr <andi@splitbrain.org> + */ +function tpl_searchform(){ + global $lang; + print '<form action="'.wl().'" accept-charset="utf-8" class="search">'; + print '<input type="hidden" name="do" value="search" />'; + print '<input type="text" accesskey="f" name="id" class="edit" />'; + print '<input type="submit" value="'.$lang['btn_search'].'" class="button" />'; + print '</form>'; +} + +/** + * Print the breadcrumbs trace + * + * @todo add a hierachical breadcrumb function + * @author Andreas Gohr <andi@splitbrain.org> + */ +function tpl_breadcrumbs(){ + global $lang; + global $conf; + + //check if enabled + if(!$conf['breadcrumbs']) return; + + $crumbs = breadcrumbs(); //setup crumb trace + print $lang['breadcrumb'].':'; + foreach ($crumbs as $crumb){ + print ' » '; + tpl_link(wl($crumb),noNS($crumb),'class="breadcrumbs" title="'.$crumb.'"'); + } +} + +/** + * Print info if the user is logged in + * + * Could be enhanced with a profile link in future? + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function tpl_userinfo(){ + global $lang; + if($_SERVER['REMOTE_USER']) + print $lang['loggedinas'].': '.$_SERVER['REMOTE_USER']; +} + +/** + * Print some info about the current page + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function tpl_pageinfo(){ + global $conf; + global $lang; + global $INFO; + global $REV; + + // prepare date and path + $fn = $INFO['filepath']; + if(!$conf['fullpath']){ + if($REV){ + $fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn); + }else{ + $fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn); + } + } + $date = date($conf['dformat'],$INFO['lastmod']); + + // print it + if($INFO['exists']){ + print $fn; + print ' · '; + print $lang['lastmod']; + print ': '; + print $date; + if($INFO['editor']){ + print ' '.$lang['by'].' '; + print $INFO['editor']; + } + if($INFO['locked']){ + print ' · '; + print $lang['lockedby']; + print ': '; + print $INFO['locked']; + } + } +} + +?> |