Commit graph

109 commits

Author SHA1 Message Date
Umherirrender
2d055eea30 block: Normalize ip in DatabaseBlock::doAutoblock
When using $wgPutIPinRC the ip from rc_ip is used, which is stored as
::1, but blocks working with 0:0:0:0:0:0:0:1, so parse the ip with the
BlockUtils::parseBlockTarget and use that value.
Also reject possible invalid types, as this is a public function and may
called with something not wanted.

The ip given via User::spreadAnyEditBlock is also ::1 and the autoblock
would be inserted, when also a regular ip block exists against ::1

Change-Id: I9c1f429a7b0ff9b2274b72c46bf850d9db9492cd
2023-06-15 18:27:08 +02:00
Alexander Vorwerk
38b466c640 Load potential current ip block from correct wiki
When placing an autoblock we check wether the ip is already blocked by a
user or through another autoblock. In the second case we just reset the
expiry. In the first case we simply do nothing.

The problem here is that DatabaseBlock::newFromTarget(), which is used
here, is not cross-wiki compatible, so the correct blocks will not be
loaded here if the parent block is a cross-wiki block.

So, unfortunately, we have to manually implement the query here so that
the correct blocks are loaded.

Bug: T281972
Bug: T284873
Change-Id: Ia90e3578f7c103c40e88f3b68ddcba4a13734d80
2023-06-10 19:37:51 +00:00
Daimona Eaytoy
4d5cd3a84f Replace deprecated MWException
Bug: T328220
Change-Id: I66be7a6dd752d6b9c254beb65f4eb5ace3c89776
2023-06-09 17:21:12 +02:00
Alexander Vorwerk
6c9aa2242f Throw for mismatched wiki in AbstractBlock::getId()
Bug: T274817
Change-Id: I5b2c27ac3639ef92a55ff7b3cbc011a489c5705a
2023-05-29 23:42:30 +02:00
Alexander Vorwerk
31d063ca71 Deprecate passing a db to DatabaseBlockStore::insertBlock()
Instead of passing a custom database to DatabaseBlockStore::instertBlock
callers should rather just fetch a correct DatabaseBlockStore
using the new DatabaseBlockStoreFactory service.

Bug: T291849
Change-Id: Ia1319f35bbc5bd786d1d96d330f94255d7b3582a
2023-05-20 11:02:45 +02:00
Umherirrender
e04d3a28f6 Replace internal Hooks::runner
The Hooks class contains deprecated functions and the whole class is
going to get removed, so remove the convenience function and inline the
code.

Bug: T335536
Change-Id: I8ef3468a64a0199996f26ef293543fcacdf2797f
2023-05-11 06:17:38 +00:00
Amir Sarabadani
412bdc8eb2 Migrate several $db->update() calls to UpdateQueryBuilder
Bug: T330640
Change-Id: I85f94e4bab28348e48a32974389bf18b4700bdd3
2023-04-21 10:52:27 +02:00
Alexander Vorwerk
ed3f707556 AbstractBlock: Hard-deprecate accessing block IDs cross-wiki
Bug: T274817
Change-Id: I5c1ee557db9be3ebce8592d06dac520df2dd1cad
2023-03-10 16:09:43 -05:00
James D. Forrester
ad06527fb4 Reorg: Namespace the Title class
This is moderately messy.

Process was principally:

* xargs rg --files-with-matches '^use Title;' | grep 'php$' | \
  xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1'
* rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \
  xargs rg --files-with-matches 'Title\b' | \
  xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1'
* composer fix

Then manual fix-ups for a few files that don't have any use statements.

Bug: T166010
Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a
Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
2023-03-02 08:46:53 -05:00
Amir Sarabadani
7d8768e931 Reorg: Move HTML-related classes out of includes/ to Html/
Bug: T321882
Change-Id: I5dc1f7e9c303cd3f5b9dd7010d6bb470d8400a18
2023-02-16 20:40:01 +01:00
Alexander Vorwerk
ef52ed41bb Introduce a DatabaseBlockStoreFactory
The DatabaseBlockStoreFactory is a new service which allows fetching
of a wiki-specific DatabaseBlockStore by fetching the correct
LoadBalancer via a LBFactory and then injecting it into the
DatabaseBlockStore. It also creates a wiki-specific ReadOnlyMode
and BlockRestrictionStore, which are also being injected.

This is being done as a part of the project of supporting cross-wiki
blocking.

