Fix NS_PROJECT_TALK (bug #7792)
[lhc/web/wiklou.git] / includes / OutputPage.php
index cea0011..d83e1e1 100644 (file)
@@ -72,6 +72,16 @@ class OutputPage {
        function addMeta( $name, $val ) { array_push( $this->mMetatags, array( $name, $val ) ); }
        function addKeyword( $text ) { array_push( $this->mKeywords, $text ); }
        function addScript( $script ) { $this->mScripts .= $script; }
+
+       /**
+        * Add a self-contained script tag with the given contents
+        * @param string $script JavaScript text, no <script> tags
+        */
+       function addInlineScript( $script ) {
+               global $wgJsMimeType;
+               $this->mScripts .= "<script type=\"$wgJsMimeType\"><!--\n$script\n--></script>";
+       }
+
        function getScript() { return $this->mScripts; }
 
        function setETag($tag) { $this->mETag = $tag; }
@@ -134,10 +144,12 @@ class OutputPage {
                                $this->sendCacheControl();
                                wfDebug( "$fname: CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
                                $this->disable();
-                               // Don't output compressed blob
-                               while( $status = ob_get_status() ) {
-                                       ob_end_clean();
-                               }
+                               
+                               // Don't output a compressed blob when using ob_gzhandler;
+                               // it's technically against HTTP spec and seems to confuse
+                               // Firefox when the response gets split over two packets.
+                               wfClearOutputBuffers();
+                               
                                return true;
                        } else {
                                wfDebug( "$fname: READY  client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
@@ -243,7 +255,7 @@ class OutputPage {
                $lb->execute();
 
                $sk =& $wgUser->getSkin();
-               foreach ( $categories as $category => $arbitrary ) {
+               foreach ( $categories as $category => $unused ) {
                        $title = Title::makeTitleSafe( NS_CATEGORY, $category );
                        $text = $wgContLang->convertHtml( $title->getText() );
                        $this->mCategoryLinks[] = $sk->makeLinkObj( $title, $text );
@@ -512,8 +524,8 @@ class OutputPage {
        public function output() {
                global $wgUser, $wgOutputEncoding, $wgRequest;
                global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
-               global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgAjaxSearch, $wgScriptPath, $wgServer;
-               global $wgStyleVersion;
+               global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgAjaxSearch, $wgAjaxWatch;
+               global $wgServer, $wgStyleVersion;
 
                if( $this->mDoNothing ){
                        return;
@@ -524,11 +536,14 @@ class OutputPage {
 
                if ( $wgUseAjax ) {
                        $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js?$wgStyleVersion\"></script>\n" );
-               }
+                       if( $wgAjaxSearch ) {
+                               $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxsearch.js\"></script>\n" );
+                               $this->addScript( "<script type=\"{$wgJsMimeType}\">hookEvent(\"load\", sajax_onload);</script>\n" );
+                       }
 
-               if ( $wgUseAjax && $wgAjaxSearch ) {
-                       $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxsearch.js?$wgStyleVersion\"></script>\n" );
-                       $this->addScript( "<script type=\"{$wgJsMimeType}\">hookEvent(\"load\", sajax_onload);</script>\n" );
+                       if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
+                               $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxwatch.js\"></script>\n" );
+                       }
                }
 
                if ( '' != $this->mRedirect ) {
@@ -652,7 +667,7 @@ class OutputPage {
        /**
         * @todo document
         */
-       public function setEncodings() {
+       public static function setEncodings() {
                global $wgInputEncoding, $wgOutputEncoding;
                global $wgUser, $wgContLang;
 
@@ -699,7 +714,9 @@ class OutputPage {
                }
                $link = '[[' . $wgContLang->getNsText( NS_USER ) . ":{$name}|{$name}]]";
 
-               $this->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name ) );
+               $blockid = $wgUser->mBlock->mId;
+
+               $this->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name, $blockid ) );
                
                # Don't auto-return to special pages
                if( $return ) {
@@ -837,7 +854,7 @@ class OutputPage {
                
                # Don't return to the main page if the user can't read it
                # otherwise we'll end up in a pointless loop
-               $mainPage = Title::newFromText( wfMsgForContent( 'mainpage' ) );
+               $mainPage = Title::newMainPage();
                if( $mainPage->userCanRead() )
                        $this->returnToMain( true, $mainPage );
        }
@@ -854,12 +871,12 @@ class OutputPage {
         */
        public function readOnlyPage( $source = null, $protected = false ) {
                global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
+               $skin = $wgUser->getSkin();
 
                $this->setRobotpolicy( 'noindex,nofollow' );
                $this->setArticleRelated( false );
 
                if( $protected ) {
-                       $skin = $wgUser->getSkin();
                        $this->setPageTitle( wfMsg( 'viewsource' ) );
                        $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
 
@@ -868,7 +885,7 @@ class OutputPage {
                        if( $wgTitle->getNamespace() == NS_MEDIAWIKI && !$wgUser->isAllowed( 'editinterface' ) ) {
                                $this->addWikiText( wfMsg( 'protectedinterface' ) );
                        } else {
-                               $this->addWikiText( wfMsg( 'protectedtext' ) );
+                               $this->addWikiText( wfMsg( 'protectedpagetext' ) );
                        }
                } else {
                        $this->setPageTitle( wfMsg( 'readonly' ) );
@@ -881,6 +898,7 @@ class OutputPage {
                }
 
                if( is_string( $source ) ) {
+                       $this->addWikiText( wfMsg( 'viewsourcetext' ) );
                        if( $source === '' ) {
                                global $wgTitle;
                                if ( $wgTitle->getNamespace() == NS_MEDIAWIKI ) {
@@ -896,7 +914,8 @@ class OutputPage {
                                htmlspecialchars( $source ) . "\n</textarea>";
                        $this->addHTML( $text );
                }
-               $this->formatTemplates();
+               $article = new Article($wgTitle);
+               $this->addHTML( $skin->formatTemplates($article->getUsedTemplates()) );
 
                $this->returnToMain( false );
        }
@@ -973,7 +992,7 @@ class OutputPage {
                }
                
                if ( '' === $returnto ) {
-                       $returnto = wfMsgForContent( 'mainpage' );
+                       $returnto = Title::newMainPage();
                }
 
                if ( is_object( $returnto ) ) {
@@ -1009,8 +1028,8 @@ class OutputPage {
                if ( !is_array( $links2d ) ) {
                        return;
                }
-               foreach ( $links2d as $ns => $dbkeys ) {
-                       foreach( $dbkeys as $dbkey => $id ) {
+               foreach ( $links2d as $dbkeys ) {
+                       foreach( $dbkeys as $dbkey => $unused ) {
                                $this->addKeyword( $dbkey );
                                if ( ++$count > 10 ) {
                                        break 2;
@@ -1135,44 +1154,5 @@ class OutputPage {
        public function showNewSectionLink() {
                return $this->mNewSectionLink;
        }
-
-       /**
-        * Outputs the "templates used on this page" list.
-        *
-        * Stolen from EditPage::formatTemplates.  Should be merged, but there are
-        * slightly fiddly bits involving previews and so on that will have to be
-        * dealt with, so I'll just copy it for now because I'm lazy.
-        *
-        * @return nothing
-        */
-       function formatTemplates() {
-               global $wgUser, $wgTitle;
-               wfProfileIn( __METHOD__ );
-
-               $sk =& $wgUser->getSkin();
-
-               $outText = '';
-               $article = new Article($wgTitle);
-               $templates = $article->getUsedTemplates();
-               if ( count( $templates ) > 0 ) {
-                       # Do a batch existence check
-                       $batch = new LinkBatch;
-                       foreach( $templates as $title ) {
-                               $batch->addObj( $title );
-                       }
-                       $batch->execute();
-
-                       # Construct the HTML
-                       $outText = '<div class="mw-templatesUsedExplanation">' .
-                               wfMsgExt( 'templatesused', array( 'parse' ) ) .
-                               '</div><ul>';
-                       foreach ( $templates as $titleObj ) {
-                               $outText .= '<li>' . $sk->makeLinkObj( $titleObj ) . '</li>';
-                       }
-                       $outText .= '</ul>';
-               }
-               wfProfileOut( __METHOD__  );
-               $this->addHTML($outText);
-       }
 }
 ?>