Commit graph

352 commits

Author SHA1 Message Date
Cindy Cicalese
a384acffa7 Use WatchlistManager in several classes
Change-Id: I720629e08373736b5fc1e12563b5059311b113e1
2021-04-21 00:37:40 -04:00
Reedy
bbe130b242 Rename some variables to use more neutral language
Bug: T254646
Change-Id: I997625b8201dce2c257d20f96d00089e995c2b0d
2021-03-19 16:18:49 +00:00
Ammarpad
c3cb206ede Mark UploadBase::$mTempPath as string or null.
It can be null. The null actually caused T187491 and T272328

Change-Id: I31511a9b29fe415bcaa4e22f962cbbac60cbedbc
2021-03-17 22:33:00 +01:00
Petr Pchelko
ea185c872e Rename Authority::getPerformer() to ::getUser()
We started to call Authority argument $performer everywhere,
and $performer->getPerformer() doesn't look that good.

Change-Id: Id2cf3f27b18340314e4ed1ea9931ad9404b4df6f
2021-03-04 12:45:28 -07:00
Umherirrender
ec4590b6d1 UploadBase: fopen can return false
Bug: T266234
Change-Id: If827646146d4d63cacf682811b3ac1c17e2a85c4
2021-03-03 01:08:19 +00:00
Petr Pchelko
3b18dcbcc5 Convert UploadBase to authority.
I've check via codesearch the methods with changed
signatures are not overridden by extensions. There's
no way really to deprecate anything properly here.

Change-Id: Id79d2d2cb05c5df21b64b5443a62a3b16e684262
2021-03-01 18:30:24 -07:00
lokal-profil
c3fef50628 Mark mRemoveTempFile as a bool
This is only ever used as a bool, so do not tag it as a string.

Change-Id: I582a8f57b11ebf165ec2831c25d65d04c8d7cb3a
2021-02-18 12:50:31 +01:00
Umherirrender
8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00
Thiemo Kreuz
9489ff2f53 Document and fix UploadBase::$mFinalExtension being null
While trying to understand T273249, I followed all code
paths and found one that can result in mFinalExtension being
null: when a file is stashed, it gets a temporary name
without an extension.

This patch fixes a bunch of usages where this null might
cause type errors.

