Commit graph

1189 commits

Author SHA1 Message Date
Aaron Schulz
54758dd160 Change getCacheSetOptions() callers to use "Database"
* This is less verbose that DatabaseBase
* Also add a few WAN cache doc comments

Change-Id: I5b6de6d0ffa06753ea96c50b63db7dae796475dc
2015-10-05 22:06:46 -07:00
Aaron Schulz
db0b9ef264 Make WANObjectCache sets account for slave lag
* This gets lag information that is useful when
  the calling code is about to run queries that
  will have their results cached.
* This is now used in place of trxTimestamp() for
  WANObjectCache set() and getWithSetCallback().
* The WAN cache will use a low TTL if the lag is
  too high to avoid caching stale data for weeks.
* Bumped MAX_COMMIT_DELAY as nothing enforces it.

Bug: T113204
Change-Id: I2a95b4088cff42d6e980351555f81a4b13519e24
2015-10-05 16:45:13 -07:00
Thiemo Mättig
56d2a644f7 Add null to @return tags if a method can return null
Change-Id: I420998351663d92c4a101f61842e40591eebcd5f
2015-10-05 17:53:13 +02:00
Aaron Schulz
2c63d57ddd Made User::loadFromId() skip cache with READ_LATEST
* That flag is used for anti-dependencies and thus
  should never rely on cache

Bug: T95839
Change-Id: I4ffc8325e55588ef649b96e7b90bc95282f765a9
2015-09-30 21:53:25 +00:00
Brad Jorsch
c3dc398514 FauxResponse: Honor cookie options, and other cleanup
We have this nice class for unit testing cookie-setting, but the
cookie-setting method ignores all the parameters! Fix that. Also provide
accessors to check the entire set of cookie data, and the set cookies as
a whole.

While this does change the semantics of FauxRequest::getcookie() in that
the name now needs to be prefixed, no extension in Gerrit uses this
method so we should be fine.

Also clean up the case of the setCookie and getCookie methods while
we're at it. Since PHP method names are case-insensitive, this doesn't
even break compatibility with extensions.

Change-Id: Ib44a074bf9796bc0b470d557e39465792f399d30
2015-09-29 22:45:56 +00:00
Kevin Israel
5577d92bf5 User::incEditCountImmediate(): Add explicit IS NOT NULL check
Within the UPDATE query, if user_editcount IS NULL, user_editcount+1 will
also be NULL, and the change becomes a no-op. So in MySQL, the number of
affected rows would be zero, which is the number of rows that actually
changed.

However, other DBMSs (e.g. PostgreSQL, SQLite) do count no-op changes,
meaning the code would not initialize user_editcount if it were NULL.
Explicitly checking for NULL should ensure consistent behavior across
database types.

Also, if the CLIENT_FOUND_ROWS flag is set when connecting to MySQL, the
server returns "Rows matched:" instead of "Changed:" as the affected row
count. This change would be necessary if MediaWiki, like Drupal, is
changed to use that flag <https://www.drupal.org/node/805858>.

Change-Id: Idac160bae56adc5c5d17f8558c55d87000019741
2015-09-29 18:52:31 +00:00
Aaron Schulz
75f06d5294 Added $opts to WANObjectCache::set() to detect snapshot lag
* This can avoid some stale write race conditions
* Made use of this option in a few key places
* HOLDOFF_TTL was also bumped

Change-Id: I83505a59cce0119e456191c3100f7d97bc86bdbf
2015-09-28 23:03:36 +00:00
jenkins-bot
f2077a3144 Merge "Fixed sanity cache clear in User::saveSettings()" 2015-09-28 22:21:16 +00:00
Aaron Schulz
b23e0b0a83 Fixed sanity cache clear in User::saveSettings()
* This works by adding a refresh mode to clearSharedCache()
  when we want to purge the cache in case it might stale to
  avoid further CAS errors. Because an exception will be
  thrown, the usual DB callback will not get fired, so avoid
  using commit hooks when doing these cache purges.
* Also lowered the tombstone TTL for such purges, since no
  data actually changed.

Bug: T114023
Change-Id: Iaad87b4ed24733dac40bc9607d3c97c940710087
2015-09-28 14:07:01 -07:00
jenkins-bot
230f2b456b Merge "Avoid CAS errors on double post to ApiOptions" 2015-09-28 20:17:22 +00:00
Vivek Ghaisas
c54766586a Fix issues identified by SpaceBeforeSingleLineComment sniff
Change-Id: I048ccb1fa260e4b7152ca5f09b053defdd72d8f9
2015-09-26 23:06:52 +00:00
Aaron Schulz
d02b98b8f3 Updated key WANObjectCache::delete() callers to avoid races
* They now issue the delete() write before COMMIT of
  the relevant DB (or immediately if no trx is active)
* This can avoid some stale write race conditions
* Updated the WAN cache delete() docs

Change-Id: Id54887976051120b76528070d5f2ceb357d57897
2015-09-26 18:02:00 +00:00
Aaron Schulz
ece85dd20f Avoid CAS errors on double post to ApiOptions
Bug: T95839
Change-Id: I62f8eea31164be1ab0eacf31c494f0b296b367f2
2015-09-24 23:19:06 -07:00
Skizzerz
8e8826b768 Fix PHP notice when logging the result of a DNS blacklist check.
When the array syntax is used for the DNS blacklist, PHP throws a notice about array to string
conversion. This change ensures that the correct string name is used regardless of what type of
blacklist entry is used.

Change-Id: I2511a8320474a02d8f321d04f005bb9d18fb15b3
2015-09-23 13:28:01 +00:00
Kunal Mehta
bdf3f3e2d7 Add the performer to the UserRightsChanged hook
This allows extensions (e.g. Echo) to detect who made the change without
relying upon $wgUser. It also allows for differentiation between
autopromotion entries which will pass in `false` as the performer.

Change-Id: Idebd78b54dcea1bdc84c83f402e87b240ab4ade1
2015-09-22 10:58:20 -07:00
jenkins-bot
e491904eef Merge "Add new authentication-related hooks (and remove one) replacing some AuthPlugin methods" 2015-09-22 07:32:03 +00:00
Brad Jorsch
37062a0c0d Add new authentication-related hooks (and remove one) replacing some AuthPlugin methods
* LocalUserCreated: Replaces AuthPlugin::initUser()
* UserGroupsChanged: Replaces AuthPlugin::updateExternalDBGroups()
** The similar UserRights hook is deprecated, mainly to get rid of the
   passing of $user by reference.
* UserIsHidden: Replaces AuthPluginUser::isHidden()
* UserIsLocked: Replaces AuthPluginUser::isLocked()
* UserLoggedIn: Replaces AuthPlugin::updateUser()

Also, AuthPlugin::updateExternalDB() is deprecated in favor of the
existing UserSaveSettings hook.

Also, 'ResetSessionID' has been removed. Nothing uses it, I don't know
why I even added it in the first place.

Also, replacing the User object passed to AuthPlugin::initUser() and
AuthPlugin::updateUser() will now raise a warning.

Change-Id: If7474cfb26a29b11c2e78147069419ca3b1cba95
2015-09-18 10:46:13 -04:00
jenkins-bot
b60dded47b Merge "Use User::equals() where applicable in the class" 2015-09-18 09:08:27 +00:00
Michał Roszka
5668f2347a Use User::equals() where applicable in the class
It is a minor cleanup operation. I replaced a comparison of user 'mId'
with a corresponding 'User::equals()' call.

Change-Id: I89dea55789f343e794429c38934c263168ef608d
2015-09-18 08:54:28 +00:00
Aaron Schulz
d30ada2ad1 Removed clearSharedCache() hack in User.php
* WAN cache key salting/tombstones makes this overkill now

Change-Id: I078daacc5d2987858d720677f11e9828d71021e2
2015-09-08 17:02:39 -07:00
jenkins-bot
04ebf62661 Merge "Default the "watchlisttoken" value to a derived HMAC value" 2015-09-08 13:41:17 +00:00
Aaron Schulz
7389dd7676 Avoid some unused parameter IDEA errors in User.php
Change-Id: I75e56ab02af6aee5dbed1735ae8a3a415094508d
2015-09-04 12:13:32 -07:00
Aaron Schulz
cd027382e0 Default the "watchlisttoken" value to a derived HMAC value
* This got created if unset on API or GUI preferences access,
  which leads to writes on GET requests. Try to avoid that
  deriving it from user_token, unless overriden. This also
  means that changing the password always resets the key,
  which is how these things work on most sites anyway.
* The whole getTokenFromOption() method is deprecated, and
  this functionality is already in OAuth.

