Rewrite getDocumentFilename for simplicity and efficiency
Add dirnameshorten template variable which expands to the dirname with each path component, if longer than MAXNAMELEN, shortened to have a unique hash appended and be at MAXNAMELEN in length. Directory creation should never fail now.
Add archivefilename which generates a filename for archival purposes. The filename is shortened, if necessary, to include the hash of the filename, queryhashq, and extension.