Requests for comment/MediaWiki HTTPS policy

This is a follow / extension of the Login security RFC.

Background
The WMF transitioned to use $wgSecureLogin for nearly all sites in Aug 2013. CentralAuth had several updates to ensure that the site and user preferences around http vs. https were respected throughout the central login as well.

The WMF needs to handle a few distinct use cases in our https policy:
 * Most users should enter their password into an https page, and submit the password via https
 * Some users want to opt out of using https after they have logged in, by setting a user preference
 * User from China and Iran should not be required to use https for login
 * For users of Wikipedia Zero, many ISP's will not zero-rate encrypted traffic, so users should not be redirected to https

In the future, some projects only want to use https.

Problem
The code is fairly brittle (bugs 71716, etc), and always consistent between core and centralauth. It's also difficult to know what the expected behavior is in the interactions between:
 * The site enforcing wgSecureLogin, and for centralauth, if the central login wiki is configured different from the local wiki
 * The user option opting into using a secure connection while logged in
 * The IP-based blacklist to prevent redirecting users to https
 * The hook to override redirecting to a secure connection when the 'forceHTTPS' cookie is set, used by Zero
 * Whether the user clicked the login link from an http or https page

Additionally, MediaWiki has no way to specify that privileged user (Admin, Checkuser, etc) must use a secure connection, and potentially login using an insecure session.

Proposal
Make the use of http or https governed by a set of site, user, and ip-based policies, and allow the user to set their own preferences when allowed by the policy.

The policies should try to cover nearly every case that site administrators want to enforce, however the policy mechanism should be extensible by extensions that want to make different decisions or decisions based on other factors (e.g., the use of 2-factor authentication for login).

The decisions to use http vs https, setting cookies with the 'secure' flag, and setting the 'forceHTTPS' cookie would be governed by the following, in this order:
 * 1) Site policy
 * 2) IP-based policy
 * 3) User policy
 * 4) User preference, if allowed by the other policies.

For example, when an anonymous user is rendering the login link on a page (determining http vs. https), MediaWiki will first check the site policy to see if using a secure login page is enforced. It will next check if there any IP-based policies based on the incoming IP address. Since the user is anonymous, no user-based policies will apply. If an anonymous user preference is implemented to adjust http vs https login pages, then that preference would be consulted last. During this process, each policy is able to indicate that it's decision is final, and further policies will not be consulted about the decision.

Code to make the decision when to use https or not would look something like:

MediaWiki would setup the policies with something like: