Created
January 16, 2014 00:02
-
-
Save alexclifford/8447264 to your computer and use it in GitHub Desktop.
Adding support for home page namespaces in MoinMoin (see diff for full description)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# HG changeset patch | |
# User Paul Boddie <[email protected]> | |
# Date 1318183386 -7200 | |
# Node ID 51e0575a1ee9907dd24da95c2951fce145a36518 | |
# Parent 89882824b375c0afe55433de0e5ccc081a740c82 | |
Added support for home page namespaces other than at the root of a site by | |
employing a homeprefix setting. | |
Changed the serveopenid action, autoadmin security policy, MyPages action and | |
the OpenID identity advertising in the Page class to work with home pages that | |
have a non-empty homeprefix. | |
Added various utility functions to work with page names. | |
Handle a result of None, possible when running a maintenance script or when no | |
user is logged in. | |
(Consolidated patch from 5782, 5816 and 5818.) | |
diff -r 89882824b375 -r 51e0575a1ee9 MoinMoin/Page.py | |
--- a/MoinMoin/Page.py Wed Aug 03 00:07:16 2011 +0200 | |
+++ b/MoinMoin/Page.py Sun Oct 09 20:03:06 2011 +0200 | |
@@ -1137,8 +1137,14 @@ | |
html_head = '' | |
if request.cfg.openid_server_enabled: | |
- openid_username = self.page_name | |
- userid = user.getUserId(request, openid_username) | |
+ pagenames = wikiutil.splitPageName(self.page_name) | |
+ prefix = wikiutil.joinPageNames(*pagenames[:-1]) | |
+ if prefix == request.cfg.user_homeprefix: | |
+ openid_username = pagenames[-1] | |
+ userid = user.getUserId(request, openid_username) | |
+ else: | |
+ openid_username = None | |
+ userid = None | |
if userid is None and 'openid.user' in self.pi: | |
openid_username = self.pi['openid.user'] | |
@@ -1373,7 +1379,11 @@ | |
_ = request.getText | |
if special_type == 'missing': | |
- if request.user.valid and request.user.name == self.page_name and \ | |
+ pagenames = wikiutil.splitPageName(self.page_name) | |
+ prefix = wikiutil.joinPageNames(*pagenames[:-1]) | |
+ | |
+ if request.user.valid and request.user.name == pagenames[-1] and \ | |
+ request.cfg.user_homeprefix == prefix and \ | |
request.cfg.user_homewiki in ('Self', request.cfg.interwikiname): | |
page = wikiutil.getLocalizedPage(request, 'MissingHomePage') | |
else: | |
diff -r 89882824b375 -r 51e0575a1ee9 MoinMoin/action/MyPages.py | |
--- a/MoinMoin/action/MyPages.py Wed Aug 03 00:07:16 2011 +0200 | |
+++ b/MoinMoin/action/MyPages.py Sun Oct 09 20:03:06 2011 +0200 | |
@@ -30,7 +30,7 @@ | |
homepageurl = wikiutil.join_wiki(wikiurl, wikitail) | |
request.http_redirect('%s?action=MyPages' % homepageurl) | |
- homepage = Page(request, username) | |
+ homepage = Page(request, wikiutil.joinPageNames(request.cfg.user_homeprefix, username)) | |
if not homepage.exists(): | |
request.theme.add_msg(_('Please first create a homepage before creating additional pages.'), "error") | |
return homepage.send_page() | |
diff -r 89882824b375 -r 51e0575a1ee9 MoinMoin/action/serveopenid.py | |
--- a/MoinMoin/action/serveopenid.py Wed Aug 03 00:07:16 2011 +0200 | |
+++ b/MoinMoin/action/serveopenid.py Sun Oct 09 20:03:06 2011 +0200 | |
@@ -172,7 +172,13 @@ | |
request = self.request | |
form = request.values | |
- username = request.page.page_name | |
+ pagenames = wikiutil.splitPageName(request.page.page_name) | |
+ prefix = wikiutil.joinPageNames(*pagenames[:-1]) | |
+ if prefix == request.cfg.user_homeprefix: | |
+ username = pagenames[-1] | |
+ else: | |
+ username = None | |
+ | |
if 'openid.user' in request.page.pi: | |
username = request.page.pi['openid.user'] | |
diff -r 89882824b375 -r 51e0575a1ee9 MoinMoin/config/multiconfig.py | |
--- a/MoinMoin/config/multiconfig.py Wed Aug 03 00:07:16 2011 +0200 | |
+++ b/MoinMoin/config/multiconfig.py Sun Oct 09 20:03:06 2011 +0200 | |
@@ -1171,6 +1171,8 @@ | |
('homewiki', u'Self', | |
"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."), | |
+ ('homeprefix', u'', | |
+ "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."), | |
('checkbox_fields', | |
[ | |
diff -r 89882824b375 -r 51e0575a1ee9 MoinMoin/security/autoadmin.py | |
--- a/MoinMoin/security/autoadmin.py Wed Aug 03 00:07:16 2011 +0200 | |
+++ b/MoinMoin/security/autoadmin.py Sun Oct 09 20:03:06 2011 +0200 | |
@@ -62,6 +62,7 @@ | |
from MoinMoin.security import Permissions | |
from MoinMoin.Page import Page | |
from MoinMoin.PageEditor import PageEditor | |
+from MoinMoin import wikiutil | |
class SecurityPolicy(Permissions): | |
""" Extend the default security policy with autoadmin feature """ | |
@@ -72,9 +73,20 @@ | |
groups = request.groups | |
username = request.user.name | |
pagename = request.page.page_name | |
+ | |
+ # test admin rights on the user's own home page | |
+ homedetails = wikiutil.getInterwikiHomePage(request, username) | |
+ | |
+ if homedetails is not None: | |
+ homewiki, homepage = homedetails | |
+ | |
+ if homewiki == "Self" and \ | |
+ (pagename == homepage or wikiutil.isSubPage(pagename, homepage)) and \ | |
+ username in groups.get(u'AutoAdminGroup', []): | |
+ return True | |
+ | |
+ # test admin rights for the user on group pages | |
mainpage = pagename.split('/')[0] | |
- if username == mainpage and username in groups.get(u'AutoAdminGroup', []): | |
- return True | |
group_name = "%s/AdminGroup" % mainpage | |
if (username in groups.get(group_name, []) and | |
group_name in groups.get(u'AutoAdminGroup', [])): | |
@@ -87,19 +99,23 @@ | |
request = self.request | |
username = request.user.name | |
pagename = editor.page_name | |
+ homedetails = wikiutil.getInterwikiHomePage(request, username) | |
- if grouppage_autocreate and username == pagename: | |
- # create group pages when a user saves his own homepage | |
- for page in grouppages: | |
- grouppagename = "%s/%s" % (username, page) | |
- grouppage = Page(request, grouppagename) | |
- if not grouppage.exists(): | |
- text = """\ | |
+ if homedetails is not None: | |
+ homewiki, homepage = homedetails | |
+ | |
+ if grouppage_autocreate and homewiki == "Self" and pagename == homepage: | |
+ # create group pages when a user saves his own homepage | |
+ for page in grouppages: | |
+ grouppagename = "%s/%s" % (homepage, page) | |
+ grouppage = Page(request, grouppagename) | |
+ if not grouppage.exists(): | |
+ text = """\ | |
#acl %(username)s:read,write,delete,revert | |
* %(username)s | |
""" % locals() | |
- editor = PageEditor(request, grouppagename) | |
- editor._write_file(text) | |
+ editor = PageEditor(request, grouppagename) | |
+ editor._write_file(text) | |
parts = pagename.split('/') | |
if len(parts) == 2: | |
diff -r 89882824b375 -r 51e0575a1ee9 MoinMoin/wikiutil.py | |
--- a/MoinMoin/wikiutil.py Wed Aug 03 00:07:16 2011 +0200 | |
+++ b/MoinMoin/wikiutil.py Sun Oct 09 20:03:06 2011 +0200 | |
@@ -737,7 +737,7 @@ | |
# known user? | |
if username: | |
# Return home page | |
- page = Page(request, username) | |
+ page = Page(request, joinPageNames(request.cfg.user_homeprefix, username)) | |
if page.exists(): | |
return page | |
@@ -769,8 +769,40 @@ | |
if homewiki == request.cfg.interwikiname: | |
homewiki = u'Self' | |
- return homewiki, username | |
+ return homewiki, joinPageNames(request.cfg.user_homeprefix, username) | |
+def joinPageNames(*pagenames): | |
+ """ | |
+ Join the given page names to construct a complete absolute page name. | |
+ | |
+ @param pagenames: the page names which construct the complete name | |
+ @return: the absolute page name | |
+ """ | |
+ | |
+ pagenames = [name for name in pagenames if name] | |
+ return u'/'.join(pagenames) | |
+ | |
+def splitPageName(pagename): | |
+ """ | |
+ Split the given page name into a hierarchy of pages. | |
+ | |
+ @param pagename: an absolute page name with potentially many parts | |
+ @return: a list of page names | |
+ """ | |
+ | |
+ return pagename.split(u'/') | |
+ | |
+def isSubPage(pagename, parent): | |
+ """ | |
+ Return whether the given page name is a subpage of the potential parent | |
+ page. | |
+ | |
+ @param pagename: a page name to be tested as a potential subpage | |
+ @param parent: a potential parent page | |
+ @return: a boolean value indicating whether pagename is a subpage of parent | |
+ """ | |
+ | |
+ return pagename.startswith("%s/" % parent) | |
def AbsPageName(context, pagename): | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment