Commit graph

203 commits

Author SHA1 Message Date
jenkins-bot
b48017285d Merge "RecentChange: Avoid duplicate patrol log entry after patrol conflict" 2024-03-02 18:03:23 +00:00
xiplus
f7552491c4 RecentChange: Avoid duplicate patrol log entry after patrol conflict
Check the affected rows count to detect a patrol conflict, which is
when the database query succeeds, but it was a no-op because another
request (possibly from the same user, or someone else) marked it as
patrolled already.

We detect it using the `rc_patrolled` condition because without it,
affectedRows() would always return 1, as the previous update condition
could match either the patrolled or patrolled version of the row.

Bug: T196182
Change-Id: I2aa4f2f752a40657883e0a6714dbb175c9d2fdcb
2024-03-02 17:41:16 +00:00
James D. Forrester
060a1b1668 Replace last remaining wfGetDB() calls in core, except ResourceLoader
Bug: T330641
Change-Id: I6d30af6ff9f667e367d39befb80c2bb0bf5fb29e
2024-02-14 11:02:01 -05:00
Amir Sarabadani
ea268ddcfd Move away from wfGetDB() calls
If we are serious about getting rid of wfGetDB(), we should start
replcing callers with proper replacement.

These classes don't have any injection so it doesn't make sense to
introduce it for this specific usecase.

Bug: T330641
Change-Id: I645f67324d441288c63787c7e42390b59106c585
2024-02-12 21:23:38 +01:00
Daimona Eaytoy
7acfa6a0a5 Replace more instances of unchecked MWException
Most (all?) of the remaining usages are caught somewhere and will be
migrated later.

Bug: T328220
Change-Id: I5c36693a5361dd75b4f1e7a0bab5ad48626ed75c
2024-01-23 16:20:53 +00:00
Bartosz Dziewoński
e4c7272976 Change uses of getDBLoadBalancerFactory() to getConnectionProvider()
Update cases where one of the IConnectionProvider methods is called
immediately.

This doesn't really change anything, but I hope it helps promote
getConnectionProvider() as the common way to do this.

Follow-up to 8604c384f6.

Change-Id: Id0e7d02bab0c570343c2b1f03c70b44ee39db112
2024-01-22 22:27:45 +01:00
Dogu
f73d342b29 Replace deprecated MWException with InvalidArgumentException
Change-Id: I14391c156f66e9686f82b93d55e0bbcd951f8057
2024-01-07 06:18:13 +00:00
James D. Forrester
67217d08df Namespace remaining files under includes/deferred
Bug: T166010
Change-Id: Ibd40734b96fd2900e3ce12239d09becfb4150059
2023-11-22 10:08:53 -05:00
Amir Sarabadani
2e1cd74ad2 Migrate off wfGetDB() in more places to ICP
This function is uber-deprecated, meaning even its replacement is
deprecated, We have already migrated in static functions and more.

In this batch, all calls have been migrated that there is already a call
to MediaWikiServices::getInstance() making the migration easier. Of
course in most cases, they should eventually turn into proper service
injection but this at least makes it clear what services should be
injected.

Also removing "category" group since we are removing all groups except a
handful from mw (see T263127 for more information).

Bug: T330641
Change-Id: I90cd35ee45a37eb6e6bf7a531cc8f75effbd0328
2023-11-20 14:40:28 +01:00
Amir Sarabadani
136fa38a4a Migrate to IConnectionProvider methods in more places
Getting rid of uber-deprecated wfGetDb() and recently deprecated
LB::getConnection.

Bug: T330641
Change-Id: Ifd4b4e01f2a120ad6db517cc8fd2eb6b11b72bc9
2023-10-05 19:51:20 +02:00
James D. Forrester
98f50660cb Drop RecentChange::getPerformer(), deprecated since 1.36
Change-Id: I10cd61f6088da3069d7e29e5fe4355747e83236e
2023-09-27 22:41:21 +00:00
James D. Forrester
c1599c91b3 Namespace Config-related classes under \MediaWiki\Config
Bug: T166010
Change-Id: I4066885a7ea071d22497abcdb3f95e73e154d08c
2023-09-21 05:41:58 +00:00
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
Daimona Eaytoy
f78fd3710d Add $wgRequest to phan's globals_type_map
The base phan config uses a file_exists check to determine whether to
use the namespaced class name, but it doesn't work when running against
core because MW_INSTALL_PATH isn't set. So specify the type in the local
config, and remove @phan-var annotations added in I6bbdbbe6.

Also use `::class` instead of string literals for classes.

Change-Id: I994a0ed32ea948253ed07ee3cc8868a0eaa6d8b9
2023-09-11 23:22:12 +02:00
Amir Sarabadani
5bd33d46ef Reorg: Move WebRequest to includes\Request
This has been approved as part of RFC T166010

Bug: T321882
Change-Id: I6bbdbbe6ea48cc1f50bc568bb8780fc7c5361a6f
2023-09-11 21:44:34 +01:00
Tim Starling
95bd40b25c In query builders, use insertInto() and deleteFrom() instead of insert() and delete()
The design principle for SelectQueryBuilder was to make the chained
builder calls look as much like SQL as possible, so that developers
could leverage their knowledge of SQL to understand what the query
builder is doing.

That's why SelectQueryBuilder::select() takes a list of fields, and by
the same principle, it makes sense for UpdateQueryBuilder::update() to
take a table. However with "insert" and "delete", the SQL designers
chose to add prepositions "into" and "from", and I think it makes sense
to follow that here.

In terms of natural language, we update a table, but we don't delete a
table, or insert a table. We delete rows from a table, or insert rows
into a table. The table is not the object of the verb.

So, add insertInto() as an alias for insert(), and add deleteFrom() as
an alias for delete(). Use the new methods in MW core callers where
PHPStorm knows the type.

Change-Id: Idb327a54a57a0fb2288ea067472c1e9727016000
2023-09-08 10:16:08 +10: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
James D. Forrester
e7ff62ea22 RecentChange: Drop getEngine(), deprecated since 1.29
Change-Id: Iad19dc62c4a06ccdb553ed11b3390679c761e17e
2023-08-23 17:31:01 -04:00
Amir Sarabadani
15a278189f Reorg: Move MWTimestamp to MediaWiki\Utils
Bug: T321882
Change-Id: I48c10343295c4eb3d9ef8037343b0070e928f040
2023-08-19 05:53:40 +02:00
Amir Sarabadani
98d6503f65 Mass migrate Database::insert calls to InsertQueryBuilder
Done automatically based on a php parser written on top of ANTLR4

Bug: T335377
Change-Id: Ie8fabc594edab18e55cb1d5bbf573762106e3d71
2023-08-07 19:44:27 +02:00
Daimona Eaytoy
8adf1bfb93 Replace some more usages of deprecated MWException
Bug: T328220
Change-Id: I3c36835fbd90acc301731e2b33ae4815cd4b0cc5
2023-06-09 02:07:08 +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
Timo Tijhof
34dc4e6d26 rcfeed: Add 'notify_url' and 'title_url' to MachineReadableRCFeedFormatter
* Move the current URL logic from IRCColourfulRCFeedFormatter
  to a new method RecentChange::getNotifyUrl (covered by tests now).

* Re-use this method in MachineReadableRCFeedFormatter so that
  the diff/patrol/rcid etc URL is also available in the modern
  JSON-based EventStreams service. And in particular to allow
  porting of the legacy irc.wikimedia.org backend to a much simpler
  one that is based on this.

* Also expose a title_url field which was previously missing,
  and made consumption of the data needlessly difficult.

Bug: T234234
Depends-On: Id740134ef30b2276688d7b7caedb6bb652158761
Change-Id: Ic3e0aebdb61b5c0e5fbed08656db4a1e90b67518
2023-05-19 15:48:40 +03: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
Matěj Suchánek
94d080d305 Allow marking recent changes about logged actions with bot flag
There was no clean way to do this but using the global state.

The parameter is three-state to keep backward compatibility.

Bug: T304428
Change-Id: I01c5f8e9646cbe861516100c3b8d165aefb95ca0
2023-03-13 01:59:35 +01: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
Timo Tijhof
b765222915 watchlist: Re-centralise former wgUseEnotif condition
Follows-up I9bfa502a0b (9b8f153f). Also document the reason for
this logic, to the best of my knowledge, and some ideas to improve
it.

Bug: T305093
Change-Id: I4c5bf4d4da83ff1e03d0fe0dd9891507b1f1e455
2023-02-02 08:48:50 +00:00
Matěj Suchánek
03fe1078cf Select recent changes for deletion only by page id
The problem this patch fixes:

- Step 1: Move an existing page A to a new title B.
- Step 2: Delete the redirect at the old title A.
- What happened: All the edits made to the page prior to the move
  are gone from recent changes.
- What should have happened: all the edits made to the page prior
  to the move are still in recent changes under the (now redlinked)
  title A.

Contrary to that, moving a page with redirect suppression would
preserve the changes.

Bug: T140960
Bug: T307865
Change-Id: Ib52a9c657620275388012a778bc9d839dd740624
2023-02-01 10:40:30 +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
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
Matěj Suchánek
fa045ecdde Suppress RecentChange::doMarkPatrolled when autopatrol is requested
The result of the method has been inappropriate and
surprising since rc_patrolled was changed to distinguish
between manually patrolled and autopatrolled changes
(T184791).

When called with $auto = true, it would mark the change
as manually patrolled (not autopatrolled), but it would
not log it as such in patrol log and would still require
'autopatrol' right (not 'patrol').

Change-Id: I0bd6f2cf317d2b1c8dd50b7998724a57f5f549fb
2022-12-03 17:16:50 +00:00
Brian Wolff
6bbdd06080 Coalesce rc comment field to empty string if null
Follow up to I14c6c22d822ae4

Fixes a warning on php 8.1 where the comment on log entries
might be null.

