build: Upgrade mediawiki-codesniffer from 26.0.0 to 28.0.0
[lhc/web/wiklou.git] / includes / Revision / RenderedRevision.php
index 818494a..ba229d1 100644 (file)
@@ -185,6 +185,7 @@ class RenderedRevision implements SlotRenderingProvider {
         * @param array $hints Hints given as an associative array. Known keys:
         *      - 'generate-html' => bool: Whether the caller is interested in output HTML (as opposed
         *        to just meta-data). Default is to generate HTML.
+        * @phan-param array{generate-html?:bool} $hints
         *
         * @return ParserOutput
         */
@@ -212,6 +213,7 @@ class RenderedRevision implements SlotRenderingProvider {
         * @param array $hints Hints given as an associative array. Known keys:
         *      - 'generate-html' => bool: Whether the caller is interested in output HTML (as opposed
         *        to just meta-data). Default is to generate HTML.
+        * @phan-param array{generate-html?:bool} $hints
         *
         * @throws SuppressedDataException if the content is not accessible for the audience
         *         specified in the constructor.
@@ -292,6 +294,7 @@ class RenderedRevision implements SlotRenderingProvider {
                $this->setRevisionInternal( $rev );
 
                $this->pruneRevisionSensitiveOutput(
+                       $this->revision->getPageId(),
                        $this->revision->getId(),
                        $this->revision->getTimestamp()
                );
@@ -300,16 +303,25 @@ class RenderedRevision implements SlotRenderingProvider {
        /**
         * Prune any output that depends on the revision ID.
         *
+        * @param int|bool $actualPageId The actual page id, to check the used speculative page ID
+        *        against; false, to not purge on vary-page-id; true, to purge on vary-page-id
+        *        unconditionally.
         * @param int|bool $actualRevId The actual rev id, to check the used speculative rev ID
-        *        against, or false to not purge on vary-revision-id, or true to purge on
+        *        against,; false, to not purge on vary-revision-id; true, to purge on
         *        vary-revision-id unconditionally.
         * @param string|bool $actualRevTimestamp The actual rev timestamp, to check against the
-        *        parser output revision timestamp, or false to not purge on vary-revision-timestamp
+        *        parser output revision timestamp; false, to not purge on vary-revision-timestamp;
+        *        true, to purge on vary-revision-timestamp unconditionally.
         */
-       private function pruneRevisionSensitiveOutput( $actualRevId, $actualRevTimestamp ) {
+       private function pruneRevisionSensitiveOutput(
+               $actualPageId,
+               $actualRevId,
+               $actualRevTimestamp
+       ) {
                if ( $this->revisionOutput ) {
                        if ( $this->outputVariesOnRevisionMetaData(
                                $this->revisionOutput,
+                               $actualPageId,
                                $actualRevId,
                                $actualRevTimestamp
                        ) ) {
@@ -322,6 +334,7 @@ class RenderedRevision implements SlotRenderingProvider {
                foreach ( $this->slotsOutput as $role => $output ) {
                        if ( $this->outputVariesOnRevisionMetaData(
                                $output,
+                               $actualPageId,
                                $actualRevId,
                                $actualRevTimestamp
                        ) ) {
@@ -384,16 +397,20 @@ class RenderedRevision implements SlotRenderingProvider {
 
        /**
         * @param ParserOutput $out
-        * @param int|bool  $actualRevId The actual rev id, to check the used speculative rev ID
-        *        against, false to not purge on vary-revision-id, or true to purge on
+        * @param int|bool $actualPageId The actual page id, to check the used speculative page ID
+        *        against; false, to not purge on vary-page-id; true, to purge on vary-page-id
+        *        unconditionally.
+        * @param int|bool $actualRevId The actual rev id, to check the used speculative rev ID
+        *        against,; false, to not purge on vary-revision-id; true, to purge on
         *        vary-revision-id unconditionally.
         * @param string|bool $actualRevTimestamp The actual rev timestamp, to check against the
-        *        parser output revision timestamp, false to not purge on vary-revision-timestamp,
-        *        or true to purge on vary-revision-timestamp unconditionally.
+        *        parser output revision timestamp; false, to not purge on vary-revision-timestamp;
+        *        true, to purge on vary-revision-timestamp unconditionally.
         * @return bool
         */
        private function outputVariesOnRevisionMetaData(
                ParserOutput $out,
+               $actualPageId,
                $actualRevId,
                $actualRevTimestamp
        ) {
@@ -420,6 +437,13 @@ class RenderedRevision implements SlotRenderingProvider {
                ) {
                        $logger->info( "$varyMsg (vary-revision-timestamp and wrong timestamp)", $context );
                        return true;
+               } elseif (
+                       $out->getFlag( 'vary-page-id' )
+                       && $actualPageId !== false
+                       && ( $actualPageId === true || $out->getSpeculativePageIdUsed() !== $actualPageId )
+               ) {
+                       $logger->info( "$varyMsg (vary-page-id and wrong ID)", $context );
+                       return true;
                } elseif ( $out->getFlag( 'vary-revision-exists' ) ) {
                        // If {{REVISIONID}} resolved to '', it now needs to resolve to '-'.
                        // Note that edit stashing always uses '-', which can be used for both
@@ -432,7 +456,7 @@ class RenderedRevision implements SlotRenderingProvider {
                ) {
                        // If a self-transclusion used the proposed page text, it must match the final
                        // page content after PST transformations and automatically merged edit conflicts
-                       $logger->info( "$varyMsg (vary-revision-sha1 with wrong SHA-1)" );
+                       $logger->info( "$varyMsg (vary-revision-sha1 with wrong SHA-1)", $context );
                        return true;
                }