From 55f92d7e8cfe32e4040ebcd55612ad3dec244640 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 6 Feb 2011 10:03:34 +0100 Subject: moved locktimer class to its own file I also adjusted the coding style to match our other JS classes --- lib/exe/js.php | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/exe') diff --git a/lib/exe/js.php b/lib/exe/js.php index 117021308..645ab3cc4 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -48,6 +48,7 @@ function js_out(){ DOKU_INC.'lib/scripts/textselection.js', DOKU_INC.'lib/scripts/toolbar.js', DOKU_INC.'lib/scripts/edit.js', + DOKU_INC.'lib/scripts/locktimer.js', DOKU_INC.'lib/scripts/linkwiz.js', DOKU_INC.'lib/scripts/media.js', DOKU_INC.'lib/scripts/subscriptions.js', -- cgit v1.2.3 From 87229c84afbda98679146558235bc7212ea404ee Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Sun, 6 Feb 2011 12:51:09 +0100 Subject: XML-RPC deleteAttachment now uses media_delete Functionality changes: * deleteAttachment now triggers MEDIA_DELETE_FILE (closes FS#1568) * deletion success msg in mediamanager is correct, even when the ns dir was deleted * media_delete changed quite a bit --- lib/exe/mediamanager.php | 22 ++++++++++++++-------- lib/exe/xmlrpc.php | 28 ++++++++-------------------- 2 files changed, 22 insertions(+), 28 deletions(-) (limited to 'lib/exe') diff --git a/lib/exe/mediamanager.php b/lib/exe/mediamanager.php index c79a25c08..6f2add2be 100644 --- a/lib/exe/mediamanager.php +++ b/lib/exe/mediamanager.php @@ -82,18 +82,24 @@ // handle deletion if($DEL) { - $INUSE = media_inuse($DEL); - if(!$INUSE) { - if(media_delete($DEL,$AUTH)) { - msg(sprintf($lang['deletesucc'],noNS($DEL)),1); - } else { - msg(sprintf($lang['deletefail'],noNS($DEL)),-1); + $res = 0; + if(checkSecurityToken()) { + $res = media_delete($DEL,$AUTH); + } + if ($res & DOKU_MEDIA_DELETED) { + $msg = sprintf($lang['deletesucc'], noNS($DEL)); + if ($res & DOKU_MEDIA_EMPTY_NS) { + // current namespace was removed. redirecting to root ns passing msg along + send_redirect(DOKU_URL.'lib/exe/mediamanager.php?msg1='. + rawurlencode($msg)); } - } else { + msg($msg,1); + } elseif ($res & DOKU_MEDIA_INUSE) { if(!$conf['refshow']) { - unset($INUSE); msg(sprintf($lang['mediainuse'],noNS($DEL)),0); } + } else { + msg(sprintf($lang['deletefail'],noNS($DEL)),-1); } } diff --git a/lib/exe/xmlrpc.php b/lib/exe/xmlrpc.php index d40e338b2..945dc3f67 100644 --- a/lib/exe/xmlrpc.php +++ b/lib/exe/xmlrpc.php @@ -674,27 +674,15 @@ class dokuwiki_xmlrpc_server extends IXR_IntrospectionServer { function deleteAttachment($id){ $id = cleanID($id); $auth = auth_quickaclcheck(getNS($id).':*'); - if($auth < AUTH_DELETE) return new IXR_ERROR(1, "You don't have permissions to delete files."); - global $conf; - global $lang; - - // check for references if needed - $mediareferences = array(); - if($conf['refcheck']){ - $mediareferences = ft_mediause($id,$conf['refshow']); - } - - if(!count($mediareferences)){ - $file = mediaFN($id); - if(@unlink($file)){ - addMediaLogEntry(time(), $id, DOKU_CHANGE_TYPE_DELETE); - io_sweepNS($id,'mediadir'); - return 0; - } - //something went wrong - return new IXR_ERROR(1, 'Could not delete file'); - } else { + $res = media_delete($id, $auth); + if ($res & DOKU_MEDIA_DELETED) { + return 0; + } elseif ($res & DOKU_MEDIA_NOT_AUTH) { + return new IXR_ERROR(1, "You don't have permissions to delete files."); + } elseif ($res & DOKU_MEDIA_INUSE) { return new IXR_ERROR(1, 'File is still referenced'); + } else { + return new IXR_ERROR(1, 'Could not delete file'); } } -- cgit v1.2.3 From ffb291f214dd47aa34d4e84b166de6e62714307f Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Sun, 6 Feb 2011 14:25:05 +0100 Subject: Use common media_save in media_upload and putAttachment Changes: * XML-RPC now correctly allows leading and trailing _ * Error messages from XML-RPC are correct * MEDIA_UPLOAD_FINISH has a sixth param specifying the move function * Not having upload rights when using media_upload throws a msg --- lib/exe/xmlrpc.php | 92 ++++++++---------------------------------------------- 1 file changed, 13 insertions(+), 79 deletions(-) (limited to 'lib/exe') diff --git a/lib/exe/xmlrpc.php b/lib/exe/xmlrpc.php index 945dc3f67..9749a2e16 100644 --- a/lib/exe/xmlrpc.php +++ b/lib/exe/xmlrpc.php @@ -605,64 +605,26 @@ class dokuwiki_xmlrpc_server extends IXR_IntrospectionServer { */ function putAttachment($id, $file, $params) { $id = cleanID($id); - global $conf; - global $lang; - $auth = auth_quickaclcheck(getNS($id).':*'); - if($auth >= AUTH_UPLOAD) { - if(!isset($id)) { - return new IXR_ERROR(1, 'Filename not given.'); - } - - $ftmp = $conf['tmpdir'] . '/' . md5($id.clientIP()); - // save temporary file - @unlink($ftmp); - $buff = base64_decode($file); - io_saveFile($ftmp, $buff); + if(!isset($id)) { + return new IXR_ERROR(1, 'Filename not given.'); + } - // get filename - list($iext, $imime,$dl) = mimetype($id); - $id = cleanID($id); - $fn = mediaFN($id); - - // get filetype regexp - $types = array_keys(getMimeTypes()); - $types = array_map(create_function('$q','return preg_quote($q,"/");'),$types); - $regex = join('|',$types); - - // because a temp file was created already - if(preg_match('/\.('.$regex.')$/i',$fn)) { - //check for overwrite - $overwrite = @file_exists($fn); - if($overwrite && (!$params['ow'] || $auth < AUTH_DELETE)) { - return new IXR_ERROR(1, $lang['uploadexist'].'1'); - } - // check for valid content - $ok = media_contentcheck($ftmp, $imime); - if($ok == -1) { - return new IXR_ERROR(1, sprintf($lang['uploadexist'].'2', ".$iext")); - } elseif($ok == -2) { - return new IXR_ERROR(1, $lang['uploadspam']); - } elseif($ok == -3) { - return new IXR_ERROR(1, $lang['uploadxss']); - } + global $conf; - // prepare event data - $data[0] = $ftmp; - $data[1] = $fn; - $data[2] = $id; - $data[3] = $imime; - $data[4] = $overwrite; + $ftmp = $conf['tmpdir'] . '/' . md5($id.clientIP()); - // trigger event - return trigger_event('MEDIA_UPLOAD_FINISH', $data, array($this, '_media_upload_action'), true); + // save temporary file + @unlink($ftmp); + $buff = base64_decode($file); + io_saveFile($ftmp, $buff); - } else { - return new IXR_ERROR(1, $lang['uploadwrong']); - } + $res = media_save(array('name' => $ftmp), $id, $params['ow'], $auth, 'rename'); + if (is_array($res)) { + return new IXR_ERROR(-$res[1], $res[0]); } else { - return new IXR_ERROR(1, "You don't have permissions to upload files."); + return $res; } } @@ -686,34 +648,6 @@ class dokuwiki_xmlrpc_server extends IXR_IntrospectionServer { } } - /** - * Moves the temporary file to its final destination. - * - * Michael Klier - */ - function _media_upload_action($data) { - global $conf; - - if(is_array($data) && count($data)===5) { - io_createNamespace($data[2], 'media'); - if(rename($data[0], $data[1])) { - chmod($data[1], $conf['fmode']); - media_notify($data[2], $data[1], $data[3]); - // add a log entry to the media changelog - if ($data[4]) { - addMediaLogEntry(time(), $data[2], DOKU_CHANGE_TYPE_EDIT); - } else { - addMediaLogEntry(time(), $data[2], DOKU_CHANGE_TYPE_CREATE); - } - return $data[2]; - } else { - return new IXR_ERROR(1, 'Upload failed.'); - } - } else { - return new IXR_ERROR(1, 'Upload failed.'); - } - } - /** * Returns the permissions of a given wiki page */ -- cgit v1.2.3 From 26497271fdd53b972af0b3a4411b6ce41a0629c0 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 6 Feb 2011 16:11:51 +0100 Subject: correctly wait for a lock in indexer (related to FS#2112) --- lib/exe/indexer.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/exe') diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php index eec8c968c..010ca7987 100644 --- a/lib/exe/indexer.php +++ b/lib/exe/indexer.php @@ -149,6 +149,7 @@ function runIndexer(){ } // try to aquire a lock + $run = 0; $lock = $conf['lockdir'].'/_indexer.lock'; while(!@mkdir($lock,$conf['dmode'])){ usleep(50); @@ -156,7 +157,8 @@ function runIndexer(){ // looks like a stale lock - remove it @rmdir($lock); print "runIndexer(): stale lock removed".NL; - }else{ + }elseif($run++ = 1000){ + // we waited 5 seconds for that lock print "runIndexer(): indexer locked".NL; return false; } -- cgit v1.2.3 From 9f881d099df700f068e5cc014d089dd9639db731 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Sun, 6 Feb 2011 16:47:38 +0100 Subject: Only remove the indexer lock when there is really a stale lock Previously the rmdir could be executed when the lock directory had been deleted by another indexer already. This could lead to a race condition when another indexer call creates the lock again between the if and the rmdir. This issue still exists for stale lock directories but they normally shouldn't exist. This also prevents the loop from becoming an endless loop when the lock directory can't be created. This change also fixes a syntax error in the indexer and prevents an endless loop when the lock directory exists but can't be deleted. --- lib/exe/indexer.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lib/exe') diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php index 010ca7987..0042e92d2 100644 --- a/lib/exe/indexer.php +++ b/lib/exe/indexer.php @@ -153,11 +153,15 @@ function runIndexer(){ $lock = $conf['lockdir'].'/_indexer.lock'; while(!@mkdir($lock,$conf['dmode'])){ usleep(50); - if(time()-@filemtime($lock) > 60*5){ + if(is_dir($lock) && time()-@filemtime($lock) > 60*5){ // looks like a stale lock - remove it - @rmdir($lock); - print "runIndexer(): stale lock removed".NL; - }elseif($run++ = 1000){ + if (!@rmdir($lock)) { + print "runIndexer(): removing the stale lock failed".NL; + return false; + } else { + print "runIndexer(): stale lock removed".NL; + } + }elseif($run++ == 1000){ // we waited 5 seconds for that lock print "runIndexer(): indexer locked".NL; return false; -- cgit v1.2.3 From c6497d393c535ea8007f277eca65d7083be02159 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 11 Feb 2011 22:23:24 +0100 Subject: avoid warning in linkwizard when a space is entered as query --- lib/exe/ajax.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/exe') diff --git a/lib/exe/ajax.php b/lib/exe/ajax.php index 1939a7bcb..7d594dc04 100644 --- a/lib/exe/ajax.php +++ b/lib/exe/ajax.php @@ -238,7 +238,7 @@ function ajax_linkwiz(){ global $conf; global $lang; - $q = ltrim($_POST['q'],':'); + $q = ltrim(trim($_POST['q']),':'); $id = noNS($q); $ns = getNS($q); -- cgit v1.2.3