<commit_before><?php

/*!
 * This file is part of {@link https://github.com/MovLib MovLib}.
 *
 * Copyright © 2013-present {@link https://movlib.org/ MovLib}.
 *
 * MovLib is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public
 * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * MovLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License along with MovLib.
 * If not, see {@link http://www.gnu.org/licenses/ gnu.org/licenses}.
 */
namespace MovLib\Presentation;

use \MovLib\Data\User\Full as FullUser;
use \MovLib\Presentation\Redirect\Temporary as TemporaryRedirect;
use \MovLib\Presentation\Partial\Navigation;

/**
 * The global language selection page.
 *
 * The language selection page is displayed if a user accesses MovLib without any language code specific subdomain. We
 * don't know what language the user might prefer and we don't want to guess (like many others are doing it, e.g. Google
 * and they're doing a really awful job there). Freedom of joice is the motto. This page is different than most other
 * MovLib page's and therefor we extend the abstract page and not the reference implementation.
 *
 * @author <NAME> <<EMAIL>>
 * @copyright © 2013 MovLib
 * @license http://www.gnu.org/licenses/agpl.html AGPL-3.0
 * @link https://movlib.org/
 * @since 0.0.1-dev
 */
class LanguageSelection extends \MovLib\Presentation\Page {


  // ------------------------------------------------------------------------------------------------------------------- Magic Methods


  /**
   * Instantiate new language selection presentation.
   *
   * @global \MovLib\Data\I18n $i18n
   * @global \MovLib\Kernel $kernel
   * @global \MovLib\Data\User\Session $session
   * @throws \MovLib\Presentation\Redirect\Temporary
   */
  public function __construct() {
    global $i18n, $kernel, $session;

    // If a signed in user is requesting this page we know where to send her or him.
    if ($session->isAuthenticated === true) {
      $user = new FullUser(FullUser::FROM_ID, $session->userId);
      throw new TemporaryRedirect("{$kernel->scheme}://{$user->systemLanguageCode}.{$kernel->domainDefault}/");
    }

    // If not render the page.
    $this->initPage($i18n->t("Language Selection"));
    $kernel->stylesheets[] = "language-selection";
  }

  /**
   * Format a single system language.
   *
   * @global \MovLib\Data\I18n $i18n
   * @global \MovLib\Kernel $kernel
   * @param string $languageCode
   *   The language code of the system language.
   * @return array
   */
  public function formatSystemLanguage($languageCode) {
    global $i18n, $kernel;
    $attributes = [ "rel" => "prerender" ];
    if ($languageCode != $i18n->languageCode) {
      $attributes["lang"] = $languageCode;
    }
    return [ "//{$languageCode}.{$kernel->domainDefault}/", \Locale::getDisplayLanguage($languageCode, $languageCode), $attributes ];
  }

  /**
   * @inheritdoc
   */
  protected function getFooter() {
    global $i18n, $kernel;
    return
      "<footer id='f'><div class='c'><div class='r'><p>{$i18n->t(
        "Is your language missing from our list? Help us translate {0} to your language. More information can be found at {1}our translation portal{2}.",
        [ $kernel->siteName, "<a href='//{$kernel->domainLocalize}/'>", "</a>" ]
      )}</p></div></div></footer>"
    ;
  }

  /**
   * @inheritdoc
   */
  protected function getHeader() {
    return "";
  }

  /**
   * @inheritdoc
   */
  protected function getMainContent() {
    global $i18n, $kernel;

    // Build the navigation.
    $navigation           = new Navigation($i18n->t("Available Languages"), array_keys($kernel->systemLanguages), [ "class" => "well well-lg" ]);
    $navigation->glue     = " / ";
    $navigation->callback = [ $this, "formatSystemLanguage" ];

    return
      "<main class='{$this->id}-content' id='m' role='main'><div class='c'>" .
        "<h1 class='cf'>" .
          "<img alt='' height='192' src='{$kernel->getAssetURL("logo/vector", "svg")}' width='192'>" .
          "<span>{$kernel->siteNameAndSloganHTML}</span>" .
        "</h1>" .
        "<p>{$i18n->t("Please select your preferred language from the following list.")}</p>{$navigation}" .
      "</div></main>"
    ;
  }

}
<commit_msg>We need to use link elements for prefetch / prerender<commit_after><?php

