Commit graph

94 commits

Author SHA1 Message Date
Umherirrender
1145328459 api: Use type-declaration for string arg in ApiBase::__construct
Also for all sub-classes
Remove simple doc-blocks without further information

Change-Id: I981934efe32d44f52e5ab865a9b887be5bd0f41e
2024-10-17 20:09:15 +02:00
James D. Forrester
984076f98e Add namespace to includes/api classes
Bug: T353458
Change-Id: I3ea6b08c5018ba03ba45c5766e1f46e12f6b8597
2024-09-25 19:31:14 +00:00
Aaron Schulz
e63f87b0dc editstash: migrate ApiStashEdit to statslib
Bug: T359465
Change-Id: Id5aa4000e8b8bbb13b0ccd4d7cdf8bb355963ad7
2024-09-09 09:39:16 -07:00
Aaron Schulz
510fe9b79e api: add missing help URLs that exist on mw.org
Bug: T342632
Change-Id: I06fe334942848a599e94edadc7e7a14094e4d4b5
2023-10-12 12:58:30 -07:00
daniel
26456e5b22 Use Authority to check rate limits in the API.
Rate limit checks are now performed implicitly by UserAuthority,
see T310476.

Change-Id: I9fee34f5b44e947a00f1aaf2d28202d009e2caec
2023-09-27 08:14:53 +00:00
Bartosz Dziewoński
365a588238 Use real type hints for services etc. in api/ except ApiQuery*.php
Mostly used find-and-replace:

Find:
/\*[\*\s]+@var (I?[A-Z](\w+)(?:Interface)?)[\s\*]+/\s*(private|protected|public) (\$[a-z]\w+;\n)((?=\s*/\*[\*\s]+@var (I?[A-Z](\w+)(?:Interface)?))\n|)
Replace with:
\3 \1 \4

Followed by some manual review to make sure I'm not changing too much,
omitting some changes that looked too complicated and anything that
caused test failures, and some whitespace fixes.

Change-Id: I6ec7587607df4f1a4f448a096c3e44c4e5270b70
2023-08-29 01:04:26 +00:00
Bartosz Dziewoński
1b825c1505 TempUserCreator: Change getStashedNameOrPlaceholder() to just getStashedName()
I found myself needing to just get the stashes name without the
placeholder for T331397, and I thought that this seems like a weird
API. The caller should get the placeholder separately if desired,
which is easy to do in all of the current callers.

Follow-up to 65f04c763a.

Change-Id: Icf1d24f17b60a461ef682bc5da01be6ebc3a2d93
2023-07-18 02:30:08 +02:00
Tim Starling
54ca544726 Add convenience method TempUserCreator::shouldAutoCreate()
Factor out common concept originating in EditPage but since duplicated.

Change-Id: I5f5b75a7da9a40a6cc3041d3d6192d2d747b9f57
2023-05-12 15:31:11 +10: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
Zabe
f6b9381d7f Revert "Reorg: Move some of request related classes to MediaWiki/Request"
This reverts commit 2bdc0b2b72.

Reason for revert: T166010#8349431

Bug: T166010
Change-Id: Idcd3025647aec99532f5d69b9c1718c531761283
2022-10-27 13:14:16 +00:00
Amir Sarabadani
2bdc0b2b72 Reorg: Move some of request related classes to MediaWiki/Request
Moving:
 - DerivativeRequest
 - FauxRequest
 - FauxRequestUpload
 - PathRouter
 - WebRequest
 - WebRequestUpload

Bug: T166010
Change-Id: I5ea70120d745f2876ae31d039f3f8a51e49e9ad8
2022-10-26 16:49:10 +02:00
Umherirrender
eb159d8f5a Remove unneeded initalize of local variables
The variables are set conditional later, but all condition branches set
it or the variable is not used outside that scope

Change-Id: Ic9612915db507028ad4733a061d3ce9be3babfb6
2022-09-21 21:29:21 +02:00
Matěj Suchánek
e670688adf Remove ApiStashEdit::parseAndStash
It has been deprecated since 1.34 and it is unused.

Change-Id: I49bdeec5a0fae2f9057e42f6cf5122cf09663480
2022-06-16 20:05:21 +02:00
Reedy
0b5084f868 api: Replace numerous deprecated constants
Change-Id: I34ffcb70efbfa257da8dab6e0790aa0d697caf5b
2022-06-06 00:18:50 +01:00
Umherirrender
851edd7a49 api: Inline ContentHandler::makeContent, use local ContentHandlerFactory
The static ContentHandler::makeContent is using the global
ContentHandlerFactory to create a new ContentHandler, use the injected
factory instead to avoid global state

Change-Id: I85e23715c67d1441dbffb904d85b7e711c6edafc
2022-04-16 16:27:21 +00:00
daniel
cbfcf9e8a8 Introduced PreparedUpdate to replace PreparedEdit
PreparedUpdate represents an in-progress edit. It can be used to access
information about the edit from hooks that do to have access to the
PageUpdater. Ideally, the PreparedUpdate or PageUpdater would be passed
to the hook as a parameter. Handlers of legacy hooks may use
WikiPage::prepareUpdate() to access it.

Bug: T242249
Needed-By: I23324a31e06e7e6f28077085c0ade05db63e9a35
Change-Id: Id5ba40a21cc4547205adf2f3a1f725c3a69c24d8
2021-12-20 21:19:52 +01:00
Reedy
7bf779524a Remove or replace usages of "sanity"
Bug: T254646
Change-Id: I2b120f0b9c9e1dc1a6c216bfefa3f2463efe1001
2021-11-19 23:19:42 +00:00
Umherirrender
1f742b548e api: Replace deprecated WikiPage::factory in ApiStashEdit
Change-Id: I0762bf7351c55952f5348258162438525329b338
2021-06-28 22:20:02 +02:00
Bartosz Dziewoński
2361889b78 Use the edited page's title for magic words in action=edit error messages
Allow specifying the title used for rendering error messages in
ApiErrorFormatter.

Then, specify one in ApiEditPage (and a few similar modules that deal
with single pages) once we've figured out which page is being edited.

Bug: T247661
Change-Id: Ic3d70efc23744ef6e90abc445f3babebf45c4697
2021-05-21 18:00:36 +02:00
Petr Pchelko
1f11b88f35 Convert PageEditStash to PageIdentity/UserIdentity
One tricky piece left when we get the Request from user
to check whether it was posted, needs a more thorrow
investigation.

Depends-On: Iab96a35be8f50fdbc66194bd8956d98b5b6b0032
Change-Id: I7164b914299441bd0f82e764252c8b5d30b45fbe
2021-04-14 09:12:04 -07:00
DannyS712
4b37f95d14 Inject services into ApiStashEdit
Bug: T259960
Change-Id: I8fede2c0df26a101f880b4038fe90557fd1818f3
2020-10-27 17:07:54 +00:00
Ammar Abdulhamid
7af5678847 API: Handle ContentHandler exception for content model mismatch
Ensure the content we are trying to save and the base content have
identical content models before proceeding to save so as to forestall
Exception that may be thrown by ContentHandler if it founds they're not.

There are two cases where the models are allowed to differ: Edit that
undoes content model change or edit that's meant to explicitly change
the model. The logic for these is handled separately and may succeed
or fail, but exception will not be thrown.

Bug: T255700
Change-Id: I8782732bb0fc3059693cd7035b7ebb43fd71d333
2020-09-04 03:41:58 +01:00
Reedy
b80a9f4f6a Fix even more PSR12.Properties.ConstantVisibility.NotFound
Change-Id: I5e04824d6fa6a4c36ce489850bb0ed7b4ac588f9
2020-05-16 00:51:14 +01:00
Petr Pchelko
e2443a7066 Remove use of deprecated Revision from ApiStashEdit
Bug: T246284
Change-Id: I734e6572c913f4f32295a14705f0fc19b8000b03
2020-03-13 08:04:39 +04:00
Daimona Eaytoy
60dc4b41f8 stashedit: Ensure that $summary is a string
It's only documented as string.

Bug: T245928
Change-Id: I8fa287f335e90a59ac18365e7401a5cf703130a3
2020-02-22 19:55:28 +00:00
ArtBaltai
30e54b3962 Introduce ContentHandlerFactory
Added:
- ContentHandlerFactory
Tests:
- PHPUnit
Changed
- Calls of changed and deprecated
- DI for some service/api
Deprecated:
- ContentHandler::* then similar to ContentHandlerFactory
- ContentHandler::getForTitle
- ContentHandler::$handlers

Bug: T235165
Change-Id: I59246938c7ad7b3e70e46c9e698708ef9bc672c6
2020-02-07 00:53:51 +03:00
Aaron Schulz
7526c30960 Remove redundant ignore_user_abort() call in ApiStashEdit
This API module has mustBePosted() return true and such POST
request are already covered by both WebStart.php and
ApiBase::useTransactionalTimeLimit().

Change-Id: Ie6f6af1459dde82572be8784049a307a3a769a1c
2019-08-29 22:18:57 -07:00
Aaron Schulz
56443daf78 Keep ERROR_* constants in ApiStashEdit for backwards compatibility
Follow-up to 2859306684

