follow-up r52858: remove unused "global $wgMessageCache;"
[lhc/web/wiklou.git] / includes / OutputPage.php
index a57bf3f..a05867d 100644 (file)
@@ -85,8 +85,15 @@ class OutputPage {
                array_push( $this->mMetatags, array( $name, $val ) );
        }
 
-       function addKeyword( $text ) { array_push( $this->mKeywords, $text ); }
-       function addScript( $script ) { $this->mScripts .= "\t\t".$script; }
+       function addKeyword( $text ) {
+               if( is_array( $text )) {
+                       $this->mKeywords = array_merge( $this->mKeywords, $text );
+               }
+               else {
+                       array_push( $this->mKeywords, $text );
+               }
+       }
+       function addScript( $script ) { $this->mScripts .= "\t" . $script . "\n"; }
        
        function addExtensionStyle( $url ) {
                $linkarr = array( 'rel' => 'stylesheet', 'href' => $url, 'type' => 'text/css' );
@@ -121,7 +128,7 @@ class OutputPage {
         */
        function addInlineScript( $script ) {
                global $wgJsMimeType;
-               $this->mScripts .= "<script type=\"$wgJsMimeType\">/*<![CDATA[*/\n$script\n/*]]>*/</script>";
+               $this->mScripts .= "\t\t<script type=\"$wgJsMimeType\">/*<![CDATA[*/\n\t\t$script\n\t\t/*]]>*/</script>\n";
        }
 
        function getScript() {
@@ -458,7 +465,7 @@ class OutputPage {
                                        if ( array_key_exists( $category, $categories ) )
                                                continue;
                                $text = $wgContLang->convertHtml( $title->getText() );
-                               $this->mCategoryLinks[$type][] = $sk->makeLinkObj( $title, $text );
+                               $this->mCategoryLinks[$type][] = $sk->link( $title, $text );
                        }
                }
        }
@@ -517,7 +524,8 @@ class OutputPage {
         * @param bool   $linestart
         */
        public function addWikiText( $text, $linestart = true ) {
-               $this->addWikiTextTitle( $text, $this->getTitle(), $linestart );
+               $title = $this->getTitle(); // Work arround E_STRICT
+               $this->addWikiTextTitle( $text, $title, $linestart );
        }
 
        public function addWikiTextWithTitle($text, &$title, $linestart = true) {
@@ -625,7 +633,7 @@ class OutputPage {
         * @deprecated Use Article::outputWikitext
         */
        public function addPrimaryWikiText( $text, $article, $cache = true ) {
-               global $wgParser, $wgUser;
+               global $wgParser;
 
                wfDeprecated( __METHOD__ );
 
@@ -654,7 +662,8 @@ class OutputPage {
         * Add wikitext with tidy enabled
         */
        public function addWikiTextTidy(  $text, $linestart = true ) {
-               $this->addWikiTextTitleTidy($text, $this->getTitle(), $linestart);
+               $title = $this->getTitle();
+               $this->addWikiTextTitleTidy($text, $title, $linestart);
        }
 
 
@@ -705,13 +714,16 @@ class OutputPage {
        /**
         * @param Article $article
         * @param User    $user
+        * 
+        * @deprecated
         *
         * @return bool True if successful, else false.
         */
        public function tryParserCache( &$article ) {
-               $parserCache = ParserCache::singleton();
-               $parserOutput = $parserCache->get( $article, $this->parserOptions() );
-               if ( $parserOutput !== false ) {
+               wfDeprecated( __METHOD__ );
+               $parserOutput = ParserCache::singleton()->get( $article, $article->getParserOptions() );
+               
+               if ($parserOutput !== false) {
                        $this->addParserOutput( $parserOutput );
                        return true;
                } else {
@@ -1032,7 +1044,7 @@ class OutputPage {
         */
        public static function setEncodings() {
                global $wgInputEncoding, $wgOutputEncoding;
-               global $wgUser, $wgContLang;
+               global $wgContLang;
 
                $wgInputEncoding = strtolower( $wgInputEncoding );
 
@@ -1190,7 +1202,7 @@ class OutputPage {
         * @param string $permission key required
         */
        public function permissionRequired( $permission ) {
-               global $wgUser, $wgLang;
+               global $wgLang;
 
                $this->setPageTitle( wfMsg( 'badaccess' ) );
                $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
@@ -1245,7 +1257,13 @@ class OutputPage {
                $this->setArticleFlag( false );
 
                $loginTitle = SpecialPage::getTitleFor( 'Userlogin' );
-               $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $this->getTitle()->getPrefixedUrl() );
+               $loginLink = $skin->link(
+                       $loginTitle,
+                       wfMsgHtml( 'loginreqlink' ),
+                       array(),
+                       array( 'returnto' => $this->getTitle()->getPrefixedText() ),
+                       array( 'known', 'noclasses' )
+               );
                $this->addHTML( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
                $this->addHTML( "\n<!--" . $this->getTitle()->getPrefixedUrl() . "-->" );
 
@@ -1270,7 +1288,7 @@ class OutputPage {
                        $text = wfMsgNoTrans( 'permissionserrorstext', count($errors)). "\n\n";
                } else {
                        global $wgLang;
-                       $action_desc = wfMsg( "action-$action" );
+                       $action_desc = wfMsgNoTrans( "action-$action" );
                        $text = wfMsgNoTrans( 'permissionserrorstext-withaction', count($errors), $action_desc ) . "\n\n";
                }
 
@@ -1285,7 +1303,7 @@ class OutputPage {
                        }
                        $text .= '</ul>';
                } else {
-                       $text .= '<div class="permissions-errors">' . call_user_func_array( 'wfMsgNoTrans', reset( $errors ) ) . '</div>';
+                       $text .= "<div class=\"permissions-errors\">\n" . call_user_func_array( 'wfMsgNoTrans', reset( $errors ) ) . "\n</div>";
                }
 
                return $text;
@@ -1327,7 +1345,18 @@ class OutputPage {
                        // Permissions error
                        if( $source ) {
                                $this->setPageTitle( wfMsg( 'viewsource' ) );
-                               $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $this->getTitle() ) ) );
+                               $this->setSubtitle(
+                                       wfMsg(
+                                               'viewsourcefor',
+                                               $skin->link(
+                                                       $this->getTitle(),
+                                                       null,
+                                                       array(),
+                                                       array(),
+                                                       array( 'known', 'noclasses' )
+                                               )
+                                       )
+                               );
                        } else {
                                $this->setPageTitle( wfMsg( 'badaccess' ) );
                        }
@@ -1442,8 +1471,8 @@ class OutputPage {
        public function addReturnTo( $title ) {
                global $wgUser;
                $this->addLink( array( 'rel' => 'next', 'href' => $title->getFullUrl() ) );
-               $link = wfMsg( 'returnto', $wgUser->getSkin()->makeLinkObj( $title ) );
-               $this->addHTML( "<p>{$link}</p>\n" );
+               $link = wfMsgHtml( 'returnto', $wgUser->getSkin()->link( $title ) );
+               $this->addHTML( "<p id=\"mw-returnto\">{$link}</p>\n" );
        }
 
        /**
@@ -1477,13 +1506,23 @@ class OutputPage {
        }
 
        /**
-        * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
+        * This function takes the title (first item of mGoodLinks), categories,
+        * existing and broken links for the page
         * and uses the first 10 of them for META keywords
         *
         * @param ParserOutput &$parserOutput
         */
        private function addKeywords( &$parserOutput ) {
-               $this->addKeyword( $this->getTitle()->getPrefixedText() );
+               global $wgContLang;
+               // Get an array of keywords if there are more than one
+               // variant of the site language
+               $text = $wgContLang->autoConvertToAllVariants( $this->getTitle()->getPrefixedText());
+               // array_values: We needn't to merge variant's code name
+               // into $this->mKeywords;
+               // array_unique: We should insert a keyword just for once
+               if( is_array( $text ))
+                       $text = array_unique( array_values( $text ));
+               $this->addKeyword( $text );
                $count = 1;
                $links2d =& $parserOutput->getLinks();
                if ( !is_array( $links2d ) ) {
@@ -1491,6 +1530,9 @@ class OutputPage {
                }
                foreach ( $links2d as $dbkeys ) {
                        foreach( $dbkeys as $dbkey => $unused ) {
+                               $dbkey = $wgContLang->autoConvertToAllVariants( $dbkey );
+                               if( is_array( $dbkey ))
+                                       $dbkey = array_unique( array_values( $dbkey ));
                                $this->addKeyword( $dbkey );
                                if ( ++$count > 10 ) {
                                        break 2;
@@ -1505,10 +1547,12 @@ class OutputPage {
        public function headElement( Skin $sk ) {
                global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
                global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
-               global $wgUser, $wgContLang, $wgUseTrackbacks, $wgStyleVersion;
+               global $wgContLang, $wgUseTrackbacks, $wgStyleVersion;
 
-               $this->addMeta( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" );
-               $this->addStyle( 'common/wikiprintable.css', 'print' );
+               $this->addMeta( "http:Content-Type", "$wgMimeType; charset={$wgOutputEncoding}" );
+               if ( $sk->commonPrintStylesheet() ) {
+                       $this->addStyle( 'common/wikiprintable.css', 'print' );
+               }
                $sk->setupUserCss( $this );
 
                $ret = '';
@@ -1517,24 +1561,23 @@ class OutputPage {
                        $ret .= "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?" . ">\n";
                }
 
-               $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n        \"$wgDTD\">\n";
+               $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\" \"$wgDTD\">\n";
 
                if ( '' == $this->getHTMLTitle() ) {
                        $this->setHTMLTitle(  wfMsg( 'pagetitle', $this->getPageTitle() ));
                }
 
-               $rtl = $wgContLang->isRTL() ? " dir='RTL'" : '';
+               $dir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
                $ret .= "<html xmlns=\"{$wgXhtmlDefaultNamespace}\" ";
                foreach($wgXhtmlNamespaces as $tag => $ns) {
                        $ret .= "xmlns:{$tag}=\"{$ns}\" ";
                }
-               $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
-               $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n\t\t";
-               $ret .= implode( "\t\t", array(
+               $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" dir=\"$dir\">\n";
+               $ret .= "<head>\n\t<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n\t";
+               $ret .= implode( "\n", array(
                        $this->getHeadLinks(),
                        $this->buildCssLinks(),
-                       $sk->getHeadScripts( $this->mAllowUserJs ),
-                       $this->mScripts,
+                       $sk->getHeadScripts( $this->mAllowUserJs, $this->mScripts ),
                        $this->getHeadItems(),
                ));
                if( $sk->usercss ){
@@ -1550,6 +1593,14 @@ class OutputPage {
        
        protected function addDefaultMeta() {
                global $wgVersion;
+
+               static $called = false;
+               if ( $called ) {
+                       # Don't run this twice
+                       return;
+               }
+               $called = true;
+
                $this->addMeta( 'http:Content-Style-Type', 'text/css' ); //bug 15835
                $this->addMeta( 'generator', "MediaWiki $wgVersion" );
                
@@ -1638,7 +1689,7 @@ class OutputPage {
                        }
                }
 
-               return implode( "\n\t\t", $tags ) . "\n";
+               return implode( "\n\t", $tags ) . "\n";
        }
 
        /**
@@ -1705,7 +1756,7 @@ class OutputPage {
                                $links[] = $link;
                }
 
-               return implode( "\n\t\t", $links );
+               return "\t" . implode( "\n\t", $links );
        }
 
        protected function styleLink( $style, $options ) {
@@ -1873,7 +1924,7 @@ class OutputPage {
         *
         * In the $wrap, $1 is replaced with the first message, $2 with the second, and so
         * on. The subsequent arguments may either be strings, in which case they are the
-        * message names, or an arrays, in which case the first element is the message name,
+        * message names, or arrays, in which case the first element is the message name,
         * and subsequent elements are the parameters to that message.
         *
         * The special named parameter 'options' in a message specification array is passed