The future plan is that BlockUser and UnblockUser are being updated to
properly support creating, updating and deleting cross-wiki blocks.
BlockUser and UnblockUser are then going to use a newly injected
DatabaseBlockStoreFactory to fetch the correct DatabaseBlockStore to
then insert/update/remove the block into/from the correct database.

Bug: T291849
Change-Id: I1051beedfd67c4e2c546b9eec04b6d592d969af3
2023-02-13 01:59:55 +00:00
Derick Alangi
8eb423c4dc Use CommentStore service instead of deprecated method
Also, added a parameters to XmlDumpWriter so that they could be
inject via WikiExporter.

Bug: T325475
Change-Id: I84b82506509e2c09dad0691af2df958a5af5b5b0
2023-01-04 23:50:51 +00:00
Alexander Vorwerk
f6bd18d6c2 Split a base class out of CommentStore
so that extensions (i.e. CheckUser) can implement their own comment
store without having a lot of code duplication

basically the comment store version of I3a6486532f2ef36

Bug: T233004
Change-Id: Ib40f99e00a514d41776ce521baf113e46d37e9cd
2023-01-01 22:34:36 +00:00
jenkins-bot
c903124b77 Merge "Make use of ?:, ?? and ??= operators in mostly trivial cases" 2022-12-16 02:51:26 +00:00
Umherirrender
45e6a2b0f9 Use str_starts_with/str_ends_with/str_contains
Use the new function in conditions to avoid creating substrings or to
search the whole string

Change-Id: Ibad6b1b447a4f62cceb34359231f88ebb967a90b
2022-12-12 19:54:24 +01:00
DannyS712
948d91d0d4 DatabaseBlock: don't save parent block id as 0
Convert 0 back to null when loading from a row

Bug: T282890
Change-Id: Ic2b4da554469a1c0d5cc6dbc82f32d4e0ce0a887
2022-12-06 23:38:44 +01:00
thiemowmde
70aa9c8e35 Make use of ?:, ?? and ??= operators in mostly trivial cases
The motivation is to make the code less confusing. I hope this is the
case.

?? is an older PHP 7.0 feature.
??= was added in PHP 7.4, which we can finally use.

Change-Id: Id807affa52bd1151a74c064623b41d950a389560
2022-12-05 21:37:13 +01:00
Umherirrender
20c3cc6ef1 Remove unused variable from unpacking arrays
Change-Id: Iac27cb4aa936cb494b3e491ce22c88c7fad375a1
2022-11-22 23:21:08 +00:00
Tim Starling
0077c5da15 Use short array destructuring instead of list()
Introduced in PHP 7.1. Because it's shorter and looks nice.

I used regex replacement.

Change-Id: I0555e199d126cd44501f859cb4589f8bd49694da
2022-10-21 15:33:37 +11:00
Thalia
1f3de22cba block: Remove temporary logging for closed task from DatabaseBlock
Bug: T192964
Change-Id: I148547c7576615a9fe7ebab7bb023e5a24d7df50
2022-10-11 19:31:13 +00:00
Daimona Eaytoy
947ff7c0f5 build: Update mediawiki/mediawiki-phan-config to 0.12.0
This patch only adds and removes suppressions, which must be done in the
same patch as the version bump.

Bug: T298571
Change-Id: I4044d4d9ce82b3dae7ba0af85bf04f22cb1dd347
2022-10-08 15:45:42 +02:00
Umherirrender
cbe949410d Improve docs of various ::getQueryInfo functions
Explict types helps phan to detect errors with keys like ef82d95

Change-Id: Iee4d964ecc58273eb9c73356ed34e13f29fbd275
2022-08-13 21:18:44 +02:00
Alexander Vorwerk
93e14502b1 block: Create wiki-aware target for autoblocks
AbstractBlock::setTarget() will fatal if the wiki of the target
doesn't match the wiki of the block.

Bug: T281972
Bug: T284873
Change-Id: Ie696bb6442abd039635ed58439c065a1eb2d1b4f
2022-07-08 22:59:27 +02:00
jenkins-bot
2268f8253e Merge "Respect the wiki when performing autoblocks" 2022-06-30 22:12:37 +00:00
Matěj Suchánek
012011d941 Hard deprecate access to public properties on AbstractBlock/DatabaseBlock
Change-Id: I3cca210627d94d72e09beb52f8b015181f14ed7c
2022-06-23 12:43:58 +02:00
Matěj Suchánek
50d0cdcb48 Remove DatabaseBlock::$mFromPrimary
It's been unused since 2c1270d744.