Bug: T221689
Change-Id: Ibe275c69d5b47fd36efac4a91b2334970dd02fe8
2019-04-23 12:43:38 -07:00
Aaron Schulz
2859306684 Refactor edit stashing into a PageEditStash service
Additional code cleanup:
* Call setCacheTime() in parseAndStash instead of relying
  on the one in DerivedPageDataUpdater.
* Improve the SPI logging by adding more extra fields.
* Treat requests in CLI/job mode (aside from tests) like
  those from bots with regard to checking the stash.
  This should avoid stats/logging pollution.

Change-Id: I8c6be919e399378e401a60502add0ecec7764d2d
2019-04-17 12:53:03 -07:00
Aaron Schulz
a8e088a4d1 Make ApiStashEdit::pruneExcessStashedEntries use user name
Follow up to c334883309

Change-Id: I35213d83a00b50bb469aab5bf8fbeb52239cff5e
2019-03-27 18:25:46 -07:00
Aaron Schulz
c334883309 Prune old edit stash entries from users as they create more
This should reduce pressure on certain medium-large sized memcached
slabs. Pre-1.5 memcached versions have a harder time pruning expired
entries in time to avoid evictions, so it will be most useful that
scenario.

Bug: T203786
Change-Id: Ic357dbfcd9abd525b02e8d631d1344db3745d24c
2019-03-26 18:24:56 +00:00
Aaron Schulz
0dc015c87b Make ApiStashEdit use a separate key for the parser output due to size
Bug: T204742
Change-Id: Ibab189c8e0dee5e840770bdb0336516fdfc75e4b
2019-03-06 09:11:07 -08:00
Umherirrender
7b05197301 Fix caller name in ApiStashEdit::parseAndStash
Seeing {closure} in the logs as caller is not helpful

Change-Id: Id77253bdd4b65b0673214e7bf6ca3cc26bd155fa
2018-09-30 16:01:23 +02:00
Aryeh Gregor
ab94b63526 Improve test coverage for ApiStashEdit
Change-Id: I1b7d95e074a7f101d13398a32898b74145ab4056
2018-08-21 15:32:29 -07:00
Aryeh Gregor
a49a6376be Fix incorrect method name
getTimestamp() returns the timestamp of the revision, and as far as I
can tell that's null here, presumably because we haven't saved the
content and thus there is no revision. getCacheTime() returns the time
when the page was parsed, which is probably what we want.

Change-Id: I7dc446800656236f6ecc872a65e620881e434c54
2018-08-07 16:16:26 +00:00
Aryeh Gregor
6380cadedc Do not return invalid hash from ApiStashEdit
If we were rate-limited, we don't store a new hash, so we shouldn't
return a new one.  If we received a hash from the client, however, that
should still be valid, so we can return it.

Change-Id: Ifc37ae044172b8838fee15d539b076a0d0f02f22
2018-08-06 20:44:20 +00:00
Aryeh Gregor
0438e94222 Clean up param handling in ApiStashEdit
It doesn't make sense to submit both stashedtexthash and text, so
requireOnlyOneParameter() is correct.  This simplifies the code and
gives a more helpful error message. (Previously if both parameters were
passed, we would ignore text unless stashedtexthash was empty, in which
case we would ignore it.)

Change-Id: I306b15eefb6fd4379a3eed88d84113c2e43c4a95
2018-08-06 19:04:43 +00:00
Brad Jorsch
27c61fb1e9 Add actor table and code to start using it
Storing the user name or IP in every row in large tables like revision
and logging takes up space and makes operations on these tables slower.
This patch begins the process of moving those into one "actor" table
which other tables can reference with a single integer field.

A subsequent patch will remove the old columns.

Bug: T167246
Depends-On: I9293fd6e0f958d87e52965de925046f1bb8f8a50
Change-Id: I8d825eb02c69cc66d90bd41325133fd3f99f0226
2018-02-23 10:06:20 -08:00
Aaron Schulz
6fb6fc9dc2 Avoid blocking locks during API edit stash generation
Bug: T180793
Change-Id: Ibc29a20329113c3ee54fd48cfe86ca8251e8098d
2017-11-21 19:23:41 +00:00
Chad Horohoe
b0944a1371 Fix up logging grouping in ApiStashEdit
Change-Id: Ie3d7b465faa26966c5745ca1bb09843a26193b9e
2017-11-09 20:19:30 +00:00
Aaron Schulz
23cd890fc9 Sanity check "stashedtexthash" param before checking memcached
The makeKey() method should do escaping and shortening, but it
is safest and clearer to not rely on that.

