changeset 3251:ecbde828b812

improved wikiutil.is_URL, use it also in theme code
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 14 Mar 2008 13:10:19 +0100
parents 0f582c5d2b9f
children 67cd62f8493f ba0707fe183d
files MoinMoin/theme/__init__.py MoinMoin/wikiutil.py
diffstat 2 files changed, 22 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/theme/__init__.py	Fri Mar 14 11:27:04 2008 +0100
+++ b/MoinMoin/theme/__init__.py	Fri Mar 14 13:10:19 2008 +0100
@@ -334,13 +334,12 @@
         else:
             pagename = text
 
-        for scheme in config.url_schemas:
-            if pagename.startswith(scheme + ':'):
-                if not title:
-                    title = pagename
-                title = wikiutil.escape(title)
-                link = fmt.url(1, pagename) + fmt.text(title) + fmt.url(0)
-                return pagename, link
+        if wikiutil.is_URL(pagename):
+            if not title:
+                title = pagename
+            title = wikiutil.escape(title)
+            link = fmt.url(1, pagename) + fmt.text(title) + fmt.url(0)
+            return pagename, link
 
         # remove wiki: url prefix
         if pagename.startswith("wiki:"):
--- a/MoinMoin/wikiutil.py	Fri Mar 14 11:27:04 2008 +0100
+++ b/MoinMoin/wikiutil.py	Fri Mar 14 13:10:19 2008 +0100
@@ -2133,11 +2133,22 @@
     """
     return word_re.match(name)
 
-def is_URL(text):
-    """ Answer true if text is an URL.
-        The method used here is pretty dumb. Improvements are welcome.
-     """
-    return '://' in text
+
+def is_URL(arg, schemas=config.url_schemas):
+    """ Return True if arg is a URL (with a schema given in the schemas list).
+
+        Note: there are not that many requirements for generic URLs, basically
+        the only mandatory requirement is the ':' between schema and rest.
+        Schema itself could be anything, also the rest (but we only support some
+        schemas, as given in config.url_schemas, so it is a bit less ambiguous).
+    """
+    if ':' not in arg:
+        return False
+    for schema in schemas:
+        if arg.startswith(schema + ':'):
+            return True
+    return False
+
 
 def isPicture(url):
     """