Commit graph

822 commits

Author SHA1 Message Date
Umherirrender
be1c33e05e api: Check for post_max_size on api requests
php documentation:
If the size of post data is greater than post_max_size, the $_POST and
$_FILES superglobals are empty.

When the action= and format= are not in the GET data,
the help page is returned in html, breaking the clients expected format.

Return api error with http status 413

Bug: T291754
Change-Id: I5906fb6b4412b161b198df0b51e2476e7e1079b8
2024-10-17 18:22:41 +00:00
Umherirrender
e662614f95 Use explicit nullable type on parameter arguments
Implicitly marking parameter $... as nullable is deprecated in php8.4,
the explicit nullable type must be used instead

Created with autofix from Ide15839e98a6229c22584d1c1c88c690982e1d7a

Break one long line in SpecialPage.php

Bug: T376276
Change-Id: I807257b2ba1ab2744ab74d9572c9c3d3ac2a968e
2024-10-16 20:58:33 +02:00
Fomafix
9208216d6b WebRequest: Deprecate parameter $default in getRawVal
Use
	$request->getRawVal( 'key' ) ?? 'default'
instead of
	$request->getRawVal( 'key', 'default' )

The ?? is more flexible, avoids a wrong type detection by phan and
avoids the evaluation of the default value if not needed.

Bug: T376245
Depends-On: I3ed6b85c0d117ed7cb3a8b79f73a3eb42977891e
Change-Id: I8b02f9297b76d04e21f8cb9194f3b85631956eca
2024-10-03 15:49:33 +00:00
James D. Forrester
984076f98e Add namespace to includes/api classes
Bug: T353458
Change-Id: I3ea6b08c5018ba03ba45c5766e1f46e12f6b8597
2024-09-25 19:31:14 +00:00
jenkins-bot
c8d4728813 Merge "api: Add missing documentation to class properties" 2024-09-12 23:20:10 +00:00
Aaron Schulz
e63f87b0dc editstash: migrate ApiStashEdit to statslib
Bug: T359465
Change-Id: Id5aa4000e8b8bbb13b0ccd4d7cdf8bb355963ad7
2024-09-09 09:39:16 -07:00
Ebrahim Byagowi
7db85051f8 Avoid use of deprecated wfParseUrl in MediaWiki\Api
Change-Id: Idd0f98ccb449735b5244bb7531327be763daceb8
2024-09-08 21:15:44 +03:30
Umherirrender
3fca49a1f4 api: Add missing documentation to class properties
Add doc-typehints to class properties found by the PropertyDocumentation
sniff to improve the documentation.

Once the sniff is enabled it avoids that new code is missing type
declarations. This is focused on documentation and does not change code.

Change-Id: I8b33b5f4d91c1935228e7010327dbc6ce138fc00
2024-09-07 22:22:13 +02:00
Larissa Gaulia
3bd0435eaa rdbms: Migrate MediaWiki.rdbms_trxprofiler_warnings to statslib
* Remove StatsdAwareInterface
 * Remove setStatsdDataFactory()
 * Add setStatsFactory()
 * Migrate api and action setStatsdDataFactory() usage.

Bug: T359366
Change-Id: Ic4e82c24d3b1cdca638b22885902cc441d8510b8
2024-09-07 19:18:11 +00:00
Aaron Schulz
1e138c9340 api: make ApiMain::getUserAgent() only use api-user-agent when set
This avoids data bloat in feature usage logging and tracking,
reducing the chance of truncation, and makes it easier to search
these records.

Note that all uses of this method are tied to deprecated API
feature use reporting.

Bug: T313731
Change-Id: Ie097ad21959fbcedc33da407145a7aad573a361e
2024-08-30 00:38:29 +00:00
Reedy
b52a8addf5 Drop writeapi userright
Bug: T294397
Depends-On: Ib34228a18917e404517d45e539bd786419d9c401
Change-Id: Ifad2edc782b36d21c8c67fecde7f011dce02c11b
2024-07-31 11:10:50 +00:00
Bartosz Dziewoński
c9f73efd5a Namespace MessageSpecifier under Wikimedia\Message\
In change I625a48a6ecd3fad5c2ed76b23343a0fef91e1b83 I am planning to
make Wikimedia\Message\MessageValue use it, and we try to pretend that
it is a library separate from MediaWiki, so it makes sense to move
MessageSpecifier to the same namespace under Wikimedia\.

Bug: T353458
Change-Id: I9ff4ff7beb098b60c92f564591937c7d789c6684
2024-07-28 14:21:32 +02:00
Umherirrender
7ba9818e07 api: Use namespaced classes
Changes to the use statements done automatically via script

Change-Id: Icc5b59f9ef6319d1fb785fcda17f43c94f94cc38
2024-06-14 21:38:40 +00:00
WMDE-Fisch
f089276e0f Replace deprecated status->getErrors calls in API classes
Change-Id: I770a98e7cc3e2bc78e363dd73439ab8b8599e0da
2024-06-13 13:27:01 +02:00
Bartosz Dziewoński
cfcfe299e2 Use StatusValue::getMessages() instead of deprecated methods
This commit replaces some of the uses of getErrorsArray(),
getWarningsArray(), getErrorsByType(), and getErrors().
In many cases the code becomes shorter and clearer.
Follow-up to Ibc4ce11594cf36ce7b2495d2636ee080d3443b04.

Change-Id: Id0ebeac26ae62231edb48458dbd2e13ddcbd0a9e
2024-05-18 14:45:54 +00:00
Lewis Cawte
76fa952f2d Refactor ApiEmailUser to use EmailUser/EmailUserFactory classes.
Removes usage of various deprecated SpecialEmailUser classes.

Bug: T362636
Change-Id: Ieb71a3741348ca9dae8c5bf32e891fee458ed5b2
2024-05-04 23:15:03 +00:00
addshore
c25d3f6bea Remove unused TitleParser in ApiFeedContributions
Change-Id: I0c57684b30365b9e5e3f2346bd342122c9d45309
2024-05-04 14:40:20 +00:00
Amir Sarabadani
214674d6b1 namespace MWDebug
Bug: T353458
Change-Id: I99d728bd111ff882220cd175ff09d4da20b81eae
2024-05-03 22:59:47 +02:00
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