(bug 5167) Add {{SUBPAGENAME}} variable
[lhc/web/wiklou.git] / includes / OutputPage.php
index 53f3f17..510b9eb 100644 (file)
@@ -1,16 +1,12 @@
 <?php
+if ( ! defined( 'MEDIAWIKI' ) )
+       die( -1 );
 /**
  * @package MediaWiki
  */
 
-/**
- * This is not a valid entry point, perform no further processing unless MEDIAWIKI is defined
- */
-if( defined( 'MEDIAWIKI' ) ) {
-
-# See design.txt
-
-if($wgUseTeX) require_once( 'Math.php' );
+if ( $wgUseTeX )
+       require_once 'Math.php';
 
 /**
  * @todo document
@@ -61,7 +57,7 @@ class OutputPage {
        function addHeader( $name, $val ) { array_push( $this->mHeaders, $name.': '.$val ) ; }
        function redirect( $url, $responsecode = '302' ) { $this->mRedirect = $url; $this->mRedirectCode = $responsecode; }
        function setStatusCode( $statusCode ) { $this->mStatusCode = $statusCode; }
-       
+
        # To add an http-equiv meta tag, precede the name with "http:"
        function addMeta( $name, $val ) { array_push( $this->mMetatags, array( $name, $val ) ); }
        function addKeyword( $text ) { array_push( $this->mKeywords, $text ); }
@@ -92,7 +88,7 @@ class OutputPage {
         * returns true iff cache-ok headers was sent.
         */
        function checkLastModified ( $timestamp ) {
-               global $wgCachePages, $wgUser;
+               global $wgCachePages, $wgCacheEpoch, $wgUser;
                if ( !$timestamp || $timestamp == '19700101000000' ) {
                        wfDebug( "CACHE DISABLED, NO TIMESTAMP\n" );
                        return;
@@ -107,7 +103,7 @@ class OutputPage {
                }
 
                $timestamp=wfTimestamp(TS_MW,$timestamp);
-               $lastmod = wfTimestamp( TS_RFC2822, max( $timestamp, $wgUser->mTouched ) );
+               $lastmod = wfTimestamp( TS_RFC2822, max( $timestamp, $wgUser->mTouched, $wgCacheEpoch ) );
 
                if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
                        # IE sends sizes after the date like this:
@@ -118,17 +114,17 @@ class OutputPage {
                        $ismodsince = wfTimestamp( TS_MW, $modsinceTime ? $modsinceTime : 1 );
                        wfDebug( "-- client send If-Modified-Since: " . $modsince . "\n", false );
                        wfDebug( "--  we might send Last-Modified : $lastmod\n", false );
-                       if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) ) {
+                       if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) {
                                # Make sure you're in a place you can leave when you call us!
                                header( "HTTP/1.0 304 Not Modified" );
                                $this->mLastModified = $lastmod;
                                $this->sendCacheControl();
-                               wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
+                               wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
                                $this->disable();
                                @ob_end_clean(); // Don't output compressed blob
                                return true;
                        } else {
-                               wfDebug( "READY  client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
+                               wfDebug( "READY  client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
                                $this->mLastModified = $lastmod;
                        }
                } else {
@@ -172,7 +168,7 @@ class OutputPage {
                                $name .= ' - '.$taction;
                        }
                }
-               
+
                $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
        }
        function getHTMLTitle() { return $this->mHTMLtitle; }
@@ -256,7 +252,7 @@ class OutputPage {
        function ParserOptions( $options = null ) {
                return wfSetVar( $this->mParserOptions, $options );
        }
-       
+
        /**
         * Set the revision ID which will be seen by the wiki text parser
         * for things such as embedded {{REVISIONID}} variable use.
@@ -297,7 +293,7 @@ class OutputPage {
                        $this->enableClientCache( false );
                }
        }
-       
+
        function addParserOutput( &$parserOutput ) {
                $this->addParserOutputNoText( $parserOutput );
                $this->addHTML( $parserOutput->getText() );
@@ -310,17 +306,33 @@ class OutputPage {
        function addPrimaryWikiText( $text, $article, $cache = true ) {
                global $wgParser, $wgUser;
 
+               $this->mParserOptions->setTidy(true);
                $parserOutput = $wgParser->parse( $text, $article->mTitle,
                        $this->mParserOptions, true, true, $this->mRevisionId );
-
-               if ( $article && $parserOutput->getCacheTime() != -1 ) {
+               $this->mParserOptions->setTidy(false);
+               if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
                        $parserCache =& ParserCache::singleton();
                        $parserCache->save( $parserOutput, $article, $wgUser );
                }
 
-               $this->addParserOutput( $parserOutput );
+               $this->addParserOutputNoText( $parserOutput );
+               $text = $parserOutput->getText();
+               wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
+               $parserOutput->setText( $text );
+               $this->addHTML( $parserOutput->getText() );
        }
 
+       /**
+        * For anything that isn't primary text or interface message
+        */
+       function addSecondaryWikiText( $text, $linestart = true ) {
+               global $wgTitle;
+               $this->mParserOptions->setTidy(true);
+               $this->addWikiTextTitle($text, $wgTitle, $linestart);
+               $this->mParserOptions->setTidy(false);
+       }
+
+
        /**
         * Add the output of a QuickTemplate to the output buffer
         * @param QuickTemplate $template
@@ -355,7 +367,9 @@ class OutputPage {
                        $this->mLanguageLinks += $parserOutput->getLanguageLinks();
                        $this->addCategoryLinks( $parserOutput->getCategories() );
                        $this->addKeywords( $parserOutput );
-                       $this->addHTML( $parserOutput->getText() );
+                       $text = $parserOutput->getText();
+                       wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) );
+                       $this->addHTML( $text );
                        $t = $parserOutput->getTitleText();
                        if( !empty( $t ) ) {
                                $this->setPageTitle( $t );
@@ -389,7 +403,7 @@ class OutputPage {
        }
 
        function sendCacheControl() {
-               global $wgUseSquid, $wgUseESI;
+               global $wgUseSquid, $wgUseESI, $wgSquidMaxage;
 
                if ($this->mETag)
                        header("ETag: $this->mETag");
@@ -599,6 +613,31 @@ class OutputPage {
                return $time;
        }
 
+       /**
+        * Produce a "user is blocked" page
+        */
+       function blockedPage() {
+               global $wgUser, $wgContLang;
+
+               $this->setPageTitle( wfMsg( 'blockedtitle' ) );
+               $this->setRobotpolicy( 'noindex,nofollow' );
+               $this->setArticleRelated( false );
+
+               $id = $wgUser->blockedBy();
+               $reason = $wgUser->blockedFor();
+               $ip = wfGetIP();
+
+               if ( is_numeric( $id ) ) {
+                       $name = User::whoIs( $id );
+               } else {
+                       $name = $id;
+               }
+               $link = '[[' . $wgContLang->getNsText( NS_USER ) . ":{$name}|{$name}]]";
+
+               $this->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name ) );
+               $this->returnToMain( false );
+       }
+
        /**
         * Note: these arguments are keys into wfMsg(), not text!
         */
@@ -707,7 +746,7 @@ class OutputPage {
                $this->mBodytext = '';
                $loginpage = Title::makeTitle(NS_SPECIAL, 'Userlogin');
                $sk = $wgUser->getSkin();
-               $loginlink = $sk->makeKnownLinkObj($loginpage, wfMsg('loginreqlink'), 
+               $loginlink = $sk->makeKnownLinkObj($loginpage, wfMsg('loginreqlink'),
                        'returnto=' . htmlspecialchars($wgTitle->getPrefixedDBkey()));
                $this->addHTML( wfMsgHtml( 'loginreqpagetext', $loginlink ) );
 
@@ -837,7 +876,7 @@ class OutputPage {
                if ( '' == $returnto ) {
                        $returnto = wfMsgForContent( 'mainpage' );
                }
-               $link = $sk->makeKnownLink( $returnto, '' );
+               $link = $sk->makeLinkObj( Title::newFromText( $returnto ), '' );
 
                $r = wfMsg( 'returnto', $link );
                if ( $auto ) {
@@ -867,7 +906,7 @@ class OutputPage {
        }
 
        /**
-        * @private
+        * @access private
         * @return string
         */
        function headElement() {
@@ -925,7 +964,7 @@ class OutputPage {
                        }
                        $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
                }
-               
+
                $p = $this->mRobotpolicy;
                if( $p !== '' && $p != 'index,follow' ) {
                        // http://www.robotstxt.org/wc/meta-user.html
@@ -974,7 +1013,4 @@ class OutputPage {
        }
 
 }
-
-} // MediaWiki
-
 ?>