changeset 19:6772e845059d

fix for gecko paste link brokenness, src cosmetics imported from: moin--main--1.5--patch-20
author Thomas Waldmann <tw@waldmann-edv.de>
date Sat, 24 Sep 2005 12:13:32 +0000
parents 316340dd9a7f
children 329b6aaf3118
files MoinMoin/converter/text_html_text_x_moin.py MoinMoin/wikiaction.py
diffstat 2 files changed, 36 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/converter/text_html_text_x_moin.py	Fri Sep 23 23:00:59 2005 +0000
+++ b/MoinMoin/converter/text_html_text_x_moin.py	Sat Sep 24 12:13:32 2005 +0000
@@ -121,6 +121,10 @@
     def do(self, tree):
         self.visit_node_list(tree.childNodes)
 
+    def visit_node_list(self, node):
+        for i in node:
+            self.visit(i)
+
     def visit(self, node):
         nodeType = node.nodeType
         if node.nodeType == Node.ELEMENT_NODE:
@@ -132,21 +136,17 @@
         elif node.nodeType == Node.CDATA_SECTION_NODE:
             return self.visit_cdata_section(node)
 
-    def visit_cdata_section(self, node):
-        pass
+    def visit_element(self, node):
+        if len(node.childNodes):
+            self.visit_node_list(node.childNodes)
 
     def visit_attribute(self, node):
         pass
 	
-    def visit_element(self, node):
-        if len(node.childNodes):
-            self.visit_node_list(node.childNodes)
+    def visit_text(self, node):
+        pass
 
-    def visit_node_list(self, node):
-        for i in node:
-            self.visit(i)
-
-    def visit_text(self, node):
+    def visit_cdata_section(self, node):
         pass
 
 
@@ -180,8 +180,9 @@
     white_space = object()
     new_line = object()
         
-    def __init__(self, request):
+    def __init__(self, request, pagename):
         self.request = request
+        self.pagename = pagename
     
     def do(self, tree):
         self.depth = 0
@@ -232,12 +233,13 @@
             self.process_heading(node)
         elif name in ('ol', 'ul',):
             self.process_list(node)
-        elif name in ('br',):
-            self.text.append('\n') # without this, std multi-line text below some heading misses a whitespace
-                                   # when it gets merged to float text, like word word wordword word word
         else:
             raise MoinMoin.error.ConvertError("Don't support %s element" % name)
 
+    def process_br(self, node):
+            self.text.append('\n') # without this, std multi-line text below some heading misses a whitespace
+                                   # when it gets merged to float text, like word word wordword word word
+        
     def visit_node_list_element_only(self, node):
         for i in node:
             if i.nodeType == Node.ELEMENT_NODE:
@@ -371,9 +373,7 @@
                 elif name == 'blockquote':
                     self.process_blockquote(i)
                 elif name in ('br',):
-                    self.text.append('\n') # without this, std multi-line text below some heading misses a whitespace
-                                           # when it gets merged to float text, like word word wordword word word
-                    pass
+                    self.process_br(i)
                 else:
                     raise MoinMoin.error.ConvertError("Don't support %s element" % name)
         self.depth -= 1
@@ -422,9 +422,6 @@
             command = ",,"
         elif name == 'sup':
             command = "^"
-        elif name in ('br',):
-            self.text.append('\n') # without this, std multi-line text below some heading misses a whitespace
-            return                 # when it gets merged to float text, like word word wordword word word
         elif name in ('h1', 'h2', 'h3', 'h4', 'h5', 'h6',): # headers are not allowed here (e.g. inside a ul li),
             text = self.node_list_text_only(node.childNodes).strip() # but can be inserted via the editor
             self.text.append(text)                          # so we just drop the header markup and keep the text
@@ -737,7 +734,7 @@
         text = self.node_list_text_only(node.childNodes)
         text = text.replace("\n", " ").lstrip()
 
-         # interwikilink
+         # interwiki link
         if class_ == "interwiki":
             wikitag, wikiurl, wikitail, err = wikiutil.resolve_wiki(
                 self.request, title + ":")
@@ -749,7 +746,7 @@
         elif class_ == "badinterwiki" and title:
             pagename = href
             interwikiname = "%s:%s" % (title, href)
-        if interwikiname and pagename == text:
+        if interwikiname and pagename == text: # XXX interwiki can be undefined here!? 
             self.text.append("%s" % interwikiname)
             return
         elif title == 'Self':
@@ -758,6 +755,12 @@
         elif interwikiname:
             self.text.append("[wiki:%s %s]" % (interwikiname, text))
             return
+        
+        # fix links generated by a broken copy & paste of gecko based browsers
+        brokenness = '../../../..'
+        if href.startswith(brokenness):
+            href = href[len(brokenness):] # just strip it away!
+        # TODO: IE pastes complete http://server/Page/SubPage as href and as text, too
 
         # Attachments
         if title and title.startswith("attachment:"):
@@ -772,7 +775,13 @@
             pagename = pagename.lstrip('/')    # XXX temp fix for generated pagenames starting with /
             if text == pagename:
                 self.text.append(wikiutil.pagelinkmarkup(pagename))
-            # relative link
+            # relative link /SubPage
+            elif href.endswith(text):
+                if pagename.startswith(self.pagename): # is this a subpage of us?
+                    self.text.append(wikiutil.pagelinkmarkup(pagename[len(self.pagename):]))
+                else:
+                    self.text.append(wikiutil.pagelinkmarkup(pagename))
+            # relative link ../
             elif href.endswith(text.lstrip("..").lstrip("/")):
                 self.text.append(wikiutil.pagelinkmarkup(text))
             # labeled link
@@ -818,12 +827,10 @@
                               self.white_space])
         # Smiley
         elif src and (self.request.cfg.url_prefix in src or '../' in src) and "img/" in src: # XXX this is dirty!
-            from MoinMoin import config
             filename = src.split("/")[-1]
             for name, data in config.smileys.iteritems():
                 if data[3] == filename:
-                    self.text.extend([self.white_space, name,
-                                      self.white_space])
+                    self.text.extend([self.white_space, name, self.white_space])
                     return
                 else:
                     pass #print name, data, filename, alt
@@ -843,10 +850,10 @@
     except xml.parsers.expat.ExpatError, msg:
         raise MoinMoin.error.ConvertError('ExpatError: %s' % msg)
 
-def convert(request, text):
+def convert(request, pagename, text):
     text = u"<page>%s</page>" % text
     tree = parse(text)
     strip_whitespace().do(tree)
     strip_break().do(tree)
-    return convert_tree(request).do(tree)
+    return convert_tree(request, pagename).do(tree)
 
--- a/MoinMoin/wikiaction.py	Fri Sep 23 23:00:59 2005 +0000
+++ b/MoinMoin/wikiaction.py	Sat Sep 24 12:13:32 2005 +0000
@@ -578,7 +578,7 @@
     # convert input from Graphical editor
     if lasteditor == 'gui':
         from MoinMoin.converter.text_html_text_x_moin import convert
-        savetext = convert(request, savetext) # XXX error handling
+        savetext = convert(request, pagename, savetext) # XXX error handling
 
     # IMPORTANT: normalize text from the form. This should be done in
     # one place before we manipulate the text.