Commit graph

66 commits

Author SHA1 Message Date
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
Thalia
7276b4effd DatabaseBlock: Remove deprecated isValid method
Change-Id: I5f54426207f31f6acaceb8f21d43ddb2227d58cc
2020-04-15 13:42:41 +01:00
Aaron Schulz
264e5a4b7b block: avoid IN() DB query clause for ipb_address with redundant entries
When there is only one entry but it was found twice, the query became
'ipb_address IN (a, a)' instead of 'ipb_address=a'.

Change-Id: If6c49ad1502c1ba277fb83b64757fd16f0886093
2020-03-26 20:07:42 +00:00
jenkins-bot
30828e2860 Merge "Use content language for autoblocker message" 2020-01-17 19:23:59 +00:00
jenkins-bot
cf92c2dc44 Merge "Use namespaced IPUtils class" 2020-01-01 23:56:22 +00:00
Kunal Mehta
99007e96c7 Use namespaced IPUtils class
Change-Id: I047e099a93203a59093946d336a143d899d0271f
2020-01-01 02:36:49 -08:00
Daimona Eaytoy
dbf0990447 Avoid PHP scalar type juggling in includes/ (part 2)
Continuation of e5444ea55a.

Change-Id: I9f95e7de4e219dee3abcdd210bb708d949f378d0
2019-12-30 20:57:18 +00:00
Umherirrender
68315a86e9 Allow null on DatabaseBlock::newFromTarget
Similar to the called DatabaseBlock::newListFromTarget

Change-Id: I5f7c9c30ce5c7c6dbe40cbacb704ac9964999d58
2019-12-28 23:28:01 +01:00
Thalia
52e648f8a3 block: Log some details to debug DatabaseBlock::setBlocker
Bug: T192964
Change-Id: I309eb85e364366eeb2f2a383f1008b4b42d83481
2019-12-20 14:45:04 +00:00
Thalia
7299ffbb7b Throw deprecation warnings for block cookie methods
DatabaseBlock methods for handling block cookies are deprecated, so
stop using these methods in tests and throw warnings.

Change-Id: I2b5cfd579aa14bbfc7a292587a288ee5032eb5ab
2019-11-18 19:22:37 +00:00
Lucas Werkmeister
eb6dfaf15b Use content language for autoblocker message
The block reason will be stored in the database and displayed to users
in all kinds of languages, so it doesn’t make sense to localize it in
whatever the blocking user’s language happens to be.

Bug: T238570
Change-Id: I5f30cf6499f0d380eb0d5336c93190affc93d6f9
2019-11-18 18:16:56 +01:00
jenkins-bot
0283aca3e8 Merge "Remove blocker dependency for System and Composite blocks" 2019-10-31 14:12:48 +00:00
Dayllan Maza
e774df240a Remove blocker dependency for System and Composite blocks
The motivations behind this change is T227892 and that a blocker for a System or
Composite block provides no useful information for the end user.

Here is what's changing:
* Move the $blocker property to DatabaseBlock, since this is the only type of
  block that can be created by a user.
* Move handling of the 'by' and 'byName' constructor option from AbstractBlock to
  DatabaseBlock.
* getBy(), getByName(),  are now abstracts methods and each block type have to provide
  their own implementation
* getBlocker(), setBlocker() are being deprecated in AbstractBlock and moved as internal
   methods into DatabaseBlock

Bug: T227892
Depends-On: Ie2aa00cfec5e166460bcaeddba3c601fe0627c13
Change-Id: I1b17c652b12d98de3d996d309d4d3f22074be411
2019-10-31 07:45:07 -04:00
Thalia
b621de3978 Save autoblock reasons with unexpanded templates
Autoblock reasons are built as a Message which takes the original
block's reason as a parameter. If the autoblock's reason is set using
the Message, it will be stored in the database with templates
expanded due to how a CommentStoreComment is constructed. Instead,
set the autoblock reason using a string with the unexpanded template.

Follow-up to 6a8920d3, which fixes how the reason is displayed in the
UI, but still expands the templates on saving.

Bug: T236501
Change-Id: I67a9941a9c039331576cbfc2ab58d9f20a7213e2
2019-10-30 14:08:26 +00:00