Commit graph

591 commits

Author SHA1 Message Date
jenkins-bot
bba5dcc76e Merge "Remove User::setInternalPassword()" 2020-06-25 13:47:06 +00:00
Ammar Abdulhamid
4477f9b7f6 Remove User::setInternalPassword()
Deprecated since 1.27, unused in deployed code.

There's one usage in one extension that's already broken for other reasons

Bug: T249181
Change-Id: I2b868060dd394fb29e389628b659c0d1b3f11833
2020-06-25 13:04:09 +01:00
Ammar Abdulhamid
6164bb3f0c Drop User::checkPassword()
Hard-deprecated since 1.27 and no callers

Bug: T249181
Change-Id: Iee36a1107dbed105456f6a645f62f1d572d4a9fc
2020-06-25 11:52:57 +01:00
Thalia
9132b2e372 User: Remove useless check from deprecated isBlocked method
Remove call to AbstractBlock::appliesToRight, because it always
returns true for 'edit', so checking it is equivalent to adding
&& true.

Although this method is deprecated, this is worth tidying this up
since it is confusing and gets us one step closer to removing the
'edit' case altogether.

Change-Id: I479d6c866ec13a791873042e623fa841dd5bebf2
2020-06-24 23:43:11 +01:00
jenkins-bot
a7dae830b3 Merge "Introduce wfDeprecatedMsg()" 2020-06-22 22:30:49 +00:00
jenkins-bot
be6df9ec5b Merge "User: Fix pingLimiter() to use makeGlobalKey() for global rate limits" 2020-06-22 22:01:29 +00:00
Timo Tijhof
11bf9b13cf User: Fix pingLimiter() to use makeGlobalKey() for global rate limits
It was previously forging keys without any makeKey() call in a way
that does produce the same string regardless of wiki, however
bypassing makeKey() means the cache key might end up containing
illegal characters (and thus fatal). It also means that any
logic for detecting local vs global keys for sharding purposes
would wrongly intepret this as a wiki-local key which could cause
split-brain scenarios.

Bug: T246991
Change-Id: I83d0e11d84e3cdcfc8916b2a9b8d85db7c42d2a7
2020-06-22 21:37:12 +00:00
Tim Starling
d459add63d Introduce wfDeprecatedMsg()
Deprecating something means to say something nasty about it, or to draw
its character into question. For example, "this function is lazy and good
for nothing". Deprecatory remarks by a developer are generally taken as a
warning that violence will soon be done against the function in question.
Other developers are thus warned to avoid associating with the deprecated
function.

However, since wfDeprecated() was introduced, it has become obvious that
the targets of deprecation are not limited to functions. Developers can
deprecate literally anything: a parameter, a return value, a file
format, Mondays, the concept of being, etc. wfDeprecated() requires
every deprecatory statement to begin with "use of", leading to some
awkward sentences. For example, one might say: "Use of your mouth to
cough without it being covered by your arm is deprecated since 2020."

So, introduce wfDeprecatedMsg(), which allows deprecation messages to be
specified in plain text, with the caller description being optionally
appended. Migrate incorrect or gramatically awkward uses of wfDeprecated()
to wfDeprecatedMsg().

Change-Id: Ib3dd2fe37677d98425d0f3692db5c9e988943ae8
2020-06-22 14:34:39 +10:00
Umherirrender
fd666afbb0 Use MediaWikiServices::getAuthManager instead of AuthManager::singleton
Change-Id: I92c31b963095eab751df9f8c1715e8e23b7e8485
2020-06-22 00:57:08 +00:00
jenkins-bot
e862341ce0 Merge "Move User::newFromIdentity logic to UserFactory" 2020-06-15 20:26:57 +00:00
jenkins-bot
2f9ccec7d3 Merge "Followups for UserGroupManager" 2020-06-15 14:50:34 +00:00
Petr Pchelko
c8d3f524ee Followups for UserGroupManager
1. User::addGroup has to be allowed to update the old group
2. Replace use of string constants to identify cache class,
that's prone to typos and errors. Instead, use private constants
3. Update cached user group memberships in place upon modification.
Before UserGroupManager, we've used to do that - this saves some
DB queries, and is better for correctness - for example UserrightsPage
is adding new memberships and then immediately reads from replica,
expecting it's changes to be there already.
We do not know however how many other cases there are which rely
on this pattern, so implement in-place cache update.

Bug: T255330
Change-Id: Ia5ae0e22d4156fd5e4b9aa7eeb801902e79803d1
2020-06-15 07:10:13 -07:00
Petr Pchelko
d00dfbd756 Move User::addAutopromoteOnceGroups to UserGroupManager
Additionally, User::checkAndSetTouched was made public and
marked as @internal. Eventually, as User class refactoring
continues, I would expect this to be replaced by some service.

Bug: T252621
Change-Id: I53533f494950d08ee5ed1ec54d24958c21e7b3aa
2020-06-12 12:06:10 -07:00
DannyS712
2d7d99f036 Move User::newFromIdentity logic to UserFactory
Simplest static constructor for Users, no dependencies on anything else

Bug: T253432
Change-Id: Ibe422de4f1753334f2737bc39e077b1e4173ad45
2020-06-12 18:24:49 +00:00
jenkins-bot
6106469ef6 Merge "UserGroupManager: Consider $queryFlags when caching" 2020-06-11 22:03:07 +00:00
Clara Andrew-Wani
144157dbdb UserGroupManager: Consider $queryFlags when caching
Bug: T254282
Change-Id: I41a31ba6d597c11c7d7c8e753aa0e4c29303d5d9
2020-06-10 15:01:04 -04:00
DannyS712
249aa916d6 Hard deprecate User::getNewMessageLinks
Bug: T253949
Change-Id: I08d1fef9effeab420824c77f6ee7fd468ae51a3a
2020-06-10 02:02:16 +00:00
Umherirrender
fd1ed0c092 Pass function name to database functions
Useful for logging

Change-Id: Ia2160fb6be5fc93f28ab51f7ae23d7f078247481
2020-06-07 14:16:52 +02:00
DannyS712
f3bcc94bcf Deprecate User::getNewMessageRevisionId
Uses User::getNewMessageLinks, which uses Revision objects
Only caller updated to use a new private method

Bug: T253949
Change-Id: I04c0558916e7216540dd7bd12a2a391a1ed7660a
2020-06-05 21:36:06 +00:00
DannyS712
aae6f0eb3a Use WatchlistNotificationManager in SpecialWatchlist
Replace use of User::clearAllNotifications - no other known uses[1],
so also hard deprecate the User method

[1] https://codesearch.wmflabs.org/deployed/?q=-%3EclearAllNotifications%5C(&i=nope&files=&repos=

Bug: T254542
Change-Id: I3425a7c1a4094459260736c94cdd2402abb622eb
2020-06-05 02:37:55 +00:00
DannyS712
c3181c6f62 WatchlistNotificationManager: Add deprecations and release notes
Bug: T208777
Change-Id: I8c9bbdc286dde6287967f5f9e82cf38987f9fb28
2020-06-04 21:31:33 +00:00
jenkins-bot
748965cb95 Merge "Add new WatchlistNotificationManager service" 2020-06-04 20:24:20 +00:00
Petr Pchelko
40b88d635b Create UserGroupManager
Introduce a UserGroupManagerFactory and UserGroupManager.
The factory utilizes the same pattern as RevisionStore
for access to user groups of a foreign wiki.

Some user group related methods were ported from User
and UserGroupMembership and deprecated, more methods to
be moved over in future patches, not to make this one to large.

Eventually as all the group-related methods are moved and their
usages are replaced, the need for the UserRightsProxy will disappear,
thus it also will be deprecated and removed. Currently for backwards
compatibility, I've had to create artificial UserIdentityValue
objects in some of the deprecated methods to avoid making transitional
temporary methods in the UserGroupManager that would take user ID
instead of the UserIdentity. All of this will go away once migration
to UserGroupManager is completed.

Bug: T234921
Change-Id: If29c6a03dfdbb80b2e846243f7e384b334da9f07
2020-06-03 16:46:51 -07: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
DannyS712
c243c1b06e Add new WatchlistNotificationManager service
Replaces watchlist notification methods in Title and User classes:
* Title::getNotificationTimestamp -> ::getTitleNotificationTimestamp
* User::clearNotification -> ::clearTitleUserNotifications
* User::clearAllNotifications -> ::clearAllUserNotifications

New service has 67.90% code coverage with pure Unit tests; as well
as integration tests for the DeferredUpdates part

A follow-up patch will deprecate the replaced methods, as well
as document that the `UserClearNewTalkNotification` hook now only
provides a UserIdentity (typehint added in T253435 but until now
a full User was still provided).

