annotate MoinMoin/action/__init__.py @ 3040:8608b258f8e6

bug fix of MoinMoinBugs/MoveAttachmentNotWorkingWithModPython (thanks to Boleslaw Kulbabinski) (ported from 1.6)
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Tue, 05 Feb 2008 21:22:56 +0100
parents ba14d391c2ba
children a739558ca3dc
rev   line source
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
2 """
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
3 MoinMoin - Action Implementation
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
4
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
5 Actions are triggered by the user clicking on special links on the page
619
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
6 (e.g. the "edit" link). The name of the action is passed in the "action"
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
7 CGI parameter.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
8
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
9 The sub-package "MoinMoin.action" contains external actions, you can
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
10 place your own extensions there (similar to extension macros). User
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
11 actions that start with a capital letter will be displayed in a list
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
12 at the bottom of each page.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
13
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
14 User actions starting with a lowercase letter can be used to work
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
15 together with a user macro; those actions a likely to work only if
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
16 invoked BY that macro, and are thus hidden from the user interface.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
17
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
18 Additionally to the usual stuff, we provide an ActionBase class here with
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
19 some of the usual base functionality for an action, like checking
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
20 actions_excluded, making and checking tickets, rendering some form,
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
21 displaying errors and doing stuff after an action.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
22
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
23 @copyright: 2000-2004 Juergen Hermann <jh@web.de>,
619
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
24 2006 MoinMoin:ThomasWaldmann
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
25 @license: GNU GPL, see COPYING for details.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
26 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
27
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
28 from MoinMoin.util import pysupport
2714
eb37036e3350 temporary fix missing http headers for action=content
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2294
diff changeset
29 from MoinMoin import config, wikiutil
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
30 from MoinMoin.Page import Page
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
31
1132
f9d8b80f5afb implement list of known actions similar to list of known macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1110
diff changeset
32 # create a list of extension actions from the package directory
1133
db56bd53fc32 cleanup plugin related code / attributes, remove unused stuff
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1132
diff changeset
33 modules = pysupport.getPackageModules(__file__)
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
34
1132
f9d8b80f5afb implement list of known actions similar to list of known macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1110
diff changeset
35 # builtin-stuff (see do_<name> below):
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
36 names = ['show', 'recall', 'raw', 'format', 'content', 'print', 'refresh', 'goto', ]
1132
f9d8b80f5afb implement list of known actions similar to list of known macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1110
diff changeset
37
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
38 class ActionBase:
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
39 """ action base class with some generic stuff to inherit
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
40
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
41 Note: the action name is the class name of the derived class
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
42 """
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
43 def __init__(self, pagename, request):
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
44 self.request = request
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
45 self.form = request.form
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
46 self.cfg = request.cfg
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
47 self._ = _ = request.getText
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
48 self.pagename = pagename
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
49 self.actionname = self.__class__.__name__
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
50 self.use_ticket = False # set this to True if you want to use a ticket
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
51 self.user_html = '''Just checking.''' # html fragment for make_form
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
52 self.form_cancel = "cancel" # form key for cancelling action
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
53 self.form_cancel_label = _("Cancel") # label for the cancel button
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
54 self.form_trigger = "doit" # form key for triggering action (override with e.g. 'rename')
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
55 self.form_trigger_label = _("Do it.") # label for the trigger button
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
56 self.page = Page(request, pagename)
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
57 self.error = ''
1751
95485f94760d action/__init__.py:fixed wrong definition
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1750
diff changeset
58 self.method = 'GET'
95485f94760d action/__init__.py:fixed wrong definition
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1750
diff changeset
59 self.enctype = 'multipart/form-data'
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
60
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
61 # CHECKS -----------------------------------------------------------------
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
62 def is_excluded(self):
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
63 """ Return True if action is excluded """
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
64 return self.actionname in self.cfg.actions_excluded
912
2f3395d42f93 some minor fixes, whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
65
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
66 def is_allowed(self):
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
67 """ Return True if action is allowed (by ACL) """
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
68 return True
912
2f3395d42f93 some minor fixes, whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
69
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
70 def check_condition(self):
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
71 """ Check if some other condition is not allowing us to do that action,
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
72 return error msg or None if there is no problem.
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
73
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
74 You can use this to e.g. check if a page exists.
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
75 """
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
76 return None
912
2f3395d42f93 some minor fixes, whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
77
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
78 def ticket_ok(self):
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
79 """ Return True if we check for tickets and there is some valid ticket
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
80 in the form data or if we don't check for tickets at all.
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
81 Use this to make sure someone really used the web interface.
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
82 """
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
83 if not self.use_ticket:
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
84 return True
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
85 # Require a valid ticket. Make outside attacks harder by
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
86 # requiring two full HTTP transactions
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
87 ticket = self.form.get('ticket', [''])[0]
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: 1550
diff changeset
88 return wikiutil.checkTicket(self.request, ticket)
912
2f3395d42f93 some minor fixes, whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
89
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
90 # UI ---------------------------------------------------------------------
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
91 def get_form_html(self, buttons_html):
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
92 """ Override this to assemble the inner part of the form,
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
93 for convenience we give him some pre-assembled html for the buttons.
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
94 """
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
95 _ = self._
1384
d1ceb31f3d02 make more use of formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1358
diff changeset
96 f = self.request.formatter
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
97 prompt = _("Execute action %(actionname)s?") % {'actionname': self.actionname}
1384
d1ceb31f3d02 make more use of formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1358
diff changeset
98 return f.paragraph(1) + f.text(prompt) + f.paragraph(0) + f.rawHTML(buttons_html)
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
99
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
100 def make_buttons(self):
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
101 """ return a list of form buttons for the action form """
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
102 return [
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
103 (self.form_trigger, self.form_trigger_label),
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
104 (self.form_cancel, self.form_cancel_label),
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
105 ]
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
106
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
107 def make_form(self):
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
108 """ Make some form html for later display.
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
109
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
110 The form might contain an error that happened when trying to do the action.
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
111 """
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
112 from MoinMoin.widget.dialog import Dialog
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
113 _ = self._
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
114
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
115 if self.error:
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
116 error_html = u'<p class="error">%s</p>\n' % self.error
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
117 else:
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
118 error_html = ''
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
119
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
120 buttons = self.make_buttons()
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
121 buttons_html = []
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
122 for button in buttons:
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
123 buttons_html.append('<input type="submit" name="%s" value="%s">' % button)
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
124 buttons_html = "".join(buttons_html)
912
2f3395d42f93 some minor fixes, whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
125
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
126 if self.use_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: 1550
diff changeset
127 ticket_html = '<input type="hidden" name="ticket" value="%s">' % wikiutil.createTicket(self.request)
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
128 else:
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
129 ticket_html = ''
912
2f3395d42f93 some minor fixes, whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
130
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
131 d = {
1751
95485f94760d action/__init__.py:fixed wrong definition
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1750
diff changeset
132 'method': self.method,
3040
8608b258f8e6 bug fix of MoinMoinBugs/MoveAttachmentNotWorkingWithModPython (thanks to Boleslaw Kulbabinski) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2966
diff changeset
133 'baseurl': self.request.getScriptname(),
1751
95485f94760d action/__init__.py:fixed wrong definition
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1750
diff changeset
134 'enctype': self.enctype,
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
135 'error_html': error_html,
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
136 'actionname': self.actionname,
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
137 'pagename': self.pagename,
3040
8608b258f8e6 bug fix of MoinMoinBugs/MoveAttachmentNotWorkingWithModPython (thanks to Boleslaw Kulbabinski) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2966
diff changeset
138 'pagename_quoted': wikiutil.quoteWikinameURL(self.pagename),
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
139 'ticket_html': ticket_html,
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
140 'user_html': self.get_form_html(buttons_html),
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
141 }
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
142
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
143 form_html = '''
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
144 %(error_html)s
3040
8608b258f8e6 bug fix of MoinMoinBugs/MoveAttachmentNotWorkingWithModPython (thanks to Boleslaw Kulbabinski) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2966
diff changeset
145 <form action="%(baseurl)s/%(pagename_quoted)s" method="%(method)s" enctype="%(enctype)s">
2842
31e9f486d1ce Fix two ActionBase form bugs: two method arguments in same form tag, input tag without a div (or any else 'container' around it)
Ville-Pekka Vainio <vpivaini AT cs DOT helsinki DOT fi>
parents: 2714
diff changeset
146 <div>
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
147 <input type="hidden" name="action" value="%(actionname)s">
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
148 %(ticket_html)s
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
149 %(user_html)s
2842
31e9f486d1ce Fix two ActionBase form bugs: two method arguments in same form tag, input tag without a div (or any else 'container' around it)
Ville-Pekka Vainio <vpivaini AT cs DOT helsinki DOT fi>
parents: 2714
diff changeset
150 </div>
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
151 </form>''' % d
912
2f3395d42f93 some minor fixes, whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
152
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
153 return Dialog(self.request, content=form_html)
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
154
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: 2842
diff changeset
155 def render_msg(self, msg, msgtype):
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
156 """ Called to display some message (can also be the action form) """
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: 2842
diff changeset
157 self.request.theme.add_msg(msg, msgtype)
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: 2842
diff changeset
158 self.page.send_page()
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
159
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: 2842
diff changeset
160 def render_success(self, msg, msgtype):
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
161 """ Called to display some message when the action succeeded """
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: 2842
diff changeset
162 self.request.theme.add_msg(msg, msgtype)
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: 2842
diff changeset
163 self.page.send_page()
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
164
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
165 def render_cancel(self):
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
166 """ Called when user has hit the cancel button """
1781
5408417e650b send_page: remove some more call's request param (see cs 1777)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1751
diff changeset
167 self.page.send_page() # we don't tell user he has hit cancel :)
912
2f3395d42f93 some minor fixes, whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
168
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
169 def render(self):
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
170 """ Render action - this is the main function called by action's
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
171 execute() function.
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
172
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
173 We usually render a form here, check for posted forms, etc.
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
174 """
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
175 _ = self._
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
176 form = self.form
912
2f3395d42f93 some minor fixes, whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
177
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1816
diff changeset
178 if self.form_cancel in form:
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
179 self.render_cancel()
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
180 return
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
181
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
182 # Validate allowance, user rights and other conditions.
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
183 error = None
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
184 if self.is_excluded():
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
185 error = _('Action %(actionname)s is excluded in this wiki!') % {'actionname': self.actionname }
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
186 elif not self.is_allowed():
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
187 error = _('You are not allowed to use action %(actionname)s on this page!') % {'actionname': self.actionname }
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
188 if error is None:
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
189 error = self.check_condition()
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
190 if error:
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: 2842
diff changeset
191 self.render_msg(error, "error")
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1816
diff changeset
192 elif self.form_trigger in form: # user hit the trigger button
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
193 if self.ticket_ok():
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
194 success, self.error = self.do_action()
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
195 else:
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
196 success = False
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
197 self.error = _('Please use the interactive user interface to use action %(actionname)s!') % {'actionname': self.actionname }
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
198 self.do_action_finish(success)
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
199 else:
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
200 # Return a new form
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: 2842
diff changeset
201 self.render_msg(self.make_form(), "dialog")
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
202
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
203 # Executing the action ---------------------------------------------------
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
204 def do_action(self):
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
205 """ Do the action and either return error msg or None, if there was no error. """
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
206 return None
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
207
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
208 # AFTER the action -------------------------------------------------------
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
209 def do_action_finish(self, success):
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
210 """ Override this to handle success or failure (with error in self.error) of your action.
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
211 """
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
212 if success:
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: 2842
diff changeset
213 self.render_success(self.error, "info")
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
214 else:
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: 2842
diff changeset
215 self.render_msg(self.make_form(), "dialog") # display the form again
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
216
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 634
diff changeset
217
1110
b27d720fbc8e actions: cleanup, fix imports
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1109
diff changeset
218 # Builtin Actions ------------------------------------------------------------
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
219
619
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
220 def do_raw(pagename, request):
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
221 """ send raw content of a page (e.g. wiki markup) """
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
222 if not request.user.may.read(pagename):
1781
5408417e650b send_page: remove some more call's request param (see cs 1777)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1751
diff changeset
223 Page(request, pagename).send_page()
621
d1e84cbab594 simplified code in wikiaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 620
diff changeset
224 else:
1682
30116d7d098a request.rev is either revision integer (when given in form) or None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
225 rev = request.rev or 0
621
d1e84cbab594 simplified code in wikiaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 620
diff changeset
226 Page(request, pagename, rev=rev).send_raw()
619
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
227
1875
5afb427026ea refactor print_mode, fix/simplify content action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
228 def do_show(pagename, request, content_only=0, count_hit=1, cacheable=1, print_mode=0):
620
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 619
diff changeset
229 """ show a page, either current revision or the revision given by rev form value.
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 619
diff changeset
230 if count_hit is non-zero, we count the request for statistics.
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 619
diff changeset
231 """
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 619
diff changeset
232 # We must check if the current page has different ACLs.
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 619
diff changeset
233 if not request.user.may.read(pagename):
1781
5408417e650b send_page: remove some more call's request param (see cs 1777)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1751
diff changeset
234 Page(request, pagename).send_page()
621
d1e84cbab594 simplified code in wikiaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 620
diff changeset
235 else:
d1e84cbab594 simplified code in wikiaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 620
diff changeset
236 mimetype = request.form.get('mimetype', [u"text/html"])[0]
1682
30116d7d098a request.rev is either revision integer (when given in form) or None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
237 rev = request.rev or 0
621
d1e84cbab594 simplified code in wikiaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 620
diff changeset
238 if rev == 0:
d1e84cbab594 simplified code in wikiaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 620
diff changeset
239 request.cacheable = cacheable
1875
5afb427026ea refactor print_mode, fix/simplify content action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
240 Page(request, pagename, rev=rev, formatter=mimetype).send_page(
5afb427026ea refactor print_mode, fix/simplify content action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
241 count_hit=count_hit,
5afb427026ea refactor print_mode, fix/simplify content action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
242 print_mode=print_mode,
5afb427026ea refactor print_mode, fix/simplify content action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
243 content_only=content_only,
5afb427026ea refactor print_mode, fix/simplify content action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
244 )
619
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
245
620
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 619
diff changeset
246 def do_format(pagename, request):
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 619
diff changeset
247 """ send a page using a specific formatter given by mimetype form key.
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 619
diff changeset
248 Since 5.5.2006 this functionality is also done by do_show, but do_format
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 619
diff changeset
249 has a default of text/plain when no format is given.
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 619
diff changeset
250 It also does not count in statistics and also does not set the cacheable flag.
656
ad2ac49d17fe use only action=show with mimetype instead of deprecated format action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 636
diff changeset
251 DEPRECATED: remove this action when we don't need it any more for compatibility.
620
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 619
diff changeset
252 """
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1816
diff changeset
253 if 'mimetype' not in request.form:
620
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 619
diff changeset
254 request.form['mimetype'] = [u"text/plain"]
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 619
diff changeset
255 do_show(pagename, request, count_hit=0, cacheable=0)
619
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
256
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
257 def do_content(pagename, request):
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
258 """ same as do_show, but we only show the content """
2714
eb37036e3350 temporary fix missing http headers for action=content
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2294
diff changeset
259 # XXX temporary fix to make it work until Page.send_page gets refactored
eb37036e3350 temporary fix missing http headers for action=content
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2294
diff changeset
260 request.setHttpHeader("Content-Type: text/html; charset=%s" % config.charset)
eb37036e3350 temporary fix missing http headers for action=content
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2294
diff changeset
261 request.setHttpHeader('Status: 200 OK')
eb37036e3350 temporary fix missing http headers for action=content
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2294
diff changeset
262 request.emit_http_headers()
1875
5afb427026ea refactor print_mode, fix/simplify content action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
263 do_show(pagename, request, count_hit=0, content_only=1)
619
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
264
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
265 def do_print(pagename, request):
1875
5afb427026ea refactor print_mode, fix/simplify content action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
266 """ same as do_show, but with print_mode set """
5afb427026ea refactor print_mode, fix/simplify content action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
267 do_show(pagename, request, print_mode=1)
619
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
268
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
269 def do_recall(pagename, request):
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
270 """ same as do_show, but never caches and never counts hits """
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
271 do_show(pagename, request, count_hit=0, cacheable=0)
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
272
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
273 def do_refresh(pagename, request):
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
274 """ Handle refresh action """
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
275 # Without arguments, refresh action will refresh the page text_html cache.
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
276 arena = request.form.get('arena', ['Page.py'])[0]
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
277 if arena == 'Page.py':
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
278 arena = Page(request, pagename)
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
279 key = request.form.get('key', ['text_html'])[0]
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
280
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
281 # Remove cache entry (if exists), and send the page
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
282 from MoinMoin import caching
682
1314fdb74689 refactor CacheEntry usage to use scope param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 662
diff changeset
283 caching.CacheEntry(request, arena, key, scope='item').remove()
1314fdb74689 refactor CacheEntry usage to use scope param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 662
diff changeset
284 caching.CacheEntry(request, arena, "pagelinks", scope='item').remove()
619
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
285 do_show(pagename, request)
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
286
615
fb4240ec8361 make goto an action (1 special case less)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 554
diff changeset
287 def do_goto(pagename, request):
fb4240ec8361 make goto an action (1 special case less)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 554
diff changeset
288 """ redirect to another page """
fb4240ec8361 make goto an action (1 special case less)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 554
diff changeset
289 target = request.form.get('target', [''])[0]
1816
4a31739bc6e1 Page.url(): removed escaping support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1781
diff changeset
290 request.http_redirect(Page(request, target).url(request, relative=False))
615
fb4240ec8361 make goto an action (1 special case less)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 554
diff changeset
291
1110
b27d720fbc8e actions: cleanup, fix imports
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1109
diff changeset
292 # Dispatching ----------------------------------------------------------------
1132
f9d8b80f5afb implement list of known actions similar to list of known macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1110
diff changeset
293 def getNames(cfg):
1550
a4f0632414da using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1384
diff changeset
294 if not hasattr(cfg.cache, 'action_names'):
1132
f9d8b80f5afb implement list of known actions similar to list of known macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1110
diff changeset
295 lnames = names[:]
f9d8b80f5afb implement list of known actions similar to list of known macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1110
diff changeset
296 lnames.extend(wikiutil.getPlugins('action', cfg))
1550
a4f0632414da using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1384
diff changeset
297 cfg.cache.action_names = lnames # remember it
a4f0632414da using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1384
diff changeset
298 return cfg.cache.action_names
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
299
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
300 def getHandler(request, action, identifier="execute"):
619
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
301 """ return a handler function for a given action or None """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
302 # check for excluded actions
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
303 if action in request.cfg.actions_excluded:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
304 return None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
305
51
54d5932d5a03 merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents: 40
diff changeset
306 try:
619
0bb6b767baec wikiaction: reordered functions, added some comments - only minor changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
307 handler = wikiutil.importPlugin(request.cfg, "action", action, identifier)
53
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
308 except wikiutil.PluginMissingError:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
309 handler = globals().get('do_' + action)
912
2f3395d42f93 some minor fixes, whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
310
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
311 return handler
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
312