First little bit of cleaning out the Augean stables of SpecialBlockip.php: spin out...
[lhc/web/wiklou.git] / includes / OutputPage.php
index f03e0e9..b7e5e9d 100644 (file)
@@ -1182,7 +1182,7 @@ class OutputPage {
         *
         * @param $options either the ParserOption to use or null to only get the
         *                 current ParserOption object
-        * @return current ParserOption object
+        * @return ParserOptions object
         */
        public function parserOptions( $options = null ) {
                if ( !$this->mParserOptions ) {
@@ -1785,10 +1785,12 @@ class OutputPage {
                        }
                }
 
-               $sk = $wgUser->getSkin();
-
                // Add base resources
-               $this->addModules( array( 'mediawiki.legacy.wikibits', 'mediawiki.util' ) );
+               $this->addModules( 'mediawiki.util' );
+               global $wgIncludeLegacyJavaScript;
+               if( $wgIncludeLegacyJavaScript ){
+                       $this->addModules( 'mediawiki.legacy.wikibits' );
+               }
 
                // Add various resources if required
                if ( $wgUseAjax ) {
@@ -1845,6 +1847,8 @@ class OutputPage {
                if ( $this->mArticleBodyOnly ) {
                        $this->out( $this->mBodytext );
                } else {
+                       $sk = $wgUser->getSkin();
+
                        // Hook that allows last minute changes to the output page, e.g.
                        // adding of CSS or Javascript by extensions.
                        wfRunHooks( 'BeforePageDisplay', array( &$this, &$sk ) );
@@ -2382,6 +2386,8 @@ class OutputPage {
 
        /**
         * Get a ResourceLoader object associated with this OutputPage
+        *
+        * @return ResourceLoader
         */
        public function getResourceLoader() {
                if ( is_null( $this->mResourceLoader ) ) {
@@ -2404,18 +2410,18 @@ class OutputPage {
                // Lazy-load ResourceLoader
                // TODO: Should this be a static function of ResourceLoader instead?
                // TODO: Divide off modules starting with "user", and add the user parameter to them
-               $query = array(
+               $baseQuery = array(
                        'lang' => $wgLang->getCode(),
                        'debug' => ResourceLoader::inDebugMode() ? 'true' : 'false',
                        'skin' => $skin->getSkinName(),
                        'only' => $only,
                );
                // Propagate printable and handheld parameters if present
-               if ( $wgRequest->getBool( 'printable' ) ) {
-                       $query['printable'] = 1;
+               if ( $this->isPrintable() ) {
+                       $baseQuery['printable'] = 1;
                }
                if ( $wgRequest->getBool( 'handheld' ) ) {
-                       $query['handheld'] = 1;
+                       $baseQuery['handheld'] = 1;
                }
 
                if ( !count( $modules ) ) {
@@ -2444,7 +2450,7 @@ class OutputPage {
                foreach ( (array) $modules as $name ) {
                        $module = $resourceLoader->getModule( $name );
                        # Check that we're allowed to include this module on this page
-                       if( ( $module->getOrigin() > $this->getAllowedModules( ResourceLoaderModule::TYPE_SCRIPTS )
+                       if ( ( $module->getOrigin() > $this->getAllowedModules( ResourceLoaderModule::TYPE_SCRIPTS )
                                        && $only == ResourceLoaderModule::TYPE_SCRIPTS )
                                || ( $module->getOrigin() > $this->getAllowedModules( ResourceLoaderModule::TYPE_STYLES )
                                        && $only == ResourceLoaderModule::TYPE_STYLES )
@@ -2462,14 +2468,30 @@ class OutputPage {
 
                $links = '';
                foreach ( $groups as $group => $modules ) {
-                       $query['modules'] = implode( '|', array_keys( $modules ) );
+                       $query = $baseQuery;
                        // Special handling for user-specific groups
                        if ( ( $group === 'user' || $group === 'private' ) && $wgUser->isLoggedIn() ) {
                                $query['user'] = $wgUser->getName();
                        }
+                       
+                       // Create a fake request based on the one we are about to make so modules return
+                       // correct timestamp and emptiness data
+                       $context = new ResourceLoaderContext( $resourceLoader, new FauxRequest( $query ) );
+                       // Drop modules that know they're empty
+                       foreach ( $modules as $key => $module ) {
+                               if ( $module->isKnownEmpty( $context ) ) {
+                                       unset( $modules[$key] );
+                               }
+                       }
+                       // If there are no modules left, skip this group
+                       if ( $modules === array() ) {
+                               continue;
+                       }
+                       
+                       $query['modules'] = implode( '|', array_keys( $modules ) );
+                       
                        // Support inlining of private modules if configured as such
                        if ( $group === 'private' && $wgResourceLoaderInlinePrivateModules ) {
-                               $context = new ResourceLoaderContext( $resourceLoader, new FauxRequest( $query ) );
                                if ( $only == ResourceLoaderModule::TYPE_STYLES ) {
                                        $links .= Html::inlineStyle(
                                                $resourceLoader->makeModuleResponse( $context, $modules )
@@ -2487,9 +2509,6 @@ class OutputPage {
                        // 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
-                               $context = new ResourceLoaderContext( $resourceLoader, new FauxRequest( $query ) );
                                // Get the maximum timestamp
                                $timestamp = 1;
                                foreach ( $modules as $module ) {
@@ -2505,18 +2524,24 @@ class OutputPage {
                        if ( $useESI && $wgResourceLoaderUseESI ) {
                                $esi = Xml::element( 'esi:include', array( 'src' => $url ) );
                                if ( $only == ResourceLoaderModule::TYPE_STYLES ) {
-                                       $links .= Html::inlineStyle( $esi );
+                                       $link = Html::inlineStyle( $esi );
                                } else {
-                                       $links .= Html::inlineScript( $esi );
+                                       $link = Html::inlineScript( $esi );
                                }
                        } else {
                                // Automatically select style/script elements
                                if ( $only === ResourceLoaderModule::TYPE_STYLES ) {
-                                       $links .= Html::linkedStyle( wfAppendQuery( $wgLoadScript, $query ) ) . "\n";
+                                       $link = Html::linkedStyle( wfAppendQuery( $wgLoadScript, $query ) );
                                } else {
-                                       $links .= Html::linkedScript( wfAppendQuery( $wgLoadScript, $query ) ) . "\n";
+                                       $link = Html::linkedScript( wfAppendQuery( $wgLoadScript, $query ) );
                                }
                        }
+
+                       if( $group == 'noscript' ){
+                               $links .= Html::rawElement( 'noscript', array(), $link ) . "\n";
+                       } else {
+                               $links .= $link . "\n";
+                       }
                }
                return $links;
        }
@@ -2542,8 +2567,8 @@ class OutputPage {
                // Modules requests - let the client calculate dependencies and batch requests as it likes
                $loader = '';
                if ( $this->getModules( true ) ) {
-                       $loader = Xml::encodeJsCall( 'mediaWiki.loader.load', array( $this->getModules( true ) ) ) .
-                               Xml::encodeJsCall( 'mediaWiki.loader.go', array() );
+                       $loader = Xml::encodeJsCall( 'mw.loader.load', array( $this->getModules( true ) ) ) .
+                               Xml::encodeJsCall( 'mw.loader.go', array() );
                }
                
                $scripts .= Html::inlineScript(
@@ -2596,11 +2621,16 @@ class OutputPage {
                $title = $this->getTitle();
                $ns = $title->getNamespace();
                $nsname = MWNamespace::exists( $ns ) ? MWNamespace::getCanonicalName( $ns ) : $title->getNsText();
+               if ( $ns == NS_SPECIAL ) {
+                       $parts = SpecialPage::resolveAliasWithSubpage( $title->getDBkey() );
+                       $canonicalName = $parts[0];
+               } else {
+                       $canonicalName = false; # bug 21115
+               }
 
                $vars = array(
                        'wgCanonicalNamespace' => $nsname,
-                       'wgCanonicalSpecialPageName' => $ns == NS_SPECIAL ?
-                               SpecialPage::resolveAlias( $title->getDBkey() ) : false, # bug 21115
+                       'wgCanonicalSpecialPageName' => $canonicalName,
                        'wgNamespaceNumber' => $title->getNamespace(),
                        'wgPageName' => $title->getPrefixedDBKey(),
                        'wgTitle' => $title->getText(),
@@ -2804,30 +2834,35 @@ class OutputPage {
        public function buildCssLinks( $sk ) {
                $ret = '';
                // Add ResourceLoader styles
-               // Split the styles into three groups
-               $styles = array( 'other' => array(), 'user' => array(), 'site' => array() );
+               // Split the styles into four groups
+               $styles = array( 'other' => array(), 'user' => array(), 'site' => array(), 'private' => array(), 'noscript' => 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
+                       // Modules in groups named "other" or anything different than "user", "site" or "private"
+                       // will be placed in the "other" group
                        $styles[isset( $styles[$group] ) ? $group : 'other'][] = $name;
                }
 
-               // We want site and user styles to override dynamically added styles from modules, but we want
+               // We want site, private and user styles to override dynamically added styles from modules, but we want
                // dynamically added styles to override statically added styles from other modules. So the order
-               // has to be other, dynamic, site, user
+               // has to be other, dynamic, site, private, user
                // Add statically added styles for other modules
                $ret .= $this->makeResourceLoaderLink( $sk, $styles['other'], ResourceLoaderModule::TYPE_STYLES );
                // Add normal styles added through addStyle()/addInlineStyle() here
                $ret .= implode( "\n", $this->buildCssLinksArray() ) . $this->mInlineStyles;
                // Add marker tag to mark the place where the client-side loader should inject dynamic styles
                // We use a <meta> tag with a made-up name for this because that's valid HTML
-               $ret .= Html::element( 'meta', array( 'name' => 'ResourceLoaderDynamicStyles', 'content' => '' ) );
-               // Add site and user styles
-               $ret .= $this->makeResourceLoaderLink(
-                       $sk, array_merge( $styles['site'], $styles['user'] ), ResourceLoaderModule::TYPE_STYLES
-               );
+               $ret .= Html::element( 'meta', array( 'name' => 'ResourceLoaderDynamicStyles', 'content' => '' ) ) . "\n";
+               
+               // Add site, private and user styles
+               // 'private' at present only contains user.options, so put that before 'user'
+               // Any future private modules will likely have a similar user-specific character
+               foreach ( array( 'site', 'noscript', 'private', 'user' ) as $group ) {
+                       $ret .= $this->makeResourceLoaderLink( $sk, $styles[$group],
+                                       ResourceLoaderModule::TYPE_STYLES
+                       );
+               }
                return $ret;
        }