Commit graph

335 commits

Author SHA1 Message Date
Thiemo Kreuz
e23b070b45 Make use of ?? and ?: operators where it makes sense
Change-Id: I1d9d62d80b17d1a05222c6e82f631cb801c311a8
2022-08-04 21:43:12 +02:00
Matěj Suchánek
e47c441078 Fix many typos in comments
Found using IntelliJ's "Typo" code inspection.

Change-Id: I746220ebe6e1e39f6cb503390ec9053e6518cf16
2022-05-10 12:46:11 +00:00
Aryeh Gregor
7b4b0135b9 Use str_starts_with/str_ends_with
All the other ways of doing it were ridiculous and much harder to read,
and usually required repeating the needle expression (to get its
length). I found these occurrences by grepping for various expressions,
but I undoubtedly missed some.

I didn't try replacing the many instances of strpos(...) === 0 with
str_starts_with(...), because I think they're readable enough as-is
(although less efficient). Likewise I didn't try porting strpos(...) !==
false to str_contains(...). For case-insensitive comparisons, Tim
Starling requested that we stick with substr_compare() because it's more
efficient than calling strtolower().

On PHP < 8 these functions will be included with a polyfill via
vendor/autoload.php. This is included at the beginning of
includes/AutoLoader.php, so if our autoloader has been included the
polyfill will be available. This means it should be safe to call these
functions from any code that would not be usable without our autoloader.

Three uses that Tim Starling identified as being performance-sensitive
have been split out to a separate commit for porting after the switch to
PHP 8.

Change-Id: I113a8d052b6845852c15969a2f0e6fbbe3e9f8d9
2022-05-02 10:59:58 +03:00
Aryeh Gregor
747bc81ac0 Use MainConfigNames instead of string literals
Part 1, proof of concept. Hundreds of files left to go. These changes
brought to you in large part by vim macros.

Bug: T305805
Change-Id: I44789091e9f6394c800a11b29f22528c8dcacf71
2022-04-11 17:53:27 +03:00
James D. Forrester
24e67e03b1 phan: Upgrade mediawiki-phan-config to 0.11.1 and set minimum_target_php_version
MediaWiki still supports PHP 7.2+, but we want to mainly test in newer versions
of PHP. Setting minimum_target_php_version to 7.2 this lets us run phan without
phan trying to get us to make PHP 7.2-incompatible changes to 'appease' PHP 8.0
or whatever later changes.

Some switches of generic 'resource' type-hinting to 'resource|object' to inform
phan to ignore this (triggering PHPCS at the time, ah well), rather than trying
to hint the specific novel PHP encapsulation classes to that have replaced them
from PHP 8.0 onwards but don't yet exist, and fixes from where we were checking
the results of implode and explode.

Bug: T293924
Change-Id: I629e3fb3adfad73beb3d424a07e643c2e079d9bb
2022-03-29 16:54:36 +00:00
Umherirrender
6dd8a2bb32 phan: Disable scalar_implicit_cast setting
Make phan stricter about scalar types by setting scalar_implicit_cast to
false (the default in mediawiki-phan-config)

Bug: T242536
Bug: T301991
Change-Id: Ia2fe30b17804186571722e728578121c8b75d455
2022-03-18 18:52:24 +00:00
Umherirrender
d30b3d8926 Fix various documentation related to scalar types
Found by phan strict checks

Change-Id: If41d16b473baddd92cc4261cdc2bfbe65fedcb19
2022-03-09 20:49:51 +00:00
Umherirrender
0d8c74d62b Fix documentation about query parameter as string[]
Url query parameter sometimes contains integer,
which are not allowed on string[], just use array instead.

Found by phan strict checks

Change-Id: I7eabe69ee7a78ffee05413a022caec940672ae9f
2022-03-03 22:04:56 +01:00
Reedy
86934b2fa8 Replace some more usages of Wikimedia\(suppress|restore)Warnings()
Change-Id: I2eb133a9e32116cd155f59086245bc4d15ecbfcc
2022-02-24 20:27:46 +00:00
Timo Tijhof
77b7cbc462 filerepo: Simplify and document 'favicon' FileRepo option
This was originally added in changes linked to T77093 without
coordination with maintainers and took various shortcuts and lacked
proper integration.

* Rather than reading a global variable from LocalRepo::getInfo,
  inject this option from Setup.php, the same as for other local
  settings.

* Apply the wfExpandUrl() call in the base class getInfo() method.

  This is done so that $wgForeignFileRepos and $wgLocalFileRepo
  settings via LocalSettings.php or wmf-config get the same treatment
  and benefit (support for paths) as $wgFavicon, which one would
  generally expect.

  Other reasons to do this at run-time are 1) We can't safely call
  wfExpandUrl() during Setup.php as it is too early, and 2) We generally
  avoid doing computational work during Setup.php given it's not
  needed for most web requests to most entry points (T189966, etc.).

