Remove HWLDFWordAccumulator, deprecated in 1.28
[lhc/web/wiklou.git] / includes / OutputPage.php
index cb90ccf..859593b 100644 (file)
@@ -2187,7 +2187,7 @@ class OutputPage extends ContextSource {
         * Parse wikitext and return the HTML (internal implementation helper)
         *
         * @param string $text
-        * @param Title The title to use
+        * @param Title $title The title to use
         * @param bool $linestart Is this the start of a line?
         * @param bool $tidy Whether the output should be tidied
         * @param bool $interface Use interface language (instead of content language) while parsing
@@ -2527,6 +2527,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
         */
@@ -2678,10 +2709,6 @@ class OutputPage extends ContextSource {
                $response->header( 'Content-language: ' .
                        MediaWikiServices::getInstance()->getContentLanguage()->getHtmlCode() );
 
-               if ( !$this->mArticleBodyOnly ) {
-                       $sk = $this->getSkin();
-               }
-
                $linkHeader = $this->getLinkHeader();
                if ( $linkHeader ) {
                        $response->header( $linkHeader );
@@ -2698,6 +2725,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 ) {
@@ -2984,7 +3021,7 @@ class OutputPage extends ContextSource {
         */
        public function showFileRenameError( $old, $new ) {
                wfDeprecated( __METHOD__, '1.32' );
-               $this->showFatalError( $this->msg( 'filerenameerror', $old, $new )->escpaed() );
+               $this->showFatalError( $this->msg( 'filerenameerror', $old, $new )->escaped() );
        }
 
        /**
@@ -3223,7 +3260,10 @@ class OutputPage extends ContextSource {
                // Use an IE conditional comment to serve the script only to old IE
                $pieces[] = '<!--[if lt IE 9]>' .
                        ResourceLoaderClientHtml::makeLoad(
-                               ResourceLoaderContext::newDummyContext(),
+                               new ResourceLoaderContext(
+                                       $this->getResourceLoader(),
+                                       new FauxRequest( [] )
+                               ),
                                [ 'html5shiv' ],
                                ResourceLoaderModule::TYPE_SCRIPTS,
                                [ 'sync' => true ],
@@ -3785,26 +3825,24 @@ class OutputPage extends ContextSource {
                if ( $config->get( 'EnableCanonicalServerLink' ) ) {
                        if ( $canonicalUrl !== false ) {
                                $canonicalUrl = wfExpandUrl( $canonicalUrl, PROTO_CANONICAL );
-                       } else {
-                               if ( $this->isArticleRelated() ) {
-                                       // This affects all requests where "setArticleRelated" is true. This is
-                                       // typically all requests that show content (query title, curid, oldid, diff),
-                                       // and all wikipage actions (edit, delete, purge, info, history etc.).
-                                       // It does not apply to File pages and Special pages.
-                                       // 'history' and 'info' actions address page metadata rather than the page
-                                       // content itself, so they may not be canonicalized to the view page url.
-                                       // TODO: this ought to be better encapsulated in the Action class.
-                                       $action = Action::getActionName( $this->getContext() );
-                                       if ( in_array( $action, [ 'history', 'info' ] ) ) {
-                                               $query = "action={$action}";
-                                       } else {
-                                               $query = '';
-                                       }
-                                       $canonicalUrl = $this->getTitle()->getCanonicalURL( $query );
+                       } elseif ( $this->isArticleRelated() ) {
+                               // This affects all requests where "setArticleRelated" is true. This is
+                               // typically all requests that show content (query title, curid, oldid, diff),
+                               // and all wikipage actions (edit, delete, purge, info, history etc.).
+                               // It does not apply to File pages and Special pages.
+                               // 'history' and 'info' actions address page metadata rather than the page
+                               // content itself, so they may not be canonicalized to the view page url.
+                               // TODO: this ought to be better encapsulated in the Action class.
+                               $action = Action::getActionName( $this->getContext() );
+                               if ( in_array( $action, [ 'history', 'info' ] ) ) {
+                                       $query = "action={$action}";
                                } else {
-                                       $reqUrl = $this->getRequest()->getRequestURL();
-                                       $canonicalUrl = wfExpandUrl( $reqUrl, PROTO_CANONICAL );
+                                       $query = '';
                                }
+                               $canonicalUrl = $this->getTitle()->getCanonicalURL( $query );
+                       } else {
+                               $reqUrl = $this->getRequest()->getRequestURL();
+                               $canonicalUrl = wfExpandUrl( $reqUrl, PROTO_CANONICAL );
                        }
                }
                if ( $canonicalUrl !== false ) {
@@ -3948,10 +3986,8 @@ class OutputPage extends ContextSource {
         * @return string HTML fragment
         */
        protected function styleLink( $style, array $options ) {
-               if ( isset( $options['dir'] ) ) {
-                       if ( $this->getLanguage()->getDir() != $options['dir'] ) {
-                               return '';
-                       }
+               if ( isset( $options['dir'] ) && $this->getLanguage()->getDir() != $options['dir'] ) {
+                       return '';
                }
 
                if ( isset( $options['media'] ) ) {