Fix duplicate "Markdown Reference" links.

MarkdownEditor could end up creating duplicate "Markdown Reference"
links when opening the same editor more than once. An easy repro case is
to draft a reply, save, and open it again. Every time that is done,
there would be an extra link.

We now check for the existence of a link before attempting to add one.

Reviewed at https://reviews.reviewboard.org/r/5749/
Don't allow "Hide Closed" to bleed into dashboard datagrids.

The toggle for hiding closed review requests on the user and all review request
grids would set a profile flag, and then bled into the "All Outgoing" datagrid.
This change adds some plumbing to prevent this from happening.

Testing done:
Reproduced the bug, and then tried with this change. Saw that with the profile
flag set, the dashboard datagrids showed closed review requests, but the others
did not.

Fixes bug 3319.

Reviewed at https://reviews.reviewboard.org/r/5746/
Normalize filediff filenames during creation.

Some of the diff APIs that we're using for post-commit review request creation
(looking at you, GitHub) give us filenames with leading slashes. This doesn't
match what we have elsewhere, which makes things annoying if filenames don't
match.

Testing done:
Used this in conjunction with testing out the suggested reviewers feature. Saw
that when I created a post-commit review request, the filenames matched what
would have been created from rbtools.

Reviewed at https://reviews.reviewboard.org/r/5734/
Switch to more explicit CSS styles for boxes in Review Board.

Boxes in Review Board now follow the new convention in Djblets of
prefixing all related CSS classes with "box-" and wrapping the title
element in a "box-head" div.

This matches what we've been using in RBCommons, helping us to keep
things consistent, and prevents conflicts with existing "title" and
"main" CSS classes.

Reviewed at https://reviews.reviewboard.org/r/5754/
Fix UnicodeDecodeError while LDAP-authenticating when user dn contains non-ascii symbols

Some logging statements would fail because we were trying to format a
bytestring. This change adds code to decode bytes that we get from LDAP into
unicode strings before logging.

This also fixes a bunch of logging statements to use the built-in formatter,
and pass exc_info=1 to all calls that are formatting an exception.

Reviewed at https://reviews.reviewboard.org/r/5751/
Style .box-head separately from .box-title.

The .box-title class was being styled with a border and background, but
this really belongs in .box-head. By doing this, it's easier for us to
change the style of one or the other, and to add additional elements
inside of .box-head.

Reviewed at https://reviews.reviewboard.org/r/5755/
Added sandboxing to action_hooks

This change adds sandboxing to the various action hooks (which allow users to
insert buttons or menu items into various pieces of the UI), so that broken
extensions won't break everything.

Testing Done:
Unit testing done - tested all 5 different action hooks (DiffViewerActionHook,
HeaderActionHook, HeaderDropdownActionHook, ReivewRequestActionHook,
ReviewRequestDropdownActionHook) with and without the sandboxing. Ran on all
tests in extensions/tests.py

Reviewed at https://reviews.reviewboard.org/r/5710/
Fix upgrading from pre-1.7 databases.

rb-site does a check to see if a dedup operation should be run. This
ends up checking some modern fields that didn't exist pre-1.7.

We now wrap this and catch the exception, handling the case where the
operation fails due to a database error. The assumption we make is that
if there's a database error, we're likely upgrading from a database that
doesn't have these columns, and a dedup is probably needed.

Reviewed at https://reviews.reviewboard.org/r/5756/
Prevent caching of filediffs when condensing diffs.

Some users reported running out of memory when attempting to condense
diffs on large databases. This is caused by Django's default behavior
of caching retrieved objects when evaluating a queryset. It'd end up
caching all objects it'd fetch, eating up all memory.

Using iterator() bypasses this, preventing caching and giving us the
objects directly. It should prevent the memory issues people were
hitting.
Fix unit tests for diff filenames.

My fix to strip off leading slashes in filenames broke one of the unit tests
for post-commit review request creation. The fix is just trivially updating the
expected result.

Testing done: Ran unit tests.
Google Code post-receive hook

This is a Google Code post-receive hook that will automatically close review
requests as "submitted" after a push. To determine which review requests should
be closed, it scans through each commit's commit message for the following
strings (case-insensitive): "Reviewed at <reviewboard_url>/r/<id>" or "Review
request #<id>".

This is what the JSON payload looks like:
http://code.google.com/p/support/wiki/PostCommitWebHooks

Testing Done:
All tests performed using an SVN and Mercurial repositories.

1) Push with the review request id in the commit message. Review request
   closed.
2) Push without a review request id in the commit message. (Error: Review
   request does not exist)
3) Push with non existent review request id. (Error: Review request does not
   exist)
4) Push with review id in the message that is already submitted. (logged a
   warning: request id already submitted.)
5) Push with review id in the message that has been marked as discarded.
   (review request marked as submitted.)

Reviewed at https://reviews.reviewboard.org/r/5744/
Fix permission name for creating repositories.

The Repository API already had some plumbing to allow users with a given
permission to create repositories regardless of their admin/staff status, but
it was using the wrong permission name. Trivial change.

Testing done: Ran unit tests.

Fixes bug 3307.
Merge branch 'release-1.7.x' into release-2.0.x
Change the URLs and method names for the new close webhooks.

The webhooks that close review requests after code is committed had the URL
"post-receive", which doesn't explain what it does, and the method names had
similar issues. I've gone through and changed both the URLs and the resulting
view names to be clearer.

Testing done: Ran unit tests.

Reviewed at https://reviews.reviewboard.org/r/5760/
Support building media with parallel-installed Django

On systems such as Fedora where older versions of Django are installed as
alternative versions (and not directly importable), we need to ensure that we
are importing exactly the right version of the Django modules.

This patch adds a new variable in the reviewboard __init__.py that is imported
by both setup.py and build-media.py to ensure that they are both relying on the
same version of Django.

Testing Done:
Built successfully on Fedora.

Reviewed at https://reviews.reviewboard.org/r/5690/
Merge branch 'release-1.7.x' into release-2.0.x
Added sandboxing to CommentDetailDisplayHook

This change adds exception handling so that broken extensions which use
CommentDetailDisplayHook won't take down the reviews page. This includes new
unit tests for this behavior.

Testing Done:
Unit testing - tested both render_review_comment_detail and
render_email_comment_detail with and without sandboxing

Reviewed at https://reviews.reviewboard.org/r/5709/
Add some error handling to autocomplete.

This is a minimal version of how the backbone models handle errors, except that
I put the JSON parsing into the error callback rather than directly into the
autocomplete library, in order to keep the latter more generic.

Testing Done:
All unit tests pass, except some VCS-specific ones, which were skipped.

Reviewed at https://reviews.reviewboard.org/r/5766/
Use imp.find_module instead of import.

Trivial change to avoid a pyflakes warning.
Add support for auth-backend UserQueryErrors.

Extensions with custom AuthBackends can now raise a UserQueryError, with a
detailed message, from within a query_users() method. It will be caught and
turned into a web API USER_QUERRY_ERROR.

Testing Done:
All unit tests pass except for some VCS-specific ones, which are skipped.

Manually verified that a UserQueryError with a custom message passed from an
extension gets included in an AJAX error response.

Reviewed at https://reviews.reviewboard.org/r/5771/