From 49eb6e38061d744f4a35b78082dce49fa35f79c8 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 15 Jan 2010 19:50:13 +0100 Subject: some more coding standard compliance updates --- inc/actions.php | 830 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 415 insertions(+), 415 deletions(-) (limited to 'inc/actions.php') diff --git a/inc/actions.php b/inc/actions.php index 27292e6f6..92f817133 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -18,149 +18,149 @@ require_once(DOKU_INC.'inc/template.php'); * @triggers ACTION_HEADERS_SEND */ function act_dispatch(){ - global $INFO; - global $ACT; - global $ID; - global $QUERY; - global $lang; - global $conf; - global $license; - - $preact = $ACT; - - // give plugins an opportunity to process the action - $evt = new Doku_Event('ACTION_ACT_PREPROCESS',$ACT); - if ($evt->advise_before()) { - - //sanitize $ACT - $ACT = act_clean($ACT); - - //check if searchword was given - else just show - $s = cleanID($QUERY); - if($ACT == 'search' && empty($s)){ - $ACT = 'show'; - } + global $INFO; + global $ACT; + global $ID; + global $QUERY; + global $lang; + global $conf; + global $license; - //login stuff - if(in_array($ACT,array('login','logout'))){ - $ACT = act_auth($ACT); - } + $preact = $ACT; - //check if user is asking to (un)subscribe a page - if($ACT == 'subscribe' || $ACT == 'unsubscribe') - $ACT = act_subscription($ACT); + // give plugins an opportunity to process the action + $evt = new Doku_Event('ACTION_ACT_PREPROCESS',$ACT); + if ($evt->advise_before()) { - //check if user is asking to (un)subscribe a namespace - if($ACT == 'subscribens' || $ACT == 'unsubscribens') - $ACT = act_subscriptionns($ACT); + //sanitize $ACT + $ACT = act_clean($ACT); - //check permissions - $ACT = act_permcheck($ACT); + //check if searchword was given - else just show + $s = cleanID($QUERY); + if($ACT == 'search' && empty($s)){ + $ACT = 'show'; + } - //register - $nil = array(); - if($ACT == 'register' && $_POST['save'] && register()){ - $ACT = 'login'; - } + //login stuff + if(in_array($ACT,array('login','logout'))){ + $ACT = act_auth($ACT); + } - if ($ACT == 'resendpwd' && act_resendpwd()) { - $ACT = 'login'; - } + //check if user is asking to (un)subscribe a page + if($ACT == 'subscribe' || $ACT == 'unsubscribe') + $ACT = act_subscription($ACT); + + //check if user is asking to (un)subscribe a namespace + if($ACT == 'subscribens' || $ACT == 'unsubscribens') + $ACT = act_subscriptionns($ACT); - //update user profile - if ($ACT == 'profile') { - if(!$_SERVER['REMOTE_USER']) { - $ACT = 'login'; - } else { - if(updateprofile()) { - msg($lang['profchanged'],1); - $ACT = 'show'; + //check permissions + $ACT = act_permcheck($ACT); + + //register + $nil = array(); + if($ACT == 'register' && $_POST['save'] && register()){ + $ACT = 'login'; } - } - } - //revert - if($ACT == 'revert'){ - if(checkSecurityToken()){ - $ACT = act_revert($ACT); - }else{ - $ACT = 'show'; - } - } + if ($ACT == 'resendpwd' && act_resendpwd()) { + $ACT = 'login'; + } - //save - if($ACT == 'save'){ - if(checkSecurityToken()){ - $ACT = act_save($ACT); - }else{ - $ACT = 'show'; - } - } + //update user profile + if ($ACT == 'profile') { + if(!$_SERVER['REMOTE_USER']) { + $ACT = 'login'; + } else { + if(updateprofile()) { + msg($lang['profchanged'],1); + $ACT = 'show'; + } + } + } - //cancel conflicting edit - if($ACT == 'cancel') - $ACT = 'show'; + //revert + if($ACT == 'revert'){ + if(checkSecurityToken()){ + $ACT = act_revert($ACT); + }else{ + $ACT = 'show'; + } + } - //draft deletion - if($ACT == 'draftdel') - $ACT = act_draftdel($ACT); + //save + if($ACT == 'save'){ + if(checkSecurityToken()){ + $ACT = act_save($ACT); + }else{ + $ACT = 'show'; + } + } - //draft saving on preview - if($ACT == 'preview') - $ACT = act_draftsave($ACT); + //cancel conflicting edit + if($ACT == 'cancel') + $ACT = 'show'; - //edit - if(($ACT == 'edit' || $ACT == 'preview') && $INFO['editable']){ - $ACT = act_edit($ACT); - }else{ - unlock($ID); //try to unlock - } + //draft deletion + if($ACT == 'draftdel') + $ACT = act_draftdel($ACT); - //handle export - if(substr($ACT,0,7) == 'export_') - $ACT = act_export($ACT); + //draft saving on preview + if($ACT == 'preview') + $ACT = act_draftsave($ACT); - //display some infos - if($ACT == 'check'){ - check(); - $ACT = 'show'; - } + //edit + if(($ACT == 'edit' || $ACT == 'preview') && $INFO['editable']){ + $ACT = act_edit($ACT); + }else{ + unlock($ID); //try to unlock + } - //handle admin tasks - if($ACT == 'admin'){ - // retrieve admin plugin name from $_REQUEST['page'] - if (!empty($_REQUEST['page'])) { - $pluginlist = plugin_list('admin'); - if (in_array($_REQUEST['page'], $pluginlist)) { - // attempt to load the plugin - if ($plugin =& plugin_load('admin',$_REQUEST['page']) !== NULL) - $plugin->handle(); - } - } - } + //handle export + if(substr($ACT,0,7) == 'export_') + $ACT = act_export($ACT); - // check permissions again - the action may have changed - $ACT = act_permcheck($ACT); - } // end event ACTION_ACT_PREPROCESS default action - $evt->advise_after(); - unset($evt); + //display some infos + if($ACT == 'check'){ + check(); + $ACT = 'show'; + } - // when action 'show', the intial not 'show' and POST, do a redirect - if($ACT == 'show' && $preact != 'show' && strtolower($_SERVER['REQUEST_METHOD']) == 'post'){ - act_redirect($ID,$preact); - } + //handle admin tasks + if($ACT == 'admin'){ + // retrieve admin plugin name from $_REQUEST['page'] + if (!empty($_REQUEST['page'])) { + $pluginlist = plugin_list('admin'); + if (in_array($_REQUEST['page'], $pluginlist)) { + // attempt to load the plugin + if ($plugin =& plugin_load('admin',$_REQUEST['page']) !== null) + $plugin->handle(); + } + } + } + + // check permissions again - the action may have changed + $ACT = act_permcheck($ACT); + } // end event ACTION_ACT_PREPROCESS default action + $evt->advise_after(); + unset($evt); + + // when action 'show', the intial not 'show' and POST, do a redirect + if($ACT == 'show' && $preact != 'show' && strtolower($_SERVER['REQUEST_METHOD']) == 'post'){ + act_redirect($ID,$preact); + } - //call template FIXME: all needed vars available? - $headers[] = 'Content-Type: text/html; charset=utf-8'; - trigger_event('ACTION_HEADERS_SEND',$headers,'act_sendheaders'); + //call template FIXME: all needed vars available? + $headers[] = 'Content-Type: text/html; charset=utf-8'; + trigger_event('ACTION_HEADERS_SEND',$headers,'act_sendheaders'); - include(template('main.php')); - // output for the commands is now handled in inc/templates.php - // in function tpl_content() + include(template('main.php')); + // output for the commands is now handled in inc/templates.php + // in function tpl_content() } function act_sendheaders($headers) { - foreach ($headers as $hdr) header($hdr); + foreach ($headers as $hdr) header($hdr); } /** @@ -171,44 +171,44 @@ function act_sendheaders($headers) { * @author Andreas Gohr */ function act_clean($act){ - global $lang; - global $conf; + global $lang; + global $conf; - // check if the action was given as array key - if(is_array($act)){ - list($act) = array_keys($act); - } + // check if the action was given as array key + if(is_array($act)){ + list($act) = array_keys($act); + } - //remove all bad chars - $act = strtolower($act); - $act = preg_replace('/[^1-9a-z_]+/','',$act); + //remove all bad chars + $act = strtolower($act); + $act = preg_replace('/[^1-9a-z_]+/','',$act); - if($act == 'export_html') $act = 'export_xhtml'; - if($act == 'export_htmlbody') $act = 'export_xhtmlbody'; + if($act == 'export_html') $act = 'export_xhtml'; + if($act == 'export_htmlbody') $act = 'export_xhtmlbody'; - // check if action is disabled - if(!actionOK($act)){ - msg('Command disabled: '.htmlspecialchars($act),-1); - return 'show'; - } + // check if action is disabled + if(!actionOK($act)){ + msg('Command disabled: '.htmlspecialchars($act),-1); + return 'show'; + } - //disable all acl related commands if ACL is disabled - if(!$conf['useacl'] && in_array($act,array('login','logout','register','admin', - 'subscribe','unsubscribe','profile','revert', - 'resendpwd','subscribens','unsubscribens',))){ - msg('Command unavailable: '.htmlspecialchars($act),-1); - return 'show'; - } - - if(!in_array($act,array('login','logout','register','save','cancel','edit','draft', - 'preview','search','show','check','index','revisions', - 'diff','recent','backlink','admin','subscribe','revert', - 'unsubscribe','profile','resendpwd','recover','wordblock', - 'draftdel','subscribens','unsubscribens',)) && substr($act,0,7) != 'export_' ) { - msg('Command unknown: '.htmlspecialchars($act),-1); - return 'show'; - } - return $act; + //disable all acl related commands if ACL is disabled + if(!$conf['useacl'] && in_array($act,array('login','logout','register','admin', + 'subscribe','unsubscribe','profile','revert', + 'resendpwd','subscribens','unsubscribens',))){ + msg('Command unavailable: '.htmlspecialchars($act),-1); + return 'show'; + } + + if(!in_array($act,array('login','logout','register','save','cancel','edit','draft', + 'preview','search','show','check','index','revisions', + 'diff','recent','backlink','admin','subscribe','revert', + 'unsubscribe','profile','resendpwd','recover','wordblock', + 'draftdel','subscribens','unsubscribens',)) && substr($act,0,7) != 'export_' ) { + msg('Command unknown: '.htmlspecialchars($act),-1); + return 'show'; + } + return $act; } /** @@ -217,44 +217,44 @@ function act_clean($act){ * @author Andreas Gohr */ function act_permcheck($act){ - global $INFO; - global $conf; - - if(in_array($act,array('save','preview','edit','recover'))){ - if($INFO['exists']){ - if($act == 'edit'){ - //the edit function will check again and do a source show - //when no AUTH_EDIT available - $permneed = AUTH_READ; - }else{ - $permneed = AUTH_EDIT; - } - }else{ - $permneed = AUTH_CREATE; - } - }elseif(in_array($act,array('login','search','recent','profile'))){ - $permneed = AUTH_NONE; - }elseif($act == 'revert'){ - $permneed = AUTH_ADMIN; - if($INFO['ismanager']) $permneed = AUTH_EDIT; - }elseif($act == 'register'){ - $permneed = AUTH_NONE; - }elseif($act == 'resendpwd'){ - $permneed = AUTH_NONE; - }elseif($act == 'admin'){ - if($INFO['ismanager']){ - // if the manager has the needed permissions for a certain admin - // action is checked later - $permneed = AUTH_READ; + global $INFO; + global $conf; + + if(in_array($act,array('save','preview','edit','recover'))){ + if($INFO['exists']){ + if($act == 'edit'){ + //the edit function will check again and do a source show + //when no AUTH_EDIT available + $permneed = AUTH_READ; + }else{ + $permneed = AUTH_EDIT; + } + }else{ + $permneed = AUTH_CREATE; + } + }elseif(in_array($act,array('login','search','recent','profile'))){ + $permneed = AUTH_NONE; + }elseif($act == 'revert'){ + $permneed = AUTH_ADMIN; + if($INFO['ismanager']) $permneed = AUTH_EDIT; + }elseif($act == 'register'){ + $permneed = AUTH_NONE; + }elseif($act == 'resendpwd'){ + $permneed = AUTH_NONE; + }elseif($act == 'admin'){ + if($INFO['ismanager']){ + // if the manager has the needed permissions for a certain admin + // action is checked later + $permneed = AUTH_READ; + }else{ + $permneed = AUTH_ADMIN; + } }else{ - $permneed = AUTH_ADMIN; + $permneed = AUTH_READ; } - }else{ - $permneed = AUTH_READ; - } - if($INFO['perm'] >= $permneed) return $act; + if($INFO['perm'] >= $permneed) return $act; - return 'denied'; + return 'denied'; } /** @@ -263,10 +263,10 @@ function act_permcheck($act){ * Deletes the draft for the current page and user */ function act_draftdel($act){ - global $INFO; - @unlink($INFO['draft']); - $INFO['draft'] = null; - return 'show'; + global $INFO; + @unlink($INFO['draft']); + $INFO['draft'] = null; + return 'show'; } /** @@ -275,23 +275,23 @@ function act_draftdel($act){ * @todo this currently duplicates code from ajax.php :-/ */ function act_draftsave($act){ - global $INFO; - global $ID; - global $conf; - if($conf['usedraft'] && $_POST['wikitext']){ - $draft = array('id' => $ID, - 'prefix' => $_POST['prefix'], - 'text' => $_POST['wikitext'], - 'suffix' => $_POST['suffix'], - 'date' => $_POST['date'], - 'client' => $INFO['client'], - ); - $cname = getCacheName($draft['client'].$ID,'.draft'); - if(io_saveFile($cname,serialize($draft))){ - $INFO['draft'] = $cname; + global $INFO; + global $ID; + global $conf; + if($conf['usedraft'] && $_POST['wikitext']){ + $draft = array('id' => $ID, + 'prefix' => $_POST['prefix'], + 'text' => $_POST['wikitext'], + 'suffix' => $_POST['suffix'], + 'date' => $_POST['date'], + 'client' => $INFO['client'], + ); + $cname = getCacheName($draft['client'].$ID,'.draft'); + if(io_saveFile($cname,serialize($draft))){ + $INFO['draft'] = $cname; + } } - } - return $act; + return $act; } /** @@ -304,31 +304,31 @@ function act_draftsave($act){ * @author Andreas Gohr */ 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,$_REQUEST['minor']); //use pretty mode for con - //unlock it - unlock($ID); - - //delete draft - act_draftdel($act); - session_write_close(); - - // when done, show page - return 'show'; + 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,$_REQUEST['minor']); //use pretty mode for con + //unlock it + unlock($ID); + + //delete draft + act_draftdel($act); + session_write_close(); + + // when done, show page + return 'show'; } /** @@ -374,38 +374,38 @@ function act_revert($act){ * Tries to add the section id as hash mark after section editing */ function act_redirect($id,$preact){ - global $PRE; - global $TEXT; - global $MSG; - - //are there any undisplayed messages? keep them in session for display - //on the next page - if(isset($MSG) && count($MSG)){ - //reopen session, store data and close session again - @session_start(); - $_SESSION[DOKU_COOKIE]['msg'] = $MSG; - session_write_close(); - } - - $opts = array( - 'id' => $id, - 'preact' => $preact - ); - //get section name when coming from section edit - if($PRE && preg_match('/^\s*==+([^=\n]+)/',$TEXT,$match)){ - $check = false; //Byref - $opts['fragment'] = sectionID($match[0], $check); - } - - trigger_event('ACTION_SHOW_REDIRECT',$opts,'act_redirect_execute'); + global $PRE; + global $TEXT; + global $MSG; + + //are there any undisplayed messages? keep them in session for display + //on the next page + if(isset($MSG) && count($MSG)){ + //reopen session, store data and close session again + @session_start(); + $_SESSION[DOKU_COOKIE]['msg'] = $MSG; + session_write_close(); + } + + $opts = array( + 'id' => $id, + 'preact' => $preact + ); + //get section name when coming from section edit + if($PRE && preg_match('/^\s*==+([^=\n]+)/',$TEXT,$match)){ + $check = false; //Byref + $opts['fragment'] = sectionID($match[0], $check); + } + + trigger_event('ACTION_SHOW_REDIRECT',$opts,'act_redirect_execute'); } function act_redirect_execute($opts){ - $go = wl($opts['id'],'',true); - if(isset($opts['fragment'])) $go .= '#'.$opts['fragment']; + $go = wl($opts['id'],'',true); + if(isset($opts['fragment'])) $go .= '#'.$opts['fragment']; - //show it - send_redirect($go); + //show it + send_redirect($go); } /** @@ -414,30 +414,30 @@ function act_redirect_execute($opts){ * @author Andreas Gohr */ function act_auth($act){ - global $ID; - global $INFO; + global $ID; + global $INFO; - //already logged in? - if(isset($_SERVER['REMOTE_USER']) && $act=='login'){ - return 'show'; - } + //already logged in? + if(isset($_SERVER['REMOTE_USER']) && $act=='login'){ + return 'show'; + } - //handle logout - if($act=='logout'){ - $lockedby = checklock($ID); //page still locked? - if($lockedby == $_SERVER['REMOTE_USER']) - unlock($ID); //try to unlock + //handle logout + if($act=='logout'){ + $lockedby = checklock($ID); //page still locked? + if($lockedby == $_SERVER['REMOTE_USER']) + unlock($ID); //try to unlock - // do the logout stuff - auth_logoff(); + // do the logout stuff + auth_logoff(); - // rebuild info array - $INFO = pageinfo(); + // rebuild info array + $INFO = pageinfo(); - act_redirect($ID,'login'); - } + act_redirect($ID,'login'); + } - return $act; + return $act; } /** @@ -446,15 +446,15 @@ function act_auth($act){ * @author Andreas Gohr */ function act_edit($act){ - global $ID; - global $INFO; + global $ID; + global $INFO; - //check if locked by anyone - if not lock for my self - $lockedby = checklock($ID); - if($lockedby) return 'locked'; + //check if locked by anyone - if not lock for my self + $lockedby = checklock($ID); + if($lockedby) return 'locked'; - lock($ID); - return $act; + lock($ID); + return $act; } /** @@ -472,81 +472,81 @@ function act_edit($act){ * @author Michael Klier */ function act_export($act){ - global $ID; - global $REV; - global $conf; - global $lang; - - $pre = ''; - $post = ''; - $output = ''; - $headers = array(); - - // search engines: never cache exported docs! (Google only currently) - $headers['X-Robots-Tag'] = 'noindex'; - - $mode = substr($act,7); - switch($mode) { - case 'raw': - $headers['Content-Type'] = 'text/plain; charset=utf-8'; - $headers['Content-Disposition'] = 'attachment; filename='.noNS($ID).'.txt'; - $output = rawWiki($ID,$REV); - break; - case 'xhtml': - $pre .= '' . DOKU_LF; - $pre .= '' . DOKU_LF; - $pre .= '' . DOKU_LF; - $pre .= ' ' . DOKU_LF; - $pre .= ' '.$ID.'' . DOKU_LF; - - // get metaheaders - ob_start(); - tpl_metaheaders(); - $pre .= ob_get_clean(); - - $pre .= '' . DOKU_LF; - $pre .= '' . DOKU_LF; - $pre .= '
' . DOKU_LF; - - // get toc - $pre .= tpl_toc(true); - - $headers['Content-Type'] = 'text/html; charset=utf-8'; - $output = p_wiki_xhtml($ID,$REV,false); - - $post .= '
' . DOKU_LF; - $post .= '' . DOKU_LF; - $post .= '' . DOKU_LF; - break; - case 'xhtmlbody': - $headers['Content-Type'] = 'text/html; charset=utf-8'; - $output = p_wiki_xhtml($ID,$REV,false); - break; - default: - $output = p_cached_output(wikiFN($ID,$REV), $mode); - $headers = p_get_metadata($ID,"format $mode"); - break; - } - - // prepare event data - $data = array(); - $data['id'] = $ID; - $data['mode'] = $mode; - $data['headers'] = $headers; - $data['output'] =& $output; - - trigger_event('ACTION_EXPORT_POSTPROCESS', $data); - - if(!empty($data['output'])){ - if(is_array($data['headers'])) foreach($data['headers'] as $key => $val){ - header("$key: $val"); + global $ID; + global $REV; + global $conf; + global $lang; + + $pre = ''; + $post = ''; + $output = ''; + $headers = array(); + + // search engines: never cache exported docs! (Google only currently) + $headers['X-Robots-Tag'] = 'noindex'; + + $mode = substr($act,7); + switch($mode) { + case 'raw': + $headers['Content-Type'] = 'text/plain; charset=utf-8'; + $headers['Content-Disposition'] = 'attachment; filename='.noNS($ID).'.txt'; + $output = rawWiki($ID,$REV); + break; + case 'xhtml': + $pre .= '' . DOKU_LF; + $pre .= '' . DOKU_LF; + $pre .= '' . DOKU_LF; + $pre .= ' ' . DOKU_LF; + $pre .= ' '.$ID.'' . DOKU_LF; + + // get metaheaders + ob_start(); + tpl_metaheaders(); + $pre .= ob_get_clean(); + + $pre .= '' . DOKU_LF; + $pre .= '' . DOKU_LF; + $pre .= '
' . DOKU_LF; + + // get toc + $pre .= tpl_toc(true); + + $headers['Content-Type'] = 'text/html; charset=utf-8'; + $output = p_wiki_xhtml($ID,$REV,false); + + $post .= '
' . DOKU_LF; + $post .= '' . DOKU_LF; + $post .= '' . DOKU_LF; + break; + case 'xhtmlbody': + $headers['Content-Type'] = 'text/html; charset=utf-8'; + $output = p_wiki_xhtml($ID,$REV,false); + break; + default: + $output = p_cached_output(wikiFN($ID,$REV), $mode); + $headers = p_get_metadata($ID,"format $mode"); + break; } - print $pre.$data['output'].$post; - exit; - } - return 'show'; + + // prepare event data + $data = array(); + $data['id'] = $ID; + $data['mode'] = $mode; + $data['headers'] = $headers; + $data['output'] =& $output; + + trigger_event('ACTION_EXPORT_POSTPROCESS', $data); + + if(!empty($data['output'])){ + if(is_array($data['headers'])) foreach($data['headers'] as $key => $val){ + header("$key: $val"); + } + print $pre.$data['output'].$post; + exit; + } + return 'show'; } /** @@ -556,32 +556,32 @@ function act_export($act){ * @todo localize */ function act_subscription($act){ - global $ID; - global $INFO; - global $lang; - - $file=metaFN($ID,'.mlist'); - if ($act=='subscribe' && !$INFO['subscribed']){ - if ($INFO['userinfo']['mail']){ - if (io_saveFile($file,$_SERVER['REMOTE_USER']."\n",true)) { - $INFO['subscribed'] = true; - msg(sprintf($lang[$act.'_success'], $INFO['userinfo']['name'], $ID),1); - } else { - msg(sprintf($lang[$act.'_error'], $INFO['userinfo']['name'], $ID),1); - } - } else { - msg($lang['subscribe_noaddress']); - } - } elseif ($act=='unsubscribe' && $INFO['subscribed']){ - if (io_deleteFromFile($file,$_SERVER['REMOTE_USER']."\n")) { - $INFO['subscribed'] = false; - msg(sprintf($lang[$act.'_success'], $INFO['userinfo']['name'], $ID),1); - } else { - msg(sprintf($lang[$act.'_error'], $INFO['userinfo']['name'], $ID),1); + global $ID; + global $INFO; + global $lang; + + $file=metaFN($ID,'.mlist'); + if ($act=='subscribe' && !$INFO['subscribed']){ + if ($INFO['userinfo']['mail']){ + if (io_saveFile($file,$_SERVER['REMOTE_USER']."\n",true)) { + $INFO['subscribed'] = true; + msg(sprintf($lang[$act.'_success'], $INFO['userinfo']['name'], $ID),1); + } else { + msg(sprintf($lang[$act.'_error'], $INFO['userinfo']['name'], $ID),1); + } + } else { + msg($lang['subscribe_noaddress']); + } + } elseif ($act=='unsubscribe' && $INFO['subscribed']){ + if (io_deleteFromFile($file,$_SERVER['REMOTE_USER']."\n")) { + $INFO['subscribed'] = false; + msg(sprintf($lang[$act.'_success'], $INFO['userinfo']['name'], $ID),1); + } else { + msg(sprintf($lang[$act.'_error'], $INFO['userinfo']['name'], $ID),1); + } } - } - return 'show'; + return 'show'; } /** @@ -589,42 +589,42 @@ function act_subscription($act){ * */ function act_subscriptionns($act){ - global $ID; - global $INFO; - global $lang; - - if(!getNS($ID)) { - $file = metaFN(getNS($ID),'.mlist'); - $ns = "root"; - } else { - $file = metaFN(getNS($ID),'/.mlist'); - $ns = getNS($ID); - } - - // reuse strings used to display the status of the subscribe action - $act_msg = rtrim($act, 'ns'); - - if ($act=='subscribens' && !$INFO['subscribedns']){ - if ($INFO['userinfo']['mail']){ - if (io_saveFile($file,$_SERVER['REMOTE_USER']."\n",true)) { - $INFO['subscribedns'] = true; - msg(sprintf($lang[$act_msg.'_success'], $INFO['userinfo']['name'], $ns),1); - } else { - msg(sprintf($lang[$act_msg.'_error'], $INFO['userinfo']['name'], $ns),1); - } + global $ID; + global $INFO; + global $lang; + + if(!getNS($ID)) { + $file = metaFN(getNS($ID),'.mlist'); + $ns = "root"; } else { - msg($lang['subscribe_noaddress']); + $file = metaFN(getNS($ID),'/.mlist'); + $ns = getNS($ID); } - } elseif ($act=='unsubscribens' && $INFO['subscribedns']){ - if (io_deleteFromFile($file,$_SERVER['REMOTE_USER']."\n")) { - $INFO['subscribedns'] = false; - msg(sprintf($lang[$act_msg.'_success'], $INFO['userinfo']['name'], $ns),1); - } else { - msg(sprintf($lang[$act_msg.'_error'], $INFO['userinfo']['name'], $ns),1); + + // reuse strings used to display the status of the subscribe action + $act_msg = rtrim($act, 'ns'); + + if ($act=='subscribens' && !$INFO['subscribedns']){ + if ($INFO['userinfo']['mail']){ + if (io_saveFile($file,$_SERVER['REMOTE_USER']."\n",true)) { + $INFO['subscribedns'] = true; + msg(sprintf($lang[$act_msg.'_success'], $INFO['userinfo']['name'], $ns),1); + } else { + msg(sprintf($lang[$act_msg.'_error'], $INFO['userinfo']['name'], $ns),1); + } + } else { + msg($lang['subscribe_noaddress']); + } + } elseif ($act=='unsubscribens' && $INFO['subscribedns']){ + if (io_deleteFromFile($file,$_SERVER['REMOTE_USER']."\n")) { + $INFO['subscribedns'] = false; + msg(sprintf($lang[$act_msg.'_success'], $INFO['userinfo']['name'], $ns),1); + } else { + msg(sprintf($lang[$act_msg.'_error'], $INFO['userinfo']['name'], $ns),1); + } } - } - return 'show'; + return 'show'; } //Setup VIM: ex: et ts=2 enc=utf-8 : -- cgit v1.2.3 From 5b75cd1f5c479ada468fbf62a733c54edad152f1 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Tue, 5 Jan 2010 14:14:00 +0100 Subject: New mail subscription with digest --- inc/actions.php | 124 +++++++++++++++++++++++++------------------------------- 1 file changed, 56 insertions(+), 68 deletions(-) (limited to 'inc/actions.php') diff --git a/inc/actions.php b/inc/actions.php index 92f817133..a856b7919 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -47,12 +47,13 @@ function act_dispatch(){ } //check if user is asking to (un)subscribe a page - if($ACT == 'subscribe' || $ACT == 'unsubscribe') - $ACT = act_subscription($ACT); - - //check if user is asking to (un)subscribe a namespace - if($ACT == 'subscribens' || $ACT == 'unsubscribens') - $ACT = act_subscriptionns($ACT); + if($ACT == 'subscribe') { + try { + $ACT = act_subscription($ACT); + } catch (Exception $e) { + msg($e->getMessage(), -1); + } + } //check permissions $ACT = act_permcheck($ACT); @@ -550,81 +551,68 @@ function act_export($act){ } /** - * Handle page 'subscribe', 'unsubscribe' + * Handle page 'subscribe' + * + * Throws exception on error. * - * @author Steven Danz - * @todo localize + * @author Adrian Lang */ function act_subscription($act){ - global $ID; - global $INFO; global $lang; - - $file=metaFN($ID,'.mlist'); - if ($act=='subscribe' && !$INFO['subscribed']){ - if ($INFO['userinfo']['mail']){ - if (io_saveFile($file,$_SERVER['REMOTE_USER']."\n",true)) { - $INFO['subscribed'] = true; - msg(sprintf($lang[$act.'_success'], $INFO['userinfo']['name'], $ID),1); - } else { - msg(sprintf($lang[$act.'_error'], $INFO['userinfo']['name'], $ID),1); - } - } else { - msg($lang['subscribe_noaddress']); - } - } elseif ($act=='unsubscribe' && $INFO['subscribed']){ - if (io_deleteFromFile($file,$_SERVER['REMOTE_USER']."\n")) { - $INFO['subscribed'] = false; - msg(sprintf($lang[$act.'_success'], $INFO['userinfo']['name'], $ID),1); - } else { - msg(sprintf($lang[$act.'_error'], $INFO['userinfo']['name'], $ID),1); - } - } - - return 'show'; -} - -/** - * Handle namespace 'subscribe', 'unsubscribe' - * - */ -function act_subscriptionns($act){ - global $ID; global $INFO; - global $lang; - if(!getNS($ID)) { - $file = metaFN(getNS($ID),'.mlist'); - $ns = "root"; - } else { - $file = metaFN(getNS($ID),'/.mlist'); - $ns = getNS($ID); + if ($_SERVER['REQUEST_METHOD'] !== 'POST') { + // No post to handle, let tpl_subscribe manage the request. + return $act; } - // reuse strings used to display the status of the subscribe action - $act_msg = rtrim($act, 'ns'); - - if ($act=='subscribens' && !$INFO['subscribedns']){ - if ($INFO['userinfo']['mail']){ - if (io_saveFile($file,$_SERVER['REMOTE_USER']."\n",true)) { - $INFO['subscribedns'] = true; - msg(sprintf($lang[$act_msg.'_success'], $INFO['userinfo']['name'], $ns),1); - } else { - msg(sprintf($lang[$act_msg.'_error'], $INFO['userinfo']['name'], $ns),1); + // Get and validate parameters. + if (!isset($_POST['subscribe_target'])) { + throw new Exception($lang['subscr_no_target']); + } + $target = $_POST['subscribe_target']; + $valid_styles = array('every', 'digest'); + if (substr($target, -1, 1) === ':') { + // Allow “list” subscribe style since the target is a namespace. + $valid_styles[] = 'list'; + } + $style = valid_input_set('subscribe_style', $valid_styles, $_POST, + $lang['subscr_invalid_style']); + $action = valid_input_set('subscribe_action', array('subscribe', + 'unsubscribe'), + $_POST, $lang['subscr_invalid_action']); + + // Check other conditions. + if ($action === 'subscribe') { + if ($INFO['userinfo']['mail'] === '') { + throw new Exception($lang['subscr_subscribe_noaddress']); + } + } elseif ($action === 'unsubscribe') { + $is = false; + foreach($INFO['subscribed'] as $subscr) { + if ($subscr['target'] === $target) { + $is = true; } - } else { - msg($lang['subscribe_noaddress']); } - } elseif ($act=='unsubscribens' && $INFO['subscribedns']){ - if (io_deleteFromFile($file,$_SERVER['REMOTE_USER']."\n")) { - $INFO['subscribedns'] = false; - msg(sprintf($lang[$act_msg.'_success'], $INFO['userinfo']['name'], $ns),1); - } else { - msg(sprintf($lang[$act_msg.'_error'], $INFO['userinfo']['name'], $ns),1); + if ($is === false) { + throw new Exception(sprintf($lang['subscr_not_subscribed_you'], + prettyprint_id($target))); } + // subscription_set deletes a subscription if style = null. + $style = null; } - return 'show'; + // Perform action. + require_once DOKU_INC . 'inc/subscription.php'; + if (!subscription_set($target, $_SERVER['REMOTE_USER'], $style)) { + throw new Exception(sprintf($lang["subscr_{$action}_error"], + hsc($INFO['userinfo']['name']), + prettyprint_id($target))); + } + $INFO['subscribed'] = get_info_subscribed(); + msg(sprintf($lang["subscr_{$action}_success"], hsc($INFO['userinfo']['name']), + prettyprint_id($target)), 1); + return $act; } //Setup VIM: ex: et ts=2 enc=utf-8 : -- cgit v1.2.3 From 8881fcc99a05f20da8fdd0f1c52f801fd84a8bb7 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Thu, 19 Nov 2009 15:25:25 +0100 Subject: Add events to subscription. --- inc/actions.php | 71 +++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 20 deletions(-) (limited to 'inc/actions.php') diff --git a/inc/actions.php b/inc/actions.php index a856b7919..222ac89dd 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -558,29 +558,69 @@ function act_export($act){ * @author Adrian Lang */ function act_subscription($act){ - global $lang; - global $INFO; - if ($_SERVER['REQUEST_METHOD'] !== 'POST') { // No post to handle, let tpl_subscribe manage the request. return $act; } + // Get and preprocess data. + $params = array(); + foreach(array('target', 'style', 'action') as $param) { + if (isset($_POST["subscribe_$param"])) { + $params[$param] = $_POST["subscribe_$param"]; + } + } + + // Handle POST data, may throw exception. + trigger_event('ACTION_HANDLE_SUBSCRIBE', $params, 'subscription_handle_post'); + + $target = $params['target']; + $style = $params['style']; + $data = $params['data']; + $action = $params['action']; + + global $lang; + global $INFO; + + // Perform action. + require_once DOKU_INC . 'inc/subscription.php'; + if (!subscription_set($_SERVER['REMOTE_USER'], $target, $style, $data)) { + throw new Exception(sprintf($lang["subscr_{$action}_error"], + hsc($INFO['userinfo']['name']), + prettyprint_id($target))); + } + $INFO['subscribed'] = get_info_subscribed(); + msg(sprintf($lang["subscr_{$action}_success"], hsc($INFO['userinfo']['name']), + prettyprint_id($target)), 1); + return $act; +} + +/** + * Validate POST data + * + * Validates POST data for a subscribe or unsubscribe request. This is the + * default action for the event ACTION_HANDLE_SUBSCRIBE. + * + * @author Adrian Lang + */ +function subscription_handle_post($params) { + global $INFO; + global $lang; + // Get and validate parameters. - if (!isset($_POST['subscribe_target'])) { + if (!isset($params['target'])) { throw new Exception($lang['subscr_no_target']); } - $target = $_POST['subscribe_target']; + $target = $params['target']; $valid_styles = array('every', 'digest'); if (substr($target, -1, 1) === ':') { // Allow “list” subscribe style since the target is a namespace. $valid_styles[] = 'list'; } - $style = valid_input_set('subscribe_style', $valid_styles, $_POST, + $style = valid_input_set('style', $valid_styles, $params, $lang['subscr_invalid_style']); - $action = valid_input_set('subscribe_action', array('subscribe', - 'unsubscribe'), - $_POST, $lang['subscr_invalid_action']); + $action = valid_input_set('action', array('subscribe', 'unsubscribe'), + $params, $lang['subscr_invalid_action']); // Check other conditions. if ($action === 'subscribe') { @@ -602,17 +642,8 @@ function act_subscription($act){ $style = null; } - // Perform action. - require_once DOKU_INC . 'inc/subscription.php'; - if (!subscription_set($target, $_SERVER['REMOTE_USER'], $style)) { - throw new Exception(sprintf($lang["subscr_{$action}_error"], - hsc($INFO['userinfo']['name']), - prettyprint_id($target))); - } - $INFO['subscribed'] = get_info_subscribed(); - msg(sprintf($lang["subscr_{$action}_success"], hsc($INFO['userinfo']['name']), - prettyprint_id($target)), 1); - return $act; + $data = in_array($style, array('list', 'digest')) ? time() : null; + $params = compact('target', 'style', 'data', 'action'); } //Setup VIM: ex: et ts=2 enc=utf-8 : -- cgit v1.2.3 From 15741132b4a2b6f006441f4c11e021062c168af8 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 23 Nov 2009 16:18:13 +0100 Subject: Some language changes in subscription management Ignore-this: 9d6c368419814c7b8cb94f778377ede7 A few language strings were dropped, others updated or added darcs-hash:20091123151813-6e07b-4d01fe03fa2c3bd5944bc05abdd05a24fb79c186.gz --- inc/actions.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'inc/actions.php') diff --git a/inc/actions.php b/inc/actions.php index 222ac89dd..32dde008e 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -609,7 +609,7 @@ function subscription_handle_post($params) { // Get and validate parameters. if (!isset($params['target'])) { - throw new Exception($lang['subscr_no_target']); + throw new Exception('no subscription target given'); } $target = $params['target']; $valid_styles = array('every', 'digest'); @@ -618,9 +618,9 @@ function subscription_handle_post($params) { $valid_styles[] = 'list'; } $style = valid_input_set('style', $valid_styles, $params, - $lang['subscr_invalid_style']); + 'invalid subscription style given'); $action = valid_input_set('action', array('subscribe', 'unsubscribe'), - $params, $lang['subscr_invalid_action']); + $params, 'invalid subscription action given'); // Check other conditions. if ($action === 'subscribe') { @@ -635,7 +635,8 @@ function subscription_handle_post($params) { } } if ($is === false) { - throw new Exception(sprintf($lang['subscr_not_subscribed_you'], + throw new Exception(sprintf($lang['subscr_not_subscribed'], + $_SERVER['REMOTE_USER'], prettyprint_id($target))); } // subscription_set deletes a subscription if style = null. -- cgit v1.2.3 From 7a9add1ccb1aed5ec92ee48b26ef14bebcf76f03 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Fri, 27 Nov 2009 15:32:23 +0100 Subject: Fix subscription data validation bug (pass by ref) darcs-hash:20091127143223-e4919-023dd4bfab074c1206580649a2927958c28f38f5.gz --- inc/actions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/actions.php') diff --git a/inc/actions.php b/inc/actions.php index 32dde008e..e61b1add3 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -603,7 +603,7 @@ function act_subscription($act){ * * @author Adrian Lang */ -function subscription_handle_post($params) { +function subscription_handle_post(&$params) { global $INFO; global $lang; -- cgit v1.2.3 From cb3f9dbab0cf12b2a7486cca0de17c47399633f3 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Mon, 30 Nov 2009 10:36:42 +0100 Subject: Add redirect after successful subscription darcs-hash:20091130093642-e4919-318eed562f0e7777d342dfbe4c8fc352eee58ddf.gz --- inc/actions.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'inc/actions.php') diff --git a/inc/actions.php b/inc/actions.php index e61b1add3..900409a90 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -589,10 +589,14 @@ function act_subscription($act){ hsc($INFO['userinfo']['name']), prettyprint_id($target))); } - $INFO['subscribed'] = get_info_subscribed(); msg(sprintf($lang["subscr_{$action}_success"], hsc($INFO['userinfo']['name']), prettyprint_id($target)), 1); - return $act; + global $ID; + act_redirect($ID, $act); + + // Assure that we have valid data if act_redirect somehow fails. + $INFO['subscribed'] = get_info_subscribed(); + return 'show'; } /** -- cgit v1.2.3 From 056c20495937fe45fe0f7204b112dbfe6931a855 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 30 Nov 2009 14:03:11 +0100 Subject: nicer subscription styles Ignore-this: e1b3b815b5ebb0da320bff997c4fed4b darcs-hash:20091130130311-6e07b-03ccfc52abb3dcc0764eed5784d81f8416841328.gz --- inc/actions.php | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'inc/actions.php') diff --git a/inc/actions.php b/inc/actions.php index 900409a90..1fda0584e 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -558,19 +558,21 @@ function act_export($act){ * @author Adrian Lang */ function act_subscription($act){ - if ($_SERVER['REQUEST_METHOD'] !== 'POST') { - // No post to handle, let tpl_subscribe manage the request. - return $act; - } + global $lang; + global $INFO; + global $ID; - // Get and preprocess data. + // get and preprocess data. $params = array(); foreach(array('target', 'style', 'action') as $param) { - if (isset($_POST["subscribe_$param"])) { - $params[$param] = $_POST["subscribe_$param"]; + if (isset($_REQUEST["sub_$param"])) { + $params[$param] = $_REQUEST["sub_$param"]; } } + // any action given? if not just return and show the subscription page + if(!$params['action']) return $act; + // Handle POST data, may throw exception. trigger_event('ACTION_HANDLE_SUBSCRIBE', $params, 'subscription_handle_post'); @@ -579,9 +581,6 @@ function act_subscription($act){ $data = $params['data']; $action = $params['action']; - global $lang; - global $INFO; - // Perform action. require_once DOKU_INC . 'inc/subscription.php'; if (!subscription_set($_SERVER['REMOTE_USER'], $target, $style, $data)) { @@ -591,7 +590,6 @@ function act_subscription($act){ } msg(sprintf($lang["subscr_{$action}_success"], hsc($INFO['userinfo']['name']), prettyprint_id($target)), 1); - global $ID; act_redirect($ID, $act); // Assure that we have valid data if act_redirect somehow fails. -- cgit v1.2.3 From 16905344219a6293705b71cd526fad3ba07b04eb Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 31 Jan 2010 19:02:14 +0100 Subject: first attempt to centralize all include loading Classes are loaded throug PHP5's class autoloader, all other includes are just loaded by default. This skips a lot of require_once calls. Parser and Plugin stuff isn't handled by the class loader yet. --- inc/actions.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'inc/actions.php') diff --git a/inc/actions.php b/inc/actions.php index 1fda0584e..7f9cb26d0 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -7,8 +7,6 @@ */ if(!defined('DOKU_INC')) die('meh.'); -require_once(DOKU_INC.'inc/template.php'); - /** * Call the needed action handlers -- cgit v1.2.3 From 0af14a6e25ba35e88d96762bc73325838868e3fe Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 1 Feb 2010 15:38:41 +0100 Subject: removed more unneeded require_once() calls --- inc/actions.php | 1 - 1 file changed, 1 deletion(-) (limited to 'inc/actions.php') diff --git a/inc/actions.php b/inc/actions.php index 7f9cb26d0..91a1d9cdd 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -580,7 +580,6 @@ function act_subscription($act){ $action = $params['action']; // Perform action. - require_once DOKU_INC . 'inc/subscription.php'; if (!subscription_set($_SERVER['REMOTE_USER'], $target, $style, $data)) { throw new Exception(sprintf($lang["subscr_{$action}_error"], hsc($INFO['userinfo']['name']), -- cgit v1.2.3 From 66d2bed97d77042bdcd15cbeb71f058918c8f614 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Tue, 9 Feb 2010 10:51:54 +0100 Subject: Add security token to subscription manage page --- inc/actions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/actions.php') diff --git a/inc/actions.php b/inc/actions.php index 1fda0584e..b7567bc20 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -571,7 +571,7 @@ function act_subscription($act){ } // any action given? if not just return and show the subscription page - if(!$params['action']) return $act; + if(!$params['action'] || !checkSecurityToken()) return $act; // Handle POST data, may throw exception. trigger_event('ACTION_HANDLE_SUBSCRIBE', $params, 'subscription_handle_post'); -- cgit v1.2.3 From 45a9933524f9a31e0a104cccfd082217501017ba Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Tue, 9 Mar 2010 11:42:34 +0100 Subject: Move data preprocessing out of html_edit --- inc/actions.php | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'inc/actions.php') diff --git a/inc/actions.php b/inc/actions.php index b7567bc20..5802bd6f5 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -111,7 +111,7 @@ function act_dispatch(){ $ACT = act_draftsave($ACT); //edit - if(($ACT == 'edit' || $ACT == 'preview') && $INFO['editable']){ + if(($ACT == 'edit' || $ACT == 'preview' || $ACT == 'recover') && $INFO['editable']){ $ACT = act_edit($ACT); }else{ unlock($ID); //try to unlock @@ -442,7 +442,7 @@ function act_auth($act){ } /** - * Handle 'edit', 'preview' + * Handle 'edit', 'preview', 'recover' * * @author Andreas Gohr */ @@ -450,6 +450,39 @@ function act_edit($act){ global $ID; global $INFO; + global $TEXT; + global $RANGE; + global $PRE; + global $SUF; + global $REV; + global $SUM; + global $lang; + global $DATE; + + if (!isset($TEXT)) { + if ($INFO['exists']) { + if ($RANGE) { + list($PRE,$TEXT,$SUF) = rawWikiSlices($RANGE,$ID,$REV); + } else { + $TEXT = rawWiki($ID,$REV); + } + } else { + $data = array($ID); + $TEXT = trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true); + } + } + + //set summary default + if(!$SUM){ + if($REV){ + $SUM = $lang['restored']; + }elseif(!$INFO['exists']){ + $SUM = $lang['created']; + } + } + + if(!$DATE) $DATE = $INFO['lastmod']; + //check if locked by anyone - if not lock for my self $lockedby = checklock($ID); if($lockedby) return 'locked'; -- cgit v1.2.3 From 5a932e77b3c806514203323540cb30e5ab9c28cf Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Tue, 9 Mar 2010 11:42:56 +0100 Subject: Remove wordblock action, issue a msg instead --- inc/actions.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'inc/actions.php') diff --git a/inc/actions.php b/inc/actions.php index 5802bd6f5..2be5259fd 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -204,7 +204,7 @@ function act_clean($act){ if(!in_array($act,array('login','logout','register','save','cancel','edit','draft', 'preview','search','show','check','index','revisions', 'diff','recent','backlink','admin','subscribe','revert', - 'unsubscribe','profile','resendpwd','recover','wordblock', + 'unsubscribe','profile','resendpwd','recover', 'draftdel','subscribens','unsubscribens',)) && substr($act,0,7) != 'export_' ) { msg('Command unknown: '.htmlspecialchars($act),-1); return 'show'; @@ -311,10 +311,13 @@ function act_save($act){ global $TEXT; global $SUF; global $SUM; + global $lang; //spam check - if(checkwordblock()) - return 'wordblock'; + if(checkwordblock()) { + msg($lang['wordblock'], -1); + return 'edit'; + } //conflict check //FIXME use INFO if($DATE != 0 && @filemtime(wikiFN($ID)) > $DATE ) return 'conflict'; @@ -353,8 +356,11 @@ function act_revert($act){ } // spam check - if(checkwordblock($Text)) - return 'wordblock'; + + if (checkwordblock($text)) { + msg($lang['wordblock'], -1); + return 'edit'; + } saveWikiText($ID,$text,$sum,false); msg($sum,1); -- cgit v1.2.3 From 8d67c48ac883f874037848be833920f4a6426995 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Wed, 10 Mar 2010 10:07:57 +0100 Subject: Correct edit conflict detection Edit conflicts occur when a page has been edited since starting the current edit. In order to detect them, the date of the newest revision is saved. --- inc/actions.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'inc/actions.php') diff --git a/inc/actions.php b/inc/actions.php index 2be5259fd..01d1d29d4 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -312,14 +312,15 @@ function act_save($act){ global $SUF; global $SUM; global $lang; + global $INFO; //spam check if(checkwordblock()) { msg($lang['wordblock'], -1); return 'edit'; } - //conflict check //FIXME use INFO - if($DATE != 0 && @filemtime(wikiFN($ID)) > $DATE ) + //conflict check + if($DATE != 0 && $INFO['meta']['date']['modified'] > $DATE ) return 'conflict'; //save it @@ -487,7 +488,9 @@ function act_edit($act){ } } - if(!$DATE) $DATE = $INFO['lastmod']; + // Use the date of the newest revision, not of the revision we edit + // This is used for conflict detection + if(!$DATE) $DATE = $INFO['meta']['date']['modified']; //check if locked by anyone - if not lock for my self $lockedby = checklock($ID); -- cgit v1.2.3 From fe17917e7668864526ec0f0ae65dd0787831d8a4 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Wed, 10 Mar 2010 10:41:32 +0100 Subject: Move & rename HTML_PAGE_FROMTEMPLATE to common.php The new COMMON_PAGE_FROMTEMPLATE is triggered by pageTemplate AFTER the template has been read but before performing the template replacements. --- inc/actions.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'inc/actions.php') diff --git a/inc/actions.php b/inc/actions.php index 01d1d29d4..6ce67eb9a 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -474,8 +474,7 @@ function act_edit($act){ $TEXT = rawWiki($ID,$REV); } } else { - $data = array($ID); - $TEXT = trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true); + $TEXT = pageTemplate($ID); } } -- cgit v1.2.3 From c9d5430b981aac42d64435908fe6016de907de0c Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Mon, 29 Mar 2010 10:18:22 +0200 Subject: Call act_edit for locked pages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 50e988b accidentally stopped act_dispatch from calling act_edit for locked pages, thus showing a generic »page not writable« message instead of a page lock message. --- inc/actions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/actions.php') diff --git a/inc/actions.php b/inc/actions.php index 66068cd36..a426f0276 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -109,7 +109,7 @@ function act_dispatch(){ $ACT = act_draftsave($ACT); //edit - if(($ACT == 'edit' || $ACT == 'preview' || $ACT == 'recover') && $INFO['editable']){ + if(in_array($ACT, array('edit', 'preview', 'recover'))) { $ACT = act_edit($ACT); }else{ unlock($ID); //try to unlock -- cgit v1.2.3 From de4d479af254512700b8aedce9c1a597880322b0 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Mon, 17 May 2010 11:05:23 +0200 Subject: Let actionOK detect auth backend capabilities --- inc/actions.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'inc/actions.php') diff --git a/inc/actions.php b/inc/actions.php index a426f0276..4b5bfdb1a 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -343,6 +343,11 @@ function act_revert($act){ global $ID; global $REV; global $lang; + // FIXME $INFO['writable'] currently refers to the attic version + // global $INFO; + // if (!$INFO['writable']) { + // return 'show'; + // } // when no revision is given, delete current one // FIXME this feature is not exposed in the GUI currently -- cgit v1.2.3 From b625808123f9b91b9803f98f818d5745bd7692cc Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 13 Jun 2010 11:40:31 +0200 Subject: msgs are saved in send_redirect now, less code duplication needed --- inc/actions.php | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'inc/actions.php') diff --git a/inc/actions.php b/inc/actions.php index 4b5bfdb1a..b447b65e1 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -387,16 +387,6 @@ function act_revert($act){ function act_redirect($id,$preact){ global $PRE; global $TEXT; - global $MSG; - - //are there any undisplayed messages? keep them in session for display - //on the next page - if(isset($MSG) && count($MSG)){ - //reopen session, store data and close session again - @session_start(); - $_SESSION[DOKU_COOKIE]['msg'] = $MSG; - session_write_close(); - } $opts = array( 'id' => $id, -- cgit v1.2.3 From 9fa341d04ad03c9f8328d3c4a836f8191a5f2f7a Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 26 Jun 2010 15:11:37 +0200 Subject: check for user in act_subscription FS#1935 --- inc/actions.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'inc/actions.php') diff --git a/inc/actions.php b/inc/actions.php index b447b65e1..5141f1941 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -596,6 +596,9 @@ function act_subscription($act){ global $INFO; global $ID; + // subcriptions work for logged in users only + if(!$_SERVER['REMOTE_USER']) return 'show'; + // get and preprocess data. $params = array(); foreach(array('target', 'style', 'action') as $param) { -- cgit v1.2.3 From 134b7bd9e90653ac01e8b80e46c4ec4ea0e62be0 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 27 Jun 2010 15:16:36 +0200 Subject: do not require special permissions to look at index FS#1720 --- inc/actions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/actions.php') diff --git a/inc/actions.php b/inc/actions.php index 5141f1941..914ff1ce6 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -231,7 +231,7 @@ function act_permcheck($act){ }else{ $permneed = AUTH_CREATE; } - }elseif(in_array($act,array('login','search','recent','profile'))){ + }elseif(in_array($act,array('login','search','recent','profile','index'))){ $permneed = AUTH_NONE; }elseif($act == 'revert'){ $permneed = AUTH_ADMIN; -- cgit v1.2.3 From 396c218f61d8626a516941cd6cd66f09e528e32c Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 27 Aug 2010 10:37:07 +0200 Subject: make use of tpl_get_action in tpl_actiondropdown FS#2005 --- inc/actions.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'inc/actions.php') diff --git a/inc/actions.php b/inc/actions.php index 914ff1ce6..3e0cb1207 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -185,6 +185,8 @@ function act_clean($act){ if($act == 'export_html') $act = 'export_xhtml'; if($act == 'export_htmlbody') $act = 'export_xhtmlbody'; + if($act === '') $act = 'show'; + // check if action is disabled if(!actionOK($act)){ msg('Command disabled: '.htmlspecialchars($act),-1); -- cgit v1.2.3