Bug: T273249
Change-Id: Ie8bd84d4637aec5a65ae8b220d9266d36873acc0
2021-02-03 19:12:07 +01:00
James D. Forrester
82b7cfbfa2 UploadBase: Don't call MimeAnalyzer if mTempPath is null
As of PHP 8, fopen() throws ValueError if the path is null.
For now, keep the same behaviour as on PHP 7, which is that
MimeAnalyzer::doGuessMimeType sees fopen() return false (as
if the path was valid but doesn't exist or is not readable)
and falls back to unknown/unknown, which UploadBase ignored.

Bug: T272328
Change-Id: I5056eba2e3fd59d7971971a32b3de36f1a018603
2021-01-19 00:52:17 +00:00
jenkins-bot
1976283835 Merge "Update a lot of unspecific "array" types in PHPDocs" 2020-11-13 21:48:24 +00:00
Umherirrender
003ce9d0e5 Replace deprecated MimeAnalyzer::getTypesForExtension
Change-Id: I8f1676cc1af9b1e46c54c27f61c6abc1f5b073bd
2020-11-02 19:08:51 +01:00
Umherirrender
c85a43561e Improve class property documentation
Reformat existing documentation to match the format

Change-Id: I190b54b5e962f17bab6502dd1b3c02f11dc926d2
2020-10-30 10:38:58 +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
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
jenkins-bot
e9ad97eead Merge "Add watchlist expiry support to applicable APIs" 2020-07-14 04:37:44 +00:00
MusikAnimal
6a898faed2 Add watchlist expiry support to applicable APIs
This introduces an ApiWatchlistTrait that refactors out common code
across APIs that allow you to watch pages. Some methods have been
migrated from ApiBase and changed completely, but codesearch suggests
they aren't being used outside the API modules in this patch.

Bug: T248512
Bug: T248514
Change-Id: Ia18627b9824dca81f44f0571e8420d89b7626cf6
2020-07-13 18:18:15 -04:00
jenkins-bot
39705eb311 Merge "Replace "@stable for subclassing" with "@stable to extend"" 2020-07-13 09:31:38 +00:00
jenkins-bot
0270990f0b Merge "Replace "@stable for calling" by "@stable to call"" 2020-07-13 09:27:04 +00:00
daniel
3c50afa46b Replace "@stable for subclassing" with "@stable to extend"
For compliance with the new version of the table interface policy
(T255803).

This patch was created by an automated search & replace operation
on the includes/ directory.

Bug: T257789
Change-Id: Ie32c1b11b3d16ddfc0c83a757327d449ff80b2e4
2020-07-13 11:00:30 +02:00
daniel
f7116bb3a2 Replace "@stable for overriding" with "@stable to override"
For compliance with the new version of the table interface policy
(T255803).

This patch was created by an automated search & replace operation
on the includes/ directory.

Bug: T257789
Change-Id: I5ffbb91882ecce2019ab644839eab5e8fb8a1c5f
2020-07-13 10:57:12 +02:00
daniel
272db6afde Replace "@stable for calling" by "@stable to call"
For compliance with the new version of the table interface policy
(T255803).

This patch was created by an automated search & replace operation
on the includes/ directory.

Bug: T257789
Change-Id: If560596f5e1e0a3da91afc36e656e7c27f040968
2020-07-13 08:55:28 +00:00
daniel
7572a152fc Annotate extensible classes.
This marks some base classes as stable for subclassing.

Bug: T247862
Change-Id: I7b77075849aa40960f2486b463e498a3ea8058e9
2020-07-09 11:07:38 +02:00
jenkins-bot
2101ed6c31 Merge "upload: Modernize callback code to make use of PHP7 syntax" 2020-06-16 19:37:15 +00:00
jenkins-bot
4bdf5c5c1a Merge "Format file sizes in upload warning" 2020-06-09 12:09:06 +00: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
Tim Starling
68c433bd23 Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.

General principles:
* Use DI if it is already used. We're not changing the way state is
  managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
  is a service, it's a more generic interface, it is the only
  thing that provides isRegistered() which is needed in some cases,
  and a HookRunner can be efficiently constructed from it
  (confirmed by benchmark). Because HookContainer is needed
  for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
  SpecialPage and ApiBase have getHookContainer() and getHookRunner()
  methods in the base class, and classes that extend that base class
  are not expected to know or care where the base class gets its
  HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
  getHookRunner() methods, getting them from the global service
  container. The point of this is to ease migration to DI by ensuring
  that call sites ask their local friendly base class rather than
  getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
  methods did not seem warranted, there is a private HookRunner property
  which is accessed directly. Very rarely (two cases), there is a
  protected property, for consistency with code that conventionally
  assumes protected=private, but in cases where the class might actually
  be overridden, a protected accessor is preferred over a protected
  property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
  global code. In a few cases it was used for objects with broken
  construction schemes, out of horror or laziness.

Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore

Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router

setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine

Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-05-30 14:23:28 +00:00
Thiemo Kreuz
e111220a39 upload: Modernize callback code to make use of PHP7 syntax
* Update the two "processing_instruction_handler" and
  "external_dtd_handler" callbacks to use a syntax for the callback
  that doesn't stuff the class name in a string, but actually
  references the class.
* We don't need call_user_func() in modern PHP7 any more.
* Add and update a few type hints in UploadBase to make the code
  easier explorable.

Change-Id: I0ab3cfbe4f0bf15b1da4ab10fd9ffc1986d968d0
2020-05-29 09:37:03 +00:00
Thiemo Kreuz
73b53b4a6d upload: Fix incomplete …|null documentation in UploadBase
Change-Id: I9baa4c4093f23bdec00e54279b18acc54f357a04
2020-05-29 09:01:36 +02:00
Ori Livneh
19931e069f mime: Update usage of MimeAnalyzer methods
Follow-up to I93bd71ec1.

Bug: T252228
Change-Id: I45c9fc592c9e41e0868e7d965206d4c04f4f92e1
2020-05-28 20:13:47 +00:00
Gergő Tisza
ef0451ee4b
Format file sizes in upload warning
Change-Id: Ied97d52eee2a4faa7a41304bbe3ae0bf4e711f7b
2020-05-08 00:05:26 +02:00
Timo Tijhof
a339338ec3 upload: Move MinUploadChunkSize logic from Setup.php to ApiUpload
This was previously making calls to various methods during the
Setup.php, which apart from being deferrable logic that isn't
needed on most requests, is also risky/complicated because MW
isn't initialised yet at this point.

Bug: T189966
Change-Id: Iaee3f2af8d18bc5095e9297cbe1b6efc627f3977
2020-05-05 01:58:15 +00:00
DannyS712
05a04ef54a Pass a user to ArchivedFile::userCan in UploadBase
Bug: T251357
Change-Id: Iba9a47c4c4e7d34fee7cd31c605d2461612fe522
2020-04-29 01:46:02 +00:00
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