Bug: T208777
Change-Id: I6f388c04cb9dc65b20ff028ece607c3dc131dfc5
2020-06-02 23:22:02 +00:00
DannyS712
1ccf066380 Add a new UserEditTracker service for user edit counts and timing
Moved to the new service are the following User:: methods:
* ::getEditCount
* ::getFirstEditTimestamp
* ::getLatestEditTimestamp
* ::getEditTimestamp
* ::initEditCountInternal

A subsequent patch will replace existing uses in core and deprecate the
User methods.

The new service has 100% test coverage with pure Unit tests.

Bug: T253431
Change-Id: If96f9d41026aa358c0fe269a3e078af5f6f058f2
2020-06-02 03:00:05 +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
fedbf6ba82 Merge "Use new TalkPageNotificationManager" 2020-05-20 19:21:52 +00:00
Reedy
af063dd794 Fix more Squiz.Scope.MethodScope.Missing
Change-Id: I44cd7ba39a898a27f0f66cf34238ab95370d2279
2020-05-18 21:02:14 +00:00
Reedy
988174411c Fix even more PSR12.Properties.ConstantVisibility.NotFound
Change-Id: If1335359b545c36fc979676c3e88d87628f9389e
2020-05-16 00:51:31 +01:00
Ammar Abdulhamid
3356762235 Drop User::checkTemporaryPassword()
Hard-deprecated since 1.27 and no callers

Bug: T249181
Change-Id: I661d280423014c6b7a609b100eee4f72daa5f81e
2020-05-15 18:36:48 +01:00
Clara Andrew-Wani
b3a5c7c0d5 Use new TalkPageNotificationManager
Bug: T239640
Change-Id: I7c06d145854ab39faaef528e169f6b51de1c8d99
2020-05-15 12:35:45 -04:00
MusikAnimal
a1ddac1d54 Add methods to check if a page is temporarily watched
Add 'mw-watchlink-temp' class to watch link when temporarily watched.

Bug: T248495
Change-Id: I61b24fddf6aaf5233f426602bfa1cc4fafce942b
2020-05-13 19:11:52 +00:00
Petr Pchelko
c2a1e0f7e5 Create TalkPageNotificationManager service
* The hook that's being deprecated is not used anywhere
in MW ecosystem.
* The getNewMessageLinks/getNewMessageRevisionId wasn't
ported to the service, only the DB lookup. The interface
of these two methods is extremelly weird, the idea is that
they should eventually be able to do cross-wiki lookups.
This doesn't belong in the service - with only a single caller,
these methods should be moved out of User and inlined into the
caller instead.
* There's been a little bit of preparation done to T146585#4233276
as the interface of setNewTalk was split into set and remove
with the idea that we gotta require Revision to be passed to
setUserHasNewMessages eventually. B/C is still maintained though
since service-conversion patches are not a right place for making
behavioural changes
* The tests are only integration tests since most of the logic
in the manager is tied up to the database anyway.

Bug: T239640
Change-Id: Ia0a52865970c11066d1089196251f62ffeaa53bb
2020-05-06 15:31:55 -07:00
Reedy
e25e5ec738 user: Close a bracket in a User.php doc comment
Change-Id: I3905a22201fc713f15aecaa50f20ec4fe23c8bad
2020-05-04 17:41:13 +00:00
Petr Pchelko
788331c48a Introduce UserOptionsManager and DefaultOptionsManager
This converts user options management to a separate
service for use in DI context.

User options are accessed quite early on in installation
process and full-on options management depends on the
database. Prior we have protected from accessing the DB
by setting a hacky $wgUser with 0 id, and relying on the
implementation that it doesn't go into the database to
get the default user options. Now we can't really do that
since DBLoadBalancer is required to instantiate the options
manager. Instead, we redefine the options manager with
a DefaultOptionsManager, that only provides access to
default options and doesn't require DB access.

UserOptionsManager uses PreferencesFactory, however
injecting it will produce a cyclic dependency. The problem
is that we separate options to different kinds, which are
inferred from the PreferencesFactory declaration for those
options (e.g. if it's a radio button in the UI declaration,
the option is of multiselect kind). This is plain wrong,
the dependency should be wise versa. This will be addressed
separately, since it's requires larger refactoring. For now
the PreferencesFactory is obtained on demand. This will be
addressed in a followup.

Bug: T248527
Change-Id: I74917c5eaec184d188911a319895b941ed55ee87
2020-04-28 15:42:43 -07:00
Aaron Schulz
3c7f29a6b9 Add small HtmlCacheUpdater service class to normalize purging code (2)
This is a re-submit of 35da1bbd7c, which was accidentally merged before
CR (and reverted with aa4da3c2e8).

The purge() method handles purging of both file cache and CDN, using
a PRESEND deferred update. This avoids code duplication and missing
file cache purge calls.

Also:
* Migrate HTMLCacheUpdate callers to just directly using HTMLCacheUpdateJob
* Add HtmlFileCacheUpdate class and defer such updates just like with CDN
* Simplify HTMLCacheUpdate constructor parameters
* Remove BacklinkCache::clear() calls which do nothing since the backlink
  query does not actually happen until the job runs

Bug: T230025
Change-Id: Ic1005e70e2c22d5bd1ca36dcdb618108ebe290f3
2020-04-14 03:19:07 +00:00
DannyS712
c75a713479 Support RevisionRecords in User Newtalk methods, deprecate Revision
Bug: T246284
Change-Id: I409e13657e52d7d286de1b7c728260aecee43220
2020-04-03 23:39:56 +00:00
DannyS712
23242d04d1 Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.

Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.

UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.

User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated

A follow up patch will add this to the release notes, to avoid merge
conflicts.

Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-03-26 01:31:14 +00:00
Petr Pchelko
aa1ea49a51 Hard deprecate Revision::loadFromTimestamp
Bug: T246284
Depends-On: Ia8d49b3158baf578ccd3476d6537be36dcea7e13
Change-Id: Ic4df02a7e21d4d1c0140e0f5a985a90f66983fab
2020-03-25 12:21:02 -07:00
DannyS712
2962e56f01 Remove UserIsHidden hook, deprecated and unused
Bug: T247019
Change-Id: Icb2703d20aed1d684cd897537cba71d5e1633541
2020-03-05 19:31:46 +00:00
jenkins-bot
6512ef160c Merge "Introduce an expiry to WatchedItem" 2020-03-04 18:33:07 +00:00
MusikAnimal
bb56abfba0 Introduce an expiry to WatchedItem
Includes the new $wgWatchlistExpiry feature flag.

Consumers of WatchedItem and WatchedItemStore have not been changed to
make use of expiries, this along with associated UI changes will be done
in a separate patch.

Bug: T245213
Change-Id: Ifff5e56e0222bb325cf796e0aa3d88825820d1fd
2020-03-04 11:32:19 -05:00
Timo Tijhof
95ec909e52 WikiMap: Add WikiMap::getCurrentWikiId() to make common use case easier
Change-Id: Ie225ebfc37c824e3167742137bbbc9f64aca5f5e
2020-03-03 16:04:21 +00:00
Umherirrender
a9cae1a917 Remove unused variables from closure use() lists
Change-Id: I11f2e0d7a95caf9d7e8732f8022e6e0685a4223d
2020-02-29 17:10:28 +00:00
Gergő Tisza
fd31b399e9
Clarify docs for User::getOption $defaultOverride parameter
The name of the parameter makes it sound like it overrides the
default value for that option, but it actually doesn't.