Change-Id: If0e41f0696a24a56f112e05c46a9a7fdbfaa3aaa
2022-09-12 19:13:43 -07:00
Umherirrender
9b8f153fb8 Setup: Remove internal short-cut config $wgUseEnotif
It is not possible to set $wgUseEnotif on LocalSettings.php,
because it is always set on setup, it should not be a global/setting.
Just remove it from the dynamic setup and use the config it is set from

Bug: T305093
Change-Id: I9bfa502a0b9798bd149b4cfe4db86a0461e76f55
2022-08-17 23:41:30 +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
Umherirrender
7f08635b13 recentchanges: Remove special handling of rc_ip for postgres
The special type of the column was changed in 6809067

Change-Id: I308df77f3ab39ddddf6219e6c292ab50ec4bbc22
2022-07-16 12:30:57 +02:00
Amir Sarabadani
f24eb94571 RecentChange: Make join to comment table also straight
The optimizer is refusing to pick the right join order

Bug: T311360
Change-Id: I742201b45975a5edcac5d4634d70d50ee851f0ac
2022-06-30 23:38:30 +02:00
Amir Sarabadani
478d604216 RecentChange: Straight join to actor table when needed
It should avoid using straight join when there is a condition on the
actor table which potentionally could make the query faster.

Bug: T311360
Change-Id: Iad3d0cf2479c560be255f85d8896f37efae606c5
2022-06-30 18:17:38 +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
Timo Tijhof
f8ecea1e5c rcfeed: Deprecate $wgRCEngines and RCFeedEngine
Follows-up 39a6e3dc4d (I8be497c623c5d92).

* Improve documentation all around and advertise 'class'
  everywhere instead of 'uri'.

* Add test coverage for RCFeed::factory().

* Deprecate the $wgRCEngines "uri to class" mapping in favour
  of specifying "class" directly in $wgRCFeeds.

* Deprecate RCFeedEngine in favour of FormattedRCFeed.
  Convert to class_alias so that UDPRCFeedEngine no longer has
  to extend the deprecated class name explicitly (for instanceof compat).

* Hard-deprecate RecentChange::getEngine.

Bug: T250628
Depends-On: Ie939e1d06b9ee2d841ec7256c8d24cc4e7e386dd
Change-Id: Ib6758d724c7200404c89c7ab157aa55f1cad9763
2022-03-08 19:50:19 +00:00
Reedy
86934b2fa8 Replace some more usages of Wikimedia\(suppress|restore)Warnings()
Change-Id: I2eb133a9e32116cd155f59086245bc4d15ecbfcc
2022-02-24 20:27:46 +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
Umherirrender
68808e5832 Replace deprecated JobQueueGroup::singleton()
Change-Id: Icdb301d352d302f70fefba9b40df2368cb217fd2
2022-01-27 21:37:50 +01:00
Umherirrender
95852cb22b Explicit cast TS_UNIX to int for arithmetic operations and int args
When the called function has a doc of int, it should be cast to be
explicit here.
Also cast for arithmetic operations to be explicit about the number

Change-Id: I905b78dfb66e66443e0e3203488bab5b548db543
2022-01-11 20:13:13 +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
vladshapik
9b92c1088f Drop User methods which were deprecated since 1.35
The following User methods, deprecated in 1.35, have been removed:
  - ::isIP,
  - ::isIPRange,
  - ::isValidUserName,
  - ::isUsableName,
  - ::isCreatableName,
  - ::getCanonicalName,
  - ::addAutopromoteOnceGroups,
  - ::getDefaultOptions,
  - ::getDefaultOption,
  - ::getOptions,
  - ::getBoolOption,
  - ::getIntOption,
  - ::setOption
  - ::listOptionKinds
  - ::getOptionKinds,
  - ::resetOptions,
  - ::getEffectiveGroups,
  - ::getAutomaticGroups,
  - ::getFormerGroups
User::GETOPTIONS_EXCLUDE_DEFAULTS has been removed, since it is used only in the description of User::getOptions.

Bug: T277511
Depends-On: Ida05c22f81b30d9b46678e8ede3d531c38855d83
Change-Id: I72bbc2336f8ddbc66ce67226cd2d5baaa2f807d8
2021-11-12 15:35:50 +02: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
Thiemo Kreuz
2ba01c7ee7 Remove some more comments that literally repeat the code
… including PHPDoc tags like `@return <type> $variableName`.
A return value doesn't have a variable name. I can see that
some people do this intentionally, repeating the variable
name that was used in the final `return $var;` at the end
of a method. This can indeed be helpful. I leave a lot of
these untouched and removed them only when it's obviously
wrong, or does not provide any additional information in
addition to what the code already says.

Change-Id: Ia18cd9f25ef658b08ad25b97a744897e2a8deffc
2021-06-18 21:23:56 +00:00
Roman Stolar
e221991e86 Hard deprecate RecentChange::getPerformer()
Added deprecation warning

Bug: T276412
Change-Id: I642a2903f7a1d6861dd5e50e8754980adc937c53
2021-06-02 11:29:06 +03:00