#1566 closed defect (fixed)
Unable to access http request arguments from a user macro
Reported by: | Emmanuel Blot | Owned by: | Jonas Borgström |
---|---|---|---|
Priority: | low | Milestone: | 0.9 |
Component: | general | Version: | devel |
Severity: | normal | Keywords: | |
Cc: | ebcom@… | Branch: | |
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
I'm not sure I'm right, but I can't figure out how to access the req.args from a user macro.
The user macro execute(hdf, content, env)
method receives three parameters:
- hdf
- macro arguments
- environment
Neither first argument or third argument contains a reference to the HTTP request.
Perhaps the first arg. might be replaced with the full request (req
) instead of the hdf object (req.hdf
) ?
Attachments (0)
Change History (8)
comment:1 by , 20 years ago
comment:2 by , 20 years ago
Actually using parameters from a macro is quite powerful and useful.
The Blog, AddComment, and my own WikiCalendar macros all make use of them. They allow you to link or post back to the current page with additional information.
You used to be able to get the args via:
hdf.getValue("args.<paramname>", <default>)
However, this no longer seems to work.
comment:3 by , 20 years ago
I'm not sure whether this is actually a valid use for macros. A wiki author can easily put more than one instance of a macro on any page (or even a ticket comment etc). How will macros behave in that case if they want to do processing of request parameters?
comment:4 by , 20 years ago
Milestone: | → 0.9 |
---|---|
Resolution: | → fixed |
Status: | new → closed |
Added the request args to the HDF in [1687].
I'm still not convinced that allowing/encouraging macros to handle request parameters is such a good idea, though.
comment:5 by , 20 years ago
Cc: | added |
---|
You're right: AddComment for example cannot be used more than once in a Wiki page - and there's nothing in the current code to prevent from using it twice or more.
Could the plug-in framework be used as an alternative - using extension point to provide advanced feature such as AddComment ?
Perhaps this advanced macro usage could be changed in a next release, but I think the compatibility should not be broken until an alternative to these macros exists.
comment:6 by , 20 years ago
Actually the !Addcomment macro does prevent multiple instances:
# prevents from multiple inclusions if hdf.has_key('addcommentmacro'): raise TracError('\'AddComment\' macro cannot be included twice') hdf['addcommentmacro'] = True
And actually for the WikiComment macro I intentionally used the same parameters as the Blog macro so that the calendar would display the same month as the Blog.
I guess there are risks that macro authors/users need to be aware of, but request handling gives macros a lot of power to do useful things.
comment:7 by , 20 years ago
prevention against multiple instances
It does since a couple of minutes ago 8'):
I've actually updated the macro to fit the new trunk, and I've added this assertion.
req. args in macros
I do not have enough experience neither in Trac nor Python to know whether it's good or not to let the user access the request arguments, so it's up to you guys.
comment:8 by , 19 years ago
One reason that macro's need a request object is that trac.wiki.wiki_to_html
requires this as its third argument.
Perhaps there is another way to obtain a req object, but I'm not aware of it.
One question is why a macro would need to access request parameters?