From: Brion Vibber Date: Wed, 14 Dec 2011 00:38:21 +0000 (+0000) Subject: Add BeforePageRedirect hook to OutputPage, allowing extensions to override redirect... X-Git-Tag: 1.31.0-rc.0~25978 X-Git-Url: http://git.cyclocoop.org/%24href?a=commitdiff_plain;h=5a6372103a1330c87b9d8ce452630cf638731b6e;p=lhc%2Fweb%2Fwiklou.git Add BeforePageRedirect hook to OutputPage, allowing extensions to override redirect output. This is needed by MobileFrontend to normalize some redirects to the mobile site, such as on login. --- diff --git a/docs/hooks.txt b/docs/hooks.txt index 759874b775..2e9e4a7022 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -599,6 +599,13 @@ $mediaWiki: Mediawiki object &$out: OutputPage object &$skin: Skin object +'BeforePageRedirect': Prior to sending an HTTP redirect. Gives a chance to +override how the redirect is output by modifying, or by returning false and +taking over the output. +$out: OutputPage object +&$redirect: URL, modifiable +&$code: HTTP code (eg '301' or '302'), modifiable + 'BeforeParserFetchFileAndTitle': before an image is rendered by Parser $parser: Parser object $nt: the image title diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 4495714ce0..1efced8ac5 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -1918,27 +1918,34 @@ class OutputPage extends ContextSource { if ( $this->mRedirect != '' ) { # Standards require redirect URLs to be absolute $this->mRedirect = wfExpandUrl( $this->mRedirect, PROTO_CURRENT ); - if( $this->mRedirectCode == '301' || $this->mRedirectCode == '303' ) { - if( !$wgDebugRedirects ) { - $message = HttpStatus::getMessage( $this->mRedirectCode ); - $response->header( "HTTP/1.1 {$this->mRedirectCode} $message" ); + + $redirect = $this->mRedirect; + $code = $this->mRedirectCode; + + if( wfRunHooks( "BeforePageRedirect", $this, &$redirect, &$code ) ) { + if( $code == '301' || $code == '303' ) { + if( !$wgDebugRedirects ) { + $message = HttpStatus::getMessage( $code ); + $response->header( "HTTP/1.1 $code $message" ); + } + $this->mLastModified = wfTimestamp( TS_RFC2822 ); + } + if ( $wgVaryOnXFP ) { + $this->addVaryHeader( 'X-Forwarded-Proto' ); + } + $this->sendCacheControl(); + + $response->header( "Content-Type: text/html; charset=utf-8" ); + if( $wgDebugRedirects ) { + $url = htmlspecialchars( $redirect ); + print "\n\nRedirect\n\n\n"; + print "

Location: $url

\n"; + print "\n\n"; + } else { + $response->header( 'Location: ' . $redirect ); } - $this->mLastModified = wfTimestamp( TS_RFC2822 ); - } - if ( $wgVaryOnXFP ) { - $this->addVaryHeader( 'X-Forwarded-Proto' ); - } - $this->sendCacheControl(); - - $response->header( "Content-Type: text/html; charset=utf-8" ); - if( $wgDebugRedirects ) { - $url = htmlspecialchars( $this->mRedirect ); - print "\n\nRedirect\n\n\n"; - print "

Location: $url

\n"; - print "\n\n"; - } else { - $response->header( 'Location: ' . $this->mRedirect ); } + wfProfileOut( __METHOD__ ); return; } elseif ( $this->mStatusCode ) {