Attachment 'patch-homeprefix-setting-1.8-4540_0f57c22a22e9.diff'

Download

   1 # HG changeset patch
   2 # User Paul Boddie <paul@boddie.org.uk>
   3 # Date 1318182665 -7200
   4 # Node ID 0f57c22a22e960d3df5df6374fe9b4d202ab4c06
   5 # Parent  8d94ac6b5587a8b7946148f24f93003648679d5f
   6 Added support for home page namespaces other than at the root of a site by
   7 employing a homeprefix setting.
   8 Changed the serveopenid action, autoadmin security policy, MyPages action and
   9 the OpenID identity advertising in the Page class to work with home pages that
  10 have a non-empty homeprefix.
  11 Added various utility functions to work with page names.
  12 Handle a result of None, possible when running a maintenance script or when no
  13 user is logged in.
  14 (Consolidated patch from 4530, 4536 and 4538.)
  15 
  16 diff -r 8d94ac6b5587 -r 0f57c22a22e9 MoinMoin/Page.py
  17 --- a/MoinMoin/Page.py	Sat Mar 26 20:57:11 2011 +0100
  18 +++ b/MoinMoin/Page.py	Sun Oct 09 19:51:05 2011 +0200
  19 @@ -1138,8 +1138,14 @@
  20  
  21                  html_head = ''
  22                  if request.cfg.openid_server_enabled:
  23 -                    openid_username = self.page_name
  24 -                    userid = user.getUserId(request, openid_username)
  25 +                    pagenames = wikiutil.splitPageName(self.page_name)
  26 +                    prefix = wikiutil.joinPageNames(*pagenames[:-1])
  27 +                    if prefix == request.cfg.user_homeprefix:
  28 +                        openid_username = pagenames[-1]
  29 +                        userid = user.getUserId(request, openid_username)
  30 +                    else:
  31 +                        openid_username = None
  32 +                        userid = None
  33  
  34                      if userid is None and 'openid.user' in self.pi:
  35                          openid_username = self.pi['openid.user']
  36 @@ -1375,7 +1381,11 @@
  37          _ = request.getText
  38  
  39          if special_type == 'missing':
  40 -            if request.user.valid and request.user.name == self.page_name and \
  41 +            pagenames = wikiutil.splitPageName(self.page_name)
  42 +            prefix = wikiutil.joinPageNames(*pagenames[:-1])
  43 +
  44 +            if request.user.valid and request.user.name == pagenames[-1] and \
  45 +               request.cfg.user_homeprefix == prefix and \
  46                 request.cfg.user_homewiki in ('Self', request.cfg.interwikiname):
  47                  page = wikiutil.getLocalizedPage(request, 'MissingHomePage')
  48              else:
  49 diff -r 8d94ac6b5587 -r 0f57c22a22e9 MoinMoin/action/MyPages.py
  50 --- a/MoinMoin/action/MyPages.py	Sat Mar 26 20:57:11 2011 +0100
  51 +++ b/MoinMoin/action/MyPages.py	Sun Oct 09 19:51:05 2011 +0200
  52 @@ -30,7 +30,7 @@
  53          homepageurl = wikiutil.join_wiki(wikiurl, wikitail)
  54          request.http_redirect('%s?action=MyPages' % homepageurl)
  55  
  56 -    homepage = Page(request, username)
  57 +    homepage = Page(request, wikiutil.joinPageNames(request.cfg.user_homeprefix, username))
  58      if not homepage.exists():
  59          request.theme.add_msg(_('Please first create a homepage before creating additional pages.'), "error")
  60          return homepage.send_page()
  61 diff -r 8d94ac6b5587 -r 0f57c22a22e9 MoinMoin/action/serveopenid.py
  62 --- a/MoinMoin/action/serveopenid.py	Sat Mar 26 20:57:11 2011 +0100
  63 +++ b/MoinMoin/action/serveopenid.py	Sun Oct 09 19:51:05 2011 +0200
  64 @@ -175,7 +175,13 @@
  65          request = self.request
  66          form = request.form
  67  
  68 -        username = request.page.page_name
  69 +        pagenames = wikiutil.splitPageName(request.page.page_name)
  70 +        prefix = wikiutil.joinPageNames(*pagenames[:-1])
  71 +        if prefix == request.cfg.user_homeprefix:
  72 +            username = pagenames[-1]
  73 +        else:
  74 +            username = None
  75 +
  76          if 'openid.user' in request.page.pi:
  77              username = request.page.pi['openid.user']
  78  
  79 diff -r 8d94ac6b5587 -r 0f57c22a22e9 MoinMoin/config/multiconfig.py
  80 --- a/MoinMoin/config/multiconfig.py	Sat Mar 26 20:57:11 2011 +0100
  81 +++ b/MoinMoin/config/multiconfig.py	Sun Oct 09 19:51:05 2011 +0200
  82 @@ -1117,6 +1117,8 @@
  83  
  84        ('homewiki', u'Self',
  85         "interwiki name of the wiki where the user home pages are located [Unicode] - useful if you have ''many'' users. You could even link to nonwiki \"user pages\" if the wiki username is in the target URL."),
  86 +      ('homeprefix', u'',
  87 +       "name of the page under which user home pages are stored [Unicode] - this page can itself be a subpage of another page; set to the empty string for the normal top-level home page behaviour."),
  88  
  89        ('checkbox_fields',
  90         [
  91 diff -r 8d94ac6b5587 -r 0f57c22a22e9 MoinMoin/security/autoadmin.py
  92 --- a/MoinMoin/security/autoadmin.py	Sat Mar 26 20:57:11 2011 +0100
  93 +++ b/MoinMoin/security/autoadmin.py	Sun Oct 09 19:51:05 2011 +0200
  94 @@ -62,6 +62,7 @@
  95  from MoinMoin.security import Permissions
  96  from MoinMoin.Page import Page
  97  from MoinMoin.PageEditor import PageEditor
  98 +from MoinMoin import wikiutil
  99  
 100  class SecurityPolicy(Permissions):
 101      """ Extend the default security policy with autoadmin feature """
 102 @@ -72,9 +73,20 @@
 103              has_member = request.dicts.has_member
 104              username = request.user.name
 105              pagename = request.page.page_name
 106 +
 107 +            # test admin rights on the user's own home page
 108 +            homedetails = wikiutil.getInterwikiHomePage(request, username)
 109 +
 110 +            if homedetails is not None:
 111 +                homewiki, homepage = homedetails
 112 +
 113 +                if homewiki == "Self" and \
 114 +                   (pagename == homepage or wikiutil.isSubPage(pagename, homepage)) and \
 115 +                   has_member('AutoAdminGroup', username):
 116 +                    return True
 117 +
 118 +            # test admin rights for the user on group pages
 119              mainpage = pagename.split('/')[0]
 120 -            if username == mainpage and has_member('AutoAdminGroup', username):
 121 -                return True
 122              groupname = "%s/AdminGroup" % mainpage
 123              if has_member(groupname, username) and has_member('AutoAdminGroup', groupname):
 124                  return True
 125 @@ -86,19 +98,23 @@
 126          request = self.request
 127          username = request.user.name
 128          pagename = editor.page_name
 129 +        homedetails = wikiutil.getInterwikiHomePage(request, username)
 130  
 131 -        if grouppage_autocreate and username == pagename:
 132 -            # create group pages when a user saves his own homepage
 133 -            for page in grouppages:
 134 -                grouppagename = "%s/%s" % (username, page)
 135 -                grouppage = Page(request, grouppagename)
 136 -                if not grouppage.exists():
 137 -                    text = """\
 138 +        if homedetails is not None:
 139 +            homewiki, homepage = homedetails
 140 +
 141 +            if grouppage_autocreate and homewiki == "Self" and pagename == homepage:
 142 +                # create group pages when a user saves his own homepage
 143 +                for page in grouppages:
 144 +                    grouppagename = "%s/%s" % (homepage, page)
 145 +                    grouppage = Page(request, grouppagename)
 146 +                    if not grouppage.exists():
 147 +                        text = """\
 148  #acl %(username)s:read,write,delete,revert
 149   * %(username)s
 150  """ % locals()
 151 -                    editor = PageEditor(request, grouppagename)
 152 -                    editor._write_file(text)
 153 +                        editor = PageEditor(request, grouppagename)
 154 +                        editor._write_file(text)
 155  
 156          parts = pagename.split('/')
 157          if len(parts) == 2:
 158 diff -r 8d94ac6b5587 -r 0f57c22a22e9 MoinMoin/wikiutil.py
 159 --- a/MoinMoin/wikiutil.py	Sat Mar 26 20:57:11 2011 +0100
 160 +++ b/MoinMoin/wikiutil.py	Sun Oct 09 19:51:05 2011 +0200
 161 @@ -811,7 +811,7 @@
 162      # known user?
 163      if username:
 164          # Return home page
 165 -        page = Page(request, username)
 166 +        page = Page(request, joinPageNames(request.cfg.user_homeprefix, username))
 167          if page.exists():
 168              return page
 169  
 170 @@ -843,8 +843,40 @@
 171      if homewiki == request.cfg.interwikiname:
 172          homewiki = u'Self'
 173  
 174 -    return homewiki, username
 175 +    return homewiki, joinPageNames(request.cfg.user_homeprefix, username)
 176  
 177 +def joinPageNames(*pagenames):
 178 +    """
 179 +    Join the given page names to construct a complete absolute page name.
 180 +
 181 +    @param pagenames: the page names which construct the complete name
 182 +    @return: the absolute page name
 183 +    """
 184 +
 185 +    pagenames = [name for name in pagenames if name]
 186 +    return u'/'.join(pagenames)
 187 +
 188 +def splitPageName(pagename):
 189 +    """
 190 +    Split the given page name into a hierarchy of pages.
 191 +
 192 +    @param pagename: an absolute page name with potentially many parts
 193 +    @return: a list of page names
 194 +    """
 195 +
 196 +    return pagename.split(u'/')
 197 +
 198 +def isSubPage(pagename, parent):
 199 +    """
 200 +    Return whether the given page name is a subpage of the potential parent
 201 +    page.
 202 +
 203 +    @param pagename: a page name to be tested as a potential subpage
 204 +    @param parent: a potential parent page
 205 +    @return: a boolean value indicating whether pagename is a subpage of parent
 206 +    """
 207 +
 208 +    return pagename.startswith("%s/" % parent)
 209  
 210  def AbsPageName(context, pagename):
 211      """

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2011-10-09 18:07:46, 8.8 KB) [[attachment:patch-homeprefix-setting-1.8-4540_0f57c22a22e9.diff]]
  • [get | view] (2011-04-18 18:49:22, 9.8 KB) [[attachment:patch-homeprefix-setting-1.8.diff]]
  • [get | view] (2011-10-09 18:08:04, 8.8 KB) [[attachment:patch-homeprefix-setting-5819_51e0575a1ee9.diff]]
  • [get | view] (2011-04-18 18:48:45, 9.8 KB) [[attachment:patch-homeprefix-setting.diff]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.