Commit graph

116 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
Umherirrender
82d24c7666 api: Use own PermissionStatus for each authorizeAction on action=purge
When the purge action fails with error "ratelimited", the linkpurge
would fail with "Precondition failed: The PermissionStatus passed as
$status parameter must still be good"

Bug: T369455
Change-Id: Ifb19cc195a51f5521f8365ab26b3cdb56429e0fb
2024-07-10 21:13:28 +02:00
Umherirrender
352fce6eda Use Authority::authorizeAction for implicit purge/linkpurge right
Use of Authority::authorizeWrite includes permission checks for the
title against the edit rights, which was not the case using
User::pingLimiter before 26456e5b / 07a9c87b

Bug: T354460
Follow-Up: I9fee34f5b44e947a00f1aaf2d28202d009e2caec
Follow-Up: If85e2af107dd901d98e9553d7d38144f1bac62af
Change-Id: Ic03714e849bf3bd550f64e194797b45823b42c08
2024-01-26 23:31:58 +01:00
Umherirrender
b458d37c04 api: Stop further linkpurges only when ratelimited
Failure related to page permissions (like $wgNamespaceProtection or
.js/.css-pages) should not stop further linkpurges.
Also stop further recursive linkpurges when ratelimited,
as that only repeats the api warning message.

Bug: T354461
Change-Id: I153f7d8e472dd17cc26e329bee40005e1ed914fd
2024-01-06 00:12:36 +00:00
Umherirrender
62c1bd5abc deferred: Add a freshness option to RefreshSecondaryDataUpdate
Allows to trigger RefreshSecondaryDataUpdate jobs with a timestamp to
ensure a link update was done after that timestamp.

Since e5655255 it is possible that RefreshSecondaryDataUpdate gets
queued for api action=purge, but RefreshSecondaryDataUpdate only checks
that the links update is done after the last edit, so when jobs get
queued by action=purge, the jobs does nothing.
Ensure that page_links_updated gets updated via action=purge when the
timestamp is before the new freshness timestamp (checked in
RefreshLinksJob::isAlreadyRefreshed).

Bug: T351729
Change-Id: I85aed4c40d430ba6c30c763141f4b821c36e6eaf
2023-12-27 16:07:06 +01:00
Umherirrender
72d6b46339 Use namespaced classes
Changes to the use statements done automatically via script
Addition of missing use statements and changes to docs done manually

Change-Id: I443aada1c18c8628b02671aa9fd6f441961e5c2e
2023-12-11 16:07:18 +01:00
James D. Forrester
67217d08df Namespace remaining files under includes/deferred
Bug: T166010
Change-Id: Ibd40734b96fd2900e3ce12239d09becfb4150059
2023-11-22 10:08:53 -05:00
daniel
a5fc516f5b ApiPurge: report permission errors properly
Previously, all kinds of permission errors were reported as "rate limit
exceeded".

Follow-Up-To: I9fee34f5b44e947a00f1aaf2d28202d009e2caec
Change-Id: Idec70e754bff265c4293aee37c600e54ed1aed40
2023-10-09 17:44:20 +00: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
Ammar Abdulhamid
cd13bbb727 Get correct main page in API call examples
Remove hardcoded "Main Page" and use whatever the main page of
the wiki is. Many wikis have their main page in a different
title than the default or even in a different namespace entirely.

With the hardcoded title this produces broken/redlink for the doc
examples and makes it overall less useful.

Most typical examples; Mediawiki.org itself, Wikidata.org, etc.

Bug: T235207
Change-Id: Ia9eee76544cad153166dd5a2eb8e8c1bf3a38b74
2023-09-20 17:12:06 +03:00
James D. Forrester
b16be7a36c Namespace TitleFormatter under \MediaWiki\Title
One of the big ones, so doing this alone.

Bug: T166010
Change-Id: Ic2d59eb6764b1a273ed7162ecabf641f638b8f66
2023-09-19 05:17:18 +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
DannyS712
c1db64b808 Make use of ??= in more places
New feature from PHP 7.4

Change-Id: Ifa7a9bc7b2ec415ad7ecb23f4c1776f51f58fd6b
2022-12-17 01:10:13 +00:00
Umherirrender
3b53613dcb api: Replace deprecated ApiPageSet::getGoodTitles in ApiPurge
Use existing variables instead of getting things every time

