Commit graph

269 commits

Author SHA1 Message Date
Amir Sarabadani
44a6dd21b3 Migrate another major batch to SelectQueryBuilder
I fixed some edge cases in the script that migrates to SQB and it
managed to fix these now.

Bug: T344971
Change-Id: I00cc9a6660d9bd4c64c976121b2121ccd7aae1f0
2023-09-20 13:32:09 +02:00
James D. Forrester
459cbb0494 Namespace remaining 'specialpage' files under \MediaWiki\SpecialPage
SpecialPageFactory is already here, but none of the others were yet.

Bug: T166010
Change-Id: I9689bf0a1ab329625e23669b99f019b96295fffd
2023-09-18 18:23:13 +01:00
Amir Sarabadani
e1b3323312 Migrate calls to wfGetDB() in static methods
wfGetDB() has been deprecated since 1.39 (or more?) and it's better to
inject LBF and call ::getReplicaDatabase() or ::getPrimaryDatabase()
which is not straightforward in classes but for static functions, there
is no way to inject the method so we can simply call
MediaWikiServices::getInstance()->getDBLoadBalancerFactory()

While I was here, I migrated one call to SelectQueryBuilder.

Bug: T330641
Change-Id: Idd2278cef647035dce05a2d461a620e145fe1167
2023-09-05 10:48:31 +02:00
Amir Sarabadani
f4e68e055f Reorg: Move Status to MediaWiki\Status\
This class is used heavily basically everywhere, moving it to Utils
wouldn't make much sense. Also with this change, we can move
StatusValue to MediaWiki\Status as well.

Bug: T321882
Depends-On: I5f89ecf27ce1471a74f31c6018806461781213c3
Change-Id: I04c1dcf5129df437589149f0f3e284974d7c98fa
2023-08-25 15:44:17 +02:00
Amir Sarabadani
e569aedde5 Introduce FileSelectQueryBuilder
So much can be cleaned up with this

Bug: T311866
Change-Id: Ia4d46679c540c731b2ae8da2f8022fd6f5b931a4
2023-08-07 19:05:34 +02:00
jenkins-bot
dc3578a910 Merge "Migrate more calls of Database::select* to SelectQueryBuilder" 2023-07-26 11:21:08 +00:00
Amir Sarabadani
7432b21816 Migrate more calls of Database::select* to SelectQueryBuilder
Using a php parser written on top of ANTLR4, done semi-automatically.

I checked everything and made adjustments.

Bug: T311866
Change-Id: I6150c6909bce8f3dbd745a26380cc0af9d9c547f
2023-07-26 13:01:28 +02:00
jenkins-bot
a2f7b4d792 Merge "revisiondelete: Use correct rev-del constants in Item/List classes" 2023-07-24 19:04:27 +00:00
Umherirrender
9edc925620 revisiondelete: Use correct rev-del constants in Item/List classes
Not use RevisionRecord constants for LogPage or File,
even the number are the same, the context should be the match

Change-Id: Icf50f48fa63144c5ac798e7453faf9cd0a1b706a
2023-07-24 17:30:57 +00:00
thiemowmde
9cc3f1f44b Turn RevDelList::getSuppressBit() into a constant
Not used anywhere else as a method. It really is just a constant.

This goes along with Icf50f48. Can be merged in any order.

Change-Id: I8270df212193c10ad35e0b735cca67b2307e535e
2023-07-24 10:46:23 +02:00
Alexander Vorwerk
d93c9001f4 Migrate more usages of Database::update() to UpdateQueryBuilder
Bug: T330640
Change-Id: I094eea810886b13d832be575d9b9df8f8e4a77ea
2023-06-09 13:36:04 +00:00
Lucas Werkmeister
15f076efca Clean up UpdateQueryBuilder usage
This follows up change I608566700c, which was mainly generated by a
script. Most of the clean up here is fixing cases where it seems the
script for some reason collapsed multi-line arrays into single-line ones
and/or removed spaces after commas. A handful of other improvements are
included too (split merged conditions into ->where()->andWhere(), use
buildComparison()). In RevDelArchiveItem, a comment is restored that I
assume was removed accidentally (perhaps because the script didn’t
expect comments inside the conditions).

