(bug 22310) Only need to declare $join_conds once
[lhc/web/wiklou.git] / includes / Wiki.php
index c7d80c2..dc4467b 100644 (file)
@@ -95,24 +95,6 @@ class MediaWiki {
                        return true;
                }
        }
-       
-       /**
-        * Check if the average lag of database slaves is higher that $avgLag, and
-        * if it's the case, output an error message
-        *
-        * @param $avgLag int: maximum lag allowed for the request, as supplied by
-        *                the client
-        * @return bool true if the request can continue
-        */
-       function checkAvgLag( $avgLag ) {
-               list( $host, $lag ) = wfGetLB()->getAvgLag();
-               if( $lag > $avgLag ) {
-                       wfAvglagError( $lag, $avgLag );
-                       return false;
-               } else {
-                       return true;
-               }
-       }
 
        /**
         * Checks some initial queries
@@ -127,11 +109,11 @@ class MediaWiki {
                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 );
@@ -197,12 +179,16 @@ class MediaWiki {
         */
        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' ) ) {
@@ -220,12 +206,20 @@ class MediaWiki {
                                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" .