Commit graph

182 commits

Author SHA1 Message Date
Tim Starling
edea1bc177 block: Fix DBS::acquireTarget() race using GET_LOCK()
A crude solution for the acquireTarget() race condition. Use SQL
GET_LOCK() to lock the target from the acquireTarget() call until the
transaction is committed.

Add FOR UPDATE to the acquireTarget() SELECT, otherwise it just sees the
snapshot version of the row and inserts a new row anyway.

Add a test which reliably failed prior to the change.

Reword the ipb-block-not-found message. This is normal for simultaneous
blocks of the same target. Don't contact us. In the API, remap it to
"alreadyblocked".

Bug: T389028
Change-Id: I1fa35bf08d456a93930194786f77df389217ba61
(cherry picked from commit 2b65587e4d92e7f27661e8821b14f74ade939cfa)
2025-04-07 11:43:34 +00:00
jenkins-bot
b60d69a6ac Merge "REST: Add items wrapper for restbase compat to some response bodies" 2024-10-21 18:40:15 +00:00
jenkins-bot
1d0377f1ba Merge "Adding token validation to the edit handler" 2024-10-17 14:51:30 +00:00
bpirkle
330e1633c2 REST: Add items wrapper for restbase compat to some response bodies
Bug: T374136
Change-Id: I995916f53eb9408923456cce8b1f3be391fbf942
2024-10-16 12:58:10 -05:00
Wendy Quarshie
0c22b25b31 Adding token validation to the edit handler
Change-Id: I86fa7d613aa79e07ce20ea7936becf02f25832ac
2024-09-26 15:08:57 +00:00
daniel
1476a90a14 REST: vary on x-restbase-compat header if present
The x-restbase-compat header can be used to instruct certrain endpoints
to produce output that is compatible to the output generated by
REStbase. Since the output varies based on the presence of this header,
we need to send add it to the Vary header to avoid cache pollution.

Bug: T374136
Change-Id: I38c75b2d6f26c49f0ebf5660d34b412ca845ec63
2024-09-24 18:16:50 +02:00
daniel
84fe1b9ccd REST: Introduce discovery endpoint
The discovery endpoint provides basic information about accessing the
wiki's APIs, as well as a directory of available modules.

Bug: T365753
Change-Id: I161aa68566da91867b650e13c8aadc87cd0c428c
2024-09-20 17:02:59 +00:00
bpirkle
90494183bb REST: add restbase compat error handling mode
In order to replace certain /api/rest_v1 endpoints, we
need to have something in MediaWiki that generates a compatible
responser. The MediaWiki REST API error format does not match
RESTbase. So the easiest approach seemed to be to
add a compatibility mode, triggered using the x-restbase-compat
header. This can be set via the gateway when rerouting the request.

Bug: T374136
Change-Id: I73934940d367be52941bd27861c248ab5bcfb5d2
2024-09-16 18:09:12 -05:00
jenkins-bot
634373a3cf Merge "REST: add restbase compat mode for some endpoints" 2024-09-16 19:21:57 +00:00
daniel
602f0ab595 REST: add restbase compat mode for some endpoints
In order to replace the /api/rest_v1/page/title/{title} endpoints, we
need to have something in MediaWiki that generates a compatible
responser. The v1/page/{title}/bare and v1/revision/{id}/bare endpoints
are functionally equivalent, so the easiest approach seemed to be to
add a compatibility mode to them. The compatibility mode is triggered
using the x-restbase-compat header, which can be set via the gateway
when routing the request from /api/rest_v1/page/title/.

Bug: T374136
Change-Id: I4af7ff5325660ae30faebb24753b9dc1c3acb2b3
2024-09-15 16:41:21 -05:00
daniel
dcde8f0101 REST: Change content.v1 to content/v1 match new conventions
Conventions for extension REST module names, and the associated
versions, are being established. Initial speculation was to use
a period as a separator, but consensus instead was to use a slash.
Modify the content module's paths accordingly.

Change-Id: Iea9e3fda8d274ebd341d9331458d37247a0384e2
2024-09-09 20:57:40 +02:00
bpirkle
3f614a0898 Add content.v1 REST module with relevant content endpoints
T366837 added the ability to group REST endpoints into modules.
This change now introduces the first use of a REST module.
The existing endpoints remain accessible at their original paths,
and mocha tests are run against both old and new paths.

Bug: T370430
Change-Id: I83a5cdbdd359e4d3e5f70dd3930783616b556738
2024-08-07 16:51:09 -05:00
daniel
d0f4e4514f REST: showcase usage of ArrayDef convenience functions
This demonstrates how to use ArrayDef::makeObjectSchema to define a
schema for a complex body field.

The "latest" field in the request body for page PUT requests identifies
the base revision. To allow the base revision info to be looped through
from an earlier GET request, it's nice to allow the "timestamp" field
to be present, even though we don't use it.

I changed the relevant part of Update.js to test that use case specifically.

Bug: T368131
Change-Id: I166396e0dbfc995e5346252ee438c9afe2c808e2
2024-07-25 16:54:18 +00:00
mimurawil
ac634435f4 api-testing/action/PageProtection.js: clear state for each test
Anonymous editing with temp account creates a new account (temporary),
so the anonymous token are not valid anymore.

This sets a clear state for each test scenario.

