Make transaction CFs correctly limited to the correct queues

In 74e6f62, the $queues{...}++ line was moved from above the "next
unless ..." line to below it.  This changes the meaning of %queues, from
"the set of queues of the tickets listed" to "the set of queues of
tickets _changed_."  This causes the transaction CF list to be broader
than expected in most cases.

Make the transaction CFs limited based on $seen_queues, which is
computed based on all tickets listed, and remove the no-longer-used
%queues.
canonicalize date/datetime cfs in ticket history and search results
show original text in editor when reediting

before we only show the error messages returned from server, which is bad for
user to correct.

I also tweaked error messages a bit so it won't affect the upcoming
submission, e.g. error messages from server could be:

    # Could not create ticket.
    # Foo: Unknown field

    Foo: bar

after tweaking, it becomes:

    # Could not create ticket.
    # Foo: Unknown field
    #
    #     Foo: bar

see also #22287
Don't output to STDOUT for successfully sent digests, by default

Most commonly, digests are sent from cron jobs, where any output to
STDOUT is sent to the administrator.  Printing on every successfully
sent digest will thus lead to the administrator getting sent daily mail
which is essentially content-less.  This might lead them to redirect the
output to /dev/null, which would cause them to be ignorant when sending
messages _failed_.

Restrict output to STDOUT to only when messages failed to send, by
default.  The new --verbose option can be used to restore the old
behavior of printing for every message sent.
Limit the Admin Queues list to 50 rows per page by default

Otherwise instances with a large number of queues take forever to load
and display (such as rt.cpan.org).
extract our code that fetches table names

keep function private, so far we use it in upgrade
scripts and tests.
require newer DBD::Pg on Pg 9.2 for upgrade

We use DBI's table_info method in upgrade scripts.
It fails on Pg 9.2 with old DBD::Pg driver. We don't
have to bump required version for all Pg users, but
can help users of Pg 9.2 to solve the problem by
providing better error message.
Fix uninitialized value warning in RT::Principal::HasRight

HasRight was storing the cananicalized value of a passed-in Right
argument back in the argument hash, so the debug log output on an
invalid right had an uninitialized value rather than the invalid right
argument.

Use a temporary variable to store the canonicalized value, in case
canonicalization fails and we need access to the pre-canonicalized form.
Tests for right name canonicalization

Tests inserting into the database and pulling back out of the database.
Note that as RT::User->Load is used, the user/email must already exist
If __check_user returns false, attempting to use that value in a warning is pointless

Store the original user or group, and use that value in the warning.
Allow CustomFieldLookupType to be called as a class method

(cherry picked from commit 1ff3f2b0a97d1e336ced7542ce2b0201ff5309fc)
Add an ObjectTypeFromlookupType method and document RecordClassFromLookupType

RecordClassFromLookupType is useful when joining to ObjectCustomFields,
but there wasn't an existing method for code that wants to join to
ObjectCustomFieldValues, so we can borrow the code and tweak the regex a
bit.
ObjectType/RecordTypeFromLookupType as class methods

Where LookupType must be passed as an argument.
Refactor part of LimitToGlobalOrObjectId into LimitToObjectId

Useful when you only want to find CFs applied to a certain object and
not global ones too.
Rename some variables that will become confusing.

As these join aliases start to refer to transaction cfs and not just
ticket cfs, it is really weird to have everything named TicketCFs
Decipher TicketSQL CF identifiers using a passed in LookupType

The LookupType is necessary to find the correct CF by name, as well as
to support the arcane CF.ObjectId.{CFName} syntax, for arbitrary object
types (not just ticket CFs on RT::Queue).

Potential syntax made possible, for example:

    TxnCF.{CFName}
    TxnCF.Queue.{CFName}
    ArticleCF.Class.{CFName}

The CF lookup behaviour of CF.Queue.{CFName} changes slightly due to
changes in which custom fields API is used.  Most notably, such syntax
previously exhibited the following behaviour but no longer does:

    • Disabled CFs could be found if no enabled CFs matched.
    • The existence of multiple matching CFs with the same name (& within
      the same queue) was ignored; the first was the only one used.

As CF.Queue.{CFName} is fairly arcane syntax, these changes shouldn't
affect most usage of TicketSQL.  It is unlikely that anyone using the
extended syntax is intentionally relying on any of the discontinued
behaviour noted above.  Disabled CFs, even if found, are eliminated from
results by later code.  The two behaviour changes are effectively bug
fixes.

A case-sensitivity difference between CF.{Name} and CF.Queue.{Name} is
preserved by checking which syntax was used.  This is bending over
backwards solely for the sake of compatibility within the 4.0 series.
It is conceivable that someone is relying on it, knowingly or not, and
it is easy enough to replicate.  In 4.2, we should remove this
distinction.
Refactor _CustomFieldJoin to take a LookupType

… so that we can join to the correct table if not Tickets.  An
extensible data structure is introduced to determine how to join CFs to
applied objects.

This lets _CustomFieldJoin handle joining for transaction CFs or other
CFs which may want to be searched.
Refactor _CustomFieldLimit to use a LookupType in %FIELD_METADATA

Potential new search clauses, such as searching transaction CFs, want to
match all the different ways that ticket CFs can.  It makes sense to
just wrap the limits in a LookupType change (especially since
_CustomFieldLimit happens to be recursive for IP and Date searches).
Fix horrendous load order of shredder tests

They started failing because of an added
RT::Ticket->CustomFieldLookupType call.

The RT::Ticket load order is also awful and doesn't setup it's base
class until very late, including after importing other packages.