Add config for serving main Page from the domain root
authorAmir Sarabadani <Ladsgroup@gmail.com>
Mon, 1 Jul 2019 23:25:01 +0000 (01:25 +0200)
committerAmir Sarabadani <Ladsgroup@gmail.com>
Mon, 23 Sep 2019 09:55:59 +0000 (11:55 +0200)
Bug: T120085
Change-Id: If2d82340ec58888a0bac96924ab63456b6d480fb

includes/DefaultSettings.php
includes/MediaWiki.php
includes/Title.php

index 47fd073..6e01efc 100644 (file)
@@ -9090,6 +9090,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 de418a7..f9b5d0f 100644 (file)
@@ -2061,7 +2061,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 );
 
@@ -2138,6 +2138,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 ] );