Commit graph

33 commits

Author SHA1 Message Date
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
Thalia
6a8920d30d Don't expand template for reason on saving an autoblock
Bug: T236501
Change-Id: Ibca6443eeaabf9e60d45989de803aacebc952d5e
2019-10-25 20:08:54 +01:00
Thalia
a652bb330a Pass the target as a string to the reason Message for autoblocks
Bug: T227007
Change-Id: Id56c7f41d96e378ff43d152ff7325de49be66df9
2019-10-22 16:51:10 +01:00
Tchanders
a6533885b8 Revert "Revert "Store block reasons as CommentStoreComments in block classes""
This reverts commit 5f06efb318, which
reverted 9335363789, which makes
the deprecated property AbstractBlock::mReason private.

After 9335363789, AbstractBlock::mReason is obsolete, since the block
reason is now stored as a CommentStoreComment, AbstractBlock::reason.

Change-Id: Ica0a74be90383689ca8e4cfe6d0fb25c9a5942c5
2019-10-20 10:41:17 +01:00
Daimona Eaytoy
5f06efb318 Revert "Store block reasons as CommentStoreComments in block classes"
This reverts commit 9335363789.

Reason for revert: It's full of code accessing AbstractBlock::mReason
out there, see [1]. Also, it was never hard deprecated. While that may
be acceptable under some circumstances, it's definitely not OK to remove
code when there are consumers around. I'd have fixed it right now without
reverting if it were a single repo, but there's just too many.

[1] - https://codesearch.wmflabs.org/search/?q=-%3EmReason&i=nope&files=&repos=

Change-Id: I8669f502b50cff89e28dada0f65fe2b130ae9b37
2019-10-19 18:55:45 +00:00
Thalia
9335363789
Store block reasons as CommentStoreComments in block classes
AbstractBlock::setReason now accepts a string, Message or
CommentStoreComment. The CommentStoreComment is accessed via
AbstractBlock::getReasonComment.

AbstractBlock::getReason returns the reason as a string, with
the language and format consistent with how block reasons were
built before this commit. This method is deprecated, since it
makes assumptions about the language and format needed. The
deprecated mReason property is no longer public.

Doing this (and T227005) will remove the implicit dependency of
BlockManager::getUserBlock on language, which causes a recursion
error if the block is checked before the user has loaded. It also
provides a mechanism for getting the block reason in a language
specified by the caller. (This does not apply to DatabaseBlock
reasons entered via the Special:Block form, which were not and
are still not translatable.)

This commit also updates authentication classes to return the
translated reason.

Bug: T227007
Change-Id: Iec36876e930dff96a256aebbdc39cbfb331c244e
2019-10-18 17:47:56 -04:00
Thalia
df20197250 Introduce a formatter service for block errors
The main reasons for adding this service layer are:
* It allows error messages to be more consistent, by defining
  a set of reportable information that can describe any block
  type and is consistently formatted.
* It decouples formatting from the block classes, removing
  their dependency on language, for the most part.

The service provides one public method, getMessage, which
returns a Message object whose key and parameters are
determined by the type of block. This should be used instead
of the deprecated AbstractBlock::getPermissionsError and
AbstractBlock::getBlockErrorParams.

Calls to AbstractBlock::getPermissionsError are replaced in
this patch.

Bug: T227174
Change-Id: I8caae7e30a46ef7120a86a4e5e6f30ae00855063
2019-10-08 12:29:23 +01:00
Brad Jorsch
c29909e59f Mostly drop old pre-actor user schemas
This removes most of the pre-actor user and user_text columns, and the
$wgActorTableSchemaMigrationStage setting that used to determine
whether the columns were used.

rev_user and rev_user_text remain in the code, as on Wikimedia wikis the
revision table is too large to alter at this time. A future change will
combine that with the removal of rev_comment, rev_content_model, and
rev_content_format (and the addition of rev_comment_id and rev_actor).

ActorMigration's constructor continues to take a $stage parameter, and
continues to have the logic for handling it, for the benefit of
extensions that might need their own migration process. Code using
ActorMigration for accessing the core fields should be updated to use
the new actor fields directly. That will be done for in a followup.

Bug: T188327
Change-Id: Id35544b879af1cd708f3efd303fce8d9a1b9eb02
2019-09-09 11:38:36 -04:00
Thalia
4c4b61c126 Improve formatting of constructor documentation for block classes
Change-Id: Idced6ce907f63d2c041d1bb926b8224ece54c3de
2019-08-29 13:18:50 +01:00
Thalia
7a5508573a Ensure block hooks keep user state consistent with realistic blocks
Several block-related hooks allow the user to be put into in a state
that is inconsistent with blocks that can actually be made:
* With UserIsHidden, User::mHideName can be set to true without there
  being a block
* With UserIsBlockedFrom, a user can be blocked from editing a page
  without there being a block
