changeset 3072:103fd9035d50

merged main
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 22 Feb 2008 22:03:12 +0100
parents 806cf4814612 (current diff) ed1a433803c6 (diff)
children 78c516164e01
files MoinMoin/request/__init__.py MoinMoin/server/server_modpython.py MoinMoin/server/server_wsgi.py
diffstat 21 files changed, 96 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/test_packages.py	Fri Feb 22 21:59:32 2008 +0100
+++ b/MoinMoin/_tests/test_packages.py	Fri Feb 22 22:03:12 2008 +0100
@@ -101,8 +101,8 @@
         package = PackagePages(self.request.rootpage.page_name, self.request)
         temp = tempfile.NamedTemporaryFile(suffix='.zip')
         package.collectpackage(self.request.rootpage.getPageList(
-                                include_underlay=False, 
-                                filter=lambda name: not wikiutil.isSystemPage(self.request, name)), 
+                                include_underlay=False,
+                                filter=lambda name: not wikiutil.isSystemPage(self.request, name)),
                                 temp)
         if package:
             py.test.skip("No user created pages in wiki!")
@@ -114,3 +114,4 @@
         package.collectpackage(['___//THIS PAGE SHOULD NOT EXIST\\___'], temp)
         assert not zipfile.is_zipfile(temp.name)
 coverage_modules = ['MoinMoin.packages']
+
--- a/MoinMoin/action/LikePages.py	Fri Feb 22 21:59:32 2008 +0100
+++ b/MoinMoin/action/LikePages.py	Fri Feb 22 22:03:12 2008 +0100
@@ -30,13 +30,13 @@
 
     # No matches
     if not matches:
-        request.theme.add_msg(_('No pages like "%s"!') % (pagename,), "error")
+        request.theme.add_msg(_('No pages like "%s"!') % (pagename, ), "error")
         Page(request, pagename).send_page()
         return
 
     # One match - display it
     if len(matches) == 1:
-        request.theme.add_msg(_('Exactly one page like "%s" found, redirecting to page.', formatted=False) % (pagename,), "info")
+        request.theme.add_msg(_('Exactly one page like "%s" found, redirecting to page.', formatted=False) % (pagename, ), "info")
         Page(request, matches.keys()[0]).send_page()
         return
 
--- a/MoinMoin/action/PackagePages.py	Fri Feb 22 21:59:32 2008 +0100
+++ b/MoinMoin/action/PackagePages.py	Fri Feb 22 22:03:12 2008 +0100
@@ -156,7 +156,7 @@
         """ Search MoinMoin for the string specified and return a list of
         matching pages, provided they are not system pages and not
         present in the underlay.
-        
+
         @param request: current request
         @param searchkey: string to search for
         @rtype: list
@@ -164,7 +164,7 @@
         """
 
         pagelist = searchPages(request, searchkey)
-        
+
         titles = []
         for title in pagelist.hits:
             if not wikiutil.isSystemPage(request, title.page_name) or not title.page.getPageStatus()[0]:
@@ -174,7 +174,7 @@
     def collectpackage(self, pagelist, fileobject, pkgname=""):
         """ Expects a list of pages as an argument, and fileobject to be an open
         file object, which a zipfile will get written to.
-        
+
         @param pagelist: pages to package
         @param fileobject: open file object to write to
         @param pkgname: optional file name, to prevent self packaging
--- a/MoinMoin/action/newaccount.py	Fri Feb 22 21:59:32 2008 +0100
+++ b/MoinMoin/action/newaccount.py	Fri Feb 22 22:03:12 2008 +0100
@@ -21,7 +21,7 @@
 
     if request.request_method != 'POST':
         return _("Use UserPreferences to change your settings or create an account.")
-           
+
     if not TextCha(request).check_answer_from_form():
         return _('TextCha: Wrong answer! Go back and try again...', formatted=False)
 
@@ -133,7 +133,7 @@
     row = html.TR()
     tbl.append(row)
     row.append(html.TD().append(html.STRONG().append(
-                                  html.Text(_('TextCha (required)', formatted=False))))) 
+                                  html.Text(_('TextCha (required)', formatted=False)))))
     td = html.TD()
     textcha = TextCha(request).render()
     if textcha:
@@ -179,3 +179,4 @@
 
         request.theme.send_footer(pagename)
         request.theme.send_closing_html()
+
--- a/MoinMoin/action/recoverpass.py	Fri Feb 22 21:59:32 2008 +0100
+++ b/MoinMoin/action/recoverpass.py	Fri Feb 22 22:03:12 2008 +0100
@@ -18,12 +18,26 @@
 Contact the owner of the wiki, who can enable email.""")
     try:
         email = wikiutil.clean_input(form['email'][0].lower())
+        if not email:
+            raise KeyError # we raise KeyError if the string is empty
     except KeyError:
-        return _("Please provide a valid email address!")
+        try:
+            username = wikiutil.clean_input(form['name'][0])
+            if not username:
+                raise KeyError
+        except KeyError:
+            return _("Please provide a valid email address!", formatted=False)
+
+        u = user.User(self.request, user.getUserId(self.request, username))
+        if u.valid:
+            is_ok, msg = u.mailAccountData()
+            if not is_ok:
+                return wikiutil.escape(msg)
+        return _("If an account with this username exists, an email was sent.", formatted=False)
 
     u = user.get_by_email_address(request, email)
     if u:
-        msg = u.mailAccountData()
+        is_ok, msg = u.mailAccountData()
         return wikiutil.escape(msg)
 
     return _("Found no account matching the given email address '%(email)s'!") % {'email': email}
--- a/MoinMoin/action/supplementation.py	Fri Feb 22 21:59:32 2008 +0100
+++ b/MoinMoin/action/supplementation.py	Fri Feb 22 22:03:12 2008 +0100
@@ -36,4 +36,4 @@
             request.theme.add_msg(errormsg, "error")
     else:
         request.theme.add_msg(errormsg, "error")
-        
\ No newline at end of file
+
--- a/MoinMoin/action/userprofile.py	Fri Feb 22 21:59:32 2008 +0100
+++ b/MoinMoin/action/userprofile.py	Fri Feb 22 22:03:12 2008 +0100
@@ -7,7 +7,7 @@
 """
 from MoinMoin.Page import Page
 from MoinMoin import user
- 
+
 def execute(pagename, request):
     """ set values in user profile """
     _ = request.getText
@@ -17,17 +17,17 @@
     if not request.user.isSuperUser():
         request.theme.add_msg(_("Only superuser is allowed to use this action."), "error")
     else:
-       user_name = form.get('name', [''])[0]
-       key = form.get('key', [''])[0]
-       val = form.get('val', [''])[0]
-       if key in cfg.user_checkbox_fields:
-           val = int(val)
-       uid = user.getUserId(request, user_name)
-       theuser = user.User(request, uid)
-       oldval = getattr(theuser, key)
-       setattr(theuser, key, val)
-       theuser.save()
-       request.theme.add_msg('%s.%s: %s -> %s' % (user_name, key, oldval, val), "info")
+        user_name = form.get('name', [''])[0]
+        key = form.get('key', [''])[0]
+        val = form.get('val', [''])[0]
+        if key in cfg.user_checkbox_fields:
+            val = int(val)
+        uid = user.getUserId(request, user_name)
+        theuser = user.User(request, uid)
+        oldval = getattr(theuser, key)
+        setattr(theuser, key, val)
+        theuser.save()
+        request.theme.add_msg('%s.%s: %s -> %s' % (user_name, key, oldval, val), "info")
 
     Page(request, pagename).send_page()
 
--- a/MoinMoin/auth/ldap_login.py	Fri Feb 22 21:59:32 2008 +0100
+++ b/MoinMoin/auth/ldap_login.py	Fri Feb 22 22:03:12 2008 +0100
@@ -86,7 +86,7 @@
                     except (ldap.SERVER_DOWN, ldap.CONNECT_ERROR), err:
                         if verbose: request.log("LDAP: Couldn't establish TLS to %r (err: %s)." % (server, str(err)))
                         raise
-  
+
                 # you can use %(username)s and %(password)s here to get the stuff entered in the form:
                 ldap_binddn = cfg.ldap_binddn % locals()
                 ldap_bindpw = cfg.ldap_bindpw % locals()
--- a/MoinMoin/i18n/__init__.py	Fri Feb 22 21:59:32 2008 +0100
+++ b/MoinMoin/i18n/__init__.py	Fri Feb 22 22:03:12 2008 +0100
@@ -272,6 +272,7 @@
             # if we don't find an english "translation", we just format it
             # on the fly (this is needed for cfg.editor_quickhelp).
             if lang != 'en':
+                logging.debug("i18n: fallback to english, requested string not in %r translation: %r" % (lang, original))
                 translated = getText(original, request, 'en', formatted)
             elif formatted:
                 translated = translations[lang].formatMarkup(request, original)
--- a/MoinMoin/parser/text_creole.py	Fri Feb 22 21:59:32 2008 +0100
+++ b/MoinMoin/parser/text_creole.py	Fri Feb 22 22:03:12 2008 +0100
@@ -413,7 +413,7 @@
                 buf.flush()
                 writ = buf.getvalue()
                 buf.close()
-                return ret+writ
+                return ret + writ
             except wikiutil.PluginMissingError:
                 pass
         return ''.join([
--- a/MoinMoin/parser/text_moin_wiki.py	Fri Feb 22 21:59:32 2008 +0100
+++ b/MoinMoin/parser/text_moin_wiki.py	Fri Feb 22 22:03:12 2008 +0100
@@ -1216,7 +1216,7 @@
                 self.parser_lines.append(word)
         else:
             self.in_pre = 'search_parser'
-        
+
         #logging.debug("_parser_repl: in_pre %r line %d" % (self.in_pre, self.lineno))
         return ''
     _parser_unique_repl = _parser_repl
--- a/MoinMoin/request/__init__.py	Fri Feb 22 21:59:32 2008 +0100
+++ b/MoinMoin/request/__init__.py	Fri Feb 22 22:03:12 2008 +0100
@@ -15,7 +15,7 @@
 #proxies_trusted = ['127.0.0.1', ] # can be a list of multiple IPs
 
 import logging
-proxy_loglevel = logging.DEBUG # logging.NOTSET (never), logging.INFO (when not debugging)
+proxy_loglevel = logging.INFO # logging.NOTSET (never), .DEBUG, .INFO
 
 def find_remote_addr(addrs):
     """ Find the last remote IP address before it hits our reverse proxies.
