Commit graph

260 commits

Author SHA1 Message Date
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
jenkins-bot
cb4d4c4d8f Merge "Move user_editcount updates to a mergeable deferred update" 2018-10-26 20:32:24 +00:00
Brad Jorsch
59e856e3e6 Improve some queries ordering by rev_timestamp with actor migration READ_NEW
The revision_actor_temp table has denormalized copies of rev_page and
rev_timestamp to support the actor indexes equivalent to
`actor_timestamp` and `page_actor_timestamp`. But to get these to be
used, we need to have the WHERE and ORDER BY use the denormalized fields
instead of the main revision-table fields.

We can take generally advantage of the fact that "ORDER BY field" uses
aliased field names before the names in the actual table, but WHERE
conditions do need to explicitly vary.

Bug: T204669
Change-Id: I992aa50f02c35d76e91a5a28e05c870f8a32f858
2018-10-26 16:44:16 +00:00
Aaron Schulz
390fce6db1 Move user_editcount updates to a mergeable deferred update
This should reduce excess contention and lock timeouts.
Previously, it used a pre-commit hook which ran just before the
end of the DB transaction round.

Also removed unused User::incEditCountImmediate() method.

Bug: T202715
Depends-on: I6d239a5ea286afb10d9e317b2ee1436de60f7e4f
Depends-on: I0ad3d17107efc7b0e59f1dd54d5733cd1572a2b7
Change-Id: I0d6d7ddd91bbb21995142808248d162e05696d47
2018-10-25 15:32:18 -07:00
jenkins-bot
ecee5cd7c7 Merge "Use PHP 7 '??' operator instead of if-then-else" 2018-10-24 21:58:04 +00:00
Dayllan Maza
d67121f6d3 Enforce partial blocks
Enforce partial blocks and display a slightly different block
notice depending on if the block is sitewide or not

Bug: T197117
Depends-On: I675316dddf272fd0d6172ecad3882160752bf780
Change-Id: I8a3635a4a04a33912eb139b7b13c4bd874183d31
2018-10-24 00:57:48 +00:00
Fomafix
43244db9a2 Use PHP 7 '??' operator instead of if-then-else
Change-Id: If9d4be5d88c8927f63cbb84dfc8181baf62ea3eb
2018-10-21 21:46:46 +02:00
Aaron Schulz
ebbccf1845 Migrate some wfWikiId() callers to getLocalDomainID()
Change-Id: I33fe222b7ca66babd61610febaebcf52d3806a7d
2018-10-15 23:58:49 -07:00
jenkins-bot
0ecfa4b919 Merge "Drop UserGetImplictGroups, deprecated since 1.25" 2018-10-11 19:41:13 +00:00
Brad Jorsch
993baa3493 ActorMigration: Remove possibility of read-both
When this was originally written, the plan was to read both the old and
new fields during the transition period, while stopping writes to them
midway through. It turns out that the WHERE conditions to do read-both
correctly are generally not handled well by the database and working
around that would require a lot of complicated code (see what's being
removed from ApiQueryUserContribs here, for example).

We can simplify things greatly by instead having it write both fields
during the transition period, reading from the old for the first part
and the new for the second part, as is being done for MCR.

Bug: T204669
Change-Id: I4764c1c7883dc1003cb12729455c8107319f70b1
Depends-On: I845f6ae462f2539ebd35cbb5f2ca8b5714e2c1fb
Depends-On: I88b31b977543fdbdf69f8c1158e77e448df94e11
2018-10-11 12:12:00 +11:00
James D. Forrester
e888061ca9 Drop UserGetImplictGroups, deprecated since 1.25
Change-Id: Iffe29131fcc85d3477fe93508902d8ea982289f5
2018-10-10 15:30:00 -07:00
Gergő Tisza
e391244629 Hard-deprecate password handling in User
Add wfDeprecated for User::checkPassword(), User::setPassword(),
User::setInternalPassword() and User::checkTemporaryPassword().
With AuthManager mediating between the caller and a set of
authentication providers in a potentially multi-step process,
a password check or change now cannot always be expressed
with a single-step succed-or-fail process. Callers should use
AuthManager::beginAuthentication() with a PasswordAuthenticationRequest
for password checks, and AuthManager::changeAuthenticationData()
for a password change.