Change-Id: I889249fd0a4f2a0f4f2a7c1f9908109e87cf0e2a
2022-02-11 23:57:48 +01:00
Umherirrender
ce51bca328 api: Replace deprecated WikiPage::factory in ApiPurge
Change-Id: Id7ff8105431d63b9008e40de0ac4d931ec1e88af
2021-06-29 20:37:13 +02:00
Reedy
beedb3aa1c SECURITY: Prevent blocked users from purging pages
CVE-2021-35197

Bug: T280226
Change-Id: Id783618e885998cddf45a4cfc7b2c19fd0c7e9f5
2021-06-23 17:22:21 +01:00
Gergő Tisza
51602a436c
[MCR] Move getSecondaryDataUpdates to the page level
Replaces Content::getSecondaryDataUpdates with
WikiPage::getSecondaryDataUpdates so that aggregation of
data updates from multiple page slots can be handled without
the caller having to care about it.
Also adds a WikiPage::updateParserCache method for convenience.

This is a temporary measure until DerivedPageDataUpdater
(or its replacement) can be exposed directly, at which point
the WikiPage methods will be deprecated.

Also fixes a parameter handling bug in DerivedPageDataUpdater.

Bug: T194043
Change-Id: Idbe7d582b49fcb7c90aea813773b7610ad44b1a8
2018-09-04 21:50:58 +02:00
Umherirrender
e8bd5978b1 Swap isset by null check in ApiSetNotificationTimestamp/ApiPurge
Change-Id: I1ebcbacf476a716d23b183dcbf379555ee1519dd
2018-04-05 12:39:24 +02:00
Chad Horohoe
e7c86d8537 Remove some dumb headers with my name in it
Change-Id: Ib34b623b47fb92f1383bc5c55c50a16dd6d49abd
2017-11-30 15:39:46 -08:00
Aaron Schulz
8f829de5f0 Add action/user tracking to link refresh jobs
Change-Id: Ie7261eacddb869988b005ba2f17968df88c7003e
2017-10-23 11:06:16 -07:00
Kunal Mehta
1fd095ec1c Avoid using the deprecated ParserCache::singleton()
Change-Id: I0da6d9cbfad26c89bf5dab564071ef97acaf44f9
2017-09-09 14:20:10 -07:00
Baha
036b9c4167 Make API documentation links language aware
Links generated by the API are now aware of the user's preferred
language and will show documents in that language if available.

To test, log in to mediawiki.org and set your language preference to 'es',
then on an MediaWiki installation with this patch view the generated
expanded API help at `api.php?action=help&recursivesubmodules=1&modules=main`.
Each link to documentation on mediawiki.org should take you to its
translated /es subpage, if one exists.

Bug: T104518
Change-Id: I339a1f3ae1bce9d759cf251899d57c32b1def91e
2017-04-05 11:08:25 -04:00
Brad Jorsch
f4a306fb18 Deprecate "Avoid page_touched update for HTTP GET action=purge requests"
This reverts most of commit c84ba4d864.
The changes made there are no longer needed, and nothing in Gerrit seems
to have started using them since they were added.

The added constants in WikiPage, WikiPage::getLastPurgeTimestamp(), and
Article::getLastPurgeTimestamp() are deprecated, useless, and unused,
but not removed yet since they snuck into 1.28 so we can't revert them
without a deprecation period. Sigh.

Bug: T145649
Change-Id: I526fd4e004bee84c831a4cee71e44e92ee73480b
2017-03-27 10:10:26 -04:00
Brad Jorsch
eada940909 ApiPurge: Require POST
This change was announced to mediawiki-api-announce on September 14,
2016,[1] and the remaining users were notified on December 28, 2016, and a
reminder was sent on the same day.[2] Time to do this.

[1]: https://lists.wikimedia.org/pipermail/mediawiki-api-announce/2016-September/000118.html
[2]: https://lists.wikimedia.org/pipermail/mediawiki-api-announce/2016-December/000124.html

Bug: T145649
Change-Id: I5ec8acfbd2cd705a7b4c81f36786149c3d9cba45
2017-02-01 10:33:15 -05: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
Petr Pchelko
d9139aa0b8 ApiPurge: Remove setTriggeringUser call.
This is a revert of 84ffa5d124. At that point we've been implementing
page-properties-change event for the EventBus extension and thought
adding this call would be a good idea. However, it was discovered
afterwards that there's much more extensions that don't set the
triggering user. Since that call is deprecated and plans are to
remove it - revert the change.

