annotate MoinMoin/action/edit.py @ 6073:338348b5d5ad

use proper parameter name in log_attempt() call
author 'Karl O. Pinc' <kop@meme.com>
date Mon, 15 Sep 2014 21:14:44 -0500
parents 68092d872ecc
children 6366f5b440ff
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1018
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
2 """
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
3 MoinMoin - edit a page
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
4
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
5 This either calls the text or the GUI page editor.
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
6
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1908
diff changeset
7 @copyright: 2000-2004 Juergen Hermann <jh@web.de>,
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1908
diff changeset
8 2006 MoinMoin:ThomasWaldmann
1018
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
9 @license: GNU GPL, see COPYING for details.
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
10 """
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
11 from MoinMoin import wikiutil
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
12 from MoinMoin.Page import Page
5255
ec00e39ec3f8 use correct check_surge_protect() call
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5252
diff changeset
13 from MoinMoin.web.utils import check_surge_protect
6063
c2e4df0f760f log action detections of access violations with abuse logger
'Karl O. Pinc' <kop@meme.com>
parents: 5978
diff changeset
14 from MoinMoin.util.abuse import log_attempt
1018
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
15
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
16 def execute(pagename, request):
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
17 """ edit a page """
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
18 _ = request.getText
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
19
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
20 if 'button_preview' in request.form and 'button_spellcheck' in request.form:
1561
d12202b5791c check if multiple submit buttons are pressed at once (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1157
diff changeset
21 # multiple buttons pressed at once? must be some spammer/bot
5255
ec00e39ec3f8 use correct check_surge_protect() call
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5252
diff changeset
22 check_surge_protect(request, kick=True) # get rid of him
1561
d12202b5791c check if multiple submit buttons are pressed at once (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1157
diff changeset
23 return
d12202b5791c check if multiple submit buttons are pressed at once (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1157
diff changeset
24
1018
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
25 if not request.user.may.write(pagename):
6073
338348b5d5ad use proper parameter name in log_attempt() call
'Karl O. Pinc' <kop@meme.com>
parents: 6066
diff changeset
26 log_attempt('edit: edit', False, request, pagename=pagename)
5310
1f0c87a833a8 action.edit: bug fix for MoinMoinBugs/MissingPageShouldn'tOfferToCreatePageForReadonlyUsers
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 5255
diff changeset
27 page = wikiutil.getLocalizedPage(request, 'PermissionDeniedPage')
1f0c87a833a8 action.edit: bug fix for MoinMoinBugs/MissingPageShouldn'tOfferToCreatePageForReadonlyUsers
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 5255
diff changeset
28 page.body = _('You are not allowed to edit this page.')
1f0c87a833a8 action.edit: bug fix for MoinMoinBugs/MissingPageShouldn'tOfferToCreatePageForReadonlyUsers
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 5255
diff changeset
29 page.page_name = pagename
1f0c87a833a8 action.edit: bug fix for MoinMoinBugs/MissingPageShouldn'tOfferToCreatePageForReadonlyUsers
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 5255
diff changeset
30 page.send_page(send_special=True)
1018
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
31 return
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
32
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
33 valideditors = ['text', 'gui', ]
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
34 editor = ''
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
35 if request.user.valid:
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
36 editor = request.user.editor_default
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
37 if editor not in valideditors:
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
38 editor = request.cfg.editor_default
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
39
4424
5ad5753ae311 pre-1.9: request.form has qs args and post data, 1.9: .form only post data, .args only qs args, .values both
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4201
diff changeset
40 editorparam = request.values.get('editor', editor)
1018
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
41 if editorparam == "guipossible":
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
42 lasteditor = editor
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
43 elif editorparam == "textonly":
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
44 editor = lasteditor = 'text'
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
45 else:
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
46 editor = lasteditor = editorparam
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
47
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
48 if request.cfg.editor_force:
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
49 editor = request.cfg.editor_default
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
50
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
51 # if it is still nothing valid, we just use the text editor
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
52 if editor not in valideditors:
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
53 editor = 'text'
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
54
1682
30116d7d098a request.rev is either revision integer (when given in form) or None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1640
diff changeset
55 rev = request.rev or 0
4201
40acd13fb3d6 Changed form access to MultiDict forms
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3304
diff changeset
56 savetext = request.form.get('savetext')
40acd13fb3d6 Changed form access to MultiDict forms
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3304
diff changeset
57 comment = request.form.get('comment', u'')
40acd13fb3d6 Changed form access to MultiDict forms
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3304
diff changeset
58 category = request.form.get('category')
40acd13fb3d6 Changed form access to MultiDict forms
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3304
diff changeset
59 rstrip = int(request.form.get('rstrip', '0'))
40acd13fb3d6 Changed form access to MultiDict forms
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3304
diff changeset
60 trivial = int(request.form.get('trivial', '0'))
1018
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
61
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
62 if 'button_switch' in request.form:
1018
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
63 if editor == 'text':
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
64 editor = 'gui'
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
65 else: # 'gui'
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
66 editor = 'text'
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
67
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
68 # load right editor class
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
69 if editor == 'gui':
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
70 from MoinMoin.PageGraphicalEditor import PageGraphicalEditor
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
71 pg = PageGraphicalEditor(request, pagename)
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
72 else: # 'text'
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
73 from MoinMoin.PageEditor import PageEditor
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
74 pg = PageEditor(request, pagename)
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
75
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
76 # is invoked without savetext start editing
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
77 if savetext is None or 'button_load_draft' in request.form:
1018
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
78 pg.sendEditor()
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
79 return
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
80
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
81 # did user hit cancel button?
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
82 cancelled = 'button_cancel' in request.form
1018
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
83
1908
8bd4b581cc60 make converter pluggable, dynamically load correct converter, move loading of parser to send_page_content
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1895
diff changeset
84 from MoinMoin.error import ConvertError
1018
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
85 try:
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
86 if lasteditor == 'gui':
1908
8bd4b581cc60 make converter pluggable, dynamically load correct converter, move loading of parser to send_page_content
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1895
diff changeset
87 # convert input from Graphical editor
4201
40acd13fb3d6 Changed form access to MultiDict forms
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3304
diff changeset
88 format = request.form.get('format', 'wiki')
1908
8bd4b581cc60 make converter pluggable, dynamically load correct converter, move loading of parser to send_page_content
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1895
diff changeset
89 if format == 'wiki':
8bd4b581cc60 make converter pluggable, dynamically load correct converter, move loading of parser to send_page_content
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1895
diff changeset
90 converter_name = 'text_html_text_moin_wiki'
8bd4b581cc60 make converter pluggable, dynamically load correct converter, move loading of parser to send_page_content
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1895
diff changeset
91 else:
8bd4b581cc60 make converter pluggable, dynamically load correct converter, move loading of parser to send_page_content
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1895
diff changeset
92 converter_name = 'undefined' # XXX we don't have other converters yet
2033
a6d829ec895d GUI editor: use correct module import function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1922
diff changeset
93 convert = wikiutil.importPlugin(request.cfg, "converter", converter_name, 'convert')
1018
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
94 savetext = convert(request, pagename, savetext)
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
95
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
96 # IMPORTANT: normalize text from the form. This should be done in
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
97 # one place before we manipulate the text.
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
98 savetext = pg.normalizeText(savetext, stripspaces=rstrip)
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
99 except ConvertError:
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
100 # we don't want to throw an exception if user cancelled anyway
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
101 if not cancelled:
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
102 raise
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
103
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
104 if cancelled:
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
105 pg.sendCancel(savetext or "", rev)
2043
cc636ac8d6a6 edit: friendly used cancel on new page removes empty pagedir
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2033
diff changeset
106 pagedir = pg.getPagePath(check_create=0)
cc636ac8d6a6 edit: friendly used cancel on new page removes empty pagedir
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2033
diff changeset
107 import os
cc636ac8d6a6 edit: friendly used cancel on new page removes empty pagedir
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2033
diff changeset
108 if not os.listdir(pagedir):
cc636ac8d6a6 edit: friendly used cancel on new page removes empty pagedir
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2033
diff changeset
109 os.removedirs(pagedir)
1018
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
110 return
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
111
1922
f486526720c5 renamed wikiutil.clean_comment > clean_input, moved translation map to config
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
112 comment = wikiutil.clean_input(comment)
1018
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
113
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
114 # Add category
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
115
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
116 # TODO: this code does not work with extended links, and is doing
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
117 # things behind your back, and in general not needed. Either we have
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
118 # a full interface for categories (add, delete) or just add them by
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
119 # markup.
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
120
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3030
diff changeset
121 if category and category != _('<No addition>'): # opera 8.5 needs this
1018
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
122 # strip trailing whitespace
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
123 savetext = savetext.rstrip()
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
124
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
125 # Add category separator if last non-empty line contains
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
126 # non-categories.
1866
0194beaf511e reduce reduce, filter and map usage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1777
diff changeset
127 lines = [line for line in savetext.splitlines() if line]
1018
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
128 if lines:
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
129
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
130 #TODO: this code is broken, will not work for extended links
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
131 #categories, e.g ["category hebrew"]
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
132 categories = lines[-1].split()
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
133
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
134 if categories:
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
135 confirmed = wikiutil.filterCategoryPages(request, categories)
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
136 if len(confirmed) < len(categories):
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
137 # This was not a categories line, add separator
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
138 savetext += u'\n----\n'
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
139
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
140 # Add new category
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
141 if savetext and savetext[-1] != u'\n':
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
142 savetext += ' '
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
143 savetext += category + u'\n' # Should end with newline!
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
144
5671
172146fe48a2 fix broken changeset f59d02d10935
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5670
diff changeset
145 if (request.cfg.edit_ticketing and
172146fe48a2 fix broken changeset f59d02d10935
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5670
diff changeset
146 not wikiutil.checkTicket(request, request.form.get('ticket', ''))):
172146fe48a2 fix broken changeset f59d02d10935
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5670
diff changeset
147 request.theme.add_msg(_('Please use the interactive user interface to use action %(actionname)s!') % {'actionname': 'edit' }, "error")
172146fe48a2 fix broken changeset f59d02d10935
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5670
diff changeset
148 pg.sendEditor(preview=savetext, comment=comment, staytop=1)
5670
f59d02d10935 if edit ticket check fails, send the editor with the current content
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5310
diff changeset
149
1018
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
150 # Preview, spellcheck or spellcheck add new words
5670
f59d02d10935 if edit ticket check fails, send the editor with the current content
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5310
diff changeset
151 elif ('button_preview' in request.form or
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
152 'button_spellcheck' in request.form or
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
153 'button_newwords' in request.form):
1018
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
154 pg.sendEditor(preview=savetext, comment=comment)
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
155
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
156 # Preview with mode switch
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
157 elif 'button_switch' in request.form:
1018
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
158 pg.sendEditor(preview=savetext, comment=comment, staytop=1)
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
159
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
160 # Save new text
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
161 else:
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
162 try:
2983
7b0aadb97d01 new antispam stuff: textchas (text CAPTCHAs), cleanup AttachFile handler (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
163 from MoinMoin.security.textcha import TextCha
7b0aadb97d01 new antispam stuff: textchas (text CAPTCHAs), cleanup AttachFile handler (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
164 if not TextCha(request).check_answer_from_form():
5890
6d5105a45257 on a save error, show the editor again and highlight the error as such
Matthijs Kooijman <matthijs@stdin.nl>
parents: 5889
diff changeset
165 raise pg.SaveError(_('TextCha: Wrong answer! Try again below...'))
5891
16f3285443ca rename require_comment option to comment_required
Matthijs Kooijman <matthijs@stdin.nl>
parents: 5890
diff changeset
166 if request.cfg.comment_required and not comment:
5978
81b8ea1e9c6f remove double space in error message
Matthijs Kooijman <matthijs@stdin.nl>
parents: 5891
diff changeset
167 raise pg.SaveError(_('Supplying a comment is mandatory. Write a comment below and try again...'))
1018
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
168 savemsg = pg.saveText(savetext, rev, trivial=trivial, comment=comment)
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
169 except pg.EditConflict, e:
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
170 msg = e.message
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
171
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
172 # Handle conflict and send editor
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
173 pg.set_raw_body(savetext, modified=1)
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
174
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
175 pg.mergeEditConflict(rev)
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
176 # We don't send preview when we do merge conflict
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
177 pg.sendEditor(msg=msg, comment=comment)
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
178 return
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
179
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
180 except pg.SaveError, msg:
5890
6d5105a45257 on a save error, show the editor again and highlight the error as such
Matthijs Kooijman <matthijs@stdin.nl>
parents: 5889
diff changeset
181 # Show the error message
6d5105a45257 on a save error, show the editor again and highlight the error as such
Matthijs Kooijman <matthijs@stdin.nl>
parents: 5889
diff changeset
182 request.theme.add_msg(unicode(msg), "error")
6d5105a45257 on a save error, show the editor again and highlight the error as such
Matthijs Kooijman <matthijs@stdin.nl>
parents: 5889
diff changeset
183 # And show the editor again
6d5105a45257 on a save error, show the editor again and highlight the error as such
Matthijs Kooijman <matthijs@stdin.nl>
parents: 5889
diff changeset
184 pg.sendEditor(preview=savetext, comment=comment, staytop=1)
6d5105a45257 on a save error, show the editor again and highlight the error as such
Matthijs Kooijman <matthijs@stdin.nl>
parents: 5889
diff changeset
185 return
1018
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
186
5890
6d5105a45257 on a save error, show the editor again and highlight the error as such
Matthijs Kooijman <matthijs@stdin.nl>
parents: 5889
diff changeset
187 # Send new page after successful save
1018
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
188 request.reset()
3304
db48ab0b2bf8 after edit, don't use backto if the page was saved
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3122
diff changeset
189 pg = Page(request, pagename)
1018
f5b796658f93 moved edit and diff code to own files, strange: needs a http_headers() call at end of edit.py - why?
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
190
1895
46e859ee4d2e edit: set request.rev to default after saving for further actions
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1868
diff changeset
191 # sets revision number to default for further actions
46e859ee4d2e edit: set request.rev to default after saving for further actions
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1868
diff changeset
192 request.rev = 0
2966
ba14d391c2ba Refactor all modules to use the new add_msg interface in 1.7 (done by Frederico Lorenzi). Should not be backported to 1.6 but
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2931
diff changeset
193 request.theme.add_msg(savemsg, "info")
ba14d391c2ba Refactor all modules to use the new add_msg interface in 1.7 (done by Frederico Lorenzi). Should not be backported to 1.6 but
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2931
diff changeset
194 pg.send_page()