Commit graph

92 commits

Author SHA1 Message Date
Jakub Vrana
711dc538dd Delete always true condition
The typehint doesn't allow null here.

Found by PHPStan.

Change-Id: I3e30bf49e778c42e8313a5b6de3d943ed7002c81
2018-12-02 19:28:11 +01:00
Max Semenik
6e956d55aa Replace call_user_func_array(), part 2
Uses new PHP 5.6 syntax like ...parameter unpacking and
calling anything looking like a callback to make the code more readable.
There are much more occurrences but this commit is intentionally limited
to an easily reviewable size.

In one occurrence, a simple conditional instead of trickery was much more readable.

This patch finishes all the easy stuf in the core, the remainder is either unobvious
or would result in smaller readability gains. It will be carefully dealt with in
further commits.

Change-Id: I79a16c48bfb98b75e5b99f2f6f4fa07b3ae02c5b
2018-06-07 20:19:26 -07:00
Umherirrender
bf61a77431 Change @inheritdoc to @inheritDoc
Only @inheritDoc works for the Sniff
MediaWiki.Commenting.FunctionComment

Change-Id: I91fc02cda6701d790e4334fc2bc47f230955545c
2017-08-11 16:49:52 +02:00
jenkins-bot
c3bdadc7a6 Merge "Remove FileRepoStatus references" 2016-12-22 05:58:04 +00:00
Aaron Schulz
c4d275b7d5 Remove FileRepoStatus references
Change-Id: I03190273670f5c255423cf59019cbf12220c5498
2016-12-21 19:07:33 +00:00
Matthias Mullie
90cb6aaa50 Do not lose message parameters in UploadFromChunks::verifyChunk()
This change is similar to If9ce05045ada1e3f55e031639e4c4ebc2a216de8

Having verifyChunk inside doStashFile was annoying. We'd have to
catch the exception in UploadBase::tryStashFile in order to convert
it to a proper Status object instead of the generic one that is
currently built there.
I felt like UploadBase::tryStashFile shouldn't have to be aware of
this exception, so I moved that catch into a new
UploadFromChunks::tryStashFile.
It makes no sense to perform that check twice when running
tryStashFile, so I got rid of it in doStashFile. But that also
meant we had to add it to a few other (now deprecated) places calling
doStashFile... But they should be cleaned up at some point anyway.

This will make sure we get error output like this:
"code":"filetype-bad-ie-mime",
"key":"filetype-bad-ie-mime",
"params":["text/html"]

instead of:
"code":"stashfailed",
"key":"Cannot upload this file because Internet Explorer would detect it as \"text/html\", which is a disallowed and potentially dangerous file type.",
"params":[]

Bug: T32095
Change-Id: I2fa767656cb3a5b366210042b8b504dc10ddaf68
2016-12-21 00:23:18 +00:00
Bartosz Dziewoński
e9dc2bd5f1 Do not lose message parameters in UploadFromChunks::verifyChunk()
This code is gross, and my changes do not really make it better,
but it works more correctly more often.

Bug: T147720
Change-Id: If9ce05045ada1e3f55e031639e4c4ebc2a216de8
2016-12-13 15:11:03 +00:00
Aaron Schulz
f7e3ac3f95 FSFile and TempFSFile cleanups
* Remove wf* function dependencies. This includes wfTempDir().
  Callers now should specify the directory, though it will try to do
  most of the wfTempDir() logic anyway if they do not.
* Update callers to inject wfTempDir() so $wgTmpDirectory is used by
  TempFSFile instead of it probing to find a valid directory itself.
* Move most of the wfTempDir() logic to TempFSFile::getUsableTempDirectory().
* Remove unused getMimeType() method.

