Commit graph

515 commits

Author SHA1 Message Date
jenkins-bot
bd78869618 Merge "No yoda conditions" 2018-12-09 01:34:23 +00:00
jenkins-bot
d8ebafe2a0 Merge "Do not pass unused parameter" 2018-12-04 06:27:39 +00:00
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
Jakub Vrana
ffc3bb1b0a Do not pass unused parameter
Found by PHPStan.

Change-Id: I9bd5b9d134d0a551ea29ff995566a17583637caa
2018-12-01 18:01:10 +01: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
petarpetkovic
39e5d8d843 Fix spelling of word "necessary"
Bug: T201491
Change-Id: Ic983889a5702b8b8552c88ebc4d676f35e9fe61e
2018-08-16 01:35:35 +02:00
Umherirrender
130ec2523d Fix PhanTypeMismatchDeclaredParam
Auto fix MediaWiki.Commenting.FunctionComment.DefaultNullTypeParam sniff

Change-Id: I865323fd0295aabd06f3e3c75e0e5043fb31069e
2018-07-07 00:34:30 +00:00
Edward Chernenko
d88e924b6e Fix PHP warnings "preg_replace(): [...] invalid range in character class"
This was spotted when running tests on Travis (PHP 7.3 nighly, trusty).

Two expressions inside preg_replace() contained non-escaped "-" inside [],
where this "-" meant an actual "-" character.
The warning is because "-" has special meaning inside [] ("a-z" for range),
and things like [\w-.] are considered "invalid range".

Solution is to escape "-" like this: [\w\-.]

Change-Id: I41cc217081f00f54d957b6d8052ee209412f5ff6
2018-06-19 00:11:33 +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
jenkins-bot
394b04a0b2 Merge "Warn for uploads with new name but same content as local file" 2017-12-05 14:58:34 +00:00
Tim Starling
dc2948d76d A few doc comment fixups
* Remove some creation dates, they are not protected by GPL
* Remove duplicate @defgroup API
* Remove @ingroup from some @file doc comments on class files. It is not
  useful to list class files alongside classes in the doxygen module menu.
  Add @ingroup to some more class files that had @ingroup on their file,
  that was probably the author's intent.
* In PackedOverlayImageGallery, use the file comment as a class comment
* Don't put @defgroup and @file in the same comment. @defgroup makes the
  whole doc comment describe the group.
* Instead of putting AnsiTermColorer in two groups, use hierarchical
  groups.

Change-Id: If54f6e0b2bc1ea6de42045885cf836ee67b8e961
2017-12-04 11:11:52 +11: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
Matthias Mullie
d33b721c4e i18n UploadStash exception messages
In some cases, the error messages have changed slightly, mostly because
of capitalisation & punctuation.
In a few other cases (mainly UploadStashNotLoggedInException), the content
has also slightly changed (removed mention of the __METHOD__ it occurred in)

Bug: T178291
Change-Id: I184067f2d7fe0a0a2df1114d2525fd9ab95b6c86
2017-11-06 12:55:00 +00:00
Cormac Parle
df1dd9b697 Rework Upload*Exception classes to implement ILocalizedException
Bug: T154781
Change-Id: Ia64295d7ea502014586b8b8e3e3f34272b72443c
2017-11-06 12:39:11 +00:00
Brad Jorsch
fa4a909def Replace more uses of "SELECT *"
With the introduction of CommentStore, selects from various table
require certain joins or column aliases for proper operation. The
upcoming actor table change, and the suggested title table change, will
add more such requirements.

Change-Id: Ic8213bff74b8350b15cd271d0ef252e63e7e79bd
2017-10-13 19:02:56 +00:00
Brad Jorsch
01a10dba5a Remove reference to deprecated IDatabase->nextSequenceValue()
The method was deprecated and made unnecessary in Ib308190c.

Change-Id: I1729ac0b3a88270a4c2f064187a2472112aaeb1e
2017-09-01 12:28:39 -04:00
Prateek Saxena
7cdc15164a UploadFromUrl: Fix typo
Change-Id: I4df0db5b4a0df0191e1eaa305fc49f1959c4a354
2017-08-31 21:11:06 +10: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
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
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
cf9f186e3f Fix log msg param in UploadFromUrl::saveTempFileChunk
$this->nbytes does not exist and is never written to.
It is probably intended that this uses the local $nbytes.

Change-Id: I8e923a27625d04c81b2e272a597d40d59397851f
2017-03-22 10:39:46 +00: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
addshore
c1968a584d Add missing access modifiers in UploadBase
Change-Id: Ia7a755ec3871f786b440005003f05ed91c14ce5b
2017-02-21 16:49:05 +00:00
Bartosz Dziewoński
3313b348cc UploadBase: Allow RDF Schema namespace in SVG files
Bug: T153285
Change-Id: I88938644e7e35ce9372ec33be687c7a899970534
2017-01-19 16:14:40 +01: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
jenkins-bot
8c1086225d Merge "Do not lose message parameters in UploadFromChunks::verifyChunk()" 2016-12-21 05:59:36 +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
rlot
0d742832f4 upload: Avoid &$this in hooks
&$this triggers warnings in PHP 7.1. Simply renaming the variable before
passing it by reference avoids the warning, without breaking backwards
compatibility.

Bug: T153505
Change-Id: I78ea04a01ecce82294837e92c2a05b00ffb6e0f6
2016-12-20 15:24:58 -08: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
f525c72590 Rename getSlaveDB() FileRepo method to getReplicaDB()
The old name is left as an alias.

Change-Id: I60ab2cd5ce05df4247d5e25b017d2debee56554e
2016-11-18 07:42:39 -08:00
Mark Holmquist
a3d562ccd1 Allow empty href in SVGs
bawolff is right, this shouldn't harm anything.

Bug: T149549
Change-Id: I377efdee7478940154ef5ec921bd0c8f7ec0c110
2016-10-31 08:29:38 -05:00
Bartosz Dziewoński
19d692051f UploadBase: Permit SVG files with broken namespace definition (Inkscape bug)
Inkscape mangles namespace definitions created by Adobe Illustrator
(apparently it can't parse custom entities or something, maybe just
in 'xmlns' attributes). These files are still valid SVG, and not
a security issue (although Illustrator probably won't like them),
so it's okay to allow them.

Added tests with some example files.

* buggynamespace-original.svg
  File generated by Illustrator (edited by hand to reduce filesize).
  Based on <https://commons.wikimedia.org/w/?curid=16495597>.

* buggynamespace-okay.svg
  The original file, opened and saved in Inkscape (no other changes).

* buggynamespace-okay2.svg
  The original file, opened and saved in Inkscape twice.

* buggynamespace-bad.svg
  The original file, edited by hand to remove custom entities.
  This is not valid XML and should be rejected (although it's valid
  when parsed as HTML, and some image viewers might display it).

* buggynamespace-evilhtml.svg
  An SVG file using an entity declared namespace for a namespace
  we want to ban. Based on buggynamespace-original.svg.

Bug: T144827
Change-Id: I0eb9766cab86a58d729f10033c64f57d2076d917
2016-10-27 10:24:32 +00:00