Bug: T330640
Change-Id: If27bafb12fdaa05d3dc1ae6da820e1630ae2742e
Follows-Up: I608566700c6d737ee986bf47dda87effc69614d6
2023-06-08 12:50:37 +02:00
Amir Sarabadani
b55c501fe0 Migrate Database::update() to UpdateQueryBuilder
I did this using a script written on top of antlr4 parser so it doesn't
have some clean ups a human would do but it's pretty nice already.

Bug: T330640
Change-Id: I608566700c6d737ee986bf47dda87effc69614d6
2023-06-08 12:34:20 +02:00
Bartosz Dziewoński
6ba47296d9 Fix Phan suppressions related to Title::castFrom*() and friends
There is no way to express that Title::castFromPageIdentity(),
Title::castFromPageReference() and Title::castFromLinkTarget()
can only return null when the parameter is null. We need to add
Phan suppressions or explicit types almost everywhere that these
methods are used with parameters that are known to not be null.

Instead, introduce new methods Title::newFromPageIdentity() and
Title::newFromPageReference() (Title::newFromLinkTarget() already
exists), without the null-coalescing behavior, and use them when
the parameter is not null. This lets static analysis tools, and
humans, easily understand where nulls can't appear.

Do the same with the corresponding TitleFactory methods.

Change the obvious uses of castFrom*() to newFrom*() (if there is
a Phan suppression, a type check, or a method call on the result).

Change-Id: Ida4da75953cf3bca372a40dc88022443109ca0cb
2023-04-22 16:45:09 +02:00
Tim Starling
317b460500 Fix even more PHPStorm inspections (#3)
* Inappropriate @inheritDoc usage. Arguably all @inheritDoc is
  inappropriate but these are the ones PHPStorm flags as misleading
  due to the method not being inherited.
* Doc comment type does not match actual argument/return type.
* I replaced "@return void|never" with "@return void" since never means
  never, it doesn't make sense for it to be conditional. If a method
  can return (even if that is unlikely) then @return contains the type
  that it returns. "@return never" means that there is no such type
  because the method never returns.
* Incomplete/partial/broken doc tags

Change-Id: Ide86bd6d2b44387f37d234c2b059d6fbc42ec962
2023-03-25 00:30:15 +00: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
fa967b49ae Switch some simple use of LoadBalancer to use new LBFactory methods
Bug: T326274
Change-Id: I837f7a7b0fad4353dbd670eec609fedfd0603af1
2023-02-23 01:36:49 +00: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
Umherirrender
5c564886a2 revisiondelete: Reuse LogFormatter::getComment instead of own formatting
Avoid code duplication and
allows to use the new styling if Icfb46d9 (T327538) gets merged

Remove duplication of span.history-deleted on Special:EditTags - before
this change a span.history-deleted element was nested inside another
span.history-deleted element and after this change it is not.

Change-Id: I2e27bd8e0bcca47a7734fcb6ee28c0d1e6bb5896
2023-02-09 22:38:42 +00:00
Umherirrender
e6f4dc96fe revisiondelete: Replace dynamic property Status::$itemStatuses
Creation of dynamic property Status::$itemStatuses is deprecated

Bug: T314099
Change-Id: I5fc1496aa38502143a3511a6a8a110eb9446a2a9
2023-02-04 20:31:11 +00:00
Daimona Eaytoy
c5a01d4b2e Replace some usages of MWException
These exceptions are not documented with @throws and they're really not
meant to be caught.

Bug: T86704
Change-Id: I07f32e42c6fd4bc8785bac91547858f15a9fc2a8
2023-01-26 00:10:34 +00:00
Thiemo Kreuz
df4120903d Remove now unused (bogus) cache key in RevDelRevisionList
Unused since Idbb5a5a.

Note it never worked because of a misplaced } at the end.

Bug: T238374
Change-Id: Ic8759a78d02fb5d3d600443445ba5122d512794b
2023-01-11 10:33:52 +01: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
Umherirrender
6442e5b1cc revisionslists: Replace deprecated Linker::revComment/commentBlock
Bug: T324906
Change-Id: I0db8521f5ea0266a41687c46d7466a97fbc21742
2022-12-11 01:40:43 +01:00
Amir Sarabadani
2d60ba0c63 Reorg: Move DummyLinker and Linker to linker/
This feels like a no-brainer unless I'm missing something obvious

Bug: T321882
Change-Id: Id49c3d0dd6ea4593211048850856b5b8e05a8fb3
2022-12-08 06:38:17 +01:00
Matěj Suchánek
39c7454539 Remove RevDelList::reloadFromMaster
It has been deprecated since 1.37 and it is unused.

Change-Id: I9f6ff3a656637528ad2f76cbd77e6980737e03c3
2022-11-28 21:25:39 +00:00
jenkins-bot
d2499f8ffb Merge "Sort logging table by timestamp and log id" 2022-10-26 10:27:48 +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
Umherirrender
8f3904a20c Sort logging table by timestamp and log id
Sorting on log_id must not give a result in time order,
because maintenance scripts can insert newer ids with older timestamps.
When only sorting for log_timestamp the result is not stable,
because for items with same timestamp the order is not defined.
For Special:Log the same timestamp gives problems on pagination

Bug: T305590
Change-Id: Ic0c2ebd19ee6a8aa570c5a12a92b31008135491c
2022-10-09 14:19:34 +00:00
Umherirrender
a5abaeba10 Call IContextSource::getAuthority instead of IContextSource::getUser
Change to use Authority object where possible
to use the interface instead of implementation

Change-Id: Ia7e9ce2a2f05ef2ae1cf981bf96faf48b04cf58d
2022-06-29 22:22:44 +02:00
Umherirrender
79e5606b7a Show change tags for log entries on Special:RevisionDelete
When revdel/suppress a log entry the change tags should be shown
as shown on Special:Log for the same log entry.

Bug: T109041
Change-Id: Ia2c89869008593ff765f06e61e0186b78539c18c
2022-05-31 19:24:05 +00:00
jenkins-bot
dd8ff26758 Merge "Start clean up of revision_actor_temp table" 2022-05-23 16:54:28 +00:00
Amir Sarabadani
24115a8f4c Start clean up of revision_actor_temp table
It is being dropped in production

Bug: T215466
Change-Id: I66b2cb8653252e720c897351065978119f040ba7
2022-05-23 15:37:42 +00:00
jenkins-bot
4390fe81f2 Merge "revisionlist: Store page identity instead of Title" 2022-05-23 04:16:34 +00:00
Umherirrender
0f954a065a revisionlist: Store page identity instead of Title
The function deprecatePublicPropertyFallback is needed when the
deprecated class property no longer exists.
Just store the PageIdentity and fallback to title if needed.

