[Checkins] SVN: zope3org/trunk/src/zorg/wikification/browser/ Added support for relative image src

Uwe Oestermeier uwe_oestermeier at iwm-kmrc.de
Tue May 2 16:44:48 EDT 2006


Log message for revision 67867:
  Added support for relative image src

Changed:
  U   zope3org/trunk/src/zorg/wikification/browser/README.txt
  U   zope3org/trunk/src/zorg/wikification/browser/templates/wiki_folder.pt
  U   zope3org/trunk/src/zorg/wikification/browser/templates/wiki_image.pt
  U   zope3org/trunk/src/zorg/wikification/browser/templates/wiki_newpage.pt
  U   zope3org/trunk/src/zorg/wikification/browser/templates/wiki_upload.pt
  U   zope3org/trunk/src/zorg/wikification/browser/wikilink.py
  U   zope3org/trunk/src/zorg/wikification/browser/wikipage.py

-=-
Modified: zope3org/trunk/src/zorg/wikification/browser/README.txt
===================================================================
--- zope3org/trunk/src/zorg/wikification/browser/README.txt	2006-05-02 20:33:32 UTC (rev 67866)
+++ zope3org/trunk/src/zorg/wikification/browser/README.txt	2006-05-02 20:44:47 UTC (rev 67867)
@@ -220,7 +220,7 @@
     >>> print edit_page.renderBody()
     <BLANKLINE>
     ...
-    <p>A <a href="http://127.0.0.1/site/New%20Label001">New Label</a></p>
+    <p>A <a href="http://127.0.0.1/site/New%20Label">New Label</a></p>
     ...
 
 The more typical usecase is that we want a global substitution. All wikilinks

Modified: zope3org/trunk/src/zorg/wikification/browser/templates/wiki_folder.pt
===================================================================
--- zope3org/trunk/src/zorg/wikification/browser/templates/wiki_folder.pt	2006-05-02 20:33:32 UTC (rev 67866)
+++ zope3org/trunk/src/zorg/wikification/browser/templates/wiki_folder.pt	2006-05-02 20:44:47 UTC (rev 67867)
@@ -4,8 +4,10 @@
            onsubmit="WikiMenu.submitForm(this); return false;"
            onreset="WikiMenu.hideForm()" >
   
-        <div class="wiki-form-title">Create Folder for Link &quot;<span tal:replace="view/unicodeLabel">Name</span>&quot;</div>
-        <input name="link_id" type="hidden" tal:attributes="value string:${view/link_id}" />
+        <div class="wiki-form-title">Create Folder for Link &quot;
+                <span tal:replace="view/unicodeLabel">Name</span>&quot;</div>
+        <input name="link_id" type="hidden" 
+                            tal:attributes="value string:${view/link_id}" />
         <input name="cmd" type="hidden" value="folder" />
         <input name="reference" type="hidden" value="001" 
                 tal:attributes="name string:${view/processor/referenceKey};
@@ -17,7 +19,9 @@
                     Foldername:
                 </td>
                 <td valign="top">
-                    <input class="wiki-input" id="folder_name" name="name" type="text" size="38" value="FolderName" tal:attributes="value python: view.upload_name or view.unicodeLabel()" />
+                    <input class="wiki-input" id="folder_name" name="name" 
+                            type="text" size="38" value="FolderName"
+                            tal:attributes="value string:${view/proposeName}" />
                 </td>
             </tr>
             <tr>
@@ -25,7 +29,8 @@
                     Title:
                 </td>
                 <td valign="top">
-                    <input class="wiki-input" id="file_title" name="title" type="text" size="38" value=""/>
+                    <input class="wiki-input" id="file_title" name="title" 
+                                                type="text" size="38" value=""/>
                 </td>
             </tr>
             <tr>
@@ -33,8 +38,9 @@
                     Description: 
                 </td>
                 <td valign="top">
-                    <textarea class="wiki-input" id="description" name="description"
-                                   cols="37" rows="8" value="123"></textarea>
+                    <textarea class="wiki-input" id="description" 
+                                name="description"
+                                cols="37" rows="8" value="123"></textarea>
                 </td>
             </tr>
             <tr tal:condition="not: view/isUnique"> 
@@ -43,7 +49,8 @@
                 </td>
                 <td valign="top" class="wiki-field">
                     <input name="scope" id="scope" type="checkbox">
-                    Apply to all links named &quot;<span tal:replace="view/unicodeLabel">Name</span>&quot;.
+                    Apply to all links named &quot;
+                        <span tal:replace="view/unicodeLabel">Name</span>&quot;.
                 </td>   
             </tr>
             <tr>

Modified: zope3org/trunk/src/zorg/wikification/browser/templates/wiki_image.pt
===================================================================
--- zope3org/trunk/src/zorg/wikification/browser/templates/wiki_image.pt	2006-05-02 20:33:32 UTC (rev 67866)
+++ zope3org/trunk/src/zorg/wikification/browser/templates/wiki_image.pt	2006-05-02 20:44:47 UTC (rev 67867)
@@ -3,7 +3,8 @@
            enctype="multipart/form-data"
            action="uploadImage"
            onreset="WikiMenu.hideForm();">
-        <div class="wiki-form-title">Upload Image for Link &quot;<span tal:replace="view/unicodeLabel">Name</span>&quot;</div>
+        <div class="wiki-form-title">Upload Image for Link &quot;
+                <span tal:replace="view/unicodeLabel">Name</span>&quot;</div>
         <input name="link_id" type="hidden" tal:attributes="value string:${view/link_id}" />
         <input name="cmd" type="hidden" value="upload" />
         <input name="reference" type="hidden" value="001" 
@@ -15,7 +16,9 @@
                     Image Name:
                 </td>
                 <td valign="top">
-                    <input class="wiki-input" id="image_name" name="name" type="text" size="40" value="FileName" tal:attributes="value string:${view/upload_name}" />
+                    <input class="wiki-input" id="image_name" name="name" 
+                            type="text" size="40" value="FileName" 
+                            tal:attributes="value string:${view/proposeName}" />
                 </td>
             </tr>
             <tr>
@@ -23,7 +26,8 @@
                     Title:
                 </td>
                 <td valign="top">
-                    <input class="wiki-input" id="image_title" name="title" type="text" size="40" value=""/>
+                    <input class="wiki-input" id="image_title" name="title" 
+                                type="text" size="40" value=""/>
                 </td>
             </tr>
             <tr>
@@ -31,8 +35,9 @@
                     Description: 
                 </td>
                 <td valign="top">
-                    <textarea class="wiki-input" id="description" name="description"
-                                   cols="37" rows="8" value="123"></textarea>
+                    <textarea class="wiki-input" id="description"
+                                    name="description"
+                                    cols="37" rows="8" value="123"></textarea>
                 </td>
             </tr>
             <tr>
@@ -49,7 +54,8 @@
                 </td>
                 <td valign="top" class="wiki-field">
                     <input name="scope" id="scope" type="checkbox">
-                    Apply to all links named &quot;<span tal:replace="view/unicodeLabel">Name</span>&quot;.
+                    Apply to all links named &quot;
+                        <span tal:replace="view/unicodeLabel">Name</span>&quot;.
                 </td>   
             </tr>
             <tr>

Modified: zope3org/trunk/src/zorg/wikification/browser/templates/wiki_newpage.pt
===================================================================
--- zope3org/trunk/src/zorg/wikification/browser/templates/wiki_newpage.pt	2006-05-02 20:33:32 UTC (rev 67866)
+++ zope3org/trunk/src/zorg/wikification/browser/templates/wiki_newpage.pt	2006-05-02 20:44:47 UTC (rev 67867)
@@ -3,8 +3,10 @@
            enctype="multipart/form-data"
            onsubmit="WikiMenu.submitForm(this); return false;"
            onreset="WikiMenu.hideForm();">
