Attachment 'CreateNewPage1.6.py'
Download 1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - CreateNewPage Action
4
5 XXX ToDo
6 Provide translations for:
7 _('Page Template')
8 _('Page Name')
9 _('Create')
10
11 CreateNewPage partly based on NewPage action
12 NewPage Action
13 @copyright: 2004 Vito Miliano (vito_moinnewpagewithtemplate@perilith.com)
14 @copyright: 2004 by Nir Soffer <nirs@freeshell.org>
15 @copyright: 2004 Alexander Schremmer <alex AT alexanderweb DOT de>
16
17 CreateNewPage Action
18 @copyright: 2007 by Oliver Siemoneit
19 @license: GNU GPL, see COPYING for details.
20 """
21
22 from MoinMoin import wikiutil
23 from MoinMoin.Page import Page
24
25 def execute(pagename, request):
26 return NewPageHandler(pagename, request).handle()
27
28 class NewPageHandler:
29
30 def __init__(self, pagename, request):
31 self.request = request
32 self._ = request.getText
33 self.pagename = pagename
34 self.newpage = ''
35 self.template = ''
36
37 def showForm(self, msg=None):
38 """ Assemble form and output it
39
40 @rtype: -
41 @return: -
42 """
43 _ = self._
44 request = self.request
45
46 # Get available templates
47 templates = []
48 filter = request.cfg.cache.page_template_regex.search
49 results = request.rootpage.getPageList(filter=filter)
50 results.sort()
51 templates.append("<option selected>%s</option>" % '') # _('<None>')
52 for result in results:
53 templates.append("<option>%s</option>" % result)
54
55 # Assemble form
56 sn = request.getScriptname()
57 pi = request.getPathinfo()
58 action = u"%s%s" % (sn, pi)
59 lang_attr = request.theme.ui_lang_attr()
60
61 form = '''
62 <form action="%(action)s" method="POST">
63 <div class="userpref" %(lang_attr)s>
64 <input type="hidden" name="action" value="CreateNewPage">
65 <table border="0">
66 <tr>
67 <td><strong>%(template)s</strong></td>
68 <td>
69 <select name="template" size="1">
70 %(templates)s
71 </select>
72 </td>
73 </tr>
74 <tr>
75 <td><strong>%(input)s</strong></td>
76 <td><input type="text" name="newpage" value="" size="36"></td>
77 </tr>
78 <tr>
79 <td><strong></strong></td>
80 <td><input type="submit" name="create" value="%(button)s"></td>
81 </tr>
82 </table>
83 </div>
84 </form>''' % { 'action': action,
85 'lang_attr': lang_attr,
86 'template': _('Page Template'),
87 'templates': ''.join(templates),
88 'input': _('Page Name'),
89 'button': _('Create') }
90
91 # Output form
92 request.emit_http_headers()
93 request.theme.send_title(_('Create New Page'), pagename=self.pagename, msg=msg)
94 request.write(request.formatter.startContent("content"))
95 request.write(request.formatter.rawHTML(unicode(form)))
96 request.write(request.formatter.endContent())
97 request.theme.send_footer(self.pagename)
98 request.theme.send_closing_html()
99
100 def checkInput(self):
101 """ Check if input is valid
102
103 @rtype: unicode
104 @return: error message
105 """
106 _ = self._
107 self.newpage = wikiutil.escape(self.newpage.strip())
108 self.template = wikiutil.escape(self.template.strip())
109 if not self.newpage:
110 return _("Cannot create a new page without a page name."
111 " Please specify a page name.")
112 page = Page(self.request, self.newpage)
113 if not (page.isWritable() and self.request.user.may.read(self.newpage)):
114 return _('You are not allowed to edit this page.')
115 return ''
116
117 def handle(self):
118 request = self.request
119 form = self.request.form
120 # If user has pressed "create" button, process it. Otherwise show form only.
121 if form.has_key('create'):
122 self.newpage = form.get('newpage', [''])[0]
123 self.template = form.get('template', [''])[0]
124 error = self.checkInput()
125 if error:
126 self.showForm(error)
127 else:
128 query = {'action': 'edit', 'backto': self.pagename}
129 if self.template:
130 query['template'] = wikiutil.quoteWikinameURL(self.template)
131 url = Page(request, self.newpage).url(request, query, escape=0, relative=False)
132 self.request.http_redirect(url)
133 else:
134 self.showForm()
135 return ''
136
137
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.