Merge "Add config for serving main Page from the domain root"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 23 Sep 2019 15:28:03 +0000 (15:28 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 23 Sep 2019 15:28:03 +0000 (15:28 +0000)
1  2 
includes/DefaultSettings.php
includes/Title.php

@@@ -2733,17 -2733,16 +2733,17 @@@ $wgExtensionInfoMTime = false
   * although they are sometimes still referred to as Squid settings for
   * historical reasons.
   *
 - * Achieving a high hit ratio with an HTTP proxy requires special
 - * configuration. See https://www.mediawiki.org/wiki/Manual:Squid_caching for
 - * more details.
 + * Achieving a high hit ratio with an HTTP proxy requires special configuration.
 + * See https://www.mediawiki.org/wiki/Manual:Performance_tuning#Page_view_caching
 + * for more details.
   *
   * @{
   */
  
  /**
   * Enable/disable CDN.
 - * See https://www.mediawiki.org/wiki/Manual:Squid_caching
 + *
 + * See https://www.mediawiki.org/wiki/Manual:Performance_tuning#Page_view_caching
   *
   * @since 1.34 Renamed from $wgUseSquid.
   */
@@@ -4445,8 -4444,7 +4445,8 @@@ $wgCentralIdLookupProvider = 'local'
   * The checks supported by core are:
   *    - MinimalPasswordLength - Minimum length a user can set.
   *    - MinimumPasswordLengthToLogin - Passwords shorter than this will
 - *            not be allowed to login, regardless if it is correct.
 + *            not be allowed to login, or offered a chance to reset their password
 + *            as part of the login workflow, regardless if it is correct.
   *    - MaximalPasswordLength - maximum length password a user is allowed
   *            to attempt. Prevents DoS attacks with pbkdf2.
   *    - PasswordCannotMatchUsername - Password cannot match the username.
@@@ -4992,8 -4990,6 +4992,8 @@@ $wgBlockAllowsUTEdit = true
  
  /**
   * Allow sysops to ban users from accessing Emailuser
 + * @deprecated since 1.34; `$wgGroupPermissions['sysop']['blockemail'] = true;`
 + * should be used instead
   */
  $wgSysopEmailBans = true;
  
@@@ -9094,6 -9090,13 +9094,13 @@@ $wgSpecialSearchFormOptions = []
   */
  $wgNativeImageLazyLoading = false;
  
+ /**
+  * Option to whether serve the main page as the domain root
+  * @since 1.34
+  * @var bool
+  */
+ $wgMainPageIsDomainRoot = false;
  /**
   * For really cool vim folding this needs to be at the end:
   * vim: foldmarker=@{,@} foldmethod=marker
diff --combined includes/Title.php
@@@ -1561,32 -1561,14 +1561,32 @@@ class Title implements LinkTarget, IDBA
         * Get a Title object associated with the talk page of this article
         *
         * @deprecated since 1.34, use getTalkPageIfDefined() or NamespaceInfo::getTalkPage()
 -       *             with NamespaceInfo::canHaveTalkPage().
 +       *             with NamespaceInfo::canHaveTalkPage(). Note that the new method will
 +       *             throw if asked for the talk page of a section-only link, or of an interwiki
 +       *             link.
         * @return Title The object for the talk page
         * @throws MWException if $target doesn't have talk pages, e.g. because it's in NS_SPECIAL
         *         or because it's a relative link, or an interwiki link.
         */
        public function getTalkPage() {
 -              return self::castFromLinkTarget(
 -                      MediaWikiServices::getInstance()->getNamespaceInfo()->getTalkPage( $this ) );
 +              // NOTE: The equivalent code in NamespaceInfo is less lenient about producing invalid titles.
 +              //       Instead of failing on invalid titles, let's just log the issue for now.
 +              //       See the discussion on T227817.
 +
 +              // Is this the same title?
 +              $talkNS = MediaWikiServices::getInstance()->getNamespaceInfo()->getTalk( $this->mNamespace );
 +              if ( $this->mNamespace == $talkNS ) {
 +                      return $this;
 +              }
 +
 +              $title = self::makeTitle( $talkNS, $this->mDbkeyform );
 +
 +              $this->warnIfPageCannotExist( $title, __METHOD__ );
 +
 +              return $title;
 +              // TODO: replace the above with the code below:
 +              // return self::castFromLinkTarget(
 +              // MediaWikiServices::getInstance()->getNamespaceInfo()->getTalkPage( $this ) );
        }
  
        /**
         * @return Title The object for the subject page
         */
        public function getSubjectPage() {
 -              return self::castFromLinkTarget(
 -                      MediaWikiServices::getInstance()->getNamespaceInfo()->getSubjectPage( $this ) );
 +              // Is this the same title?
 +              $subjectNS = MediaWikiServices::getInstance()->getNamespaceInfo()
 +                      ->getSubject( $this->mNamespace );
 +              if ( $this->mNamespace == $subjectNS ) {
 +                      return $this;
 +              }
 +              // NOTE: The equivalent code in NamespaceInfo is less lenient about producing invalid titles.
 +              //       Instead of failing on invalid titles, let's just log the issue for now.
 +              //       See the discussion on T227817.
 +              $title = self::makeTitle( $subjectNS, $this->mDbkeyform );
 +
 +              $this->warnIfPageCannotExist( $title, __METHOD__ );
 +
 +              return $title;
 +              // TODO: replace the above with the code below:
 +              // return self::castFromLinkTarget(
 +              // MediaWikiServices::getInstance()->getNamespaceInfo()->getSubjectPage( $this ) );
 +      }
 +
 +      /**
 +       * @param Title $title
 +       * @param string $method
 +       *
 +       * @return bool whether a warning was issued
 +       */
 +      private function warnIfPageCannotExist( Title $title, $method ) {
 +              if ( $this->getText() == '' ) {
 +                      wfLogWarning(
 +                              $method . ': called on empty title ' . $this->getFullText() . ', returning '
 +                              . $title->getFullText()
 +                      );
 +
 +                      return true;
 +              }
 +
 +              if ( $this->getInterwiki() !== '' ) {
 +                      wfLogWarning(
 +                              $method . ': called on interwiki title ' . $this->getFullText() . ', returning '
 +                              . $title->getFullText()
 +                      );
 +
 +                      return true;
 +              }
 +
 +              return false;
        }
  
        /**
         * @return Title
         */
        public function getOtherPage() {
 -              return self::castFromLinkTarget(
 -                      MediaWikiServices::getInstance()->getNamespaceInfo()->getAssociatedPage( $this ) );
 +              // NOTE: Depend on the methods in this class instead of their equivalent in NamespaceInfo,
 +              //       until their semantics has become exactly the same.
 +              //       See the discussion on T227817.
 +              if ( $this->isSpecialPage() ) {
 +                      throw new MWException( 'Special pages cannot have other pages' );
 +              }
 +              if ( $this->isTalkPage() ) {
 +                      return $this->getSubjectPage();
 +              } else {
 +                      if ( !$this->canHaveTalkPage() ) {
 +                              throw new MWException( "{$this->getPrefixedText()} does not have an other page" );
 +                      }
 +                      return $this->getTalkPage();
 +              }
 +              // TODO: replace the above with the code below:
 +              // return self::castFromLinkTarget(
 +              // MediaWikiServices::getInstance()->getNamespaceInfo()->getAssociatedPage( $this ) );
        }
  
        /**
         *
         * @see self::getLocalURL for the arguments.
         * @see wfExpandUrl
 -       * @param string|string[] $query
 +       * @param string|array $query
         * @param string|string[]|bool $query2
         * @param string|int|null $proto Protocol type to use in URL
         * @return string The URL
         *  valid to link, locally, to the current Title.
         * @see self::newFromText to produce a Title object.
         *
 -       * @param string|string[] $query An optional query string,
 +       * @param string|array $query An optional query string,
         *   not used for interwiki links. Can be specified as an associative array as well,
         *   e.g., [ 'action' => 'edit' ] (keys and values will be URL-escaped).
         *   Some query patterns will trigger various shorturl path replacements.
         * @return string String of the URL.
         */
        public function getLocalURL( $query = '', $query2 = false ) {
-               global $wgArticlePath, $wgScript, $wgServer, $wgRequest;
+               global $wgArticlePath, $wgScript, $wgServer, $wgRequest, $wgMainPageIsDomainRoot;
  
                $query = self::fixUrlQueryArgs( $query, $query2 );
  
                                $url = $wgServer . $url;
                        }
                }
+               if ( $wgMainPageIsDomainRoot && $this->isMainPage() && $query === '' ) {
+                       return '/';
+               }
                // Avoid PHP 7.1 warning from passing $this by reference
                $titleRef = $this;
                Hooks::run( 'GetLocalURL', [ &$titleRef, &$url, $query ] );
         * protocol-relative, the URL will be expanded to http://
         *
         * @see self::getLocalURL for the arguments.
 -       * @param string|string[] $query
 +       * @param string|array $query
         * @param string|bool $query2 Deprecated
         * @return string The URL
         */
         * NOTE: Unlike getInternalURL(), the canonical URL includes the fragment
         *
         * @see self::getLocalURL for the arguments.
 -       * @param string|string[] $query
 +       * @param string|array $query
         * @param string|bool $query2 Deprecated
         * @return string The URL
         * @since 1.18