Fix NS_PROJECT_TALK (bug #7792)
[lhc/web/wiklou.git] / includes / OutputPage.php
index dc56282..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 );
@@ -231,7 +243,7 @@ class OutputPage {
         * Add an array of categories, with names in the keys
         */
        public function addCategoryLinks($categories) {
-               global $wgContLang;
+               global $wgUser, $wgContLang;
 
                if ( !is_array( $categories ) ) {
                        return;
@@ -242,10 +254,11 @@ class OutputPage {
                $lb->setArray( $arr );
                $lb->execute();
 
-               foreach ( $categories as $category => $arbitrary ) {
+               $sk =& $wgUser->getSkin();
+               foreach ( $categories as $category => $unused ) {
                        $title = Title::makeTitleSafe( NS_CATEGORY, $category );
                        $text = $wgContLang->convertHtml( $title->getText() );
-                       $this->mCategoryLinks[] = Linker::makeLinkObj( $title, $text );
+                       $this->mCategoryLinks[] = $sk->makeLinkObj( $title, $text );
                }
        }
 
@@ -511,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;
@@ -523,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 ) {
@@ -614,6 +630,9 @@ class OutputPage {
                # Buffer output; final headers may depend on later processing
                ob_start();
 
+               # Disable temporary placeholders, so that the skin produces HTML
+               $sk->postParseLinkColour( false );
+
                $wgRequest->response()->header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
                $wgRequest->response()->header( 'Content-language: '.$wgContLanguageCode );
 
@@ -648,7 +667,7 @@ class OutputPage {
        /**
         * @todo document
         */
-       public function setEncodings() {
+       public static function setEncodings() {
                global $wgInputEncoding, $wgOutputEncoding;
                global $wgUser, $wgContLang;
 
@@ -695,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 ) {
@@ -756,7 +777,7 @@ class OutputPage {
         * @param string $permission key required
         */
        public function permissionRequired( $permission ) {
-               global $wgGroupPermissions;
+               global $wgGroupPermissions, $wgUser;
 
                $this->setPageTitle( wfMsg( 'badaccess' ) );
                $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
@@ -770,7 +791,8 @@ class OutputPage {
                                $groupName = User::getGroupName( $key );
                                $groupPage = User::getGroupPage( $key );
                                if( $groupPage ) {
-                                       $groups[] = '"'.Linker::makeLinkObj( $groupPage, $groupName ).'"';
+                                       $skin =& $wgUser->getSkin();
+                                       $groups[] = '"'.$skin->makeLinkObj( $groupPage, $groupName ).'"';
                                } else {
                                        $groups[] = '"'.$groupName.'"';
                                }
@@ -818,19 +840,21 @@ class OutputPage {
                        return;
                }
 
+               $skin = $wgUser->getSkin();
+               
                $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
                $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
                $this->setRobotPolicy( 'noindex,nofollow' );
                $this->setArticleFlag( false );
                
                $loginTitle = SpecialPage::getTitleFor( 'Userlogin' );
-               $loginLink = Linker::makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
+               $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
                $this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
                $this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
                
                # 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 );
        }
@@ -847,20 +871,21 @@ 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 ) {
                        $this->setPageTitle( wfMsg( 'viewsource' ) );
-                       $this->setSubtitle( wfMsg( 'viewsourcefor', Linker::makeKnownLinkObj( $wgTitle ) ) );
+                       $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
 
                        # Determine if protection is due to the page being a system message
                        # and show an appropriate explanation
                        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' ) );
@@ -873,6 +898,7 @@ class OutputPage {
                }
 
                if( is_string( $source ) ) {
+                       $this->addWikiText( wfMsg( 'viewsourcetext' ) );
                        if( $source === '' ) {
                                global $wgTitle;
                                if ( $wgTitle->getNamespace() == NS_MEDIAWIKI ) {
@@ -883,11 +909,13 @@ class OutputPage {
                        }
                        $rows = $wgUser->getIntOption( 'rows' );
                        $cols = $wgUser->getIntOption( 'cols' );
-                       
+
                        $text = "\n<textarea name='wpTextbox1' id='wpTextbox1' cols='$cols' rows='$rows' readonly='readonly'>" .
                                htmlspecialchars( $source ) . "\n</textarea>";
                        $this->addHTML( $text );
                }
+               $article = new Article($wgTitle);
+               $this->addHTML( $skin->formatTemplates($article->getUsedTemplates()) );
 
                $this->returnToMain( false );
        }
@@ -957,14 +985,14 @@ class OutputPage {
         * @param $returnto page title to return to. Default is Main Page.
         */
        public function returnToMain( $auto = true, $returnto = NULL ) {
-               global $wgOut, $wgRequest;
+               global $wgUser, $wgOut, $wgRequest;
                
                if ( $returnto == NULL ) {
                        $returnto = $wgRequest->getText( 'returnto' );
                }
                
                if ( '' === $returnto ) {
-                       $returnto = wfMsgForContent( 'mainpage' );
+                       $returnto = Title::newMainPage();
                }
 
                if ( is_object( $returnto ) ) {
@@ -976,7 +1004,8 @@ class OutputPage {
                        $titleObj = Title::newMainPage();
                }
 
-               $link = Linker::makeLinkObj( $titleObj, '' );
+               $sk = $wgUser->getSkin();
+               $link = $sk->makeLinkObj( $titleObj, '' );
 
                $r = wfMsg( 'returnto', $link );
                if ( $auto ) {
@@ -999,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;
@@ -1125,6 +1154,5 @@ class OutputPage {
        public function showNewSectionLink() {
                return $this->mNewSectionLink;
        }
-
 }
 ?>