~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/action/newpage.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mfrom: (0.9.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080622211713-fpo2zrq3s5dfecxg
Tags: 1.7.0-3
Simplify /etc/moin/wikilist format: "USER URL" (drop unneeded middle
CONFIG_DIR that was wrongly advertised as DATA_DIR).  Make
moin-mass-migrate handle both formats and warn about deprecation of
the old one.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
    Create a new page with optional template. Can be used with NewPage.py macro.
5
5
 
6
 
    @copyright: 2004 Vito Miliano (vito_moinnewpagewithtemplate@perilith.com)
7
 
    @copyright: 2004 by Nir Soffer <nirs@freeshell.org>
8
 
    @copyright: 2004 Alexander Schremmer <alex AT alexanderweb DOT de>
 
6
    @copyright: 2004 Vito Miliano (vito_moinnewpagewithtemplate@perilith.com),
 
7
                2004 Nir Soffer <nirs@freeshell.org>,
 
8
                2004 Alexander Schremmer <alex AT alexanderweb DOT de>
 
9
                2008 MoinMoin:ReimarBauer
9
10
    @license: GNU GPL, see COPYING for details.
10
11
"""
11
12
 
12
 
from MoinMoin.util import MoinMoinNoFooter
 
13
import time
13
14
from MoinMoin.Page import Page
14
 
import time
15
15
 
16
16
class NewPage:
17
17
    """ Open editor for a new page, using template """
21
21
        self.referrer = referrer # The page the user came from
22
22
        self.pagename = self.request.form.get('pagename', [None])[0]
23
23
        self.nametemplate = self.request.form.get('nametemplate', ['%s'])[0]
24
 
        self.nametemplate = self.nametemplate.replace('\x00','')
 
24
        self.nametemplate = self.nametemplate.replace('\x00', '')
25
25
 
26
26
    def checkAndCombineArguments(self):
27
27
        """ Check arguments in form, return error msg
30
30
        @return: error message
31
31
        """
32
32
        _ = self.request.getText
33
 
        need_replace = self.nametemplate.find('%s') != -1
 
33
        need_replace = '%s' in self.nametemplate
34
34
        if not self.pagename and need_replace:
35
35
            return _("Cannot create a new page without a page name."
36
36
                     "  Please specify a page name.")
37
 
        if need_replace: 
38
 
            # generate a string that can be safely used as the pagename
39
 
            # template variable
 
37
        if need_replace:
 
38
        # generate a string that can be safely used as the pagename
 
39
        # template variable
40
40
            repl = 'A@'
41
41
            i = 0
42
 
            while self.nametemplate.find(repl) != -1:
43
 
                repl += ['#','&','$','x','X',':','@'][i]
 
42
            while repl in self.nametemplate:
 
43
                repl += ['#', '&', '$', 'x', 'X', ':', '@'][i]
44
44
                i += 1
45
45
                i = i % 7
46
46
            template = self.nametemplate.replace('%s', repl)
54
54
        else:
55
55
            self.pagename = template
56
56
        return ''
57
 
        
 
57
 
58
58
    def checkPermissions(self):
59
59
        """ Check write permission in form, return error msg
60
60
 
70
70
 
71
71
    def render(self):
72
72
        """ Redirect to the new page, using edit action and template """
73
 
        
74
73
        error = self.checkAndCombineArguments() or self.checkPermissions()
75
74
        if error:
76
75
            # Send back to the page you came from, with an error msg
77
76
            page = Page(self.request, self.referrer)
78
 
            page.send_page(self.request, msg=error)
 
77
            self.request.theme.add_msg(error, "error")
 
78
            page.send_page()
79
79
        else:
80
80
            # Redirect to new page using edit action. No error checking
81
81
            # is needed because it is done later in new request.
84
84
 
85
85
            template = self.request.form.get('template', [''])[0]
86
86
            if template:
87
 
                from MoinMoin.wikiutil import quoteWikinameURL
88
 
                query['template'] = quoteWikinameURL(template)
 
87
                query['template'] = template
89
88
 
90
89
            parent = self.request.form.get('parent', [''])[0]
91
90
            if parent:
92
91
                pagename = "%s/%s" % (parent, pagename)
93
92
 
94
 
            url = Page(self.request, pagename).url(self.request, query, 0)
 
93
            url = Page(self.request, pagename).url(self.request, query)
95
94
            self.request.http_redirect(url)
96
 
            raise MoinMoinNoFooter
97
95
 
98
96
        return ''
99
97
 
100
98
def execute(pagename, request):
101
99
    """ Temporary glue code for current moin action system """
 
100
    if request.request_method != 'POST':
 
101
        return False, u''
 
102
 
102
103
    return NewPage(request, pagename).render()
103
104