annotate MoinMoin/action/edit.py @ 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
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 16 Nov 2008 22:20:21 +0100
parents 40acd13fb3d6
children 6f6736e7683c
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
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
13
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
14 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
15 """ 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
16 _ = 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
17
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
18 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
19 # multiple buttons pressed at once? must be some spammer/bot
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
20 request.makeForbidden403()
1570
8bfaae6fa0a5 kick spammers by triggering surge protection
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1561
diff changeset
21 request.surge_protect(kick_him=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
22 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
23
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
24 if not request.user.may.write(pagename):
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
25 request.theme.add_msg(_('You are not allowed to edit this page.'), "error")
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
26 Page(request, pagename).send_page()
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
27 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
28
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
29 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
30 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
31 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
32 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
33 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
34 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
35
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
36 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
37 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
38 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
39 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
40 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
41 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
42 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
43
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 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
45 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
46
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 # 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
48 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
49 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
50
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
51 rev = request.rev or 0
4201
40acd13fb3d6 Changed form access to MultiDict forms
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3304
diff changeset
52 savetext = request.form.get('savetext')
40acd13fb3d6 Changed form access to MultiDict forms
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3304
diff changeset
53 comment = request.form.get('comment', u'')
40acd13fb3d6 Changed form access to MultiDict forms
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3304
diff changeset
54 category = request.form.get('category')
40acd13fb3d6 Changed form access to MultiDict forms
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3304
diff changeset
55 rstrip = int(request.form.get('rstrip', '0'))
40acd13fb3d6 Changed form access to MultiDict forms
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3304
diff changeset
56 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
57
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
58 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
59 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
60 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
61 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
62 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
63
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 # 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
65 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
66 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
67 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
68 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
69 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
70 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
71
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 # 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
73 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
74 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
75 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
76
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
77 # did user hit cancel button?
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
78 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
79
1573
1453513eaa7e use tickets for editing, cfg.edit_ticketing, make tickets more safe, invalidate old tickets
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1570
diff changeset
80 if request.cfg.edit_ticketing:
4201
40acd13fb3d6 Changed form access to MultiDict forms
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3304
diff changeset
81 ticket = request.form.get('ticket', '')
1573
1453513eaa7e use tickets for editing, cfg.edit_ticketing, make tickets more safe, invalidate old tickets
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1570
diff changeset
82 if not wikiutil.checkTicket(request, ticket):
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
83 request.theme.add_msg(_('Please use the interactive user interface to use action %(actionname)s!') % {'actionname': 'edit' }, "error")
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
84 pg.send_page()
1573
1453513eaa7e use tickets for editing, cfg.edit_ticketing, make tickets more safe, invalidate old tickets
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1570
diff changeset
85 return
1453513eaa7e use tickets for editing, cfg.edit_ticketing, make tickets more safe, invalidate old tickets
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1570
diff changeset
86
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 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
88 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
89 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
90 # convert input from Graphical editor
4201
40acd13fb3d6 Changed form access to MultiDict forms
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3304
diff changeset
91 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
92 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
93 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
94 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
95 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
96 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
97 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
98
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 # 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
100 # 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
101 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
102 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
103 # 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
104 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
105 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
106
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
107 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
108 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
109 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
110 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
111 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
112 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
113 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
114
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
115 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
116
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 # 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
118
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 # 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
120 # 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
121 # 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
122 # 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
123
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3030
diff changeset
124 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
125 # 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
126 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
127
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 # 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
129 # non-categories.
1866
0194beaf511e reduce reduce, filter and map usage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1777
diff changeset
130 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
131 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
132
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 #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
134 #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
135 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
136
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 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
138 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
139 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
140 # 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
141 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
142
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 # 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
144 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
145 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
146 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
147
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
148 # Preview, spellcheck or spellcheck add new words
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
149 if ('button_preview' in request.form or
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
150 'button_spellcheck' in request.form or
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
151 '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
152 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
153
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 # Preview with mode switch
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
155 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
156 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
157
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 # 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
159 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
160 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
161 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
162 if not TextCha(request).check_answer_from_form():
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3030
diff changeset
163 raise pg.SaveError(_('TextCha: Wrong answer! Go back 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
164 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
165 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
166 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
167
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 # 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
169 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
170
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 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
172 # 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
173 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
174 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
175
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 except pg.SaveError, msg:
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 # msg contains a unicode string
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 savemsg = unicode(msg)
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 # Send new page after save or after unsuccessful conflict merge.
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
181 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
182 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
183
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
184 # 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
185 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
186 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
187 pg.send_page()