16b13307fSandi<?php 26b13307fSandi/** 36b13307fSandi * DokuWiki Actions 46b13307fSandi * 56b13307fSandi * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 66b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 76b13307fSandi */ 86b13307fSandi 9fa8adffeSAndreas Gohrif(!defined('DOKU_INC')) die('meh.'); 106b13307fSandirequire_once(DOKU_INC.'inc/template.php'); 116b13307fSandi 12af182434Sandi 136b13307fSandi/** 146b13307fSandi * Call the needed action handlers 156b13307fSandi * 166b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 17c9570649SAndreas Gohr * @triggers ACTION_ACT_PREPROCESS 18c9570649SAndreas Gohr * @triggers ACTION_HEADERS_SEND 196b13307fSandi */ 206b13307fSandifunction act_dispatch(){ 216b13307fSandi global $INFO; 226b13307fSandi global $ACT; 236b13307fSandi global $ID; 246b13307fSandi global $QUERY; 256b13307fSandi global $lang; 266b13307fSandi global $conf; 27066fee30SAndreas Gohr global $license; 286b13307fSandi 2969cd1e27SAndreas Gohr $preact = $ACT; 3069cd1e27SAndreas Gohr 31c2e830f2Schris // give plugins an opportunity to process the action 3224bb549bSchris $evt = new Doku_Event('ACTION_ACT_PREPROCESS',$ACT); 3324bb549bSchris if ($evt->advise_before()) { 34c2e830f2Schris 35af182434Sandi //sanitize $ACT 36af182434Sandi $ACT = act_clean($ACT); 37af182434Sandi 38b8957367SBenjamin Gilbert //check if searchword was given - else just show 390868021bSAndreas Gohr $s = cleanID($QUERY); 400868021bSAndreas Gohr if($ACT == 'search' && empty($s)){ 41b8957367SBenjamin Gilbert $ACT = 'show'; 42b8957367SBenjamin Gilbert } 43b8957367SBenjamin Gilbert 44b8957367SBenjamin Gilbert //login stuff 451b2a85e8SAndreas Gohr if(in_array($ACT,array('login','logout'))){ 46b8957367SBenjamin Gilbert $ACT = act_auth($ACT); 471b2a85e8SAndreas Gohr } 48b8957367SBenjamin Gilbert 491380fc45SAndreas Gohr //check if user is asking to (un)subscribe a page 501380fc45SAndreas Gohr if($ACT == 'subscribe' || $ACT == 'unsubscribe') 511380fc45SAndreas Gohr $ACT = act_subscription($ACT); 52b158d625SSteven Danz 5352b0dd67SGuy Brand //check if user is asking to (un)subscribe a namespace 5452b0dd67SGuy Brand if($ACT == 'subscribens' || $ACT == 'unsubscribens') 5552b0dd67SGuy Brand $ACT = act_subscriptionns($ACT); 5652b0dd67SGuy Brand 576b13307fSandi //check permissions 586b13307fSandi $ACT = act_permcheck($ACT); 596b13307fSandi 60b8957367SBenjamin Gilbert //register 61c9570649SAndreas Gohr $nil = array(); 62b3510079SAndreas Gohr if($ACT == 'register' && $_POST['save'] && register()){ 63b8957367SBenjamin Gilbert $ACT = 'login'; 64b8957367SBenjamin Gilbert } 656b13307fSandi 668b06d178Schris if ($ACT == 'resendpwd' && act_resendpwd()) { 678b06d178Schris $ACT = 'login'; 688b06d178Schris } 698b06d178Schris 708b06d178Schris //update user profile 7125b2a98cSMichael Klier if ($ACT == 'profile') { 7225b2a98cSMichael Klier if(!$_SERVER['REMOTE_USER']) { 7325b2a98cSMichael Klier $ACT = 'login'; 7425b2a98cSMichael Klier } else { 7525b2a98cSMichael Klier if(updateprofile()) { 764cb79657SMatthias Grimm msg($lang['profchanged'],1); 774cb79657SMatthias Grimm $ACT = 'show'; 788b06d178Schris } 7925b2a98cSMichael Klier } 8025b2a98cSMichael Klier } 818b06d178Schris 82*1246e016SAndreas Gohr //revert 83*1246e016SAndreas Gohr if($ACT == 'revert'){ 84*1246e016SAndreas Gohr if(checkSecurityToken()){ 85*1246e016SAndreas Gohr $ACT = act_revert($ACT); 86*1246e016SAndreas Gohr }else{ 87*1246e016SAndreas Gohr $ACT = 'show'; 88*1246e016SAndreas Gohr } 89*1246e016SAndreas Gohr } 90*1246e016SAndreas Gohr 916b13307fSandi //save 921b2a85e8SAndreas Gohr if($ACT == 'save'){ 931b2a85e8SAndreas Gohr if(checkSecurityToken()){ 946b13307fSandi $ACT = act_save($ACT); 951b2a85e8SAndreas Gohr }else{ 961b2a85e8SAndreas Gohr $ACT = 'show'; 971b2a85e8SAndreas Gohr } 981b2a85e8SAndreas Gohr } 996b13307fSandi 100067c5d22SBen Coburn //cancel conflicting edit 101067c5d22SBen Coburn if($ACT == 'cancel') 102067c5d22SBen Coburn $ACT = 'show'; 103067c5d22SBen Coburn 104ee4c4a1bSAndreas Gohr //draft deletion 105ee4c4a1bSAndreas Gohr if($ACT == 'draftdel') 106ee4c4a1bSAndreas Gohr $ACT = act_draftdel($ACT); 107ee4c4a1bSAndreas Gohr 108ee4c4a1bSAndreas Gohr //draft saving on preview 109ee4c4a1bSAndreas Gohr if($ACT == 'preview') 110ee4c4a1bSAndreas Gohr $ACT = act_draftsave($ACT); 111ee4c4a1bSAndreas Gohr 1126b13307fSandi //edit 113b146b32bSandi if(($ACT == 'edit' || $ACT == 'preview') && $INFO['editable']){ 114af182434Sandi $ACT = act_edit($ACT); 1156b13307fSandi }else{ 1166b13307fSandi unlock($ID); //try to unlock 1176b13307fSandi } 1186b13307fSandi 1196b13307fSandi //handle export 120ac83b9d8Sandi if(substr($ACT,0,7) == 'export_') 1216b13307fSandi $ACT = act_export($ACT); 1226b13307fSandi 1236b13307fSandi //display some infos 1246b13307fSandi if($ACT == 'check'){ 1256b13307fSandi check(); 1266b13307fSandi $ACT = 'show'; 1276b13307fSandi } 1286b13307fSandi 129c19fe9c0Sandi //handle admin tasks 130c19fe9c0Sandi if($ACT == 'admin'){ 13111e2ce22Schris // retrieve admin plugin name from $_REQUEST['page'] 132bb4866bdSchris if (!empty($_REQUEST['page'])) { 13311e2ce22Schris $pluginlist = plugin_list('admin'); 13411e2ce22Schris if (in_array($_REQUEST['page'], $pluginlist)) { 13511e2ce22Schris // attempt to load the plugin 13611e2ce22Schris if ($plugin =& plugin_load('admin',$_REQUEST['page']) !== NULL) 13711e2ce22Schris $plugin->handle(); 13811e2ce22Schris } 13911e2ce22Schris } 140c19fe9c0Sandi } 1415f312bacSAndreas Gohr 1425f312bacSAndreas Gohr // check permissions again - the action may have changed 1435f312bacSAndreas Gohr $ACT = act_permcheck($ACT); 14424bb549bSchris } // end event ACTION_ACT_PREPROCESS default action 14524bb549bSchris $evt->advise_after(); 14624bb549bSchris unset($evt); 147c19fe9c0Sandi 14846c0ed74SMichael Hamann // when action 'show', the intial not 'show' and POST, do a redirect 14946c0ed74SMichael Hamann if($ACT == 'show' && $preact != 'show' && strtolower($_SERVER['REQUEST_METHOD']) == 'post'){ 15069cd1e27SAndreas Gohr act_redirect($ID,$preact); 15169cd1e27SAndreas Gohr } 1525f312bacSAndreas Gohr 1536b13307fSandi //call template FIXME: all needed vars available? 154f63a2007Schris $headers[] = 'Content-Type: text/html; charset=utf-8'; 155746855cfSBen Coburn trigger_event('ACTION_HEADERS_SEND',$headers,'act_sendheaders'); 156f63a2007Schris 1575a892029SAndreas Gohr include(template('main.php')); 158c19fe9c0Sandi // output for the commands is now handled in inc/templates.php 159c19fe9c0Sandi // in function tpl_content() 1606b13307fSandi} 1616b13307fSandi 162f63a2007Schrisfunction act_sendheaders($headers) { 163f63a2007Schris foreach ($headers as $hdr) header($hdr); 164f63a2007Schris} 165f63a2007Schris 1666b13307fSandi/** 167af182434Sandi * Sanitize the action command 168af182434Sandi * 169af182434Sandi * Add all allowed commands here. 170af182434Sandi * 171af182434Sandi * @author Andreas Gohr <andi@splitbrain.org> 172af182434Sandi */ 173af182434Sandifunction act_clean($act){ 174af182434Sandi global $lang; 17560e6b550SAndreas Gohr global $conf; 176af182434Sandi 177ee4c4a1bSAndreas Gohr // check if the action was given as array key 178ee4c4a1bSAndreas Gohr if(is_array($act)){ 179ee4c4a1bSAndreas Gohr list($act) = array_keys($act); 180ee4c4a1bSAndreas Gohr } 181ee4c4a1bSAndreas Gohr 182ac83b9d8Sandi //remove all bad chars 183ac83b9d8Sandi $act = strtolower($act); 1842d5ccb39SAndreas Gohr $act = preg_replace('/[^1-9a-z_]+/','',$act); 185ac83b9d8Sandi 186ac83b9d8Sandi if($act == 'export_html') $act = 'export_xhtml'; 187cc2ae802SAndreas Gohr if($act == 'export_htmlbody') $act = 'export_xhtmlbody'; 188b146b32bSandi 189409d7af7SAndreas Gohr // check if action is disabled 190409d7af7SAndreas Gohr if(!actionOK($act)){ 191409d7af7SAndreas Gohr msg('Command disabled: '.htmlspecialchars($act),-1); 192409d7af7SAndreas Gohr return 'show'; 193409d7af7SAndreas Gohr } 194409d7af7SAndreas Gohr 19560e6b550SAndreas Gohr //disable all acl related commands if ACL is disabled 19660e6b550SAndreas Gohr if(!$conf['useacl'] && in_array($act,array('login','logout','register','admin', 197*1246e016SAndreas Gohr 'subscribe','unsubscribe','profile','revert', 19852b0dd67SGuy Brand 'resendpwd','subscribens','unsubscribens',))){ 19960e6b550SAndreas Gohr msg('Command unavailable: '.htmlspecialchars($act),-1); 20060e6b550SAndreas Gohr return 'show'; 20160e6b550SAndreas Gohr } 20260e6b550SAndreas Gohr 203067c5d22SBen Coburn if(!in_array($act,array('login','logout','register','save','cancel','edit','draft', 204ac83b9d8Sandi 'preview','search','show','check','index','revisions', 205*1246e016SAndreas Gohr 'diff','recent','backlink','admin','subscribe','revert', 20618829381SAndreas Gohr 'unsubscribe','profile','resendpwd','recover','wordblock', 20752b0dd67SGuy Brand 'draftdel','subscribens','unsubscribens',)) && substr($act,0,7) != 'export_' ) { 208ee4c4a1bSAndreas Gohr msg('Command unknown: '.htmlspecialchars($act),-1); 209af182434Sandi return 'show'; 210af182434Sandi } 211af182434Sandi return $act; 212af182434Sandi} 213af182434Sandi 214af182434Sandi/** 2156b13307fSandi * Run permissionchecks 2166b13307fSandi * 2176b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 2186b13307fSandi */ 2196b13307fSandifunction act_permcheck($act){ 220dbbc6aa7Sandi global $INFO; 2215e199953Smatthiasgrimm global $conf; 222dbbc6aa7Sandi 223ee4c4a1bSAndreas Gohr if(in_array($act,array('save','preview','edit','recover'))){ 2246b13307fSandi if($INFO['exists']){ 225bdbc16bfSandi if($act == 'edit'){ 226bdbc16bfSandi //the edit function will check again and do a source show 227bdbc16bfSandi //when no AUTH_EDIT available 228bdbc16bfSandi $permneed = AUTH_READ; 229bdbc16bfSandi }else{ 2306b13307fSandi $permneed = AUTH_EDIT; 231bdbc16bfSandi } 2326b13307fSandi }else{ 2336b13307fSandi $permneed = AUTH_CREATE; 2346b13307fSandi } 2358b06d178Schris }elseif(in_array($act,array('login','search','recent','profile'))){ 2366b13307fSandi $permneed = AUTH_NONE; 237*1246e016SAndreas Gohr }elseif($act == 'revert'){ 238*1246e016SAndreas Gohr $permneed = AUTH_ADMIN; 239*1246e016SAndreas Gohr if($INFO['ismanager']) $permneed = AUTH_EDIT; 2405e199953Smatthiasgrimm }elseif($act == 'register'){ 2415e199953Smatthiasgrimm $permneed = AUTH_NONE; 242ebd3d9ceSchris }elseif($act == 'resendpwd'){ 243ebd3d9ceSchris $permneed = AUTH_NONE; 244c19fe9c0Sandi }elseif($act == 'admin'){ 245f8cc712eSAndreas Gohr if($INFO['ismanager']){ 246f8cc712eSAndreas Gohr // if the manager has the needed permissions for a certain admin 247f8cc712eSAndreas Gohr // action is checked later 248f8cc712eSAndreas Gohr $permneed = AUTH_READ; 249f8cc712eSAndreas Gohr }else{ 250c19fe9c0Sandi $permneed = AUTH_ADMIN; 251f8cc712eSAndreas Gohr } 2526b13307fSandi }else{ 2536b13307fSandi $permneed = AUTH_READ; 2546b13307fSandi } 255dbbc6aa7Sandi if($INFO['perm'] >= $permneed) return $act; 256dbbc6aa7Sandi 2576b13307fSandi return 'denied'; 2586b13307fSandi} 2596b13307fSandi 2606b13307fSandi/** 261ee4c4a1bSAndreas Gohr * Handle 'draftdel' 262ee4c4a1bSAndreas Gohr * 263ee4c4a1bSAndreas Gohr * Deletes the draft for the current page and user 264ee4c4a1bSAndreas Gohr */ 265ee4c4a1bSAndreas Gohrfunction act_draftdel($act){ 266ee4c4a1bSAndreas Gohr global $INFO; 267ee4c4a1bSAndreas Gohr @unlink($INFO['draft']); 268ee4c4a1bSAndreas Gohr $INFO['draft'] = null; 269ee4c4a1bSAndreas Gohr return 'show'; 270ee4c4a1bSAndreas Gohr} 271ee4c4a1bSAndreas Gohr 272ee4c4a1bSAndreas Gohr/** 273ee4c4a1bSAndreas Gohr * Saves a draft on preview 274ee4c4a1bSAndreas Gohr * 275ee4c4a1bSAndreas Gohr * @todo this currently duplicates code from ajax.php :-/ 276ee4c4a1bSAndreas Gohr */ 277ee4c4a1bSAndreas Gohrfunction act_draftsave($act){ 278ee4c4a1bSAndreas Gohr global $INFO; 279ee4c4a1bSAndreas Gohr global $ID; 280ee4c4a1bSAndreas Gohr global $conf; 281ee4c4a1bSAndreas Gohr if($conf['usedraft'] && $_POST['wikitext']){ 282ee4c4a1bSAndreas Gohr $draft = array('id' => $ID, 283ee4c4a1bSAndreas Gohr 'prefix' => $_POST['prefix'], 284ee4c4a1bSAndreas Gohr 'text' => $_POST['wikitext'], 285ee4c4a1bSAndreas Gohr 'suffix' => $_POST['suffix'], 286ee4c4a1bSAndreas Gohr 'date' => $_POST['date'], 287ee4c4a1bSAndreas Gohr 'client' => $INFO['client'], 288ee4c4a1bSAndreas Gohr ); 289ee4c4a1bSAndreas Gohr $cname = getCacheName($draft['client'].$ID,'.draft'); 290ee4c4a1bSAndreas Gohr if(io_saveFile($cname,serialize($draft))){ 291ee4c4a1bSAndreas Gohr $INFO['draft'] = $cname; 292ee4c4a1bSAndreas Gohr } 293ee4c4a1bSAndreas Gohr } 294ee4c4a1bSAndreas Gohr return $act; 295ee4c4a1bSAndreas Gohr} 296ee4c4a1bSAndreas Gohr 297ee4c4a1bSAndreas Gohr/** 2986b13307fSandi * Handle 'save' 2996b13307fSandi * 3006b13307fSandi * Checks for spam and conflicts and saves the page. 3016b13307fSandi * Does a redirect to show the page afterwards or 3026b13307fSandi * returns a new action. 3036b13307fSandi * 3046b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 3056b13307fSandi */ 3066b13307fSandifunction act_save($act){ 3076b13307fSandi global $ID; 3086b13307fSandi global $DATE; 3096b13307fSandi global $PRE; 3106b13307fSandi global $TEXT; 3116b13307fSandi global $SUF; 3126b13307fSandi global $SUM; 3136b13307fSandi 3146b13307fSandi //spam check 3156b13307fSandi if(checkwordblock()) 3166b13307fSandi return 'wordblock'; 3176b13307fSandi //conflict check //FIXME use INFO 3186b13307fSandi if($DATE != 0 && @filemtime(wikiFN($ID)) > $DATE ) 3196b13307fSandi return 'conflict'; 3206b13307fSandi 3216b13307fSandi //save it 322b6912aeaSAndreas Gohr saveWikiText($ID,con($PRE,$TEXT,$SUF,1),$SUM,$_REQUEST['minor']); //use pretty mode for con 3236b13307fSandi //unlock it 3246b13307fSandi unlock($ID); 3256b13307fSandi 326ee4c4a1bSAndreas Gohr //delete draft 327ee4c4a1bSAndreas Gohr act_draftdel($act); 32869cd1e27SAndreas Gohr session_write_close(); 329ee4c4a1bSAndreas Gohr 33069cd1e27SAndreas Gohr // when done, show page 33169cd1e27SAndreas Gohr return 'show'; 33269cd1e27SAndreas Gohr} 333f951a474SAndreas Gohr 33414a122deSAndreas Gohr/** 335*1246e016SAndreas Gohr * Revert to a certain revision 336*1246e016SAndreas Gohr * 337*1246e016SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 338*1246e016SAndreas Gohr */ 339*1246e016SAndreas Gohrfunction act_revert($act){ 340*1246e016SAndreas Gohr global $ID; 341*1246e016SAndreas Gohr global $REV; 342*1246e016SAndreas Gohr global $lang; 343*1246e016SAndreas Gohr 344*1246e016SAndreas Gohr // when no revision is given, delete current one 345*1246e016SAndreas Gohr // FIXME this feature is not exposed in the GUI currently 346*1246e016SAndreas Gohr $text = ''; 347*1246e016SAndreas Gohr $sum = $lang['deleted']; 348*1246e016SAndreas Gohr if($REV){ 349*1246e016SAndreas Gohr $text = rawWiki($ID,$REV); 350*1246e016SAndreas Gohr if(!$text) return 'show'; //something went wrong 351*1246e016SAndreas Gohr $sum = $lang['restored']; 352*1246e016SAndreas Gohr } 353*1246e016SAndreas Gohr 354*1246e016SAndreas Gohr // spam check 355*1246e016SAndreas Gohr if(checkwordblock($Text)) 356*1246e016SAndreas Gohr return 'wordblock'; 357*1246e016SAndreas Gohr 358*1246e016SAndreas Gohr saveWikiText($ID,$text,$sum,false); 359*1246e016SAndreas Gohr msg($sum,1); 360*1246e016SAndreas Gohr 361*1246e016SAndreas Gohr //delete any draft 362*1246e016SAndreas Gohr act_draftdel($act); 363*1246e016SAndreas Gohr session_write_close(); 364*1246e016SAndreas Gohr 365*1246e016SAndreas Gohr // when done, show current page 366*1246e016SAndreas Gohr $_SERVER['REQUEST_METHOD'] = 'post'; //should force a redirect 367*1246e016SAndreas Gohr $REV = ''; 368*1246e016SAndreas Gohr return 'show'; 369*1246e016SAndreas Gohr} 370*1246e016SAndreas Gohr 371*1246e016SAndreas Gohr/** 37214a122deSAndreas Gohr * Do a redirect after receiving post data 37314a122deSAndreas Gohr * 37414a122deSAndreas Gohr * Tries to add the section id as hash mark after section editing 37514a122deSAndreas Gohr */ 37669cd1e27SAndreas Gohrfunction act_redirect($id,$preact){ 37769cd1e27SAndreas Gohr global $PRE; 37869cd1e27SAndreas Gohr global $TEXT; 37914a122deSAndreas Gohr global $MSG; 38014a122deSAndreas Gohr 38114a122deSAndreas Gohr //are there any undisplayed messages? keep them in session for display 38214a122deSAndreas Gohr //on the next page 38314a122deSAndreas Gohr if(isset($MSG) && count($MSG)){ 38414a122deSAndreas Gohr //reopen session, store data and close session again 38514a122deSAndreas Gohr @session_start(); 38614a122deSAndreas Gohr $_SESSION[DOKU_COOKIE]['msg'] = $MSG; 38714a122deSAndreas Gohr session_write_close(); 38814a122deSAndreas Gohr } 389f951a474SAndreas Gohr 390f951a474SAndreas Gohr //get section name when coming from section edit 391f951a474SAndreas Gohr if($PRE && preg_match('/^\s*==+([^=\n]+)/',$TEXT,$match)){ 392443d207bSAndreas Gohr $check = false; 393443d207bSAndreas Gohr $title = sectionID($match[0],$check); 394f951a474SAndreas Gohr } 395f951a474SAndreas Gohr 39669cd1e27SAndreas Gohr $opts = array( 39769cd1e27SAndreas Gohr 'id' => $id, 39869cd1e27SAndreas Gohr 'fragment' => $title, 39969cd1e27SAndreas Gohr 'preact' => $preact 40069cd1e27SAndreas Gohr ); 40169cd1e27SAndreas Gohr trigger_event('ACTION_SHOW_REDIRECT',$opts,'act_redirect_execute'); 40269cd1e27SAndreas Gohr} 40369cd1e27SAndreas Gohr 40469cd1e27SAndreas Gohrfunction act_redirect_execute($opts){ 40569cd1e27SAndreas Gohr $go = wl($opts['id'],'',true); 40669cd1e27SAndreas Gohr if($opts['fragment']) $go .= '#'.$opts['fragment']; 40769cd1e27SAndreas Gohr 4086b13307fSandi //show it 409af2408d5SAndreas Gohr send_redirect($go); 4106b13307fSandi} 4116b13307fSandi 4126b13307fSandi/** 413b8957367SBenjamin Gilbert * Handle 'login', 'logout' 4146b13307fSandi * 4156b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 4166b13307fSandi */ 4176b13307fSandifunction act_auth($act){ 41808eda5bcSmatthiasgrimm global $ID; 4197cace34dSAndreas Gohr global $INFO; 42008eda5bcSmatthiasgrimm 4216b13307fSandi //already logged in? 4222288dc06SGuy Brand if($_SERVER['REMOTE_USER'] && $act=='login'){ 423ca12ce46SAndreas Gohr return 'show'; 4242288dc06SGuy Brand } 4256b13307fSandi 4266b13307fSandi //handle logout 4276b13307fSandi if($act=='logout'){ 42808eda5bcSmatthiasgrimm $lockedby = checklock($ID); //page still locked? 429424c3c4fSJohannes Buchner if($lockedby == $_SERVER['REMOTE_USER']) 43008eda5bcSmatthiasgrimm unlock($ID); //try to unlock 43108eda5bcSmatthiasgrimm 4327cace34dSAndreas Gohr // do the logout stuff 4336b13307fSandi auth_logoff(); 4347cace34dSAndreas Gohr 4357cace34dSAndreas Gohr // rebuild info array 4367cace34dSAndreas Gohr $INFO = pageinfo(); 4377cace34dSAndreas Gohr 438e16eccb7SGuy Brand act_redirect($ID,'login'); 4396b13307fSandi } 4406b13307fSandi 4416b13307fSandi return $act; 4426b13307fSandi} 4436b13307fSandi 4446b13307fSandi/** 4456b13307fSandi * Handle 'edit', 'preview' 4466b13307fSandi * 4476b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 4486b13307fSandi */ 4496b13307fSandifunction act_edit($act){ 450cd409024Sjorda global $ID; 451ee4c4a1bSAndreas Gohr global $INFO; 452cd409024Sjorda 4536b13307fSandi //check if locked by anyone - if not lock for my self 4546b13307fSandi $lockedby = checklock($ID); 4556b13307fSandi if($lockedby) return 'locked'; 4566b13307fSandi 4576b13307fSandi lock($ID); 4586b13307fSandi return $act; 4596b13307fSandi} 4606b13307fSandi 4616b13307fSandi/** 462f6dad9fdSMichael Klier * Export a wiki page for various formats 463f6dad9fdSMichael Klier * 464f6dad9fdSMichael Klier * Triggers ACTION_EXPORT_POSTPROCESS 465f6dad9fdSMichael Klier * 466f6dad9fdSMichael Klier * Event data: 467f6dad9fdSMichael Klier * data['id'] -- page id 468f6dad9fdSMichael Klier * data['mode'] -- requested export mode 469f6dad9fdSMichael Klier * data['headers'] -- export headers 470f6dad9fdSMichael Klier * data['output'] -- export output 4716b13307fSandi * 4726b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 473f6dad9fdSMichael Klier * @author Michael Klier <chi@chimeric.de> 4746b13307fSandi */ 4756b13307fSandifunction act_export($act){ 4766b13307fSandi global $ID; 4776b13307fSandi global $REV; 47885f8705cSAnika Henke global $conf; 47985f8705cSAnika Henke global $lang; 4806b13307fSandi 481f6dad9fdSMichael Klier $pre = ''; 482f6dad9fdSMichael Klier $post = ''; 483f6dad9fdSMichael Klier $output = ''; 484f6dad9fdSMichael Klier $headers = array(); 485cc2ae802SAndreas Gohr 486f6dad9fdSMichael Klier // search engines: never cache exported docs! (Google only currently) 487f6dad9fdSMichael Klier $headers['X-Robots-Tag'] = 'noindex'; 488f6dad9fdSMichael Klier 489ac83b9d8Sandi $mode = substr($act,7); 490f6dad9fdSMichael Klier switch($mode) { 491f6dad9fdSMichael Klier case 'raw': 4925adfc5afSAnika Henke $headers['Content-Type'] = 'text/plain; charset=utf-8'; 493f6dad9fdSMichael Klier $output = rawWiki($ID,$REV); 494f6dad9fdSMichael Klier break; 495f6dad9fdSMichael Klier case 'xhtml': 496f6dad9fdSMichael Klier $pre .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"' . DOKU_LF; 497f6dad9fdSMichael Klier $pre .= ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . DOKU_LF; 498f6dad9fdSMichael Klier $pre .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.$conf['lang'].'"' . DOKU_LF; 499f6dad9fdSMichael Klier $pre .= ' lang="'.$conf['lang'].'" dir="'.$lang['direction'].'">' . DOKU_LF; 500f6dad9fdSMichael Klier $pre .= '<head>' . DOKU_LF; 501f6dad9fdSMichael Klier $pre .= ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' . DOKU_LF; 502f6dad9fdSMichael Klier $pre .= ' <title>'.$ID.'</title>' . DOKU_LF; 503f6dad9fdSMichael Klier 504f6dad9fdSMichael Klier // get metaheaders 505f6dad9fdSMichael Klier ob_start(); 506f6dad9fdSMichael Klier tpl_metaheaders(); 507f6dad9fdSMichael Klier $pre .= ob_get_clean(); 508f6dad9fdSMichael Klier 509f6dad9fdSMichael Klier $pre .= '</head>' . DOKU_LF; 510f6dad9fdSMichael Klier $pre .= '<body>' . DOKU_LF; 511f6dad9fdSMichael Klier $pre .= '<div class="dokuwiki export">' . DOKU_LF; 512f6dad9fdSMichael Klier 513f6dad9fdSMichael Klier // get toc 514f6dad9fdSMichael Klier $pre .= tpl_toc(true); 515f6dad9fdSMichael Klier 516f6dad9fdSMichael Klier $headers['Content-Type'] = 'text/html; charset=utf-8'; 517f6dad9fdSMichael Klier $output = p_wiki_xhtml($ID,$REV,false); 518f6dad9fdSMichael Klier 519f6dad9fdSMichael Klier $post .= '</div>' . DOKU_LF; 520f6dad9fdSMichael Klier $post .= '</body>' . DOKU_LF; 521f6dad9fdSMichael Klier $post .= '</html>' . DOKU_LF; 522f6dad9fdSMichael Klier break; 523f6dad9fdSMichael Klier case 'xhtmlbody': 524f6dad9fdSMichael Klier $headers['Content-Type'] = 'text/html; charset=utf-8'; 525f6dad9fdSMichael Klier $output = p_wiki_xhtml($ID,$REV,false); 526f6dad9fdSMichael Klier break; 527f6dad9fdSMichael Klier default: 528f6dad9fdSMichael Klier $output = p_cached_output(wikiFN($ID,$REV), $mode); 5299acedd40SAndreas Gohr $headers = p_get_metadata($ID,"format $mode"); 530f6dad9fdSMichael Klier break; 531f6dad9fdSMichael Klier } 532f6dad9fdSMichael Klier 533f6dad9fdSMichael Klier // prepare event data 534f6dad9fdSMichael Klier $data = array(); 535f6dad9fdSMichael Klier $data['id'] = $ID; 536f6dad9fdSMichael Klier $data['mode'] = $mode; 537f6dad9fdSMichael Klier $data['headers'] = $headers; 538f6dad9fdSMichael Klier $data['output'] =& $output; 539f6dad9fdSMichael Klier 540f6dad9fdSMichael Klier trigger_event('ACTION_EXPORT_POSTPROCESS', $data); 541f6dad9fdSMichael Klier 542f6dad9fdSMichael Klier if(!empty($data['output'])){ 543f6dad9fdSMichael Klier if(is_array($data['headers'])) foreach($data['headers'] as $key => $val){ 54485767031SAndreas Gohr header("$key: $val"); 54585767031SAndreas Gohr } 546f6dad9fdSMichael Klier print $pre.$data['output'].$post; 5476b13307fSandi exit; 5486b13307fSandi } 5496b13307fSandi return 'show'; 5506b13307fSandi} 551340756e4Sandi 552b158d625SSteven Danz/** 55352b0dd67SGuy Brand * Handle page 'subscribe', 'unsubscribe' 554b158d625SSteven Danz * 555b158d625SSteven Danz * @author Steven Danz <steven-danz@kc.rr.com> 5561380fc45SAndreas Gohr * @todo localize 557b158d625SSteven Danz */ 5581380fc45SAndreas Gohrfunction act_subscription($act){ 559b158d625SSteven Danz global $ID; 560b158d625SSteven Danz global $INFO; 561f9eb5648Ssteven-danz global $lang; 562b158d625SSteven Danz 5631380fc45SAndreas Gohr $file=metaFN($ID,'.mlist'); 5641380fc45SAndreas Gohr if ($act=='subscribe' && !$INFO['subscribed']){ 565b158d625SSteven Danz if ($INFO['userinfo']['mail']){ 5661380fc45SAndreas Gohr if (io_saveFile($file,$_SERVER['REMOTE_USER']."\n",true)) { 5671380fc45SAndreas Gohr $INFO['subscribed'] = true; 568f9eb5648Ssteven-danz msg(sprintf($lang[$act.'_success'], $INFO['userinfo']['name'], $ID),1); 569b158d625SSteven Danz } else { 570f9eb5648Ssteven-danz msg(sprintf($lang[$act.'_error'], $INFO['userinfo']['name'], $ID),1); 571b158d625SSteven Danz } 572b158d625SSteven Danz } else { 573f9eb5648Ssteven-danz msg($lang['subscribe_noaddress']); 574b158d625SSteven Danz } 5751380fc45SAndreas Gohr } elseif ($act=='unsubscribe' && $INFO['subscribed']){ 576b158d625SSteven Danz if (io_deleteFromFile($file,$_SERVER['REMOTE_USER']."\n")) { 5771380fc45SAndreas Gohr $INFO['subscribed'] = false; 578f9eb5648Ssteven-danz msg(sprintf($lang[$act.'_success'], $INFO['userinfo']['name'], $ID),1); 579b158d625SSteven Danz } else { 580f9eb5648Ssteven-danz msg(sprintf($lang[$act.'_error'], $INFO['userinfo']['name'], $ID),1); 581b158d625SSteven Danz } 582b158d625SSteven Danz } 583b158d625SSteven Danz 584b158d625SSteven Danz return 'show'; 585b158d625SSteven Danz} 586b158d625SSteven Danz 58752b0dd67SGuy Brand/** 58852b0dd67SGuy Brand * Handle namespace 'subscribe', 'unsubscribe' 58952b0dd67SGuy Brand * 59052b0dd67SGuy Brand */ 59152b0dd67SGuy Brandfunction act_subscriptionns($act){ 59252b0dd67SGuy Brand global $ID; 59352b0dd67SGuy Brand global $INFO; 59452b0dd67SGuy Brand global $lang; 59552b0dd67SGuy Brand 59652b0dd67SGuy Brand if(!getNS($ID)) { 59752b0dd67SGuy Brand $file = metaFN(getNS($ID),'.mlist'); 598613964ecSGuy Brand $ns = "root"; 59952b0dd67SGuy Brand } else { 60052b0dd67SGuy Brand $file = metaFN(getNS($ID),'/.mlist'); 601613964ecSGuy Brand $ns = getNS($ID); 60252b0dd67SGuy Brand } 60352b0dd67SGuy Brand 604613964ecSGuy Brand // reuse strings used to display the status of the subscribe action 605613964ecSGuy Brand $act_msg = rtrim($act, 'ns'); 606613964ecSGuy Brand 60752b0dd67SGuy Brand if ($act=='subscribens' && !$INFO['subscribedns']){ 60852b0dd67SGuy Brand if ($INFO['userinfo']['mail']){ 60952b0dd67SGuy Brand if (io_saveFile($file,$_SERVER['REMOTE_USER']."\n",true)) { 61052b0dd67SGuy Brand $INFO['subscribedns'] = true; 611613964ecSGuy Brand msg(sprintf($lang[$act_msg.'_success'], $INFO['userinfo']['name'], $ns),1); 61252b0dd67SGuy Brand } else { 613613964ecSGuy Brand msg(sprintf($lang[$act_msg.'_error'], $INFO['userinfo']['name'], $ns),1); 61452b0dd67SGuy Brand } 61552b0dd67SGuy Brand } else { 61652b0dd67SGuy Brand msg($lang['subscribe_noaddress']); 61752b0dd67SGuy Brand } 61852b0dd67SGuy Brand } elseif ($act=='unsubscribens' && $INFO['subscribedns']){ 61952b0dd67SGuy Brand if (io_deleteFromFile($file,$_SERVER['REMOTE_USER']."\n")) { 62052b0dd67SGuy Brand $INFO['subscribedns'] = false; 621613964ecSGuy Brand msg(sprintf($lang[$act_msg.'_success'], $INFO['userinfo']['name'], $ns),1); 62252b0dd67SGuy Brand } else { 623613964ecSGuy Brand msg(sprintf($lang[$act_msg.'_error'], $INFO['userinfo']['name'], $ns),1); 62452b0dd67SGuy Brand } 62552b0dd67SGuy Brand } 62652b0dd67SGuy Brand 62752b0dd67SGuy Brand return 'show'; 62852b0dd67SGuy Brand} 62952b0dd67SGuy Brand 630340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 : 631