-        <div class="wiki-form-title">Add Page for Link &quot;<span tal:replace="view/unicodeLabel">Name</span>&quot;</div>
-        <input name="link_id" type="hidden" tal:attributes="value string:${view/link_id}" />
+        <div class="wiki-form-title">Add Page for Link &quot;
+            <span tal:replace="view/unicodeLabel">Name</span>&quot;</div>
+        <input name="link_id" type="hidden" 
+                            tal:attributes="value string:${view/link_id}" />
         <input name="cmd" type="hidden" value="newpage" />
         <input name="reference" type="hidden" value="001" 
                 tal:attributes="name string:${view/processor/referenceKey};
@@ -15,7 +17,9 @@
                     Filename:
                 </td>
                 <td valign="top">
-                    <input class="wiki-input" id="page_name" name="name" type="text" size="40" value="FileName"  tal:attributes="value python: view.unicodeLabel() + u'.html'" />
+                    <input class="wiki-input" id="page_name" name="name" 
+                           type="text" size="40" value="FileName"  
+                           tal:attributes="value string:${view/proposeName}" />
                 </td>
             </tr>
             <tr>
@@ -23,7 +27,8 @@
                     Title:
                 </td>
                 <td valign="top">
-                    <input class="wiki-input" id="page_title" name="title" type="text" size="40" value=""/>
+                    <input class="wiki-input" id="page_title" name="title" 
+                                    type="text" size="40" value=""/>
                 </td>
             </tr>
             <tr>
@@ -31,8 +36,9 @@
                     Abstract: 
                 </td>
                 <td valign="top">
-                    <textarea class="wiki-input" id="description" name="description"
-                                   cols="37" rows="8" value="123"></textarea>
+                    <textarea class="wiki-input" id="description" 
+                                name="description"
+                                cols="37" rows="8" value="123"></textarea>
                 </td>
             </tr>
 
@@ -42,7 +48,8 @@
                 </td>
                 <td valign="top" class="wiki-field">
                     <input name="scope" id="scope" type="checkbox">
-                    Apply to all links named &quot;<span tal:replace="view/unicodeLabel">Name</span>&quot;.
+                    Apply to all links named &quot;
+                        <span tal:replace="view/unicodeLabel">Name</span>&quot;.
                 </td>   
             </tr>
 

Modified: zope3org/trunk/src/zorg/wikification/browser/templates/wiki_upload.pt
===================================================================
--- zope3org/trunk/src/zorg/wikification/browser/templates/wiki_upload.pt	2006-05-02 20:33:32 UTC (rev 67866)
+++ zope3org/trunk/src/zorg/wikification/browser/templates/wiki_upload.pt	2006-05-02 20:44:47 UTC (rev 67867)
@@ -3,8 +3,10 @@
            enctype="multipart/form-data"
            action="uploadFile"
            onreset="WikiMenu.hideForm();">
-        <div class="wiki-form-title">Upload File for Link &quot;<span tal:replace="view/unicodeLabel">Name</span>&quot;</div>
-        <input name="link_id" type="hidden" tal:attributes="value string:${view/link_id}" />
+        <div class="wiki-form-title">Upload File for Link &quot;
+                <span tal:replace="view/unicodeLabel">Name</span>&quot;</div>
+        <input name="link_id" type="hidden" 
+                            tal:attributes="value string:${view/link_id}" />
         <input name="cmd" type="hidden" value="upload" />
         <input name="reference" type="hidden" value="001" 
                 tal:attributes="name string:${view/processor/referenceKey};
@@ -15,7 +17,9 @@
                     File Name:
                 </td>
                 <td valign="top">
-                    <input class="wiki-input" id="file_name" name="name" type="text" size="40" value="FileName" tal:attributes="value string:${view/upload_name}" />
+                    <input class="wiki-input" id="file_name" name="name" 
+                            type="text" size="40" value="FileName" 
+                            tal:attributes="value string:${view/proposeName}" />
                 </td>
             </tr>
             <tr>
@@ -23,7 +27,8 @@
                     Title:
                 </td>
                 <td valign="top">
-                    <input class="wiki-input" id="file_title" name="title" type="text" size="40" value=""/>
+                    <input class="wiki-input" id="file_title" name="title" 
+                                                type="text" size="40" value=""/>
                 </td>
             </tr>
             <tr>
@@ -31,8 +36,9 @@
                     Description: 
                 </td>
                 <td valign="top">
-                    <textarea class="wiki-input" id="description" name="description"
-                                   cols="37" rows="8" value="123"></textarea>
+                    <textarea class="wiki-input" id="description" 
+                                    name="description"
+                                    cols="37" rows="8" value="123"></textarea>
                 </td>
             </tr>
             <tr>
@@ -49,7 +55,8 @@
                 </td>
                 <td valign="top" class="wiki-field">
                     <input name="scope" id="scope" type="checkbox">
-                    Apply to all links named &quot;<span tal:replace="view/unicodeLabel">Name</span>&quot;.
+                    Apply to all links named &quot;
+                    <span tal:replace="view/unicodeLabel">Name</span>&quot;.
                 </td>   
             </tr>
             <tr>

Modified: zope3org/trunk/src/zorg/wikification/browser/wikilink.py
===================================================================
--- zope3org/trunk/src/zorg/wikification/browser/wikilink.py	2006-05-02 20:33:32 UTC (rev 67866)
+++ zope3org/trunk/src/zorg/wikification/browser/wikilink.py	2006-05-02 20:44:47 UTC (rev 67867)
@@ -51,15 +51,12 @@
         self.page = processor.page
         self.index = index
         self.label = label
-        if self.label :                 # with a label we are in text mode
-                                        # and it's up to the user to provide
-                                        # an additional upload target name
-            self.upload_name = ""
-        else :
-            self.upload_name = link
         self.link = link
         self.link_id = processor.createLinkId(index)
         self.nested = 0
+        
+    def proposeName(self) :
+        return self.page.proposePageName(self.label) or self.link
  
     def textLink(self) :
         wikified, link = self.processor.wikifyLink(self.link)
@@ -126,6 +123,8 @@
     def unicodeLabel(self) :
         return unicode(self.editableLabel(), encoding='utf-8')
         
+    
+        
  
  
 class BaseLinkProcessor(BaseHTMLProcessor) :