@@ -24,7 +24,7 @@
         The FIRST address in the <addrs> list might be the client's IP - if noone cheats
         and everyone supports x-f-f header.
 
-        See http://bob.pythonmac.org/archives/2005/09/23/apache-x-forwarded-for-caveat/                                                          
+        See http://bob.pythonmac.org/archives/2005/09/23/apache-x-forwarded-for-caveat/
 
         For debug loglevel, we log all <addrs>.
 
@@ -530,16 +530,16 @@
 
     def rewriteRemoteAddr(self, env):
         """ Rewrite remote_addr transparently
-        
+
         Get the proxy remote addr using 'X-Forwarded-For' header, added by
         Apache 2 and other proxy software.
-        
+
         TODO: Will not work for Apache 1 or others that don't add this header.
-        
+
         TODO: If we want to add an option to disable this feature it
         should be in the server script, because the config is not
         loaded at this point, and must be loaded after url is set.
-        
+
         @param env: dict like object containing cgi meta variables or http headers.
         """
         xff = (env.get(self.proxy_xff) or
--- a/MoinMoin/script/export/package.py	Fri Feb 22 21:59:32 2008 +0100
+++ b/MoinMoin/script/export/package.py	Fri Feb 22 22:03:12 2008 +0100
@@ -35,7 +35,7 @@
             "-s", "--search", dest="search",
             help="Search string to match."
         )
-        
+
         self.parser.add_option(
             "-u", "--user", dest="package_user",
             help="User as whom the package operation will be performed as. "
@@ -43,12 +43,12 @@
 
     def mainloop(self):
         """ moin-package's main code. """
-        
+
         # Initalize request
         self.init_request()
         request = self.request
         _ = self.request.getText
-        
+
         # Check our command line args
         if self.options.pages and self.options.search:
             script.fatal(_("Options --pages and --search are mutually exclusive!"))
@@ -60,14 +60,14 @@
         # Sanity checks
         if os.path.exists(self.options.output):
             script.fatal(_("Output file already exists! Cowardly refusing to continue!"))
-        
+
         # Check for user
         if self.options.package_user:
             request.user = user.User(request, name=self.options.package_user)
-        
+
         # Import PackagePages here, as we now have an initalized request.
         from MoinMoin.action.PackagePages import PackagePages
-        
+
         # Perform actual packaging.
         package = PackagePages(request.rootpage.page_name, request)
         packageoutput = open(self.options.output, "wb")
@@ -78,8 +78,9 @@
                 packagedata = package.collectpackage(self.options.pages.split(","), packageoutput)
         else:
                 packagedata = package.collectpackage(request.rootpage.getPageList(
-                                include_underlay=False, 
-                                filter=lambda name: not wikiutil.isSystemPage(request, name)), 
+                                include_underlay=False,
+                                filter=lambda name: not wikiutil.isSystemPage(request, name)),
                                 packageoutput)
         if packagedata:
             script.fatal(packagedata)