Change-Id: I9797696990aafad4b5fc2a62ace739d485315b73
2020-02-04 19:20:05 -08:00
Peter Ovchyn
61e0908fa2 languages: Introduce LanguageConverterFactory
Done:
* Replace LanguageConverter::newConverter by LanguageConverterFactory::getLanguageConverter
* Remove LanguageConverter::newConverter from all subclasses
* Add LanguageConverterFactory integration tests which covers all languages by their code.
* Caching of LanguageConverters in factory
* Make all tests running (hope that's would be enough)
* Uncomment  the deprecated functions.
* Rename FakeConverter to TrivialLanguageConverter
* Create ILanguageConverter to have shared ancestor
* Make the LanguageConverter class abstract.
* Create table with mapping between lang code and converter instead of using name convention
* ILanguageConverter @internal
* Clean up code

Change-Id: I0e4d77de0f44e18c19956a1ffd69d30e63cf51bf
Bug: T226833, T243332
2020-02-03 11:38:03 +02:00
Daimona Eaytoy
41ee2f2c61 Upgrade phan to 0.9.1
Released just now.

Many old suppressions can now be removed. Enabling the issue for
undeclared variables is left to do later, given that there are
roughly 200 warning.

Change-Id: I99462a1e9232d6e75022912e2df82bc2038476ef
2020-01-25 10:53:26 +00:00
Ammar Abdulhamid
f482090d77 Replace deprecated IP class with IPUtils
Bug: T242556
Change-Id: Ieaf4e1de2d766766bdb5fdb2425e8148ddd331b4
2020-01-24 18:49:33 +01:00
jenkins-bot
b77482b798 Merge "user: More descriptive docs for User::getDefaultOptions()" 2020-01-15 05:59:19 +00:00
James D. Forrester
0958a0bce4 Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNull
Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
2020-01-10 14:17:13 -08:00
James D. Forrester
4f2d1efdda Coding style: Auto-fix MediaWiki.Classes.UnsortedUseStatements.UnsortedUse
Change-Id: I94a0ae83c65e8ee419bbd1ae1e86ab21ed4d8210
2020-01-10 09:32:25 -08:00
Thalia
f7cb1c910c Throw deprecation warning from deprecated User::isDnsBlacklisted
Change-Id: I790e03fbef4eea9a3f2c7829f68d012f8afc2231
2020-01-08 18:28:44 +00:00
DannyS712
0e7f323df9 Remove User::addNewUserLogEntryAutoCreate
Bug: T241349
Change-Id: Id02fc164fd31c0e75fc6dfd4456544d8feb4c7fe
2020-01-02 00:23:43 +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
Thiemo Kreuz
ffc2839eea user: More descriptive docs for User::getDefaultOptions()
This code can not guarantee the return values are strings, and doesn't
need to, as far as I can tell. There is no need to enforce these values
to be strings at this point, even if user options will typically become
strings later, after being stored in the database.

Change-Id: Ia09064018aed34fff6f94d7a43036f16fed1a864
2019-12-29 12:01:11 +01:00
Umherirrender
10407dffb7 Allow null on User::setEmailAuthenticationTimestamp
Called from User::invalidateEmail

Change-Id: Ief9a9d19bbeecd29ab13244e18eeabc0aa08a520
2019-12-28 23:16:36 +01:00
Fomafix
09bc7484a7 Use type mixed|null for $defaultOverride in User::getOption
Extension Gadgets use a boolean value for $defaultOverride.

Also fix the return type for getOption and getDefaultOption.

This change is needed to pass the tests in
I255237574e76f1c0d92f376bc8cbb81f7cb4ed14.

Change-Id: I92ecaa9c14e5c8ba32d152a9e2246a2144b1c7da
2019-12-21 20:56:19 +00:00
daniel
db3e7f8b7e User: better error message when getActorId fails.
This changes User::getActorId() to include the user name and id
when throwing an exception. This doesn't solve the problem
reported in T211450, but should allow the the probelmatic user
name to be identified.

Bug: T211450
Change-Id: Ie83ce6ad6b5ef18ea44a52e204f580cd9c992148
2019-12-20 15:37:30 +01:00
Daimona Eaytoy
598c4d7fcb build: Upgrade phan to 0.9.0
Scalar casts are still allowed (for now), because there's a huge amount
of false positives. Ditto for invalid array offsets.

Thoughts about the rest: luckily, many false positives with array offsets
have gone. Moreover, since *Internal issues are suppressed in the base
config, we can remove inline suppressions.

Unfortunately, there are a couple of new issues about array additions
with only false positives, because apparently they don't take
branches into account.

Change-Id: I5a3913c6e762f77bfdae55051a395fae95d1f841
2019-12-07 20:16:19 +00:00
DannyS712
47a2da4b5c Split out separate User::isSystemUser method.
Drawing from comments associated with `User::newSystemUser` for
checking if a user is a system user, a new method, `User:isSystemUser`
is split out to avoid duplication elsewhere.

Bug: T237356
Change-Id: I73f25a10df2c28a69f612eb1db3e91b7125383d9
2019-11-25 16:48:38 +00:00
Cormac Parle
c4eae0dad4 Search: Provide new preference to control redirects on search matches
To avoid preference bloat, this preference is hidden unless the new
sysadmin config $wgSearchMatchRedirectPreference is set.

Bug: T235263
Change-Id: Ic16f53a4e6ddb6da071d63cd5da28d937d4692c8
2019-11-06 15:37:56 +00:00
Brad Jorsch
685b505628 User: Allow newSystemUser() to create over anonymous actors
Various maintenance scripts assume reserved usernames like
"MediaWiki default" exist, but since they're reserved
User::isUsableName() returns false and therefore the actor migration
created them as anonymous actors. Which would then prevent those
maintenance scripts from using User::newSystemUser() to ensure they
actually exist.

This adjusts User::newSystemUser() to be able to create users for
those anonymous actors.

This also adjusts uses of "MediaWiki default" in core to create it as a
system user.

Bug: T236444
Change-Id: I59a646df36ff9343cc43c05aa20b2b69b2ee124a
2019-11-01 10:36:59 -04:00
jenkins-bot
364a72419a Merge "Hard-deprecate User::getAllRights" 2019-11-01 01:43:36 +00:00
Petr Pchelko
e4b7fc3570 Hard deprecate User::isEveryoneAllowed
The method was soft-deprecated in 1.34. It's not used in any WMF
installed extensions or the tarball, so it can be hard deprecated.

Bug: T220191
Change-Id: I2f48d62a8dd3592918a6197168d31a1e08bd2a3e
2019-10-30 11:17:19 -07:00
Petr Pchelko
4548b53563 Hard-deprecate User::getAllRights
The method was soft-deprecated in 1.34, all usages in
WMF installed extensions or tarball installation were removed.

Depends-On: Icb739a3fbf54f5926ca1b661a8707a043ebf09f1
Bug: T220191
Change-Id: I0ee797be35d5278bd081dd07c483e69d9cba6244
2019-10-30 11:15:38 -07:00
Thalia
7f96f52187 Deprecate public User properties related to blocks
Deprecate mBlock, mBlockedby and mHideName as public properties,
since they allow the user to be put into an inconsistent state.
These properties were previously used by now-deprecated hooks
(bf5464614b, af24fc1a7a) and tests.

Bug: T229035
Change-Id: Ia657eaf8b5e4a77ff9df84eb706de1030e17c3bd
2019-10-23 10:49:35 +01:00
jenkins-bot
23dfdf865f Merge "Fix new phan errors, part 7" 2019-10-21 23:00:40 +00:00
Daimona Eaytoy
b1a5367ec8 Fix new phan errors, part 7
Bug: T231636
Change-Id: Ia5e0abee7163c5a1abd0bb53b89603cc2e7a9b5c
2019-10-21 22:10:20 +00:00
Thalia
3be681e625 Remove the deprecated GetBlockedStatus hook
Change-Id: I19d522ce32f540cc39bf482ab76f71492e4e9fd0
2019-10-21 17:16:20 +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
Daimona Eaytoy
bd5b6f98ba Fix new phan errors, part 3
These are almost only doc changes, with two exceptions:
1-In LinkHolderArray, int-alike array keys are now cast to int, to be uniform with what we do in other code paths
2-In ExtensionRegistration, changed a line to throw an Exception
immediately, instead of an ExtensionDependencyError. This is because the
latter takes an array with msg and type, but we were passing it a plain
string (and in fact the code was bugged).

Bug: T231636
Change-Id: I8b0ef50d279c2a87490dde6a467a4e22c0710afd
2019-10-12 10:35:22 +00:00
Daimona Eaytoy
2612175ef3 Use real variargs for variadic methods
These were all checked via codesearch to ensure that nothing is overriding
these methods.

Change-Id: Ie2d8c1fd01478f46f3d0d1259417182b0d955a12
2019-10-06 14:47:54 +00:00
jenkins-bot
76391b2a67 Merge "block: Allow cookie-block tracking from any uncached web request" 2019-10-01 23:22:47 +00:00
Thiemo Kreuz
bcbd880b13 user: Fix documentation of User::mBlock and related
Change-Id: Ia71c81a96fe74bf8d75fe826af432b0e3ff4c52c
2019-10-01 18:43:10 +00:00
Timo Tijhof
0e1e4ee5de
block: Allow cookie-block tracking from any uncached web request
This was previously hardcoded from three places: 1) Upon viewing EditPage,
2) Upon viewing SpecialCreateAccount, 3) For any url if the user is
logged-in (User::loadFromSession/isLoggedIn).

== User::loadFromSession

Performing cookie blocks from here created a circular dependency because
Block may need the user language for localisation, which is determined by
asking the User object. This was previously worked around by using a
DeferredUpdate (T180050, T226777). Moving this logic explicitly to the
end of the pre-send cycle in MediaWiki::preOutputCommit breaks the cycle.
This is also where other request-specific handling resides already.

== Limited effect on unregistered users

When an unregistered user performs an edit, and gets blocked,
the cookie block is not applied until they open built-in editor
or CreateAccount page. This makes it more likely for a user's
IP to change meanwhile. Either intentionally, or simply due to
IPs varying naturally (e.g. between mobile locations, or when
going on/off WiFi). By applying it throughout sessioned page
views for unregistered users, it is more likely to get set.
Similar to what was already done for logged-in users.

This commit also makes the intent of not caching EditPage and
SpecialCreateAccount explicit. This was previously implicit
through nothing having called setCdnMaxage() and/or due to
Session::persist being checked for by OutputPage::sendCacheControl.

Bug: T233594
Change-Id: Icf5a00f9b41d31bb6d4742c049feca0039d0c9d9
2019-10-01 13:52:58 -04:00
jenkins-bot
f15d6aaa97 Merge "Remove usages of Title::get{Previous,Next}RevisionId" 2019-09-13 22:58:36 +00:00
Reedy
58fb47b1e2 Remove User::setNewpassword()
Change-Id: I0a52ac16bc9c62bf344af3f489f4cbe7576fc733
2019-09-13 19:03:20 +01:00
Petr Pchelko
56c21d059c Remove usages of Title::get{Previous,Next}RevisionId
The methods were deprecated since 1.34.

Change-Id: Ib95ac1ba36a8ffd6b71ed67642d8abb2e3538bae
2019-09-13 09:49:13 -07:00
jenkins-bot
f9242d74f8 Merge "Pass the user and request into BlockManager::getUserBlock" 2019-09-11 18:58:32 +00:00
Thalia
5fffa5c07a Pass the user and request into BlockManager::getUserBlock
Blocks are checked from the User object. Specifically,
User::getBlockedStatus instantiates a BlockManager and calls
BlockManager::getUserBlock. However, checking the block often depends
on knowing more about the state than the User should know. As a result,
the global user and request objects were passed into the block manager
on construction.

Whether the global request object should be passed into a service
constructor is still up for debate, so this moves the check for the
global state back to User::getBlockedStatus for now. (Note that it
reintroduces the problem of the User knowing more about state than it
should.)

This change also makes clearer the cases in which
BlockManager::getUserBlock is called from the User.

Different blocks may be sought, depending on the user and their
permissions. The user may be:
(1) The global user (and can be affected by IP blocks). The global
    request object is needed for checking the IP address, the XFF
    header and the cookies.
(2) The global user (and exempt from IP blocks). The global request
    object is needed for checking the cookies.
(3) Another user (not the global user). No request object is available
    or needed; just look for a block against the user account.

Cases #1 and #2 check whether the global user is blocked in practice;
the block may due to their user account being blocked or to an IP
address block or cookie block (or multiple of these). Case #3 simply
checks whether a user's account is blocked, and does not determine
whether the person using that account is affected in practice by any
IP address or cookie blocks.

Bug: T231919
Change-Id: I3f51fd3579514b83b567dfe20926df2f0930dc85
2019-09-11 08:23:54 +01:00
jenkins-bot
1dcf5b66d3 Merge "Deprecate the GetBlockedStatus hook" 2019-09-10 18:23:54 +00:00
jenkins-bot
6b89d180d9 Merge "Move callers away from Title::GAID_FOR_UPDATE" 2019-09-10 03:32:37 +00:00
Thalia
bf5464614b Deprecate the GetBlockedStatus hook
This was replaced by GetUserBlock in 7a5508573a.

Handlers in production were updated to use GetUserBlock in
I952aa7d40 and Ibbcd3a239.

Bug: T229035
Change-Id: I95f9fabc6e795243cfe0a1e8737ca6abfb865538
2019-09-09 23:29:25 +01:00
Aaron Schulz
a5c7fd0db2 Move callers away from Title::GAID_FOR_UPDATE
These callers just need to load some data from DB_MASTER.
Subsequent code needing that latest title data should also use the
required flags, rather than relying on flakey global cache state.

Change-Id: I53248ea4b5bf1cd953f956c41b8244831ec5ef04
2019-09-09 13:19:08 -07:00
Thalia
af24fc1a7a Deprecate the UserIsHidden hook
This was replaced by GetUserBlock in 7a5508573a.

Handlers in production were updated to use GetUserBlock in
Ibbcd3a239.

Bug: T228948
Change-Id: I3e6da73e595e2bd6a96600fe2a6dc68a54d06a2e
2019-09-09 20:31:02 +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
Daimona Eaytoy
b5cbb5ab3f Upgrade phan config to 0.7.1
This allows us to remove many suppressions for phan false positives.

Bug: T231636
Depends-On: I82a279e1f7b0fdefd3bb712e46c7d0665429d065
Change-Id: I5c251e9584a1ae9fb1577afcafb5001e0dcd41c7
2019-09-04 08:20:53 +00:00
Daimona Eaytoy
43cc14657d Unsuppress phan issues, part 8
And also clean up the config.

Bug: T231636
Depends-On: Ie6233561de78457cae5e4e44e220feec2d1272d8
Change-Id: I82a279e1f7b0fdefd3bb712e46c7d0665429d065
2019-09-04 01:02:06 +00:00
Daimona Eaytoy
e70b5b3309 Unsuppress other phan issues (part 4)
Bug: T231636
Depends-On: I58e67c2b38389df874438deada4239510d21654f
Change-Id: I6e5fba7bd273219b1206559420b5bdb78734aa84
2019-08-31 17:13:39 +00:00
Derick Alangi
f7eb6a66dc user: Hard deprecate User::addNewUserLogEntryAutoCreate() method
This method is no longer used in core or any extension per CS below;

https://codesearch.wmflabs.org/search/?q=addNewUserLogEntryAutoCreate&i=nope&files=&repos=

Change-Id: I906db9a123f6eb4210642b68525324071422eb61
2019-08-30 21:56:08 +00:00
Daimona Eaytoy
fb3428eb8f Unsuppress other phan issues with low count
And also update approximated counts, which for the most part are lower
than reported (hooray!)

Bug: T231636
Depends-On: Ica50297ec7c71a81ba2204f9763499da925067bd
Change-Id: I78354bf5f0c831108c8f606e50c87cf6bc00d8bd
2019-08-30 09:42:15 +00:00
Petr Pchelko
49e2aec53a Move User::getAllRights to PermissionManager.
Bug: T220191
Change-Id: I7f4bf7f6a85b01ffd7f9ea3991597f1bd40ab1f6
2019-08-29 15:38:26 +02:00
jenkins-bot
3e49b37b68 Merge "Migrate BagOStuff::incr() calls to incrWithInit()" 2019-08-25 15:11:49 +00:00
Aaron Schulz
1879bf796a Migrate BagOStuff::incr() calls to incrWithInit()
Change-Id: I722d6fe3d50c594858e3e7960fb99ef2fc1664b3
2019-08-25 01:15:32 +00:00
Ppchelko
ab9436fb9a Merge "Deprecate and replace usages of User:isAllowed{All,Any}" 2019-08-22 17:31:50 +00:00
Petr Pchelko
acaa3e3136 Remove deprecated User groups/permission static calls.
Bug: T220191
Change-Id: Ifa8afa90c432723b0bba0033a46b6a499c77e6fc
2019-08-21 19:42:01 -07:00
Petr Pchelko
fd130247c2 Deprecate and replace usages of User:isAllowed{All,Any}
Bug: T220191
Change-Id: I197b8fadaa93e7b320fc19c10e3e09387fe09ad2
2019-08-21 18:36:16 -07:00
Aaron Schulz
f72ae0f6e6 Switch various LoadBalancer::getConnection() callers to getConnectionRef()
This is the preferred method as it enforces read-only mode for DB_REPLICA
and handles LoadBalancer::reuseConnection() calls automatically.

Change-Id: Iab9439ba8e0810fa14c302661ed7a3534f6bfc0d
2019-07-12 10:56:30 -07:00
jenkins-bot
78c11f0679 Merge "User: support setting custom fields + array autocreation in non-existent field" 2019-07-10 20:53:02 +00:00
Gergő Tisza
b530dca430 User: support setting custom fields + array autocreation in non-existent field
I889924037 added a __set method which did not actually handle fields being set.
For better or worse, setting custom fields on ubiquitous objects like User is a
common form of in-process caching, so this is a B/C break; restore for now.

PHP allows creating an array in a previously non-existent object property
with $o->foo['bar'] = $val, but doesn't properly handle that on objects
which have magic getter/setter. Add an ugly hack to make it work (but warn).

Depends on I15090ae9e4b66ac25f631f6179c4394ce8c445a9.

Bug: T227688
Change-Id: I62b80ab4fa10de984cf2c879ab12d91b0fd9bc1c
2019-07-10 20:35:56 +00:00
jenkins-bot
cca344a717 Merge "Rename various $wikiId fields/parameters to $dbDomain in user classes" 2019-07-04 13:58:54 +00:00
jenkins-bot
87193d29e9 Merge "Make UserEditCountUpdate::doUpdate avoid comparing IDatabase instances" 2019-07-02 21:57:10 +00:00
Aaron Schulz
08b0462fdc Make UserEditCountUpdate::doUpdate avoid comparing IDatabase instances
Also make User::initEditCountInternal take the specific DB handle that
was waited on for replication. This shouldn't make a difference but makes
things more explicit.

