Commit graph

79 commits

Author SHA1 Message Date
Umherirrender
6ea3d6ac2c Add explicit casts between scalar types
php internal functions like floor/round/ceil documented to return
float, most cases the result is used as int, added casts

Found by phan strict checks

Change-Id: I92daeb0f7be8a0566fd9258f66ed3aced9a7b792
2022-03-08 16:59:01 +00:00
Umherirrender
ba2c15abb2 block: Avoid use of null block id and blocker
Use a local variable to allow phan to track the not-null part

Found by phan strict checks

Change-Id: I32e023d3dbd70e987c79527a6936209d62deffcf
2022-02-26 10:35:10 +01:00
Alexander Vorwerk
283763c893 DatabaseBlock: assert the blocker to be from the correct wiki
If the wiki to which the blocker belongs does not match the wiki to
which the block belongs, things can go wrong.

Bug: T274817
Change-Id: Iab88ff2106932dffeb8b6da193e5a5e12f686cc3
2022-01-26 00:26:31 +01:00
jenkins-bot
d9e3eadcee Merge "Introduce a BlockRestrictionStoreFactory" 2022-01-25 20:36:39 +00:00
Alexander Vorwerk
dcd112360f Introduce a BlockRestrictionStoreFactory
The BlockRestrictionStoreFactory is a new service which allows fetching
of a wiki-specific BlockRestrictionStore by fetching the correct
LoadBalancer via a LBFactory and then injecting it into the
BlockRestrictionStore.

This is being done as a part of the project of supporting cross-wiki
blocking. Currently if a cross-wiki block with restrictions is being
created, the block is being stored in the foreign database, but the
restrictions are being stored in the local one.

Blocks were made wikiaware in I8ae8133f7e232cc75aae6b72fcd7feaeb313cba7.

Bug: T291983
Change-Id: Ia342030c31710f40c95acc75d3cc76f1ad79d806
2022-01-24 20:17:40 +01:00
Alexander Vorwerk
91a59f1a11 DatabaseBlock: fetch a database connection for the correct wiki
Bug: T274817
Bug: T299655
Co-authored-by: Taavi Väänänen <hi@taavi.wtf>
Change-Id: I99700e9c562635d52f2350703f46f07a39eb349f
2022-01-20 20:23:56 +00:00
Alexander Vorwerk
b6793e47de Make Block objects aware of which wiki they belong to
Bug: T274817
Depends-On: I1c46c712a3afefce56238108cb2e78382dd41956
Change-Id: I8ae8133f7e232cc75aae6b72fcd7feaeb313cba7
2022-01-17 21:49:20 +01: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
Amir Sarabadani
9bcd3fdfa5 Remove ActionAjax
Bug: T42786
Change-Id: I8bda0c281e1f4abbffbddb80ac74a6d61a034d28
2021-12-01 22:31:30 +01:00
Petr Pchelko
25bb5b296a Cleanup hard-deprecated code in blocks.
Change-Id: I1b3f4a0f072197c6b3dc6c9a80fcb2946aeb6360
2021-10-26 06:44:05 -07:00
Alexander Vorwerk
734b912d55 Only allow UserIdentity in DatabaseBlock::setBlocker()
Passing a string is deprecated since 1.36.

Change-Id: Ia1c5bde0815f860f8671e9acae73c69af0a0f96a
2021-10-04 14:03:29 +00:00
Roman Stolar
4af3d59f24 Remove DatabaseBlock 'byText' and 'by' with user ID
Bug: T283641
Change-Id: I5176b1cb388b9962baae3fb99ce8f677b614c4ae
2021-09-29 17:08:32 +03:00
Alexander Vorwerk
a622cf1229 Hard deprecate DatabaseBlock::purgeExpired()
Cleaning a bit up before doing some refactoring.

Soft-deprecated since 1.36 and unused.

Change-Id: I2c93049e6820afd446d284cf0ba756e26c2e50b3
2021-09-28 20:41:32 +00:00
Umherirrender
220fd020c4 Simplify if-then-else-return statements with explicit true/false
When both branches returns a bool, use the condition as return value

Change-Id: I59416aa021d0ada77d84fda4aaf7def0eea54009
2021-08-17 23:19:04 +02:00
libraryupgrader
5357695270 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0
  The following sniffs now pass and were enabled:
  * Generic.ControlStructures.InlineControlStructure
  * MediaWiki.PHPUnit.AssertCount.NotUsed

npm:
* svgo: 2.3.0 → 2.3.1
  * https://npmjs.com/advisories/1754 (CVE-2021-33587)

Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
2021-07-22 03:36:05 +00:00
Alexander Vorwerk
825ac0232c Convert BlockUtils::parseBlockTarget to UserIdentity
Bug: T286490
Change-Id: Ice96180690828bcf2efd60faf6ad10d64307713d
2021-07-20 22:12:26 +02:00
Matěj Suchánek
90b47f0077 Fix deprecation warnings in DatabaseBlock
The admin should see what is deprecated, not the actual value provided.

Change-Id: Ie09d2124ea40ba460feff7cb846514a89587fac7
2021-06-04 15:44:59 +00:00
Roman Stolar
4613e36b97 Hard deprecated DatabaseBlock options 'byText' and 'by' with user ID
Bug: T283641
Change-Id: Id1444253b26605f4c68b4cbeb61dc2299ed8ac34
2021-06-04 17:33:48 +03:00
jenkins-bot
28c34c539a Merge "Remove DatabaseBlock::forcedUserId feature" 2021-06-02 09:31:35 +00:00
Petr Pchelko
e5083b79ee Drop hard-deprecated and unused DatabaseBlock::chooseBlock
Change-Id: Ifc04faefc590404e30b509850b67073e1b1d64c0
2021-05-25 16:52:05 -07:00
Petr Pchelko
a3b4881f6f Remove DatabaseBlock::forcedUserId feature
This used to be needed when we couldn't pass a cross-wiki
user target correctly. Now that UserIdentity is cross-wiki-aware,
we can.

Bug: T283642
Depends-On: I6f57357d3a73e753e018986e6af6245c29468875
Depends-On: Ie48ee3fcbf3fa7a285e80caf627be0b726b757c2
Change-Id: I3c21e55022c5fb316a390027f7c28211b29c3d62
2021-05-25 15:41:34 -07:00
DannyS712
e6c6a525cb Add return typehints to Block interface and classes implementing it
Change-Id: I422895aca72cb34ceaee9e741b2b988786ebbfdc
2021-05-14 21:16:59 +00:00
James D. Forrester
f2f9345e39 Replace uses of DB_MASTER with DB_PRIMARY in documentation and local variables
This is just a start.

Bug: T254646
Change-Id: I9213aad4660e27afe7ff9e5d2e730cbf03911068
2021-05-14 12:40:34 -07:00
daniel
753b1bcaff Introduce Block interface and replace AbstractBlock.
In order to allow Authority to know about user blocks,
we need a narrow interface to represent such blocks.

This deprecates some methods on AbstractBlocks in favor
of new methods on the Block interface that avoid binding to
the User class.

Bug: T271494
Change-Id: I7bb950533970984a014de0434518fbbefb695131
2021-05-11 11:36:11 +02:00
James D. Forrester
d13b4678a6 DatabaseBlock: Hard-deprecate calls to isWhitelistedFromAutoblocks()
Bug: T277987
Change-Id: Ic14f38e0e60bd156d1ff04392e65eeceb3ba77b2
2021-05-08 11:40:56 -07:00
James D. Forrester
f121d0fbde DatabaseBlock::isExemptedFromAutoblocks: Drop fallback message load
This is no longer needed in Wikimedia production. Third
party users will have had a release to adjust to one of
the three called-out migration issues. It's time.

Bug: T277987
Change-Id: Ia4a797afc71441ed9a7a90ff4f1e72cc4495cf63
2021-05-08 11:39:28 -07:00
James D. Forrester
df5eb22f83 Replace uses of DB_MASTER with DB_PRIMARY
Just an auto-replace from codesniffer for now.