Bug: T91699
Change-Id: Ib0ae8f1ff10ae6c2655d529db8b3a32e0cb489b0
2018-10-01 23:13:03 +00:00
jenkins-bot
ef44b9075c Merge "Create UserGetRightsRemove hook" 2018-09-30 18:12:50 +00:00
Umherirrender
2af5b6b086 Fix caller name in User::addToDatabase
Seeing {closure} in the logs as caller is not helpful

Change-Id: I876877046ae4bd1756c13e04892c1381904566de
2018-09-30 15:22:29 +02:00
Timo Tijhof
adf774f0b1 user: Remove use of Message:text() from User::isUsableName()
None of the current translations use of "&", "{" or "[", which
presumably means they don't require tranformation. I'd also
very much prefer such dynamic constructs not be added into
this system which would make it rather unpredictable given these
reserved usernames shouldn't change from time to time.

The only match for the below command is qqq.json,

> $ git grep -E '"(double-redirect-fixer|usermessage-editor|\
> proxyblocker|sorbs|spambot.username|autochange-username)"\
> ' | grep -E '[{&[]'

This code was originally introduced with r37928 (5ad5cb4f0a),
which used wfMsgForContent() and made no explicit mention of
transformation, it just happened to be the default. Later, when
that function was deprecated, it got batch-replaced by
->inContentLanguage()->text().

Bug: T189966
Change-Id: Ia4ddf215e83f15de552f8311b9e737559c72b49a
2018-09-29 02:09:35 +01:00
MR70
9ea4764b2f Create UserGetRightsRemove hook
This hook is created specifically for I379e17c.

The purpose of this hook is to override UserGetRights hook and ensure
that the removed rights will not be reinserted by the other callbacks.

Change-Id: Id31b1f25f2eda012bd811f4b96aac525bc3251c4
2018-09-24 03:21:24 +00:00
jenkins-bot
6f3d5a5204 Merge "user: Allow "CAS update failed" exceptions to be normalised" 2018-09-20 22:31:11 +00:00
Chad Horohoe
befd48c5f7 SECURITY: Make 'newbie' limit in $wgRateLimits really override 'user' limit
The order of operations was incorrect.

Bug: T169545
Change-Id: Ia910aa2a494914d3b0017daac9ab294ea9fa8705
2018-09-20 22:26:11 +01:00
Umherirrender
a4caa4d0c6 build: Updating mediawiki/mediawiki-codesniffer to 22.0.0
Added spaces around .
Removed empty return statement which are not required
Removed return after phpunit markTestIncomplete,
which is throwing to exit the test, no need for a return

Change-Id: I2c80b965ee52ba09949e70ea9e7adfc58a1d89ce
2018-09-16 15:51:11 +00:00
Timo Tijhof
65f714e1e6 user: Allow "CAS update failed" exceptions to be normalised
Take the user_id variable out of the exception message.
To compensate and still allow one to correlate patterns relating
to a specific user (e.g. a bot), add a warning message that
still contains the variable via context. This way that warning
will also be normalised/grouped, but with the extra context.

This is separate because exceptions do not currently support
context placeholders.

Bug: T202149
Change-Id: Ic0c25f66f23fdc65821da12f949c6224bc03f9b3
2018-09-12 18:33:34 +01:00
Aryeh Gregor
90d4f56fe4 Mass conversion of $wgContLang to service
Brought to you by vim macros.

Bug: T200246
Change-Id: I79e919f4553e3bd3eb714073fed7a43051b4fb2a
2018-08-11 22:44:29 -06:00
Aryeh Gregor
115d4e2826 Return array without holes from User::getAllGroups
Change-Id: I2933ffe2cddec3d595536f93df17b609cdabab9e
2018-07-31 16:17:42 +03:00
Gergő Tisza
db888bc5ad
Segregate right to edit sitewide CSS/JS
To limit the likelihood of incidents like T189665, the ability to
edit sitewide CSS/JSON/JS is split out from editinterface, into
separate 'editsitecss', 'editsitejson' and 'editsitejs' rights.

editsitecss, editsitejs, and the right to edit another (potentially
more privileged) user's personal CSS/JS is removed from sysops, and
a new user group, interface-admin, is created specifically for that
task (along with a new grant group 'editsiteconfig').

interface-admin is granted to the first user of a new wiki, along with
sysop and bureaucrat.

Bug: T120886
Bug: T190015
Depends-On: Ia9b2ea1450aff6121dc0f3777bf029292c8aaad9
Change-Id: Ifefd872640642441e26f8b2f144ffe4b88d2eb12
2018-07-22 12:37:32 +02:00
Max Semenik
e6b4944dbf Introduce preference filters
This normalizes handling of transformations on the boundaries between
preferences and generic form controls and removes the special case
where email-blacklist is passed around as an array internally, leaking
into the API.