Change-Id: Ibb8e083406eb4f4453afce94a2b33450239fce94
2019-07-02 21:43:00 +00:00
jenkins-bot
9e43263709 Merge "Defer cookie block checks to resolve a circular dependency" 2019-07-01 11:09:45 +00:00
Vedmaka
dd6b94024c Re-apply: Factors out permissions check from User into PermissionManager service
Was reverted by I549810a4cd2e424cc4a438887d2f24614a24cc00 due to
T224607.

Original change by  Vedmaka Wakalaka was
Ia0d840b772ea5f20c9594ce151cc57adc270e48b.

Original commit message:

The following methods should are factored out of the User class into PermissionManager,
leaving only deprecated stubs:

- User::isAllowed -> PermissionManager::userHasRight
- User::getRights -> PermissionManager::getUserPermissions
- User::groupHasPermission -> PermissionManager::groupHasPermission
- User::getGroupPermissions -> PermissionManager::getGroupPermissions
 -User::getGroupsWithPermission -> PermissionManager::getGroupsWithPermission
- User::groupHasPermission -> PermissionManager::groupHasPermission
- User::isEveryoneAllowed -> PermissionManager::isEveryoneAllowed
- User::getAllRights -> PermissionManager::getAllPermissions

Depends-On: I7909e9bd6bbfbd708c0a00b861a9b22a38c6665d

Bug: T218558
Bug: T223294
Change-Id: I8899240378f636ea70f447616710516c0a3c5c31
2019-06-28 13:19:38 -07:00
Max Semenik
c873333333 Defer cookie block checks to resolve a circular dependency
User needs to load user preferences to get preferred language, which
calls User::load() which calls User::loadFromSession().

User::loadFromSession() tries to load blocks which might use messages
which need user language which calls User::load() because the previous
call to it haven't completed yet...

We have a protection against infinite recursion to prevent this from
completely crashing MW, however this patch fixes the main issue: loading
too much stuff when a User is initialized.

Bug: T180050
Change-Id: I63af6d2239b36124d5ed382b8d2aab82c8d54d69
2019-06-27 22:37:44 -07:00
Aaron Schulz
5c88c98932 Rename various $wikiId fields/parameters to $dbDomain in user classes
Change-Id: I0d4455ff4a693de41b8985b1421b18d93527acd6
2019-06-27 18:23:18 -07:00
James D. Forrester
06a34d5895 Drop the UserLoadFromSession hook, deprecated in 1.27
Change-Id: Ic86d9ee1fe6763270e79e31296ecd027e5d41be2
2019-06-24 14:12:33 -07:00
Fomafix
110a5877e9 Use [...] instead of array(...) in PHP comments and documentation
Change-Id: I0c83783051bf35fe785bc01644eeb2946902b6b2
2019-06-17 21:15:09 +02:00
Alexia E. Smith
aa9bbc47c3 user: Move idFromName cache truncation to before adding the new value
This prevents a double query for the same User::idFromName() call
twice in a row.

Bug: T225843
Change-Id: I5beb0a3ad5e715b68dd8a450408fb089184fa6ce
2019-06-14 18:05:26 +00: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
jenkins-bot
cb349fb447 Merge "Move cookie-blocking methods to BlockManager" 2019-06-11 15:16:00 +00: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
Umherirrender
5f43b1706c Pass options as array to IDatabase::insert
The documentation only allows arrays there

Change-Id: I00c6e47a817a70bed9a443aebc675ef4c3d6b1e5
2019-06-07 19:12:35 +02:00
Umherirrender
8e72fa0475 Improve @var on User class
Add missing @var tags with types or add missing types to @var

Change-Id: I34eb4c26d34da072465f1b162fb2d0291610f564
2019-06-05 19:19:22 +02:00
Kosta Harlan
7f90d1e3a3 Revert "Factors out permissions check from User into PermissionManager service"
This reverts commit 7faa7a7420.

Reason for revert: T224607

Change-Id: I549810a4cd2e424cc4a438887d2f24614a24cc00
2019-05-30 13:51:37 +00:00
Vedmaka
7faa7a7420 Factors out permissions check from User into PermissionManager service
The following methods should are factored out of the User class into PermissionManager, leaving only deprecated stubs:

- User::isAllowed -> PermissionManager::userHasRight
- User::getRights -> PermissionManager::getUserPermissions
- User::groupHasPermission -> PermissionManager::groupHasPermission
- User::getGroupPermissions -> PermissionManager::getGroupPermissions
 -User::getGroupsWithPermission -> PermissionManager::getGroupsWithPermission
- User::groupHasPermission -> PermissionManager::groupHasPermission
- User::isEveryoneAllowed -> PermissionManager::isEveryoneAllowed
- User::getAllRights -> PermissionManager::getAllPermissions

Depends-On: I258f02e286b6ba0387e1bff540a744fafb03dc55
Depends-On: Ie4cedf457eaaa93ec3055c37539322855e02ce26
Depends-On: Id274f240d687efa61cb9f7a15033ae2a7a532083

Bug: T218558
Bug: T223294
Change-Id: Ia0d840b772ea5f20c9594ce151cc57adc270e48b
2019-05-29 17:41:07 +02: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
Derick Alangi
fffadf725e user: Remove deprecated and unused method getPasswordValidity()
This method was deprecated in 1.33 and no longer used. See usage;

Usage
=====

https://codesearch.wmflabs.org/search/?q=%5CbgetPasswordValidity%5Cb&i=nope&files=&repos=

Bug: T220656
Change-Id: I28829f33d40b5568bedb9678fc43beb146b72e56
2019-05-10 00:13:20 +01:00
Thalia
824655f3b7 Separate Block into AbstractBlock, Block and SystemBlock
This commit splits the existing Block class into AbstractBlock, Block
and SystemBlock.

Before this patch, the Block class represents several types of
blocks, which can be separated into blocks stored in the database,
and temporary blocks created by the system. These are now
represented by Block and SystemBlock, which inherit from
AbstractBlock.

This lays the foundations for:
* enforcing block parameters from multiple blocks that apply to a
user/IP address
* improvements to the Block API, including the addition of services

Breaking changes: functions expecting a Block object should still
expect a Block object if it came from the database, but other
functions may now need to expect an AbstractBlock or SystemBlock
object. (Note that an alternative naming scheme, in which the
abstract class is called Block and the subclasses are DatabaseBlock
and SystemBlock, avoids this breakage. However, it introduces more
breakages to calls to static Block methods and new Block
instantiations.)

Changes to tests: system blocks don't set the $blockCreateAccount or
$mExipry block properties, so remove/change any tests that assume
they do.

Bug: T222737
Change-Id: I83bceb5e5049e254c90ace060f8f8fad44696c67
2019-05-07 17:36:31 -05:00
jenkins-bot
9d8759327a Merge "Let User::idFromName always return int or null" 2019-05-07 11:58:31 +00:00
jenkins-bot
8d9d8c8bb3 Merge "Force user id and actor id to 0 when loading from remote wikis" 2019-05-06 15:19:38 +00:00
Bill Pirkle
d4b72572a6 Force user id and actor id to 0 when loading from remote wikis
Stop-gap solution for the problem described in T222212.
Force the User ID and Actor ID to zero for users loaded
from the database of another wiki, to prevent subtle data
corruption and confusing failure modes.

Bug: T222381
Change-Id: Ic585f972d61da136744d080df13d8eb1ecd04cf5
2019-05-06 09:08:51 -05:00
Aryeh Gregor
f7201e3b9b Convert WatchedItem and friends to UserIdentity
I wasn't able to port some places that rely on isAllowed, getOption, or
related methods.

This adds isRegistered() to UserIdentity, which works like
User::isLoggedIn() but with a better name.

I also cleaned up User mocks in WatchedItemQueryServiceUnitTest in the
course of debugging test failures when switching them to
UserIdentityValue instead of mock Users where possible. They now specify
explicitly which methods are allowed to be called on their User objects,
which I believe is good practice for mocks (and unfortunately PHPUnit
makes it awkward).

Bug: T207972
Depends-On: I883d506197a011fe4c102b72df4d9deb58ab5ca2
Change-Id: Iadbf7bc31a496899dbef44e49065ff89f37aea89
2019-05-05 14:35:52 +03:00
jenkins-bot
12b7e6f38a Merge "Introduce a BlockManager service" 2019-05-01 18:26:59 +00:00
jenkins-bot
53338c123c Merge "Add missing IDatabase type hints to all doAtomicSection() calls" 2019-04-30 17:52:54 +00:00
Thiemo Kreuz
acf2f9a6c3 Add missing IDatabase type hints to all doAtomicSection() calls
Change-Id: I11061c358013fc67ec7a8ded54aeddcb7ff4910b
2019-04-30 17:08:48 +02:00
WMDE-Fisch
a91638bd38 Let User::idFromName always return int or null
This patch makes sure, that idFromName always returns either an int
or null value. The $idCacheByName can contain string values so we cast
the values if necessary.

An alternative could have been to make sure that just int values go
into the cache. But since the cache is public the current approach
to seems to be better atm.

Change-Id: I3085d89b93db2b888c190ba193623b86dc93759a
2019-04-30 16:45:59 +02:00
Derick Alangi
08a30a34f5 User: Remove/Kill usage of deprecated User::makeGroupLinkWiki()
This method was deprecated in 1.29 and usage of this method can no
longer be found.

Usage
=====

https://codesearch.wmflabs.org/search/?q=makeGroupLinkWiki&i=nope&files=&repos=

Bug: T220656
Change-Id: Iff5ef6666e8ec3e7060ddef8f60362206f4306d0
2019-04-29 21:39:14 +01:00
jenkins-bot
c29840f537 Merge "User: Remove deprecated methods ::getGroupPage() & ::makeGroupLinkHTML()" 2019-04-29 19:35:18 +00:00
Derick Alangi
621866f220 User: Remove deprecated methods ::getGroupPage() & ::makeGroupLinkHTML()
These methods were deprecated in 1.29 and usage can no longer be found so,
removing ahead of 1.34 cut.

Usage
=====

* User::getGroupPage() -
  https://codesearch.wmflabs.org/search/?q=%5B%5E%3E%5D(User)%3A%3AgetGroupPage%5C(&i=nope&files=&repos=

* User::makeGroupLinkHTML() -
  https://codesearch.wmflabs.org/search/?q=%5B%5E%3E%5D(User)%3A%3AmakeGroupLinkHTML%5C(&i=nope&files=&repos=

Bug: T220656
Change-Id: I4e48eb351883b044269d77a8baaf7b5030138c34
2019-04-29 11:40:24 -07:00
Thalia
52f7720227 Introduce a BlockManager service
This introduces a minimal BlockManager service, for getting blocks
that apply to a User.

Move the part of User::getBlockedStatus that checks for the blocks
into BlockManager::getUserBlock, and move the related helper
methods from User to BlockManager.

Hard deprecate or remove these helper methods, and move to private
methods in the BlockManager:
* User::getBlockFromCookieValue
* User::isLocallyBlockedProxy
* User::inDnsBlacklist

Soft deprecate these helper methods, and move to public methods in
the BlockManager:
* User::isDnsBlacklisted

Add tests to cover the methods moved to BlockManager.

Bug: T219441
Change-Id: I0af658d71288376735cebe541215383b56bb72e5
2019-04-29 17:47:55 +01:00
jenkins-bot
b942fc27c9 Merge "Deprecate User::isBlocked()" 2019-04-29 11:44:50 +00:00
David Barratt
e86a060284
Deprecate User::isBlocked()
The method User::isBlocked() attempts to answer two questions:
(1) Does the user have a block?
(2) Is the user prevented from performing this action?
The method can answer #1, but it cannot answer #2. Since User::getBlock() can
also answer #1, this method is redundant. The method cannot answer #2 because
there is not enough context in order to answer that question.

If access is being checked against a Title object, all access checks can be
performed with PermissionManager:userCan() which will also check the user's
blocks.

If performing all access checks is not desirable, using
PermissionManager::isBlockedFrom() is also acceptable for only checking if the
user is blocked. This method does *not* determine if the action is allowed,
only that the user's block applies to that Title.

If access is being checked without an existing Title, User::getBlock() can be
used to get the user's block. Then Block::appliesToRight() can be used to
determine if the block applies explicitly to a right (or returns null if
it is unknown or false if explicitly allowed). If the user is creating a new
Title, but the text of the title is not yet known (as in the case of Wikibase),
access should be checked with Block::appliesToNamespace().

Bug: T209004
Change-Id: Ic0ad1b92e957797fee8dcd00bd1092fe69fa58f1
2019-04-25 11:47:44 -04:00
Aaron Schulz
7a69b598f2 Alter two uses of hasOrMadeRecentMasterChanges() for consistency
Rather than have the behavior vary and possibly break code or tests
when small changes happen, make User/NameTableStore more explicit
about when cache key purges happens.

This should reduce problems with certain fragile tests, such as those
that could be affected by 0390811263 when --use-normal tables is not
used. Ideally, any fragility should be ironed out of effected code.

Change-Id: Ibe5d1bb4bece2526bc0da99648f7ba73bdc0ffa5
2019-04-23 11:34:09 -07:00
Derick Alangi
6b89deff20 User: Remove deprecated ::randomPassword() method
Usage:

https://codesearch.wmflabs.org/search/?q=(%3A%3A%7C-%3E)randomPassword%5C(&i=nope&files=&repos=

Only TwitterLogin (an unmaintained) extension still using it and
this patch I2c8d395dd2296a233f4 removes it.

