Add the 403 fix from r49833 to RawPage as well.
[lhc/web/wiklou.git] / includes / RawPage.php
index 6c0c458..4f8523d 100644 (file)
@@ -34,7 +34,7 @@ class RawPage {
                }
 
                $ctype = $this->mRequest->getVal( 'ctype' );
-               $smaxage = $this->mRequest->getIntOrNull( 'smaxage', $wgSquidMaxage );
+               $smaxage = $this->mRequest->getIntOrNull( 'smaxage' );
                $maxage = $this->mRequest->getInt( 'maxage', $wgSquidMaxage );
 
                $this->mExpandTemplates = $this->mRequest->getVal( 'templates' ) === 'expand';
@@ -111,7 +111,7 @@ class RawPage {
        function view() {
                global $wgOut, $wgScript;
 
-               if( isset( $_SERVER['SCRIPT_URL'] ) ) {
+               if( isset( $_SERVER['SCRIPT_NAME'] ) ) {
                        # Normally we use PHP_SELF to get the URL to the script
                        # as it was called, minus the query string.
                        #
@@ -122,9 +122,18 @@ class RawPage {
                        #
                        # If in this mode, use SCRIPT_URL instead, which mod_rewrite
                        # provides containing the "before" URL.
-                       $url = $_SERVER['SCRIPT_URL'];
+                       $url = $_SERVER['SCRIPT_NAME'];
                } else {
-                       $url = $_SERVER['PHP_SELF'];
+                       $url = $_SERVER['URL'];
+               }
+
+               if( $url == '' ) {
+                       # This will make the next check fail with a confusing error
+                       # message, so we should mention it separately.
+                       wfHttpError( 500, 'Internal Server Error',
+                               "\$_SERVER['URL'] is not set.  Perhaps you're using CGI" .
+                               " and haven't set cgi.fix_pathinfo = 1 in php.ini?" );
+                       return;
                }
 
                if( strcmp( $wgScript, $url ) ) {
@@ -149,10 +158,22 @@ class RawPage {
                # allow the client to cache this for 24 hours
                $mode = $this->mPrivateCache ? 'private' : 'public';
                header( 'Cache-Control: '.$mode.', s-maxage='.$this->mSmaxage.', max-age='.$this->mMaxage );
+               
+               if( HTMLFileCache::useFileCache() ) {
+                       $cache = new HTMLFileCache( $this->mTitle, 'raw' );
+                       if( $cache->isFileCacheGood( /* Assume up to date */ ) ) {
+                               $cache->loadFromFileCache();
+                               $wgOut->disable();
+                               return;
+                       } else {
+                               ob_start( array(&$cache, 'saveToFileCache' ) );
+                       }
+               }
+               
                $text = $this->getRawText();
 
                if( !wfRunHooks( 'RawPageViewBeforeOutput', array( &$this, &$text ) ) ) {
-                       wfDebug( __METHOD__ . ': RawPageViewBeforeOutput hook broke raw page output.' );
+                       wfDebug( __METHOD__ . ": RawPageViewBeforeOutput hook broke raw page output.\n" );
                }
 
                echo $text;