changeset 1737:fa04be6b7ea4

merged main
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 13 Jan 2007 21:55:21 +0100
parents 6e4acd9904d7 (current diff) 5e870f4e5d2e (diff)
children 7ac15b5e2db8
files
diffstat 7 files changed, 169 insertions(+), 78 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/PackagePages.py	Sat Jan 13 21:53:11 2007 +0100
+++ b/MoinMoin/action/PackagePages.py	Sat Jan 13 21:55:21 2007 +0100
@@ -112,10 +112,11 @@
             zf.writestr(zi, page.get_raw_body().encode("utf-8"))
             for attname in files:
                 if attname != packagename:
-                    script.append(packLine(["AddAttachment", attname, page.page_name, user.getUserIdentification(self.request), "Created by the PackagePages action."]))
-                    filename =  AttachFile.getFilename(self.request, page.page_name, attname)
-                    zf.write(filename.encode("cp437"), attname.encode("cp437"))
-
+                    cnt += 1
+                    zipname = "%s_attachment" % str(cnt)
+                    script.append(packLine(["AddAttachment", zipname, attname, page.page_name, user.getUserIdentification(self.request), "Created by the PackagePages action."]))
+                    filename = AttachFile.getFilename(self.request, page.page_name, attname)
+                    zf.write(filename.encode("cp437"), zipname)
         script += [packLine(['Print', 'Thank you for using PackagePages!'])]
 
         zf.writestr(MOIN_PACKAGE_FILE, u"\n".join(script).encode("utf-8"))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/action/supplementation.py	Sat Jan 13 21:55:21 2007 +0100
@@ -0,0 +1,36 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - Action for supplementation pages
+
+    This Action is used to create a supplementation subpage e.g. a Discussion page below a comon page
+        
+    Note:
+    derived from the newpage macro by Vito Miliano (vito_moinnewpagewithtemplate@perilith.com) et al
+
+    @copyright: 2006-2007 ReimarBauer  
+    @license: GNU GPL, see COPYING for details.  
+"""
+from MoinMoin.Page import Page
+from MoinMoin.wikiutil import quoteWikinameURL
+
+def execute(pagename, request):
+    _ = request.getText
+    sub_page_name = request.cfg.supplementation_page_name
+    sub_page_template = request.cfg.supplementation_page_template
+    newpagename = "%s/%s" % (pagename, sub_page_name)
+
+    if pagename.endswith(sub_page_name): # sub_sub_page redirects to sub_page
+        query = {}
+        url = Page(request, pagename).url(request, query, escape=0, relative=False)
+        request.http_redirect(url)
+    elif request.user.may.read(newpagename) and request.user.may.write(newpagename):
+        query = {}
+        url = Page(request, newpagename).url(request, query, escape=0, relative=False)
+        test = Page(request, newpagename)
+        if test.exists(): # page is defined -> redirect
+            request.http_redirect(url)
+        else:  # page will be created from template
+            query = {'action': 'edit', 'backto': newpagename}
+            query['template'] = quoteWikinameURL(sub_page_template)
+            url = Page(request, newpagename).url(request, query, escape=0, relative=False)
+            request.http_redirect(url)
--- a/MoinMoin/config/multiconfig.py	Sat Jan 13 21:53:11 2007 +0100
+++ b/MoinMoin/config/multiconfig.py	Sat Jan 13 21:55:21 2007 +0100
@@ -383,7 +383,9 @@
     stylesheets = [] # list of tuples (media, csshref) to insert after theme css, before user css
     subscribed_pages_default = [] # preload user subscribed pages with this page list
     superuser = [] # list of unicode user names that have super powers :)
-
+    supplementation_page = False
+    supplementation_page_name = u'Discussion'
+    supplementation_page_template = u'DiscussionTemplate'
     surge_action_limits = {# allow max. <count> <action> requests per <dt> secs
         # action: (count, dt)
         'all': (30, 30),
--- a/MoinMoin/formatter/text_gedit.py	Sat Jan 13 21:53:11 2007 +0100
+++ b/MoinMoin/formatter/text_gedit.py	Sat Jan 13 21:55:21 2007 +0100
@@ -73,9 +73,14 @@
     def attachment_image(self, url, **kw):
         _ = self.request.getText
         pagename = self.page.page_name
-        return self.image(
-            title="attachment:%s" % wikiutil.quoteWikinameURL(url),
-            src=AttachFile.getAttachUrl(pagename, url, self.request, addts=1))
+        kw = {}
+        kw['title'] = "attachment:%s" % wikiutil.quoteWikinameURL(url)
+        if '/' in url:
+            pagename, target = AttachFile.absoluteName(url, pagename)
+            url = url.split('/')
+            url = url[len(url)-1]
+        kw['src'] = AttachFile.getAttachUrl(pagename, url, self.request, addts=1)
+        return self.image(**kw)
 
     def attachment_drawing(self, url, text, **kw):
         _ = self.request.getText
@@ -119,15 +124,16 @@
                         if url.startswith('http'):
                             kw['src'] = url
                         else:
-                            if '/' in arg:
-                                pagename, arg = arg.split('/')
-                                url = arg
                             kw['title'] = "attachment:%s" % wikiutil.quoteWikinameURL(url)
                     elif pos == 1 and arg:
                         kw['target'] = arg
                     pos += 1
             if not kw['src']:
-               kw['src'] = AttachFile.getAttachUrl(pagename, url, self.request, addts=1)
+                if '/' in url:
+                    pagename, target = AttachFile.absoluteName(url, pagename)
+                    url = url.split('/')
+                    url = url[len(url)-1]
+                kw['src'] = AttachFile.getAttachUrl(pagename, url, self.request, addts=1)
             return self.image(**kw)
 
         elif args is not None:
--- a/MoinMoin/packages.py	Sat Jan 13 21:53:11 2007 +0100
+++ b/MoinMoin/packages.py	Sat Jan 13 21:55:21 2007 +0100
@@ -118,31 +118,36 @@
         #Satisfy pylint
         self.msg = getattr(self, "msg", "")
         self.request = getattr(self, "request", None)
-    def do_addattachment(self, filename, pagename, author=u"Scripting Subsystem", comment=u""):
+    def do_addattachment(self, zipname, filename, pagename, author=u"Scripting Subsystem", comment=u""):
         """
         Installs an attachment
 
         @param pagename: Page where the file is attached. Or in 2.0, the file itself.
+        @param zipname: Filename of the attachment from the zip file
         @param filename: Filename of the attachment (just applicable for MoinMoin < 2.0)
         """
-        _ = self.request.getText
+        if self.request.user.may.write(pagename):
+            _ = self.request.getText
 
-        attachments = Page(self.request, pagename).getPagePath("attachments", check_create=1)
-        filename = wikiutil.taintfilename(filename)
-        target = os.path.join(attachments, filename)
-        page = PageEditor(self.request, pagename, do_editor_backup=0, uid_override=author)
-        rev = page.current_rev()
-        path = page.getPagePath(check_create=0)
-        if not os.path.exists(target):
-           self._extractToFile(filename, target)
-           if os.path.exists(target):
-              os.chmod(target, config.umask )
-              action = 'ATTNEW'
-              edit_logfile_append(self, pagename, path, rev, action, logname='edit-log',
-                      comment=u'%(filename)s' % {"filename":filename}, author=author)
-              self.msg += u"%(filename)s attached \n" % {"filename": filename}
+            attachments = Page(self.request, pagename).getPagePath("attachments", check_create=1)
+            filename = wikiutil.taintfilename(filename)
+            zipname = wikiutil.taintfilename(zipname)
+            target = os.path.join(attachments, filename)
+            page = PageEditor(self.request, pagename, do_editor_backup=0, uid_override=author)
+            rev = page.current_rev()
+            path = page.getPagePath(check_create=0)
+            if not os.path.exists(target):
+                self._extractToFile(zipname, target)
+                if os.path.exists(target):
+                    os.chmod(target, config.umask )
+                    action = 'ATTNEW'
+                    edit_logfile_append(self, pagename, path, rev, action, logname='edit-log',
+                                       comment=u'%(filename)s' % {"filename":filename}, author=author)
+                self.msg += u"%(filename)s attached \n" % {"filename": filename}
+            else:
+                self.msg += u"%(filename)s not attached \n" % {"filename":filename}
         else:
-           self.msg += u"%(filename)s not attached \n" % {"filename":filename}
+            self.msg += u"action add attachment: not enough rights - nothing done \n"
 
     def do_delattachment(self, filename, pagename, author=u"Scripting Subsystem", comment=u""):
         """
