1<?php 2/** 3 * DokuWiki Actions 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Andreas Gohr <andi@splitbrain.org> 7 */ 8 9 if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); 10 require_once(DOKU_INC.'inc/template.php'); 11 12 13/** 14 * Call the needed action handlers 15 * 16 * @author Andreas Gohr <andi@splitbrain.org> 17 */ 18function act_dispatch(){ 19 global $INFO; 20 global $ACT; 21 global $ID; 22 global $QUERY; 23 global $lang; 24 global $conf; 25 26 //sanitize $ACT 27 $ACT = act_clean($ACT); 28 29 //check if searchword was given - else just show 30 $s = cleanID($QUERY); 31 if($ACT == 'search' && empty($s)){ 32 $ACT = 'show'; 33 } 34 35 //login stuff 36 if(in_array($ACT,array('login','logout'))) 37 $ACT = act_auth($ACT); 38 39 //check if user is asking to (un)subscribe a page 40 if($ACT == 'subscribe' || $ACT == 'unsubscribe') 41 $ACT = act_subscription($ACT); 42 43 //check permissions 44 $ACT = act_permcheck($ACT); 45 46 //register 47 if($ACT == 'register' && register()){ 48 $ACT = 'login'; 49 } 50 51 if ($ACT == 'resendpwd' && act_resendpwd()) { 52 $ACT = 'login'; 53 } 54 55 //update user profile 56 if (($ACT == 'profile') && updateprofile()) { 57 msg($lang['profchanged'],1); 58 $ACT = 'show'; 59 } 60 61 //save 62 if($ACT == 'save') 63 $ACT = act_save($ACT); 64 65 //edit 66 if(($ACT == 'edit' || $ACT == 'preview') && $INFO['editable']){ 67 $ACT = act_edit($ACT); 68 }else{ 69 unlock($ID); //try to unlock 70 } 71 72 //handle export 73 if(substr($ACT,0,7) == 'export_') 74 $ACT = act_export($ACT); 75 76 //display some infos 77 if($ACT == 'check'){ 78 check(); 79 $ACT = 'show'; 80 } 81 82 //handle admin tasks 83 if($ACT == 'admin'){ 84 // retrieve admin plugin name from $_REQUEST['page'] 85 if ($_REQUEST['page']) { 86 $pluginlist = plugin_list('admin'); 87 if (in_array($_REQUEST['page'], $pluginlist)) { 88 // attempt to load the plugin 89 if ($plugin =& plugin_load('admin',$_REQUEST['page']) !== NULL) 90 $plugin->handle(); 91 } 92 } 93/* 94 if($_REQUEST['page'] == 'acl'){ 95 require_once(DOKU_INC.'inc/admin_acl.php'); 96 admin_acl_handler(); 97 } 98*/ 99 } 100 101 //call template FIXME: all needed vars available? 102 header('Content-Type: text/html; charset=utf-8'); 103 include(template('main.php')); 104 // output for the commands is now handled in inc/templates.php 105 // in function tpl_content() 106} 107 108/** 109 * Sanitize the action command 110 * 111 * Add all allowed commands here. 112 * 113 * @author Andreas Gohr <andi@splitbrain.org> 114 */ 115function act_clean($act){ 116 global $lang; 117 118 //handle localized buttons 119 if($act == $lang['btn_save']) $act = 'save'; 120 if($act == $lang['btn_preview']) $act = 'preview'; 121 if($act == $lang['btn_cancel']) $act = 'show'; 122 123 //remove all bad chars 124 $act = strtolower($act); 125 $act = preg_replace('/[^a-z_]+/','',$act); 126 127 if($act == 'export_html') $act = 'export_xhtml'; 128 if($act == 'export_htmlbody') $act = 'export_xhtmlbody'; 129 130 if(array_search($act,array('login','logout','register','save','edit', 131 'preview','search','show','check','index','revisions', 132 'diff','recent','backlink','admin','subscribe', 133 'unsubscribe','profile','resendpwd',)) === false 134 && substr($act,0,7) != 'export_' ) { 135 msg('Unknown command: '.htmlspecialchars($act),-1); 136 return 'show'; 137 } 138 return $act; 139} 140 141/** 142 * Run permissionchecks 143 * 144 * @author Andreas Gohr <andi@splitbrain.org> 145 */ 146function act_permcheck($act){ 147 global $INFO; 148 global $conf; 149 150 if(in_array($act,array('save','preview','edit'))){ 151 if($INFO['exists']){ 152 if($act == 'edit'){ 153 //the edit function will check again and do a source show 154 //when no AUTH_EDIT available 155 $permneed = AUTH_READ; 156 }else{ 157 $permneed = AUTH_EDIT; 158 } 159 }else{ 160 $permneed = AUTH_CREATE; 161 } 162 }elseif(in_array($act,array('login','search','recent','profile'))){ 163 $permneed = AUTH_NONE; 164 }elseif($act == 'register'){ 165 if ($conf['openregister']){ 166 $permneed = AUTH_NONE; 167 }else{ 168 $permneed = AUTH_ADMIN; 169 } 170 }elseif($act == 'admin'){ 171 $permneed = AUTH_ADMIN; 172 }else{ 173 $permneed = AUTH_READ; 174 } 175 if($INFO['perm'] >= $permneed) return $act; 176 177 return 'denied'; 178} 179 180/** 181 * Handle 'save' 182 * 183 * Checks for spam and conflicts and saves the page. 184 * Does a redirect to show the page afterwards or 185 * returns a new action. 186 * 187 * @author Andreas Gohr <andi@splitbrain.org> 188 */ 189function act_save($act){ 190 global $ID; 191 global $DATE; 192 global $PRE; 193 global $TEXT; 194 global $SUF; 195 global $SUM; 196 197 //spam check 198 if(checkwordblock()) 199 return 'wordblock'; 200 //conflict check //FIXME use INFO 201 if($DATE != 0 && @filemtime(wikiFN($ID)) > $DATE ) 202 return 'conflict'; 203 204 //save it 205 saveWikiText($ID,con($PRE,$TEXT,$SUF,1),$SUM,$_REQUEST['minor']); //use pretty mode for con 206 //unlock it 207 unlock($ID); 208 209 //show it 210 session_write_close(); 211 header("Location: ".wl($ID,'',true)); 212 exit(); 213} 214 215/** 216 * Handle 'login', 'logout' 217 * 218 * @author Andreas Gohr <andi@splitbrain.org> 219 */ 220function act_auth($act){ 221 global $ID; 222 global $INFO; 223 224 //already logged in? 225 if($_SERVER['REMOTE_USER'] && $act=='login') 226 return 'show'; 227 228 //handle logout 229 if($act=='logout'){ 230 $lockedby = checklock($ID); //page still locked? 231 if($lockedby == $_SERVER['REMOTE_USER']) 232 unlock($ID); //try to unlock 233 234 // do the logout stuff 235 auth_logoff(); 236 237 // rebuild info array 238 $INFO = pageinfo(); 239 240 return 'login'; 241 } 242 243 return $act; 244} 245 246/** 247 * Handle 'edit', 'preview' 248 * 249 * @author Andreas Gohr <andi@splitbrain.org> 250 */ 251function act_edit($act){ 252 global $ID; 253 254 //check if locked by anyone - if not lock for my self 255 $lockedby = checklock($ID); 256 if($lockedby) return 'locked'; 257 258 lock($ID); 259 return $act; 260} 261 262/** 263 * Handle 'edit', 'preview' 264 * 265 * @author Andreas Gohr <andi@splitbrain.org> 266 */ 267function act_export($act){ 268 global $ID; 269 global $REV; 270 271 // no renderer for this 272 if($act == 'export_raw'){ 273 header('Content-Type: text/plain; charset=utf-8'); 274 print rawWiki($ID,$REV); 275 exit; 276 } 277 278 // html export #FIXME what about the template's style? 279 if($act == 'export_xhtml'){ 280 header('Content-Type: text/html; charset=utf-8'); 281 ptln('<html>'); 282 ptln('<head>'); 283 tpl_metaheaders(); 284 ptln('</head>'); 285 ptln('<body>'); 286 ptln('<div class="dokuwiki">'); 287 print p_wiki_xhtml($ID,$REV,false); 288 ptln('</div>'); 289 ptln('</body>'); 290 ptln('</html>'); 291 exit; 292 } 293 294 // html body only 295 if($act == 'export_xhtmlbody'){ 296 print p_wiki_xhtml($ID,$REV,false); 297 exit; 298 } 299 300 // try to run renderer #FIXME use cached instructions 301 $mode = substr($act,7); 302 $text = p_render($mode,p_get_instructions(rawWiki($ID,$REV)),$info); 303 if(!is_null($text)){ 304 print $text; 305 exit; 306 } 307 308 309 310 return 'show'; 311} 312 313/** 314 * Handle 'subscribe', 'unsubscribe' 315 * 316 * @author Steven Danz <steven-danz@kc.rr.com> 317 * @todo localize 318 */ 319function act_subscription($act){ 320 global $ID; 321 global $INFO; 322 global $lang; 323 324 $file=metaFN($ID,'.mlist'); 325 if ($act=='subscribe' && !$INFO['subscribed']){ 326 if ($INFO['userinfo']['mail']){ 327 if (io_saveFile($file,$_SERVER['REMOTE_USER']."\n",true)) { 328 $INFO['subscribed'] = true; 329 msg(sprintf($lang[$act.'_success'], $INFO['userinfo']['name'], $ID),1); 330 } else { 331 msg(sprintf($lang[$act.'_error'], $INFO['userinfo']['name'], $ID),1); 332 } 333 } else { 334 msg($lang['subscribe_noaddress']); 335 } 336 } elseif ($act=='unsubscribe' && $INFO['subscribed']){ 337 if (io_deleteFromFile($file,$_SERVER['REMOTE_USER']."\n")) { 338 $INFO['subscribed'] = false; 339 msg(sprintf($lang[$act.'_success'], $INFO['userinfo']['name'], $ID),1); 340 } else { 341 msg(sprintf($lang[$act.'_error'], $INFO['userinfo']['name'], $ID),1); 342 } 343 } 344 345 return 'show'; 346} 347 348//Setup VIM: ex: et ts=2 enc=utf-8 : 349