Fixed obvious bug
[lhc/web/wiklou.git] / includes / OutputPage.php
index 9177c31..fee9e5e 100644 (file)
@@ -1,6 +1,5 @@
 <?php
 /**
- * @version $Id$
  * @package MediaWiki
  */
 
@@ -87,14 +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( 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,7 +99,8 @@ class OutputPage {
                        return;
                }
 
-               $lastmod = gmdate( 'D, j M Y H:i:s', wfTimestamp(TS_UNIX, max( $timestamp, $wgUser->mTouched ) ) ) . ' GMT';
+               $timestamp=wfTimestamp(TS_MW,$timestamp);
+               $lastmod = wfTimestamp( TS_RFC2822, max( $timestamp, $wgUser->mTouched ) );
 
                if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
                        # IE sends sizes after the date like this:
@@ -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;
                }
        }
@@ -259,6 +257,26 @@ class OutputPage {
                $this->addHTML( $text );
        }
 
+       /**
+        * Add the output of a QuickTemplate to the output buffer
+        * @param QuickTemplate $template
+        */
+       function addTemplate( &$template ) {
+               ob_start();
+               $template->execute();
+               $this->addHtml( ob_get_contents() );
+               ob_end_clean();
+       }
+
+       /**
+        * Parse wikitext and return the HTML. This is for special pages that add the text later
+        */
+       function parse( $text, $linestart = true ) {
+               global $wgParser, $wgTitle;
+               $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions, $linestart );
+               return $parserOutput->getText();
+       }
+       
        /**
         * @param $article
         * @param $user
@@ -294,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') ] ) &&
@@ -364,7 +383,7 @@ class OutputPage {
                                if( !$wgDebugRedirects ) {
                                        header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
                                }
-                               $this->mLastModified = gmdate( 'D, j M Y H:i:s' ) . ' GMT';
+                               $this->mLastModified = wfTimestamp( TS_RFC2822 );
                        }
 
                        $this->sendCacheControl();
@@ -382,7 +401,9 @@ class OutputPage {
                }
 
 
-               $this->sendCacheControl();
+               # Buffer output; final headers may depend on later processing
+               ob_start();
+
                $this->transformBuffer();
                
                # Disable temporary placeholders, so that the skin produces HTML
@@ -396,8 +417,12 @@ class OutputPage {
                        setcookie( $name, $val, $exp, '/' );
                }
 
+               wfProfileIn( 'Output-skin' );
                $sk->outputPage( $this );
-               # flush();
+               wfProfileOut( 'Output-skin' );
+               
+               $this->sendCacheControl();
+               ob_end_flush();
        }
 
        function out( $ins ) {
@@ -500,8 +525,6 @@ class OutputPage {
                $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
                $this->setRobotpolicy( 'noindex,nofollow' );
                $this->setArticleRelated( false );
-               $this->suppressQuickbar();
-               
                $this->enableClientCache( false );
                $this->mRedirect = '';
 
@@ -563,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' );
@@ -571,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 )) {
@@ -703,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 = '';
@@ -715,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}" ) );
 
@@ -782,9 +808,7 @@ class OutputPage {
                        $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
                        $ret .= "<link rel='alternate' type='application/rss+atom' title='Atom 0.3' href='$link' />\n";
                }
-               # FIXME: get these working
-               # $fix = htmlspecialchars( $wgStylePath . "/ie-png-fix.js" );
-               # $ret .= "<!--[if gte IE 5.5000]><script type='text/javascript' src='$fix'>< /script><![endif]-->";
+
                return $ret;
        }
        
@@ -794,6 +818,7 @@ class OutputPage {
        function transformBuffer( $options = 0 ) {
        }
 
+
 }
 
 }