Commit graph

37 commits

Author SHA1 Message Date
Umherirrender
b126dbe3f2 Fix various documentation related to null types
The functions returning null or the class property is set explict null

Found by phan strict checks

Change-Id: I4a271093fb6526564d8083a08249c64cb21f2453
2022-02-26 10:31:24 +01:00
Siddharth VP
061ee25f7e Fix typos in comments (E-H)
Change-Id: I0748e0d5962fa909fdd6b7fcae4ab259bde4cdf1
2021-12-30 18:14:43 +05:30
Thiemo Kreuz
b4c63c64ae Remove some more comments that literally repeat the code
Nothing to learn from these.

You can find a longer explanation in the comments in I93751e6.

Change-Id: I195aae70fc282b58be5b18160783f27d38605d15
2021-12-09 19:01:36 +01:00
jenkins-bot
3690fb0f5d Merge "Use DeletePage in FileDeleteForm and fix output of ApiDelete" 2021-11-23 09:55:55 +00:00
Reedy
2a2bb1e9bd Remove or replace usages of "sane"
Bug: T254646
Change-Id: I096b2cf738a1395a14f1d47bcbed0c2c686c2581
2021-11-22 13:35:17 +00:00
Reedy
7bf779524a Remove or replace usages of "sanity"
Bug: T254646
Change-Id: I2b120f0b9c9e1dc1a6c216bfefa3f2463efe1001
2021-11-19 23:19:42 +00:00
Daimona Eaytoy
b77ae63e48 Use DeletePage in FileDeleteForm and fix output of ApiDelete
- Use DeletePage in FileDeleteForm instead of
  WikiPage::doDeleteArticleReal
- Properly handle scheduled deletions in FileDeleteForm: previously, a
  null status value could indicate a missing page OR a scheduled
  deletion, but the code always assumed the first, and it would generate
  a duplicated log entry. The API response would also not contain the
  "delete-scheduled" message. This has been broken since the introduction
  of scheduled deletion.
- In ApiDelete, for file deletions, check whether the status is OK not
  good. The two might be equivalent, but this way it's more consistent.
- Add some documentation for the Status objects returned by file-related
  methods. This is still incomplete, as there are many methods using
  Status and none of them says what the status could be. In particular,
  this means that for now we keep checking whether the status is OK
  instead of good, even though it's unclear what could produce a
  non-fatal error.
- In LocalFileDeleteBatch, avoid using a class property for the returned
  status, as that's hard to follow. Instead, use a local variable and
  pass it around when needed.

Bug: T288758
Change-Id: I22d60c05bdd4a3ea531e63dbb9e49efc36935137
2021-11-18 01:41:51 +01:00
Tim Starling
65b1b6b56a Remove $wgShellLocale, always use C
$wgShellLocale was a flawed solution to the problem of locale
dependence. MediaWiki has its own concept of locale (the Language
hierarchy) and any kind of dependence on the server's libc locale is
incorrect and harmful, leading to bugs. Developers have an expectation
that functions like strtolower() will work in a certain way, and
respecting the locale set in the environment at install time violates
this expectation.

The problems with using C as a locale, which led to $wgShellLocale, are:

* escapeshellarg() will strip non-ASCII characters. This can be worked
  around by not using it. The security vulnerability it was trying to
  fix can be prevented in another way.
* Shell commands like rsvg will fail to correctly interpret UTF-8
  arguments. This is the reason for the putenv(). On Linux, this can
  be fixed by using C.UTF-8, which we didn't know at the time. On
  Windows, the problem is not relevant (there are unrelated issues
  with UTF-8 arguments).

Bug: T291234
Change-Id: Ib5ac0e7bc720dcc094303a358ee1c7bbdcfc6447
2021-09-24 17:25:01 -07:00
Umherirrender
220ada99b9 FileBackend: Do not use SOCKET_ENOENT on windows
It is a unix specific constant

Change-Id: I02b41e72d0aa740d3db1572f59ab0fb893b88f42
2021-01-05 02:15:05 +01:00
Tim Starling
5b1c7fc157 Fix English/*nix specific error messages in FSFileBackend
FileBackend::getFileList() is supposed to return an empty array when the
specified path does not exist, however this was broken on Windows due to
a difference in the exception message raised by DirectoryIterator.

Unit tests and code inspection showed that there were several other
instances of unmatched Windows error messages, which I also fixed. Now
FileBackendIntegrationTest passes on Windows.

It was also broken when $wgShellLocale is set to a non-English locale.
Recommend against this in the default LocalSettings.php. Work around
the issue using socket_strerror() if available. I was able to confirm
the bug and the fix using the existing tests.

Bug: T265778
Change-Id: I2b4cfbb1554d9e05cce53513f4b474064fb57de5
2020-12-03 15:00:02 +11:00
Matěj Suchánek
51642e0aae Replace tabs with spaces
Change-Id: Id034c34a294585f58dba58c26db466e0e39cb557
2020-09-04 18:04:07 +02:00
Timo Tijhof
b547aa6396 Use PHP_OS_FAMILY instead of substr(PHP_OS,0,3) for Windows checks
This is new in PHP 7.2, and has a documented set of values at
<https://www.php.net/manual/en/reserved.constants.php>.

Change-Id: If732a652f091c26d7d645766ba6e76fbf464f755
2020-06-13 19:44:00 +00:00
Aaron Schulz
fff1e12362 filebackend: rename $dir variables to $fsDirectory in FSFilebackend for clarity
Change-Id: Ia8797899d39cc114fce9d52a02729c49397ef387
2019-10-22 02:29:36 +00:00
Aaron Schulz
752ad738e9 filebackend: reduce unnecessary stat calls in FileBackend some cases
* Only call FileBackend::clearCache() only specific file paths.
  Make FSFileBackend respect specific path lists in doClearCache().
* Detect FSFileBackendList errors during initialization rather than
  doing additional stat calls beforehand.
* Simplify FSFileBackend::doPrepareInternal() by removing is_readable()
  check as well as is_writable() when mkdir() was just successfully run.
* Simplify FSFileBackend::isPathUsableInternal() to just look at the
  parent directory (more likely to exist and be cacheable). Since files
  are renamed into place, there isn't much need to sanity check the
  target file path itself.
* Add a process cache for "usable directories" to FSFileBackend.
* Use is_dir() in TempFSFile to avoid triggering access() syscalls
  each time.

Change-Id: Ib2c76f4c4117b9beffd89370498aa57b5972f167
2019-10-22 02:29:26 +00:00
Aaron Schulz
6cd695605c filebackend: optimize 'create', 'store', and 'copy' in FSFileBackend
Avoid latency of more race-condition prone is_file() calls.
Make the create/store/copy operations stream the file to a temp file
on the same device as the destination and then rename the temp file
over the destination file on success.

Use fopen() with stream_copy_to_stream() to avoid weird NFS copy()
bug and to be able to check the size properly without worrying about
race conditions since fstat() will be for the same inode that fopen()
worked on, even if the file was renamed over in the middle.

Since all operations to the "real" files happen via rename()/unlink()
or some script using the same underlying FS methods, this means that
FSFileBackend has isolation and atomicity closer to SwiftFileBackend
for these files.

Refactor the FSFileOpHandle/doExecuteOpHandlesInternal() chmod logic
to be in one place. Replace variables named $path with clearer $fsPath.

Change-Id: Ie07ec930b5cd2bcfea7b5aca11f6a667c6928e56
2019-10-16 12:37:27 -07:00
Reedy
9a913a1d21 Remove Windows PHP < 7.1 edgecase from FSFileBackend::getFeatures()
Change-Id: Ic849384ebd2195f8fc5ed58333374653d972f68c
2019-10-12 22:42:58 +01:00
Umherirrender
6c64f01c23 Fix spaces in doc comments
Change-Id: Ic404324003d40569d0ddb697c8b1bcf95f28e2ec
2019-09-12 21:45:18 +02:00
Aaron Schulz
e021adabb9 filebackend: remove unneeded is_dir() call in FSFileBackend::doCleanInternal()
Change-Id: Ia630e2052edd31f0d9b6ed7068497dc4ae66d917
2019-09-10 03:13:34 +00:00
jenkins-bot
cd898eb4ed Merge "filebackend: use self:: instead of FileBackend:: for some constant uses" 2019-09-08 14:38:17 +00:00
Aaron Schulz
e390198c4e filebackend: use self:: instead of FileBackend:: for some constant uses
Change-Id: Iae82a074ef9da3c36b34713d31ec65407d2a90b7
2019-09-08 14:15:19 +00:00
Aaron Schulz
417dea8e95 filebackend: optimize 'move' in FSFileBackend to avoid is_file() calls
Also, remove clearstatcache() call that is redundant with moveInternal()

Change-Id: I56e6c3d91427e7d0b49011f884b77daa5eb0b61c
2019-09-07 15:18:43 -07:00
Aaron Schulz
00e4420020 filebackend: optimize 'delete' for FSFileBackend to avoid is_file() calls
This also should reduce the chance of warnings due to race conditions

Change-Id: I06b6bcc5e0f009bb3d5135591d13ff098710a5b3
2019-09-07 15:06:28 -07:00
Aaron Schulz
28a23740d8 filebackend: optimize the chmod() calls in FSFileBackend
Bypass the calls in Windows to avoid the stat overhead. The file system
will almost always be NTFS, in which case it can't do anything since the
ACL model is totally different than that of Unix.

Add chmod calls to the existing command in FSFileOpHandle rather than
doing them all serially afterwards.

Use AtEase class for more simple error suppression cases.

Change-Id: Ib4fae9a1bf64c1a9dfde8debe724556633a5532c
2019-09-07 22:02:10 +00:00
Aaron Schulz
903f1810c8 filebackend: improve internal use of FileBackend constants
Add more result constants and split up FileBackend::UNKNOWN for
clarity. This follows up 5719815f3b, which added that constant.

Make internal FileBackendStore::doGet* methods distinguish I/O errors
from missing files; the return types of public FileBackend methods are
unchanged. Avoid process caching any mtime/size/sha1 values in the
case of I/O errors. Use error constants consistently for stat methods
when given invalid paths.

Also:
* Factor out FileBackendStore::processCacheAndPersistStatEntries() method
  to reduce significant code duplication.
* Consolidate duplicated isPathUsable() checks in FileOp subclasses to
  FileOp::precheck().
* Remove null process cache value check from FileBackend::getFileStat()
  as null values are never stored in the process cache to begin with.
* Reformat some oddly wrapped lines to look cleaner.

Change-Id: Id0e4b0da0bb2ed3184847b35142d587c7f3d953d
2019-09-03 19:31:17 -07:00
Aaron Schulz
5719815f3b filebackend: add idiom constant to FileBackend for null results
Change-Id: I65f043e87d82192c13d3627fb45ef222f0290bf8
2019-08-29 01:19:33 -07:00
Timo Tijhof
bebb26eb26 filebackend: Remove private handleWarning in favour of local closure
This is a pattern from before PHP 5.3, which we no longer need.

Change-Id: I886d1ded25ffe1ee12b6a3f8d48c04aa7dd2ef51
2019-08-23 20:37:45 +00:00
Aryeh Gregor
a83b33582a TempFSFileFactory service
This replaces TempFSFile::factory(), which is now deprecated.

Change-Id: I9e65c3867e26c16687560dccc7d9f3e195a8bdd6
2019-08-21 16:26:05 +03:00
Reedy
7f04a47d68 Split filebackend files to class per file
Change-Id: Idf9f4177fb9a523ce41227bda2af923bf418396b
2019-04-14 23:02:13 +01:00
Fomafix
9cbb8f104d Use https://www.php.net/ instead of https://secure.php.net/
Change-Id: I0acca592c6909e91b28b904da49dcbd6a43cd2a5
2019-04-12 06:44:48 +02:00
Kunal Mehta
cc5d9a92a2 build: Updating mediawiki/mediawiki-codesniffer to 24.0.0
Change-Id: I66b1775b7c1d36076d9ca78cbeb42787a743f2aa
2019-02-07 18:39:42 +00: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
Fomafix
d65ac78277 Replace HTTP by HTTPS
* https://www.unicode.org/ instead of http://www.unicode.org/ or
  http://unicode.org/
* https://secure.php.net/ instead of http://www.php.net/ or
  http://php.net/
* https://hhvm.com/ instead of http://hhvm.com/
* https://www.iis.net/ instead of http://www.iis.net/

Change-Id: I84d818a7e0ced5ffb9485ec89a75efb28a77c1e0
2018-05-22 12:14:14 +02:00
Brion Vibber
1b04c8a106 Support uploads with UTF-8 names on Windows
On PHP 7.1 and later, filesystem functions on Windows
use the Unicode system functions, which makes our file
handling work for non-ASCII file names.

Previously this was blacklisted for Windows on all PHP
versions. Versions before 7.1 will still reject Unicode
filenames with non-ASCII chars.

Bug: T3780
Change-Id: I94377faa5185f133be2dfb7b9b6aeacbd582834f
2017-10-03 23:13:33 +00:00
Aaron Schulz
82e2c924e4 Remove "@author Aaron Schulz" annotations
Bug: T139301
Change-Id: Ib5248e8e27d60611c7373bce4b29dd5e85aa3489
2017-06-27 15:24:14 -07:00
Kunal Mehta
a57b64436c Use wikimedia/timestamp
Bug: T100924
Depends-On: I0a067367cda6885fa45631ed7c18799d653dc9bf
Change-Id: I69ba64e364df8af089c1c918cdf32f99454e693a
2017-02-28 21:15:38 -08:00
Aaron Schulz
58f1016063 Fix IDEA warning in FSFileBackend
Change-Id: Ia46bffabde91fb22df11cf953c0199995a41cb91
2016-09-24 03:34:14 -07:00
Aaron Schulz
1bf0390fbd Move FSFilebackend and MemoryFileBackend to /libs
Change-Id: Id38a2ef9e0e22537d0267b536f8a4dfd60c5b41d
2016-09-24 00:10:27 +00:00
Renamed from includes/filebackend/FSFileBackend.php (Browse further)