changeset 2927:51b6cbc64dcb

redirect to page%20name for page_name when the former exists and the latter doesn't
author Johannes Berg <johannes AT sipsolutions DOT net>
date Mon, 29 Oct 2007 11:06:25 +0100
parents 6efbf2fbce6c
children 263d4f8009f9
files MoinMoin/request/__init__.py
diffstat 1 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/request/__init__.py	Mon Oct 29 10:39:50 2007 +0100
+++ b/MoinMoin/request/__init__.py	Mon Oct 29 11:06:25 2007 +0100
@@ -11,6 +11,7 @@
 import logging
 import Cookie
 
+from MoinMoin.Page import Page
 from MoinMoin import config, wikiutil, user, caching, error
 from MoinMoin.config import multiconfig
 from MoinMoin.support.python_compatibility import set
@@ -1147,6 +1148,16 @@
             theme_name = self.user.theme_name
         self.loadTheme(theme_name)
 
+    def _try_redirect_spaces_page(self, pagename):
+        if '_' in pagename and not self.page.exists():
+            pname = pagename.replace('_', ' ')
+            pg = Page(self, pname)
+            if pg.exists():
+                url = pg.url(self, relative=False)
+                self.http_redirect(url)
+                return True
+        return False
+
     def run(self):
         # Exit now if __init__ failed or request is forbidden
         if self.failed or self.forbidden or self._auth_redirected:
@@ -1156,8 +1167,6 @@
         _ = self.getText
         self.clock.start('run')
 
-        from MoinMoin.Page import Page
-
         self.initTheme()
 
         action_name = self.action
@@ -1229,6 +1238,8 @@
                     self.page = wikiutil.getFrontPage(self)
                 else:
                     self.page = Page(self, pagename)
+                    if self._try_redirect_spaces_page(pagename):
+                        return self.finish()
 
                 msg = None
                 # Complain about unknown actions