From ee4c4a1b5a5840c1b9d2d8c74b3f4298dd52928b Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 11 Mar 2006 21:01:48 +0100 Subject: Automatic draft saving DokuWiki now automatically creates a draft file of the currently edited page. In case of an editing interuption (eg. Browsercrash) the draftfile can be continued later. darcs-hash:20060311200148-7ad00-919337a51e001136178d175a1755cd26122e9726.gz --- lib/exe/ajax.php | 38 ++++++++++++++++++++++++++++++++++++-- lib/exe/js.php | 4 ++-- 2 files changed, 38 insertions(+), 4 deletions(-) (limited to 'lib/exe') diff --git a/lib/exe/ajax.php b/lib/exe/ajax.php index e52d5d378..886e9829d 100644 --- a/lib/exe/ajax.php +++ b/lib/exe/ajax.php @@ -61,18 +61,52 @@ function ajax_qsearch(){ } /** - * Refresh a page lock + * Refresh a page lock and save draft * * Andreas Gohr */ function ajax_lock(){ + global $conf; + global $lang; $id = cleanID($_POST['id']); if(empty($id)) return; if(!checklock($id)){ lock($id); - print 1; + echo 1; } + + if($conf['usedraft'] && $_POST['wikitext']){ + $client = $_SERVER['REMOTE_USER']; + if(!$client) $client = clientIP(true); + + $draft = array('id' => $ID, + 'prefix' => $_POST['prefix'], + 'text' => $_POST['wikitext'], + 'suffix' => $_POST['suffix'], + 'date' => $_POST['date'], + 'client' => $client, + ); + $cname = getCacheName($draft['client'].$id,'.draft'); + if(io_saveFile($cname,serialize($draft))){ + echo $lang['draftdate'].' '.date($conf['dformat']); + } + } + +} + +/** + * Delete a draft + */ +function ajax_draftdel(){ + $id = cleanID($_POST['id']); + if(empty($id)) return; + + $client = $_SERVER['REMOTE_USER']; + if(!$client) $client = clientIP(true); + + $cname = getCacheName($client.$id,'.draft'); + @unlink($cname); } //Setup VIM: ex: et ts=2 enc=utf-8 : diff --git a/lib/exe/js.php b/lib/exe/js.php index 5147f1be3..9cc4a863c 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -93,7 +93,7 @@ function js_out(){ js_runonstart("initChangeCheck('".js_escape($lang['notsavedyet'])."')"); // add lock timer - js_runonstart("locktimer.init(".($conf['locktime'] - 60).",'".js_escape($lang['willexpire'])."')"); + js_runonstart("locktimer.init(".($conf['locktime'] - 60).",'".js_escape($lang['willexpire'])."',".$conf['usedraft'].")"); // load spell checker if($conf['spellchecker']){ @@ -195,7 +195,7 @@ function js_escape($string){ * @author Andreas Gohr */ function js_runonstart($func){ - echo "addInitEvent(function(){ $func; });"; + echo "addInitEvent(function(){ $func; });\n"; } /** -- cgit v1.2.3