diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js
index 95c0723f254d115556c9e0c0ccf193f75a28682d..8c56f1cb364ea224fdcaa3e0f7f82b594093da34 100644
--- a/apps/files/js/file-upload.js
+++ b/apps/files/js/file-upload.js
@@ -465,7 +465,11 @@ $(document).ready(function() {
 		crumb.text(text);
 	}
 
-	$(document).click(function() {
+	$(document).click(function(ev) {
+		// do not close when clicking in the dropdown
+		if ($(ev.target).closest('#new').length){
+			return;
+		}
 		$('#new>ul').hide();
 		$('#new').removeClass('active');
 		if ($('#new .error').length > 0) {
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js
index c33a06bbdc3d2d20db942ee3e1527a20e7f6dd9f..02dfa16a22435f50ca016569058903e8ee4af489 100644
--- a/apps/files/js/filelist.js
+++ b/apps/files/js/filelist.js
@@ -593,18 +593,19 @@ var FileList={
 				var fileSize = '<td class="filesize">'+humanFileSize(totalSize)+'</td>';
 			}
 
-			$('#fileList').append('<tr class="summary"><td><span class="info">'+info+'</span></td>'+fileSize+'<td></td></tr>');
+			var $summary = $('<tr class="summary"><td><span class="info">'+info+'</span></td>'+fileSize+'<td></td></tr>');
+			$('#fileList').append($summary);
 
-			var $dirInfo = $('.summary .dirinfo');
-			var $fileInfo = $('.summary .fileinfo');
-			var $connector = $('.summary .connector');
+			var $dirInfo = $summary.find('.dirinfo');
+			var $fileInfo = $summary.find('.fileinfo');
+			var $connector = $summary.find('.connector');
 
 			// Show only what's necessary, e.g.: no files: don't show "0 files"
-			if ($dirInfo.html().charAt(0) === "0") {
+			if (totalDirs === 0) {
 				$dirInfo.hide();
 				$connector.hide();
 			}
-			if ($fileInfo.html().charAt(0) === "0") {
+			if (totalFiles === 0) {
 				$fileInfo.hide();
 				$connector.hide();
 			}
diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php
index 123268e240afee61b59c179df4166e631a9d6eaa..6b66edcacc56daf0b9dfd0994c7fc1456d212a37 100644
--- a/apps/files_sharing/lib/cache.php
+++ b/apps/files_sharing/lib/cache.php
@@ -228,69 +228,73 @@ class Shared_Cache extends Cache {
 	 */
 	public function search($pattern) {
 
+		$where = '`name` LIKE ? AND ';
+
 		// normalize pattern
-		$pattern = $this->normalize($pattern);
+		$value = $this->normalize($pattern);
 
-		$ids = $this->getAll();
+		return $this->searchWithWhere($where, $value);
 
-		$files = array();
-		
-		// divide into 1k chunks
-		$chunks = array_chunk($ids, 1000);
-		
-		foreach ($chunks as $chunk) {
-			$placeholders = join(',', array_fill(0, count($chunk), '?'));
-
-			$sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`,
-					`encrypted`, `unencrypted_size`, `etag`
-					FROM `*PREFIX*filecache` WHERE `name` LIKE ? AND `fileid` IN (' . $placeholders . ')';
-			
-			$result = \OC_DB::executeAudited($sql, array_merge(array($pattern), $chunk));
-			
-			while ($row = $result->fetchRow()) {
-				if (substr($row['path'], 0, 6)==='files/') {
-					$row['path'] = substr($row['path'],6); // remove 'files/' from path as it's relative to '/Shared'
-				}
-				$row['mimetype'] = $this->getMimetype($row['mimetype']);
-				$row['mimepart'] = $this->getMimetype($row['mimepart']);
-				$files[] = $row;
-			}
-		}
-		return $files;
 	}
 
 	/**
 	 * search for files by mimetype
 	 *
-	 * @param string $part1
-	 * @param string $part2
+	 * @param string $mimetype
 	 * @return array
 	 */
 	public function searchByMime($mimetype) {
+
 		if (strpos($mimetype, '/')) {
-			$where = '`mimetype` = ?';
+			$where = '`mimetype` = ? AND ';
 		} else {
-			$where = '`mimepart` = ?';
+			$where = '`mimepart` = ? AND ';
 		}
-		$mimetype = $this->getMimetypeId($mimetype);
+
+		$value = $this->getMimetypeId($mimetype);
+
+		return $this->searchWithWhere($where, $value);
+
+	}
+	
+	/**
+	 * The maximum number of placeholders that can be used in an SQL query.
+	 * Value MUST be <= 1000 for oracle:
+	 * see ORA-01795 maximum number of expressions in a list is 1000
+	 * FIXME we should get this from doctrine as other DBs allow a lot more placeholders
+	 */
+	const MAX_SQL_CHUNK_SIZE = 1000;
+	
+	/**
+	 * search for files with a custom where clause and value
+	 * the $wherevalue will be array_merge()d with the file id chunks
+	 *
+	 * @param string $sqlwhere
+	 * @param string $wherevalue
+	 * @return array
+	 */
+	private function searchWithWhere($sqlwhere, $wherevalue, $chunksize = self::MAX_SQL_CHUNK_SIZE) {
+
 		$ids = $this->getAll();
 
 		$files = array();
 		
-		// divide into 1k chunks
-		$chunks = array_chunk($ids, 1000);
+		// divide into chunks
+		$chunks = array_chunk($ids, $chunksize);
 		
 		foreach ($chunks as $chunk) {
-			$placeholders = join(',', array_fill(0, count($ids), '?'));
+			$placeholders = join(',', array_fill(0, count($chunk), '?'));
 			$sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`,
 					`encrypted`, `unencrypted_size`, `etag`
-					FROM `*PREFIX*filecache` WHERE ' . $where . ' AND `fileid` IN (' . $placeholders . ')';
+					FROM `*PREFIX*filecache` WHERE ' . $sqlwhere . ' `fileid` IN (' . $placeholders . ')';
 			
-			$result = \OC_DB::executeAudited($sql, array_merge(array($mimetype), $chunk));
+			$stmt = \OC_DB::prepare($sql);
+
+			$result = $stmt->execute(array_merge(array($wherevalue), $chunk));
 
 			while ($row = $result->fetchRow()) {
-				if (substr($row['path'], 0, 6)==='files/') {
-					$row['path'] = substr($row['path'],6); // remove 'files/' from path as it's relative to '/Shared'
+				if (substr($row['path'], 0, 6) === 'files/') {
+					$row['path'] = substr($row['path'], 6); // remove 'files/' from path as it's relative to '/Shared'
 				}
 				$row['mimetype'] = $this->getMimetype($row['mimetype']);
 				$row['mimepart'] = $this->getMimetype($row['mimepart']);
diff --git a/core/js/share.js b/core/js/share.js
index c53fa4110b536824aa00ea3e15eafab1e89d952f..411f0d23c36bd7987f2c9c051eefc9a0191f0de8 100644
--- a/core/js/share.js
+++ b/core/js/share.js
@@ -56,7 +56,7 @@ OC.Share={
 						var path = dir;
 						// Search for possible parent folders that are shared
 						while (path != last) {
-							if (path == data['path']) {
+							if (path == data['path'] && !data['link']) {
 								var actions = $('.fileactions .action[data-action="Share"]');
 								$.each(actions, function(index, action) {
 									var img = $(action).find('img');
@@ -244,7 +244,9 @@ OC.Share={
 			if (data.shares) {
 				$.each(data.shares, function(index, share) {
 					if (share.share_type == OC.Share.SHARE_TYPE_LINK) {
-						OC.Share.showLink(share.token, share.share_with, itemSource);
+						if ( !('file_target' in share) ) {
+							OC.Share.showLink(share.token, share.share_with, itemSource);
+						}
 					} else {
 						if (share.collection) {
 							OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.permissions, possiblePermissions, share.mail_send, share.collection);
diff --git a/lib/private/api.php b/lib/private/api.php
index 26091657b31ab335c7881c056277e628e0a765ae..7e69a6a77d20490bc286e2716117c5da01a49ace 100644
--- a/lib/private/api.php
+++ b/lib/private/api.php
@@ -250,7 +250,8 @@ class OC_API {
 
 		// reuse existing login
 		$loggedIn = OC_User::isLoggedIn();
-		if ($loggedIn === true) {
+		$ocsApiRequest = isset($_SERVER['HTTP_OCS_APIREQUEST']) ? $_SERVER['HTTP_OCS_APIREQUEST'] === 'true' : false;
+		if ($loggedIn === true && $ocsApiRequest) {
 			return OC_User::getUser();
 		}
 
diff --git a/lib/private/util.php b/lib/private/util.php
index f63884c0f320b63106639a939b8b88c0d80662aa..176eb4bc36955cc8ec7b6be732eca3435e314d60 100755
--- a/lib/private/util.php
+++ b/lib/private/util.php
@@ -579,6 +579,7 @@ class OC_Util {
 	 * @return void
 	 */
 	public static function checkAdminUser() {
+		OC_Util::checkLoggedIn();
 		if( !OC_User::isAdminUser(OC_User::getUser())) {
 			header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php' ));
 			exit();
@@ -611,6 +612,7 @@ class OC_Util {
 	 * @return array $groups where the current user is subadmin
 	 */
 	public static function checkSubAdminUser() {
+		OC_Util::checkLoggedIn();
 		if(!OC_SubAdmin::isSubAdmin(OC_User::getUser())) {
 			header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php' ));
 			exit();
diff --git a/settings/templates/admin.php b/settings/templates/admin.php
index a5724bf3b174e43c19923425a7195ddaaf89c0b2..5413b7009360c00090df6b7a4193d0645f64b094 100644
--- a/settings/templates/admin.php
+++ b/settings/templates/admin.php
@@ -4,6 +4,13 @@
  * See the COPYING-README file.
  */
 $levels = array('Debug', 'Info', 'Warning', 'Error', 'Fatal');
+$levelLabels = array(
+	$l->t( 'Everything (fatal issues, errors, warnings, info, debug)' ),
+	$l->t( 'Info, warnings, errors and fatal issues' ),
+	$l->t( 'Warnings, errors and fatal issues' ),
+	$l->t( 'Errors and fatal issues' ),
+	$l->t( 'Fatal issues only' ),
+);
 ?>
 
 <?php
@@ -210,12 +217,13 @@ if (!$_['internetconnectionworking']) {
 <fieldset class="personalblock">
 	<h2><?php p($l->t('Log'));?></h2>
 	<?php p($l->t('Log level'));?> <select name='loglevel' id='loglevel'>
-	<option value='<?php p($_['loglevel'])?>'><?php p($levels[$_['loglevel']])?></option>
-	<?php for ($i = 0; $i < 5; $i++):
-	if ($i !== $_['loglevel']):?>
-		<option value='<?php p($i)?>'><?php p($levels[$i])?></option>
-		<?php endif;
-endfor;?>
+<?php for ($i = 0; $i < 5; $i++):
+	$selected = '';
+	if ($i == $_['loglevel']):
+		$selected = 'selected="selected"';
+	endif; ?>
+		<option value='<?php p($i)?>' <?php p($selected) ?>><?php p($levelLabels[$i])?></option>
+<?php endfor;?>
 </select>
 	<table id="log" class="grid">
 		<?php foreach ($_['entries'] as $entry): ?>
diff --git a/tests/lib/preview.php b/tests/lib/preview.php
index d0cdd2c44fba78c7031333e4132117a70f3a9344..353b66fd6d66d9e8852aca36470fe84ba4e8cb84 100644
--- a/tests/lib/preview.php
+++ b/tests/lib/preview.php
@@ -134,13 +134,11 @@ class Preview extends \PHPUnit_Framework_TestCase {
 	}
 
 	private function initFS() {
-		if(\OC\Files\Filesystem::getView()){
-			$user = \OC_User::getUser();
-		}else{
-			$user=uniqid();
-			\OC_User::setUserId($user);
-			\OC\Files\Filesystem::init($user, '/'.$user.'/files');
-		}
+		// create a new user with his own filesystem view
+		// this gets called by each test in this test class
+		$user=uniqid();
+		\OC_User::setUserId($user);
+		\OC\Files\Filesystem::init($user, '/'.$user.'/files');
 
 		\OC\Files\Filesystem::mount('OC\Files\Storage\Temporary', array(), '/');