/*!
 * This file is part of {@link https://github.com/MovLib MovLib}.
 *
 * Copyright © 2013-present {@link https://movlib.org/ MovLib}.
 *
 * MovLib is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public
 * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * MovLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License along with MovLib.
 * If not, see {@link http://www.gnu.org/licenses/ gnu.org/licenses}.
 */
namespace MovLib\Presentation;

use \MovLib\Data\User\Full as FullUser;
use \MovLib\Presentation\Redirect\Temporary as TemporaryRedirect;
use \MovLib\Presentation\Partial\Navigation;

/**
 * The global language selection page.
 *
 * The language selection page is displayed if a user accesses MovLib without any language code specific subdomain. We
 * don't know what language the user might prefer and we don't want to guess (like many others are doing it, e.g. Google
 * and they're doing a really awful job there). Freedom of joice is the motto. This page is different than most other
 * MovLib page's and therefor we extend the abstract page and not the reference implementation.
 *
 * @author <NAME> <<EMAIL>>
 * @copyright © 2013 MovLib
 * @license http://www.gnu.org/licenses/agpl.html AGPL-3.0
 * @link https://movlib.org/
 * @since 0.0.1-dev
 */
class LanguageSelection extends \MovLib\Presentation\Page {


  // ------------------------------------------------------------------------------------------------------------------- Magic Methods


  /**
   * Instantiate new language selection presentation.
   *
   * @global \MovLib\Data\I18n $i18n
   * @global \MovLib\Kernel $kernel
   * @global \MovLib\Data\User\Session $session
   * @throws \MovLib\Presentation\Redirect\Temporary
   */
  public function __construct() {
    global $i18n, $kernel, $session;

    // If a signed in user is requesting this page we know where to send her or him.
    if ($session->isAuthenticated === true) {
      $user = new FullUser(FullUser::FROM_ID, $session->userId);
      throw new TemporaryRedirect("{$kernel->scheme}://{$user->systemLanguageCode}.{$kernel->domainDefault}/");
    }

    // If not render the page.
    $this->initPage($i18n->t("Language Selection"));
    $kernel->stylesheets[] = "language-selection";
  }

  /**
   * @inheritdoc
   */
  protected function getFooter() {
    global $i18n, $kernel;
    return
      "<footer id='f'><div class='c'><div class='r'><p>{$i18n->t(
        "Is your language missing from our list? Help us translate {0} to your language. More information can be found at {1}our translation portal{2}.",
        [ $kernel->siteName, "<a href='//{$kernel->domainLocalize}/'>", "</a>" ]
      )}</p></div></div></footer>"
    ;
  }

  /**
   * @inheritdoc
   */
  protected function getHeader() {
    return "";
  }

  /**
   * @inheritdoc
   */
  protected function getMainContent() {
    global $i18n, $kernel;

    $prerender = $menuitems = null;
    foreach ($kernel->systemLanguages as $code => $locale) {
      $href = "//{$code}.{$kernel->domainDefault}/";
      // Doesn't validate, but the browsers like it. Please note that Chrome doesn't prerender more than one URL and
      // no HTTPS pages; there's nothing we can do about that. But it works great in Gecko and IE.
      $prerender  .= "<link rel='prefetch' href='{$href}'><link rel='prerender' href='{$href}'>";
      $menuitems[] = [ $href, \Locale::getDisplayLanguage($locale, $code), ($code == $i18n->languageCode ? null : [ "lang" => $code ]) ];
    }

    // Build the navigation.
    $navigation       = new Navigation($i18n->t("Available Languages"), $menuitems, [ "class" => "well well-lg" ]);
    $navigation->glue = " / ";

    return
      "{$prerender}<main class='{$this->id}-content' id='m' role='main'><div class='c'>" .
        "<h1 class='cf'>" .
          "<img alt='' height='192' src='{$kernel->getAssetURL("logo/vector", "svg")}' width='192'>" .
          "<span>{$kernel->siteNameAndSloganHTML}</span>" .
        "</h1>" .
        "<p>{$i18n->t("Please select your preferred language from the following list.")}</p>{$navigation}" .
      "</div></main>"
    ;
  }

}

{'fraction_non_alphanumeric': 0.16655773420479303, 'fraction_numerical': 0.01045751633986928, 'mean_word_length': 2.967588591184097, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 99, 'https://': 6, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '361649', 'n_tokens_mistral': 2758, 'n_tokens_neox': 2646, 'n_words': 868}