Checking permissions for $wgUser while doing an edit with another user is not a good...
[lhc/web/wiklou.git] / includes / OutputPage.php
index a80d4eb..de50c06 100644 (file)
@@ -1617,8 +1617,7 @@ class OutputPage {
                $sk = $wgUser->getSkin();
 
                // Add base resources
-               $this->addModules( array( 'mediawiki.legacy.wikibits' ) );
-               $this->addModules( array( 'mediawiki.util' ) );
+               $this->addModules( array( 'mediawiki.legacy.wikibits', 'mediawiki.util' ) );
 
                // Add various resources if required
                if ( $wgUseAjax ) {
@@ -1627,7 +1626,7 @@ class OutputPage {
                        wfRunHooks( 'AjaxAddScript', array( &$this ) );
 
                        if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
-                               $this->addModules( 'mediawiki.legacy.ajaxwatch' );
+                               $this->addModules( 'mediawiki.action.watch.ajax' );
                        }
 
                        if ( $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ) {
@@ -1702,21 +1701,6 @@ class OutputPage {
                print $outs;
        }
 
-       /**
-        * @todo document
-        */
-       public static function setEncodings() {
-               global $wgInputEncoding, $wgOutputEncoding;
-
-               $wgInputEncoding = strtolower( $wgInputEncoding );
-
-               if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
-                       $wgOutputEncoding = strtolower( $wgOutputEncoding );
-                       return;
-               }
-               $wgOutputEncoding = $wgInputEncoding;
-       }
-
        /**
         * @deprecated use wfReportTime() instead.
         *
@@ -1818,9 +1802,7 @@ class OutputPage {
                $this->mRedirect = '';
                $this->mBodytext = '';
 
-               array_unshift( $params, 'parse' );
-               array_unshift( $params, $msg );
-               $this->addHTML( call_user_func_array( 'wfMsgExt', $params ) );
+               $this->addWikiMsgArray( $msg, $params );
 
                $this->returnToMain();
        }
@@ -1905,7 +1887,7 @@ class OutputPage {
                $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
                $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
                $this->setRobotPolicy( 'noindex,nofollow' );
-               $this->setArticleFlag( false );
+               $this->setArticleRelated( false );
 
                $loginTitle = SpecialPage::getTitleFor( 'Userlogin' );
                $loginLink = $skin->link(
@@ -2231,8 +2213,8 @@ class OutputPage {
                $ret .= Html::element( 'title', null, $this->getHTMLTitle() ) . "\n";
 
                $ret .= implode( "\n", array(
-                       $this->getHeadLinks( $sk ),
-                       $this->buildCssLinks(),
+                       $this->getHeadLinks(),
+                       $this->buildCssLinks( $sk ),
                        $this->getHeadItems(),
                ) );
                if ( $sk->usercss ) {
@@ -2374,11 +2356,12 @@ class OutputPage {
                                }
                                continue;
                        }
-                       // Special handling for user and site groups; because users might change their stuff on-wiki like site or
-                       // user pages, or user preferences; we need to find the highest timestamp of these user-changable modules so
-                       // we can ensure cache misses on change
+                       // Special handling for user and site groups; because users might change their stuff
+                       // on-wiki like site or user pages, or user preferences; we need to find the highest
+                       // timestamp of these user-changable modules so we can ensure cache misses on change
                        if ( $group === 'user' || $group === 'site' ) {
-                               // Create a fake request based on the one we are about to make so modules return correct times
+                               // Create a fake request based on the one we are about to make so modules return
+                               // correct times
                                $context = new ResourceLoaderContext( $resourceLoader, new FauxRequest( $query ) );
                                // Get the maximum timestamp
                                $timestamp = 1;
@@ -2425,48 +2408,50 @@ class OutputPage {
                // Startup - this will immediately load jquery and mediawiki modules
                $scripts = $this->makeResourceLoaderLink( $sk, 'startup', 'scripts', true );
 
-               // Configuration -- This could be merged together with the load and go, but makeGlobalVariablesScript returns a
-               // whole script tag -- grumble grumble...
+               // Configuration -- This could be merged together with the load and go, but
+               // makeGlobalVariablesScript returns a whole script tag -- grumble grumble...
                $scripts .= Skin::makeGlobalVariablesScript( $sk->getSkinName() ) . "\n";
 
-               // Script and Messages "only"
-               
-               // Scripts
+               // Script and Messages "only" requests
                $scripts .= $this->makeResourceLoaderLink( $sk, $this->getModuleScripts(), 'scripts' );
-
-               // Messages
                $scripts .= $this->makeResourceLoaderLink( $sk, $this->getModuleMessages(), 'messages' );
 
-               // Modules - let the client calculate dependencies and batch requests as it likes
+               // Modules requests - let the client calculate dependencies and batch requests as it likes
                if ( $this->getModules() ) {
-                       $modules = FormatJson::encode( $this->getModules() );
                        $scripts .= Html::inlineScript(
-                               "if ( window.mediaWiki ) { mediaWiki.loader.load( {$modules} ); mediaWiki.loader.go(); }"
+                               ResourceLoader::makeLoaderConditionalScript(
+                                       Xml::encodeJsCall( 'mediaWiki.loader.load', array( $this->getModules() ) ) .
+                                       Xml::encodeJsCall( 'mediaWiki.loader.go', array() )
+                               )
                        ) . "\n";
                }
 
+               // Legacy Scripts
+               $scripts .= "\n" . $this->mScripts;
+
+               // Add site JS if enabled
+               if ( $wgUseSiteJs ) {
+                       $scripts .= $this->makeResourceLoaderLink( $sk, 'site', 'scripts' );
+               }
+
                // Add user JS if enabled - trying to load user.options as a bundle if possible
                $userOptionsAdded = false;
                if ( $this->isUserJsAllowed() && $wgUser->isLoggedIn() ) {
                        $action = $wgRequest->getVal( 'action', 'view' );
                        if( $this->mTitle && $this->mTitle->isJsSubpage() && $sk->userCanPreview( $action ) ) {
                                # XXX: additional security check/prompt?
-                               $this->addInlineScript( $wgRequest->getText( 'wpTextbox1' ) );
+                               $scripts .= Html::inlineScript( "\n" . $wgRequest->getText( 'wpTextbox1' ) . "\n" ) . "\n";
                        } else {
-                               $scripts .= $this->makeResourceLoaderLink( $sk, array( 'user', 'user.options' ), 'scripts' );
+                               $scripts .= $this->makeResourceLoaderLink(
+                                       $sk, array( 'user', 'user.options' ), 'scripts'
+                               );
                                $userOptionsAdded = true;
                        }
                }
                if ( !$userOptionsAdded ) {
                        $scripts .= $this->makeResourceLoaderLink( $sk, 'user.options', 'scripts' );
                }
-               $scripts .= "\n" . $this->mScripts;
-
-               // Add site JS if enabled
-               if ( $wgUseSiteJs ) {
-                       $scripts .= $this->makeResourceLoaderLink( $sk, 'site', 'scripts' );
-               }
-
+               
                return $scripts;
        }
 
@@ -2514,7 +2499,7 @@ class OutputPage {
        /**
         * @return string HTML tag links to be put in the header.
         */
-       public function getHeadLinks( Skin $sk ) {
+       public function getHeadLinks() {
                global $wgFeed;
 
                // Ideally this should happen earlier, somewhere. :P
@@ -2585,8 +2570,6 @@ class OutputPage {
                        }
                }
 
-               $tags[] = $this->makeResourceLoaderLink( $sk, $this->getModuleStyles(), 'styles' );
-
                return implode( "\n", $tags );
        }
 
@@ -2644,8 +2627,23 @@ class OutputPage {
         * Build a set of <link>s for the stylesheets specified in the $this->styles array.
         * These will be applied to various media & IE conditionals.
         */
-       public function buildCssLinks() {
-               return implode( "\n", $this->buildCssLinksArray() );
+       public function buildCssLinks( $sk ) {
+               // Split the styles into three groups
+               $styles = array( 'other' => array(), 'user' => array(), 'site' => array() );
+               $resourceLoader = $this->getResourceLoader();
+               foreach ( $this->getModuleStyles() as $name ) {
+                       $group = $resourceLoader->getModule( $name )->getGroup();
+                       // Modules in groups named "other" or anything different than "user" or "site" will
+                       // be placed in the "other" group
+                       $styles[isset( $style[$group] ) ? $group : 'other'][] = $name;
+               }
+               // Add tags created using legacy methods
+               $tags = $this->buildCssLinksArray();
+               // Add ResourceLoader module style tags
+               $tags[] = $this->makeResourceLoaderLink(
+                       $sk, array_merge( $styles['other'], $styles['site'], $styles['user'] ), 'styles'
+               );
+               return implode( "\n", $tags );
        }
 
        public function buildCssLinksArray() {