Merge "Rename CDN config variables to be generic, deprecating the old names"
[lhc/web/wiklou.git] / includes / OutputPage.php
index 1da8ac8..54b3ee5 100644 (file)
@@ -548,15 +548,6 @@ class OutputPage extends ContextSource {
                $this->mModules = array_merge( $this->mModules, (array)$modules );
        }
 
-       /**
-        * @deprecated since 1.33 Use getModules() instead.
-        * @return array
-        */
-       public function getModuleScripts() {
-               wfDeprecated( __METHOD__, '1.33' );
-               return [];
-       }
-
        /**
         * Get the list of style-only modules to load on this page.
         *
@@ -755,10 +746,10 @@ class OutputPage extends ContextSource {
                        'user' => $this->getUser()->getTouched(),
                        'epoch' => $config->get( 'CacheEpoch' )
                ];
-               if ( $config->get( 'UseSquid' ) ) {
+               if ( $config->get( 'UseCdn' ) ) {
                        $modifiedTimes['sepoch'] = wfTimestamp( TS_MW, $this->getCdnCacheEpoch(
                                time(),
-                               $config->get( 'SquidMaxage' )
+                               $config->get( 'CdnMaxAge' )
                        ) );
                }
                Hooks::run( 'OutputPageCheckLastModified', [ &$modifiedTimes, $this ] );
@@ -827,7 +818,7 @@ class OutputPage extends ContextSource {
         * @return int Timestamp
         */
        private function getCdnCacheEpoch( $reqTime, $maxAge ) {
-               // Ensure Last-Modified is never more than (wgSquidMaxage) in the past,
+               // Ensure Last-Modified is never more than $wgCdnMaxAge in the past,
                // because even if the wiki page content hasn't changed since, static
                // resources may have changed (skin HTML, interface messages, urls, etc.)
                // and must roll-over in a timely manner (T46570)
@@ -1487,7 +1478,7 @@ class OutputPage extends ContextSource {
                        $helpUrl = $to;
                } else {
                        $toUrlencoded = wfUrlencode( str_replace( ' ', '_', $to ) );
-                       $helpUrl = "//www.mediawiki.org/wiki/Special:MyLanguage/$toUrlencoded";
+                       $helpUrl = "https://www.mediawiki.org/wiki/Special:MyLanguage/$toUrlencoded";
                }
 
                $link = Html::rawElement(
@@ -2198,8 +2189,6 @@ class OutputPage extends ContextSource {
         * @return ParserOutput
         */
        private function parseInternal( $text, $title, $linestart, $tidy, $interface, $language ) {
-               global $wgParser;
-
                if ( is_null( $title ) ) {
                        throw new MWException( 'Empty $mTitle in ' . __METHOD__ );
                }
@@ -2212,7 +2201,7 @@ class OutputPage extends ContextSource {
                        $oldLang = $popts->setTargetLanguage( $language );
                }
 
-               $parserOutput = $wgParser->getFreshParser()->parse(
+               $parserOutput = MediaWikiServices::getInstance()->getParser()->getFreshParser()->parse(
                        $text, $title, $popts,
                        $linestart, true, $this->mRevisionId
                );
@@ -2259,12 +2248,12 @@ class OutputPage extends ContextSource {
         *
         * @param string|int|float|bool|null $mtime Last-Modified timestamp
         * @param int $minTTL Minimum TTL in seconds [default: 1 minute]
-        * @param int $maxTTL Maximum TTL in seconds [default: $wgSquidMaxage]
+        * @param int $maxTTL Maximum TTL in seconds [default: $wgCdnMaxAge]
         * @since 1.28
         */
        public function adaptCdnTTL( $mtime, $minTTL = 0, $maxTTL = 0 ) {
                $minTTL = $minTTL ?: IExpiringStore::TTL_MINUTE;
-               $maxTTL = $maxTTL ?: $this->getConfig()->get( 'SquidMaxage' );
+               $maxTTL = $maxTTL ?: $this->getConfig()->get( 'CdnMaxAge' );
 
                if ( $mtime === null || $mtime === false ) {
                        return $minTTL; // entity does not exist
@@ -2527,6 +2516,37 @@ class OutputPage extends ContextSource {
                return $config->get( 'OriginTrials' );
        }
 
+       private function getReportTo() {
+               $config = $this->getConfig();
+
+               $expiry = $config->get( 'ReportToExpiry' );
+
+               if ( !$expiry ) {
+                       return false;
+               }
+
+               $endpoints = $config->get( 'ReportToEndpoints' );
+
+               if ( !$endpoints ) {
+                       return false;
+               }
+
+               $output = [ 'max_age' => $expiry, 'endpoints' => [] ];
+
+               foreach ( $endpoints as $endpoint ) {
+                       $output['endpoints'][] = [ 'url' => $endpoint ];
+               }
+
+               return json_encode( $output, JSON_UNESCAPED_SLASHES );
+       }
+
+       private function getFeaturePolicyReportOnly() {
+               $config = $this->getConfig();
+
+               $features = $config->get( 'FeaturePolicyReportOnly' );
+               return implode( ';', $features );
+       }
+
        /**
         * Send cache control HTTP headers
         */
@@ -2547,7 +2567,7 @@ class OutputPage extends ContextSource {
 
                if ( $this->mEnableClientCache ) {
                        if (
-                               $config->get( 'UseSquid' ) &&
+                               $config->get( 'UseCdn' ) &&
                                !$response->hasCookies() &&
                                !SessionManager::getGlobalSession()->isPersistent() &&
                                !$this->isPrintable() &&
@@ -2564,7 +2584,7 @@ class OutputPage extends ContextSource {
                                        # start with a shorter timeout for initial testing
                                        # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
                                        $response->header(
-                                               "Surrogate-Control: max-age={$config->get( 'SquidMaxage' )}" .
+                                               "Surrogate-Control: max-age={$config->get( 'CdnMaxAge' )}" .
                                                "+{$this->mCdnMaxage}, content=\"ESI/1.0\""
                                        );
                                        $response->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
@@ -2694,6 +2714,16 @@ class OutputPage extends ContextSource {
                        $response->header( "Origin-Trial: $originTrial", false );
                }
 
+               $reportTo = $this->getReportTo();
+               if ( $reportTo ) {
+                       $response->header( "Report-To: $reportTo" );
+               }
+
+               $featurePolicyReportOnly = $this->getFeaturePolicyReportOnly();
+               if ( $featurePolicyReportOnly ) {
+                       $response->header( "Feature-Policy-Report-Only: $featurePolicyReportOnly" );
+               }
+
                ContentSecurityPolicy::sendHeaders( $this );
 
                if ( $this->mArticleBodyOnly ) {
@@ -2959,46 +2989,6 @@ class OutputPage extends ContextSource {
                $this->addHTML( $message );
        }
 
-       /**
-        * @deprecated 1.32 Use OutputPage::showFatalError or throw FatalError instead.
-        */
-       public function showUnexpectedValueError( $name, $val ) {
-               wfDeprecated( __METHOD__, '1.32' );
-               $this->showFatalError( $this->msg( 'unexpected', $name, $val )->escaped() );
-       }
-
-       /**
-        * @deprecated 1.32 Use OutputPage::showFatalError or throw FatalError instead.
-        */
-       public function showFileCopyError( $old, $new ) {
-               wfDeprecated( __METHOD__, '1.32' );
-               $this->showFatalError( $this->msg( 'filecopyerror', $old, $new )->escaped() );
-       }
-
-       /**
-        * @deprecated 1.32 Use OutputPage::showFatalError or throw FatalError instead.
-        */
-       public function showFileRenameError( $old, $new ) {
-               wfDeprecated( __METHOD__, '1.32' );
-               $this->showFatalError( $this->msg( 'filerenameerror', $old, $new )->escaped() );
-       }
-
-       /**
-        * @deprecated 1.32 Use OutputPage::showFatalError or throw FatalError instead.
-        */
-       public function showFileDeleteError( $name ) {
-               wfDeprecated( __METHOD__, '1.32' );
-               $this->showFatalError( $this->msg( 'filedeleteerror', $name )->escaped() );
-       }
-
-       /**
-        * @deprecated 1.32 Use OutputPage::showFatalError or throw FatalError instead.
-        */
-       public function showFileNotFoundError( $name ) {
-               wfDeprecated( __METHOD__, '1.32' );
-               $this->showFatalError( $this->msg( 'filenotfound', $name )->escaped() );
-       }
-
        /**
         * Add a "return to" link pointing to a specified title
         *
@@ -3391,8 +3381,9 @@ class OutputPage extends ContextSource {
 
                $title = $this->getTitle();
                $ns = $title->getNamespace();
-               $canonicalNamespace = MWNamespace::exists( $ns )
-                       ? MWNamespace::getCanonicalName( $ns )
+               $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
+               $canonicalNamespace = $nsInfo->exists( $ns )
+                       ? $nsInfo->getCanonicalName( $ns )
                        : $title->getNsText();
 
                $sk = $this->getSkin();
@@ -4191,16 +4182,6 @@ class OutputPage extends ContextSource {
                wfDeprecated( __METHOD__, '1.31' );
        }
 
-       /**
-        * @return bool
-        * @since 1.23
-        * @deprecated since 1.31, use $poOptions to addParserOutput() instead.
-        */
-       public function sectionEditLinksEnabled() {
-               wfDeprecated( __METHOD__, '1.31' );
-               return true;
-       }
-
        /**
         * Helper function to setup the PHP implementation of OOUI to use in this request.
         *