r93137 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93136‎ | r93137 | r93138 >
Date:22:39, 25 July 2011
Author:raindrift
Status:ok (Comments)
Tags:
Comment:
Added a workaround for the lack of RequestContext in 1.17, so this code can be rolled into production.
This code can be removed in 1.18+, but it'll work either way.
Modified paths:
  • /trunk/phase3/includes/api/ApiUpload.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiUpload.php
@@ -220,9 +220,18 @@
221221 $this->dieUsageMsg( 'invalid-file-key' );
222222 }
223223
224 - // context allows access to the current user without creating new $wgUser references
225 - $context = $this->createContext();
226 - $this->mUpload = new UploadFromStash( $context->getUser() );
 224+ if( class_exists( 'RequestContext' ) ) {
 225+ // context allows access to the current user without creating new $wgUser references
 226+ $context = $this->createContext();
 227+ $this->mUpload = new UploadFromStash( $context->getUser() );
 228+ } else {
 229+ // this is here to maintain 1.17 compatibility, so these changes can
 230+ // be merged into production
 231+ // remove this after we've moved to 1.18
 232+ global $wgUser;
 233+ $this->mUpload = new UploadFromStash( $wgUser );
 234+ }
 235+
227236 $this->mUpload->initialize( $this->mParams['filekey'], $this->mParams['filename'] );
228237
229238 } elseif ( isset( $this->mParams['file'] ) ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r93427changed api output for blacklisted entries to be something more correct and i...raindrift20:32, 28 July 2011

Comments

#Comment by Dantman (talk | contribs)   22:46, 25 July 2011

This seams a little verbose, that could be done in one line instead of 7+comments.

$this->mUpload = new UploadFromStash( class_exists( 'RequestContext' ) ? $this->createContext()->user : $GLOBALS['wgUser'] );
#Comment by 😂 (talk | contribs)   22:51, 25 July 2011

Comments are nice.

#Comment by Dantman (talk | contribs)   23:01, 25 July 2011

Sure, but separating the class_exists into two whole conditional blocks and completely duplicating the $this->mUpload = new UploadFromStash(...);?

#Comment by 😂 (talk | contribs)   23:07, 25 July 2011

I see no reason for getting panties in a bunch over it...it looks just fine to me. TBH: this fix can probably be merge straight to 1.17wmf1 and then reverted in trunk.

#Comment by Raindrift (talk | contribs)   22:52, 27 July 2011

I used to write a lot of Perl with deeply-nested map {} sort {} grep {} map {} @array; things. I thought it was very clever. Then, I realized my code was hard to read a year later. Lately, I just use intermediate containers since that's what's happening internally anyway. Along similar lines, I'm pretty shy about the ternary operator unless what's going on is just blindingly obvious.

I'm not too concerned about having a similar line in there twice. My usual test is that if I'm duplicating more than 2-3 lines of code, it's time to break it out. If I used the User object in two places, for example, I'd have stored it and moved the new UploadStash() outside the block.

My current style is probably influenced by my switch to a modern editor with block folding, and access to large monitors. I understand that people using other tools might be more concerned about the use of vertical space. So, if that's you, apologies.

#Comment by Platonides (talk | contribs)   23:10, 27 July 2011

I find this ok. But why is 1.17 compatibility code added to phase3?

#Comment by Reedy (talk | contribs)   23:12, 27 July 2011

I'm guessing he doesn't have commit access to 1.17wmf1, so committing it to trunk, for someone to merge was probably easier...

#Comment by Platonides (talk | contribs)   23:13, 27 July 2011

Add to REL1_17?

#Comment by 😂 (talk | contribs)   23:16, 27 July 2011

There is no request context in REL1_17, so no need to merge.

#Comment by Platonides (talk | contribs)   23:18, 27 July 2011

Then again, if this is not something needed for 1.17 anywhere, why is this needed? :)

#Comment by Raindrift (talk | contribs)   23:30, 27 July 2011

I'm not quite sure I understand, but let me see if this clears it up:

This version of UploadStash is needed to make the current version of UploadWizard work, and also to fix a bug that prevented simultaneous file uploads from working. Neilk and I were working on merging it into the current release branch so it could be deployed before 1.18 is released.

This code is present because the RequestContext dependency is the only thing that prevented this code from working in 1.17, but we're actively developing it in trunk. I can't commit changes against anything but trunk or my own branch, and branching for this seemed wrong. Making a change for production in a working copy and wrapping it up in a patch (but not checking it in) also seemed wrong.

It's necessary to grab the User object in the constructor because new uses of $wgUser are apparently frowned upon in 1.18+, so I'm not accessing the global each place it's used. The UploadStash from 1.17 isn't aware of the current user at all, since it stores its state in the session.

I'm sure there's a correct way to introduce code that's only needed when back-porting a feature to production. If someone feels like explaining that part of the process to me, that'd be the best.

#Comment by Raindrift (talk | contribs)   23:15, 27 July 2011

Reedy, you are correct! Platonides, I added the tag (still figuring these tags out), but I believe Neilk already packaged this up in a patch for deployment, along with the other UploadStash changes, and sent it over to Roan.

#Comment by Raindrift (talk | contribs)   23:15, 27 July 2011

(and I could learn to use the "reply" button...)

#Comment by Platonides (talk | contribs)   23:17, 27 July 2011

The tag for requesting merge with 1.17 is "1.17" REL1_17 is the name of the branch in branches svn folder, where you could have changed it directly.

#Comment by Reedy (talk | contribs)   00:08, 28 July 2011

Can leave it be... I'm guessing you're going to be replacing ApiUpload in 1.17wmf1 with the trunk version of ApiUpload too?

Status & tagging log