Don't use <br/> tags for newlines in Markdown text in e-mails.

We had the "nl2br" filter applied for Markdwon text, which caused every
newline to have a <br/>. However, these appeared inside a <pre/>, and we
still had newlines. The end result was that we had a blank line for
every line of text.

I can't see any reason why we'd need this filter, so I've removed it.
This results in proper-looking e-mails.

Reviewed at https://reviews.reviewboard.org/r/6286/
Fix URLs to users on Local Sites.

The URLs shown in the user infobox, in the Submitter field on a review
request, and in the target reviewers lists weren't correct on Local
Sites. We were using get_absolute_url, and need to instead use
local_site_reverse.

After this change, all URLs to users should be correct.

Reviewed at https://reviews.reviewboard.org/r/6289/
Fix the display of the floating review banners while scrolling.

The floating review draft banners had some issues when scrolling off the
edge of a review. Due to some imprecise calculations, the page would
appear to stutter for a brief moment while scrolling, as the banner
jumped back and forth between being docked to the page and floating over
the page.

To fix the stutter, we needed to set the placeholder to have the exact
height and margins of the original banner, pre-float. This kept the
container the same size. We also needed to fix some of the calculations
to not go in/out of float mode too soon.

With this fixed, the page no longer jumped, but the banner would just
disappear as we hit the edge of the review. Now, the banner will appear
to dock at the bottom of the review, and just scroll out of view as the
user scrolls further down.

The end result is a buttery-smooth scrolling experience.

Reviewed at https://reviews.reviewboard.org/r/6293/
Fix errors when resizing the review request page.

The resize layout scheduling code, which has been fixed a couple
different times, was still broken. Resizing would end up calling
_scheduleResizeLayout with the window as the context. We now include
this function in the bindAll() in order to ensure the context is set
correctly.

Reviewed at https://reviews.reviewboard.org/r/6294/
Fix showing Markdown field changes with 'None' values.

When rendering a Markdown field in a change description box, we weren't
ensuring that the old or new values were strings. They could be None,
which is a valid value indicating there was no content before. This
would end up breaking render_markdown().

We now convert to an empty string if it's None.

Fixes bug #3549
Reviewed at https://reviews.reviewboard.org/r/6290/
Fix 'interdiff-revision' field name in the diff context resource.

When I added this resource, I copied the field names that are used for POST/PUT
operations (which use underscores), rather than those in GET operations (which
use hyphens). This worked from the web UI (where we assemble the URL directly),
but caused problems when using the RBTools API (which transforms all
underscores into hyphens for GET requests). This change fixes that field name
to be 'interdiff-revision'.

Testing done:
Verified that diff and interdiff selection still worked properly using the new
URL parameters.

Reviewed at https://reviews.reviewboard.org/r/6292/
Merge branch 'release-2.0.x'
Fix bomb when showing differences between two diff versions

Fix crash when trying to show the differerence between two versions of a patch
(e.g. with a URL like r/31/diff/2-3/).  RawFileDiffData was passing self.binary
to tool.get_parser(), which fails because the buffer object has no splitlines()
method.  Fixed by passing self.content instead.

Testing Done:
Ad-hoc testing - I now see a diff rather than a stack trace.

Reviewed at https://reviews.reviewboard.org/r/6297/
Remove deprecation warning during cron job.

Change crontab entry to use clearsessions in favour of cleanup as cleanup has
been deprecated.

Testing Done:
Running `./reviewboard/manage.py cleanup` causes warning messages to be
outputted, but running `./reviewboard/manage.py clearsessions` does not.

Bugs closed: 3535

Reviewed at https://reviews.reviewboard.org/r/6300/
Merge branch 'release-2.0.x'
Fix usage of timedelta.total_seconds() in condensediffs.

The `total_seconds()` method doesn't exist in Python 2.6, so we can't use it
yet. This change replaces it with the equivalent implementation (and moves us
over to using true division throughout this file as a side effect).

Testing done:
Condensed some diffs.

Reviewed at https://reviews.reviewboard.org/r/6304/
Merge branch 'release-2.0.x'
Allow local_site_reverse to take an actual LocalSite.

local_site_reverse was able to take a LocalSite's name, or a request
object, but if you actually had a LocalSite (or None), you'd have to
write your own conditional to extract the name and pass it.

Now, local_site_reverse can take a LocalSite. This saves a database
query, if one is already available, and simplifies calling code.

Reviewed at https://reviews.reviewboard.org/r/6302/
Fix Local Site and validation issues with post-commit hooks.

The post-commit hook support in hosting services had a few issues that
could lead to unintentionally closing the wrong review requests on
other repositories. They also weren't compatible with Local Sites.

The URL for the hook identified the repository, and the URL also
contained the hosting service ID, but we wouldn't use either to properly
validate the repositories. That meant that if a hook was set up to point
to repository 1 on GitHub, and then had a commit referencing a review
request on repository 2 on Bitbucket, things would break.

