Merge "Protect -{...}- variant constructs in definition lists."
[lhc/web/wiklou.git] / includes / OutputPage.php
index 9bae882..eb2f7e7 100644 (file)
@@ -299,6 +299,9 @@ class OutputPage extends ContextSource {
         */
        private $copyrightUrl;
 
+       /** @var array Profiling data */
+       private $limitReportJSData = [];
+
        /**
         * Constructor for OutputPage. This should not be called directly.
         * Instead a new RequestContext should be created and it will implicitly create
@@ -531,14 +534,32 @@ class OutputPage extends ContextSource {
                        if ( $module instanceof ResourceLoaderModule
                                && $module->getOrigin() <= $this->getAllowedModules( $type )
                                && ( is_null( $position ) || $module->getPosition() == $position )
-                               && ( !$this->mTarget || in_array( $this->mTarget, $module->getTargets() ) )
                        ) {
+                               if ( $this->mTarget && !in_array( $this->mTarget, $module->getTargets() ) ) {
+                                       $this->warnModuleTargetFilter( $module->getName() );
+                                       continue;
+                               }
                                $filteredModules[] = $val;
                        }
                }
                return $filteredModules;
        }
 
+       private function warnModuleTargetFilter( $moduleName ) {
+               static $warnings = [];
+               if ( isset( $warnings[$this->mTarget][$moduleName] ) ) {
+                       return;
+               }
+               $warnings[$this->mTarget][$moduleName] = true;
+               $this->getResourceLoader()->getLogger()->debug(
+                       'Module "{module}" not loadable on target "{target}".',
+                       [
+                               'module' => $moduleName,
+                               'target' => $this->mTarget,
+                       ]
+               );
+       }
+
        /**
         * Get the list of modules to include on this page
         *
@@ -1266,10 +1287,12 @@ class OutputPage extends ContextSource {
                        }
                }
 
+               // Avoid PHP 7.1 warning of passing $this by reference
+               $outputPage = $this;
                # Add the remaining categories to the skin
                if ( Hooks::run(
                        'OutputPageMakeCategoryLinks',
-                       [ &$this, $categories, &$this->mCategoryLinks ] )
+                       [ &$outputPage, $categories, &$this->mCategoryLinks ] )
                ) {
                        $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
                        foreach ( $categories as $category => $type ) {
@@ -1802,16 +1825,23 @@ class OutputPage extends ContextSource {
                        }
                }
 
-               // enable OOUI if requested via ParserOutput
+               // Enable OOUI if requested via ParserOutput
                if ( $parserOutput->getEnableOOUI() ) {
                        $this->enableOOUI();
                }
 
+               // Include parser limit report
+               if ( !$this->limitReportJSData ) {
+                       $this->limitReportJSData = $parserOutput->getLimitReportJSData();
+               }
+
                // Link flags are ignored for now, but may in the future be
                // used to mark individual language links.
                $linkFlags = [];
+               // Avoid PHP 7.1 warning of passing $this by reference
+               $outputPage = $this;
                Hooks::run( 'LanguageLinks', [ $this->getTitle(), &$this->mLanguageLinks, &$linkFlags ] );
-               Hooks::run( 'OutputPageParserOutput', [ &$this, $parserOutput ] );
+               Hooks::run( 'OutputPageParserOutput', [ &$outputPage, $parserOutput ] );
        }
 
        /**
@@ -1839,7 +1869,9 @@ class OutputPage extends ContextSource {
         */
        public function addParserOutputText( $parserOutput ) {
                $text = $parserOutput->getText();
-               Hooks::run( 'OutputPageBeforeHTML', [ &$this, &$text ] );
+               // Avoid PHP 7.1 warning of passing $this by reference
+               $outputPage = $this;
+               Hooks::run( 'OutputPageBeforeHTML', [ &$outputPage, &$text ] );
                $this->addHTML( $text );
        }
 
@@ -2358,9 +2390,11 @@ class OutputPage extends ContextSource {
                        }
                        MWDebug::addModules( $this );
 
+                       // Avoid PHP 7.1 warning of passing $this by reference
+                       $outputPage = $this;
                        // Hook that allows last minute changes to the output page, e.g.
                        // adding of CSS or Javascript by extensions.
-                       Hooks::run( 'BeforePageDisplay', [ &$this, &$sk ] );
+                       Hooks::run( 'BeforePageDisplay', [ &$outputPage, &$sk ] );
 
                        try {
                                $sk->outputPage();
@@ -2499,9 +2533,10 @@ class OutputPage extends ContextSource {
                                        $query['returntoquery'] = wfArrayToCgi( $returntoquery );
                                }
                        }
-                       $loginLink = Linker::linkKnown(
+                       $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
+                       $loginLink = $linkRenderer->makeKnownLink(
                                SpecialPage::getTitleFor( 'Userlogin' ),
-                               $this->msg( 'loginreqlink' )->escaped(),
+                               $this->msg( 'loginreqlink' )->text(),
                                [],
                                $query
                        );
@@ -2997,6 +3032,14 @@ class OutputPage extends ContextSource {
                        }
                }
 
+               if ( $this->limitReportJSData ) {
+                       $chunks[] = ResourceLoader::makeInlineScript(
+                               ResourceLoader::makeConfigSetScript(
+                                       [ 'wgPageParseReport' => $this->limitReportJSData ]
+                               )
+                       );
+               }
+
                return self::combineWrappedStrings( $chunks );
        }
 