Change-Id: I9891da628f968970247edc37cccd4a666950273b
2016-10-19 03:37:27 +00:00
Petr Pchelko
84ffa5d124 ApiPurge: Set the triggering user for the LinksUpdate
Even if the API call was done anonymously, we still have the IP
address to set as a triggering user. This is needed in the EventBus
since the LinksUpdate job triggers a page-properties-change event
and we need information about the performer for each page-related
event.

Bug: T147516
Bug: T147977
Change-Id: Idc6efc894698606ba528f4bd67658267ed250862
2016-10-13 10:07:31 +03:00
Brad Jorsch
8e461ca44e API: Deprecate use of ApiPurge via GET
This emits a warning and logs feature usage, and also pretends that POST
is required in the help and paraminfo output.

Bug: T145649
Change-Id: Ied8d47a947662158fddab383c764bf70c5ab0112
2016-09-14 11:04:33 -04:00
Aaron Schulz
c84ba4d864 Avoid page_touched update for HTTP GET action=purge requests
This will still clear the local DC parser cache and the CDN cache
in all DCs. Therefore, the next page views served by the local
DC will reflect the refreshed content, as will further GET/HEAD
requests by the client that issued the purge using GET/HEAD.

If the problem was imply a stale CDN cache entry, then all
DCs will be up-to-date. If the problem is stale parser cache,
then a proper POST purge request is required to refresh all DCs.

Bug: T92357
Change-Id: I9af12ca8cfff73298f404fd3e2dd4f546621c546
2016-09-13 05:24:46 +00:00
Aaron Schulz
dc0cdc8a4d Make DeferredUpdates able to run DataUpdates
* Also make ErrorPageError exceptions display themselves
  in PRESEND mode. Before they were always suppressed.
* Make DataUpdate::runUpdates() simply wrap
  DeferredUpdates::execute().
* Remove unused installDBListener() method, which was
  basically moved to Maintenance.
* Enable DBO_TRX for DeferredUpdates::execute() in CLI mode
* Also perform sub-DeferrableUpdate jobs right after their
  parent for better transaction locality.
* Made rollbackMasterChangesAndLog() clear all master
  transactions/rounds, even if there are no changes yet.
  This keeps the state cleaner for continuing.
* For sanity, avoid calling acquirePageLock() in link updates
  unless the transaction ticket is set. These locks are
  already redundant and weaker in range than the locks the
  Job classes that run them get. This helps guard against
  DBTransactionError.
* Renamed $type to $stage to be more clear about the order.

Change-Id: I1e90b56cc80041d70fb9158ac4f027285ad0f2c9
2016-09-02 04:12:50 +00:00
umherirrender
815055276a ApiPurge: Do not die on non content pages
Some pages seems to have page_latest = 0, and therefore no content to
linkupdate. To not get a BadMethodCallException (see T140514) there is a
null checked needed.

Change-Id: I1ebfcf131ad3f59f38ec2583650eba5b43bac999
2016-07-20 14:02:58 +00:00
Aaron Schulz
e052761ca0 Add RecursiveLinkPurge log for API requests
Change-Id: I29636c045f7b561b2da0100f5e69050808d1aec7
2016-03-15 21:39:40 +00:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Reedy
7fe05a9fb6 Add page purge limiter
Change-Id: I737dc77ce803432b0792f7e49323a29661bc056f
2015-10-02 20:27:44 +00:00
Brad Jorsch
beab6b009e Change API result data structure to be cleaner in new formats
Nothing in this patch should result in changed output for format=json or
format=php except as noted in RELEASE-NOTES-1.25, and changed output for
format=xml should be similar or cosmetic. However, other code accessing
the result data directly may need to be updated.

Bug: T87053
Bug: T12887
Change-Id: I3500708965cb8869b5aed1543381aad208dadd13
2015-04-20 17:49:37 -04:00
Brad Jorsch
1c57794e37 API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.

ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.

So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
  arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
  Formatters are responsible for stripping it if necessary. "raw mode"
  is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
  question, and so on.
* New class for formatting warnings and errors using i18n messages, and
  support for multiple errors and a more machine-readable format for
  warnings. For the moment, though, the actual output will not be changing
  yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
  between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
  modules currently returning booleans will need to use
  ApiResult::META_BC_BOOLS to preserve their current output.

Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.

Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2015-04-10 16:57:15 -04:00
Brad Jorsch
f62bc7536e API: Fix access on getExamplesMessages
ApiBase declares it protected, but for some reason I had made it public
in all subclasses.