Bug: T365647
Change-Id: I41c6d98a107830f7b9dcc90b91cff0a776767195
2024-07-11 09:27:21 +00:00
mimurawil
c98e555ec6 api-testing/REST/PageHistory.js: update tests for temp account
- Adjust expected user name auto-generated from the first edit
- Anonymous edit count updated (there's a new temporary count)
- Temporary edit count updated (anonymous users are temporary)
- Total number of unique editors (each anonymous edit is a different
user)

Bug: T365647
Change-Id: I5eb93d8eda607708ba7b03f5dfba4ed7e272ce5c
2024-07-11 09:27:21 +00:00
mimurawil
e5abaa2929 api-testing/action/Autopatrolling.js: adjust key prop for temp account
Update autopatrolling rights key from `anon` to `temp`.

Bug: T365647
Change-Id: I4a0eeb2739ea7a457e52cb7dd9441eb87bcaea84
2024-07-11 09:27:21 +00:00
mimurawil
0578848298 api-testing/action/Edit.js: Adjust username assertion for anonymous
Anonymous users (temp accounts) have auto-generated usernames.
This change prevents the assertion test of the username for temporary
accounts, while it still tests everything else in the change record.

Bug: T365647
Change-Id: I406340cd54421ef48fa96da76d58cf3b0b8b77e1
2024-07-11 09:27:21 +00:00
Kosta Harlan
3309f7023a api-testing/REST/Update.js: Use named user for edits
Why:

- The tests in this file aren't specifically about anonymous editing,
  and using a named user for the test edits makes it easier to support
  this test in both a temp accounts and non-temp-accounts context

What:

- Switch the actor used in making edits for the fixtures in the tests to
  be a named user

Bug: T365647
Change-Id: Ic3cc846892b03a9a550f39a92686ae904cfa2c82
2024-07-11 09:27:21 +00:00
Kosta Harlan
e5ea321269
api-testing/REST/Page.js: Use authenticated user for edits
Why:

- There's nothing in these tests making assertions about anonymous
  editing behavior, and using the anon user is problematic with temp
  accounts enabled, because after the initial edit, the user is
  logged-in, and subsequent edits need a new token.

What:

- Switch the actor used in making edits for the fixtures in the tests to
  be a named user

Bug: T365647
Change-Id: If1d3cdc46c894242b2c335e3e8bf25063ea5d8b5
2024-07-10 23:06:32 +02:00
jenkins-bot
d9f64a6287 Merge "REST: Generate request body specs from param settings." 2024-07-10 19:27:24 +00:00
daniel
e6d0adcc68 REST: Generate request body specs from param settings.
Bug: T323786
Change-Id: I49da2a07efa32759480070c9d93c31d46f211d26
2024-07-10 20:23:56 +02:00
Kosta Harlan
405cb9cad9
api-testing/REST/Creation.js: Reset REST client before each test run
Why:

- We need a clear state for each test run, because anonymous editing
  with temp accounts results in a temporary acocunt being generated, and
  the anonymous token is no longer valid.

What:

- Set a new REST client so that we have a clear cookie state before
  running a test

Bug: T365647
Change-Id: I79666ff92de090e69d32f1152ba330cf913e64e2
2024-07-10 10:24:27 +02:00
STran
9d1f0813a9 Add temporary account case for page history count
Edits made by temporary accounts could not be counted independently
when accessing `v1/page/Test2/history/counts/{type}`.

- Add a `temporary` case for page history revision counts.

Bug: T365673
Change-Id: Ib5279684e2843c84a56eea04721dc62700c12577
2024-07-09 05:12:11 -07:00
Ed Sanders
4b9ccab9b9 ESLint: Enforce prefer-arrow-callback and autofix
Change-Id: Iddfa574e42e569ac5e2a2b098ad2f11ca80c5955
2024-06-11 19:03:54 +01:00
Ed Sanders
2af1c3c901 build: Update eslint-config-wikimedia to 0.28.1 and autofix
Also remove temporary explicit dependency on eslint-plugin-vue
introduced in Ibd616750f046a.

Change-Id: Ic6330fcb116e99d5827b4877e094e3073e2b7b72
2024-06-11 19:03:53 +01:00
Lucas Werkmeister
a5c1fc67ee api-testing: Further increase ETag number in transform tests
Change I5521b7652f (commit 682a19e9f6) increased the number by roughly
one order of magnitude, which leaves me nervous that the tests might
start failing again if enough other tests are run in the same wiki to
let the increased revision IDs exist. Let’s bump it further to make that
much less likely (though not impossible).

1219844647 is an arbitrary large number; my intention in choosing a
random-looking number (rather than, say, 1234567890) is that it’s easier
to search for, both in codesearch and in commit messages, if it should
ever pop up in an error message.

Bug: T366142
Change-Id: I8186d9d46bc2a3f5ec04b38aab5cbe85e609835a
Follows-Up: I5521b7652faca9821fa08a9987a9452a4c555203
2024-06-10 16:50:41 +02:00
Arlo Breault
009edac867 Don't ignore offsetType attribute on lint API paths
The default used to be 'ucs2' when linting but
Ic9b7cc0fcf365e772b7d080d76a065e3fd585f80 stopped setting the offsetType
in the environment options, which changed the output to Parsoid's
default, 'byte'.

For the parsing paths, pagebundles are now post-processed and
non-pagebundles were left as a TODO.

However, for the lint paths, it was always ok to continue setting the
environment option because Parsoid is called directly and doesn't go
through the ParserOutputAccess.  The above patch was trying to limit
Parsoid specific options to that.

Bug: T365284
Change-Id: I8389c2f53b399b39a9f1d908a38aecb3abcb15ef
2024-06-03 19:59:28 -04:00
Jakob Warkotsch
682a19e9f6 api-testing: Increase ETag number in transform tests
These tests fail for wikis with many revisions, and even in CI when
running after a suite that generates many edits such as Wikibase.

Bug: T366142
Change-Id: I5521b7652faca9821fa08a9987a9452a4c555203
2024-05-30 10:05:06 +02:00
daniel
879846b29c REST: introduce OpenSearchDescriptionHandler
Move open search description endpoint from /w/opensource_desc.php
to /w/rest.php/v1/search.

Bug: T363984
Change-Id: Idb5b0d21adc6152ef77e6d17846b6acc6a904e01
2024-05-18 17:29:07 +00:00
daniel
91a1741787 Introduce Modules into the REST framework
Modules group together endpoints by a shared prefix. The idea is that each module has its own version and can generated self-contained self-documentation. This allows clients to have clear expectations about the endpoints of each module, no matter what wiki they are accessing. So far, each wiki may be exposing a different set of endpoints, with no way to provide a spec that describes that set of endpoints in a way that would be consistent across wikis and stable over time.

Bug: T362480
Change-Id: Iebcde4645d472d27eee5a30adb6eee12cc7d046b
2024-05-08 16:12:30 +02:00
Tim Starling
917f0a5996 Replace all instances of "per default" with "by default"
According to the dictionary, "per" (or more conventionally "as per")
means "according to". Refer OED "per" sense II.3.a. For example:

"No value was passed, so return null, as per default".

In this sentence, we are not specifying the default, we are referring
to the default. This correct usage of "per default" was used nowhere
in MediaWiki core as far as I can see.

Instead we have "per default" being used to mean "by default", that is,
giving the value to use when no explicit value was specified.

In OED, the phrase "by default" is blessed with its own section just
for computing usage:

"P.1.e. Computing. As an option or setting adopted automatically by a
computer program whenever an alternative is not specified by the user
or programmer. Cf. sense I.7a."

There are highly similar pre-computing usages of the same phrase,
whereas the phrase "per default" is not mentioned.

As a matter of style, I think "per default" should not be used even
when it is strictly correct, since the common incorrect usage makes it
ambiguous and misleading.

Change-Id: Ibcccc65ead864d082677b472b34ff32ff41c60ae
2024-04-29 10:47:54 +10:00
Wendy Quarshie
2ef78ee34b Improve error localization in REST handlers
BUg: T358745
Change-Id: Icb804560c827ee3e5df56d9d8d9565b8157fa9e1
2024-04-02 16:49:40 +00:00
Bill Pirkle
c3fe4b037d Remove experimental contributions endpoints
These four endpoints have been experimental for many months:
  /coredev/v0/me/contributions
  /coredev/v0/user/{user}/contributions
  /coredev/v0/me/contributions/count
  /coredev/v0/user/{user}/contributions/count

Analytics data shows they are not receiving any traffic.
Remove to clear out the coreDevelopmentRoutes.json file for
unrelated experiments, and to reduce future code maintenance.

Bug: T305506
Change-Id: I21cf9a398638d34725a3c34d348fbad50df40153
2024-03-13 21:22:47 -05:00
Jakob Warkotsch
c307f70b4c api-testing: Increase highest expected revId
999 edits isn't that many, even for a freshly created CI wiki.
Wikibase's e2e test suite started hitting this limit which causes
this test to fail.

Change-Id: I0aff1fcc648780201cb2ad14a1e27aafb3e90774
2024-01-31 16:41:11 +01:00
jenkins-bot
3c388afe21 Merge "Add Content-Type header checks to REST API tests" 2023-12-07 21:09:51 +00:00
Daniel Kinzler
b73cc87dd1 Re-apply "REST: Emit swagger spec"
This reverts commit 890558f1fa.
This restores Id584208d9b67d877606a0add1d71c9b1784cdb1b with some fixes.

Bug: T323786
Bug: T352742
Change-Id: Ib31c451ddd75b06c95a544c8a3d2a64b32264126
2023-12-06 11:20:11 +01:00
Urbanecm
890558f1fa Revert "REST: Emit swagger spec"
This reverts commit bb4b5c5f87.

Reason for revert: patch breaks CI

Bug: T352742
Change-Id: Iaf57bad945f5cbd01508a513f0d219ec4b510ce8
2023-12-05 10:37:48 +00:00
daniel
bb4b5c5f87 REST: Emit swagger spec
This is only enabled in development mode for now.
It's intended as a baseline for further development,
the feature is not ready for production.

Bug: T323786
Change-Id: Id584208d9b67d877606a0add1d71c9b1784cdb1b
Co-authored-by: Atieno <pnjira@wikimedia.org>
2023-12-04 16:28:32 +03:00
Chlod Alejandro
e20ef88cb2
Add Content-Type header checks to REST API tests
Add extra checks on all REST API tests which return sucess data values.
This extra check is used to ensure that an accurate `Content-Type` is
being sent to the client, as an incorrect header can cause consumers
to misinterpret the data returned by the API (particularly JQuery, as
described in T352546).

The check was added only to endpoints which return success data.
Tests that check for 4xx status codes do not have the content type
check.

This is a follow-up to I381f33dd.

Bug: T352546
Change-Id: Ib9316b26035ed699f1e607f96e04da110c0edb32
2023-12-02 15:21:53 +08:00
James D. Forrester
c2aa05102d build: Upgrade eslint-config-wikimedia from 0.25.0 to 0.26.0 and make pass
Mostly this has a bunch of whitespace changes from the
template-curly-spacing and brace-style rules being set
to align with other spacing rules.

Change-Id: I4609c52a4ef426ad1f35fb4bfe447bb08323a8e8
2023-11-22 13:25:32 -05:00
Amir Sarabadani
beb3261b8d Remove language coverter for Kazakh
This has been constantly mentioned as buggy and broken and there is no
official version of latin or Arabic (see the ticket for more details).

This can be turned back as an extension if needed by third party users.

Bug: T350684
Bug: T268143
Depends-On: I6180dca2c49b3119751766268acc56087aaf8414
Change-Id: Ifbf3c8954d885daf891f8d9efc11743d898302f0
2023-11-20 10:31:16 -05:00
daniel
7b2d7abecb REST: enable parsoid transform endpoints
Bug: T350661
Change-Id: I7fe681b591eb1414cab6ff33cdc25410000b7cd6
2023-11-07 09:50:27 +01:00
jenkins-bot
dcbe0d3083 Merge "Parsoid API should return latest version instead of redirecting to it" 2023-11-03 16:51:29 +00:00
daniel
7d0fb8d247 Parsoid API should return latest version instead of redirecting to it
Request that only specify a title, no revision, should get the page
content directly.

Bug: T350359
Change-Id: Ia461cce0df63c05c6f8f94275f6b94f81323d171
2023-11-03 16:30:03 +00:00
jenkins-bot
ddb5721d16 Merge "Page endpoints should return 404 for bad titles" 2023-11-02 19:48:33 +00:00
daniel
51036da29e Page endpoints should return 404 for bad titles
Asking a page endpoint for an invalid title should generate a 404
response, not a 403.

Change-Id: Ic0e9c5a99a6561cfd10dd3725a059cda476e6563
2023-11-02 10:18:14 +01:00
daniel
e9aaa47b96 ParsoidHandler: emit relative URLs in redirects
This was missed when fixing a similar issue for core endpoints.

I also deleted some dead code in ParsoidHandler, instead of fixing
it to also generate relative redirects.

Bug: T350219
Bug: T349001
Change-Id: If3fe901723dcae9a22806650a21a79778354d8c5
2023-11-01 16:59:15 +00:00
daniel
b57ec34e2b REST: support relative redirects
Make HTTP redirects returned by the REST API use relative
URLs in the Location header. This ensures interoperability with the WMF
service mesh, avoiding issues with internal services trying to resolve
redirects by accessing the canonical external URLs.

Note that relative URLs are allowed in the Location header per RFC 7231,
while the obsolete RFC 2616 required it to be absolute.

Bug: T349001
Change-Id: Ibb38c30eb66aaed14ab3ad01ffc42c348a0d07c8
2023-10-19 16:46:38 +00:00
Subramanya Sastry
1aa71cf51b Disable Parsoid support for non-default output versions and offset types
* This is in service of a followup patch that merges ParsoidOutputAccess
  and ParserOutputAccess. We want to eliminate all Parsoid-specific options
  that aren't part of ParserOptions and aren't easily supportable via
  html2html transforms.

* offsetType conversion relies on Parsoid code that is a bit entangled
  with env, siteconfig (and extension configs), page source, etc. It
  could all be refactored but once the html2html output transformation
  framework lands, we could potentially use that to call Parsoid to do
  these transforms by exposing such transforms to the framework.

* In this patch, outputContentVersion that isn't the default major HTML
  version is no longer support. It could potentially be supported via the
  downgrade functionality in Parsoid in the future, or we might decide
  to re-enable multiple outputContentVersion selection in the future
  if such a use case arises. But, there are no plans to bump the major
  HTML version in the near future while we work on read views.

* Rather than delete associated tests, I've marked them skipped so that
  they can re-enabled when this support is added back.

Bug: T347426
Change-Id: Ibede4acd68e944512f6d00763d29c6b1605d67eb
2023-09-27 15:03:41 -05:00
daniel
96249612d4 Add a mocha test for variant redirects on the page html endpoint
Change-Id: Idbcbf534a61c8ca1ff162cec613c1e3a7de30ef6
2023-09-14 09:10:24 +00:00