* With GetBlockedStatus, public block properties can be arbitrarily
  set on a user

These problems are mostly theoretical, but mean that it is impossible to
make some basic assumptions, e.g. that a user who is blocked from a page
must have a block. The hooks are not widely used, and with a few changes
we can make them more robust so such assumptions can be made.

This patch:
* Ensures UserIsBlockedFrom is only called if there is a block. This
  would be a breaking change if any extensions were using this to block
  an unblocked user; the intended use case is clearly for extensions to
  allow user talk page access to blocked users.
* Adds a new hook, GetUserBlockComplete, which passes the block for
  modification. This should be used instead GetBlockedStatus and
  UserIsHidden, which will be deprecated in the future.
* Allows the 'hideName' option to be passed into the AbstractBlock
  constructor so that suppressing system blocks can be made.

Bug: T228948
Bug: T229035
Change-Id: I6f145335abeb16775b08e8c7c751a01f113281e3
2019-08-21 17:38:52 +01:00
Thalia
f45359a0a9 Deprecate several public properties on the block classes
Public methods for checking and setting these properties already
exist where needed. Also update the remaining direct uses of these
properties in core.

Change-Id: Icdef025c9700e625aeb2a07975e69f1b1cc2466c
2019-07-29 21:29:54 +01:00
Max Semenik
48d355de81 MediaWiki\Block namespace minor tweaks
* Visibility
* Parameter type hints and docs
* Minor doc fixes

Change-Id: I46d4b99e18cffdf8323fb01b7ed30f3eda2906d1
2019-06-27 13:42:54 -07:00
Thalia
9510597f26 Filter out duplicate autoblocks when checking for blocks
Follow-up to I7654907.

Bug: T225919
Change-Id: I67e72d6c88e3cbfd9515a016b2782d1d9b123775
2019-06-20 22:01:44 +01:00
Thalia
1eaf65d0a5 Add CompositeBlock class for enforcing multiple blocks
Create a CompositeBlock class which extends AbstractBlock and
adds the property $originalBlocks. This is for situations where
more than one block applies to a user/IP, and avoids the need
to choose just one of these blocks to enforce.

Behaviour of the resulting block is determined by combining the
strictest parameters of the original blocks.

Also add DatabaseBlock::newListFromTarget, which is similar to
DatabaseBlock::newFromTarget, but returns all relevant blocks,
rather than choosing the most specific one.

For tracking a CompositeBlock with a cookie, examine the
original blocks and only track the first trackable block that
is found.

Bug: T206163
Change-Id: I088401105ac8ceb2c6117c6d2fcdb277c754d882
2019-06-12 19:16:52 +01:00
Thalia
c5991f614f Move cookie-blocking methods to BlockManager
Move the cookie blocking logic into one place. Specifically, move
these methods to the BlockManager:
* User::trackBlockWithCookie
* DatabaseBlock::setCookie
* DatabaseBlock::clearCookie
* DatabaseBlock::getCookieValue
* DatabaseBlock::getIdFromCookieValue
* AbstractBlock::shouldTrackWithCookie

After this, BlockManager::trackBlockWithCookie should be called to
track a block, and BlockManager::clearBlockCookie should be called
to unset the cookie. The other methods in the above list are
helper methods that are made private or marked internal.

Also update places in core that call User::trackBlockWithCookie to
BlockManager::trackBlockWithCookie

Bug: T225141
Change-Id: I818962c6932c01c841a549a101637e00a7593e48
2019-06-11 15:08:21 +01:00
Thalia
a387a375a1 Decouple DatabaseBlock::newFromTarget from DatabaseBlock::newLoad
Before this, DatabaseBlock:newFromTarget initialises a new block and
calls DatabaseBlock::newLoad on that instance, passing through the
target and type via that instance. However, newLoad returns a brand
new block instance. This patch makes newLoad into a static method,
with the target and type passed as method parameters.

It also separates the block-choosing logic in newLoad into a separate
method, DatabaseBlock::chooseMostSpecificBlock. Doing this (1) makes
it more transparent that Block uses two different ways to choose a
block (see also Block::chooseBlock), and (2) makes it possible to
re-use newLoad to get multiple blocks.

Also, filter out any duplicate autoblocks that are found by newLoad.

Bug: T206163
Change-Id: Iefa3aaadf2954c3b86f5c691096af31de40fae6c
2019-06-05 11:38:29 -04:00
Thalia
e65a5b5882 Rename Block to MediaWiki\Block\DatabaseBlock
Keep Block as a deprecated class alias for DatabaseBlock.
Update calls to the Block constructor and Block static
methods from external classes.

Also update documentation in several places that refer to
blocks as Blocks.

Bug: T222737
Change-Id: I6d96b63ca0a84bee19486471e0a16a53a79d768a
2019-05-28 12:20:48 +01:00
Renamed from includes/Block.php (Browse further)