From ed1dc3e064e4ca64fc2db2cecbd1f6bd48242b7b Mon Sep 17 00:00:00 2001
From: Bart Visscher <bartv@thisnet.nl>
Date: Fri, 8 Feb 2013 22:05:13 +0100
Subject: [PATCH] Fix files router download links

---
 apps/files/index.php      |  2 +-
 apps/files/js/filelist.js |  2 +-
 lib/public/util.php       | 14 ++++++++++++++
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/apps/files/index.php b/apps/files/index.php
index 104cf1a55d..434e98c6ea 100644
--- a/apps/files/index.php
+++ b/apps/files/index.php
@@ -92,7 +92,7 @@ foreach (explode('/', $dir) as $i) {
 $list = new OCP\Template('files', 'part.list', '');
 $list->assign('files', $files, false);
 $list->assign('baseURL', OCP\Util::linkTo('files', 'index.php') . '?dir=', false);
-$list->assign('downloadURL', OCP\Util::linkTo('files', 'download.php') . '?file=', false);
+$list->assign('downloadURL', OCP\Util::linkToRoute('download', array('file' => '/')), false);
 $list->assign('disableSharing', false);
 $breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', '');
 $breadcrumbNav->assign('breadcrumb', $breadcrumb, false);
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js
index 72b353b48c..c176057c86 100644
--- a/apps/files/js/filelist.js
+++ b/apps/files/js/filelist.js
@@ -15,7 +15,7 @@ var FileList={
 			extension=false;
 		}
 		html+='<td class="filename" style="background-image:url('+img+')"><input type="checkbox" />';
-		html+='<a class="name" href="download.php?file='+$('#dir').val().replace(/</, '&lt;').replace(/>/, '&gt;')+'/'+escapeHTML(name)+'"><span class="nametext">'+escapeHTML(basename);
+		html+='<a class="name" href="' +OC.Router.generate('download', { file: $('#dir').val()+'/'+name }) +'"><span class="nametext">'+escapeHTML(basename);
 		if(extension){
 			html+='<span class="extension">'+escapeHTML(extension)+'</span>';
 		}
diff --git a/lib/public/util.php b/lib/public/util.php
index 968ca891b4..5f6ede4460 100644
--- a/lib/public/util.php
+++ b/lib/public/util.php
@@ -147,6 +147,20 @@ class Util {
 		return \OC_Helper::linkToPublic($service);
 	}
 
+	/**
+	 * @brief Creates an url using a defined route
+	 * @param $route
+	 * @param array $parameters
+	 * @return
+	 * @internal param array $args with param=>value, will be appended to the returned url
+	 * @returns the url
+	 *
+	 * Returns a url to the given app and file.
+	 */
+	public static function linkToRoute( $route, $parameters = array() ) {
+		return \OC_Helper::linkToRoute($route, $parameters);
+	}
+
 	/**
 	* @brief Creates an url
 	* @param string $app app
-- 
GitLab