Commit graph

11 commits

Author SHA1 Message Date
Gergő Tisza
926cfa3b3d Use a constant for 'Maintenance script' username
The user 'Maintenance script' is often used to perform various
automated tasks. Providing it everywhere as a string literal is
error-prone, and errors can be somewhat disruptive (e.g. with
User::newSystemUser with steal=true it can erase the credentials
of a legitimate account). Provide a constant instead.
Also replace existing uses for consistency.

Change-Id: I685a5bfe56bbf1a47f35072f7f7c8be320ee27db
2021-05-03 23:34:26 +02:00
jenkins-bot
9e22096c6d Merge "BlockUsers maintenance script: Allow setting of block flags" 2021-02-25 14:23:51 +00:00
Ed Sanders
8cc67fa352 BlockUsers maintenance script: Allow setting of block flags
As all these flags are all true by default, create inverted
command line flags to selectively set them to false.

Change-Id: I19affd2d0c35799b537c987739a01fdbc2c35a13
2021-02-24 20:25:59 +00:00
Ed Sanders
6e2762c797 BlockUsers maintenance script: Avoid bug in hasOption
hasOption always returns true after getOption has been called
(T275619), so just use the result of getOption instead, which
will be a string or false.

Bug: T275627
Change-Id: I23b9a5258cc8ef3532eb18c5fa974c2989937c80
2021-02-24 14:17:01 +00:00
Martin Urbanec
c106f679b0 Make blockUsers.php capable of both blocking and unblocking
Bug: T248640
Change-Id: I0f8ae29e04f563060ab0edea0f0478698f47adcb
2020-10-06 17:40:25 +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
Thalia
0a847ae6dd maintenance/blockUsers.php: Check only for prior DatabaseBlocks
BlockUsers needs to know if there is a block stored in the database
against a particular user account. This is answered by
DatabaseBlock::newFromTarget.

Prior to this, the script called User::getBlock, which can return
SystemBlocks and CompositeBlocks too. These are not stored in the
database, so are irrelevant and would cause an error on attempting to
update them.

It also meant parameter types for BlockIpCompleteHook needed to be
changed to AbstractBlock in a302833fc3.
This changes them back to DatabaseBlock.

Change-Id: Iec90d4938e76d76ac1f5b1d1e9ffb736a58d5c53
2020-07-03 03:50:56 +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
Bryan Davis
37efd34d1a maintenance/BlockUsers: Add reblocking and BlockIpComplete hook
* Add a --reblock flag to allow updating existing blocks
* Call the BlockIpComplete hook after blocking

Change-Id: I2daa142e7034c43b01d3e9b8b0304584656b2dae
2020-05-21 18:31:16 -06:00
Daimona Eaytoy
41a17c3bec blockUsers script: fix logging
If the username isn't valid, $performer is just false and not the
invalid name. For the other prints, use $performerName directly instead
of relying on User::__toString.

Change-Id: I22ad6f98a14a69ea13aa794b45869dd2eb747dee
2020-03-03 12:22:19 +01:00
Reedy
c448337b61 Add a maintenance script to block a list of users
Bug: T246368
Change-Id: I93b7d92023af06adabd7767f30b5179d12223be1
2020-03-02 19:35:03 +00:00