Commit graph

6665 commits

Author SHA1 Message Date
Timo Tijhof
01f3efe4ff Hook: Mark abortable=false hooks as void
* Remove the mention of 'return true' being legal.
  This is only allowed for compat with code from before MW 1.21,
  when I added hook aborting as well as tolerance for null to
  be the same as true.

  Since then, there is no reason to return null or return true.
  For early returns, an explicitly void 'return;' should be used
  instead. Returning anything else like null/true serves no purpose
  other than to confuse the reader.

* Mark the interfaces as natively 'void' with return type hints.

  This means in core code that runs the hook, static analysis
  like Phan and in IDEs, it will be known that these onFoo()s
  never return a value, thus allowing them to detect if its
  return value is assigned or used in a conditional for any
  reason, which can be an easy mistake.

  It also means that in the future when extensions start using
  these interfaces in 'implements' statement, they will be
  required to mark their hooks as void.

  That migration is opt-in and still up ahead. This is not
  a breaking change even for all existing extensions where
  a return true/null may exist in an abortable hook since this
  only applies to code directly typed against the interface.
  The internal run() method doesn't care.

Change-Id: Ib79289bd486ac97cec492e72f9a8dee70cf2f6c2
2020-06-22 19:07:35 +00:00
Translation updater bot
6c579760b7 Localisation updates from https://translatewiki.net.
Change-Id: I88a918275744305a67113417be036edb31d1699e
2020-06-22 08:41:20 +02:00
jenkins-bot
daff5b8e5a Merge "API: Use MediaWikiServices::getAuthManager in various Api classes" 2020-06-20 23:23:07 +00:00
Umherirrender
3d45f17398 API: Use MediaWikiServices::getAuthManager in various Api classes
Change-Id: I0af2e5fe91097077eeaf83027494065a0c1a6c04
2020-06-20 23:04:17 +00:00
Umherirrender
2280d96cdc Remove null check on type hinted argument
Change-Id: I2d98662cc325a69b3a139df65d390d801684b4fd
2020-06-19 19:18:28 +02:00
jenkins-bot
5b75d2e142 Merge "Reduce direct uses of $wgUser in ApiQueryInfo's token methods" 2020-06-15 21:42:58 +00:00
Translation updater bot
51710d3668 Localisation updates from https://translatewiki.net.
Change-Id: Id63e297246af2fb662823be388b23aad70fd8a27
2020-06-15 08:37:55 +02:00
Reedy
520be2ba0a Don't call needsToken() statically
Change-Id: I2c739b1d2b06cbdbaf8519878999e90a527655f5
2020-06-14 18:11:36 +00:00
Translation updater bot
b57815f34a Localisation updates from https://translatewiki.net.
Change-Id: I7350c7ddcbb45788041f9da70db2cb396d66f630
2020-06-12 08:36:40 +02:00
DannyS712
5875a979b4 ApiRollback: Reduce use of Revision objects
WikiPage::doRollback modifies $details to include Revision objects,
and while the method has been marked as internal and will have breaking
changes made in 1.36 to remove the use of Revision objects entirely,
for now they should not be used, but rather their RevisionRecord objects
retrieved instead.

Bug: T251853
Change-Id: Ie907af06774a3980d506c9f089b0122f36cda7bf
2020-06-10 00:24:21 +00:00
DannyS712
269db7e699 Reduce direct uses of $wgUser in ApiQueryInfo's token methods
Yes, the methods are all deprecated, as is using that API path, but
until they can be removed we can at least reduce the use of $wgUser

Bug: T243708
Change-Id: I34df7dc3b1c3b1258d3bd3dca4bdb261124004cd
2020-06-08 02:12:51 +00:00
Sam Wilson
5e0fd6d664 Remove PreferencesFactory::setUser()
This method was recently added and was to result in the deprecation
of a few places where User objects were being passed to the factory.
This has now been reconsidered and this patch reverts to the
previous behaviour. It is largely a revert of Ie1bed9e9537cabc836992ccfa7fb127885ea3e11

Bug: T238466
Depends-On: Idc9f33fd5ab55bde88cc306ca63adead286380a8
Change-Id: I3653559704ccfd9bca0946f5a865be93bdf5ceb6
2020-06-08 00:27:04 +00:00
DannyS712
69e63b4c07 Reduce further direct references to $wgUser
Should be a no-op

