summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2014-01-08 20:28:17 +0100
committerAndreas Gohr <andi@splitbrain.org>2014-01-08 20:28:17 +0100
commitbc1b7a8a0fdd1812e352cab5e2362bd5770d5b3b (patch)
treed8912a5e37370dcc55bd7120acc2caa457819d50
parent4bad83d828217dc64292223b268c6a3674984070 (diff)
downloadrpg-bc1b7a8a0fdd1812e352cab5e2362bd5770d5b3b.tar.gz
rpg-bc1b7a8a0fdd1812e352cab5e2362bd5770d5b3b.tar.bz2
better filename parsing
The filename found in the URL will be used for old plugins missing a base entry in their plugin.info.txt and lacking a subdirectory inside the archive as well. This patch makes sure possible query strings aren't included in the filename. Note: io_download() will also try to get a filename from any content-disposition header. If no filename can be found we simply use an md5 sum of the URL and hope the plugin will contain it's own hint for naming.
-rw-r--r--lib/plugins/extension/helper/extension.php12
-rw-r--r--lib/plugins/extension/lang/en/lang.php2
2 files changed, 10 insertions, 4 deletions
diff --git a/lib/plugins/extension/helper/extension.php b/lib/plugins/extension/helper/extension.php
index c13aa983d..7958cd2da 100644
--- a/lib/plugins/extension/helper/extension.php
+++ b/lib/plugins/extension/helper/extension.php
@@ -783,11 +783,17 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
*/
public function download($url) {
// check the url
- $matches = array();
- if(!preg_match('/[^\/]*$/', $url, $matches) || !$matches[0]) {
+ if(!preg_match('/https?:\/\//i', $url)){
throw new Exception($this->getLang('error_badurl'));
}
- $file = $matches[0];
+
+ // try to get the file from the path (used as plugin name fallback)
+ $file = parse_url($url, PHP_URL_PATH);
+ if(is_null($file)){
+ $file = md5($url);
+ }else{
+ $file = utf8_basename($file);
+ }
// create tmp directory for download
if(!($tmp = $this->mkTmpDir())) {
diff --git a/lib/plugins/extension/lang/en/lang.php b/lib/plugins/extension/lang/en/lang.php
index 06c83a708..b11490c0c 100644
--- a/lib/plugins/extension/lang/en/lang.php
+++ b/lib/plugins/extension/lang/en/lang.php
@@ -82,7 +82,7 @@ $lang['update_available'] = '<strong>Update:</strong> New version %s
$lang['wrong_folder'] = '<strong>Plugin installed incorrectly:</strong> Rename plugin directory "%s" to "%s".';
$lang['url_change'] = '<strong>URL changed:</strong> Download URL has changed since last download. Check if the new URL is valid before updating the extension.<br />New: %s<br />Old: %s';
-$lang['error_badurl'] = 'URL ends with slash - unable to determine file name from the url';
+$lang['error_badurl'] = 'URLs should start with http or https';
$lang['error_dircreate'] = 'Unable to create temporary folder to receive download';
$lang['error_download'] = 'Unable to download the file: %s';
$lang['error_decompress'] = 'Unable to decompress the downloaded file. This maybe as a result of a bad download, in which case you should try again; or the compression format may be unknown, in which case you will need to download and install manually.';