if( $wgRequest->getVal( 'printable' ) === 'yes' ) {
$wgOut->setPrintable();
}
- $ret = NULL;
+ $ret = null;
if( $curid = $wgRequest->getInt( 'curid' ) ) {
# URLs like this are generated by RC, because rc_title isn't always accurate
$ret = Title::newFromID( $curid );
- } elseif( '' == $title && 'delete' != $action ) {
+ } elseif( $title == '' && $action != 'delete' ) {
$ret = Title::newMainPage();
} else {
$ret = Title::newFromURL( $title );
*/
function handleSpecialCases( &$title, &$output, $request ) {
wfProfileIn( __METHOD__ );
+ global $wgContLang, $wgUser;
$action = $this->getVal( 'Action' );
- // Invalid titles
- if( is_null($title) || $title->getDBkey() == '' ) {
+ $perferred = $wgContLang->getPreferredVariant( false );
+
+ // Invalid titles. Bug 21776: The interwikis must redirect even if the page name is empty.
+ if( is_null($title) || ( ($title->getDBkey() == '') && ($title->getInterwiki() == '') ) ) {
$title = SpecialPage::getTitleFor( 'Badtitle' );
# Die now before we mess up $wgArticle and the skin stops working
throw new ErrorPageError( 'badtitle', 'badtitletext' );
+
// Interwiki redirects
} else if( $title->getInterwiki() != '' ) {
if( $rdfrom = $request->getVal( 'rdfrom' ) ) {
wfProfileOut( __METHOD__ );
throw new ErrorPageError( 'badtitle', 'badtitletext' );
}
- // Redirect loops, no title in URL, $wgUsePathInfo URLs
+ // Redirect loops, no title in URL, $wgUsePathInfo URLs, and URLs with a variant
} else if( $action == 'view' && !$request->wasPosted() &&
- ( !isset($this->GET['title']) || $title->getPrefixedDBKey() != $this->GET['title'] ) &&
+ ( ( !isset($this->GET['title']) || $title->getPrefixedDBKey() != $this->GET['title'] ) ||
+ // No valid variant in URL (if the main-language has multi-variants), to ensure
+ // anonymous access would always be redirect to a URL with 'variant' parameter
+ ( !isset($this->GET['variant']) && $wgContLang->hasVariants() && !$wgUser->isLoggedIn() ) ) &&
!count( array_diff( array_keys( $this->GET ), array( 'action', 'title' ) ) ) )
{
- $targetUrl = $title->getFullURL();
+ if( !$wgUser->isLoggedIn() ) {
+ $pref = $wgContLang->getPreferredVariant( false, $fromHeader = true );
+ $targetUrl = $title->getFullURL( '', $variant = $pref );
+ }
+ else
+ $targetUrl = $title->getFullURL();
// Redirect to canonical url, make it a 301 to allow caching
if( $targetUrl == $request->getFullRequestURL() ) {
$message = "Redirect loop detected!\n\n" .