Back to index

moin  1.9.0~rc2
MyPages.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - MyPages - assisting creation of Homepage subpages
00004 
00005     @copyright: 2005-2006 Bastian Blank, Florian Festi, Thomas Waldmann
00006     @license: GNU GPL, see COPYING for details.
00007 """
00008 
00009 def execute(pagename, request):
00010     from MoinMoin import wikiutil
00011     from MoinMoin.Page import Page
00012 
00013     _ = request.getText
00014     thispage = Page(request, pagename)
00015 
00016     if request.user.valid:
00017         username = request.user.name
00018     else:
00019         username = ''
00020 
00021     if not username:
00022         request.theme.add_msg(_('Please log in first.'), "error")
00023         return thispage.send_page()
00024 
00025     userhomewiki = request.cfg.user_homewiki
00026     if userhomewiki != 'Self' and userhomewiki != request.cfg.interwikiname:
00027         interwiki = wikiutil.getInterwikiHomePage(request, username=username)
00028         wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_interwiki(request, *interwiki)
00029         wikiurl = wikiutil.mapURL(request, wikiurl)
00030         homepageurl = wikiutil.join_wiki(wikiurl, wikitail)
00031         request.http_redirect('%s?action=MyPages' % homepageurl)
00032 
00033     homepage = Page(request, username)
00034     if not homepage.exists():
00035         request.theme.add_msg(_('Please first create a homepage before creating additional pages.'), "error")
00036         return homepage.send_page()
00037 
00038     pagecontent = _("""\
00039 You can add some additional sub pages to your already existing homepage here.
00040 
00041 You can choose how open to other readers or writers those pages shall be,
00042 access is controlled by group membership of the corresponding group page.
00043 
00044 Just enter the sub page's name and click on the button to create a new page.
00045 
00046 Before creating access protected pages, make sure the corresponding group page
00047 exists and has the appropriate members in it. Use HomepageGroupsTemplate for creating
00048 the group pages.
00049 
00050 ||'''Add a new personal page:'''||'''Related access control list group:'''||
00051 ||<<NewPage(HomepageReadWritePageTemplate,read-write page,%(username)s)>>||[[%(username)s/ReadWriteGroup]]||
00052 ||<<NewPage(HomepageReadPageTemplate,read-only page,%(username)s)>>||[[%(username)s/ReadGroup]]||
00053 ||<<NewPage(HomepagePrivatePageTemplate,private page,%(username)s)>>||%(username)s only||
00054 
00055 """)
00056     pagecontent = pagecontent % locals()
00057 
00058     pagecontent = pagecontent.replace('\n', '\r\n')
00059 
00060     from MoinMoin.parser.text_moin_wiki import Parser as WikiParser
00061 
00062     # This action generate data using the user language
00063     request.setContentLanguage(request.lang)
00064     request.theme.send_title(_('MyPages management'), page=homepage)
00065 
00066     parser = WikiParser(pagecontent, request)
00067     p = Page(request, "$$$")
00068     request.formatter.setPage(p)
00069     parser.format(request.formatter)
00070 
00071     # Start content - IMPORTANT - without content div, there is no direction support!
00072     request.write(request.formatter.startContent("content"))
00073 
00074     request.write(request.formatter.endContent())
00075     request.theme.send_footer(homepage.page_name)
00076     request.theme.send_closing_html()
00077