+
--- a/MoinMoin/script/xmlrpc/write.py	Fri Feb 22 21:59:32 2008 +0100
+++ b/MoinMoin/script/xmlrpc/write.py	Fri Feb 22 22:03:12 2008 +0100
@@ -59,9 +59,10 @@
             # but you should definitely access all the results
             # once so that faults are checked and raised
             assert results[0] == 'SUCCESS'
-            assert results[1] == True
+            assert results[1] is True
 
         finally:
             # be nice to the server and clean up the token
             # regardless of what happened
             assert s.deleteAuthToken(token) == 'SUCCESS'
+
--- a/MoinMoin/security/textcha.py	Fri Feb 22 21:59:32 2008 +0100
+++ b/MoinMoin/security/textcha.py	Fri Feb 22 22:03:12 2008 +0100
@@ -1,7 +1,7 @@
 # -*- coding: iso-8859-1 -*-
 """
     MoinMoin - Text CAPTCHAs
-    
+
     This is just asking some (admin configured) questions and
     checking if the answer is as expected. It is up to the wiki
     admin to setup questions that a bot can not easily answer, but
@@ -73,7 +73,7 @@
 
     def _init_qa(self, question=None):
         """ Initialize the question / answer.
-        
+
          @param question: If given, the given question will be used.
                           If None, a new question will be generated.
         """
@@ -107,7 +107,7 @@
                 },
                 'de': {}, # having no questions for 'de' means disabling textchas for 'de'
                 # ...
-            }             
+            }
         """
         return not not self.textchas # we don't want to return the dict
 
@@ -142,8 +142,8 @@
     def render(self, form=None):
         """ Checks if textchas are enabled and returns HTML for one,
             or an empty string if they are not enabled.
-            
-            @return: unicode result html         
+
+            @return: unicode result html
         """
         if self.is_enabled():
             question, given_answer = self._extract_form_values(form)
@@ -168,3 +168,4 @@
             return self.check_answer(given_answer)
         else:
             return True
+
--- a/MoinMoin/server/server_modpython.py	Fri Feb 22 21:59:32 2008 +0100
+++ b/MoinMoin/server/server_modpython.py	Fri Feb 22 22:03:12 2008 +0100
@@ -9,12 +9,12 @@
     Minimal usage:
 
         from MoinMoin.server.server_modpython import CgiConfig, run
-        
+
         class Config(CgiConfig):
             pass
 
         run(Config)
-        
+
     See more options in CgiConfig class.
 
     @copyright: 2006 MoinMoin:ThomasWaldmann
--- a/MoinMoin/server/server_wsgi.py	Fri Feb 22 21:59:32 2008 +0100
+++ b/MoinMoin/server/server_wsgi.py	Fri Feb 22 22:03:12 2008 +0100
@@ -5,7 +5,7 @@
 
     import logging
     from MoinMoin.server.server_wsgi import WsgiConfig, moinmoinApp
-    
+
     class Config(WsgiConfig):
         logPath = 'moin.log' # define your log file here
         #loglevel_file = logging.INFO # if you do not like the default
--- a/MoinMoin/theme/__init__.py	Fri Feb 22 21:59:32 2008 +0100
+++ b/MoinMoin/theme/__init__.py	Fri Feb 22 22:03:12 2008 +0100
@@ -1119,7 +1119,7 @@
 
            If the discussion page doesn't exist and the user
            has no right to create it, show a disabled link.
-	"""
+        """
         _ = self.request.getText
         suppl_name = self.request.cfg.supplementation_page_name
         suppl_name_full = "%s/%s" % (page.page_name, suppl_name)
