Commit graph

1695 commits

Author SHA1 Message Date
Umherirrender
fd1ed0c092 Pass function name to database functions
Useful for logging

Change-Id: Ia2160fb6be5fc93f28ab51f7ae23d7f078247481
2020-06-07 14:16:52 +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
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
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
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
Aaron Schulz
58c94afe2e filerepo: make ForeignDBRepo::getSharedKey() use the DB domain ID for consistency
Follows-up 96ad0db6b4 and 88e17d3f7c.

Change-Id: I5e3163e54006b35792a82264905c637b187d25dd
2020-05-25 20:54:39 +00:00
Aaron Schulz
2d1c2154fa filerepo: bump LocalFile::VERSION following 88e17d3f7c
Bug: T253405
Change-Id: I0f7e885997d60dfa9b65ade1d66dfa0aebfda896
2020-05-23 11:19:24 -07:00
Aaron Schulz
88e17d3f7c filerepo: make LocalRepo::getSharedCacheKey() use makeGlobalKey()
Also rename image_redirect key to file_redirect while at it.
This assures that stale keys are not still in use.

Bug: T253405
Change-Id: I31a9bb6672b33fbfa1b974955d78fdfd8d58f5da
2020-05-23 17:32:55 +00:00
Aaron Schulz
96ad0db6b4 filerepo: use makeGlobalKey() in ForiegnDBViaLBRepo::getSharedCacheKey()
Keys used by multiple wikis should use this key generation method.
It also means settings like "coalesceKeys" in WANObjectCache will
correctly identify these keys as being global.

This change should be deployed on all wikis at once.

Bug: T253405
Change-Id: Ie19613ef7643af92aeb56db203e3d79139143231
2020-05-22 21:24:37 +00:00
Reedy
efa1f43a0b Final Squiz.Scope.MethodScope.Missing commit
Change-Id: I12c3705af348f91ea1f175028d2360209df18d75
2020-05-19 04:08:56 +01:00
Reedy
18773532f6 Fix more of includes/filerepo/ Squiz.Scope.MethodScope.Missing
Change-Id: I7a36fb8fa191374831ad06ed66eeb923fb0c78c2
2020-05-19 02:32:24 +00: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
DannyS712
77e2dd7169 Replace NewRevisionFromEditComplete with RevisionFromEditComplete
Bug: T250338
Change-Id: I4ef249d013d1a9bc33d1d0f380c41963635012ab
2020-05-11 15:09:25 +00:00
Tim Starling
550f5930f2 Hook interface type fixes, to fix Phan errors
Phan flagged a lot of incorrect type hints when run against the call
site migration patch.

Bug: T240307
Change-Id: I698de5536446c241b200430198b21b72763b0c69
2020-05-05 11:22:04 +10:00
DannyS712
8a88d51536 WikiPage::updateRevisionOn - replace uses, hard deprecate Revision use
See codesearch - only deployed call outside of core is in flaggedrevs,
and already passes a RevisionRecord:
https://codesearch.wmflabs.org/deployed/?q=-%3EupdateRevisionOn%5C(&i=nope&files=&repos=

Also fixed a use of Revision::newFromId in orphans.php

Bug: T249561
Bug: T249021
Change-Id: I5933a278de8645b7005c11026c87ae27c0373770
2020-05-01 04:54:37 +00:00
jenkins-bot
207420f0b2 Merge "filerepo: Improve $wgLocalFileRepo docs" 2020-04-21 21:28:17 +00:00
apaskulin
c44488f725 docs: Hook interface doc comment review
Edited doc comments for hook interfaces to improve
consistency and add type hints.

Bug: T246855
Change-Id: I38fa802463cd6f39bf5946dbbeb1b3ebaea604b2
2020-04-21 09:10:08 +10:00
Tim Starling
f5aaf75ad1 Automatically generated hook interfaces
Add hook interfaces which were generated by a script which parses
hooks.txt and identifies caller namespaces and directories.

Hook interfaces are mostly placed in a Hook/ subdirectory
relative to the caller location. When there are callers in multiple
directories, a "primary" caller was manually selected. The exceptions to
this are:

* The source root, maintenance and tests, which use includes/Hook. Test
  hooks need to be autoloadable in a non-test request so that
  implementing test interfaces in a generic handler will not fail.
* resources uses includes/resourceloader/Hook
* The following third-level subdirectories had their hooks placed in
  the parent ../Hook:
    * includes/filerepo/file
    * includes/search/searchwidgets
    * includes/specials/forms
    * includes/specials/helpers
    * includes/specials/pagers

Parameters marked as legacy references in hooks.txt are passed
by value in the interfaces.

