From: Amir Sarabadani Date: Mon, 1 Jul 2019 23:25:01 +0000 (+0200) Subject: Add config for serving main Page from the domain root X-Git-Tag: 1.34.0-rc.0~121^2 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=a5deeac58c9fbfd989f460827103aefed6bb2c14;ds=sidebyside Add config for serving main Page from the domain root Bug: T120085 Change-Id: If2d82340ec58888a0bac96924ab63456b6d480fb --- 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 ] );