/**
  * @param bool $rapidFail if true, render a form as a fail page rather than redirect
  * @param string $failPage either a wiki page title, or a URL to an external wiki
  *                         page title.
  * @param array $data information about the current request.
  *                    language, gateway, payment_method, and payment_submethod must be set
  * @param Psr\Log\LoggerInterface $logger
  * @return string full URL of the fail page, or just form name in case of rapidFail
  */
 private static function getFailPageFromParams($rapidFail, $failPage, $data, LoggerInterface $logger)
 {
     if (isset($data['language'])) {
         $language = $data['language'];
     } else {
         $language = WmfFramework::getLanguageCode();
     }
     // Prefer RapidFail.
     if ($rapidFail) {
         // choose which fail page to go for.
         try {
             $fail_ffname = GatewayFormChooser::getBestErrorForm($data['gateway'], $data['payment_method'], $data['payment_submethod']);
             return $fail_ffname;
         } catch (Exception $e) {
             $logger->error('Cannot determine best error form. ' . $e->getMessage());
         }
     }
     if (filter_var($failPage, FILTER_VALIDATE_URL)) {
         return self::appendLanguageAndMakeURL($failPage, $language);
     }
     // FIXME: either add Special:FailPage to avoid depending on wiki content,
     // or update the content on payments to be consistent with the /lang
     // format of ThankYou pages so we can use appendLanguageAndMakeURL here.
     $failTitle = Title::newFromText($failPage);
     $url = wfAppendQuery($failTitle->getFullURL(), array('uselang' => $language));
     return $url;
 }
 /**
  * normalize helper function.
  * If the language has not yet been set or is not valid, pulls the language code
  * from the current global language object.
  */
 protected function setLanguage()
 {
     $language = false;
     if ($this->isSomething('uselang')) {
         $language = $this->getVal('uselang');
     } elseif ($this->isSomething('language')) {
         $language = $this->getVal('language');
     }
     if ($language) {
         $language = strtolower($language);
     }
     if ($language == false || !WmfFramework::isValidBuiltInLanguageCode($language)) {
         $language = WmfFramework::getLanguageCode();
     }
     $this->setVal('language', $language);
     $this->expunge('uselang');
 }
 /**
  * Returns a valid mediawiki language code to use for all the DonationInterface translations.
  *
  * Will only look at the currently configured language if the 'language' key
  * doesn't exist in the data set: Users may not have a language preference
  * set if we're bouncing between mediawiki instances for payments.
  * @param array $data A normalized DonationInterface data set.
  * @return string A valid mediawiki language code.
  */
 public static function guessLanguage($data)
 {
     if (array_key_exists('language', $data) && WmfFramework::isValidBuiltInLanguageCode($data['language'])) {
         return $data['language'];
     } else {
         return WmfFramework::getLanguageCode();
     }
 }