@@ -151,22 +156,25 @@
         @param pagename: Page where the file is attached. Or in 2.0, the file itself.
         @param filename: Filename of the attachment (just applicable for MoinMoin < 2.0)
         """
-        _ = self.request.getText
+        if self.request.user.may.write(pagename):
+            _ = self.request.getText
 
-        attachments = Page(self.request, pagename).getPagePath("attachments", check_create=1)
-        filename = wikiutil.taintfilename(filename)
-        target = os.path.join(attachments, filename)
-        page = PageEditor(self.request, pagename, do_editor_backup=0, uid_override=author)
-        rev = page.current_rev()
-        path = page.getPagePath(check_create=0)
-        if os.path.exists(target):
-              os.remove(target)
-              action = 'ATTDEL'
-              edit_logfile_append(self, pagename, path, rev, action, logname='edit-log',
-                      comment=u'%(filename)s' % {"filename":filename}, author=author)
-              self.msg += u"%(filename)s removed \n" % {"filename":filename}
+            attachments = Page(self.request, pagename).getPagePath("attachments", check_create=1)
+            filename = wikiutil.taintfilename(filename)
+            target = os.path.join(attachments, filename)
+            page = PageEditor(self.request, pagename, do_editor_backup=0, uid_override=author)
+            rev = page.current_rev()
+            path = page.getPagePath(check_create=0)
+            if os.path.exists(target):
+                os.remove(target)
+                action = 'ATTDEL'
+                edit_logfile_append(self, pagename, path, rev, action, logname='edit-log',
+                                    comment=u'%(filename)s' % {"filename":filename}, author=author)
+                self.msg += u"%(filename)s removed \n" % {"filename":filename}
+            else:
+                self.msg += u"%(filename)s not exists \n" % {"filename":filename}
         else:
-           self.msg += u"%(filename)s not exists \n" % {"filename":filename}
+            self.msg += u"action delete attachment: not enough rights - nothing done \n"
 
     def do_print(self, *param):
         """ Prints the parameters into output of the script. """
@@ -285,18 +293,21 @@
         @param comment:  comment related to this revision (optional)
         @param trivial:  boolean, if it is a trivial edit
         """
-        _ = self.request.getText
-        trivial = str2boolean(trivial)
-        uid = user.getUserId(self.request, author)
-        theuser = user.User(self.request, uid)
-        self.request.user = theuser
-        page = PageEditor(self.request, pagename, do_editor_backup=0, uid_override=author)
-        try:
-            page.saveText(self.extract_file(filename).decode("utf-8"), 0, trivial=trivial, comment=comment)
-            self.msg += u"%(pagename)s added \n" % {"pagename": pagename}
-        except PageEditor.Unchanged:
-            pass
-        page.clean_acl_cache()
+        if self.request.user.may.write(pagename):
+            _ = self.request.getText
+            trivial = str2boolean(trivial)
+            uid = user.getUserId(self.request, author)
+            theuser = user.User(self.request, uid)
+            self.request.user = theuser
+            page = PageEditor(self.request, pagename, do_editor_backup=0, uid_override=author)
+            try:
+                page.saveText(self.extract_file(filename).decode("utf-8"), 0, trivial=trivial, comment=comment)
+                self.msg += u"%(pagename)s added \n" % {"pagename": pagename}
+            except PageEditor.Unchanged:
+                pass
+            page.clean_acl_cache()
+        else:
+            self.msg += u"action add revision: not enough rights - nothing done \n"
 
     def do_renamepage(self, pagename, newpagename, author=u"Scripting Subsystem", comment=u"Renamed by the scripting subsystem."):
         """ Renames a page.
@@ -306,15 +317,18 @@
         @param author:   user name of the editor (optional)
         @param comment:  comment related to this revision (optional)
         """
-        _ = self.request.getText
-        page = PageEditor(self.request, pagename, do_editor_backup=0, uid_override=author)
-        if not page.exists():
-            raise RuntimeScriptException(_("The page %s does not exist.") % pagename)
-        newpage = PageEditor(self.request, newpagename)
-        page.renamePage(newpage.page_name, comment=u"Renamed from '%s'" % (pagename))
-        self.msg += u'%(pagename)s renamed to %(newpagename)s\n' % {
-                    "pagename": pagename,
-                    "newpagename": newpagename}
+        if self.request.user.may.write(pagename):
+            _ = self.request.getText
+            page = PageEditor(self.request, pagename, do_editor_backup=0, uid_override=author)
+            if not page.exists():
+                raise RuntimeScriptException(_("The page %s does not exist.") % pagename)
+            newpage = PageEditor(self.request, newpagename)
+            page.renamePage(newpage.page_name, comment=u"Renamed from '%s'" % (pagename))
+            self.msg += u'%(pagename)s renamed to %(newpagename)s\n' % {
+                            "pagename": pagename,
+                            "newpagename": newpagename}
+        else:
+            self.msg += u"action rename page: not enough rights - nothing done \n"
 
     def do_deletepage(self, pagename, comment="Deleted by the scripting subsystem."):
         """ Marks a page as deleted (like the DeletePage action).
@@ -322,12 +336,14 @@
         @param pagename: page to delete
         @param comment:  the related comment (optional)
         """
-        _ = self.request.getText
-        page = PageEditor(self.request, pagename, do_editor_backup=0)
-        if not page.exists():
-            raise RuntimeScriptException(_("The page %s does not exist.") % pagename)
-
-        page.deletePage(comment)
+        if self.request.user.may.write(pagename):
+            _ = self.request.getText
+            page = PageEditor(self.request, pagename, do_editor_backup=0)
+            if not page.exists():
+                raise RuntimeScriptException(_("The page %s does not exist.") % pagename)
+            page.deletePage(comment)
+        else:
+            self.msg += u"action delete page: not enough rights - nothing done \n"
 
     def do_replaceunderlay(self, filename, pagename):
         """
--- a/MoinMoin/theme/__init__.py	Sat Jan 13 21:53:11 2007 +0100
+++ b/MoinMoin/theme/__init__.py	Sat Jan 13 21:55:21 2007 +0100
@@ -1053,13 +1053,40 @@
         This is separate method to make it easy to customize the
         edtibar in sub classes.
         """
-        return [self.editorLink(page),
-                self.infoLink(page),
-                self.subscribeLink(page),
-                self.quicklinkLink(page),
-                self.attachmentsLink(page),
-                self.actionsMenu(page),
-               ]
+
+        editbar_items = {'Edit': self.editorLink(page),
+                          self.request.cfg.supplementation_page_name:
+                          self.supplementation_page_nameLink(page),
+                          'Info': self.infoLink(page),
+                          'Subscribe': self.subscribeLink(page),
+                          'Quicklink': self.quicklinkLink(page),
+                          'Attachments': self.attachmentsLink(page),
+                          'ActionsMenu': self.actionsMenu(page)
+                          }
+        edit_bar = [u'Edit', u'Info', u'Subscribe', u'Quicklink', u'Attachments', u'ActionsMenu', ]
+        if self.request.cfg.supplementation_page is True:
+            if self.request.getPragma('supplementation-page', 1) == 'off':
+                edit_bar = edit_bar
+            else:
+                edit_bar.insert(1, self.request.cfg.supplementation_page_name)
+        else:
+            if self.request.getPragma('supplementation-page', 1) == 'on':
+                edit_bar.insert(1, self.request.cfg.supplementation_page_name)
+            else:
+                edit_bar = edit_bar
+
+
+        allowed_action = []
+        for action in edit_bar:
+            allowed_action.append(editbar_items[action])
+        return allowed_action
+
+    def supplementation_page_nameLink(self, page):
+        """  discussion for page """
+        _ = self.request.getText
+        return page.link_to(self.request,
+                            text=_(self.request.cfg.supplementation_page_name, formatted=False),
+                            querystr={'action': 'supplementation'}, id='supplementation', rel='nofollow')
 
     def guiworks(self, page):
         """ Return whether the gui editor / converter can work for that page.
@@ -1128,7 +1155,7 @@
 var gui_editor_link_text = "%(text)s";
 //-->
 </script>        
-""" % {'url': page.url(self.request, querystr={'action': 'edit', 'editor': 'gui', }, escape=0),
+""" % {'url': page.url(self.request, querystr={'action': 'edit', 'editor': 'gui', }, escape=0, relative=False),
        'text': _('Edit (GUI)', formatted=False),
       }
 
--- a/docs/CHANGES	Sat Jan 13 21:53:11 2007 +0100
+++ b/docs/CHANGES	Sat Jan 13 21:55:21 2007 +0100
@@ -290,6 +290,9 @@
     * the login page gives now the possibility to recover a lost password, thanks to 
       Oliver Siemoneit. This is especially useful for wikis where access to user 
       preferences is restricted by acl.
+    * we now have the possibility to add a Discussion page 
+      (FeatureRequests/DiscussionAndOrCommentPages) 
+    * Package Pages does now support attachments
 
   Bugfixes:
     * on action "info" page, "revert" link will not be displayed for empty page