Commit graph

58 commits

Author SHA1 Message Date
Umherirrender
a9007e8baf Add missing & to @param documentation to match functon call
Change-Id: I81e68310abcbc59964b22e0e74842d509f6b1fb9
2017-08-11 18:47:46 +02:00
Aaron Schulz
7d19b4820e Remove pointless override of doStashFile in UploadFromStash
Change-Id: If6bc31d7398c68320a6633b045c33279bf6f8dbd
2016-08-17 20:58:27 +00:00
Bartosz Dziewoński
2ee27d9a4d Introduce UploadStashFile hook, improve API handling of stash errors
UploadBase:
* Introduce a new method, tryStashFile(), as a replacement for the
  now-soft-deprecated stashFile(). The method runs the new hook and
  returns a Status object, with an error (if the hook returned an
  error) or a value (if it didn't).
* Introduce a new hook, UploadStashFile, allowing extensions to
  prevent a file from being stashed. Note that code in extensions
  which has not been updated for MediaWiki 1.28 may still call
  stashFile() directly, and therefore not call this hook. For
  important checks (not just for UI), extension authors should use
  UploadVerifyFile or UploadVerifyUpload hooks.
* Extract common code of tryStashFile() and stashFile() to
  a new protected method doStashFile().

SpecialUpload:
* Use tryStashFile() when stashing a file after a warning or
  "recoverable error" was encountered.

ApiUpload:
* Refactor stashing code so that error handling only happens in one
  place, not four different ones. Use Status objects rather than
  exception throwing/catching for control flow.
* Simplify the error messages slightly (error codes are unchanged).
  Produce better ones by always using handleStashException().
  'stashfailed' is now always at root (not nested inside 'warnings'),
  behaving the same as 'filekey' does on success.
* Use tryStashFile() when stashing. Handle errors so as to allow
  custom API results passed via ApiMessage to be preserved.

Some API result changes for different requests are shown below.

  api.php?action=upload&format=json&filename=good.png&file=...&stash=1

    Before:
      {
        "error": {
          "code": "stashfilestorage",
          "info": "Could not store upload in the stash: Stashing temporary file failed: UploadStashFileException Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\".",
          "*": "See http://localhost:3080/w/api.php for API usage"
        }
      }

    After:
      {
        "error": {
          "code": "stashfilestorage",
          "info": "Could not store upload in the stash: Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\".",
          "*": "See http://localhost:3080/w/api.php for API usage"
        }
      }

  api.php?action=upload&format=json&filename=[bad].png&file=...

    Before:
      {
        "upload": {
          "result": "Warning",
          "warnings": {
            "badfilename": "-bad-.png",
            "stashfailed": "Stashing temporary file failed: UploadStashFileException Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\"."
          }
        }
      }

    After:
      {
        "upload": {
          "result": "Warning",
          "stashfailed": "Could not store upload in the stash: Error storing file in '/tmp/phpB32SRT': Could not create directory \"mwstore://local-backend/local-temp/3/3a\"."
          "warnings": {
            "badfilename": "-bad-.png",
          }
        }
      }

Bug: T140521
Change-Id: I2f574b355cd33b2e9fa7ff8e1793503b257cce65
2016-08-09 18:10:18 +02:00
Bartosz Dziewoński
521742a9ff UploadBase: Formally deprecate old methods for stashing files
Change-Id: I4c60083a4e773e401aae8c90b99a051cbca4c961
2016-08-03 01:59:36 +02:00
Bartosz Dziewoński
fba745b359 UploadFromStash: Only remove stashed file on successful uploads
Also, makes code shorter!

Change-Id: I144d8a207c753bd9e38ac847a0fc61257f11e54d
2016-01-21 23:56:16 +01:00
Vivek Ghaisas
c54766586a Fix issues identified by SpaceBeforeSingleLineComment sniff
Change-Id: I048ccb1fa260e4b7152ca5f09b053defdd72d8f9
2015-09-26 23:06:52 +00:00
Siebrand Mazeland
69a2ecfe3e Update formatting of includes/upload/
Change-Id: I8cf59cd3bb6dd8de2ed6509b7bc2ef9ff7c5caf1
2014-05-09 16:53:19 +02:00
Siebrand Mazeland
e61cb8218b Update docs and declare visibility on class props
Change-Id: Ib0f02202d075d4a56dc4e37b08d7ac9399e8c86c
2013-11-01 12:35:27 +01:00
csteipp
4233341283 SECURITY: Do checks on all upload types
Also, verify file before stashing it

Change-Id: Ib2474cb778d53959a4f479e53d0392f916b18d83
2013-05-21 13:20:06 -07:00
umherirrender
ee31d37821 Fixed spacing in context/installer/media/templates/upload folder
Added spaces before if, foreach
Added some braces for one line statements

Change-Id: I9761be9fa47adc3554852a97b19792b4648466ad
2013-04-21 06:22:06 +00:00
Marius Hoch
b3683bbd40 Make UploadBase::getTempFileSha1Base36 public
There's no obvious reason for this method to be private while
it's pretty handy to have it in hooks.

Change-Id: If716665a939e8fe84288354ee8c16369604b67fb
2013-02-28 02:42:56 +01:00
Aaron Schulz
a31d0f8edd Added async upload-from-stash support.
* This works similarly to the async concatenation code.

Change-Id: Iae38b93d65182158561b92168af51a1e9f50374c
2013-01-09 02:13:37 +00:00
umherirrender
497fddfe11 Fix method declaration in UploadFromStash
1) UploadStashTest::testValidRequest
Declaration of UploadFromStash::stashFile() should be compatible with
that of UploadBase::stashFile()