@@ -1458,12 +1458,12 @@
     def add_msg(self, msg, msg_class="dialog"):
         """ Adds a message to a list which will be used to generate status
         information.
-        
+
         @param msg: additional message
         @param msg_class: html class for the div of the additional message.
         """
         if self._send_title_called:
-            raise Exception("You cannot call add_msg() after send_title()") 
+            raise Exception("You cannot call add_msg() after send_title()")
         self._status.append((msg, msg_class))
 
     # stuff from wikiutil.py
@@ -1493,7 +1493,7 @@
             pagename = keywords.get('pagename', '')
             page = Page(request, pagename)
         if keywords.get('msg', ''):
-            raise DeprecationWarning ("Using send_page(msg=) is deprecated! Use theme.add_msg() instead!")
+            raise DeprecationWarning("Using send_page(msg=) is deprecated! Use theme.add_msg() instead!")
         scriptname = request.getScriptname()
         pagename_quoted = wikiutil.quoteWikinameURL(pagename)
 
--- a/MoinMoin/user.py	Fri Feb 22 21:59:32 2008 +0100
+++ b/MoinMoin/user.py	Fri Feb 22 22:03:12 2008 +0100
@@ -1054,5 +1054,5 @@
                     formatted=False) % {'sitename': self._cfg.sitename or "Wiki"}
         mailok, msg = sendmail.sendmail(self._request, [self.email], subject,
                                     text, mail_from=self._cfg.mail_from)
-        return msg
+        return mailok, msg
 
--- a/MoinMoin/userform/admin.py	Fri Feb 22 21:59:32 2008 +0100
+++ b/MoinMoin/userform/admin.py	Fri Feb 22 22:03:12 2008 +0100
@@ -48,7 +48,7 @@
         if account.disabled:
             enable_disable_link = request.page.link_to(
                                     request, text=_('Enable user'),
-                                    querystr={"action":"userprofile",
+                                    querystr={"action": "userprofile",
                                               "name": account.name,
                                               "key": "disabled",
                                               "val": "0",
@@ -58,7 +58,7 @@
         else:
             enable_disable_link = request.page.link_to(
                                     request, text=_('Disable user'),
-                                    querystr={"action":"userprofile",
+                                    querystr={"action": "userprofile",
                                               "name": account.name,
                                               "key": "disabled",
                                               "val": "1",
--- a/MoinMoin/wikiutil.py	Fri Feb 22 21:59:32 2008 +0100
+++ b/MoinMoin/wikiutil.py	Fri Feb 22 22:03:12 2008 +0100
@@ -16,6 +16,7 @@
 import re
 import time
 import urllib
+import logging
 
 from MoinMoin import config
 from MoinMoin.util import pysupport, lock
@@ -2168,8 +2169,16 @@
 ### Tickets - used by RenamePage and DeletePage
 ########################################################################
 
-def createTicket(request, tm=None):
-    """Create a ticket using a site-specific secret (the config)"""
+def createTicket(request, tm=None, action=None):
+    """ Create a ticket using a site-specific secret (the config)
+
+        @param tm: unix timestamp (optional, uses current time if not given)
+        @param action: action name (optional, uses current action if not given)
+                       Note: if you create a ticket for a form that calls another
+                             action than the current one, you MUST specify the
+                             action you call when posting the form.
+    """
+
     import sha
     if tm is None:
         tm = "%010x" % time.time()
@@ -2180,10 +2189,11 @@
     except:
         pagename = 'None'
 
-    try:
-        action = request.action
-    except:
-        action = 'None'
+    if action is None:
+        try:
+            action = request.action
+        except:
+            action = 'None'
 
 
     ticket = "%s.%s.%s" % (tm, pagename, action)
@@ -2209,12 +2219,15 @@
         timestamp = int(timestamp_str, 16)
     except ValueError:
         # invalid or empty ticket
+        logging.debug("checkTicket: invalid or empty ticket %r" % ticket)
         return False
     now = time.time()
     if timestamp < now - 10 * 3600:
         # we don't accept tickets older than 10h
+        logging.debug("checkTicket: too old ticket, timestamp %r" % timestamp)
         return False
     ourticket = createTicket(request, timestamp_str)
+    logging.debug("checkTicket: returning %r, got %r, expected %r" % (ticket == ourticket, ticket, ourticket))
     return ticket == ourticket