Bug: T243708
Change-Id: Id2df2009eada1e6d2b4ce0b03485d9bc4e8f18d7
2020-06-05 11:06:21 +00:00
Translation updater bot
209bb5450e Localisation updates from https://translatewiki.net.
Change-Id: Ie04ac13e3d90167b005ec7c8cf63251838ef7d09
2020-06-04 08:22:37 +02:00
jenkins-bot
0c0a60c87b Merge "Remove terminating line breaks from debug messages" 2020-06-03 02:24:13 +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
Translation updater bot
b869dcb57f Localisation updates from https://translatewiki.net.
Change-Id: I3e92df7871e0b4203f8307f1db24732694004797
2020-06-02 08:25:32 +02:00
DannyS712
d6a38d0f10 Add ContentModelChangeFactory, implemented by PageCommandFactory
Bug: T253080
Change-Id: I62eda1163cd5b0472af912e8dbd5843df8303b8d
2020-05-30 22:36:16 +00: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
jenkins-bot
24688cc0c5 Merge "mime: Update usage of MimeAnalyzer methods" 2020-05-28 20:32:05 +00: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
jenkins-bot
aef18790c6 Merge "ExtensionRegistry: Remove exporting and caching of wgExtensionCredits" 2020-05-28 19:12:06 +00:00
Timo Tijhof
5d8f62bdd3 ExtensionRegistry: Remove exporting and caching of wgExtensionCredits
This data is the same as the 'credits' data that is already compiled,
cached and made available via ExtensionRegistry.

Similar to various other configuration variables previously, the
$wgExtensionCredits variable is now also required to only be used
for providing input to the system (e.g. from LocalSettings.php,
or from legacy extension PHP entry points). It is no longer
supported to use this variable to reliably read out a full view
of all extension credits (specifically those registered via
extension.json).

Doing so had the downside of adding processing cost to every
web request, as well as taking one the single largest portion
of the ExtensionRegistry APCu cache key, which in PHP7+ incurs
a linear cost for every string value, string key, of every
(sub)array in this huge structure; and does to on every request
just in case something reads from $wgExtensionCredits.

The new method to access this information reliably is owned
by SpecialVersion for now (could be moved elsewhere). This
also makes the merging logic more testable and incurs it on-demand
rather than upfront.

Details:

* Move 'type' internally from NOT_ATTRIBS to CREDIT_ATTRIBS.
  These two arrays behave identically for most purposes (they are
  both used to mean "don't export this as a global attribute").

  By placing it in CREDIT_ATTRIBS it becomes complete and makes
  it easy to refer to in docs. Previously, extractCredits()
  read the 'type' key outside the loop for CREDIT_ATTRIBS.

* Remove redundant code in ApiBase.php, that is now more obviously
  redundant. Looks like a left-over or merge conflict mistake
  from when ExtensionRegistry was first introduced.

Bug: T187154
Change-Id: I6d66c58fbe57c530f9a43cae504b0d6aa4ffcd0d
2020-05-28 18:46:41 +00:00
Translation updater bot
7bdf818823 Localisation updates from https://translatewiki.net.
Change-Id: I344ecf9bbeafb770924a05476d898eb8e95a5488
2020-05-28 08:37:32 +02:00
jenkins-bot
d535ebeb51 Merge "WatchedItemStore: Enforce a maximum watchlist expiry duration" 2020-05-27 22:32:06 +00:00
Translation updater bot
bdf7e3b250 Localisation updates from https://translatewiki.net.
Change-Id: Ie873f38c1fa9856eee43114d201564730aca927b
2020-05-25 08:37:27 +02:00
MusikAnimal
0694cc02f1 WatchedItemStore: Enforce a maximum watchlist expiry duration
Introduces $wgWatchlistExpiryMaxDuration which is used instead of given
expiry if the given exceeds it. This is done in the storage layer. The
reasoning is to control the size of the watchlist_expiry table. Hence,
the max duration does not apply to indefinite expiries (since that would
mean now row in watchlist_expiry).

The frontend is responsible for disallowing expiries greater than the
max, if it choses to do so.

APIs should now pass in $wgWatchlistExpiryMaxDuration as the PARAM_MAX
setting for the 'expiry' type. They should also set PARAM_USE_MAX so
that the maximum value is used if it is exceeded.

Other APIs that watch pages will be updated in separate patches
(see T248512 and T248514).

Bug: T249672
Change-Id: I811c444c36c1da1470f2d6e185404b6121a263eb
2020-05-22 00:15:23 -04:00
jenkins-bot
9147222695 Merge "In ApiQueryBase, use a SelectQueryBuilder to store query information" 2020-05-21 19:01:39 +00:00
jenkins-bot
fedbf6ba82 Merge "Use new TalkPageNotificationManager" 2020-05-20 19:21:52 +00:00
Aaron Schulz
438c94cd7c exception: cleanup "caught_by" and use Throwable in more places
Make sure that CAUGHT_BY_HANDLER is only for errors caught by the
handler from MWExceptionHandler::installHandler().

Add CAUGHT_BY_ENTRYPOINT constant for entrypoint try/catch logic,
e.g. MediaWiki::run()/ApiMain::executeActionWithErrorHandling().

Use Throwable to catch more types of errors given that PHP 7.2
is already required.

Change-Id: Ib496e26572c98d771a772972676c02c05b872e31
2020-05-18 16:20:56 -07:00
Translation updater bot
21cdf3740c Localisation updates from https://translatewiki.net.
Change-Id: Id9fc26a72daf0f95828247b6e84ac8913f36a7ba
2020-05-18 08:28:03 +02:00
Tim Starling
28b7f0b3f2 In ApiQueryBase, use a SelectQueryBuilder to store query information
Bug: T243051
Change-Id: I5bc99ee4b0674a5bc02ff31e3f7182fd7564b848
2020-05-18 14:42:42 +10:00
Reedy
b80a9f4f6a Fix even more PSR12.Properties.ConstantVisibility.NotFound
Change-Id: I5e04824d6fa6a4c36ce489850bb0ed7b4ac588f9
2020-05-16 00:51:14 +01:00
Clara Andrew-Wani
b3a5c7c0d5 Use new TalkPageNotificationManager
Bug: T239640
Change-Id: I7c06d145854ab39faaef528e169f6b51de1c8d99
2020-05-15 12:35:45 -04:00
DannyS712
29aa36c06e Add MergeHistoryFactory interface, implemented by PageCommandFactory
Bug: T249446
Change-Id: I94676e065a8aed5cad2fe2d5cf16ca586adce97d
2020-05-13 19:08:09 +00:00
Translation updater bot
7d574626a8 Localisation updates from https://translatewiki.net.
Change-Id: I23d04fa98de700eb3fa93094e39c0e78373b7ea6
2020-05-13 08:41:19 +02:00
Translation updater bot
6166714589 Localisation updates from https://translatewiki.net.
Change-Id: I5717e550d6f6c76a1610521c94a738e46c2a43f6
2020-05-12 08:19:45 +02:00
DannyS712
880050d190 ApiClearHasMsg: Use new TalkPageNotificationManager
Bug: T239640
Change-Id: Id622783a28843b8304af4b712008cec7c2732a12
2020-05-11 19:21:57 +00:00
Translation updater bot
89157202af Localisation updates from https://translatewiki.net.
Change-Id: Iad2d93fb615495863e5f55ab506545877425b01e
2020-05-11 08:35:29 +02:00
Reedy
12a3883a7b Fix SingleSpaceBeforeSingleLineComment
Change-Id: I285af438ce484af40741489797f20455726ec110
2020-05-11 00:57:11 +00:00
jenkins-bot
fc3058a567 Merge "Allow extensions (et al) to have multiple LICENSE/COPYING files" 2020-05-06 22:06:53 +00:00
Translation updater bot
d8fd1adde6 Localisation updates from https://translatewiki.net.
Change-Id: I44fc9ffa7e65a555414b84b3821fc88ea6b85fb2
2020-05-06 08:28:13 +02:00
jenkins-bot
15399a4020 Merge "Create ExtensionInfo" 2020-05-06 02:17:00 +00:00
Sam Wilson
36defc20eb Add PreferencesFactory::setUser()
Add a new setUser() method to PreferencesFactory so that a User
object doesn't have to be passed around so much. This is how
GlobalPreferencesFactory has done it, and so after this change
that code can be removed from GlobalPreferences.

Bug: T238466
Change-Id: Ie1bed9e9537cabc836992ccfa7fb127885ea3e11
2020-05-06 09:04:08 +08:00
Reedy
7dd416484a Allow extensions (et al) to have multiple LICENSE/COPYING files
Bug: T251642
Change-Id: I25f4df5a5b03d2e9bdf7b9997db00a986d252a9b
2020-05-05 22:49:04 +00:00
Reedy
bd43b01f78 Create ExtensionInfo
Bug: T251818
Change-Id: I0ef5479caf61d44c964a77164c952badc84f6b80
2020-05-05 23:27:22 +01:00
jenkins-bot
6f620f83b9 Merge "Add HookRunner classes" 2020-05-05 15:32:33 +00:00
Translation updater bot
31f5fe7adf Localisation updates from https://translatewiki.net.
Change-Id: I699783b8b52a8153d27f54afd6c14f8b55363e94
2020-05-05 08:28:50 +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
Tim Starling
4df108429a Add HookRunner classes
These classes implement hook interfaces, providing implementations which
proxy calls to HookContainer::run().

To reduce the size of the HookRunner class, I split it into two parts:
one for the API and one for everything else. The API was the largest
identifiable component, and this matches the way we modularize i18n
files.

These two classes were originally generated by the hook interfaces
script. I've added abortable options for hooks that were
called with runWithAbort().

Bug: T240307
Change-Id: Id6789070bf830ecea271ddc74fa929e0bd39356d
2020-05-05 11:22:24 +10:00