Change-Id: I48f81e80c3cdd91f34da9d71344660ab5d27bda2
2022-04-16 18:03:08 +02:00
Aryeh Gregor
666ca1bdf3 Use MainConfigNames instead of string literals, #2
This covers all occurrences of /onfig->.*get( '/ in includes/.
Undoubtedly there are still plenty more to go.

Change-Id: I33196c4153437778496f40436bcde399638ac361
2022-04-13 18:55:46 +03:00
Umherirrender
b126dbe3f2 Fix various documentation related to null types
The functions returning null or the class property is set explict null

Found by phan strict checks

Change-Id: I4a271093fb6526564d8083a08249c64cb21f2453
2022-02-26 10:31:24 +01:00
Aaron Schulz
ae2296f88a revisiondelete: make RevDelList use cancelAtomic() instead of rollbackPrimaryChanges
Bug: T297424
Change-Id: Id20d94d0ccc564038a1cd126f6675167929dbd55
2022-02-21 13:15:29 +00:00
C. Scott Ananian
9e033de4f2 Don't double-escape the ellipses in Language::truncateForVisual()
It turns out this gets rid of a bunch of suppressed
"SecurityCheck-DoubleEscaped" that appear to have been accurate
warnings.

There seems to have been some confusion about how ::truncateForVisual()
is supposed to be used; in particular it is to be passed *unescaped*
output, because it is not (generally speaking) safe to truncate
HTML-escaped strings.  The goal of ::truncateForVisual() is to have
a specific number of codepoints in the output for display purposes,
the encoding of those codepoints is not an issue (htmlspecialchars
can be applied to the *return value*.)  If you need a specific number
of *bytes* you should be using ::truncateForDatabase().  If you want
a certain number of *HTML bytes* then the ::truncateHtml() method
is probably what you want.

Slightly refactor some code in RevDelLogItem to avoid a false positive.

Bug: T301205
Bug: T290624
Change-Id: I893362e049aedfa699043fcf27caf4815196f748
2022-02-10 17:09:18 -05:00
jenkins-bot
1351452097 Merge "SECURITY: properly escape output used within galleries and Special:RevisionDelete" 2022-01-10 21:02:29 +00:00
sbassett
29d5d95eaf SECURITY: properly escape output used within galleries and Special:RevisionDelete
* Sanitize $img->getDimensionsString() within TraditionalImageGallery.php

* Sanitize width, height, nbytes messages within RevDelFileItem.php

Bug: T297543
Change-Id: I586a052595ecdc976476d4330510750a59099648
2022-01-10 14:20:48 -06: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
Thiemo Kreuz
b4c63c64ae Remove some more comments that literally repeat the code
Nothing to learn from these.

You can find a longer explanation in the comments in I93751e6.

Change-Id: I195aae70fc282b58be5b18160783f27d38605d15
2021-12-09 19:01:36 +01:00
Matěj Suchánek
50b010e5e8 Don't throw away '0' edit summary
Those "$comment ?? ''" are a bit ugly, but the other way around is
changing the return values of some ::getDescription implementations,
which is dangerous, at least.

Change-Id: I07e6b58258c256d19b058c56280150b70a46b407
2021-11-24 10:33:36 +00:00
Reedy
7bf779524a Remove or replace usages of "sanity"
Bug: T254646
Change-Id: I2b120f0b9c9e1dc1a6c216bfefa3f2463efe1001
2021-11-19 23:19:42 +00:00
Umherirrender
07b499fbcf build: Update mediawiki/mediawiki-phan-config to 0.11.0
Addition and remove of suppression needs to be done with the version
update.

Change-Id: I3288b3cefa744b507eadebb67b8ab08c86517c1c
2021-09-07 17:19:05 +02:00
James D. Forrester
af079ea4c6 RevDelList: Rename reloadFromMaster to reloadFromPrimary
Hard-deprecating immediately as no known users in git outside of this repo.

Bug: T282894
Change-Id: I2a28394b3a5126bad8dbcfe4b0e4665d009132d7
2021-09-03 20:16:18 +00:00
James D. Forrester
10324c232a ILoadBalancer/ILBFactory: Rename rollbackMasterChanges to rollbackPrimaryChanges
Bug: T282894
Change-Id: I31794e052d71160195dd3b6c29fea24bc98b356b
2021-09-02 12:50:52 -07:00
Kunal Mehta
a85f569dd1 Revert "Use CsrfTokenSet as CSRF token source"
This reverts commit 0d75fdb4f7.

Bug: T287542
Change-Id: Iedd3461869f973f8d621a39e6ad4674cbb577551
2021-08-05 15:48:26 -07:00
Umherirrender
ed6fc1dcb4 Replace deprecated CommentStore::getStore in RevDelLogItem
Change-Id: Id47e0fa26f1846be0313288275c903ab073c50bb
2021-08-04 03:26:57 +02:00