Bug: T92357
Change-Id: I96c0d6f6e535e67545049f01205430249eea8da0
2015-09-03 06:22:30 +00:00
Aaron Schulz
a15cf05188 Optimized notification timestamp clearing
* Hint that mariadb can avoid scanning already NULL rows since
  we want to set them all to NULL. This lets the index with the
  timestamp be used, which avoids logs of scanning for users with
  many rows. For non-parallel replication, this also avoids slave
  lag in particular.

Bug: T107923
Change-Id: I8cded5476ef6adb2f8fea57239afd6e9b2a49708
2015-08-12 15:37:57 -07:00
Aaron Schulz
3f24d1e348 Make Special:ConfirmEmail load the user from the master
* This can help guard against stale reads if the user was
  created or changed a second ago.

Bug: T105896
Change-Id: Ib2a59762cd8f4a4b7ad86d0700f186bee1d5b2d1
2015-08-04 18:40:38 +00:00
Aaron Schulz
dc713626b1 Fixed missing space in User CAS exception
Change-Id: Ibb34a3bd33c1eb92a2e2787a7e2402615ef02ccd
2015-07-23 13:51:37 -07:00
Kunal Mehta
c8ac9622ea Clean up UserMailer::send() parameters
$replyto and $contentType should now be passed as an array of $options.
This will make it easier to add more options in the future without
having a long list of optional parameters.

Change-Id: I2c38bb438bd01e0ed2552024a40311f3e8e2dc08
2015-07-20 21:34:44 -07:00
Aaron Schulz
64bf3a12b5 Defer user_newtalk updates in clearNotification() to post-send
* Also only issue DELETE if notifications exist. Previously,
  this would issue a DELETE for all self talk page views.

Bug: T92007
Change-Id: Ifef11c9e5175d68d9615e59e2ed7de2f2c57bde1
2015-07-17 21:56:36 +00:00
jenkins-bot
36f21b89ca Merge "Tweaked User::READ_LOCKING to use LOCK IN SHARE MODE" 2015-07-16 22:26:32 +00:00
jenkins-bot
eeb2329ac3 Merge "Upgraded User::saveSettings logged errors to exceptions" 2015-07-15 07:36:56 +00:00
jenkins-bot
8352deb985 Merge "Fixed User class IDE warnings" 2015-07-15 07:30:21 +00:00
csteipp
6a69a4eb73 Add "purpose" to password validity check
Allow callers to specify why they are checking a passwords validity, so
some checks can be modified. Only check the default policy on creation,
since the account doesn't exist it's not a member of any groups.

Bug: T104615
Change-Id: I56b66002562aaa1493d94a90309bc8e4ae3841c8
2015-07-14 20:04:23 +00:00
Aaron Schulz
939dbec87a Tweaked User::READ_LOCKING to use LOCK IN SHARE MODE
* This better alignes with IDBAccessObject docs and
  still locks out INSERTs

Change-Id: Ib8713938e0afa14bee6f90bc51d6331eaf356447
2015-07-14 11:13:05 -07:00
Legoktm
4c528691e1 Revert "Add 'AuthPluginStrict' log to identify users who are unable to authenticate"
Does not work as it will also log failed login attempts due
to a wrong password.

This reverts commit 9a97a7530f.

Change-Id: I6abd19da4e6939315a7fe6f7debe5227b68d38a7
2015-07-13 23:07:02 +00:00
Aaron Schulz
e47c2e0c95 Fixed User class IDE warnings
Change-Id: I68c30fd81a266aa1acdf74162bfa864b67922347
2015-07-13 14:30:50 -07:00
Kunal Mehta
9a97a7530f Add 'AuthPluginStrict' log to identify users who are unable to authenticate
To be able to identify any users who are unable to log in when switching
from allowing local authentication to strict.

Change-Id: I2ebdccdad9c7794d1c1b13db6a646a43bc770c4e
2015-07-13 17:37:35 +00:00
jenkins-bot
05fce41bb7 Merge "Made the prior user existence check in LoginForm use DB_MASTER" 2015-07-11 00:37:31 +00:00
Aaron Schulz
e0ee2cdc4b Fixed bitfield check in User::loadFromId()
* READ_LOCKING is a composite field, so it can yeild 00, 01,
  10, or 11 for the relevant two bits. Only one of them should
  pass the check to avoid locking and snapshot breaking queries
  for no reason.

Change-Id: Ief04ac20c7639fcf79443a3ee39a471542a59551
2015-07-10 16:52:28 -07:00
Aaron Schulz
08698e48e8 Made the prior user existence check in LoginForm use DB_MASTER
* This helps if multiple account creation attempts were made in a row
  and the slave selected was lagged (either too much for Chronology
  Protector or the user did not resend the cookies to link the session).
