Commit graph

319 commits

Author SHA1 Message Date
Umherirrender
e0fb121518 Fix ignore of local dupes in UploadBase
Was added with I455df30085c05320dca976b9f7f8fb711a083271
There is no key 'exists ' (with space) setting in the code base
'exists' is known in upload code

Change-Id: I712c4763825aeb18c750ce77365486f24a44ae86
2020-04-14 14:51:09 +02:00
Umherirrender
e28b4bd8af Use MediaWikiServices::getRepoGroup in file related classes
Change-Id: Iceec961de4f0cc689f7d3b981afac923b46c98f6
2020-03-14 12:36:27 +00:00
DannyS712
7186b63f82 Hard deprecate Title::getUserPermissionsErrors
Remove final uses as well

Bug: T244929
Change-Id: I65e937c7b9904b1e93f649508b14148849589f82
2020-02-26 05:09:55 +00:00
DannyS712
909f0bef6e Replace calls to Title::getUserPermissionsErrors (part 5)
This does //not// fix all calls in core.

Bug: T244929
Change-Id: I02ffcca31fa0bdc6bffddf21e82f4ff5e9ab5374
2020-02-26 03:00:33 +00:00
James D. Forrester
0958a0bce4 Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNull
Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
2020-01-10 14:17:13 -08:00
Thiemo Kreuz
e9c49cd14c upload: Fix incomplete type hint in UploadBase::initializePathInfo
The $fileSize parameter can be null.

I'm also removing all sudo documentation that doesn't add any
information beyond what the method and parameter names already literally
say. If code is self-documenting, repeating that does not make it easier
to read, it makes it *harder*. There is more text to read, but not more
information. The text needs to be updated, and will be wrong if forgotten.

Change-Id: I6d3fcd3aba098826d119454df923e3b1c4cc83aa
2019-12-29 11:23:39 +00:00
Máté Szabó
07bcb18c49 upload: Improve method documentation blocks
* Correct the documentation of UploadBase::verifyUpload()
  to clarify that it returns an array in all cases, and
  document possible keys.
* Change the type hint of verification methods that may return
  a boolean or a status array depending on the outcome of the
  verification from 'mixed' to 'array|bool'.

Change-Id: I39d13db457104b02fc47a77fb6bfab05b2cbdcb6
2019-12-14 20:27:13 +01:00
Max Semenik
bdf7e3f5bd Set constant visibility, part 1
Change-Id: I3dad26b1a0bd469fa84fee5c15d9b581765ceb94
2019-10-18 02:19:24 +00:00
Max Semenik
2c39c152fc UploadBase: remove HHVM support
Change-Id: I3518b043f08de6b385072d6b1f4f686d7570a648
2019-10-02 21:03:49 -07:00
Daimona Eaytoy
b138a9b228 Fix using null for a non-nullable argument
These are reported by phan as PhanTypeMismatchArgumentNullableInternal
when null_casts_as_any_type is disabled.

Change-Id: I85076ee31c1bfc59a19600e84da0d915e425890a
2019-09-19 16:55:03 +00:00
Petr Pchelko
7b4eafda0d Replace usages of deprecated User::isAllowed. Step 2.
Bug: T220191
Depends-On: I509cd88355cfd0cc074f4135ec86399b4075f89f
Change-Id: I2341e6f1d108c92924620fba3c64ec090cb09918
2019-09-11 16:00:03 -07:00
Daimona Eaytoy
5eac6d131c Unsuppress more phan issues (part 3)
Bug: T231636
Depends-On: I78354bf5f0c831108c8f606e50c87cf6bc00d8bd
Change-Id: I58e67c2b38389df874438deada4239510d21654f
2019-08-31 16:38:55 +00:00
Tim Starling
51e837f68f Don't try to store File objects to the upload session
File objects can contain closures which can't be serialized.

Instead, add makeWarningsSerializable(), which converts the warnings
to a serializable array. Make ApiUpload::transformWarnings() act on this
serializable array instead. For consistency, ApiUpload::getApiWarnings()
also needs to convert the result of checkWarnings() before transforming
it.

