Fixed obvious bug
[lhc/web/wiklou.git] / includes / OutputPage.php
index a9ce24f..fee9e5e 100644 (file)
@@ -86,15 +86,12 @@ class OutputPage {
         */
        function checkLastModified ( $timestamp ) {
                global $wgLang, $wgCachePages, $wgUser;
-               $timestamp=wfTimestamp(TS_MW,$timestamp);
-               if( !$wgCachePages ) {
-                       wfDebug( "CACHE DISABLED\n", false );
+               if ( !$timestamp || $timestamp == '19700101000000' ) {
+                       wfDebug( "CACHE DISABLED, NO TIMESTAMP\n" );
                        return;
                }
-               if( isset( $_SERVER["HTTP_USER_AGENT"] ) &&
-                   preg_match( '/MSIE ([1-4]|5\.0)/', $_SERVER["HTTP_USER_AGENT"] ) ) {
-                       # IE 5.0 has probs with our caching
-                       wfDebug( "-- bad client, not caching\n", false );
+               if( !$wgCachePages ) {
+                       wfDebug( "CACHE DISABLED\n", false );
                        return;
                }
                if( $wgUser->getOption( 'nocache' ) ) {
@@ -102,6 +99,7 @@ class OutputPage {
                        return;
                }
 
+               $timestamp=wfTimestamp(TS_MW,$timestamp);
                $lastmod = wfTimestamp( TS_RFC2822, max( $timestamp, $wgUser->mTouched ) );
 
                if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
@@ -112,7 +110,7 @@ class OutputPage {
                        $ismodsince = wfTimestamp( TS_MW, strtotime( $modsince ) );
                        wfDebug( "-- client send If-Modified-Since: " . $modsince . "\n", false );
                        wfDebug( "--  we might send Last-Modified : $lastmod\n", false );
-                       if( ($ismodsince >= $timestamp ) and $wgUser->validateCache( $ismodsince ) ) {
+                       if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) ) {
                                # Make sure you're in a place you can leave when you call us!
                                header( "HTTP/1.0 304 Not Modified" );
                                $this->mLastModified = $lastmod;
@@ -125,7 +123,7 @@ class OutputPage {
                                $this->mLastModified = $lastmod;
                        }
                } else {
-                       wfDebug( "We're confused.\n", false );
+                       wfDebug( "client did not send If-Modified-Since header\n", false );
                        $this->mLastModified = $lastmod;
                }
        }
@@ -314,7 +312,8 @@ class OutputPage {
 
        function sendCacheControl() {
                global $wgUseSquid, $wgUseESI;
-               # FIXME: This header may cause trouble with some versions of Internet Explorer
+               # don't serve compressed data to clients who can't handle it
+               # maintain different caches for logged-in users and non-logged in ones
                header( 'Vary: Accept-Encoding, Cookie' );
                if( $this->mEnableClientCache ) {
                        if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
@@ -587,7 +586,7 @@ class OutputPage {
        }
 
        function databaseError( $fname, $sql, $error, $errno ) {
-               global $wgUser, $wgCommandLineMode;
+               global $wgUser, $wgCommandLineMode, $wgShowSQLErrors;
 
                $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
                $this->setRobotpolicy( 'noindex,nofollow' );
@@ -595,12 +594,20 @@ class OutputPage {
                $this->enableClientCache( false );
                $this->mRedirect = '';
 
-               if ( $wgCommandLineMode ) {
-                       $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
-                                               htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
+               if( $wgShowSQLErrors ) {
+                       if ( $wgCommandLineMode ) {
+                               $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
+                                                       htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
+                       } else {
+                               $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
+                                                       htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
+                       }
                } else {
-                       $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
-                                               htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
+                       if( $wgCommandLineMode ) {
+                               $msg = wfMsg( 'internalerror' );
+                       } else {
+                               $msg = htmlspecialchars( wfMsg( 'internalerror' ) );
+                       }
                }
 
                if ( $wgCommandLineMode || !is_object( $wgUser )) {
@@ -727,8 +734,7 @@ class OutputPage {
                global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
                global $wgUser, $wgContLang, $wgRequest;
 
-               $xml = ($wgMimeType == 'text/xml');
-               if( $xml ) {
+               if( $wgMimeType == 'text/xml' || $wgMimeType == 'application/xhtml+xml' || $wgMimeType == 'application/xml' ) {
                        $ret = "<" . "?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?" . ">\n";
                } else {
                        $ret = '';
@@ -739,13 +745,9 @@ class OutputPage {
                if ( "" == $this->mHTMLtitle ) {
                        $this->mHTMLtitle = wfMsg( "pagetitle", $this->mPagetitle );
                }
-               if( $xml ) {
-                       $xmlbits = "xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\"";
-               } else {
-                       $xmlbits = '';
-               }
+
                $rtl = $wgContLang->isRTL() ? " dir='RTL'" : '';
-               $ret .= "<html $xmlbits lang=\"$wgContLanguageCode\" $rtl>\n";
+               $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
                $ret .= "<head>\n<title>" . htmlspecialchars( $this->mHTMLtitle ) . "</title>\n";
                array_push( $this->mMetatags, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );