Pass user to File::recordUpload to avoid $wgUser
authorumherirrender <umherirrender_de.wp@web.de>
Mon, 18 Feb 2013 18:55:08 +0000 (19:55 +0100)
committerGerrit Code Review <gerrit@wikimedia.org>
Sat, 23 Feb 2013 12:46:28 +0000 (12:46 +0000)
Moves the giving of a user one level up, because File::recordUpload2
already needs this (and fallback to $wgUser).
Can also use the user for the watching of the file, which was using
$wgUser before.

Change-Id: I697ae0df65b07ea59ab11b62804853cdc03cb172

includes/filerepo/file/File.php
includes/filerepo/file/ForeignDBFile.php
includes/filerepo/file/LocalFile.php

index f371115..bf2749f 100644 (file)
@@ -1414,8 +1414,12 @@ abstract class File {
         * @param $copyStatus string
         * @param $source string
         * @param $watch bool
+        * @param $timestamp string|bool
+        * @param $user User object or null to use $wgUser
+        * @return bool
+        * @throws MWException
         */
-       function recordUpload( $oldver, $desc, $license = '', $copyStatus = '', $source = '', $watch = false ) {
+       function recordUpload( $oldver, $desc, $license = '', $copyStatus = '', $source = '', $watch = false, $timestamp = false, User $user = null ) {
                $this->readOnlyError();
        }
 
index b0a1ebf..610f556 100644 (file)
@@ -73,11 +73,12 @@ class ForeignDBFile extends LocalFile {
         * @param $source string
         * @param $watch bool
         * @param $timestamp bool|string
+        * @param $user User object or null to use $wgUser
         * @return bool
         * @throws MWException
         */
        function recordUpload( $oldver, $desc, $license = '', $copyStatus = '', $source = '',
-               $watch = false, $timestamp = false ) {
+               $watch = false, $timestamp = false, User $user = null ) {
                $this->readOnlyError();
        }
 
index 27386b4..11eab1e 100644 (file)
@@ -1120,20 +1120,25 @@ class LocalFile extends File {
         * @param $source string
         * @param $watch bool
         * @param $timestamp string|bool
+        * @param $user User object or null to use $wgUser
         * @return bool
         */
        function recordUpload( $oldver, $desc, $license = '', $copyStatus = '', $source = '',
-               $watch = false, $timestamp = false )
+               $watch = false, $timestamp = false, User $user = null )
        {
+               if ( !$user ) {
+                       global $wgUser;
+                       $user = $wgUser;
+               }
+
                $pageText = SpecialUpload::getInitialPageText( $desc, $license, $copyStatus, $source );
 
-               if ( !$this->recordUpload2( $oldver, $desc, $pageText, false, $timestamp ) ) {
+               if ( !$this->recordUpload2( $oldver, $desc, $pageText, false, $timestamp, $user ) ) {
                        return false;
                }
 
                if ( $watch ) {
-                       global $wgUser;
-                       $wgUser->addWatch( $this->getTitle() );
+                       $user->addWatch( $this->getTitle() );
                }
                return true;
        }