@@ -3234,9 +3277,11 @@ class OutputPage extends ContextSource {
                }
 
                foreach ( $this->mMetatags as $tag ) {
-                       if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
+                       if ( strncasecmp( $tag[0], 'http:', 5 ) === 0 ) {
                                $a = 'http-equiv';
                                $tag[0] = substr( $tag[0], 5 );
+                       } elseif ( strncasecmp( $tag[0], 'og:', 3 ) === 0 ) {
+                               $a = 'property';
                        } else {
                                $a = 'name';
                        }
@@ -3538,7 +3583,6 @@ class OutputPage extends ContextSource {
        protected function buildExemptModules() {
                global $wgContLang;
 
-               $resourceLoader = $this->getResourceLoader();
                $chunks = [];
                // Things that go after the ResourceLoaderDynamicStyles marker
                $append = [];
@@ -3671,6 +3715,8 @@ class OutputPage extends ContextSource {
         */
        public static function transformResourcePath( Config $config, $path ) {
                global $IP;
+
+               $localDir = $IP;
                $remotePathPrefix = $config->get( 'ResourceBasePath' );
                if ( $remotePathPrefix === '' ) {
                        // The configured base path is required to be empty string for
@@ -3679,12 +3725,23 @@ class OutputPage extends ContextSource {
                } else {
                        $remotePath = $remotePathPrefix;
                }
-               if ( strpos( $path, $remotePath ) !== 0 ) {
-                       // Path is outside wgResourceBasePath, ignore.
+               if ( strpos( $path, $remotePath ) !== 0 || substr( $path, 0, 2 ) === '//' ) {
+                       // - Path is outside wgResourceBasePath, ignore.
+                       // - Path is protocol-relative. Fixes T155310. Not supported by RelPath lib.
                        return $path;
                }
+               // For files in resources, extensions/ or skins/, ResourceBasePath is preferred here.
+               // For other misc files in $IP, we'll fallback to that as well. There is, however, a fourth
+               // supported dir/path pair in the configuration (wgUploadDirectory, wgUploadPath)
+               // which is not expected to be in wgResourceBasePath on CDNs. (T155146)
+               $uploadPath = $config->get( 'UploadPath' );
+               if ( strpos( $path, $uploadPath ) === 0 ) {
+                       $localDir = $config->get( 'UploadDirectory' );
+                       $remotePathPrefix = $remotePath = $uploadPath;
+               }
+
                $path = RelPath\getRelativePath( $path, $remotePath );
-               return self::transformFilePath( $remotePathPrefix, $IP, $path );
+               return self::transformFilePath( $remotePathPrefix, $localDir, $path );
        }
 
        /**