diff --git a/_test/tests/inc/media_isexternal.test.php b/_test/tests/inc/media_isexternal.test.php
new file mode 100644
index 0000000000000000000000000000000000000000..cf5f793e4e2ccf970fcd66ec8525e7bf8595fd7b
--- /dev/null
+++ b/_test/tests/inc/media_isexternal.test.php
@@ -0,0 +1,22 @@
+<?php
+
+class media_isexternal_test extends DokuWikiTest {
+
+
+    public function test_external(){
+        $this->assertTrue(media_isexternal('http://www.example.com/foo.png'));
+        $this->assertTrue(media_isexternal('https://www.example.com/foo.png'));
+        $this->assertTrue(media_isexternal('ftp://www.example.com/foo.png'));
+        $this->assertTrue(media_isexternal('hTTp://www.example.com/foo.png'));
+        $this->assertTrue(media_isexternal('hTTps://www.example.com/foo.png'));
+        $this->assertTrue(media_isexternal('Ftp://www.example.com/foo.png'));
+    }
+
+    public function test_internal(){
+        $this->assertFalse(media_isexternal('wiki:logo.png'));
+        $this->assertFalse(media_isexternal('private:logo.png'));
+        $this->assertFalse(media_isexternal('ftp:private:logo.png'));
+
+    }
+
+}
\ No newline at end of file
diff --git a/inc/Mailer.class.php b/inc/Mailer.class.php
index f87d7dd84b38842c75e20d92486842717ad63a50..cb5f22f54f47680fbf2863dea4f32973a0e527d7 100644
--- a/inc/Mailer.class.php
+++ b/inc/Mailer.class.php
@@ -192,7 +192,7 @@ class Mailer {
         // copy over all replacements missing for HTML (autolink URLs)
         foreach($textrep as $key => $value) {
             if(isset($htmlrep[$key])) continue;
-            if(preg_match('/^https?:\/\//i', $value)) {
+            if(media_isexternal($value)) {
                 $htmlrep[$key] = '<a href="'.hsc($value).'">'.hsc($value).'</a>';
             } else {
                 $htmlrep[$key] = hsc($value);
diff --git a/inc/common.php b/inc/common.php
index b292fb75ee0db954f8101b3bb2f65c30c1067bff..1b4d9e8e49dfd5f22446893f2fe830aabbab8a9e 100644
--- a/inc/common.php
+++ b/inc/common.php
@@ -467,7 +467,7 @@ function exportlink($id = '', $format = 'raw', $more = '', $abs = false, $sep =
  */
 function ml($id = '', $more = '', $direct = true, $sep = '&amp;', $abs = false) {
     global $conf;
-    $isexternalimage = preg_match('#^(https?|ftp)://#i', $id);
+    $isexternalimage = media_isexternal($id);
     if(!$isexternalimage) {
         $id = cleanID($id);
     }
diff --git a/inc/fetch.functions.php b/inc/fetch.functions.php
index ea524a37a93a38594833dbe954133825c2f190bb..53ade3555f78d79042b620ce137d1f9af5cacb9f 100644
--- a/inc/fetch.functions.php
+++ b/inc/fetch.functions.php
@@ -89,15 +89,18 @@ function sendFile($file, $mime, $dl, $cache, $public = false) {
  * WRITE: MEDIA, FILE, array( STATUS, STATUSMESSAGE )
  *
  * @author Gerry Weissbach <gerry.w@gammaproduction.de>
- * @param $media reference to the media id
- * @param $file  reference to the file variable
- * @returns array(STATUS, STATUSMESSAGE)
+ * @param string $media  reference to the media id
+ * @param string $file   reference to the file variable
+ * @param string $rev
+ * @param int    $width
+ * @param int    $height
+ * @return array(STATUS, STATUSMESSAGE)
  */
 function checkFileStatus(&$media, &$file, $rev = '', $width=0, $height=0) {
     global $MIME, $EXT, $CACHE, $INPUT;
 
     //media to local file
-    if(preg_match('#^(https?)://#i', $media)) {
+    if(media_isexternal($media)) {
         //check hash
         if(substr(PassHash::hmac('md5', $media, auth_cookiesalt()), 0, 6) !== $INPUT->str('hash')) {
             return array(412, 'Precondition Failed');
diff --git a/inc/fulltext.php b/inc/fulltext.php
index 7ee3860636b89bd645e214d6bd8bb3c1c4df371b..2f073aceaab2adf3e83d2ff0d8d150259511a689 100644
--- a/inc/fulltext.php
+++ b/inc/fulltext.php
@@ -172,7 +172,7 @@ function ft_mediause($id,$max){
         preg_match_all('/\{\{([^|}]*'.$pcre.'[^|}]*)(|[^}]+)?\}\}/i',rawWiki($doc),$matches);
         foreach($matches[1] as $img){
             $img = trim($img);
-            if(preg_match('/^https?:\/\//i',$img)) continue; // skip external images
+            if(media_isexternal($img)) continue; // skip external images
                 list($img) = explode('?',$img);                  // remove any parameters
             resolve_mediaid($ns,$img,$exists);               // resolve the possibly relative img
 
diff --git a/inc/media.php b/inc/media.php
index 18148a44607f3a9131d3b10d46c092f0a65bab66..fbe1363ec2026a59663ed093cf6b54501223bb13 100644
--- a/inc/media.php
+++ b/inc/media.php
@@ -82,6 +82,18 @@ function media_metasave($id,$auth,$data){
     }
 }
 
+/**
+ * check if a media is external source
+ *
+ * @author Gerrit Uitslag <klapinklapin@gmail.com>
+ * @param string $id the media ID or URL
+ * @return bool
+ */
+function media_isexternal($id){
+    if (preg_match('#^(https?|ftp)://#i', $id)) return true;
+    return false;
+}
+
 /**
  * Check if a media item is public (eg, external URL or readable by @ALL)
  *
@@ -90,7 +102,7 @@ function media_metasave($id,$auth,$data){
  * @return bool
  */
 function media_ispublic($id){
-    if(preg_match('/^https?:\/\//i',$id)) return true;
+    if(media_isexternal($id)) return true;
     $id = cleanID($id);
     if(auth_aclcheck(getNS($id).':*', '', array()) >= AUTH_READ) return true;
     return false;
diff --git a/inc/parser/handler.php b/inc/parser/handler.php
index 55b715ad9d258d6e05829058fd53fba5878a808d..1cf32aaed248702bcc7fa678fb839af33ab6fce7 100644
--- a/inc/parser/handler.php
+++ b/inc/parser/handler.php
@@ -680,7 +680,7 @@ function Doku_Handler_Parse_Media($match) {
     }
 
     // Check whether this is a local or remote image
-    if ( preg_match('#^(https?|ftp)#i',$src) ) {
+    if ( media_isexternal($src) ) {
         $call = 'externalmedia';
     } else {
         $call = 'internalmedia';
diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php
index 8638ffa6a0da10894a5ac94f86ccd5d6d578db0a..e17b82f8b9f27d236b8d477b9ed0bf3475186f59 100644
--- a/inc/parser/metadata.php
+++ b/inc/parser/metadata.php
@@ -432,7 +432,7 @@ class Doku_Renderer_metadata extends Doku_Renderer {
     global $ID;
 
     list($src,$hash) = explode('#',$src,2);
-    if(!preg_match('/^https?:\/\//i',$src)){
+    if(!media_isexternal($src)){
         resolve_mediaid(getNS($ID),$src, $exists);
     }
     if(preg_match('/.(jpe?g|gif|png)$/i',$src)){