Bug: T240307
Change-Id: I6efe2e7dd1f0c6a3d0f4d100a4c34e41f8428720
2020-04-20 13:31:05 +10: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
Aaron Schulz
0d933c6760 Deprecate wfForeignMemcKey() and remove the last call
Bug: T250407 
Change-Id: I82ca5a8a5d04166263eb19c4c99d72321bbbcdec
2020-04-17 09:57:37 +00:00
DannyS712
76cf98a3b1 Replace uses and hard deprecate Revision::newNullRevision
Bug: T249979
Change-Id: I84bb08032278248bbcc4d620a28f45504ab85d35
2020-04-15 05:43:43 +00:00
Aaron Schulz
3c7f29a6b9 Add small HtmlCacheUpdater service class to normalize purging code (2)
This is a re-submit of 35da1bbd7c, which was accidentally merged before
CR (and reverted with aa4da3c2e8).

The purge() method handles purging of both file cache and CDN, using
a PRESEND deferred update. This avoids code duplication and missing
file cache purge calls.

Also:
* Migrate HTMLCacheUpdate callers to just directly using HTMLCacheUpdateJob
* Add HtmlFileCacheUpdate class and defer such updates just like with CDN
* Simplify HTMLCacheUpdate constructor parameters
* Remove BacklinkCache::clear() calls which do nothing since the backlink
  query does not actually happen until the job runs

Bug: T230025
Change-Id: Ic1005e70e2c22d5bd1ca36dcdb618108ebe290f3
2020-04-14 03:19:07 +00:00
DannyS712
1f24330647 Hard deprecate File::delete methods
Replaced with ::deleteFile

Bug: T245710
Change-Id: I3949c88419aa196d293e70f37e40e01b93d54d1b
2020-03-21 03:13:50 +00:00
Aaron Schulz
2da2011979 filerepo: clean up File::getRepo() subclass return type comments
Change-Id: I7fbe19c96cc41e9f4534e56853fd119b74b2603c
2020-03-19 16:40:15 -07:00
DannyS712
05cf8ae216 LocalFileDeleteBatch: Migrate to new signature requiring a user
Move the user parameter to be before the other optional parameters,
and hard deprecate not passing a user. Interim signature is fully
backwards compatible, emitting deprecation noticed when a user is
not passed but otherwise accepting parameters in the old order as well
as the old order, including handling of defaults.

File::delete is a soft deprecated wrapper for the new File::deleteFile,
and File::deleteOld is a hard deprecated wrapper for the new
File::deleteOldFile. Both of the former methods accepted optional user
parameters; both of the new methods require a user, so that the call to
construct a LocalFileDeleteBatch can pass a user.

Bug: T245710
Change-Id: I9cde7831e16a719c22f093f95248b8055d9ac6fd
2020-03-17 15:38:42 +00:00
DannyS712
febd88cb5e Hard deprecate not passing a user to ArchivedFile::userCan
Bug: T246189
Change-Id: Ia9085bfb10d1151bca4f2f106bd02cc4bb2da443
2020-03-16 23:52:48 +00:00
DannyS712
40675f9b45 Hard deprecate not passing a user to OldLocalFile::userCan
Bug: T246189
Change-Id: I8a40578dc2131086d010709f4ecfd3356ac10e1a
2020-03-16 22:28:24 +00:00
jenkins-bot
208009082a Merge "Use MediaWikiServices::getRepoGroup in file related classes" 2020-03-14 18:11:21 +00:00
Umherirrender
e28b4bd8af Use MediaWikiServices::getRepoGroup in file related classes
Change-Id: Iceec961de4f0cc689f7d3b981afac923b46c98f6
2020-03-14 12:36:27 +00:00
Tim Starling
30d5810572 Reconcile differences between arguments in hooks.txt and at the call site
The interface generator script now flags any differences between the
argument list at the call site and the documented arguments. Resolve all
such differences.

* In AlternateEditPreview, $parserOutput is a reference, and a
  WMF-deployed extension replaces it.
* In DeleteUnknownPreferences, fix missing "$" in &$where
* In LocalisationCacheRecache, document the unused parameter, as is the
  convention elsewhere in the file.
* In NewRevisionFromEditComplete, make all callers pass a $tags
  variable, and document the fact that there are multiple callers.
* In PageContentInsertComplete, document legacy references
* In PageContentSave, document the fact that $flags and $status are
  references. I made them legacy references, since although replacement
  will have an effect, no extension relies on this and it is not
  documented on the Manual:Hooks page.
* In PageContentSaveComplete, document $wikiPage, $user, $flags and
  $status as legacy references. Replacement of $status was broken
  by If610c68f4912e89 (MW 1.32), but I confirmed that no extensions
  in CodeSearch are currently affected.
* In ParserGetVariableValueSwitch, document $frame as a legacy reference
* In WatchArticleComplete and UnwatchArticleComplete, SpecialEditWatchlist
  was passing $user by value where as the other callers were passing it
  by reference. Passed by reference. It was already marked legacy.

Bug: T240307

Change-Id: I33f69ebdb5242982fd7986d9877959d2d33149b9
2020-03-06 15:49:15 +11:00
Thiemo Kreuz
40cf0d2ee5 filerepo: Add and fix visibility keywords in ArchivedFile
The constructor should be a no-brainer, because it is actually used
in several places outside of this class.