Bug: T228749
Change-Id: I8236aaf3683f93a03a5505803f4638e022cf6d85
2019-07-26 16:15:30 +10:00
James D. Forrester
e745bfed82 Drop UploadBase:: and UploadFromChunks::stashFileGetKey() and stashSession(), deprecated in 1.28
Change-Id: I2411753a24092a5c37434b095e594831ecff04e1
2019-07-19 13:50:13 -07:00
James D. Forrester
714797861b Drop the UploadVerification hook, deprecated in 1.28
Change-Id: Ic1917fc95223cbf97845c2702ddf98accf8ba9c2
2019-07-19 13:50:13 -07:00
Aaron Schulz
4a83841fa7 upload: move UploadBase status store from $wgMainStash to "db-replicated"
This is only triggered for chunked uploads and does not need anything
more special the local objectcache table.

Also add comments and fix numerous IDEA warnings.

Bug: T227376
Change-Id: Ia61855293a265306c5a27a9dfc0139c4d0b04c4f
2019-07-13 19:56:45 +00:00
Derick Alangi
21e2d71560 Replace some uses of deprecated wfFindFile() and wfLocalFile()
These global functions were deprecated in 1.34 and services made
available to replace them. See services below;

* wfFindFile() - MediaWikiServices::getInstance()->getRepoGroup()->findFile()
* wfLocalFind() - MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()->newFile()

NOTES:

* wfFindFile() and wfLocalFind() usages in tests have been ignored
  in this change per @Timo's comments about state of objects.

* includes/upload/UploadBase.php also maintained for now as it causes
  some failures I don't fully understand, will investigate and handle
  it in a follow up patch.

* Also, includes/MovePage.php

Change-Id: I9437494de003f40fbe591321da7b42d16bb732d6
2019-06-11 13:26:37 +00:00
Brion Vibber
2e83387666 Relax HTML sniffing checks on image upload
Allows uploaded files to include some HTML tag strings that were
previously forbidden in the first 1k or so of the file:
* <a href
* <img
* <pre
* <table
* <title

They are now allowed as long as the IE MIME type detection heuristic
would not change their types. This should reduce the number of false
positive checks in JPEGs with EXIF data with links.

Also deprecates $wgAllowTitlesInSVG and allows it by default.

This should still protect against malformed PNG attacks on old IE
versions, though false positive checks are conceivable on PNG files
containing comments very close to the beginning of the file.

Adds $wgVerifyMimeTypeIE config var to allow disabling the IE checks
entirely, if desired, but leaves it in place by default. These are
more conservative than the checks that were removed.

Added test cases for the old IE5/6 bug and the particular sort of
JPEG metadata that struck false positives previously.

Bug: T27707
Change-Id: I66642a74fce1a1894cad67d62b0da61020db469a
2019-06-07 14:21:00 -07:00
Umherirrender
62f2c52385 Fix return type of UploadBase::check* functions
Change-Id: I37964663fc8cb63575c1e0be9c5ced489d69136e
2019-06-04 21:44:51 +02:00
Derick Alangi
84292b7728 Replace deprecated function wfEscapeShellArg with Shell::escape()
Change-Id: I4046d593d1450cfffc489ca2abadba1084a540e4
2019-04-07 20:17:39 +01:00
Reedy
c13fee87d4 Collapse some nested if statements
Change-Id: I9a97325d738d09370d29d35d5254bc0dadc57ff4
2019-04-04 19:02:22 +00:00
jenkins-bot
ae58991566 Merge "upload: Simplify file extension extraction in UploadBase" 2019-03-25 06:33:58 +00:00
Thiemo Kreuz
cc329a5b06 Update PHPDoc types in several maintenance scripts and related
There is like a billion of these in our core codebase. I would love to
update them all. But I don't have the time, at least not to do them all
at once.

TL;DR: It's an improvement. :-)

Change-Id: I0a9c51bdcf0f261f971586bb8703f418324b0f98
2019-03-07 17:54:26 +00:00
Thiemo Kreuz
caf66ceb91 upload: Simplify file extension extraction in UploadBase
The code does the exact same, just shorter and hopefully better
readable.