We now capture the hosting service ID and pass it, the local site name,
and the repository ID to the function that handles closing review
requests. That function will then use that information to narrow down
the list of repositories being processed, in order to avoid operating on
some other review request. The function has also been rewritten to
minimize the number of SQL queries needed.

Local Sites were broken because nothing bothered to check for them. The
URLs were added to the root urlpatterns, and not to
localsite_urlpatterns. There was some code that did something weird with
trying to get a Local Site from a resolved URL, but that didn't really
do anything. Now everything is wired up to allow for hooks on Local
Sites and to restrict operations to review requests on the Local Site.

There's a few other changes here and there to help consistency and to
minimize code. For instance, we had different error responses for
invalid payloads, and they weren't really correct. We just use HTTP 400
now.

Unit tests were added for the three services that support post-commit
hooks. They test hooks with and without Local Sites, and test invalid
repository IDs, Local Site names, and service IDs.

The unit test for testing service registration was also split up into
several tests, since it was testing several things.

Reviewed at https://reviews.reviewboard.org/r/6303/
Merge branch 'release-2.0.x'
Make the Review Dialog use inlineEditors.

Traditionally, the Review Dialog (created either via the "Review" action or
"Edit Review" in the draft review header) had a text box for the body top and
body bottom headers, and a text box for each comment.

This made a lot more sense when the comments were plain text, and the contents
of the text inputs was the same as what the user would see. One thing that
always bothered me about the addition of markdown formatting for comments was
that it was impossible to truly know what you'd get after a review was
published, since we never showed the comments in rendered form. It also meant
that we were potentially creating a huge number of CodeMirror instances, which
made the Review Dialog pretty slow.

This change replaces all the text boxes with rendered text. This makes it more
or less resemble what the user would see after publishing the review. Headers
and footers can be added via the relevant links (either "Add header", "Add
footer", or "Add text" depending on the number of comments), which works a lot
like "Add comment" in the review replies.

The individual comments and other states (whether an issue is open, ship it)
are now all "instant apply". The dialog therefore no longer has "Save" and
"Cancel" buttons, but just a "Close" button. Changes to each individual comment
can still be cancelled.

Testing done:
- Clicked "Review" without a pending draft review. Saw the ship-it checkbox and
  an open/focused inline editor.
- Checked that checking or unchecking "Ship it" would send a request to the
  server, editing the review.
- Clicked "Review" without a pending draft review. Clicked "Ship it" and
  published. Saw a review with "Ship it".
- Edited draft reviews, changing comment text and issue state.
- Added and removed headers and footers, checking that everything was saved
  correctly, and that when the relevant text was empty/null, that the "Add ..."
  links were shown.
- Installed the severity extension and verified that changes to the severity
  fields were saved when clicking "Close" and "Publish".

Reviewed at https://reviews.reviewboard.org/r/6239/
Add a JavaScript view for showing modal dialogs.

RB.DialogView is a wrapper around $.modalBox() that makes it easy to
construct, show, and hide modal dialogs. It can be instantiated and
bound to an element to show the contents of that element as a dialog, or
it can be subclassed to allow another view to act as a dialog.

Reviewed at https://reviews.reviewboard.org/r/6305/
Add a central function for returning the server URL.

We had a lot of code that attempted to build a server URL by fetching a
Site, SiteConfiguration, doing a URL lookup, and building a string. This
was getting silly, so I've added two central functions for this purpose:
get_server_url() and build_server_url().

get_server_url() returns the URL to the root of the server (or a Local
Site, if one of the identifying arguments are provided).

build_server_url() builds a URL off of the server URL. It's a
convenience around calling `urljoin(get_server_url(), ...)`.

Many call sites have been updated to use these new functions. Many still
remain, as we have templates that are building their own URLs, and some
code that's doing fancier URL building, and I didn't want to risk
breaking them right now.

This also fixes a bug with the e-mail headers. We were always referring
to the root of the site, rather than the Local Site, which made it
harder to filter when working on multiple Local Sites.

Reviewed at https://reviews.reviewboard.org/r/6307/
Fix review dialog js-tests.

I had fixed up some of the relevant tests during my overhaul of the review
dialog, but apparently the last time I ran them was before I removed
_bodyTopEditor and _bodyBottomEditor. This change fixes those tests to use the
new _bodyTopView and _bodyBottomView, and does a little bit of extra cleanup
while I was in there.

Testing done:
Ran js-tests. After this change there are still some failures, but all of the
review dialog tests now pass.

Reviewed at https://reviews.reviewboard.org/r/6308/
Fix bug-id format string in js-tests.

The tests for linkification of bugs was never updated when we merged the new
bug-tracker stuff, and so it was still using '%s' instead of '--bug_id--'. This
change fixes that.

Testing done:
Ran js-tests.

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