From a5deeac58c9fbfd989f460827103aefed6bb2c14 Mon Sep 17 00:00:00 2001 From: Amir Sarabadani Date: Tue, 2 Jul 2019 01:25:01 +0200 Subject: [PATCH] Add config for serving main Page from the domain root Bug: T120085 Change-Id: If2d82340ec58888a0bac96924ab63456b6d480fb --- includes/DefaultSettings.php | 7 +++++++ includes/MediaWiki.php | 4 ++++ includes/Title.php | 7 ++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 47fd073153..6e01efc18a 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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 diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php index f91477af2e..28c9e16002 100644 --- a/includes/MediaWiki.php +++ b/includes/MediaWiki.php @@ -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() ); diff --git a/includes/Title.php b/includes/Title.php index de418a7163..f9b5d0f1ee 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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 ] ); -- 2.20.1