Depends-On: I2c8d395dd2296a233f46abd44b89604c579c3020
Change-Id: I549d536e3c3e1da1c0c9c768640351bddf1d3449
2019-04-20 13:46:43 +01:00
jenkins-bot
7f2f49ad23 Merge "Improve documentation of constants throughout the codebase" 2019-04-12 21:38:16 +00:00
Aaron Schulz
59bac70c9b Fix phpdoc for type hint for User::makeUpdateConditions()
Change-Id: I46b3842495b3b9b8d44d16f434de4b44c65c1d80
2019-04-07 20:46:22 -07:00
jenkins-bot
9282d8f099 Merge "Fix/suppress phan errors related to arrays (#11)" 2019-04-07 16:44:03 +00:00
Kunal Mehta
02b18ba4cd Fix/suppress phan errors related to arrays (#11)
Change-Id: Ie5c05fbc88c51d493bc1462005d2f8dde5f72101
2019-04-07 16:27:02 +00:00
Aaron Schulz
deaf6b0e5d Change Database type hints to use IDatabase
Change-Id: Ie1e86cd961a619335138402ba22fe2a73a3e62fd
2019-04-07 01:15:50 +00:00
jenkins-bot
b235c8be4b Merge "Introduce PermissionManager service" 2019-04-05 16:45:32 +00:00
Vedmaka
8e1342ed47 Introduce PermissionManager service
First iteration of adding a PermissionManager service as a replacement
for Title::userCan and User::isBlockedFrom methods.

- Created PermissionManager service
- Migrated Title::userCan to PermissionManager::userCan and deprecated the first
- Migrated Title::quickUserCan to PermissionManager::quickUserCan and deprecated the first
- Migrated User::isBlockedFrom to PermissionManager::isBlockedFrom and deprecated the first

Same for User::isBlockedFrom and PermissionManager::isBlockedFrom - the
$user parameter is now required so the declaration is changed from
isBlockedFrom( $title, ... ) to isBlockedFrom( $user, $title, .. ) which
means before User::isBlockedFrom removal all calls to it need to be updated.

Added PermissionManagerTest, it copies TitlePermissionTest but uses
PermissionManager instance instead of Title methods, this way keeping both tests
in place, we can ensure that nothing was broken and both are in working state
during the deprecation phase.

Bug: T208768
Change-Id: I94479b44afb3068695f8e327b46bda38e44e691f
2019-04-05 14:54:51 +00:00
Reedy
c13fee87d4 Collapse some nested if statements
Change-Id: I9a97325d738d09370d29d35d5254bc0dadc57ff4
2019-04-04 19:02:22 +00:00
Erik Bernhardson
fe2cb4efc6 Recalculate user default options for each test
Statically caching the default user options means tests that change
the inputs, and expect to see the result in their code, are foiled
and the reasons shrowded in mystery.  Recalculate default user options
on a per test basis.

Change-Id: I9075cc9c05546a857850e8b4b4dea9f51873451b
2019-03-28 11:12:17 -07:00
Thalia
79706a8c93 Move logic for checking block behaviour to Block class
User::trackBlockWithCookie and PasswordReset::isBlocked make decisions
about block behaviour based on the block parameters. This should be
done in the Block class.

Bug: T218905
Change-Id: Ia3f46abacdaf70e720b715b39dc60aed53be2d0a
2019-03-27 12:54:55 +00:00
Thalia
1b9ca741a7 Remove reliance on Block properties being public
Use getters and setters for $mReason, $mTimestamp, $mExpiry and
$mHideName; use Block::getType to check if a block is an autoblock
instead of checking $mAuto; no change needed for $mParentBlockId,
which is not accessed externally.

Change-Id: I767ed44ce4c2e21f53962d75fb86891add2282f6
2019-03-22 21:17:22 +00:00
Reedy
7a4f2663a7 User::(get|is)Block*(): We don't need to prefix variables with their type…
Change-Id: I38e10453051dd300217542de68daab352993b2a6
2019-03-22 13:13:50 +00:00
Gergő Tisza
02387b7dc8
Rearrange code in User::getBlockedStatus to avoid isAllowed calls
User::isAllowed() triggers session loading, which results in a loop
if it is called during session loading. Session providers need to
check block status when $wgBlockDisablesLogin is enabled, so try to
avoid isAllowed calls in that situation.

Bug: T218608
Change-Id: Iab24923c613d6aeed4b574f587fc4cee8f33077c
2019-03-21 09:00:49 -07:00
Dayllan Maza
dba3a36be4 Remove block cookie stats measurement implementation
When setting a cookie on IP blocks was rolled out we wanted to
add some form of measurement to keep an eye on it. This patch is
removing that implementation 'cause it is not needed anymore.

Bug: T218596
Change-Id: I33ee164157b539560a3d88c6f3018dc013218640
2019-03-19 11:16:02 -04:00
Gergő Tisza
3b0effb203 Replace $wgUser with RequestContext::getUser in User::getBlockedStatus
$wgUser is not guaranteed to exist until MediaWiki has been fully
initialized; block status needs to be checked early on for
authentication-related permission checks.

Bug: T218608
Change-Id: I16315c071855024bc0412d5360c95f843420d9a9
2019-03-18 23:18:41 +00:00
Timo Tijhof
074ce9ab14 User: Remove redundant wgClockSkewFudge code
Ensuring the new value is at least as high as 1 second higher
than the current value is sufficient.

The main code paths using this are checkAndSetTouched (for user group
changes) and saveSettings(), both of which use makeUpdateConditions() which
ensures we bail out if something else already wrote to it in the mean time.
As such, there is no longer a need to make sure our time is higher than
something another server may have written, given that is no longer something
we support.

This variable was introduced in 2005 (MW 1.4) with r9403 (1d12276bcb),
and factored out as newTouchedTimestamp() in 2007 (MW 1.8)
with r16772 (c1094ba987).

Change-Id: I940fb0dd125286a4a348c11e2c8d197f9288a75d
2019-03-15 20:03:54 +00:00
Aaron Schulz
acfe6c8469 user: Avoid page_touched update in User::saveSettings
This was added in r42179 (65bbc14783) and only CDN and object caches
need purging.

Change-Id: I7ca40f8eda15ffeac3aa21aa4445b993d9fcc131
2019-03-15 00:01:30 +00:00
jenkins-bot
5a2e5db4fc Merge "Add password policy setting suggestChangeOnLogin" 2019-03-12 16:35:00 +00:00
Dayllan Maza
4b39919c47 Add password policy setting suggestChangeOnLogin
Password policy checks that fail and have `suggestChangeOnLogin` set to true will
prompt for a password change on login.

Below are some rules that apply to this setting in different scenarios:

- If only one policy fails and has `suggestChangeOnLogin = false`, a password change will
  not be requested
- If more than one policy fails and one or more have `suggestChangeOnLogin` set to true`,
  a password change will be requested
- If `forceChange` is present in any of the failing policies, `suggestChangeOnLogin` value
  will be ignored and password change will be enforced
- if $wgInvalidPasswordReset is set to false `suggestChangeOnLogin` is ignored

IMPORTANT**
Before this patch, suggesting a password change was the default behavior (depending on
$wgInvalidPasswordReset), which means that the necessary changes to $wgPasswordPolicy
need to be in place before this patch is merged and gets to production.

Bug: T211621
Change-Id: I7a4a0a06273fa4e8bd0da3dac54cf5a1b78bb3fd
2019-03-09 14:59:02 -05:00
Stephane Bisson
33a06450c9 Introducing User::getLatestEditTimestamp()
This will be used by the GrowthExperiments
Mentorship module to show when a user made their
latest contribution.

* Introduce a private function to reduce duplication with
  getFirstEditTimestamp()
* Add unit tests for both

Bug: T216631
Change-Id: Ica3e6e7165496bdc9b8f12972cf93847ecfffa50
2019-03-07 20:17:03 +00:00
James D. Forrester
3f717984c1 Drop AuthPlugin and related code, deprecated in 1.27
Bug: T215843
Depends-On: Ie49709faa6f67b0a31bd546823d29dbfea0a70eb
Depends-On: If8109dbfdeeb88a6265f4cd79d1ae81bff48d934
Depends-On: I36b195fa2d6c23a76631ebaf869c787e44427d60
Depends-On: Iaa171b085fde331eab7d85c7de74523e27fc625a
Change-Id: I330b30d6582034a233fed204c0680b1ce84eec6e
2019-03-05 08:23:14 +00:00
Roan Kattouw
10f7497eab Add UserSendConfirmationMail hook
Allow extensions to modify the confirmation email.

Bug: T215665
Change-Id: I4bcf76699a5114292fc19085fe441de8b898a8d3
2019-02-27 16:44:43 -08:00
Thiemo Kreuz
18741b9306 Improve documentation of constants throughout the codebase
The most notable improvements I was able to fit into this patch can be
seen in the User class, as well as in AbstractRestriction.

Our documentation generator ignores the @const tag. It's not needed. Just
have a comment above a constant and it will show up in the generated
documentation.

Using @var is misleading because a constant is not a "variable". The type
of a constant is strictly derived from it's value. Documenting the type
typically does not provide useful information. Doxygen does not understand
the type, but ignores any @… tag and renders everything else as plain text.

I can split this patch if you prefer. Please tell me.

Change-Id: I8019ae45c049822cdc1768d895ea3e3216c6db5f
2019-02-26 14:02:50 +01:00
Thalia
02cb7aefef Separate out different functionalities of Block::prevents
Block::prevents plays several different roles:
* acts as get/setter for Boolean properties that correspond to
ipb_create_account, ipb_block_email and ipb_allow_usertalk
* calculates whether a block blocks a given right, based on Block
properties, global configs, white/blacklists and anonymous user
rights
* decides whether a block prevents editing of the target's own
user talk page (listed separately because 'editownusertalk' is
not a right)

This patch:
* renames mDisableUsertalk to allowEditUsertalk (and reverses the
value), to match the field ipb_allow_usertalk and make this logic
easier to follow
* renames mCreateAccount to blockCreateAccount, to make it clear
that the flag blocks account creation when true, and make this
logic easier to follow
* decouples the block that is stored in the database (which now
reflects the form that the admin submitted) and the behaviour of
the block on enforcement (since the properties set by the admin
can be overridden by global configs) - so if the global configs
change, the block behaviour could too
* creates get/setters for blockCreateAccount, mBlockEmail and
allowEditUsertalk properties
* creates appliesToRight, exclusively for checking whether the
block blocks a given right, taking into account the block
properties, global configs and anonymous user rights
* creates appliesToUsertalk, for checking whether the block
blocks a user from editing their own talk page. The block is
unaware of the user trying to make the edit, and this user is not
always the same as the block target, e.g. if the block target is
an IP range. Therefore the user's talk page is passed in to this
method. appliesToUsertalk can be called from anywhere where the
user is known
* uses the get/setters wherever Block::prevents was being used as
such
* uses appliesToRight whenever Block::prevents was being used to
determine if the block blocks a given right
* uses appliesToUsertalk in User::isBlockedFrom

Bug: T211578
Bug: T214508
Change-Id: I0e131696419211319082cb454f4f05297e55d22e
2019-02-21 18:21:28 +00:00
James D. Forrester
9973617ae7 Drop User::getGroup{Name|Member}(), deprecated in 1.29 and unused
Except in the Configure extension.

Change-Id: Id6e2511cc2c5f86afcf0af2faa69d4a712efbe26
2019-02-09 20:47:43 +00:00
jenkins-bot
d90508d3c2 Merge "Collapse some else statements and nested if statements" 2019-02-08 03:55:22 +00:00
Reedy
31f5327b7d Collapse some else statements and nested if statements
Change-Id: Idd4d751e149e2ee11b8749ba847323f189b6ae51
2019-02-08 03:39:54 +00:00
jenkins-bot
28c6ce84c3 Merge "Stop overwriting $cache in User::getCacheKey()" 2019-02-07 16:57:13 +00:00
Reedy
5a1f6dbe63 Stop overwriting $cache in User::getCacheKey()
Replace a few deprecated function calls

Bug: T215483
Change-Id: I000b58d8bf67d9c1ea0123a7547b986e8ca69f25
2019-02-07 03:30:57 +00:00
Aaron Schulz
5196ac32c6 Rename WikiMap DB domain ID methods to reduce confusion with web domains
Those added in this same release do not need alias methods.

Change-Id: I05feeb9b0b13afe43aea1f95551965489cdbe094
2019-02-06 12:28:45 -08:00
David Barratt
be27181956 Add NamespaceRestriction class so that BlockRestriction can handle namespaces.
This begins work on making namespaces a valid restriction type. The CRUD
operations of BlockRestriction can now handle namespaces. Since
NamespaceRestriction implements Restriction, enforcement should start working
immediately, but testing enforcement will come in a subsequent patch since it's
impossible to create them.

Bug: T204991
Change-Id: I7264b452d9ad788c146d6ea25d01d4d7cb5ac4f6
2019-01-21 14:19:39 +00:00
Thiemo Kreuz
734a969d55 Safe replacement of a lot of !count() with === []
This was originally a global search and replace. I manually checked all
replacements and reverted them if (due to the lack of type hints) either
null (that would be 0 when counted) or a Countable object can end in the
variable or property in question.

Now this patch only touches places where I'm sure nothing can break.

For the sanity of the honorable reviewers this patch is exclusively touching
negated counts. You should not find a single `!== []` in this patch, that
would be a mistake.

Change-Id: I5eafd4d8fccdb53a668be8e6f25a566f9c3a0a95
2019-01-15 17:28:49 +01:00
jenkins-bot
36bbdfb8ad Merge "Add @since tags to new public methods related to partial blocks" 2019-01-08 18:37:25 +00:00
Thalia
d11e342ed6 Add @since tags to new public methods related to partial blocks
Bug: T210369
Change-Id: I20197ceee8e5e43fac20addc494b841519b915c8
2019-01-08 12:44:33 +00:00
jenkins-bot
dae39db4e3 Merge "Add force option to password policy" 2019-01-07 16:59:55 +00:00
Gergő Tisza
f15ecc60cd
Add force option to password policy
Adds a way to set an array of options for a password policy. Currently
there is one option, 'forceChange', which forces the user to change
their password (if it fails the given check) before logging in.

Bug: T118774
Change-Id: I28c31fc4eae08c3ac44eff3a05f5e785ce4b9e01
2019-01-02 12:38:11 -08:00
Max Semenik
abe2167b67 user: Ensure returned user groups are sorted
Without it, Special:UserRights sometimes fails with a bogus conflict error
just because groups are somehow ordered differently.

Bug: T164211
Change-Id: I9c7f51338e0849d9e134dc780eb13c542960c655
2018-12-22 07:38:51 +00:00
Gergő Tisza
86db28715f
Deprecate User::getPasswordValidity()
Unused, the return format does not seem useful.

Also improve the documentation of $wgPasswordPolicy
and PasswordPolicyChecks.

Change-Id: Ic01e80cfefc4cfb0eee1eccc6a66942f692278a0
2018-12-20 20:26:51 -08:00
jenkins-bot
ce54089bdf Merge "Add new rules when user is blocked for UTP" 2018-12-11 13:18:14 +00:00
Dayllan Maza
05a5b8e749 Add new rules when user is blocked for UTP
No changes for sitewide blocks when "Prevent user... edit own talk page"
is checked. On partial blocks, this option will be disabled and ignored. All users
will be allowed to edit their own talk page unless a page restriction
for their page is in place.

New rules will be implemented for Namespace restrictions in a different
patch when Namespace blocking is ready.

Bug: T210475
Change-Id: I096edf2887441bccd59f09bf0eceb3988b36db1e
2018-12-11 00:01:29 -05:00
jenkins-bot
bd78869618 Merge "No yoda conditions" 2018-12-09 01:34:23 +00:00
jenkins-bot
3be252f8cb Merge "User: Bypass repeatable-read when creating an actor_id" 2018-12-07 23:37:09 +00:00
Matthewrbowker
4da89d7d74 Remove User::EDIT_TOKEN_SUFFIX, a deprecated constant since 1.27.
Bug: T61113
Change-Id: I4a461003c881b457283dc6118153e24380fccc88
2018-12-07 22:59:20 +00:00
jenkins-bot
954327b642 Merge "Fix unexpected return type of User::idFromName()" 2018-12-03 18:18:54 +00:00
Thiemo Kreuz
a50014d259 Fix unexpected return type of User::idFromName()
The user_id is an unsigned integer in the database. But not all database
abstractions we use are guaranteed to return integer values as PHP
integers. Sometimes it's a string and needs an integer cast first.

Want proof? Search for usages of this method. Almost all add an (int)
cast. This is weird and should not be necessary.

Change-Id: If1d706f73350fca5b3a0f1e0de59e4518162445b
2018-12-03 14:33:48 +01:00
Brad Jorsch
37f48fdb25 User: Bypass repeatable-read when creating an actor_id
When MySQL is using repeatable-read transaction isolation (which is the
default), the following sequence of events can occur:

1. Request A: Begin a transaction.
2. Request A: Try to select the actor ID for a user. Find no rows.
3. Request B: Insert an actor ID for that user.
4. Request A: Try to insert an actor ID for the user. Fails because one
   exists.
5. Request A: Try to select the actor ID that must exist. Fail because of
   the snapshot created at step 2.

In MySQL we can avoid this issue at step #5 by using a locking select
(FOR UPDATE or LOCK IN SHARE MODE), so let's do that.

Bug: T210621
Change-Id: I6c1d255fdd14c6f49d2ea9790e7bd7d101e98ee4
2018-11-29 11:28:05 -05:00
David Barratt
93a894a8b3
Do not ignore the 'Prevent this user from editing his own talk page while
blocked' option on partial blocks.

Partial blocks currently ignore this option as it gets into an edge case. The
option should take precidence if it is true, but should be ignored if it is
false. On sitewide blocks, the option should always be honored.

Bug: T210475
Change-Id: I33177b48a5c261ec3f510ce01998c1b096077b85
2018-11-27 10:30:21 -05:00
Fomafix
3ee1560232 No yoda conditions
Replace
  if ( 42 === $foo )
by
  if ( $foo === 42 )

Change-Id: Ice320ef1ae64a59ed035c20134326b35d454f943
2018-11-21 17:54:39 +01:00
jenkins-bot
1db4c42f46 Merge "Block: Clean up handling of non-User targets" 2018-11-19 23:56:17 +00:00
jenkins-bot
5466734477 Merge "doc: Modernise parameter names and documentation for 'replica' DBs" 2018-11-13 21:39:14 +00:00
Brad Jorsch
74ff87d291 Block: Clean up handling of non-User targets
The fix applied in d67121f6d took care of the immediate issue in
T208398, but after further analysis it was not a correct fix.

* Near line 770, the method shouldn't even be called unless the target
  is TYPE_USER.
* Near line 1598, it isn't dealing with a target at all.
* Near line 1813, you're not going to get a sensible result trying to
  call `$user->getTalkPage()` for a range or auto-block ID. What you
  would really need there to handle range and auto-blocks correctly is
  to pass in the User actually making the edit.

But after some pushback in code review about passing the User into
Block::preventsEdit() to make line 1813 work, we'll instead replace the
method with Block::appliesToTitle() and put the check for user talk
pages back into User::isBlockedFrom().

Bug: T208398
Bug: T208472
Change-Id: I23d3a3a1925e97f0cabe328c1cc74e978cb4d24a
2018-11-02 12:33:57 -04:00
jenkins-bot
5f27c2fc65 Merge "Improve some queries ordering by rev_timestamp with actor migration READ_NEW" 2018-11-01 06:28:26 +00:00
Roan Kattouw
614dceed00 User: Don't fail mysteriously when passing a User object to idFromName()
If $name is a User object, some code magically works because the object
gets converted to a string, but other code blows up because objects
aren't valid array keys. Prevent this from happening by explicitly
forcing $name to be a string.

Bug: T208469
Change-Id: Icc9ebec93d18609605e2633ccd23b90478e05e51
2018-10-31 15:38:07 -07:00
James D. Forrester
903e8b63de doc: Modernise parameter names and documentation for 'replica' DBs
Non-breaking change. Remaining uses are public interfaces (a constant, two
globals, a config sub-parameter, SQL queries, storage function names), one i18n
message key, and a whole lot of maintenance scripts with calls to the deprecated
function wfWaitForSlaves().

Change-Id: I6ee5ca92ccf6a80c08f53d9efe38ebb4b05064d7
2018-10-31 10:36:48 -07:00
jenkins-bot
6edf7d44fa Merge "Use WikiMap methods for wiki ID logic in more places" 2018-10-30 07:20:29 +00:00
jenkins-bot
c6ad2554f4 Merge "Add isCurrentWikiId()/isCurrentWikiDomain()/getCurrentWikiDomain() to WikiMap" 2018-10-29 22:27:15 +00:00
Aaron Schulz
dbccb3a361 Use WikiMap methods for wiki ID logic in more places
Change-Id: I25b53576a8fecb7cfb0e4d684f064bebf6c968fc
2018-10-29 22:02:00 +00:00
Aaron Schulz
dcd0a3d534 Add isCurrentWikiId()/isCurrentWikiDomain()/getCurrentWikiDomain() to WikiMap
Use these in place of various wfWikiID() calls.

Also cleanup UserRightsProxy wiki ID variable names and removed unused
and poorly named getDBname() method.

Change-Id: Ib28889663989382d845511f8d34712b08317f60e
2018-10-29 14:53:37 -07:00
Aaron Schulz
e2088f1170 Make UserEditCountUpdate faster by using auto-commit mode
Bug: T202715
Change-Id: I92c08694cb5e1c367809439cff42e33a56ff9878
2018-10-27 13:52:45 -07:00