* Follow-up r84610: don't assume a Parser object is attached
[lhc/web/wiklou.git] / includes / OutputPage.php
index 7f343b4..a9e549a 100644 (file)
@@ -123,6 +123,7 @@ class OutputPage {
        var $mInlineMsg = array();
 
        var $mTemplateIds = array();
+       var $mImageTimeKeys = array();
 
        # What level of 'untrustworthiness' is allowed in CSS/JS modules loaded on this page?
        # @see ResourceLoaderModule::$origin
@@ -361,7 +362,8 @@ class OutputPage {
        }
 
        /**
-        * Filter an array of modules to remove insufficiently trustworthy members
+        * Filter an array of modules to remove insufficiently trustworthy members, and modules
+        * which are no longer registered (eg a page is cached before an extension is disabled)
         * @param $modules Array
         * @return Array
         */
@@ -370,7 +372,9 @@ class OutputPage {
                $filteredModules = array();
                foreach( $modules as $val ){
                        $module = $resourceLoader->getModule( $val );
-                       if( $module->getOrigin() <= $this->getAllowedModules( $type ) ) {
+                       if( $module instanceof ResourceLoaderModule
+                               && $module->getOrigin() <= $this->getAllowedModules( $type ) )
+                       {
                                $filteredModules[] = $val;
                        }
                }
@@ -1092,7 +1096,7 @@ class OutputPage {
 
        /**
         * Return whether user JavaScript is allowed for this page
-        * @deprecated @since 1.18 Load modules with ResourceLoader, and origin and
+        * @deprecated since 1.18 Load modules with ResourceLoader, and origin and
         *     trustworthiness is identified and enforced automagically. 
         * @return Boolean
         */
@@ -1305,14 +1309,19 @@ class OutputPage {
                $this->mNoGallery = $parserOutput->getNoGallery();
                $this->mHeadItems = array_merge( $this->mHeadItems, $parserOutput->getHeadItems() );
                $this->addModules( $parserOutput->getModules() );
-               // Versioning...
-               foreach ( (array)$parserOutput->mTemplateIds as $ns => $dbks ) {
+
+               // Template versioning...
+               foreach ( (array)$parserOutput->getTemplateIds() as $ns => $dbks ) {
                        if ( isset( $this->mTemplateIds[$ns] ) ) {
                                $this->mTemplateIds[$ns] = $dbks + $this->mTemplateIds[$ns];
                        } else {
                                $this->mTemplateIds[$ns] = $dbks;
                        }
                }
+               // File versioning...
+               foreach ( (array)$parserOutput->getImageTimeKeys() as $dbk => $data ) {
+                       $this->mImageTimeKeys[$dbk] = $data;
+               }
 
                // Hooks registered in the object
                global $wgParserOutputHooks;
@@ -1785,10 +1794,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 +1856,8 @@ class OutputPage {
                if ( $this->mArticleBodyOnly ) {
                        $this->out( $this->mBodytext );
                } else {
+                       $sk = $wgUser->getSkin( $this->getTitle() );
+
                        // Hook that allows last minute changes to the output page, e.g.
                        // adding of CSS or Javascript by extensions.
                        wfRunHooks( 'BeforePageDisplay', array( &$this, &$sk ) );
@@ -1891,7 +1904,7 @@ class OutputPage {
                $this->setRobotPolicy( 'noindex,nofollow' );
                $this->setArticleRelated( false );
 
-               $name = User::whoIs( $wgUser->blockedBy() );
+               $name = $wgUser->blockedBy();
                $reason = $wgUser->blockedFor();
                if( $reason == '' ) {
                        $reason = wfMsg( 'blockednoreason' );
@@ -1903,29 +1916,9 @@ class OutputPage {
 
                $link = '[[' . $wgContLang->getNsText( NS_USER ) . ":{$name}|{$name}]]";
 
-               $blockid = $wgUser->mBlock->mId;
+               $blockid = $wgUser->mBlock->getId();
 
-               $blockExpiry = $wgUser->mBlock->mExpiry;
-               if ( $blockExpiry == 'infinity' ) {
-                       // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
-                       // Search for localization in 'ipboptions'
-                       $scBlockExpiryOptions = wfMsg( 'ipboptions' );
-                       foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
-                               if ( strpos( $option, ':' ) === false ) {
-                                       continue;
-                               }
-                               list( $show, $value ) = explode( ':', $option );
-                               if ( $value == 'infinite' || $value == 'indefinite' ) {
-                                       $blockExpiry = $show;
-                                       break;
-                               }
-                       }
-               } else {
-                       $blockExpiry = $wgLang->timeanddate(
-                               wfTimestamp( TS_MW, $blockExpiry ),
-                               true
-                       );
-               }
+               $blockExpiry = $wgLang->formatExpiry( $wgUser->mBlock->mExpiry );
 
                if ( $wgUser->mBlock->mAuto ) {
                        $msg = 'autoblockedtext';
@@ -1935,7 +1928,7 @@ class OutputPage {
 
                /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
                 * This could be a username, an IP range, or a single IP. */
-               $intended = $wgUser->mBlock->mAddress;
+               $intended = $wgUser->mBlock->getTarget();
 
                $this->addWikiMsg(
                        $msg, $link, $reason, $ip, $name, $blockid, $blockExpiry,
@@ -2501,10 +2494,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
+                       // Special handling for the user group; because users might change their stuff
+                       // on-wiki like 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' ) {
+                       // This should NOT be done for the site group (bug 27564) because anons get that too
+                       // and we shouldn't be putting timestamps in Squid-cached HTML
+                       if ( $group === 'user' ) {
                                // Get the maximum timestamp
                                $timestamp = 1;
                                foreach ( $modules as $module ) {
@@ -2520,18 +2515,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;
        }
@@ -2825,7 +2826,7 @@ class OutputPage {
                $ret = '';
                // Add ResourceLoader styles
                // Split the styles into four groups
-               $styles = array( 'other' => array(), 'user' => array(), 'site' => array(), 'private' => array() );
+               $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();
@@ -2843,12 +2844,12 @@ class OutputPage {
                $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' => '' ) );
+               $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', 'private', 'user' ) as $group ) {
+               foreach ( array( 'site', 'noscript', 'private', 'user' ) as $group ) {
                        $ret .= $this->makeResourceLoaderLink( $sk, $styles[$group],
                                        ResourceLoaderModule::TYPE_STYLES
                        );
@@ -3065,7 +3066,7 @@ class OutputPage {
         * @param $modules Array: list of jQuery modules which should be loaded
         * @return Array: the list of modules which were not loaded.
         * @since 1.16
-        * @deprecated @since 1.17
+        * @deprecated since 1.17
         */
        public function includeJQuery( $modules = array() ) {
                return array();