Fix detection of extension resource content type

For extension resources (loaded via /extension-resource/$EXT/$NAME) we
detect the content type simply by looking at the filename extensions
and the list of mappings in configuration.mimetypes.MIMETYPES.  (This is
in itself not perfect; there should be some way for the extension to
declare the content types of its resources itself.)

The old code used "everything after the first period" in the full
file-system path of the resource as its extension, used to look up the
content type.  This is obviously broken, and for instance breaks down
completely if the user hosting the extension has a period in his/her
user name, or if the extension's name contains a period.

The new code looks only at the resource's basename, and also tries to
look up every possible extension, longest first.  For example, given the
resource name "a.b.c.d" it will look up "b.c.d" first, then "c.d", and
finally "d".