* Document the option in DefaultSettings.php.

* Fix bad doc in FileRepo.php, to reflect that it is optional
  and may be null.

* Remove now-redundant hack in ForeignDBRepo::getInfo,
  which had to jump over its parent class previously to avoid
  inheriting the other hack in LocalRepo::getInfo, which is now
  gone as well.

Bug: T77093
Change-Id: I9102b5a246ff81a3435748a3fd1c759a4b884a51
2022-01-26 19:27:35 +00:00
TChin
47adb6d65a Refactor global variables to use MediaWikiServices instead
Automatically refactors wg prefixed globals to use MediaWikiServices config using Rector. Doesn't include files that set globals or files that fail CI.

Rector Gist: https://gist.github.com/tchin25/7cc54f6d23aedef010b22e4dfbead228

* This patch uses a modified source code rector library for our specific use case and the rector will have different effects without it.

A writeup for future reference is here: https://meta.wikimedia.org/wiki/User:TChin_(WMF)/Using_Rector_On_MediaWiki

Change-Id: I1a691f01cd82e60bf41207d32501edb4b9835e37
2022-01-10 13:55:53 -05:00
jenkins-bot
3690fb0f5d Merge "Use DeletePage in FileDeleteForm and fix output of ApiDelete" 2021-11-23 09:55:55 +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
James D. Forrester
20fd877da4 Drop experimental FileJournal system without deprecation
The feature was introduced in 2012 with d19f54602f (just before
the gerrit migration).

Change-Id: Ia3f59ad0ddeb1f610947b14e22b0694ff4c6ed84
2021-11-01 14:08:09 +11:00
Umherirrender
44fd53fee3 Using @return never documentation on always-throw-function
This helps phan to detect unreachable code and also impossible types
after the functions.
It helps phan to avoid false positives for array keys
when the keys are checked before

Bug: T240141
Change-Id: I895f70e82b3053a46cd44135b15437e6f82a07b2
2021-09-07 17:29:03 +02:00
Umherirrender
07b499fbcf build: Update mediawiki/mediawiki-phan-config to 0.11.0
Addition and remove of suppression needs to be done with the version
update.

Change-Id: I3288b3cefa744b507eadebb67b8ab08c86517c1c
2021-09-07 17:19:05 +02:00
Umherirrender
41334d56f6 filerepo: Improve return types in documentation
Also avoid a local variable

Change-Id: I31e8a95124addcfa78b7290201c14b0735b48730
2021-09-04 01:13:35 +02:00
TChin
fa5d3dba51 Support fluent interface for StatusValue
Also refactored some calls to use it.

Bug: T287485
Change-Id: If9e96ce87dc3f3641e9b3ebe093f92d8fa49b9ee
2021-08-02 15:14:11 -04:00
Petr Pchelko
fb6529e653 FileRepo::findFile - support Authority
Change-Id: Ib42b7f7d5aa88447b4fb363f52062b08a1af30c3
2021-05-26 19:01:12 -07:00
Petr Pchelko
99ca273aa7 Convert UploadStash to UserIdentity
Change-Id: I7e0a0824bc9924f40e68119aa3d8cf0687446c79
2021-05-10 11:33:02 -07:00
Umherirrender
8971719867 UploadBase::getSha1Base36FromPath can return false
Bug: T187491
Change-Id: Ie91d87f3a0aeab0344f8af6d1e0906dacf8a8e38
2021-04-27 22:48:53 +02:00
daniel
4eebc3491a FileRepo: replace Title in method signatures
NOTE: FileRepo is extended (via LocalRepo) by a couple of extensions,
even though it is not stable to extend. Hwever, none of these extensions
overrides any of the methods changed here.
https://codesearch.wmcloud.org/extensions/?q=extends%20%5Cw%2BRepo%5Cb&i=nope&files=&excludeFiles=&repos=

Bug: T278459
Change-Id: I0c236bfa354b01b03f864dd343371e4ae323b56f
2021-04-16 11:01:48 +00:00
Tim Starling
d08c5ba3b1 Better config for disabling all local image scaling
SpecialUploadStash would check $wgUploadStashScalerBaseUrl to see if
remote scaling is enabled, but would then throw the value away and use
thumbProxyUrl instead. So:

* Refactor SpecialUploadStash so that thumbProxyUrl is checked first.
* Soft-deprecate $wgUploadStashScalerBaseUrl.
* Don't use thumbProxySecret in the $wgUploadStashScalerBaseUrl case
* Document thumbProxyUrl and thumbProxySecret in DefaultSettings.php
* Add disableLocalTransform, which enforces this configuration and
  ensures nothing else tries to do local scaling.