Change-Id: Idd55936b07f9448a6c90577708722b7b52b8fe66
2016-09-19 19:55:09 +00:00
Bartosz Dziewoński
ec41a9c559 UploadBase: Stop mLocalFile doubling as stashed file
"I've a great idea", they said. "You know what would be cool? If I
made this boring getter, getLocalFile(), return something completely
different after the file was stashed. This will be a nice surprise for
someone in the future to discover", they added gleefully.

I am pretty sure everything still works, but I never could get async
upload publishing to work locally, so I'd appreciate some testing.

Change-Id: I11dcf2ed89e4f1dd8ddf081af521da005efdbf39
2016-08-19 03:00:30 +02:00
Bartosz Dziewoński
c9b5b3e988 Run 'UploadStashFile' hook for chunked uploads too
In UploadFromChunks, doStashFile() only stashes the current chunk,
and stashing the whole file after all chunks are uploaded is done
in concatenateChunks().

Also more custom code on top of custom code to handle ApiMessage
errors, because action=upload is special.

Follow-up to 2ee27d9a4d.

Change-Id: I968280353f15bbca9b1059631fa2cfd7c3cd2f1d
2016-08-17 17:53:08 +02:00
Aaron Schulz
4bcfe7d0ad Database transaction flushing cleanups
* Do not commit() inside masterPosWait(). This could happen
  inside JobRunner::commitMasterChanges, resulting in
  one DB committing while the others may or may not later commit.
* Migrate some commit() callers to commitMasterChanges().
* Removed unsafe upload class commit() which could break
  outer transactions.
* Also cleaned up the "flush" flag to make it harder to misuse.

Change-Id: I75193baaed979100c5338abe0c0899abba3444cb
2016-08-16 20:34:54 +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
Reedy
b5656b6953 Many more function case mismatches
Change-Id: I5d3a5eb8adea1ecbf136415bb9fd7a162633ccca
2016-03-19 00:20:58 +00:00
jenkins-bot
a25d6fbc28 Merge "Make UploadBase use TempFSFile to wrap the temporary file" 2016-03-10 20:04:54 +00:00
Aaron Schulz
dcb5ec5cbf Make UploadBase use TempFSFile to wrap the temporary file
* The cleanupTempFile() method now only marks it as ready
  for unlinking when unreferenced.
* Pass TempFSFile down the FileRepo call chain so that it
  can build off a5d903860a and allow more fast async writes
  for secondary backends. Previously, the 'store' operation
  used on upload forced sync file change replication writes.
* Also fix bogus method call in LocalFile::publishTo().

Bug: T91869
Change-Id: I06caa6e5d8bdec9a7cae2b68cb02dd2e64b9ac74
2016-03-07 20:54:06 +00:00
Aaron Schulz
35907d886e Clarify FileRepo::concatenate() docs a bit
Change-Id: I6d978a7e6c8a3671192c346eaef590aa3033cf99
2016-03-04 12:05:12 -08:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Aaron Schulz
feb03ba80a Convert updateChunkStatus to using a flush commit()
This will at least warn if an explicit transaction
from a caller via begin() is active

Change-Id: Id4198cb35368c0d92cf8abfde46c75ea09fd8f96
2015-10-07 11:06:55 -07:00
Aaron Schulz
5085a4b5cf Made wfFindFile/wfLocalFile callers use explicit "latest" flags
* Callers that should not use caches won't
* Aliased the old "bypassCache" param to "latest"

bug: T89184
Change-Id: I9f79e5942ced4ae13ba4de0b4c62908cc746e777
2015-03-06 04:18:50 +00:00
rillke
9853803750 Chunked upload: Return expected offset on offset error
Bug: T87535
Change-Id: If68e0075e73a78c1dd8d95839f7ee9374a995201
2015-02-12 17:04:41 +01:00
umherirrender
40a21ab2b8 Pass user to FileRepo::getUploadStash
This avoids use of $wgUser in UploadStash

