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 50*5b75cd1fSAdrian Lang if($ACT == 'subscribe') { 51*5b75cd1fSAdrian Lang try { 521380fc45SAndreas Gohr $ACT = act_subscription($ACT); 53*5b75cd1fSAdrian Lang } catch (Exception $e) { 54*5b75cd1fSAdrian Lang msg($e->getMessage(), -1); 55*5b75cd1fSAdrian Lang } 56*5b75cd1fSAdrian Lang } 5752b0dd67SGuy Brand 586b13307fSandi //check permissions 596b13307fSandi $ACT = act_permcheck($ACT); 606b13307fSandi 61b8957367SBenjamin Gilbert //register 62c9570649SAndreas Gohr $nil = array(); 63b3510079SAndreas Gohr if($ACT == 'register' && $_POST['save'] && register()){ 64b8957367SBenjamin Gilbert $ACT = 'login'; 65b8957367SBenjamin Gilbert } 666b13307fSandi 678b06d178Schris if ($ACT == 'resendpwd' && act_resendpwd()) { 688b06d178Schris $ACT = 'login'; 698b06d178Schris } 708b06d178Schris 718b06d178Schris //update user profile 7225b2a98cSMichael Klier if ($ACT == 'profile') { 7325b2a98cSMichael Klier if(!$_SERVER['REMOTE_USER']) { 7425b2a98cSMichael Klier $ACT = 'login'; 7525b2a98cSMichael Klier } else { 7625b2a98cSMichael Klier if(updateprofile()) { 774cb79657SMatthias Grimm msg($lang['profchanged'],1); 784cb79657SMatthias Grimm $ACT = 'show'; 798b06d178Schris } 8025b2a98cSMichael Klier } 8125b2a98cSMichael Klier } 828b06d178Schris 831246e016SAndreas Gohr //revert 841246e016SAndreas Gohr if($ACT == 'revert'){ 851246e016SAndreas Gohr if(checkSecurityToken()){ 861246e016SAndreas Gohr $ACT = act_revert($ACT); 871246e016SAndreas Gohr }else{ 881246e016SAndreas Gohr $ACT = 'show'; 891246e016SAndreas Gohr } 901246e016SAndreas Gohr } 911246e016SAndreas Gohr 926b13307fSandi //save 931b2a85e8SAndreas Gohr if($ACT == 'save'){ 941b2a85e8SAndreas Gohr if(checkSecurityToken()){ 956b13307fSandi $ACT = act_save($ACT); 961b2a85e8SAndreas Gohr }else{ 971b2a85e8SAndreas Gohr $ACT = 'show'; 981b2a85e8SAndreas Gohr } 991b2a85e8SAndreas Gohr } 1006b13307fSandi 101067c5d22SBen Coburn //cancel conflicting edit 102067c5d22SBen Coburn if($ACT == 'cancel') 103067c5d22SBen Coburn $ACT = 'show'; 104067c5d22SBen Coburn 105ee4c4a1bSAndreas Gohr //draft deletion 106ee4c4a1bSAndreas Gohr if($ACT == 'draftdel') 107ee4c4a1bSAndreas Gohr $ACT = act_draftdel($ACT); 108ee4c4a1bSAndreas Gohr 109ee4c4a1bSAndreas Gohr //draft saving on preview 110ee4c4a1bSAndreas Gohr if($ACT == 'preview') 111ee4c4a1bSAndreas Gohr $ACT = act_draftsave($ACT); 112ee4c4a1bSAndreas Gohr 1136b13307fSandi //edit 114b146b32bSandi if(($ACT == 'edit' || $ACT == 'preview') && $INFO['editable']){ 115af182434Sandi $ACT = act_edit($ACT); 1166b13307fSandi }else{ 1176b13307fSandi unlock($ID); //try to unlock 1186b13307fSandi } 1196b13307fSandi 1206b13307fSandi //handle export 121ac83b9d8Sandi if(substr($ACT,0,7) == 'export_') 1226b13307fSandi $ACT = act_export($ACT); 1236b13307fSandi 1246b13307fSandi //display some infos 1256b13307fSandi if($ACT == 'check'){ 1266b13307fSandi check(); 1276b13307fSandi $ACT = 'show'; 1286b13307fSandi } 1296b13307fSandi 130c19fe9c0Sandi //handle admin tasks 131c19fe9c0Sandi if($ACT == 'admin'){ 13211e2ce22Schris // retrieve admin plugin name from $_REQUEST['page'] 133bb4866bdSchris if (!empty($_REQUEST['page'])) { 13411e2ce22Schris $pluginlist = plugin_list('admin'); 13511e2ce22Schris if (in_array($_REQUEST['page'], $pluginlist)) { 13611e2ce22Schris // attempt to load the plugin 13749eb6e38SAndreas Gohr if ($plugin =& plugin_load('admin',$_REQUEST['page']) !== null) 13811e2ce22Schris $plugin->handle(); 13911e2ce22Schris } 14011e2ce22Schris } 141c19fe9c0Sandi } 1425f312bacSAndreas Gohr 1435f312bacSAndreas Gohr // check permissions again - the action may have changed 1445f312bacSAndreas Gohr $ACT = act_permcheck($ACT); 14524bb549bSchris } // end event ACTION_ACT_PREPROCESS default action 14624bb549bSchris $evt->advise_after(); 14724bb549bSchris unset($evt); 148c19fe9c0Sandi 14946c0ed74SMichael Hamann // when action 'show', the intial not 'show' and POST, do a redirect 15046c0ed74SMichael Hamann if($ACT == 'show' && $preact != 'show' && strtolower($_SERVER['REQUEST_METHOD']) == 'post'){ 15169cd1e27SAndreas Gohr act_redirect($ID,$preact); 15269cd1e27SAndreas Gohr } 1535f312bacSAndreas Gohr 1546b13307fSandi //call template FIXME: all needed vars available? 155f63a2007Schris $headers[] = 'Content-Type: text/html; charset=utf-8'; 156746855cfSBen Coburn trigger_event('ACTION_HEADERS_SEND',$headers,'act_sendheaders'); 157f63a2007Schris 1585a892029SAndreas Gohr include(template('main.php')); 159c19fe9c0Sandi // output for the commands is now handled in inc/templates.php 160c19fe9c0Sandi // in function tpl_content() 1616b13307fSandi} 1626b13307fSandi 163f63a2007Schrisfunction act_sendheaders($headers) { 164f63a2007Schris foreach ($headers as $hdr) header($hdr); 165f63a2007Schris} 166f63a2007Schris 1676b13307fSandi/** 168af182434Sandi * Sanitize the action command 169af182434Sandi * 170af182434Sandi * Add all allowed commands here. 171af182434Sandi * 172af182434Sandi * @author Andreas Gohr <andi@splitbrain.org> 173af182434Sandi */ 174af182434Sandifunction act_clean($act){ 175af182434Sandi global $lang; 17660e6b550SAndreas Gohr global $conf; 177af182434Sandi 178ee4c4a1bSAndreas Gohr // check if the action was given as array key 179ee4c4a1bSAndreas Gohr if(is_array($act)){ 180ee4c4a1bSAndreas Gohr list($act) = array_keys($act); 181ee4c4a1bSAndreas Gohr } 182ee4c4a1bSAndreas Gohr 183ac83b9d8Sandi //remove all bad chars 184ac83b9d8Sandi $act = strtolower($act); 1852d5ccb39SAndreas Gohr $act = preg_replace('/[^1-9a-z_]+/','',$act); 186ac83b9d8Sandi 187ac83b9d8Sandi if($act == 'export_html') $act = 'export_xhtml'; 188cc2ae802SAndreas Gohr if($act == 'export_htmlbody') $act = 'export_xhtmlbody'; 189b146b32bSandi 190409d7af7SAndreas Gohr // check if action is disabled 191409d7af7SAndreas Gohr if(!actionOK($act)){ 192409d7af7SAndreas Gohr msg('Command disabled: '.htmlspecialchars($act),-1); 193409d7af7SAndreas Gohr return 'show'; 194409d7af7SAndreas Gohr } 195409d7af7SAndreas Gohr 19660e6b550SAndreas Gohr //disable all acl related commands if ACL is disabled 19760e6b550SAndreas Gohr if(!$conf['useacl'] && in_array($act,array('login','logout','register','admin', 1981246e016SAndreas Gohr 'subscribe','unsubscribe','profile','revert', 19952b0dd67SGuy Brand 'resendpwd','subscribens','unsubscribens',))){ 20060e6b550SAndreas Gohr msg('Command unavailable: '.htmlspecialchars($act),-1); 20160e6b550SAndreas Gohr return 'show'; 20260e6b550SAndreas Gohr } 20360e6b550SAndreas Gohr 204067c5d22SBen Coburn if(!in_array($act,array('login','logout','register','save','cancel','edit','draft', 205ac83b9d8Sandi 'preview','search','show','check','index','revisions', 2061246e016SAndreas Gohr 'diff','recent','backlink','admin','subscribe','revert', 20718829381SAndreas Gohr 'unsubscribe','profile','resendpwd','recover','wordblock', 20852b0dd67SGuy Brand 'draftdel','subscribens','unsubscribens',)) && substr($act,0,7) != 'export_' ) { 209ee4c4a1bSAndreas Gohr msg('Command unknown: '.htmlspecialchars($act),-1); 210af182434Sandi return 'show'; 211af182434Sandi } 212af182434Sandi return $act; 213af182434Sandi} 214af182434Sandi 215af182434Sandi/** 2166b13307fSandi * Run permissionchecks 2176b13307fSandi * 2186b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 2196b13307fSandi */ 2206b13307fSandifunction act_permcheck($act){ 221dbbc6aa7Sandi global $INFO; 2225e199953Smatthiasgrimm global $conf; 223dbbc6aa7Sandi 224ee4c4a1bSAndreas Gohr if(in_array($act,array('save','preview','edit','recover'))){ 2256b13307fSandi if($INFO['exists']){ 226bdbc16bfSandi if($act == 'edit'){ 227bdbc16bfSandi //the edit function will check again and do a source show 228bdbc16bfSandi //when no AUTH_EDIT available 229bdbc16bfSandi $permneed = AUTH_READ; 230bdbc16bfSandi }else{ 2316b13307fSandi $permneed = AUTH_EDIT; 232bdbc16bfSandi } 2336b13307fSandi }else{ 2346b13307fSandi $permneed = AUTH_CREATE; 2356b13307fSandi } 2368b06d178Schris }elseif(in_array($act,array('login','search','recent','profile'))){ 2376b13307fSandi $permneed = AUTH_NONE; 2381246e016SAndreas Gohr }elseif($act == 'revert'){ 2391246e016SAndreas Gohr $permneed = AUTH_ADMIN; 2401246e016SAndreas Gohr if($INFO['ismanager']) $permneed = AUTH_EDIT; 2415e199953Smatthiasgrimm }elseif($act == 'register'){ 2425e199953Smatthiasgrimm $permneed = AUTH_NONE; 243ebd3d9ceSchris }elseif($act == 'resendpwd'){ 244ebd3d9ceSchris $permneed = AUTH_NONE; 245c19fe9c0Sandi }elseif($act == 'admin'){ 246f8cc712eSAndreas Gohr if($INFO['ismanager']){ 247f8cc712eSAndreas Gohr // if the manager has the needed permissions for a certain admin 248f8cc712eSAndreas Gohr // action is checked later 249f8cc712eSAndreas Gohr $permneed = AUTH_READ; 250f8cc712eSAndreas Gohr }else{ 251c19fe9c0Sandi $permneed = AUTH_ADMIN; 252f8cc712eSAndreas Gohr } 2536b13307fSandi }else{ 2546b13307fSandi $permneed = AUTH_READ; 2556b13307fSandi } 256dbbc6aa7Sandi if($INFO['perm'] >= $permneed) return $act; 257dbbc6aa7Sandi 2586b13307fSandi return 'denied'; 2596b13307fSandi} 2606b13307fSandi 2616b13307fSandi/** 262ee4c4a1bSAndreas Gohr * Handle 'draftdel' 263ee4c4a1bSAndreas Gohr * 264ee4c4a1bSAndreas Gohr * Deletes the draft for the current page and user 265ee4c4a1bSAndreas Gohr */ 266ee4c4a1bSAndreas Gohrfunction act_draftdel($act){ 267ee4c4a1bSAndreas Gohr global $INFO; 268ee4c4a1bSAndreas Gohr @unlink($INFO['draft']); 269ee4c4a1bSAndreas Gohr $INFO['draft'] = null; 270ee4c4a1bSAndreas Gohr return 'show'; 271ee4c4a1bSAndreas Gohr} 272ee4c4a1bSAndreas Gohr 273ee4c4a1bSAndreas Gohr/** 274ee4c4a1bSAndreas Gohr * Saves a draft on preview 275ee4c4a1bSAndreas Gohr * 276ee4c4a1bSAndreas Gohr * @todo this currently duplicates code from ajax.php :-/ 277ee4c4a1bSAndreas Gohr */ 278ee4c4a1bSAndreas Gohrfunction act_draftsave($act){ 279ee4c4a1bSAndreas Gohr global $INFO; 280ee4c4a1bSAndreas Gohr global $ID; 281ee4c4a1bSAndreas Gohr global $conf; 282ee4c4a1bSAndreas Gohr if($conf['usedraft'] && $_POST['wikitext']){ 283ee4c4a1bSAndreas Gohr $draft = array('id' => $ID, 284ee4c4a1bSAndreas Gohr 'prefix' => $_POST['prefix'], 285ee4c4a1bSAndreas Gohr 'text' => $_POST['wikitext'], 286ee4c4a1bSAndreas Gohr 'suffix' => $_POST['suffix'], 287ee4c4a1bSAndreas Gohr 'date' => $_POST['date'], 288ee4c4a1bSAndreas Gohr 'client' => $INFO['client'], 289ee4c4a1bSAndreas Gohr ); 290ee4c4a1bSAndreas Gohr $cname = getCacheName($draft['client'].$ID,'.draft'); 291ee4c4a1bSAndreas Gohr if(io_saveFile($cname,serialize($draft))){ 292ee4c4a1bSAndreas Gohr $INFO['draft'] = $cname; 293ee4c4a1bSAndreas Gohr } 294ee4c4a1bSAndreas Gohr } 295ee4c4a1bSAndreas Gohr return $act; 296ee4c4a1bSAndreas Gohr} 297ee4c4a1bSAndreas Gohr 298ee4c4a1bSAndreas Gohr/** 2996b13307fSandi * Handle 'save' 3006b13307fSandi * 3016b13307fSandi * Checks for spam and conflicts and saves the page. 3026b13307fSandi * Does a redirect to show the page afterwards or 3036b13307fSandi * returns a new action. 3046b13307fSandi * 3056b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 3066b13307fSandi */ 3076b13307fSandifunction act_save($act){ 3086b13307fSandi global $ID; 3096b13307fSandi global $DATE; 3106b13307fSandi global $PRE; 3116b13307fSandi global $TEXT; 3126b13307fSandi global $SUF; 3136b13307fSandi global $SUM; 3146b13307fSandi 3156b13307fSandi //spam check 3166b13307fSandi if(checkwordblock()) 3176b13307fSandi return 'wordblock'; 3186b13307fSandi //conflict check //FIXME use INFO 3196b13307fSandi if($DATE != 0 && @filemtime(wikiFN($ID)) > $DATE ) 3206b13307fSandi return 'conflict'; 3216b13307fSandi 3226b13307fSandi //save it 323b6912aeaSAndreas Gohr saveWikiText($ID,con($PRE,$TEXT,$SUF,1),$SUM,$_REQUEST['minor']); //use pretty mode for con 3246b13307fSandi //unlock it 3256b13307fSandi unlock($ID); 3266b13307fSandi 327ee4c4a1bSAndreas Gohr //delete draft 328ee4c4a1bSAndreas Gohr act_draftdel($act); 32969cd1e27SAndreas Gohr session_write_close(); 330ee4c4a1bSAndreas Gohr 33169cd1e27SAndreas Gohr // when done, show page 33269cd1e27SAndreas Gohr return 'show'; 33369cd1e27SAndreas Gohr} 334f951a474SAndreas Gohr 33514a122deSAndreas Gohr/** 3361246e016SAndreas Gohr * Revert to a certain revision 3371246e016SAndreas Gohr * 3381246e016SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 3391246e016SAndreas Gohr */ 3401246e016SAndreas Gohrfunction act_revert($act){ 3411246e016SAndreas Gohr global $ID; 3421246e016SAndreas Gohr global $REV; 3431246e016SAndreas Gohr global $lang; 3441246e016SAndreas Gohr 3451246e016SAndreas Gohr // when no revision is given, delete current one 3461246e016SAndreas Gohr // FIXME this feature is not exposed in the GUI currently 3471246e016SAndreas Gohr $text = ''; 3481246e016SAndreas Gohr $sum = $lang['deleted']; 3491246e016SAndreas Gohr if($REV){ 3501246e016SAndreas Gohr $text = rawWiki($ID,$REV); 3511246e016SAndreas Gohr if(!$text) return 'show'; //something went wrong 3521246e016SAndreas Gohr $sum = $lang['restored']; 3531246e016SAndreas Gohr } 3541246e016SAndreas Gohr 3551246e016SAndreas Gohr // spam check 3561246e016SAndreas Gohr if(checkwordblock($Text)) 3571246e016SAndreas Gohr return 'wordblock'; 3581246e016SAndreas Gohr 3591246e016SAndreas Gohr saveWikiText($ID,$text,$sum,false); 3601246e016SAndreas Gohr msg($sum,1); 3611246e016SAndreas Gohr 3621246e016SAndreas Gohr //delete any draft 3631246e016SAndreas Gohr act_draftdel($act); 3641246e016SAndreas Gohr session_write_close(); 3651246e016SAndreas Gohr 3661246e016SAndreas Gohr // when done, show current page 3671246e016SAndreas Gohr $_SERVER['REQUEST_METHOD'] = 'post'; //should force a redirect 3681246e016SAndreas Gohr $REV = ''; 3691246e016SAndreas Gohr return 'show'; 3701246e016SAndreas Gohr} 3711246e016SAndreas Gohr 3721246e016SAndreas Gohr/** 37314a122deSAndreas Gohr * Do a redirect after receiving post data 37414a122deSAndreas Gohr * 37514a122deSAndreas Gohr * Tries to add the section id as hash mark after section editing 37614a122deSAndreas Gohr */ 37769cd1e27SAndreas Gohrfunction act_redirect($id,$preact){ 37869cd1e27SAndreas Gohr global $PRE; 37969cd1e27SAndreas Gohr global $TEXT; 38014a122deSAndreas Gohr global $MSG; 38114a122deSAndreas Gohr 38214a122deSAndreas Gohr //are there any undisplayed messages? keep them in session for display 38314a122deSAndreas Gohr //on the next page 38414a122deSAndreas Gohr if(isset($MSG) && count($MSG)){ 38514a122deSAndreas Gohr //reopen session, store data and close session again 38614a122deSAndreas Gohr @session_start(); 38714a122deSAndreas Gohr $_SESSION[DOKU_COOKIE]['msg'] = $MSG; 38814a122deSAndreas Gohr session_write_close(); 38914a122deSAndreas Gohr } 390f951a474SAndreas Gohr 39169cd1e27SAndreas Gohr $opts = array( 39269cd1e27SAndreas Gohr 'id' => $id, 39369cd1e27SAndreas Gohr 'preact' => $preact 39469cd1e27SAndreas Gohr ); 395c66972f2SAdrian Lang //get section name when coming from section edit 396c66972f2SAdrian Lang if($PRE && preg_match('/^\s*==+([^=\n]+)/',$TEXT,$match)){ 397c66972f2SAdrian Lang $check = false; //Byref 398c66972f2SAdrian Lang $opts['fragment'] = sectionID($match[0], $check); 399c66972f2SAdrian Lang } 400c66972f2SAdrian Lang 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); 406c66972f2SAdrian Lang if(isset($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? 422c66972f2SAdrian Lang if(isset($_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'; 49366b23ce9SAndreas Gohr $headers['Content-Disposition'] = 'attachment; filename='.noNS($ID).'.txt'; 494f6dad9fdSMichael Klier $output = rawWiki($ID,$REV); 495f6dad9fdSMichael Klier break; 496f6dad9fdSMichael Klier case 'xhtml': 497f6dad9fdSMichael Klier $pre .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"' . DOKU_LF; 498f6dad9fdSMichael Klier $pre .= ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . DOKU_LF; 499f6dad9fdSMichael Klier $pre .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.$conf['lang'].'"' . DOKU_LF; 500f6dad9fdSMichael Klier $pre .= ' lang="'.$conf['lang'].'" dir="'.$lang['direction'].'">' . DOKU_LF; 501f6dad9fdSMichael Klier $pre .= '<head>' . DOKU_LF; 502f6dad9fdSMichael Klier $pre .= ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' . DOKU_LF; 503f6dad9fdSMichael Klier $pre .= ' <title>'.$ID.'</title>' . DOKU_LF; 504f6dad9fdSMichael Klier 505f6dad9fdSMichael Klier // get metaheaders 506f6dad9fdSMichael Klier ob_start(); 507f6dad9fdSMichael Klier tpl_metaheaders(); 508f6dad9fdSMichael Klier $pre .= ob_get_clean(); 509f6dad9fdSMichael Klier 510f6dad9fdSMichael Klier $pre .= '</head>' . DOKU_LF; 511f6dad9fdSMichael Klier $pre .= '<body>' . DOKU_LF; 512f6dad9fdSMichael Klier $pre .= '<div class="dokuwiki export">' . DOKU_LF; 513f6dad9fdSMichael Klier 514f6dad9fdSMichael Klier // get toc 515f6dad9fdSMichael Klier $pre .= tpl_toc(true); 516f6dad9fdSMichael Klier 517f6dad9fdSMichael Klier $headers['Content-Type'] = 'text/html; charset=utf-8'; 518f6dad9fdSMichael Klier $output = p_wiki_xhtml($ID,$REV,false); 519f6dad9fdSMichael Klier 520f6dad9fdSMichael Klier $post .= '</div>' . DOKU_LF; 521f6dad9fdSMichael Klier $post .= '</body>' . DOKU_LF; 522f6dad9fdSMichael Klier $post .= '</html>' . DOKU_LF; 523f6dad9fdSMichael Klier break; 524f6dad9fdSMichael Klier case 'xhtmlbody': 525f6dad9fdSMichael Klier $headers['Content-Type'] = 'text/html; charset=utf-8'; 526f6dad9fdSMichael Klier $output = p_wiki_xhtml($ID,$REV,false); 527f6dad9fdSMichael Klier break; 528f6dad9fdSMichael Klier default: 529f6dad9fdSMichael Klier $output = p_cached_output(wikiFN($ID,$REV), $mode); 5309acedd40SAndreas Gohr $headers = p_get_metadata($ID,"format $mode"); 531f6dad9fdSMichael Klier break; 532f6dad9fdSMichael Klier } 533f6dad9fdSMichael Klier 534f6dad9fdSMichael Klier // prepare event data 535f6dad9fdSMichael Klier $data = array(); 536f6dad9fdSMichael Klier $data['id'] = $ID; 537f6dad9fdSMichael Klier $data['mode'] = $mode; 538f6dad9fdSMichael Klier $data['headers'] = $headers; 539f6dad9fdSMichael Klier $data['output'] =& $output; 540f6dad9fdSMichael Klier 541f6dad9fdSMichael Klier trigger_event('ACTION_EXPORT_POSTPROCESS', $data); 542f6dad9fdSMichael Klier 543f6dad9fdSMichael Klier if(!empty($data['output'])){ 544f6dad9fdSMichael Klier if(is_array($data['headers'])) foreach($data['headers'] as $key => $val){ 54585767031SAndreas Gohr header("$key: $val"); 54685767031SAndreas Gohr } 547f6dad9fdSMichael Klier print $pre.$data['output'].$post; 5486b13307fSandi exit; 5496b13307fSandi } 5506b13307fSandi return 'show'; 5516b13307fSandi} 552340756e4Sandi 553b158d625SSteven Danz/** 554*5b75cd1fSAdrian Lang * Handle page 'subscribe' 555b158d625SSteven Danz * 556*5b75cd1fSAdrian Lang * Throws exception on error. 557*5b75cd1fSAdrian Lang * 558*5b75cd1fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de> 559b158d625SSteven Danz */ 5601380fc45SAndreas Gohrfunction act_subscription($act){ 561f9eb5648Ssteven-danz global $lang; 56252b0dd67SGuy Brand global $INFO; 56352b0dd67SGuy Brand 564*5b75cd1fSAdrian Lang if ($_SERVER['REQUEST_METHOD'] !== 'POST') { 565*5b75cd1fSAdrian Lang // No post to handle, let tpl_subscribe manage the request. 566*5b75cd1fSAdrian Lang return $act; 56752b0dd67SGuy Brand } 56852b0dd67SGuy Brand 569*5b75cd1fSAdrian Lang // Get and validate parameters. 570*5b75cd1fSAdrian Lang if (!isset($_POST['subscribe_target'])) { 571*5b75cd1fSAdrian Lang throw new Exception($lang['subscr_no_target']); 572*5b75cd1fSAdrian Lang } 573*5b75cd1fSAdrian Lang $target = $_POST['subscribe_target']; 574*5b75cd1fSAdrian Lang $valid_styles = array('every', 'digest'); 575*5b75cd1fSAdrian Lang if (substr($target, -1, 1) === ':') { 576*5b75cd1fSAdrian Lang // Allow “list” subscribe style since the target is a namespace. 577*5b75cd1fSAdrian Lang $valid_styles[] = 'list'; 578*5b75cd1fSAdrian Lang } 579*5b75cd1fSAdrian Lang $style = valid_input_set('subscribe_style', $valid_styles, $_POST, 580*5b75cd1fSAdrian Lang $lang['subscr_invalid_style']); 581*5b75cd1fSAdrian Lang $action = valid_input_set('subscribe_action', array('subscribe', 582*5b75cd1fSAdrian Lang 'unsubscribe'), 583*5b75cd1fSAdrian Lang $_POST, $lang['subscr_invalid_action']); 584613964ecSGuy Brand 585*5b75cd1fSAdrian Lang // Check other conditions. 586*5b75cd1fSAdrian Lang if ($action === 'subscribe') { 587*5b75cd1fSAdrian Lang if ($INFO['userinfo']['mail'] === '') { 588*5b75cd1fSAdrian Lang throw new Exception($lang['subscr_subscribe_noaddress']); 58952b0dd67SGuy Brand } 590*5b75cd1fSAdrian Lang } elseif ($action === 'unsubscribe') { 591*5b75cd1fSAdrian Lang $is = false; 592*5b75cd1fSAdrian Lang foreach($INFO['subscribed'] as $subscr) { 593*5b75cd1fSAdrian Lang if ($subscr['target'] === $target) { 594*5b75cd1fSAdrian Lang $is = true; 59552b0dd67SGuy Brand } 59652b0dd67SGuy Brand } 597*5b75cd1fSAdrian Lang if ($is === false) { 598*5b75cd1fSAdrian Lang throw new Exception(sprintf($lang['subscr_not_subscribed_you'], 599*5b75cd1fSAdrian Lang prettyprint_id($target))); 600*5b75cd1fSAdrian Lang } 601*5b75cd1fSAdrian Lang // subscription_set deletes a subscription if style = null. 602*5b75cd1fSAdrian Lang $style = null; 60352b0dd67SGuy Brand } 60452b0dd67SGuy Brand 605*5b75cd1fSAdrian Lang // Perform action. 606*5b75cd1fSAdrian Lang require_once DOKU_INC . 'inc/subscription.php'; 607*5b75cd1fSAdrian Lang if (!subscription_set($target, $_SERVER['REMOTE_USER'], $style)) { 608*5b75cd1fSAdrian Lang throw new Exception(sprintf($lang["subscr_{$action}_error"], 609*5b75cd1fSAdrian Lang hsc($INFO['userinfo']['name']), 610*5b75cd1fSAdrian Lang prettyprint_id($target))); 611*5b75cd1fSAdrian Lang } 612*5b75cd1fSAdrian Lang $INFO['subscribed'] = get_info_subscribed(); 613*5b75cd1fSAdrian Lang msg(sprintf($lang["subscr_{$action}_success"], hsc($INFO['userinfo']['name']), 614*5b75cd1fSAdrian Lang prettyprint_id($target)), 1); 615*5b75cd1fSAdrian Lang return $act; 61652b0dd67SGuy Brand} 61752b0dd67SGuy Brand 618340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 : 619