Change-Id: If94ab8b718e23b50a1b67ba0fac3ea24926d5950
2012-12-07 09:18:41 +01:00
Aaron Schulz
e5d41cca90 [Upload] [Schema] Added us_props column to avoid expensive GETs.
* We already compute the props when stashing, so including that in a column
  lets us reuse it later when the stashed file is to be published.

Change-Id: I3d6adb6528f1e992d8986058806e745c4e1c0300
2012-12-03 10:23:40 -08:00
Reedy
a69152d732 Minor bits of documentation updates to upload code
Including hint for bug 39195

Change-Id: I4cdab97011330c12a943112f6c05134362d26a82
2012-08-09 16:20:09 +01:00
awjrichards
c29fd59775 Big oops - merged to wrong branch.
Revert "Revert to arbitrarily old point before initial remote branch creation to help clean up"

This reverts commit ee0d3d330f
2012-06-05 22:58:54 +00:00
awjrichards
ee0d3d330f Revert to arbitrarily old point before initial remote branch creation to help clean up
Change-Id: I41a3d1e55d3ea9dffa42451237fe065f9334361d
2012-06-02 08:43:04 -07:00
Alexandre Emsenhuber
58bb669812 Added missing GPLv2 headers in some places.
Also made file/class documentation more consistent.

Change-Id: Ia1a7230adc92079b505362317d2e03b36130cc8b
2012-05-29 13:01:11 +02:00
Reedy
f8d2958da9 Can't return values from functions that don't return anything
Change-Id: If964ce2f39904f1e9e3101e7cafaa6a96d58adfc
2012-04-19 14:07:40 +01:00
Sam Reed
0a626db6e1 Fixing some of the "@return true" or "@return false", need to be "@return bool" and then the metadata can say true if foo, false if bar
Other documentation improvements
2012-02-09 19:29:36 +00:00
Antoine Musso
2bf8d0db90 Fix doc for includes/upload 2012-02-08 17:03:43 +00:00
Jan Gerber
0095c08ed2 Use database to track uploaded chunks and concatenate at the end.
with i18n documentation dont break phpunit

follow up r93720
2011-11-30 14:56:40 +00:00
Roan Kattouw
e83bb90997 Revert r104659 and its followup r104665: break the unit tests with a fatal error. This cripples our CI system, we can't detect new failures this way. 2011-11-30 13:54:35 +00:00
Jan Gerber
d70c169b90 Use database to track uploaded chunks and concatenate at the end.
follow up r93720
2011-11-30 08:55:16 +00:00
Sam Reed
0c8f30b3c4 Few bits of documentation 2011-10-16 22:01:10 +00:00
Sam Reed
27665d27ae Update some deprecated code
Documentation

Fix "/*" comments to "/**"