Bug: T260504
Change-Id: I111c01ae7e07ac7a943a32192c867ce9754b690a
2021-02-22 16:19:58 +11:00
jenkins-bot
1976283835 Merge "Update a lot of unspecific "array" types in PHPDocs" 2020-11-13 21:48:24 +00:00
jenkins-bot
6415fd72a1 Merge "Replace deprecated Title::getCdnUrls" 2020-11-13 08:22:53 +00:00
Thiemo Kreuz
20b2c5000d Make use of array deconstruction directly in foreach, if possible
Deconstructing non-sparse, numerically indexed arrays directly in
foreach (a.k.a. using the list() syntax in foreach) is possible since
PHP 5.5.

The possibility to use string array keys as well as non-sequential
numeric keys in array deconstruction was added in PHP 7.1.

Change-Id: I56a48552a45f61cedc291b306cad8548fc70d485
2020-11-12 18:38:06 +00:00
Umherirrender
1b80321f39 Replace deprecated Title::getCdnUrls
Change-Id: Ie3cd9ebd6ef442af19a054a1bb81e5c3574fb2bb
2020-11-03 11:58:05 +01:00
Thiemo Kreuz
b0130ca649 Update a lot of unspecific "array" types in PHPDocs
This includes fixing some mistakes, as well as removing
redundant text that doesn't add new information, either because
it literally repeats what the code already says, or is actually
duplicated.

Change-Id: I3a8dd8ce57192deda8916cc444c87d7ab1a36515
2020-10-28 11:01:33 +01:00
Aaron Schulz
70c4255978 filerepo: clean up shared cache keys to avoid key metrics clutter
This avoids statsd metrics with names that begin with DB domains

Bug: T261534
Change-Id: I69fa4482c639bd49bdc2dec48a8dcdd74d455432
2020-10-21 13:29:15 -07:00
jenkins-bot
d4d9f5bbd0 Merge "Remove fallback to $wgUser in FileRepo::findFileFromKey" 2020-09-25 18:40:23 +00:00
DannyS712
90a4be5145 Remove fallback to $wgUser in FileRepo::findFile
Add a fallback to RequestContext::getMain()->getUser()
in FileRepo::findFiles, per task

Bug: T263033
Change-Id: I57b49a8e33af4f69ce2b9e464dc39b4099cfe4fd
Depends-On: Iedde4a39dcc3192616e36a45690a0619efeb7309
2020-09-20 22:14:46 +00:00
DannyS712
d1d6e0a663 Remove fallback to $wgUser in FileRepo::findFileFromKey
Bug: T263033
Change-Id: I436b188dc5afbe32d7d9fe1be9739752c95c1230
2020-09-20 21:27:37 +00:00
C. Scott Ananian
5e703cdf66 Hard deprecate File::userCan() with $user=null
The ArchivedFile::userCan and OldLocalFile::userCan() methods, along
with a number of other methods where the user parameter was optional,
were deprecated in 1.35, but this case was overlooked. This patch is
intended for backport to 1.35, so that the $user parameter can be
removed in 1.36 in accordance with the deprecation policy.

This path is known to be used by LocalRepo::findFile(),
FileRepo::findFile(), and FileRepo::findFileFromKey(), so hacky
workarounds have been added in this patch to avoid triggering
deprecation warnings in 1.35. T263033 has been filed to fix these
'correctly' in 1.36.

Bug: T263014
Change-Id: I17cab8ce043a5965aeab089392068b91c686025e
2020-09-16 12:27:51 -04:00
Ed Sanders
7683f7d839 Use strict (in)equality with namespaces constants when LHS is definitely an integer
Change-Id: I8fede00dfe1270d93c5d78d3c36e788cddfc8a99
2020-07-31 18:03:28 +01:00
daniel
db4ac19f7e Replace @protected tag
This patch replaces all usages of @protected in core.
The @protected tag was removed in cases where it was redundant or
contradictory. It has been replaced by @internal where usage outside of
core is not desired, and with @note for cases where use by extensions
is desired, but should be limited.

Bug: T247862
Change-Id: I5da208e5cb4504dde4113afb3a44922fd01325a3
2020-06-26 14:31:16 +02:00
Tim Starling
47a1619027 Remove terminating line breaks from debug messages
A terminating line break has not been required in wfDebug() since 2014,
however no migration was done. Some of these line breaks found their way
into LoggerInterface::debug() calls, where they mess up the formatting
of the debug log.

So, remove terminating line breaks from wfDebug() and
LoggerInterface::debug() calls.

Also:
* Fix the stripping of leading line breaks from the log header emitted
  by Setup.php. This feature, accidentally broken in 2014, allows
  requests to be distinguished in the log file.
* Avoid using the global variable $self.
* Move the logging of the client IP back to Setup.php. It was moved to
  WebRequest in the hopes that it would not always be needed, however
  $wgRequest->getIP() is now called unconditionally a few lines up in
  Setup.php. This means that it is put in its proper place after the
  "start request" message.
* Wrap the log header code in a closure so that variables like $name do
  not leak into global scope.
* In Linker.php, remove a few instances of an unnecessary second
  parameter to wfDebug().

Change-Id: I96651d3044a95b9d210b51cb8368edc76bebbb9e
2020-06-03 12:01:16 +10:00
Reedy
f34c647098 Make FileRepo::newFatal() take variadic params
Change-Id: I84abb7e6f7126af647b69b038848bb4d68d846b0
2020-05-28 22:39:11 +01:00
Reedy
693df22570 Mark two FileRepo functions public
Functions references as callbacks are passed outside the class

Bug: T253922
Change-Id: I301283aeb814b558d338e600390b8af5679d7f70
Follows-Up: I44cd7ba39a898a27f0f66cf34238ab95370d2279
2020-05-28 22:03:02 +01:00
Reedy
af063dd794 Fix more Squiz.Scope.MethodScope.Missing
Change-Id: I44cd7ba39a898a27f0f66cf34238ab95370d2279
2020-05-18 21:02:14 +00:00
Reedy
b1e515e36e Fix even more PSR12.Properties.ConstantVisibility.NotFound
Change-Id: I4a30a44bc33fc98479799438d65342f6529e14f9
2020-05-16 00:51:46 +01:00
Timo Tijhof
dfbe91e03b filerepo: Improve $wgLocalFileRepo docs
* Move 'hashLevels' docs from $wgHashedUploadDirectory to $wgLocalFileRepo.

* Add docs for the 'deletedHashLevels' option.

* Cross-reference between LocalRepo constructor and $wgLocalFileRepo
  so that its option docs can be more easily found.

* Remove the TODO for deprecating 'hashLevels' per T199590.

Change-Id: I19c28fd0c2fb937608963fe0643607b07af69c70
2020-04-18 16:04:49 +01:00
James D. Forrester
0958a0bce4 Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNull
Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
2020-01-10 14:17:13 -08:00
Umherirrender
b6e4da2b24 Fix doc of File::getSize()
Change-Id: I374256b0b5fff8a5b4e4135a3c51d3b679eea1d2
2019-12-30 15:24:25 +01:00
Umherirrender
167f991e31 Handle null from FileBackend::getFileList
Avoid warning with null passed to foreach

Change-Id: Id61ab8ba1952cdabd7c3f9c78a06a52553aadabe
2019-12-04 20:55:42 +01:00
jenkins-bot
605bf24772 Merge "docs: Convert class-level documentation files to Markdown" 2019-11-01 01:43:29 +00:00
apaskulin
80221c0aff docs: Convert class-level documentation files to Markdown
The FileRepo, FileBackend, and JobQueue classes include documentation
files that don’t appear in the generated Doxygen docs. This PR:

* Converts these files to Markdown
* Links to each file from the respective class description
* Adds an ingroup tag so the files appear in the sidebar at the
  module level
* Updates the exclude pattern in the Doxyfile to surface these pages

Bug: T87796
Change-Id: I94f0636ab489d741ab505f15da43a5d63c1ca61a
2019-10-31 11:03:13 -07:00
jenkins-bot
979465a0e1 Merge "Convert FileBackendGroup to service" 2019-10-29 09:46:26 +00:00
Aryeh Gregor
0d3d6be18d Convert FileBackendGroup to service
Bug: T234228
Change-Id: I25575f565eba122cdf971a5945572811d17fa3e1
2019-10-25 10:46:20 +03:00
Aryeh Gregor
b4a7620b9e Hard-deprecate Title::getUserCaseDBKey
The only use-case for this was if the local wiki's File namespace didn't
allow initial-lowercase names but a remote repo did. This case is
unlikely to be useful and was broken anyway, so it's now prohibited, and
getUserCaseDBKey is no longer needed. It's now an alias for getDBkey
until we remove it.

This includes a breaking change to
MediaWikiTitleCodec::splitTitleString, but that was always intended as
an internal method and I have now marked it officially as such. There is
one caller in code search outside core (JsonConfig), but it looks like
it will be unaffected.

Bug: T202094
Depends-On: I4b8ceb8a7f4624d6a3763aca6df41bf1a0d7293f
Depends-On: I724be15e93421f874fb202f0ec2ca6940e56a20a
Change-Id: I4fd64d4b0036b6dabdcfeee18766df18bf538542
2019-10-24 19:26:37 +03:00