comparison MoinMoin/action/CopyPage.py @ 4732:e9a2cbcf5479

action.CopyPage: added textcha feature
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Thu, 21 May 2009 16:38:16 +0200
parents e2107f4b6217
children d887cc013e76 c6fd8b7f82b4 37306fba2189
comparison
equal deleted inserted replaced
4731:512aeb66b980 4732:e9a2cbcf5479
11 import re 11 import re
12 from MoinMoin import wikiutil 12 from MoinMoin import wikiutil
13 from MoinMoin.Page import Page 13 from MoinMoin.Page import Page
14 from MoinMoin.PageEditor import PageEditor 14 from MoinMoin.PageEditor import PageEditor
15 from MoinMoin.action import ActionBase 15 from MoinMoin.action import ActionBase
16 from MoinMoin.security.textcha import TextCha
16 17
17 class CopyPage(ActionBase): 18 class CopyPage(ActionBase):
18 """ Copy page action 19 """ Copy page action
19 20
20 Note: the action name is the class name 21 Note: the action name is the class name
43 return None 44 return None
44 45
45 def do_action(self): 46 def do_action(self):
46 """ copy this page to "pagename" """ 47 """ copy this page to "pagename" """
47 _ = self._ 48 _ = self._
49 # Currently we only check TextCha for upload (this is what spammers ususally do),
50 # but it could be extended to more/all attachment write access
51 if not TextCha(self.request).check_answer_from_form():
52 return status, _('TextCha: Wrong answer! Go back and try again...')
53
48 form = self.form 54 form = self.form
49 newpagename = form.get('newpagename', [u''])[0] 55 newpagename = form.get('newpagename', [u''])[0]
50 newpagename = self.request.normalizePagename(newpagename) 56 newpagename = self.request.normalizePagename(newpagename)
51 comment = form.get('comment', [u''])[0] 57 comment = form.get('comment', [u''])[0]
52 comment = wikiutil.clean_input(comment) 58 comment = wikiutil.clean_input(comment)
82 _ = self._ 88 _ = self._
83 if self.users_subpages: 89 if self.users_subpages:
84 subpages = ' '.join(self.users_subpages) 90 subpages = ' '.join(self.users_subpages)
85 91
86 d = { 92 d = {
93 'textcha': TextCha(self.request).render(),
87 'subpage': subpages, 94 'subpage': subpages,
88 'subpages_checked': ('', 'checked')[self.request.form.get('subpages_checked', ['0'])[0] == '1'], 95 'subpages_checked': ('', 'checked')[self.request.form.get('subpages_checked', ['0'])[0] == '1'],
89 'subpage_label': _('Copy all /subpages too?'), 96 'subpage_label': _('Copy all /subpages too?'),
90 'pagename': wikiutil.escape(self.pagename, True), 97 'pagename': wikiutil.escape(self.pagename, True),
91 'newname_label': _("New name"), 98 'newname_label': _("New name"),
96 103
97 return ''' 104 return '''
98 <strong>%(querytext)s</strong> 105 <strong>%(querytext)s</strong>
99 <br> 106 <br>
100 <br> 107 <br>
108 %(textcha)s
101 <table> 109 <table>
102 <tr> 110 <tr>
103 <dd> 111 <dd>
104 %(subpage_label)s<input type="checkbox" name="copy_subpages" value="1" %(subpages_checked)s> 112 %(subpage_label)s<input type="checkbox" name="copy_subpages" value="1" %(subpages_checked)s>
105 </dd> 113 </dd>
130 </table> 138 </table>
131 ''' % d 139 ''' % d
132 140
133 else: 141 else:
134 d = { 142 d = {
143 'textcha': TextCha(self.request).render(),
135 'pagename': wikiutil.escape(self.pagename, True), 144 'pagename': wikiutil.escape(self.pagename, True),
136 'newname_label': _("New name"), 145 'newname_label': _("New name"),
137 'comment_label': _("Optional reason for the copying"), 146 'comment_label': _("Optional reason for the copying"),
138 'buttons_html': buttons_html, 147 'buttons_html': buttons_html,
139 } 148 }
140 return ''' 149 return '''
150 %(textcha)s
141 <table> 151 <table>
142 <tr> 152 <tr>
143 <td class="label"><label>%(newname_label)s</label></td> 153 <td class="label"><label>%(newname_label)s</label></td>
144 <td class="content"> 154 <td class="content">
145 <input type="text" name="newpagename" value="%(pagename)s" size="80"> 155 <input type="text" name="newpagename" value="%(pagename)s" size="80">