The $exists property is used in the Video extension:
https://codesearch.wmflabs.org/search/?q=extends%20ArchivedFile
This extension is broken right now.

There is no obvious workaround, as far as I can see. I noticed that
almost all other properties are also protected. So why not make this
protected as well?

Change-Id: Ie80360e6362cd7fd4f3d9c9a60b6f64e8e9532f0
2020-02-28 16:35:01 +01:00
DannyS712
d3aa888904 Hard deprecate Revision::userCanBitfield
Also replace uses. Some callers had a user that could be null;
RevisionRecord::userCanBitfield requires a user, so add $wgUser
fallbacks at the callers with soft deprecations for using them,
and will hard deprecate in a subsequent task.

Bug: T245958
Change-Id: I137e21e3883b149fdd98d1b59d4e498d15b39dd9
2020-02-24 21:18:49 +00:00
Bill Pirkle
512b0b08d9 Add core REST API endpoint for media links
Add an endpoint to the core REST API to return the list of
media files embedded in a page, including certain metadata
for each media file.

Bug: T236169
Change-Id: I3188848ee7de365d209dfb7da5b885313e9f705b
2020-01-22 15:10:44 -06:00
James D. Forrester
0958a0bce4 Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNull
Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
2020-01-10 14:17:13 -08:00
James D. Forrester
4f2d1efdda Coding style: Auto-fix MediaWiki.Classes.UnsortedUseStatements.UnsortedUse
Change-Id: I94a0ae83c65e8ee419bbd1ae1e86ab21ed4d8210
2020-01-10 09:32:25 -08:00
Umherirrender
b6e4da2b24 Fix doc of File::getSize()
Change-Id: I374256b0b5fff8a5b4e4135a3c51d3b679eea1d2
2019-12-30 15:24:25 +01:00
jenkins-bot
de5ced5772 Merge "Fix return type for MediaHandler::pageCount" 2019-12-29 01:56:11 +00:00
Thiemo Kreuz
d6eb3b2165 Fix wrong File::getMetadata() return type
Required for I4bd97f058ce54d2c14ead75fdc11f60a15cabb46.

Change-Id: I3f531d38dac8088667bc371ea465f00896f0787a
2019-12-28 21:41:18 +01:00
Umherirrender
40b62aa8f7 Fix return type for MediaHandler::pageCount
Change-Id: Ia5a3ae0397bec29577354575997f2a57ebcc2216
2019-12-28 20:51:21 +01:00
jenkins-bot
f3a783d46f Merge "Handle null from FileBackend::getFileList" 2019-12-23 22:40:09 +00:00
Brad Jorsch
b26248235b Add string casts when using array_keys() with SQL query conditions
Until I70473280, integer literals were always quoted as strings, because
the databases we support all have no problem with casting
string-literals for comparisons and such.

But it turned out that gave MySQL/MariaDB's planner problems in some
queries, so we changed it to not quote actual PHP integers.

But then we run into the fact that PHP associative arrays don't preserve
the types of keys, it converts integer-like strings into actual
integers. And when those are passed to the DB unquoted for comparison
with a string-typed column, MySQL/MariaDB screws up the comparison while
PostgreSQL simply throws an error. Sigh.

This patch adds string casting to direct uses of array_keys() to supply
values for such query conditions. It doesn't change uses where the field
being compared is a numeric field.

If anyone knows of a good way to find indirect uses of array_keys() for
passing as $conds to IDatabase methods, please do so!

Change-Id: Ie72ee33437d492904e1495b3f4ebb1fcf0118f49
2019-12-16 16:05:18 -05:00
jenkins-bot
94b12c7ba8 Merge "Set visibility on php magic functions __destruct/sleep/wakeup/get/call" 2019-12-09 16:36:13 +00:00
Umherirrender
eb2373dcd1 Set visibility on php magic functions __destruct/sleep/wakeup/get/call
All the magic functions needs public visibility to be callable from php
internals like garbage collector

Change-Id: I1baf04bf8ff787da880d46e4a6daa77f5a6de73f
2019-12-05 18:52:55 +01:00
jenkins-bot
800783d9ad Merge "UnregisteredLocalFile: fix PHP 7.4 warnings" 2019-12-05 17:39:55 +00:00
jenkins-bot
2b04ef6657 Merge "Set method visibility for various constructors" 2019-12-05 10:23:34 +00:00
Max Semenik
cf7d3d690f UnregisteredLocalFile: fix PHP 7.4 warnings
In deciding whath the functions should return if dimensions
are unknown: null as currently, false as base class signatures
suggest, or 0 as sister classes do, it seems the latter is most
compatible.

Bug: T239759
Bug: T233012
Change-Id: I67b2df1c46ce08ba01a0dcc5137e3a0ca10283e6
2019-12-05 08:56:46 +03: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
Umherirrender
0688dd7c6d Set method visibility for various constructors
Change-Id: Id3c88257e866923b06e878ccdeddded7f08f2c98
2019-12-03 20:17:30 +01:00