Change-Id: I3c004791080a64b6c84656cf1f64557c9ab0b52b
2022-06-22 13:47:34 +02:00
Alexander Vorwerk
cf748c5978 Throw for mismatched wiki in AbstractBlock::getBy()
Bug: T274817
Change-Id: I0a8c212ab1a5a975d00018a1d069a0a6edced87a
2022-06-16 23:31:18 +02:00
Aryeh Gregor
7b791474a5 Use MainConfigNames instead of string literals, #4
Now largely automated:

VARS=$(grep -o "'[A-Za-z0-9_]*'" includes/MainConfigNames.php | \
  tr "\n" '|' | sed "s/|$/\n/;s/'//g")
sed -i -E "s/'($VARS)'/MainConfigNames::\1/g" \
  $(grep -ERIl "'($VARS)'" includes/)

Then git add -p with lots of error-prone manual checking. Then
semi-manually add all the necessary "use" lines:

vim $(grep -L 'use MediaWiki\\MainConfigNames;' \
  $(git diff --cached --name-only --diff-filter=M HEAD^))

I didn't bother fixing lines that were over 100 characters unless they
were over 120 and triggered phpcs.

Bug: T305805
Change-Id: I74e0ab511abecb276717ad4276a124760a268147
2022-04-26 19:03:37 +03:00
Amir Sarabadani
280c2ed0d3 rdbms: Fold MaintainableDBConnRef into DBConnRef
We really don't need this complexity and it prevents us from improving
connection management.

MaintainableDatabase should stay but the connection ref shouldn't.

Bug: T255493
Change-Id: I867301dc7fa07cac298f8faba9cf82ca4617f50e
2022-04-14 01:57:11 +02:00
Umherirrender
6ea3d6ac2c Add explicit casts between scalar types
php internal functions like floor/round/ceil documented to return
float, most cases the result is used as int, added casts

Found by phan strict checks

Change-Id: I92daeb0f7be8a0566fd9258f66ed3aced9a7b792
2022-03-08 16:59:01 +00:00
Umherirrender
ba2c15abb2 block: Avoid use of null block id and blocker
Use a local variable to allow phan to track the not-null part

Found by phan strict checks

Change-Id: I32e023d3dbd70e987c79527a6936209d62deffcf
2022-02-26 10:35:10 +01:00
Alexander Vorwerk
78b9dc1927 Respect the wiki when performing autoblocks
Currently an autoblock is always inserted into the database of
the local wiki, even if the block is a cross-wiki one. This is
also the one of the issues that caused T281972.

In combination with Icdf9e4f37c3bfa568c712bebceccf9cc46db2ec8
this is going to fix the wrongly performed autoblocks by the
CheckUser extension.

I1051beedfd67c4e2c546b9eec04b6d592d969af3 is still a more clean
solution that this, but since that patch is blocked on T292375,
which is probably not going to be resolved in the near future,
this patch is chosen as a temporary solution.

Bug: T281972
Bug: T284873
Change-Id: I0d42c743ec188b20b636c8ec577d6cf02a7f1059
2022-02-23 21:09:45 +00:00
Alexander Vorwerk
283763c893 DatabaseBlock: assert the blocker to be from the correct wiki
If the wiki to which the blocker belongs does not match the wiki to
which the block belongs, things can go wrong.

Bug: T274817
Change-Id: Iab88ff2106932dffeb8b6da193e5a5e12f686cc3
2022-01-26 00:26:31 +01:00
jenkins-bot
d9e3eadcee Merge "Introduce a BlockRestrictionStoreFactory" 2022-01-25 20:36:39 +00:00
Alexander Vorwerk
dcd112360f Introduce a BlockRestrictionStoreFactory
The BlockRestrictionStoreFactory is a new service which allows fetching
of a wiki-specific BlockRestrictionStore by fetching the correct
LoadBalancer via a LBFactory and then injecting it into the
BlockRestrictionStore.

This is being done as a part of the project of supporting cross-wiki
blocking. Currently if a cross-wiki block with restrictions is being
created, the block is being stored in the foreign database, but the
restrictions are being stored in the local one.

Blocks were made wikiaware in I8ae8133f7e232cc75aae6b72fcd7feaeb313cba7.

Bug: T291983
Change-Id: Ia342030c31710f40c95acc75d3cc76f1ad79d806
2022-01-24 20:17:40 +01:00
Alexander Vorwerk
91a59f1a11 DatabaseBlock: fetch a database connection for the correct wiki
Bug: T274817
Bug: T299655
Co-authored-by: Taavi Väänänen <hi@taavi.wtf>
Change-Id: I99700e9c562635d52f2350703f46f07a39eb349f
2022-01-20 20:23:56 +00:00
Alexander Vorwerk
b6793e47de Make Block objects aware of which wiki they belong to
Bug: T274817
Depends-On: I1c46c712a3afefce56238108cb2e78382dd41956
Change-Id: I8ae8133f7e232cc75aae6b72fcd7feaeb313cba7
2022-01-17 21:49:20 +01:00
TChin
47adb6d65a Refactor global variables to use MediaWikiServices instead
Automatically refactors wg prefixed globals to use MediaWikiServices config using Rector. Doesn't include files that set globals or files that fail CI.

Rector Gist: https://gist.github.com/tchin25/7cc54f6d23aedef010b22e4dfbead228

* This patch uses a modified source code rector library for our specific use case and the rector will have different effects without it.

A writeup for future reference is here: https://meta.wikimedia.org/wiki/User:TChin_(WMF)/Using_Rector_On_MediaWiki

Change-Id: I1a691f01cd82e60bf41207d32501edb4b9835e37
2022-01-10 13:55:53 -05:00
Amir Sarabadani
9bcd3fdfa5 Remove ActionAjax
Bug: T42786
Change-Id: I8bda0c281e1f4abbffbddb80ac74a6d61a034d28
2021-12-01 22:31:30 +01:00
Petr Pchelko
25bb5b296a Cleanup hard-deprecated code in blocks.
Change-Id: I1b3f4a0f072197c6b3dc6c9a80fcb2946aeb6360
2021-10-26 06:44:05 -07:00
Alexander Vorwerk
734b912d55 Only allow UserIdentity in DatabaseBlock::setBlocker()
Passing a string is deprecated since 1.36.

Change-Id: Ia1c5bde0815f860f8671e9acae73c69af0a0f96a
2021-10-04 14:03:29 +00:00
Roman Stolar
4af3d59f24 Remove DatabaseBlock 'byText' and 'by' with user ID
Bug: T283641
Change-Id: I5176b1cb388b9962baae3fb99ce8f677b614c4ae
2021-09-29 17:08:32 +03:00
Alexander Vorwerk
a622cf1229 Hard deprecate DatabaseBlock::purgeExpired()
Cleaning a bit up before doing some refactoring.

Soft-deprecated since 1.36 and unused.

Change-Id: I2c93049e6820afd446d284cf0ba756e26c2e50b3
2021-09-28 20:41:32 +00:00
Umherirrender
220fd020c4 Simplify if-then-else-return statements with explicit true/false
When both branches returns a bool, use the condition as return value

Change-Id: I59416aa021d0ada77d84fda4aaf7def0eea54009
2021-08-17 23:19:04 +02:00
libraryupgrader
5357695270 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0
  The following sniffs now pass and were enabled:
  * Generic.ControlStructures.InlineControlStructure
  * MediaWiki.PHPUnit.AssertCount.NotUsed

npm:
* svgo: 2.3.0 → 2.3.1
  * https://npmjs.com/advisories/1754 (CVE-2021-33587)

Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
2021-07-22 03:36:05 +00:00
Alexander Vorwerk
825ac0232c Convert BlockUtils::parseBlockTarget to UserIdentity
Bug: T286490
Change-Id: Ice96180690828bcf2efd60faf6ad10d64307713d
2021-07-20 22:12:26 +02:00
Matěj Suchánek
90b47f0077 Fix deprecation warnings in DatabaseBlock
The admin should see what is deprecated, not the actual value provided.

Change-Id: Ie09d2124ea40ba460feff7cb846514a89587fac7
2021-06-04 15:44:59 +00:00
Roman Stolar
4613e36b97 Hard deprecated DatabaseBlock options 'byText' and 'by' with user ID
Bug: T283641
Change-Id: Id1444253b26605f4c68b4cbeb61dc2299ed8ac34
2021-06-04 17:33:48 +03:00
jenkins-bot
28c34c539a Merge "Remove DatabaseBlock::forcedUserId feature" 2021-06-02 09:31:35 +00:00
Petr Pchelko
e5083b79ee Drop hard-deprecated and unused DatabaseBlock::chooseBlock
Change-Id: Ifc04faefc590404e30b509850b67073e1b1d64c0
2021-05-25 16:52:05 -07:00