Edgewall Software
Modify

Opened 19 years ago

Closed 19 years ago

Last modified 19 years ago

#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:

  1. hdf
  2. macro arguments
  3. 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 Christopher Lenz, 19 years ago

One question is why a macro would need to access request parameters?

comment:2 by Matthew Good, 19 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 Christopher Lenz, 19 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 Christopher Lenz, 19 years ago

Milestone: 0.9
Resolution: fixed
Status: newclosed

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 Emmanuel Blot, 19 years ago

Cc: ebcom@… 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 Matthew Good, 19 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 Emmanuel Blot, 19 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 trac-form@…, 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.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jonas Borgström.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Jonas Borgström to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.