@@ -260,19 +259,23 @@
         into absolute ones. 
      
         >>> html = '''<p><a href="http://www.iwm-kmrc.de">Absolute</a></p>
-        ...           <p><a href="relative">Relative</a></p>'''
+        ...           <p><a href="relative">Relative</a></p>
+        ...           <img src="http://www.iwm-kmrc.de/image.gif"/>
+        ...           <img src="images/image.gif"/>'''
         
         >>> processor = RelativeLinkProcessor("http://www.iwm-kmrc.de")
         >>> processor.feed(html)
         >>> print processor.output()
         <p><a href="http://www.iwm-kmrc.de">Absolute</a></p>
         <p><a href="http://www.iwm-kmrc.de/relative">Relative</a></p>
-       
+        <img src="http://www.iwm-kmrc.de/image.gif">
+        <img src="http://www.iwm-kmrc.de/images/image.gif">
+     
         
     """
  
     def __init__(self, base_url) :
-        BaseHTMLProcessor.__init__(self)
+        BaseLinkProcessor.__init__(self)
         self.base_url = base_url
         
     def onRelativeLink(self, link) :
@@ -280,7 +283,7 @@
         return "%s/%s" % (self.base_url, link)
         
         
-class WikiLinkProcessor(BaseLinkProcessor) :
+class WikiLinkProcessor(RelativeLinkProcessor) :
     """ A link processor that wikifies the links by modifying the
         href and other attributes of a link.
         
@@ -293,7 +296,10 @@
     command = None
 
     def __init__(self, page) :
-        BaseHTMLProcessor.__init__(self)
+        """ Inits the wiki link processor with base url of the page container.
+        """
+        base_url = page.getBaseURL()
+        RelativeLinkProcessor.__init__(self, base_url)
         self.page = page
         self.placeholders = {}
         self.placeholder = None     # current placeholder
@@ -426,7 +432,7 @@
         else :
             self.placeholder.nested += 1
             
-        BaseHTMLProcessor.unknown_starttag(self, tag, attrs)               
+        RelativeLinkProcessor.unknown_starttag(self, tag, attrs)               
 
     def unknown_endtag(self, tag) :
         """ Called for each tag. Looks for pending placeholders and
@@ -434,7 +440,7 @@
             is rendered after the tag is closed.
         """
         
-        BaseHTMLProcessor.unknown_endtag(self, tag)
+        RelativeLinkProcessor.unknown_endtag(self, tag)
         if self.placeholder is not None :
             if self.placeholder.nested == 0 :
                 after = self.placeholder.afterCloseTag()
@@ -485,7 +491,7 @@
             self.pieces.append(text)
             return
             
-        BaseLinkProcessor.handle_data(self, text)
+        RelativeLinkProcessor.handle_data(self, text)
              
     def onWikiTextLink(self, label) :
         name = label.replace(" ", "")
@@ -500,7 +506,7 @@
         for placeholder commands with global scope.
         
         """
-        html = BaseHTMLProcessor.output(self)
+        html = RelativeLinkProcessor.output(self)
         for placeholder in self.placeholders.values() :
             html = placeholder.postProcessing(html)
                        
@@ -596,7 +602,7 @@
         
     """
     
-    global_scope = False        # default: depends on usecase
+    global_scope = True        # default: depends on usecase
     render_form = False
     
     def textLink(self) :
@@ -629,7 +635,8 @@
         """ Replaces the label in text mode. """
         
         scope = self.page.parameter('scope')
-        self.global_scope = scope and scope.lower() == 'on'
+        if scope :
+            self.global_scope = scope.lower() == 'on'
         
         label = self._newLabel()
         self.new_link = '[' + label + ']'
@@ -684,9 +691,10 @@
         """
         
         zope.event.notify(ObjectCreatedEvent(obj))
-        
+            
         scope = self.page.parameter('scope')
-        self.global_scope = scope and scope.lower() == 'on'
+        if scope :
+            self.global_scope = scope.lower() == 'on'
         
         container = self.page.container
         chooser = INameChooser(container)
@@ -787,6 +795,10 @@
     
     _form = ViewPageTemplateFile("./templates/wiki_newpage.pt")
                 
+    def proposeName(self) :
+        name = super(CreatePagePlaceholder, self).proposeName()
+        return name + self.page.getExtension()
+        
     def apply(self) :
         """ Create a page. Returns the name of the new page.
         """

Modified: zope3org/trunk/src/zorg/wikification/browser/wikipage.py
===================================================================
--- zope3org/trunk/src/zorg/wikification/browser/wikipage.py	2006-05-02 20:33:32 UTC (rev 67866)
+++ zope3org/trunk/src/zorg/wikification/browser/wikipage.py	2006-05-02 20:44:47 UTC (rev 67867)
@@ -103,7 +103,7 @@
         
         self.title = dc.title or self.untitled
         self.language = dc.Language()
-        
+     
     def message(self, msg) :
         return '<div class="system-message">%s</div>' % msg
         
@@ -125,6 +125,15 @@
         if file is not None :
             return IZopeDublinCore(file).description or u""
         return u""
+        
+    def getExtension(self) :
+        return '.html'
+        
+    def proposePageName(self, label) :
+        """ Translates a wiki label into a reasonable filename.
+            The default implementation returns the unmodified label.
+        """
+        return label
 
     def isEditable(self) :
         try :
@@ -208,7 +217,10 @@
        #  print "Form:"
 #         print form
         return form
-        
+
+    def getBaseURL(self) :
+        return zapi.absoluteURL(self.container, self.request) + '/'
+
     def getURL(self) :
         return zapi.absoluteURL(self.context, self.request)
       



More information about the Checkins mailing list