Commit graph

804 commits

Author SHA1 Message Date
Dreamy Jazz
d6ac3dac74 Catch exceptions from ::isWriteMode in ApiMain::sendCacheHeaders
Why:
* Modules that extend ApiQueryBase are loaded using the ApiQuery
  module. This defines an override to the ApiBase::isWriteMode
  method that loads the modules.
* Using the mModule when $isError is true could lead to the
  exception that was thrown in ::executeAction being thrown again.
* Therefore, ApiMain::sendCacheHeaders should only call the
  ApiBase::isWriteMode method if the request did not fail
  with an error that caused $isError to be true.
* Without this fix, ApiUsageExceptions appear in logstash as
  exceptions, as described in T363133.

What:
* Only interact with $this->mModule if the $isError argument
  is false. If $isError is true, assume that ::isWriteMode
  would return true. Assuming this will also avoid error
  responses being marked as fresh for any amount of time, as
  the error may be temporary.
* Add a test that verifies that the method does not throw if
  ApiBase::isWriteMode throws an ApiUsageException.

Bug: T363133
Change-Id: I41d869c257878b8a94d6c40332e2028405de8729
2024-04-23 21:15:23 +01:00
Taavi Väänänen
9cb7cd443c
Use ignore comments for MediaWiki.Usage.ExtendClassUsage.FunctionVarUsage
Instead of globally ignoring this sniff, convert the current violations
(which set the variable so can't be fixed easily yet) to use local phpcs
comments to silence the errors.

Change-Id: I490cbf4915e2705383edb4a2fc5ddc1efd55c960
2024-04-22 14:17:02 +03:00
Dreamy Jazz
4ac2533470 Update help text for 'hideanons' in ApiFeedRecentChanges API
Why:
* Since 1941f28f60, the
  recentchangesfeed API (ApiFeedRecentChanges) has treated
  temporary accounts as being anon users for the purposes of the
  'hideanons' parameter.
* However, the help text does not describe that temporary accounts
  are treated in this way and as such the help text needs to be
  modified depending on whether temporary accounts are enabled.

What:
* Add 'apihelp-feedrecentchanges-param-hideanons-temp' as a i18n
  message which duplicates the existing 'apihelp-feedrecentchanges
  -param-hideanons' but includes temporary accounts.
* Update ApiFeedRecentChanges::getAllowedParams to use the new
  message if TempUserConfig::isEnabled returns true.
* Add the TempUserConfig as a injected dependency for
  ApiFeedRecentChanges.
* Add an integration test to verify that the correct help message
  is used for the 'hideanons' parameter in ApiFeedRecentChanges.

Bug: T358249
Change-Id: I516c1a563a81777217cda998efaeda7967dd224d
2024-02-22 17:20:28 +00:00
James D. Forrester
102a4f8a35 build: Upgrade mediawiki/mediawiki-phan-config from 0.13.0 to 0.14.0 manually
* Switch out raw Exceptions, mostly for InvalidArgumentExceptions.
  * Fake exceptions triggered to give Monolog a backtrace are for
    some reason "traditionally" RuntimeExceptions, instead, so we
    continue to use that pattern in remaining locations.
* Just entirely give up on PostgresResultWrapper's resource vs. object mess.
* Drop now-unneeded false positive hits.

Change-Id: Id183ab60994cd9c6dc80401d4ce4de0ddf2b3da0
2024-02-10 02:22:41 +00:00
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
jenkins-bot
ff6e1e50e9 Merge "ApiMain: Remove fallback IDs for headings in generated doc" 2024-02-07 18:29:12 +00:00
Bartosz Dziewoński
4b1bbe2803 ApiMain: Remove fallback IDs for headings in generated doc
This adds significant complexity and provides very little value.
As far as I can tell, we've never linked to those IDs. Other headings
in generated documentation don't have fallback IDs (in ApiHelp).

I'm mostly doing this because I want to deprecate and remove
Linker::makeHeadline(), which is a function with really silly
parameters that grew out of a regexp replacement callback in
Parser.php, and which – except for these usages I'm removing
– is only used there.

Change-Id: If793f5023fca744f109f5a1f0f0ad3857375db8c
2024-02-06 15:06:28 +01:00
daniel
d79af914ff Move code from api.php into ApiEntryPoint class
The goal is to unify the high level control flow in entry points by
making them use a shared base class. Eventually, this will allow
us to test all aspects of request handling, including response
headers and output buffer handling. That will however require
us to move quite a bit of logic from ApiMain into ApiEntryPoint.

Bug: T354216
Change-Id: I4ea1cbb8b2786c24deade7d5029d95fe0c2abc57
2024-02-02 19:27:53 +00:00
Umherirrender
9b0591448e Use UserFactory::newAnonymous
Bug: T325686
Change-Id: Ia7ce7df94c233a4534625d250229806fb21d8017
2024-01-22 20:39:05 +00:00
Cole White
a3a6d2bfd0 ApiMain, ApiQuery: update stats to generate StatsFactory metrics
Bug: T350592
Change-Id: I12681e3d069bdcaf184952d692d36bf71697e4d8
2024-01-17 16:02:43 +00:00
daniel
70bd080bba API: mark HTML output as non-cacheable
When we format API output as HTML, that HTML may contain user secrets
and should not be cacheable, even if the API output would ordinarily be
cacheable.

Bug: T354045
Change-Id: I94fe5f7bfae580e8bda8af1971b9448db8201c22
2024-01-12 00:30:32 +01:00
Thalia
beff37ce18 Add 'temp' to allowed user types in various APIs
Why:

* Before this task, when an API parameter specifies allowed user
  types, temporary users and permanent users are in the same
  category: 'name'.
* However, it is useful to separate them out, and sometimes
  allow a permanent user but not a temporary user (e.g.
  ApiResetPassword, since temporary users don't have passwords).
* We therefore re-defined the 'name' type only to refer to
  permanent (named) users, and add a new 'temp' type.
* This fixes params that currently intend to allow temp users,
  and that use 'name' to do so, by adding 'temp'.

What:

* Based on a search for `UserDef::PARAM_ALLOWED_USER_TYPES`,
  add the 'temp' type where necessary.
* The following were not updated, because they shouldn't apply
  to temporary users:
  - owners for includes/api/ApiQueryWatchlist.php,
    includes/api/ApiQueryWatchlistRaw.php
  - users for includes/api/ApiResetPassword.php,
    includes/api/ApiUserrights.php,
    includes/api/ApiValidatePassword.php

Bug: T350701
Change-Id: If5ccf1d469327791acff74d013343307e411cca9
2023-11-30 14:19:40 +00:00
Derick Alangi
0ee08d6616 Request: Deprecate methods in WebRequest class
Deprecated methods are:
* WebRequest::isSafeRequest()
* WebRequest::markAsSafeRequest()

Introduced in I43f4bc06c19d823d7d1f (549af8bf) and used in
I01ae2f045726208d2af7 (ce3a25be), then later removed in I4eb10817cccb40aa255
(e34fd634) which became unused in core.

As a result, it made markAsSafeRequest useless as there is really no
consumer at this point.

No known usage (confirmation) per our code search tool today. See below:
https://codesearch.wmcloud.org/search/?q=isSafeRequest&files=&excludeFiles=&repos=

Change-Id: I39cfb04c46374153d374fe0bb88690fa48ad7250
2023-10-03 11:31:03 +00:00
James D. Forrester
468e69bccc Namespace Sanitizer under \MediaWiki\Parser
Bug: T166010
Change-Id: Id13dcbf7a0372017495958dbc4f601f40c122508
2023-09-21 05:39:23 +00:00
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00: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
jenkins-bot
bbfa65643f Merge "ArchivedRevisionLookup: Allow lookups using just the revision ID" 2023-09-06 18:43:32 +00:00
Alexander Vorwerk
b0adbad624 ApiMain: Do not allow negative max age
Bug: T345544
Change-Id: I79b8bc8204871ef629b302cc870c9a22f60883f7
2023-09-04 10:05:36 +00:00
Bartosz Dziewoński
2911de600f ArchivedRevisionLookup: Allow lookups using just the revision ID
A unique index on ar_rev_id was added in T193180 (2019), allowing
revisions of deleted pages to be reliably looked up by just their ID.

Use the improved getArchivedRevisionRecord() method in a few places
that previously had to use manual queries.

Bug: T251066
Change-Id: I9352f64952ac4b803d76e9e72f88a01be7317c56
2023-09-02 01:56:20 +00:00
Umherirrender
778d266c2e api: Use ParserFactory on module creation
Change "Parser" to "ParserFactory" in object specs
and get a instance when needed

Bug: T343070
Change-Id: I9b65c272726bb0035f4cdca4fbf417a0a11375cb
2023-08-29 20:19:32 +02:00
jenkins-bot
22489ac99c Merge "Remove deprecated ActorMigration usages around ContribsPager" 2023-08-26 12:34:05 +00:00
Umherirrender
bb53f71076 api: Add watch option for userpage to action=userrights
Bug: T272294
Change-Id: I8078bb4a2f5cc2e45e8eb7a8ab29a71f5edb5ba8
2023-08-25 19:42:39 +00:00
Func
596ea5eacb Remove deprecated ActorMigration usages around ContribsPager
Change-Id: I1a4224eac8bad47f7228faf68ea7f9c7d44a44ad
2023-08-25 17:43:44 +08:00
Amir Sarabadani
15a278189f Reorg: Move MWTimestamp to MediaWiki\Utils
Bug: T321882
Change-Id: I48c10343295c4eb3d9ef8037343b0070e928f040
2023-08-19 05:53:40 +02:00
Bartosz Dziewoński
6ac1c4789d ApiEditPage: Check permissions of the temp user if we will create one
Bug: T342770
Change-Id: I024c79551ca9d67e4e7e91cce028b25718141232
2023-08-08 20:26:10 +02:00
Bartosz Dziewo?ski
ccbd669d83 Acquire a temporary user username before previewing
* Add an API action=acquiretempusername
* Add a mw.config variable with the temp user name
* Add mw.user.acquireTempUserName, which checks the mw.config
  variable, then fetches a name from the API
* Use mw.user.acquireTempUserName when previewing

Bug: T331397
Change-Id: Iec8a15dadd595bed0f7e54f907fbb8e192b45cf3
2023-07-31 10:48:20 +02:00
Umherirrender
e77a022350 api: Replace deprecated ApiPageSet::getRedirectTitles in action=parse
Bug: T339384
Change-Id: Iabcaf55723118660648472047e0fd1f7cee56a50
2023-06-27 19:42:35 +02:00
jenkins-bot
3ae994553e Merge "api: Replace deprecated ApiPageSet::getGoodPages in action=query" 2023-06-26 20:52:31 +00:00
jenkins-bot
a7e796fb0f Merge "api: Replace deprecated ApiPageSet::getMissingTitles in action=watch" 2023-06-26 20:52:23 +00:00
jenkins-bot
b2691d5041 Merge "api: Replace ApiPageSet::getTitles in setnotificationtimestamp" 2023-06-26 19:40:13 +00:00
jenkins-bot
91ad3ce732 Merge "api: Replace deprecated ApiPageSet::getTitles in imagerotate" 2023-06-26 19:40:05 +00:00
James D. Forrester
83d72bc108 API: Replace deprecated calls to wfExpandUrl with UrlUtils::expand
Bug: T319340
Change-Id: Ic987f9381ac17e9e46504abdb2d07a5a94ba3b4a
2023-06-22 16:49:01 -04:00
Umherirrender
46b5580f4f api: Replace deprecated ApiPageSet::getGoodPages in action=query
Inject TitleFormatter and TitleFactory to improve the best case
(getGoodPages) to avoid calling the factory there instead of using
Title::getPrefixedText after calling factory

Bug: T339384
Change-Id: I21cf9b738cfdb1a418c10e48ec834efefccb6ab7
2023-06-16 22:38:33 +02:00
Umherirrender
e6cc82cf56 api: Replace ApiPageSet::getTitles in setnotificationtimestamp
Reduce creating of Title objects to minimum place and use the
TitleFormatter instead. Getting the known state may moved to own
service.

Bug: T339384
Change-Id: I712c5abe426940a4dd1c3b384e356845175c0ae3
2023-06-16 22:15:19 +02:00
Umherirrender
3ebec136eb api: Replace deprecated ApiPageSet::getMissingTitles in action=watch
Bug: T339384
Change-Id: I6ca0620f943557e9cc977c4b22f27975295b0811
2023-06-16 22:11:12 +02:00
Umherirrender
ac28aba62a api: Replace deprecated ApiPageSet::getTitles in imagerotate
Bug: T339384
Change-Id: I3b151ab81dd129a9f5642d76f35240a2ecd78f74
2023-06-16 20:09:36 +00:00
thiemowmde
9b03cde58e Merge sequences of if that end doing the same thing anyway
Motivation:
* Avoid code duplication.
* Hopefully make it easier to read.
* Also order stuff from cheap to expensive, if possible.

Change-Id: I575e3f2027ce60a0d0885be5b9bd3e07bc035eee
2023-06-16 16:09:42 +02:00
jenkins-bot
b616ceffcb Merge "Start using ChangeTagsStore" 2023-06-09 17:39:53 +00:00
Amir Sarabadani
a5dac5d598 Start using ChangeTagsStore
Also some clean ups here and there

Bug: T245964
Change-Id: Ibf20eec3257a2dc54e3ccbe766b679ebdfbab8d9
2023-06-09 15:09:06 +02:00
Daimona Eaytoy
0d29958cc1 Replace more usages of deprecated MWException
Bug: T328220
Change-Id: Ib619ead0f397188d828e6e5dfc80ed1fa7175c7d
2023-06-08 21:37:07 +00:00
Amir Sarabadani
1ff0188dbf api: Drop ApiQuery::getNamedDB() and ApiQueryBase::selectNamedDB()
Both deprecated in 1.39 and hard-deprecated. Unused in production and
allow us to clean up dependency of ApiQuery to LB.

Depends-On: Ia94618b7f58fcca72e903fd2e2e9f0aaa501ac24
Change-Id: Ie0322e5346b94932a2eddc0b7aad5a384768b888
2023-06-01 11:11:58 +00:00
jenkins-bot
62dcbdc6ab Merge "api: Use a temp placeholder for signature on preview/pst" 2023-05-10 05:32:25 +00:00
Umherirrender
65f04c763a api: Use a temp placeholder for signature on preview/pst
For pst on parse/compare/editstash/(all)revisions/(all)deletedrevisions

Do not show the IP when IP masking is enabled,
instead show a previous aquired temp name or a placeholder on preview.
MediaWiki itself used this for the ajax preview on GUI's action=edit

Cannot acquire a new unsaved temp user as api parse does not persist
the global session (each request results in a new id)
and it would require a db write on a read request.

Bug: T331397
Change-Id: I74bb4d655f371bd99e3b618d1a0ac45d730c746c
2023-05-04 20:52:40 +02:00
Amir Sarabadani
d7c8a0648f api: Switch to use IConnectionProvider
As much as possible

Bug: T330641
Change-Id: Icb943d6d65b210760ba8966419327c9603e768e0
2023-04-24 13:54:27 +02:00
Amir Sarabadani
830c51f0a2 Specials: Mass switch everything to IConnectionProvider from LB
Bug: T330641
Change-Id: Ie1772da59f92213fea598f02385c3e0ac6d200a7
2023-04-19 19:19:16 +02:00
Subramanya Sastry
05535be6a8 Ensure ApiHelp correctly types values in TOCData objects
* Broken since 153a415742

Bug: T334551
Change-Id: Id46ba8096beb29d4ece35a6c41b94237e5d9fe1e
2023-04-12 10:26:26 -05:00
Tim Starling
d36ea70309 Fix some PHPStorm inspections (#1)
* Triple backslash in regex should really be quadruple backslash
* Using the returned value of a void method
* Immediately overwritten array keys
* Duplicate array keys
* Foreach variable reuse
* sprintf() with too many params
* Incorrect reference usage

Change-Id: I3c649b543c9561a1614058c50f3847f663ff04df
2023-03-25 00:19:33 +00:00
Aaron Schulz
29bab859fc profiler: Add ProfilingContext class
Use this class to track the entry point and handler used for requests,
making it available for use in profiling, stats, and logging code.

This makes it possible for periodic and/or shutdown profiling callbacks
to know the basic action handler that applies to the request (if any).
Metric names can easily include this string along with MW_ENTRY_POINT
to create per-action profiling dashboards.

This info cannot otherwise be acquired from things like excimer stack
traces since the router and handler classes do not appear in the stack
during PRESEND deferred updates and variations like ApiMain/SpecialPage
"inclusion mode" would have to be detected somehow.

Bug: T330810
Change-Id: Icca5a7a343faeeb18652994c96752acb61a61fd1
2023-03-23 00:08:49 +00:00
Umherirrender
14f3cb2b17 api: Add watch option for userpage to action=unblock
Bug: T257662
Change-Id: I73e26bb97a16579a76ea8dc992157d8180193f27
2023-03-08 22:49:55 +01:00
Amir Sarabadani
4bb2886562 Reorg: Migrate WikiMap to WikiMap/ out of includes
And WikiReference

Bug: T321882
Change-Id: I60cf4b9ef02b9d58118caa39172677ddfe03d787
2023-02-27 05:19:46 +01:00