changeset 5176:c16381dd17fe

merged moin/1.8
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 03 Oct 2009 22:27:50 +0200
parents 6277639194df (current diff) ece8d64f8a57 (diff)
children d60888cbfb22
files MoinMoin/Page.py MoinMoin/action/RenamePage.py MoinMoin/action/SubscribeUser.py MoinMoin/i18n/__init__.py MoinMoin/web/contexts.py
diffstat 6 files changed, 91 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/Page.py	Fri Oct 02 21:38:47 2009 +0200
+++ b/MoinMoin/Page.py	Sat Oct 03 22:27:50 2009 +0200
@@ -1035,7 +1035,7 @@
             redirect_url = Page(request, pagename).url(request,
                                                        querystr={'action': 'show', 'redirect': self.page_name, },
                                                        anchor=anchor)
-            request.http_redirect(redirect_url)
+            request.http_redirect(redirect_url, status='301')
             return
 
         # if necessary, load the formatter
--- a/MoinMoin/action/RenamePage.py	Fri Oct 02 21:38:47 2009 +0200
+++ b/MoinMoin/action/RenamePage.py	Sat Oct 03 22:27:50 2009 +0200
@@ -72,7 +72,7 @@
     def do_action_finish(self, success):
         if success:
             url = Page(self.request, self.newpagename).url(self.request)
-            self.request.http_redirect(url)
+            self.request.http_redirect(url, status='301')
         else:
             self.render_msg(self.make_form(), "dialog")
 
--- a/MoinMoin/action/SubscribeUser.py	Fri Oct 02 21:38:47 2009 +0200
+++ b/MoinMoin/action/SubscribeUser.py	Sat Oct 03 22:27:50 2009 +0200
@@ -1,19 +1,20 @@
 """
    MoinMoin - Subscribeuser - Action
-   Subscribe a user to a page
+   Subscribe (or unsubscribe) a user to a page.
 
    @copyright: 2003 Daniela Nicklas <nicklas@informatik.uni-stuttgart.de>,
-               2005 MoinMoin:AlexanderSchremmer
+               2005 MoinMoin:AlexanderSchremmer,
+               2009 MoinMoin:ThomasWaldmann
    @license: GNU GPL, see COPYING for details.
 """
 
-import sys, os
-#sys.path.append("YOUR CONFIG DIRECTORY HERE")
+import sys, os, re
 
 from MoinMoin.Page import Page
 from MoinMoin import user
 from MoinMoin import wikiutil
 
+
 def show_form(pagename, request):
     _ = request.getText
     request.theme.send_title(_("Subscribe users to the page %s") % pagename, pagename=pagename)
@@ -29,6 +30,31 @@
     request.theme.send_footer(pagename)
     request.theme.send_closing_html()
 
+
+def parse_re(usernames):
+    username_regexes = []
+    for name in usernames:
+        if name.startswith("re:"):
+            name = name[3:]
+        else:
+            name = re.escape(name)
+        username_regexes.append(name)
+    return username_regexes
+
+
+def parse_userlist(usernames):
+    subscribe = []
+    unsubscribe = []
+    for name in usernames:
+        if name.startswith("-"):
+            unsubscribe.append(name[1:])
+        elif name.startswith("+"):
+            subscribe.append(name[1:])
+        else:
+            subscribe.append(name)
+    return parse_re(subscribe), parse_re(unsubscribe)
+
+
 def show_result(pagename, request):
     _ = request.getText
 
@@ -37,50 +63,65 @@
     from MoinMoin.formatter.text_html import Formatter
     formatter = Formatter(request)
 
-    result = subscribe_users(request, request.form['users'].split(","), pagename, formatter)
+    usernames = request.form['users'].split(",")
+    subscribe, unsubscribe = parse_userlist(usernames)
+
+    result = subscribe_users(request, subscribe, unsubscribe, pagename, formatter)
     request.write(result)
 
     request.theme.send_footer(pagename)
     request.theme.send_closing_html()
 
-def subscribe_users(request, usernamelist, pagename, formatter):
+
+def subscribe_users(request, subscribe, unsubscribe, pagename, formatter):
     _ = request.getText
 
     if not Page(request, pagename).exists():
         return u"Page does not exist."
 
     result = []
-
-    realusers = []              # usernames that are really wiki users
+    did_match = {}
 
     # get user object - only with IDs!
     for userid in user.getUserList(request):
-        success = False
         userobj = user.User(request, userid)
+        name = userobj.name
 
-        if userobj.name in usernamelist:   # found a user
-            realusers.append(userobj.name)
-            if userobj.isSubscribedTo([pagename]):
-                success = True
-            elif not userobj.email and not userobj.jid:
-                success = False
-            elif userobj.subscribe(pagename):
-                success = True
-            if success:
-                result.append(formatter.smiley('{OK}'))
-                result.append(formatter.text(" "))
-            else:
-                result.append(formatter.smiley('{X}'))
-                result.append(formatter.text(" "))
-            result.append(formatter.url(1, Page(request, userobj.name).url(request)))
-            result.append(formatter.text(userobj.name))
-            result.append(formatter.url(0))
-            result.append(formatter.linebreak(preformatted=0))
+        matched = subscribed = False
 
-    result.extend([''.join([formatter.smiley('{X}'), formatter.text(" " + _("Not a user:") + " " + username), formatter.linebreak(preformatted=0)]) for username in usernamelist if username not in realusers])
+        for name_re in unsubscribe:
+            if re.match(name_re, name, re.U):
+                matched = did_match[name_re] = True
+                if (not userobj.isSubscribedTo([pagename]) or
+                    userobj.unsubscribe(pagename)):
+                    subscribed = False
+                break
+
+        for name_re in subscribe:
+            if re.match(name_re, name, re.U):
+                matched = did_match[name_re] = True
+                if (userobj.isSubscribedTo([pagename]) or
+                    (userobj.email or userobj.jid) and userobj.subscribe(pagename)):
+                    subscribed = True
+                break
+
+        if matched:
+            result.extend([formatter.smiley(subscribed and '{*}' or '{o}'),
+                           formatter.text(" "),
+                           formatter.url(1, Page(request, name).url(request)),
+                           formatter.text(name),
+                           formatter.url(0),
+                           formatter.linebreak(preformatted=0),
+                          ])
+
+    result.extend([''.join([formatter.smiley('{X}'),
+                            formatter.text(" " + _("Not a user:") + " " + name_re),
+                            formatter.linebreak(preformatted=0)])
+                   for name_re in subscribe + unsubscribe if name_re not in did_match])
 
     return ''.join(result)
 
+
 def execute(pagename, request):
     _ = request.getText
     if not request.user.may.admin(pagename):
@@ -92,14 +133,19 @@
     else:
         show_result(pagename, request)
 
+
 if __name__ == '__main__':
     args = sys.argv
-    if not len(args) > 1:
+    if len(args) < 2:
         print >>sys.stderr, """Subscribe users
 
-%(myname)s pagename username[,username[,username[,...]]] [URL]
+%(myname)s pagename [+|-][re:]username[,username[,username[,...]]] [URL]
 
-Subscribes the users to a page.
++username: subscribes user <username> to page <pagename>.
+-username: unsubscribes user <username> from page <pagename>.
++re:username_re: subscribes users who match <username_re> regex.
+-re:username_re: unsubscribes users who match <username_re> regex.
+
 URL is just needed for a farmconfig scenario.
 
 Example:
@@ -109,7 +155,7 @@
         raise SystemExit
 
     pagename = args[1]
-    usernames = args[2]
+    usernames = args[2].split(",")
 
     if len(args) > 3:
         request_url = args[3]
@@ -123,5 +169,7 @@
     from MoinMoin.formatter.text_plain import Formatter
     formatter = Formatter(request)
 
-    print subscribe_users(request, usernames.split(","), pagename, formatter)
+    subscribe, unsubscribe = parse_userlist(usernames)
 
+    print subscribe_users(request, subscribe, unsubscribe, pagename, formatter)
+
--- a/MoinMoin/filter/application_pdf.py	Fri Oct 02 21:38:47 2009 +0200
+++ b/MoinMoin/filter/application_pdf.py	Sat Oct 03 22:27:50 2009 +0200
@@ -2,7 +2,9 @@
 """
     MoinMoin - PDF filter
 
-    Depends on: pdftotext command from xpdf-utils package
+    Depends on: pdftotext command from either xpdf-utils or poppler-utils
+                or any other package that provides a pdftotext command that
+                is callable with: pdftotext -enc UTF-8 filename.pdf -
 
     @copyright: 2006 MoinMoin:ThomasWaldmann
     @license: GNU GPL, see COPYING for details.
--- a/MoinMoin/i18n/__init__.py	Fri Oct 02 21:38:47 2009 +0200
+++ b/MoinMoin/i18n/__init__.py	Sat Oct 03 22:27:50 2009 +0200
@@ -301,6 +301,9 @@
                 translation.formatted[key] = translated # remember it
     else:
         try:
+            if languages is None:
+                # languages not initialized yet
+                raise KeyError
             language = languages[lang]['x-language-in-english']
             dictpagename = "%sDict" % language.replace(' ', '')
             dicts = request.dicts
--- a/MoinMoin/web/contexts.py	Fri Oct 02 21:38:47 2009 +0200
+++ b/MoinMoin/web/contexts.py	Sat Oct 03 22:27:50 2009 +0200
@@ -266,9 +266,9 @@
             self.headers.set('Pragma', 'no-cache')
         self.request.expires = time.time() - 3600 * 24 * 365
 
-    def http_redirect(self, url):
+    def http_redirect(self, url, status='302'):
         """ Raise a simple redirect exception. """
-        abort(redirect(url))
+        abort(redirect(url, code=int(status)))
 
     # the output related methods
     def write(self, *data):