Flesh out some missing returns, change some return types
2011-10-14 21:18:38 +00:00
Ian Baker
4840027b4d UploadFromStash::stashSession returned an object instead of a file key, which broke stashing in SpecialUpload in some cases.
Fixes bug 30505
2011-08-26 23:17:43 +00:00
Ian Baker
000080990d 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
2011-08-18 23:36:24 +00:00
Ian Baker
a26afff4e0 Cleaning up little things, updates to code clarity, documentation fixes per Catrope's suggestions.
followup to r94536, r94592, r94594
2011-08-16 17:57:32 +00:00
Ian Baker
53f3c48a95 Removed the ability to pass a key into stashFile(), which simplifies the stash row creation a great deal.
Updated UploadFromUrlJob to properly use the database stash
followup to r92200
2011-08-15 23:58:40 +00:00
Ian Baker
6410788a46 checking for existence of mLocalFile in stashFile() was inverted
followup to r94536
2011-08-15 18:19:54 +00:00
Ian Baker
9cb2d4743a Fixed incorrect usage of || operator, added test
removed spurious use of empty()
listFiles() was broken, now works
followup to r92009
2011-08-15 18:10:10 +00:00
Jan Gerber
65c85b5072 Extend upload api adding an option to upload files in chunks,
using UploadStash to track the unfinished upload.
2011-08-02 10:13:56 +00:00
Ian Baker
9b50e7ade7 properly handle the case where a file disappears during the uploadwizard process
remove database records for files that move out of the stash
2011-07-14 23:01:00 +00:00
Ian Baker
c2e2c8270e Added us_status column for future expansion re Bryan's suggestion
Implemented changes suggested in code review on r92009:
 constructor bug handling passed repo/stash
 up-to-date timestamp generation
 fetching db handle from repo
 iterating over select results according to convention
 changed uploadstash.us_media_type to enum to mirror image.img_media_type
 removed (most) new references to $wgUser, instead using ApiBase::createContext to find the user
2011-07-13 19:08:51 +00:00
Ian Baker
9d4fd0c567 Refactored UploadStash and related classes to use the database for file metadata storage instead of the session, see bug 26179
Tweaked the UploadWizard to work properly with the new backend code, updated tests
2011-07-12 21:11:43 +00:00
Sam Reed
ba2c3a793d And even more documentation in various files 2011-05-29 14:25:20 +00:00
Sam Reed
b15737fa83 And even more documentation, the last of this batch 2011-05-28 19:00:01 +00:00
Sam Reed
baf83f74b8 More explicit variable definitions, function documentation 2011-02-20 13:33:42 +00:00
Sam Reed
bdb325cb4e Fixup some trailing newlines
Fixup indentation of a few methods

Add a couple of return type hints
2011-02-02 10:42:17 +00:00
Bryan Tong Minh
2b0fe5866b (bug 27021) Session key was changed somewhere from an int to a string, which broke stashed uploads totally. Changed $wgRequest->getInt to $wgRequest->getText. The API never explicitly defined it as int, so should not be affected.
Note that this also may break API clients in certain cases for strongly, statically typed languages (e.g. int sessionKey = request->sessionKey;). I see no way around this, so I will announce a breaking change on the API mailing list shortly.
2011-01-29 21:42:03 +00:00
Bryan Tong Minh
db544af120 $wgMaxUploadSize may now be set to an array to specify the upload size limit per upload type.
Backwards compatible, if not set to an array, applies to all uploads. If set to an array, per upload type maximums can be set, using the file and url keys. If the * key is set this value will be used as maximum for non-specified types.
2011-01-06 19:42:55 +00:00
Sam Reed
03e4248def Properly qualify usage of class constants 2010-12-22 00:25:16 +00:00
Alexandre Emsenhuber
2d078552de * Standardised file description headers
* Added some descriptions
* Added @file where needed
2010-08-20 20:39:04 +00:00
Bryan Tong Minh
9e63cdf976 Uploading to a protected title will allow the user to choose a new name instead of showing an error page
* Made validateNameAndOverwrite protected and moved it to validateName since overwriting is now checked in verifyPermissions()
* Fixed mime verification in case getTitle was not yet called
* Checking for overwrites no longer uses $wgUser
	
Other changes:
* convertVerifyErrorToStatus now works
* Allow passing the session key to stashSession in UploadFromStash as well
2010-07-29 13:04:34 +00:00
Mark A. Hershberger
4f771bb264 use class constant from r64403 2010-03-31 00:15:32 +00:00
Bryan Tong Minh
dd349d7b3a Merge r63621 and r63636 from REL1_16:
* Rollback chunked uploading support for 1.16
* 	Pass $sessionKey as parameter to UploadFromStash::initialize.
2010-03-12 18:26:12 +00:00
Mark A. Hershberger
2e2c089898 follow up r61407
rename UploadBase::initialize to UploadBase::initializeFileInfo
Each sub-class implements initialize() with a different prototype.  Only two sub-classes actually use the parent initialize().
2010-02-09 03:54:59 +00:00
Bryan Tong Minh
c4637d292f * Disable autofill for reuploads
* Fix UploadFromStash::initialize parameters
2009-11-04 12:53:09 +00:00
Bryan Tong Minh
c824e30197 * Updated upload hooks documentation
* Allow users to submit a modified file description without ignoring warnings
2009-10-23 20:05:31 +00:00