Change-Id: I8a50d4f47e66c7f09137968d3941dc5cdc1d28e4
2014-10-29 11:15:27 -04:00
Brad Jorsch
ad225f501c API: Internationalize all remaining core API modules
This also adds some new ApiBase::PARAM_* constants to generate more
helpful help, and a method to override the default description message
for the use of ApiDisabled and ApiQueryDisabled.

Bug: 71638
Change-Id: Ic0c3d232e0498d58a043037e2e0c6f0b1c3edad3
2014-10-20 16:56:35 -04:00
Brad Jorsch
f0a6435f3b API: Remove action=paraminfo 'props' and 'errors' result properties
The format for 'props' was never specified and the list for 'errors' is
impossible to keep updated when considering that many errors come from
MediaWiki backend code and extension hook functions. And since there
doesn't seem to be any real use case for either of these, let's just
kill both of them instead of wasting effort on trying to fix them.

Note that neither getResultProperties nor getPossibleErrors are called
from any extensions in gerrit, and none of the other deprecated methods
are called outside of the implementations of those two methods. Removing
the obsolete methods is left to the maintainers of the extensions, as
keeping them hurts nothing and is needed to maintain compatibility with
earlier versions of MediaWiki.

Change-Id: Ie11a401d60c834059fbf1b5625ca8ea093b3337c
2014-08-07 16:51:19 +01:00
Brad Jorsch
1e7ea938da API: Refactor continuation code and add to purge, watch, etc.
While generator support was added to various actions, the continuation
parameters from the generators weren't being returned to the client.

This patch refactors the code for handling continuation out of ApiQuery
and into ApiResult, and then uses it in the other actions that need it.

Bug: 60734
Change-Id: I1a6e51cdc964ddcdd69aaa2f735223371233e8af
2014-07-04 15:48:35 -04:00
Reedy
e48ecbc524 Switch API to use Config classes
Only done where globals are config (so not $wgParser, $wgContLang etc)

Change-Id: Ic39cdd858cfb9096a2bc09618f97e64270d76f13
2014-06-15 23:56:38 +01:00
addshore
719d7a2f03 Add final period to API module descriptions
Change-Id: Icae68c1ab1fd0006e00a3a9a56ae8f831d3d0d45
2014-03-10 09:04:08 +00:00
umherirrender
d99e39a97f Remove final period from api module descriptions
The most description are without a final period, so that looks common.

Change-Id: If72a3cc094cfff436b53948728354cbaeff768c8
2014-03-02 20:20:56 +01:00
eranroz
75e28dc018 Support ApiPageSet in ApiWatch
Add support for ApiPageSet capabilities in ApiWatch to support batch
operation on titles, pageids etc. The old 'title' parameter (for a
single page) is still supported to keep backwards compatibility.

Moved a function from ApiPurge to ApiPageSet: getInvalidTitlesAndRevisions() gathers
warnings about invalid/missing titles/ids in the requested page set.

Split from If993f6e8.

Change-Id: I820dcb64d469616b10741df013911197cc5bde29
2014-02-04 14:44:22 -05:00
Siebrand Mazeland
1707a7995e Fix CodeSniffer errors and warnings (final round for API classes)
Change-Id: I97bf36ebef254818dc17378a06405b681ad19c59
2013-11-15 10:33:50 -08:00
Siebrand Mazeland
c6630e8bbe Update formatting on API classes, Part 3
Change-Id: I526be68e21836201c992b391a81f4d41e1fa801e
2013-11-14 18:12:29 +00:00
Aaron Schulz
bc69502492 Support rate limiting backlink purges, including null edits
Change-Id: I86e45b7d0eba7d87f65150b34e190e04d8342b3e
2013-09-27 05:37:39 +00:00
Tim Starling
48828f5c14 Don't queue refreshLinks jobs on null edit
Bug 50785: don't queue refreshLinks jobs on null edit or API
action=purge forcelinkupdate=1, since these actions are commonly
performed in order to clear the cache of a single page, and queueing
millions of jobs is not the response the user usually expects.

Change-Id: I2dbb5d21fa6b876adefd6bcfc93a83c5904d8d13
2013-07-08 15:04:38 +10:00
umherirrender
a35cce4be0 Fixed spacing in api folder
Added spaces before if, foreach
Added some braces for one line statements

Change-Id: Id7779dca4d1185245cf5764102b8de8b232c34b6
2013-04-20 07:47:36 +00:00