r94966 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94965‎ | r94966 | r94967 >
Date:23:36, 18 August 2011
Author:raindrift
Status:ok (Comments)
Tags:
Comment:
Two bugs:
1. When the user isn't passed to UploadFromStash::__construct(), it would break when it shouldn't.
2. When stashing files, sometimes an instance of UnregisteredLocalFile would be returned instead of UploadStashFile
Modified paths:
  • /trunk/phase3/includes/upload/UploadFromStash.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/upload/UploadFromStash.php
@@ -29,7 +29,12 @@
3030 if( $stash ) {
3131 $this->stash = $stash;
3232 } else {
33 - wfDebug( __METHOD__ . " creating new UploadStash instance for " . $user->getId() . "\n" );
 33+ if( $user ) {
 34+ wfDebug( __METHOD__ . " creating new UploadStash instance for " . $user->getId() . "\n" );
 35+ } else {
 36+ wfDebug( __METHOD__ . " creating new UploadStash instance with no user\n" );
 37+ }
 38+
3439 $this->stash = new UploadStash( $this->repo, $this->user );
3540 }
3641
@@ -100,13 +105,13 @@
101106 }
102107
103108 /**
104 - * There is no need to stash the image twice
 109+ * Stash the file.
105110 */
106111 public function stashFile() {
107 - if ( $this->mLocalFile ) {
108 - return $this->mLocalFile;
109 - }
110 - return parent::stashFile();
 112+ // replace mLocalFile with an instance of UploadStashFile, which adds some methods
 113+ // that are useful for stashed files.
 114+ $this->mLocalFile = parent::stashFile();
 115+ return $this->mLocalFile;
111116 }
112117
113118 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r95667merge r94966, r95581 into core -- will fix some fatals in prod, such as bug #...neilk15:37, 29 August 2011
r95671MFT of r94966. Slight change in brace style because ariel already committed a...neilk15:46, 29 August 2011

Comments

#Comment by Raindrift (talk | contribs)   23:48, 18 August 2011

Err, I meant to say LocalFile, not UnregisteredLocalFile.

#Comment by NeilK (talk | contribs)   17:08, 22 August 2011

Why shouldn't it break if there's no user? Not that we should call a method on a nonexistent object but shouldn't we give up in some other graceful way?

#Comment by Raindrift (talk | contribs)   18:56, 23 August 2011

Sometimes there isn't a user, like when running from a maintenance script.

#Comment by 😂 (talk | contribs)   19:01, 23 August 2011

Callers should be required to pass a user (or a dummy user) to the UploadStash constructor. Force the caller to be evil and use $wgUser, rather than pushing that logic to an otherwise clean implementation.

#Comment by NeilK (talk | contribs)   20:06, 23 August 2011

^demon: I disagree, this solution will work okay for now -- Ian & I went over this together and decided on this, but I just forgot about it in the interval between discussion & deploy. Never mind.

#Comment by 😂 (talk | contribs)   20:08, 23 August 2011

Ok for now, perhaps. I'm just saying UploadStash only relies on one global, and that's $wgUser in one place :)

#Comment by NeilK (talk | contribs)   20:15, 23 August 2011

Well, the sexy way to get the user now is to obtain it from context, right? So perhaps there could a be a 'scheduled task' context, or does this exist already?

http://www.mediawiki.org/wiki/Request_Context

Unfortunately using it makes your code undeployable at the moment. :(

Status & tagging log