/**
  * Invocation of hook SpecialPageBeforeExecute
  *
  * We use this hook to ensure that login/account creation pages
  * are redirected to HTTPS if they are not accessed via HTTPS and
  * $wgSecureLogin == true - but only when using the
  * mobile site.
  *
  * @param SpecialPage $special
  * @param string $subpage
  * @return bool
  */
 public static function onSpecialPageBeforeExecute(SpecialPage $special, $subpage)
 {
     $mobileContext = MobileContext::singleton();
     $isMobileView = $mobileContext->shouldDisplayMobileView();
     $context = $special->getContext();
     $out = $context->getOutput();
     $secureLogin = $context->getConfig()->get('SecureLogin');
     $request = $special->getContext()->getRequest();
     $skin = $out->getSkin()->getSkinName();
     $name = $special->getName();
     // Ensure desktop version of Special:Preferences page gets mobile targeted modules
     // FIXME: Upstream to core (?)
     if ($skin === 'minerva') {
         if ($name === 'Preferences') {
             $out->addModules('skins.minerva.special.preferences.scripts');
         }
         // Add default warning message to Special:UserLogin and Special:UserCreate
         // if no warning message set.
         if ($name === 'Userlogin' && !$request->getVal('warning', null) && !$context->getUser()->isLoggedIn()) {
             $request->setVal('warning', 'mobile-frontend-generic-login-new');
         }
     }
     if ($isMobileView) {
         if ($name === 'Search') {
             $out->addModuleStyles('skins.minerva.special.search.styles');
         } elseif ($name === 'Userlogin') {
             $out->addModuleStyles('skins.minerva.special.userlogin.styles');
             $out->addModules('mobile.special.userlogin.scripts');
             // make sure we're on https if we're supposed to be and currently aren't.
             // most of this is lifted from https redirect code in SpecialUserlogin::execute()
             // also, checking for 'https' in $wgServer is a little funky, but this is what
             // is done on the WMF cluster (see config in CommonSettings.php)
             if ($secureLogin && WebRequest::detectProtocol() != 'https') {
                 // get the https url and redirect
                 $query = $special->getContext()->getRequest()->getQueryValues();
                 if (isset($query['title'])) {
                     unset($query['title']);
                 }
                 $url = $mobileContext->getMobileUrl($special->getFullTitle()->getFullURL($query), true);
                 $special->getContext()->getOutput()->redirect($url);
             }
         }
     }
     return true;
 }