Change-Id: I5240dc9ac5929d291b0ef1c743ea2bfd3f428266
2021-04-29 09:24:31 -07:00
Tim Starling
44c76b8d9f Stop using legacy ActionMigration field "ipb_by"
Bug: T278917
Change-Id: I392b0bf23f23a2ca08664e4b49c9eeb26df348de
2021-04-28 16:29:04 +10:00
Thalia
c67f181dd4 Introduce infrastructure for partial blocks for actions
This adds a new type of block restriction for actions, which extends
AbstractRestriction. Like page and namespace restrictions, action
restrictions are stored in the ipblocks_restrictions table.

Blockable actions are defined in a BlockActionInfo service, with a
method for getting all the blockable actions, getAllBlockActions.

Action blocks are checked for in PermissionManager::checkUserBlock
using DatabaseBlock::appliesToRight. To make this work, this patch
also removes the 'edit' case from AbstractBlock::appliesToRight,
which always returned true. This was incorrect, as blocks do not
always apply to edit, so cases that called appliesToRight('edit')
were fixed before this commit. appliesToRight('edit') now returns
null (i.e. unsure), which is correct because it is not possible to
determine whether a block applies to editing a particular page
without knowing what that page is, and appliesToRight doesn't know
that page.

There are some flags on sitewide blocks that predate partial blocks,
which block particular actions: 'createaccount' and 'sendemail'.
These are still handled in AbstractBlock::appliesToRight, and are
still checked for separately in the peripheral components.

The feature flag $wgEnablePartialActionBlocks must set to true to
enable partial action blocks.

Bug: T279556
Bug: T6995
Change-Id: I17962bb7c4247a12c722e7bc6bcaf8c36efd8600
2021-04-27 21:53:13 +01:00
daniel
fed7f0b179 Remove $actor field from UsererIdentityValue
Code that needs to store an actor ID in the database to
represent a UserIdentity, or needs to construct a UserIdentity based on
an actor ID loaded from the database, should use the ActorNormalization
service.

Note: The getActorId() method is removed from the UserIdentity interface,
but all concrete classes continue to support it for now.
UsererIdentityValue::getActorId() is hard deprecated and should
be removed in 1.37. It always returns 0.
User::getActorId() is not deprecated at this point.

Bug: T274179
Depends-On: Id2b3ddf6a2a7cdf90f8936a69148d2cce6fde237
Change-Id: I9925906d11e47efaec3c1f48d5cb3f9896a982c1
2021-04-13 18:18:06 +00:00
jenkins-bot
fffb54708f Merge "Relax AbstractBlock typehints to UserIdentity where possible" 2021-03-22 23:17:55 +00:00
Petr Pchelko
42b727f159 Relax AbstractBlock typehints to UserIdentity where possible
Change-Id: Ia975f44a05567561b1cdc417735b124e568b2ece
2021-03-22 16:12:21 -06:00
Reedy
70cc0f85fa Deprecate DatabaseBlock::isWhitelistedFromAutoblocks
Use MediaWiki:Block-autoblock-exemptionlist instead of MediaWiki:Autoblock_whitelist

Bug: T277987
Change-Id: I2274c3cf2ceec43c9190c028b0f8ba821c2f0e34
2021-03-20 22:27:01 +00:00
Petr Pchelko
f984d3f83b Hard-deprecate AbstractBlock::parseTarget
Bug: T276610
Change-Id: I2f10ae5da1d9b1ca4aa20492b943e0c94d32a0b6
2021-03-19 07:22:48 -06:00
Petr Pchelko
ea213aadf5 Make DatabaseBlock::$blocker a UserIdentity
Bug: T277687
Depends-On: I062313ea579ba7e972e8394689e122603945f4cf
Change-Id: I144603516bc5f75c3ec7b2bb630ef9c0348674df
2021-03-17 12:32:59 -06: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
jenkins-bot
1976283835 Merge "Update a lot of unspecific "array" types in PHPDocs" 2020-11-13 21:48:24 +00: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
Thiemo Kreuz
1fc8d79ac6 Remove documentation that literally repeats the code
For example, documenting the method getUser() with "get the User
object" does not add any information that's not already there.
But I have to read the text first to understand that it doesn't
document anything that's not already obvious from the code.

