Attachment 'patch-homeprefix-setting.diff'
Download 1 # HG changeset patch
2 # User Paul Boddie <paul@boddie.org.uk>
3 # Date 1299376586 -3600
4 # Node ID 3ba458f6a6bd0c808b91a4603ff25cf021ea9d46
5 # Parent 173c3623377ba8ef4d21edb4c1a7f331e75cdbc7
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 173c3623377b -r 3ba458f6a6bd MoinMoin/Page.py
14 --- a/MoinMoin/Page.py Sat Feb 26 21:28:24 2011 +0100
15 +++ b/MoinMoin/Page.py Sun Mar 06 02:56:26 2011 +0100
16 @@ -1137,8 +1137,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 @@ -1373,7 +1379,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 173c3623377b -r 3ba458f6a6bd MoinMoin/action/MyPages.py
47 --- a/MoinMoin/action/MyPages.py Sat Feb 26 21:28:24 2011 +0100
48 +++ b/MoinMoin/action/MyPages.py Sun Mar 06 02:56:26 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 173c3623377b -r 3ba458f6a6bd MoinMoin/action/serveopenid.py
59 --- a/MoinMoin/action/serveopenid.py Sat Feb 26 21:28:24 2011 +0100
60 +++ b/MoinMoin/action/serveopenid.py Sun Mar 06 02:56:26 2011 +0100
61 @@ -172,7 +172,13 @@
62 request = self.request
63 form = request.values
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 173c3623377b -r 3ba458f6a6bd MoinMoin/config/multiconfig.py
77 --- a/MoinMoin/config/multiconfig.py Sat Feb 26 21:28:24 2011 +0100
78 +++ b/MoinMoin/config/multiconfig.py Sun Mar 06 02:56:26 2011 +0100
79 @@ -1171,6 +1171,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 173c3623377b -r 3ba458f6a6bd MoinMoin/security/autoadmin.py
89 --- a/MoinMoin/security/autoadmin.py Sat Feb 26 21:28:24 2011 +0100
90 +++ b/MoinMoin/security/autoadmin.py Sun Mar 06 02:56:26 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 groups = request.groups
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 + username in groups.get(u'AutoAdminGroup', []):
109 + return True
110 +
111 + # test admin rights for the user on group pages
112 mainpage = pagename.split('/')[0]
113 - if username == mainpage and username in groups.get(u'AutoAdminGroup', []):
114 - return True
115 group_name = "%s/AdminGroup" % mainpage
116 if (username in groups.get(group_name, []) and
117 group_name in groups.get(u'AutoAdminGroup', [])):
118 @@ -87,11 +95,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 173c3623377b -r 3ba458f6a6bd MoinMoin/wikiutil.py
134 --- a/MoinMoin/wikiutil.py Sat Feb 26 21:28:24 2011 +0100
135 +++ b/MoinMoin/wikiutil.py Sun Mar 06 02:56:26 2011 +0100
136 @@ -737,7 +737,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 @@ -769,8 +769,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 1303152467 -7200
190 # Node ID 1909f8c695f2092d16fe590de87d886fa5c3601b
191 # Parent 3ba458f6a6bd0c808b91a4603ff25cf021ea9d46
192 Handle a result of None, possible when running a maintenance script.
193
194 diff -r 3ba458f6a6bd -r 1909f8c695f2 MoinMoin/security/autoadmin.py
195 --- a/MoinMoin/security/autoadmin.py Sun Mar 06 02:56:26 2011 +0100
196 +++ b/MoinMoin/security/autoadmin.py Mon Apr 18 20:47:47 2011 +0200
197 @@ -95,20 +95,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.You are not allowed to attach a file to this page.