Change-Id: I82ca69818317508109b4d5f4823a20de47f29b01
2015-01-31 21:46:05 +01:00
umherirrender
3a85ac488f Do not return anything on __construct
Change-Id: I47f67ed17112af832b19f7e7538cae3e0b8354ef
2014-08-24 11:29:45 +02:00
Yuri Astrakhan
703464a88c Cleanup - let's make IDEs more useful
http://phpdoc.org/docs/latest/references/phpdoc/types.html

If IDEs have many warnings, we don't look at them.
Let's minimize the number of warnings, and make them useful again.

* Some function docs fixes
* Removed unused $iwprefixes var in ApiQuerySearch.php
* declared private $blockStatusByUid in SpecialActiveusers
* declared private $repo in UploadFromChunks

Change-Id: Ifd20f78b168b9a913fdb8d89dc26a76a173b1c29
2014-08-13 16:02:59 -04:00
umherirrender
768ac15c70 Cleanup some docs (includes/[s-z])
- Swap "$variable type" to "type $variable"
- Added missing types
- Fixed spacing inside docs
- Makes beginning of @param/@return/@var/@throws in capital
- Changed some types to match the more common spelling

Change-Id: Ie419638e909a47aa72a274043604247830ee1a81
2014-07-24 19:43:44 +02:00
Siebrand Mazeland
69a2ecfe3e Update formatting of includes/upload/
Change-Id: I8cf59cd3bb6dd8de2ed6509b7bc2ef9ff7c5caf1
2014-05-09 16:53:19 +02:00
umherirrender
957adbef22 Fixed some @params documentation (includes/[file...|upload])
Swapped some "$var type" to "type $var" or added missing types
before the $var. Changed some other types to match the more common
spelling. Makes beginning of some text in captial.
Also added some missing @param.

Change-Id: I8804ebe0922d3a414863b162a2110e0b9e49b80f
2014-04-19 17:19:17 +02:00
Alexandre Emsenhuber
8d701eeeea Remove trailing line breaks from wfDebugLog() messages
This is useless since the message is passed through trim() and a
line break is added afterwards.

Change-Id: I1a26b30a07f7c9c749fce5bb6b2b4b3d79901b7c
2014-02-04 22:16:13 +01:00
umherirrender
f153998317 Fixed spacing
- Removed double spaces
- Added space after if/switch/foreach
- Removed space on elseif
- Added space around parentheses
- Added newline at end of file
- Removed space before semicolon at end of line

Change-Id: Id40b87e04786c6111e6686d7f7eea1e588bdf37d
2013-11-19 19:03:54 +01:00
Siebrand Mazeland
e61cb8218b Update docs and declare visibility on class props
Change-Id: Ib0f02202d075d4a56dc4e37b08d7ac9399e8c86c
2013-11-01 12:35:27 +01:00
umherirrender
24bfde2710 Fix spacing and break some lines
Change-Id: Ia57685d8858e02e399ad5c75ce64d12609d340ac
2013-08-24 17:06:25 +02: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
Timo Tijhof
acb292d733 phpcs: Fix Squiz.WhiteSpace.ScopeClosingBrace.ContentBefore violations
ERROR: Closing brace must be on a line by itself
Squiz.WhiteSpace.ScopeClosingBrace.ContentBefore

- For non-empty scopes it means the closing brace must be on a separate
  line. This is already the case in most classes in some cases the "lazy
  closing" is still used.
  array(
   'x' ); // Moved } to next line
  function () { return 'x'; } // Moved } to next line
  case 1:
    stuff; break; // Moved break to next line
- For empty function it serves as a visual distinction between there not
  being a scope block / function body and there being an empty function
  body.
  function foo(); // No body
  function foo() {} // Empty body - violation
  function bar() { // Empty body corrected
  }

Change-Id: I0310ec379c6d41cc7d483671994d027a49f32164
2013-04-11 07:34:41 +00:00
umherirrender
6c278b6d7e fix some spacing
* Removed spaces around array index
* Removed double spaces or added spaces to begin or end of function
  calls, method signature, conditions or foreachs