Change-Id: Ia4a95e0bb12074d141ddcca2089b920403cab100
2017-08-31 14:35:17 -07:00
Aaron Schulz
7ff8529984 Avoid high edit stash TTLs when a user signature was used
This adds a new ParserOuput user-signature tracking flag.

Bug: T84843
Change-Id: I77de05849c15e17ee2b9b31b34172f4b6a49a38e
2017-07-06 16:34:26 -07:00
Aaron Schulz
82e2c924e4 Remove "@author Aaron Schulz" annotations
Bug: T139301
Change-Id: Ib5248e8e27d60611c7373bce4b29dd5e85aa3489
2017-06-27 15:24:14 -07:00
Erik Bernhardson
d67197fa11 Cleanup some incorrect return annotations
Most of these are simply changing annotations to reflect
reality. If a function can return false to indicate failure
the @return should indicate it.

Some are fixing preg_match calls, preg match returns 1, 0 or false,
but the functions all claim to return booleans.

This is far from all the incorrect return types in mediawiki, there
are around 250 detected by phan, but have to start somewhere.

Change-Id: I1bbdfee6190747bde460f8a7084212ccafe169ef
2016-12-12 10:15:05 -08:00
Brad Jorsch
4e6810e4a2 API: i18n for warnings and errors
API warnings and error messages are currently hard-coded English
strings. This patch changes that.

With a few exceptions, this patch should be compatible with non-updated
extensions:
* The change to ApiBase::$messageMap will blow up anything trying to
  mess with it.
* The changes to the 'ApiCheckCanExecute' hook will cause a wrong
  (probably unparsed) error message to be emitted for extensions not
  already using an ApiMessage. Unless they're currently broken like
  Wikibase.

Bug: T37074
Bug: T47843
Depends-On: Ia2b66b57cd4eaddc30b3ffdd7b97d6ca3e02d898
Depends-On: I2e1bb975bb0045476c03ebe6cdec00259bae22ec
Depends-On: I53987bf87c48f6c00deec17a8e957d24fcc3eaa6
Depends-On: Ibf93a459eb62d30f7c70d20e91ec9faeb80d10ed
Depends-On: I3cf889811f44a15935e454dd42f081164d4a098c
Depends-On: Ieae527de86735ddcba34724730e8730fb277b99b
Depends-On: I535344c29d51521147c2a26c341dae38cec3e931
Change-Id: Iae0e2ce3bd42dd4776a9779664086119ac188412
2016-12-06 10:20:48 -05:00
Kunal Mehta
61adc1e146 Use namespaced ScopedCallback
The un-namespaced \ScopedCallback is deprecated.

Change-Id: Ie014d5a775ead66335a24acac9d339915884d1a4
2016-10-17 15:46:05 -07:00
Aaron Schulz
ae648472b0 Fix ApiStashEdit IDEA warnings
Change-Id: Icc1d0225908e432df10c36d69c6ed282f8761198
2016-09-07 12:00:52 -07:00
Aaron Schulz
950cf6016c Rename DB_SLAVE constant to DB_REPLICA
This is more consistent with LoadBalancer, modern, and inclusive
of master/master mysql, NDB cluster, and MariaDB galera cluster.

The old constant is an alias now.

Change-Id: I0b37299ecb439cc446ffbe8c341365d1eef45849
2016-09-05 22:55:53 -07:00
Aaron Schulz
3853783ef7 Optimize summary-based extension edit stash caches
* Send stash requests when the summary changes, so that things like
  AbuseFilter caching have a higher hit rate.
* Make the backend API skip parsing if a fresh cache is already present.
  This makes requests for summary-only changes much faster and more likely
  to finish in time.
* Avoid sending the full text if only the summary changed since the
  last successful stash. This works via an optional stashedtexthash
  parameter to the API.
* Also always apply the lock in parseAndStash(), even for VE.

Change-Id: I9bfd74cf05411853b675c6f54ff5d8934bcfc54c
2016-08-10 17:50:19 -07:00
Aaron Schulz
005b4d6fff Try to predict the rev_id when preparing edits
During both the edit stash and first parse in on page save,
guess what the rev_id will be and use that instead of null.
Only reparse if it turns out to be wrong. This avoids extra
parsing on wikis that have low-medium traffic, and does not
cost much. The parsing that can be avoided is:
a) in doEditContent() by using the stash
b) in doEditUpdates() by using the doEditContent() result,
   whether that was able to use the stash or not itself

Also improved the parse operation logging in save paths.

Bug: T137900
Change-Id: Ic6faae70a78b4e223e4d3585cefd482c0fa00677
2016-06-29 05:39:33 -07:00