Hi Caleb, On 02/27/2011 02:00 PM, Caleb James DeLisle wrote:
When I was looking for places where hasProgrammingRights is called, I found calls to c.x.x.api.Context.get() in the templates. I discovered that there is code in the templates which implicitly calls $xcontext.get('something') by calling $xcontext.something where there is no function Context.getSomething().
Since this is so easy and there is no way to know that anything is wrong since Context.get() returns null if you don't have PR, I am proposing that we do away with the practice of implicitly referring to functions in $context entirely.
I don't understand what is the problem. Can you be more explicit? Thanks, Marius
I used the following command to find implicit context references and I have filled in the mappings which I determined manually
user@debo8:~/wrk/xwiki.clone/xwiki/platform/web/trunk/standard/src/main/webapp/templates$ find ./ -name '*.vm' -exec grep '$xcontext\.[a-zA-Z0-9]*[^a-zA-Z0-9\(]' {} \; | sed -n -e 's/\($xcontext\.[a-zA-Z0-9]*[^a-zA-Z0-9(]\)/\n\1\n/p' | grep '^$xcontext' | sort $xcontext.action= $xcontext.action= $xcontext.action= $xcontext.action $xcontext.action $xcontext.action $xcontext.action $xcontext.action $xcontext.action $xcontext.action $xcontext.action, $xcontext.action, $xcontext.action, $xcontext.action, $xcontext.action, $xcontext.action, $xcontext.action, $xcontext.action, $xcontext.action, $xcontext.action, $xcontext.action, $xcontext.action, $xcontext.action. $xcontext.action) ^-- maps to Context.getAction()
$xcontext.database $xcontext.database) $xcontext.database) $xcontext.database) $xcontext.database) $xcontext.database) $xcontext.database) ^-- maps to Context.getDatabase()
$xcontext.language" $xcontext.language" $xcontext.language" ^-- maps to Context.getLanguage()
$xcontext.tocData ^-- this line is broken entirely, it maps to context.get('tocData') but the line is: #set ($xcontext.tocData = $tocData) which is simply invalid and I can't even figure out what it would do.
$xcontext.user $xcontext.user $xcontext.user $xcontext.user $xcontext.user $xcontext.user $xcontext.user $xcontext.user $xcontext.user $xcontext.user $xcontext.user $xcontext.user, $xcontext.user, $xcontext.user, $xcontext.user, $xcontext.user, $xcontext.user, $xcontext.user, $xcontext.user, $xcontext.user, $xcontext.user, $xcontext.user, $xcontext.user, $xcontext.user, $xcontext.user. $xcontext.user. $xcontext.user. $xcontext.user" $xcontext.user" $xcontext.user) $xcontext.user) $xcontext.user) $xcontext.user) $xcontext.user) ^-- Maps to $xcontext.getUser()
$xcontext.wiki, $xcontext.wiki, $xcontext.wiki, ^-- Maps to $xcontext.get('wiki') I think this is the source of most of the messages and since it appears to be relatively new code, it convinces me that the $context.blah pattern is simply unsafe and should be abandoned at least for the xcontext object.
I would like to fix these now and establish a best practice of avoiding the use of these in the future for $xcontext. I myself avoid this pattern entirely but I do not have a compelling reason to propose it as a best practice except for $context.
WDYT?
Caleb
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs