[FIX] Make sure there are no trailing spaces when generating references, skip values that look like argument variables when building references

git-svn-id: file:///var/local/code.tiki.org/tikisvn/branches/12.x@48244 b456876b-0849-0410-b77d-98878d47e9d5