Yurik has uploaded a new change for review. https://gerrit.wikimedia.org/r/96503
Change subject: Allow external home script to access landing URL logic ...................................................................... Allow external home script to access landing URL logic *Incomplete* code This patch will allow a new site entry file (like extract2.php) to access the redirect logic direcly without going through the regular page rendering. Change-Id: I648ec8d5cfa52ce0fffdfc82e471a987be471cac --- M includes/PageRenderingHooks.php 1 file changed, 25 insertions(+), 14 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ZeroRatedMobileAccess refs/changes/03/96503/1 diff --git a/includes/PageRenderingHooks.php b/includes/PageRenderingHooks.php index 1b328ee..e962d21 100644 --- a/includes/PageRenderingHooks.php +++ b/includes/PageRenderingHooks.php @@ -763,26 +763,18 @@ * @return array */ private function makeRedirectInfo() { + if ( $this->request->getCheck( 'isroot' ) ) { + $url = $this->getLandingRedirect(); + return array( 'redirect' => $url, 'code' => '302' ); + } $config = $this->getConfig(); - $isRoot = $this->request->getCheck( 'isroot' ); $from = $this->request->getVal( 'from' ); $toUrl = $this->request->getVal( 'to' ); - if ( $isRoot || $toUrl === null || $from === null ) { + if ( $toUrl === null || $from === null ) { // This is not an external link or file redirect, see if we need to redirect anywhere $langCode = null; $isLanding = false; - if ( $isRoot ) { - // User requested the root m.* or zero.* page - if ( $config === null ) { - // Staying consistent with the current behaviour - redirect to en.*.* - $langCode = 'en'; - // zero.* -> Landing, m.* -> Main Page - $isLanding = $this->isZeroSubdomain; - } else { - $langCode = $config['showLangs'][0]; - $isLanding = $config['showZeroPage']; - } - } elseif ( $config !== null ) { + if ( $config !== null ) { // if ( !$config['showZeroPage'] ) { $langCode = $config['showLangs'][0]; @@ -965,4 +957,23 @@ return $global; } } + + /** + * Create redirect URL for m.* and zero.* root pages + * @return string + */ + public function getLandingRedirect() + { + $config = $this->getConfig(); + if ( $config === null ) { + // Staying consistent with the current behaviour - redirect to en.*.* + $langCode = 'en'; + // zero.* -> Landing, m.* -> Main Page + $isLanding = $this->isZeroSubdomain; + } else { + $langCode = $config['showLangs'][0]; + $isLanding = $config['showZeroPage']; + } + return $this->getStartPageUrl( $langCode, false, $isLanding ); + } } -- To view, visit https://gerrit.wikimedia.org/r/96503 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I648ec8d5cfa52ce0fffdfc82e471a987be471cac Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ZeroRatedMobileAccess Gerrit-Branch: master Gerrit-Owner: Yurik <yu...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits