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)
includes/DefaultSettings.php
includes/MediaWiki.php
includes/Title.php

index fd1affc..1068700 100644 (file)
@@ -9094,6 +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
index f91477a..28c9e16 100644 (file)
@@ -346,6 +346,10 @@ class MediaWiki {
                        return false;
                }
 
+               if ( $this->config->get( 'MainPageIsDomainRoot' ) && $request->getRequestURL() === '/' ) {
+                       return false;
+               }
+
                if ( $title->isSpecialPage() ) {
                        list( $name, $subpage ) = MediaWikiServices::getInstance()->getSpecialPageFactory()->
                                resolveAlias( $title->getDBkey() );
index 9843e81..6c15a06 100644 (file)
@@ -2137,7 +2137,7 @@ class Title implements LinkTarget, IDBAccessObject {
         * @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 );
 
@@ -2214,6 +2214,11 @@ class Title implements LinkTarget, IDBAccessObject {
                                $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 ] );