Gergő Tisza has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/402476 )

Change subject: Add hooks for modifying file content headers
......................................................................

Add hooks for modifying file content headers

Adds FileGetContentHeaders and FileGetContentHeadersNew hooks
for modifying what HTTP headers get sent (the first is for
existing files streamed via PHP, the second is for sending
the headers to the backend when creating a new file).

Mainly intended for extensions which provide some alternative
way of file patrolling and want to take over handling of the
X-MediaWiki-Patrol-Status header.

Bug: T167400
Change-Id: I5f30aa06401affcbad6b7be289f3b8893a4b4e1c
---
M RELEASE-NOTES-1.31
M docs/hooks.txt
M includes/filerepo/file/File.php
M includes/filerepo/file/LocalFile.php
4 files changed, 32 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/76/402476/1

diff --git a/RELEASE-NOTES-1.31 b/RELEASE-NOTES-1.31
index a496b02..ce4eb3c 100644
--- a/RELEASE-NOTES-1.31
+++ b/RELEASE-NOTES-1.31
@@ -37,6 +37,11 @@
   users during an import.
 * Added a hook, ParserOutputPostCacheTransform, to allow extensions to affect
   the ParserOutput::getText() post-cache transformations.
+* For certain file repo/backend configurations, unpatrolled files are served 
with
+  an 'X-MediaWiki-Patrol-Status: unpatrolled' header. This allows CDNs to limit
+  access to recent uploads until they get reviewed. The FileGetContentHeaders 
and
+  FileGetContentHeadersNew hooks and LocalFile::onMarkPatrolled method have 
been
+  added to aid extensions which want to interact with that.
 
 === External library changes in 1.31 ===
 
diff --git a/docs/hooks.txt b/docs/hooks.txt
index 45387a3..8a3e175 100644
--- a/docs/hooks.txt
+++ b/docs/hooks.txt
@@ -1553,6 +1553,25 @@
 &$user: user who performed the deletion
 &$reason: reason
 
+'FileGetContentHeaders': Modify HTTP headers returned when a file is requested.
+Custom headers should start with 'X-MediaWiki-'. Unless MediaWiki is configured
+to stream files via PHP, this hook will not be used most of the time a file is
+served; for certain backends, the FileGetContentHeadersNew can be used to cover
+those cases.
+$file: the File in question.
+&$headers: headers as an associative array. See the documentation for the
+  'headers' parameter of FileBackend::doOperations for details.
+
+'FileGetContentHeadersNew': Modify what HTTP headers should be returned when
+a file is requested. Called when the file is created (so the hook should not
+rely on the File object already existing). The headers will be passed to the
+backend (so this hook is only useful with a FileBackend with the ATTR_HEADERS
+feature).
+$props: array of file properties (in the format returned by MWFileProps).
+$user: the User uploading the file.
+&$headers: headers as an associative array. See the documentation for the
+  'headers' parameter of FileBackend::doOperations for details.
+
 'FileTransformed': When a file is transformed and moved into storage.
 $file: reference to the File object
 $thumb: the MediaTransformOutput object
diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php
index d67a81f..62b52de 100644
--- a/includes/filerepo/file/File.php
+++ b/includes/filerepo/file/File.php
@@ -2187,6 +2187,8 @@
         * @see MediaHandler::getContentHeaders()
         */
        public function getContentHeaders() {
+               $headers = [];
+
                $handler = $this->getHandler();
                if ( $handler ) {
                        $metadata = $this->getMetadata();
@@ -2199,10 +2201,12 @@
                                $metadata = [];
                        }
 
-                       return $handler->getContentHeaders( $metadata );
+                       $headers = $handler->getContentHeaders( $metadata );
                }
 
-               return [];
+               Hooks::run( 'FileGetContentHeaders', [ $this, &$headers ] );
+
+               return $headers;
        }
 
        /**
diff --git a/includes/filerepo/file/LocalFile.php 
b/includes/filerepo/file/LocalFile.php
index 1a27967..0f7912c 100644
--- a/includes/filerepo/file/LocalFile.php
+++ b/includes/filerepo/file/LocalFile.php
@@ -2167,6 +2167,8 @@
                        ];
                }
 
+               Hooks::run( 'FileGetContentHeadersNew', [ $props, $user, 
&$headers ] );
+
                return $headers;
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/402476
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5f30aa06401affcbad6b7be289f3b8893a4b4e1c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Gergő Tisza <gti...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to