Some of this is from a time when we had a PHPCS sniff that was
complaining when a line like `@param User $user` doesn't end
with some descriptive text. Some users started adding text like
`@param User $user The User` back then. Let's please remove
this.

Change-Id: I0ea8d051bc732466c73940de9259f87ffb86ce7a
2020-10-27 19:20:26 +00:00
Thalia
c0e81bd69b Move $isHardblock property up to AbstractBlock from DatabaseBlock
System blocks (which tend to be against IP addresses) can apply to
anon users only, or to logged-in users too. This differs depending
on the type of system block.

This is enforced in BlockManager::getAdditionalIpBlocks by checking
whether the user is anonymous before constructing a given type of
system block. Before this commit, it is not codified in the block's
properties, meaning that there is no way to communicate via the
API whether the block blocks logged-in users too.

Database blocks have a property $isHardblock; move this up to
AbstractBlock, so that system blocks and composite blocks can set
this property too.

Bug: T261639
Change-Id: I4f6ddf6cca6e01e85c56eef1ca7496dd6fcf52e6
2020-10-07 13:23:12 +01:00
DannyS712
24d13e6048 Remove hard deprecated DatabaseBlock cookie methods
Along with AbstractBlock::shouldTrackWithCookie,
the following DatabaseBlock methods were removed:
* setCookie
* clearCookie
* getCookieValue
* getIdFromCookieValue
* shouldTrackWithCookie
All appear to be unused

Change-Id: Ia42ffd7b4688d83c1647e61ed018ed70587f30d0
2020-10-06 17:30:20 +00:00
DannyS712
2c1270d744 Remove DatabaseBlock::fromMaster, deprecated and unused
See https://codesearch.wmcloud.org/search/?q=fromMaster%5C(&i=nope&files=&repos=

Change-Id: I45011991cfffc6ecf5c7d15c8b0756fe4abf8884
2020-10-06 17:18:07 +00:00
DannyS712
6ff12e6527 Remove DatabaseBlock::deleteIfExpired, deprecated and unused
See https://codesearch.wmcloud.org/search/?q=deleteIfExpired&i=nope&files=&repos=

Change-Id: I320794d1b6baa85cdf16477c8b2ccf4919e2f0f2
2020-10-05 23:17:19 +00:00
Thalia
addb098c39 Deprecate DatabaseBlock methods moved to DatabaseBlockStore
Following 23c3c70d7f, soft deprecate the static methods on
DatabaseBlock that have been moved to DatabaseBlockStore:
* ::insert
* ::delete
* ::update
* ::purgeExpired

Update calls to the deprecated methods from core.

Change-Id: I1272eb978594fd4f386bda12cbc24131ad7d882f
2020-09-13 22:17:27 +00:00
Umherirrender
114f37a0de Use UserNameUtils in DatabaseBlock
Change-Id: I097b642bfde4efd120cb59f314a433d18876ae82
2020-08-05 22:11:30 +02:00
DannyS712
23c3c70d7f Add a DatabaseBlockStore service
The new service replaces the following public DatabaseBlock methods:
* ::delete
* ::insert
* ::update
* ::purgeExpired

Bug: T221075
Change-Id: I5f95db14b1189fd62d2c2bd5dae2cab0a368f401
2020-07-29 15:55:09 +01: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
Martin Urbanec
b6d5ad7112 DatabaseBlock's status variables should return bool
This happens because DatabaseBlock::initFromRow didn't
cast all database-loaded variables to boolean.

Bug: T251048
Change-Id: I0c328b7d06fd911d67a9744253e005902a6aa136
2020-04-26 20:09:40 +02:00
Thalia
dc4ff4f5b4 DatabaseBlock: Deprecate some obsolete methods
Deprecate deleteIfExpired, chooseBlock and fromMaster, which are
unused.

deleteIfExpired, called internally, appears unused since
b3c844133a.

fromMaster, an internal getter/setter for the mFromMaster property,
is unused since newLoad was refactored in
a387a375a1.

chooseBlock is unused since the introduction of CompositeBlock in
1eaf65d0a5.

Change-Id: I9db6d989e3138b3e0cbf6315ecbf2f8793a37bd6
2020-04-15 20:35:48 +01:00