* Added braces to one-line ifs
* Changed multi line conditions to one line conditions
* Realigned some arrays

Change-Id: Ia04d2a99d663b07101013c2d53b3b2e872fd9cc3
2013-03-25 22:22:46 +00:00
Aaron Schulz
9671fd3ba6 Fixed E_STRICT warning:
Strict Standards: Declaration of UploadFromChunks::stashFile() should be
compatible with UploadBase::stashFile(User $user = NULL)

Change-Id: If14d7aeacb23df16bff94c5989cde4ee31c1d105
2013-03-15 05:54:08 +00:00
Tyler Anthony Romeo
4dcc7961df Fixed @param tags to conform with Doxygen format.
Doxygen expects parameter types to come before the
parameter name in @param tags. Used a quick regex
to switch everything around where possible. This
only fixes cases where a primitve variable (or a
primitive followed by other types) is the variable
type. Other cases will need to be fixed manually.

Change-Id: Ic59fd20856eb0489d70f3469a56ebce0efb3db13
2013-03-11 13:15:01 -04:00
umherirrender
f3cf109e62 remove space before semicolon
Change-Id: Ic0d890f5e27cec017c7f7910a67d53b2edf82079
2013-02-09 22:44:24 +01:00
umherirrender
824fad9956 fix some spacing
Change-Id: I78a97ad87e0bfe724fc851daf6ffeeed81887800
2013-01-26 19:15:35 +01:00
Antoine Musso
cb60d72be1 misc style fix
* makes booleans lower case
* add spaces before open braces

Change-Id: Id88884e08bc23d7730361ee91646f54f5e16920b
2012-12-20 16:09:25 +01:00
Aaron Schulz
ba5e774de9 [Upload] Added async upload concatenation support.
* Clients can send the last chunk with 'async' to get an immediate
  response and then check the status of the upload by polling the API
  using the 'checkstatus' parameter.
* Pass the User object along to stash functions within UploadFromChunks.

Change-Id: Ie2ad4c7e94862a728e8a687c3195306e16a5059e
2012-12-05 09:39:31 -08:00
umherirrender
7cc01d56b2 Add some __METHOD__ to begin/commit/rollback calls
Change-Id: I20dad8d6bb7a523e8a6f50bc0af5cdba57d7160f
2012-12-01 15:04:10 +01:00
Aaron Schulz
7ecf9ab87e Various simple optimizations for the chunked upload process.
* This adds an UnregisteredLocalFile::setLocalReference()
  function, which is used to avoid an extra GET request.
* This removes the useless rename() in stashFile(). We just
  need to make sure the stashed file has the right extension.
  Getting rid of the rename makes setLocalReference() usable.
* Also adds some debug logging with ellapsed time.

Change-Id: I087701ad0c27a4eba74591e6b49f5667b011424c
2012-11-18 12:40:30 -08:00
Siebrand Mazeland
9816c18141 Remove some unused local variables.
Also add a FIXME for a weird case.

Change-Id: I1f7f8a522fc49be85051a467455796c3f564584b
2012-10-08 02:05:49 +02:00
Aaron Schulz
3a1431aa09 Use quickImport() for upload chunk storage calls.
* Using store() is slower and causes problems with multiwrite backends,
  since the other temp storage calls already wrap doQuickOperations().
* Modified quickImport() to accept stored files as the source parameter.

Change-Id: I3b32b46ce6b5562bb661ec49255630236aeaa44c
2012-09-08 21:48:31 -07: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
Reedy
e3f2a90bf0 Remove unused variables/function values returned
Fix trailing whitespace

Change-Id: I53abf75e142f0166032b98e4adb3dabe06643017
2012-08-08 00:47:25 +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
Antoine Musso
73247df204 Remove backslash from @return types
Ping r111103
2012-02-13 16:35:59 +00:00