* The locking also better handles concurrent attempt to make another
  account, especially with CentralAuth trying to make external accounts.
  This assumes that the rate of concurrent account creations with close
  names is low enough given trx speed to avoid gap locking issues. This
  will need to be confirmed with low error log rates to be sure.
* The User::idFromName() method now includes a $flags parameter.

Bug: T104615
Change-Id: I8385526a19efc528a016ad2bbf376b377138966b
2015-07-10 16:45:28 -07:00
Aaron Schulz
ed1b8d3a0e Upgraded User::saveSettings logged errors to exceptions
* This gives more visibility and the error rate is not
  extreme (and mostly affects certain users due to
  usage patterns).

Change-Id: I3eae28a584e4db8ae40ae80087a97c416b3bd3e8
2015-07-10 01:41:29 -07:00
Aaron Schulz
84758e6f10 Made WANObjectCache::getCheckKey() automatically init the key
* This still allows If-Modified-Since logic but does not
  need to broadcast initialization values just because a
  key fell out of cache. The value can differ between DCs
  anyway via skew, this just lets them drift more. Actual
  purge events are still broadcasted, which is what matters.
* The User class has now been simplified given this change.
* Added more general comments to getCheckKeyTime().

Change-Id: Ic1f4bbb1947e0d1dd47499c9e9dc86991c30580c
2015-07-02 07:13:22 +00:00
jenkins-bot
b42a5e851c Merge "Replace some MWException usage in User" 2015-07-01 04:19:14 +00:00
Aaron Schulz
35fb85ba0b Replace some MWException usage in User
Change-Id: I61dbd6223354530311c497ad0f45ed49a573d0cb
2015-06-30 21:07:48 -07:00
Aaron Schulz
0aa93ad8b8 Made User::loadFromId() use READ_NORMAL by default
* This covers CentralAuthHooks::onUserLoadFromSession()
  among other cases (OAuth user loading, ect).

Bug: T92357
Change-Id: I9c90027d8852ff8c1d626c03b5dbd765b95b0ce1
2015-06-25 20:16:55 +00:00
Sam Smith
16cea35d85 Configure logged in session length independently
* Add the $wgExtendedLoginCookies configuration variable, which defines
  the set of login cookies that can have their lifetime configured
  independently
* Add the $wgExtendedLoginCookieExpiration configuration variable, which
  dictates when the extended lifetime login cookies expire
* Default $wgExtendedLoginCookieExpiration to null so that the current
  behaviour is unaffected

Bug: T68699
Change-Id: I0cc24524e4d7d9d1d21c9fa8a28c7c76b677b96c
2015-06-23 19:31:20 -04:00
Aaron Schulz
dd42294d29 Made User generally use DB_SLAVE by default
* By default, users will load from the slave unless
  the thread did a recent DB write. This is to handle
  changes within a request.
* ChronologyProtector should avoid staleness in common
  cases, and the CAS check on user_touched is a final
  barrier to block stale user object updates.
* Note that passwords are not cached, so they hit the
  DB when ever needed. Passwords now load from slaves
  when possible, instead of the master.
* This should get the code closer to handling user
  login and logged in users when the master is down.
* Fixed loadFromId() when READ_LOCKING is used.
* Also addressed TODO comment in load().

Bug: T92357
Change-Id: I0a8bdab720c19fe3fc2381799ae2e90ff09bb4cf
2015-06-16 08:29:06 -07:00
jenkins-bot
9ce9ca079f Merge "Password validity by policy per group" 2015-06-10 17:46:20 +00:00
csteipp
1a20dc9362 Password validity by policy per group
Make password policies defined in a configurable policy, which is
defined by group. A user's password policy will be the maximum of
each group policy that the user belongs to.

Bug: T94774
Change-Id: Iad8e49ffcffed38df6293db0ef31a227d3962003
2015-06-10 10:34:17 -07:00
Aaron Schulz
fd5bde60ec Fixed "wfTimestamp() fed bogus time value" errors
* This broke OutputPage::checkLastModified() as the touched time was false

Change-Id: I118d3ddf07c7b69ad269f3aee0c70ab4159df192
2015-06-09 18:47:49 -07:00
jenkins-bot
6378a12c88 Merge "Made User::touch no longer call load()" 2015-06-03 07:47:00 +00:00