Change-Id: Idd1d34927a5c027d378d1a54afd23dc7f33ee004
2019-02-28 12:38:52 +01:00
Aaron Schulz
be7423c52c filerepo: avoid dynamic calls to FileRepo::isVirtualUrl
Change-Id: Ie851ec33ba5d7965393e41595d0b4b9df070bd27
2019-01-18 13:03:45 -08:00
Brian Wolff
8c7b635162 Relax filter attribute filtering to allow self-referential urls
The filter attribute will often have things like filter="url( #foo )"
These local to the file filters in svgs should be fine (We already
disallow non-local xlink:href attributes on <filter> elements). In
fact, users can already do the exact same thing by doing:
style="filter: url( #foo )"

Bug: 67044
Change-Id: Ib25328c160c0d5ea7e01dc84616b76e1b9dcd0eb
2019-01-08 14:37:53 +00:00
Fomafix
3ee1560232 No yoda conditions
Replace
  if ( 42 === $foo )
by
  if ( $foo === 42 )

Change-Id: Ice320ef1ae64a59ed035c20134326b35d454f943
2018-11-21 17:54:39 +01:00
Fomafix
43244db9a2 Use PHP 7 '??' operator instead of if-then-else
Change-Id: If9d4be5d88c8927f63cbb84dfc8181baf62ea3eb
2018-10-21 21:46:46 +02:00
Umherirrender
130ec2523d Fix PhanTypeMismatchDeclaredParam
Auto fix MediaWiki.Commenting.FunctionComment.DefaultNullTypeParam sniff

Change-Id: I865323fd0295aabd06f3e3c75e0e5043fb31069e
2018-07-07 00:34:30 +00:00
Fomafix
e1630b6a53 PHP: Use short ternary operator (?:) where possible
Change-Id: Idcc7e4fcdd4d8302ceda44bf6d294fa8c2219381
2018-06-11 11:26:35 +02: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
Kunal Mehta
827cfb3351 Fix UploadBase::checkXMLEncodingMissmatch() on PHP 7.1+
file_get_contents() started supporting a negative offset in 7.1+. But
we really just want to start with 0.

Also fix the order of arguments to assertSame() so that the expected
value is first.

Bug: T182366
Change-Id: I84c92652de5b51a43f6e2b58cd235d2889093453
2018-06-06 20:13:13 -07:00
Bartosz Dziewoński
485f66f174 Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient
Find: /isset\(\s*([^()]+?)\s*\)\s*\?\s*\1\s*:\s*/
Replace with: '\1 ?? '

(Everywhere except includes/PHPVersionCheck.php)
(Then, manually fix some line length and indentation issues)

Then manually reviewed the replacements for cases where confusing
operator precedence would result in incorrect results
(fixing those in I478db046a1cc162c6767003ce45c9b56270f3372).

Change-Id: I33b421c8cb11cdd4ce896488c9ff5313f03a38cf
2018-05-30 18:06:13 -07:00
Reedy
39f0f919c5 Update suppressWarning()/restoreWarning() calls
Bug: T182273
Change-Id: I9e1b628fe5949ca54258424c2e45b2fb6d491d0f
2018-02-10 08:50:12 +00:00
Umherirrender
255d76f2a1 build: Updating mediawiki/mediawiki-codesniffer to 15.0.0
Clean up use of @codingStandardsIgnore
- @codingStandardsIgnoreFile -> phpcs:ignoreFile
- @codingStandardsIgnoreLine -> phpcs:ignore
- @codingStandardsIgnoreStart -> phpcs:disable
- @codingStandardsIgnoreEnd -> phpcs:enable

For phpcs:disable always the necessary sniffs are provided.
Some start/end pairs are changed to line ignore

Change-Id: I92ef235849bcc349c69e53504e664a155dd162c8
2018-01-01 14:10:16 +01:00
Cormac Parle
bfe0513609 Warn for uploads with new name but same content as local file
Previously warnings about the sha1 of an uploaded file being
the same as an existing file were stripped if the existing
file was in local storage - this was to avoid duplicate
warnings if a file with the same name had already been found
and had the same content. Now the warning is only stripped
for local files with the same name as the uploaded file.

Bug: T180691
Change-Id: I455df30085c05320dca976b9f7f8fb711a083271
2017-11-30 17:59:29 +00:00
Reedy
c16af68fb6 Replace MimeMagic::singleton() calls
Change-Id: Ieed41b5d6b0f568fe2872e7754f2feae7868fe7a
2017-11-27 02:13:51 +00:00
Umherirrender
3f1a52805e Use short type bool/int in param documentation
Enable the phpcs sniffs for this and used phpcbf

Change-Id: Iaa36687154ddd2bf663b9dd519f5c99409d37925
2017-08-20 13:20:59 +02:00
Umherirrender
718e63694d Add missing @param and @return documentation
Change-Id: I1d1098eec3933df6561cceef646576013ddc08c8
2017-08-11 22:17:01 +02:00
Umherirrender
a9007e8baf Add missing & to @param documentation to match functon call
Change-Id: I81e68310abcbc59964b22e0e74842d509f6b1fb9
2017-08-11 18:47:46 +02:00
jenkins-bot
2c12b1fd2a Merge "Refactor UploadBase::checkWarnings into smaller methods" 2017-07-11 05:53:17 +00:00
Umherirrender
b5cddfb27b Remove empty lines at begin of function, if, foreach, switch
Organize phpcs.xml a bit

Change-Id: Ifb767729b481b4b686e6d6444cf48b1f580cc478
2017-07-01 11:34:16 +00:00
addshore
cbf03f81d7 Refactor UploadBase::checkWarnings into smaller methods
These methods also don't access any of the class
properties and could one day be factored out into
some file checking service.

This also means that individual checks can be used for
the attached task if made protected.

Bug: T163500
Change-Id: I7cf912507ee02c35b6a666d7ed48fcab001316d3
2017-06-30 11:19:51 +00:00
Matthias Mullie
71df44bf9b Allow SVGs using an older proposed recommendation DTD
Dia software seems to use this DTD (at least in some versions)

Bug: T168856
Change-Id: I51ad7ff4a935d4edb78e091142be9c58017dd3af
2017-06-27 15:47:55 +02:00
Kunal Mehta
316641798f UploadBase: Avoid deprecated wfMemcKey()
Change-Id: I717948d6550ed2d98c3a89b3e48e161c3af15d48
2017-05-25 11:20:24 -07:00
addshore
65538b0ccd UploadBase::getTitle can return null
Change-Id: I5bd94f6233476bda43a01155f6e7d6df420412e2
2017-04-18 20:42:54 +01:00
Brian Wolff
bc31c5bd57 SECURITY: Whitelist DTD declaration in SVG
Only allow ENTITY declarations inside the doctype internal
subset. Do not allow parameter entities, recursive entity
references are entity values longer than 255 bytes, or
external entity references. Filter external doctype subset
to only allow the standard svg doctypes.

Recursive entities that are simple aliases are allowed
because people appear to use them on commons. Declaring
xmlns:xlink to have a #FIXED value to the xlink namespace
is allowed because GraphViz apparently does that so its
somewhat common.

This prevents someone bypassing filter by using default
attribute values in internal dtd subset. No browser loads
the external dtd subset that I could find, but whitelist
just to be safe anyways.

Issue reported by Cassiogomes11.

Bug: T151735
Change-Id: I7cb4690f759ad97e70e06e560978b6207d84c446
2017-04-06 13:43:04 -07:00
addshore
d2bf8056b7 Use getMainObjectStash from MediawikiServices in static UploadBase methods
Change-Id: Ic547efe231c1457b2028301b9db055d3d4e6abfe
2017-03-04 11:49:05 +00:00
jenkins-bot
766d795f27 Merge "Add missing access modifiers in UploadBase" 2017-02-28 18:34:13 +00:00
James D. Forrester
9635dda73a includes: Replace implicit Bugzilla bug numbers with Phab ones
It's unreasonable to expect newbies to know that "bug 12345" means "Task T14345"
except where it doesn't, so let's just standardise on the real numbers.

Change-Id: I6f59febaf8fc96e80f8cfc11f4356283f461142a
2017-02-21 18:13:24 +00:00