Rather than a cop-out of using RequestContext::getMain()->getUser(), this is going to be a larger project to ensure that a user is always passed when constructing a LocalfileDeleteBatch. The plan:
LocalFileDeleteBatch
Currently, LocalFileDeleteBatch has the following constructor:
public function __construct( File $file, $reason = '', $suppress = false, $user = null ) { $this->file = $file; $this->reason = $reason; $this->suppress = $suppress; global $wgUser; $this->user = $user ?: $wgUser; $this->status = $file->repo->newGood(); }
In order to reduce the usage of the global $wgUser variable, the $user must become required. Since it is impossible for a required variable to come after optional ones, the eventual signature will be:
public function __construct( File $file, User $user, $reason = '', $suppress = false ) {
However, the constructor will need to be backwards compatible. Since the only documented calls to create a new LocalFileDeleteBatch are in core, and will be updated alongside this change[1], using the old format for parameters will be immediately hard deprecated
[1] See https://codesearch.wmflabs.org/search/?q=LocalFileDeleteBatch&i=nope&files=&repos=
Callers
The 2 core callers are in LocalFile::deleteOld and LocalFile::delete
Both of these take an optional user parameter:
function deleteOld( $archiveName, $reason, $suppress = false, $user = null ) {
function delete( $reason, $suppress = false, $user = null ) {
Both of those will be updated to call new methods, ::deleteFile and ::deleteOldFile, which switch the user parameter to be required. The old methods will be soft deprecated, and will include temporary fallbacks to $wgUser to ensure a user is always passed to the new methods.
Summary
- 1.35: Update constructor of LocalFileDeleteBatch which maintaining backwards compatibility, immediately hard deprecate old signature, update core calls, update LocalFile::delete and LocalFile::deleteOld to call ::deleteFile and ::deleteOldFile, which have the user earlier and required, immediately soft deprecate old functions
- After step 1 is merged: update extensions to pass a user to ::deleteFile and ::deleteOldFile
- 1.35 or 1.36: Update LocalFile::delete and LocalFile::deleteOld to hard deprecated
- 1.36: Remove support for old construction of LocalFileDeleteBatch, as well as fallback to $wgUser within that class.
- 1.36 or 1.37: Remove support for LocalFile::delete and LocalFile::deleteOld
This task will be resolved when the direct callers to LocalFileDeleteBatch's constructor all hard deprecate the old code paths. All that remains is updating calls to LocalFile::delete to use ::deleteFile