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

Download

   1 # HG changeset patch
   2 # User Paul Boddie <paul@boddie.org.uk>
   3 # Date 1299375137 -3600
   4 # Node ID 1a333e78214f2d26882cee1f2d463e04e6d763df
   5 # Parent  77bea805221c0b3de5f9af9b49e0bbae0af7e469
   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 
  13 diff -r 77bea805221c -r 1a333e78214f MoinMoin/Page.py
  14 --- a/MoinMoin/Page.py	Thu Mar 03 21:01:51 2011 +0100
  15 +++ b/MoinMoin/Page.py	Sun Mar 06 02:32:17 2011 +0100
  16 @@ -1138,8 +1138,14 @@
  17  
  18                  html_head = ''
  19                  if request.cfg.openid_server_enabled:
  20 -                    openid_username = self.page_name
  21 -                    userid = user.getUserId(request, openid_username)
  22 +                    pagenames = wikiutil.splitPageName(self.page_name)
  23 +                    prefix = wikiutil.joinPageNames(*pagenames[:-1])
  24 +                    if prefix == request.cfg.user_homeprefix:
  25 +                        openid_username = pagenames[-1]
  26 +                        userid = user.getUserId(request, openid_username)
  27 +                    else:
  28 +                        openid_username = None
  29 +                        userid = None
  30  
  31                      if userid is None and 'openid.user' in self.pi:
  32                          openid_username = self.pi['openid.user']
  33 @@ -1375,7 +1381,11 @@
  34          _ = request.getText
  35  
  36          if special_type == 'missing':
  37 -            if request.user.valid and request.user.name == self.page_name and \
  38 +            pagenames = wikiutil.splitPageName(self.page_name)
  39 +            prefix = wikiutil.joinPageNames(*pagenames[:-1])
  40 +
  41 +            if request.user.valid and request.user.name == pagenames[-1] and \
  42 +               request.cfg.user_homeprefix == prefix and \
  43                 request.cfg.user_homewiki in ('Self', request.cfg.interwikiname):
  44                  page = wikiutil.getLocalizedPage(request, 'MissingHomePage')
  45              else:
  46 diff -r 77bea805221c -r 1a333e78214f MoinMoin/action/MyPages.py
  47 --- a/MoinMoin/action/MyPages.py	Thu Mar 03 21:01:51 2011 +0100
  48 +++ b/MoinMoin/action/MyPages.py	Sun Mar 06 02:32:17 2011 +0100
  49 @@ -30,7 +30,7 @@
  50          homepageurl = wikiutil.join_wiki(wikiurl, wikitail)
  51          request.http_redirect('%s?action=MyPages' % homepageurl)
  52  
  53 -    homepage = Page(request, username)
  54 +    homepage = Page(request, wikiutil.joinPageNames(request.cfg.user_homeprefix, username))
  55      if not homepage.exists():
  56          request.theme.add_msg(_('Please first create a homepage before creating additional pages.'), "error")
  57          return homepage.send_page()
  58 diff -r 77bea805221c -r 1a333e78214f MoinMoin/action/serveopenid.py
  59 --- a/MoinMoin/action/serveopenid.py	Thu Mar 03 21:01:51 2011 +0100
  60 +++ b/MoinMoin/action/serveopenid.py	Sun Mar 06 02:32:17 2011 +0100
  61 @@ -175,7 +175,13 @@
  62          request = self.request
  63          form = request.form
  64  
  65 -        username = request.page.page_name
  66 +        pagenames = wikiutil.splitPageName(request.page.page_name)
  67 +        prefix = wikiutil.joinPageNames(*pagenames[:-1])
  68 +        if prefix == request.cfg.user_homeprefix:
  69 +            username = pagenames[-1]
  70 +        else:
  71 +            username = None
  72 +
  73          if 'openid.user' in request.page.pi:
  74              username = request.page.pi['openid.user']
  75  
  76 diff -r 77bea805221c -r 1a333e78214f MoinMoin/config/multiconfig.py
  77 --- a/MoinMoin/config/multiconfig.py	Thu Mar 03 21:01:51 2011 +0100
  78 +++ b/MoinMoin/config/multiconfig.py	Sun Mar 06 02:32:17 2011 +0100
  79 @@ -1117,6 +1117,8 @@
  80  
  81        ('homewiki', u'Self',
  82         "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."),
  83 +      ('homeprefix', u'',
  84 +       "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."),
  85  
  86        ('checkbox_fields',
  87         [
  88 diff -r 77bea805221c -r 1a333e78214f MoinMoin/security/autoadmin.py
  89 --- a/MoinMoin/security/autoadmin.py	Thu Mar 03 21:01:51 2011 +0100
  90 +++ b/MoinMoin/security/autoadmin.py	Sun Mar 06 02:32:17 2011 +0100
  91 @@ -62,6 +62,7 @@
  92  from MoinMoin.security import Permissions
  93  from MoinMoin.Page import Page
  94  from MoinMoin.PageEditor import PageEditor
  95 +from MoinMoin import wikiutil
  96  
  97  class SecurityPolicy(Permissions):
  98      """ Extend the default security policy with autoadmin feature """
  99 @@ -72,9 +73,16 @@
 100              has_member = request.dicts.has_member
 101              username = request.user.name
 102              pagename = request.page.page_name
 103 +
 104 +            # test admin rights on the user's own home page
 105 +            homewiki, homepage = wikiutil.getInterwikiHomePage(request, username)
 106 +            if homewiki == "Self" and \
 107 +               (pagename == homepage or wikiutil.isSubPage(pagename, homepage)) and \
 108 +               has_member('AutoAdminGroup', username):
 109 +                return True
 110 +
 111 +            # test admin rights for the user on group pages
 112              mainpage = pagename.split('/')[0]
 113 -            if username == mainpage and has_member('AutoAdminGroup', username):
 114 -                return True
 115              groupname = "%s/AdminGroup" % mainpage
 116              if has_member(groupname, username) and has_member('AutoAdminGroup', groupname):
 117                  return True
 118 @@ -86,11 +94,12 @@
 119          request = self.request
 120          username = request.user.name
 121          pagename = editor.page_name
 122 +        homewiki, homepage = wikiutil.getInterwikiHomePage(request, username)
 123  
 124 -        if grouppage_autocreate and username == pagename:
 125 +        if grouppage_autocreate and homewiki == "Self" and pagename == homepage:
 126              # create group pages when a user saves his own homepage
 127              for page in grouppages:
 128 -                grouppagename = "%s/%s" % (username, page)
 129 +                grouppagename = "%s/%s" % (homepage, page)
 130                  grouppage = Page(request, grouppagename)
 131                  if not grouppage.exists():
 132                      text = """\
 133 diff -r 77bea805221c -r 1a333e78214f MoinMoin/wikiutil.py
 134 --- a/MoinMoin/wikiutil.py	Thu Mar 03 21:01:51 2011 +0100
 135 +++ b/MoinMoin/wikiutil.py	Sun Mar 06 02:32:17 2011 +0100
 136 @@ -811,7 +811,7 @@
 137      # known user?
 138      if username:
 139          # Return home page
 140 -        page = Page(request, username)
 141 +        page = Page(request, joinPageNames(request.cfg.user_homeprefix, username))
 142          if page.exists():
 143              return page
 144  
 145 @@ -843,8 +843,40 @@
 146      if homewiki == request.cfg.interwikiname:
 147          homewiki = u'Self'
 148  
 149 -    return homewiki, username
 150 +    return homewiki, joinPageNames(request.cfg.user_homeprefix, username)
 151  
 152 +def joinPageNames(*pagenames):
 153 +    """
 154 +    Join the given page names to construct a complete absolute page name.
 155 +
 156 +    @param pagenames: the page names which construct the complete name
 157 +    @return: the absolute page name
 158 +    """
 159 +
 160 +    pagenames = [name for name in pagenames if name]
 161 +    return u'/'.join(pagenames)
 162 +
 163 +def splitPageName(pagename):
 164 +    """
 165 +    Split the given page name into a hierarchy of pages.
 166 +
 167 +    @param pagename: an absolute page name with potentially many parts
 168 +    @return: a list of page names
 169 +    """
 170 +
 171 +    return pagename.split(u'/')
 172 +
 173 +def isSubPage(pagename, parent):
 174 +    """
 175 +    Return whether the given page name is a subpage of the potential parent
 176 +    page.
 177 +
 178 +    @param pagename: a page name to be tested as a potential subpage
 179 +    @param parent: a potential parent page
 180 +    @return: a boolean value indicating whether pagename is a subpage of parent
 181 +    """
 182 +
 183 +    return pagename.startswith("%s/" % parent)
 184  
 185  def AbsPageName(context, pagename):
 186      """
 187 # HG changeset patch
 188 # User Paul Boddie <paul@boddie.org.uk>
 189 # Date 1303151702 -7200
 190 # Node ID 66c0ff302aacec754b2cc994e3b1714c85d28cfc
 191 # Parent  1a333e78214f2d26882cee1f2d463e04e6d763df
 192 Handle a result of None, possible when running a maintenance script.
 193 
 194 diff -r 1a333e78214f -r 66c0ff302aac MoinMoin/security/autoadmin.py
 195 --- a/MoinMoin/security/autoadmin.py	Sun Mar 06 02:32:17 2011 +0100
 196 +++ b/MoinMoin/security/autoadmin.py	Mon Apr 18 20:35:02 2011 +0200
 197 @@ -94,20 +94,23 @@
 198          request = self.request
 199          username = request.user.name
 200          pagename = editor.page_name
 201 -        homewiki, homepage = wikiutil.getInterwikiHomePage(request, username)
 202 +        homedetails = wikiutil.getInterwikiHomePage(request, username)
 203  
 204 -        if grouppage_autocreate and homewiki == "Self" and pagename == homepage:
 205 -            # create group pages when a user saves his own homepage
 206 -            for page in grouppages:
 207 -                grouppagename = "%s/%s" % (homepage, page)
 208 -                grouppage = Page(request, grouppagename)
 209 -                if not grouppage.exists():
 210 -                    text = """\
 211 +        if homedetails is not None:
 212 +            homewiki, homepage = homedetails
 213 +
 214 +            if grouppage_autocreate and homewiki == "Self" and pagename == homepage:
 215 +                # create group pages when a user saves his own homepage
 216 +                for page in grouppages:
 217 +                    grouppagename = "%s/%s" % (homepage, page)
 218 +                    grouppage = Page(request, grouppagename)
 219 +                    if not grouppage.exists():
 220 +                        text = """\
 221  #acl %(username)s:read,write,delete,revert
 222   * %(username)s
 223  """ % locals()
 224 -                    editor = PageEditor(request, grouppagename)
 225 -                    editor._write_file(text)
 226 +                        editor = PageEditor(request, grouppagename)
 227 +                        editor._write_file(text)
 228  
 229          parts = pagename.split('/')
 230          if len(parts) == 2:

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.