As a result of this normalization, meta=userinfo no longer returns an
array of users, using the internal representation like action=options.

Bug: T198935
Change-Id: Iff63da0d215585cfcf083e7f7ec8ed45d5b77301
2018-07-17 13:19:14 -07:00
Umherirrender
130ec2523d Fix PhanTypeMismatchDeclaredParam
Auto fix MediaWiki.Commenting.FunctionComment.DefaultNullTypeParam sniff

Change-Id: I865323fd0295aabd06f3e3c75e0e5043fb31069e
2018-07-07 00:34:30 +00:00
jenkins-bot
4f73259b37 Merge "Replace deprecated language codes in user options" 2018-06-14 13:56:36 +00:00
Fomafix
80f31ecac6 Replace deprecated language codes in user options
This change replaces deprecated language codes in the user options by
the new language codes when loading the user setting from database.

The database entry for the user gets updated with the new language code
when the user saves the preferences.

Bug: T131042
Change-Id: I1dd6fb1f240ce3319b132d0f29f0622fba33e655
2018-06-14 13:32:28 +00:00
daniel
e8632ab0f6 [MCR] Factor PageUpdater out of WikiPage
This introduces PageUpdater to replace WikiPage::doEditContent,
and DerivedPageDataUpdater, to replace WikiPage::doEditUpdates
and WikiPage::prepareContentForEdit.

See docs/pageupdater.txt for a description of their
functionality.

MCR migration notes:

* The interface of PageUpdater is expected to
remain mostly stable after this patch. Code that has been using
WikiPage::doEditContent can be confidently migrated to using the
new mechanism for revision creation.

* This patch keeps the code inside PageUpdater largely aligned
with the old code in WikiPage, to make review easier to to avoid
mistakes. It is intended to be refactored further, moving
application logic into stateless services.

* DerivedPageDataUpdate is intended as a stepping stone for further
refactoring. Its behavior is designed to be compatible with
callback code that currently relies on
WikiPage::prepareContentForEdit. Much of the code that currently
lives in DerivedPageDataUpdate should be factored out into
services, all behavior relevant to calling code should be exposed
via narrow interfaces.

Bug: T174038
Bug: T196653
Change-Id: If610c68f4912e89af616cdcac1d35a1be3946afa
2018-06-14 13:22:13 +00:00
Bartosz Dziewoński
485f66f174 Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient
Find: /isset\(\s*([^()]+?)\s*\)\s*\?\s*\1\s*:\s*/
Replace with: '\1 ?? '

(Everywhere except includes/PHPVersionCheck.php)
(Then, manually fix some line length and indentation issues)

Then manually reviewed the replacements for cases where confusing
operator precedence would result in incorrect results
(fixing those in I478db046a1cc162c6767003ce45c9b56270f3372).

Change-Id: I33b421c8cb11cdd4ce896488c9ff5313f03a38cf
2018-05-30 18:06:13 -07:00
Dayllan Maza
e8063a0846 Send a cookie with IP/IP-Range blocks when blocking logged-out users
A cookie will be set when ip users try to edit and their IP has been
blocked or if they try to create an account and the block prevents
account creation

This feature is disabled by default and can be enabled by
setting the new $wgCookieSetOnIpBlock config variable to true.

Note: this is meant to discourage vandals that try to avoid blocks by
switching their ip address while editing anonymously.

Bug: T152462
Change-Id: I0b78a5e174bcd882edea39e868a08f9a347f5aba
2018-05-24 00:48:05 -04:00
Brad Jorsch
d152ff76a5 User: System block reasons shouldn't expand templates
The block reasons for "system" blocks shouldn't expand wikitext
templates immediately. That should be left for the code parsing the
block reason for display.

This should only affect how these blocks are reported to API clients, as
when the block is displayed in the web UI it's passed through the parser
anyway. The main drawback, as far as the default messages go, is that
MediaWiki:sorbsreason won't have {{SITENAME}} expanded in
the API response anymore.

Bug: T191939
Change-Id: Ib2024721ea0e26358b9b50efdac16316d6d0f0b6
2018-05-12 08:13:39 -04:00
Gergő Tisza
df1c24fde8
Add equals() to UserIdentity
Change-Id: Ia2f33d551e96bd6f58ba9414049449282575a63b
2018-05-08 16:31:03 +02:00