Commit graph

131 commits

Author SHA1 Message Date
James D. Forrester
984076f98e Add namespace to includes/api classes
Bug: T353458
Change-Id: I3ea6b08c5018ba03ba45c5766e1f46e12f6b8597
2024-09-25 19:31:14 +00:00
Martin Urbanec
29af4dd074 Move user options related classes into its own namespace
There are a couple of user options related classes already,
and the T321527 work on dynamic defaults is going to add
even more. Let's move them into a separate namespace
to make core a bit more organized.

Old name is kept as an alias for compatibility purposes.

Bug: T321527
Bug: T352284
Change-Id: I9822eb1553870b876d0b8a927e4e86c27d83bd52
2023-11-29 13:27:13 +01: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
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
James D. Forrester
dc73e71710 Api: Fix some very old copyright statements for Roan
Change-Id: I820a2d388922653a6a5b9048b0feaafbb4297d91
2023-03-16 13:27:37 -04:00
Reedy
f45fefec0e api: Replace numerous more deprecated constants
Change-Id: I498a315b8b4b56d5e2f939e797adbe0487cd7d07
2022-06-06 02:24:41 +01:00
Reedy
0b5084f868 api: Replace numerous deprecated constants
Change-Id: I34ffcb70efbfa257da8dab6e0790aa0d697caf5b
2022-06-06 00:18:50 +01:00
Umherirrender
a7e8f87d9f Remove usages of deprecated Title::getRestrictionTypes
Bug: T306131
Change-Id: Id7b2849bb1c31dbd79acbeb607dfc4f7869e6142
2022-04-13 20:34:10 +00:00
Aryeh Gregor
666ca1bdf3 Use MainConfigNames instead of string literals, #2
This covers all occurrences of /onfig->.*get( '/ in includes/.
Undoubtedly there are still plenty more to go.

Change-Id: I33196c4153437778496f40436bcde399638ac361
2022-04-13 18:55:46 +03:00
Arlo Breault
58f7e36f63 Try to ensure tags are arrays
In a similar vein to I46033d5ddda055c275dbda71d5c38c4a7a858c9d

The documentation to WikiPage::doUpdateRestrictions is changed to remove
`|string|null`.  ManualLogEntry::addTags can handle a string but it's
unexpected in the RevisionFromEditComplete hook.  From codesearch,
ApiProtect is the only caller passing in $tags, and that's coming from
a PARAM_ISMULTI, which presumably can only be an array or null.

Bug: T302918
Change-Id: Icd8a7391f7a8c21b0cdb1f734e65ee5661c1075f
2022-03-04 19:07:30 -05:00
Umherirrender
d146800ee8 api: Inject services into ApiWatchlistTrait
Bug: T259960
Change-Id: I73596f8c924ec4a02a7042608d19a35f82bb752a
2021-07-06 20:15:30 +00: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
Reedy
6b9be9c0e9 SECURITY: Allow user to only apply protection they have right to do so via action=protect
'apierror-protect-invalidlevel' potentially wants updating at a later point as the
message isn't necessarily clear what the error is; the protection may be valid
but the users right to do so is not.

Bug: T270713
Change-Id: I72fe67264baa4123599ec424a7d780192ca54bcc
2021-04-08 20:55:25 +01:00
Petr Pchelko
ee7d3e9335 Convert ChangeTags public interface to Authority.
Bug: T275507
Change-Id: I3b7f99391ab299df2b046a2878010cf6afe7fed7
2021-02-24 14:09:16 -07:00
Ammar Abdulhamid
cf004d524d Remove requirement for ApiWatchlistTrait to be in ApiBase.
This trait is not needed in ApiBase and its presence here is
proving to be problematic. See I795db12.

In this patch, the trait usage (more precisely the 'use statement')
has been removed from ApiBase and accordingly the signatures of
ApiWatchlistTrait::getWatchlistValue() and ::setWatch() have been
altered to now require User object.

With these changes, the abstract getUser() method in the trait is no
longer needed, so it has been removed also.

All core usages of the affected functions are fixed in this patch.

The trait is used in only one extension according to codesearch tool,
the extension will be fixed in  Ic22e163.

Bug: T262175
Bug: T248512
Follow-up: Ia18627b9824dca81f44f0571e8420d89b7626cf6
Change-Id: Idabcea71edfca9e7ed42000a258c99ff407873d4
2020-09-07 01:13:57 +01:00
MusikAnimal
6a898faed2 Add watchlist expiry support to applicable APIs
This introduces an ApiWatchlistTrait that refactors out common code
across APIs that allow you to watch pages. Some methods have been
migrated from ApiBase and changed completely, but codesearch suggests
they aren't being used outside the API modules in this patch.

Bug: T248512
Bug: T248514
Change-Id: Ia18627b9824dca81f44f0571e8420d89b7626cf6
2020-07-13 18:18:15 -04:00
James D. Forrester
0958a0bce4 Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNull
Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
2020-01-10 14:17:13 -08:00
Umherirrender
c9d303d39e Remove "Created on" from file header comments
It is the job of git and svn to provide this information/metadata.
The form was different, some with short, some with long month name
some with leading zero at the day, some without.
The year is also present in the Copyright clause

Change-Id: If006907b82b9e45f13cfa2e45d41107a95570e1a
2018-01-26 23:12:40 +00: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
a066419628 ApiResult: Add ApiResult::formatExpiry()
This allows for removing $wgContLang from many API modules where it was
only used to call $wgContLang->formatExpiry() in a way in which the
results don't actually depend on the language.

Change-Id: Ib0f25f288b9b87d2e4131297c552e5971696db87
2017-01-11 11:11:19 -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
Geoffrey Mon
e70c4eb664 Add tags support to patrol, protect, unblock, and undelete
- Add 'tags' parameters to appropriate API modules
- Add tag-adding logic to appropriate functions that carry out
  relevant functions
- ManualLogEntry::{set,get}Tags to handle adding tags to log
  entries in a cleaner fashion
- Use ManualLogEntry::setTags in LocalFile::recordUpload2

Bug: T97720
Change-Id: I98c52da7985623bfdafda2dc2dae937b39b72419
2016-02-29 16:59:31 -05: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
32ff1f4c47 Remove various unused variables
Change-Id: I4b1b20b4126735cb32a80e473fe48d523bcb24d1
2015-11-07 21:22:17 +00:00
Brad Jorsch
05ff357a42 API: Log all deprecated parameter uses to api-feature-usage.log
Some were being logged, and some weren't. Let's log them all
automatically when PARAM_DEPRECATED is processed, instead of requiring
each module to manually log them.

Bug: T117569
Change-Id: Ia38aeeccd0b9857b12b28914f509284483fbcca8
2015-11-03 12:23:00 -05: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
jenkins-bot
4fa0240228 Merge "API: Overhaul ApiResult, make format=xml not throw, and add json formatversion" 2015-04-16 01:05:51 +00: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
ac6f81d9ad Clean up handling of 'infinity'
There's a bunch of stuff that probably only works because the database
representation of infinity is actually 'infinity' on all databases
besides Oracle, and Oracle in general isn't maintained.

Generally, we should probably use 'infinity' everywhere except where
directly dealing with the database.

* Many extension callers of Language::formatExpiry() with $format !==
  true are assuming it'll return 'infinity', none are checking for
  $db->getInfinity().
* And Language::formatExpiry() would choke if passed 'infinity', despite
  callers doing this.
* And Language::formatExpiry() could be more useful for the API if we
  can override the string returned for infinity.
* As for core, Title is using Language::formatExpiry() with TS_MW which
  is going to be changing anyway. Extension callers mostly don't exist.
* Block already normalizes its mExpiry field (and ->getExpiry()),
  but some stuff is comparing it with $db->getInfinity() anyway. A few
  external users set mExpiry to $db->getInfinity(), but this is mostly
  because SpecialBlock::parseExpiryInput() returns $db->getInfinity()
  while most callers (including all extensions) are assuming 'infinity'.
* And for that matter, Block should use $db->decodeExpiry() instead of
  manually doing it, once we make that safe to call with 'infinity' for
  all the extensions passing $db->getInfinity() to Block's contructor.
* WikiPage::doUpdateRestrictions() and some of its callers are using
  $db->getInfinity(), when all the inserts using that value are using
  $db->encodeExpiry() which will convert 'infinity'.

This also cleans up a slave-lag issue I noticed in ApiBlock while
testing.

Bug: T92550
Change-Id: I5eb68c1fb6029da8289276ecf7c81330575029ef
2015-03-13 11:19:53 -04:00
JuneHyeon Bae
511525a136 Refactor out 'infinity' variants
Refactor out 'infinity' vartiant values which used in blocking and
protecting actions. This patchset adds GlobalFunction wfIsInfinity.

Bug: T68646
Change-Id: I60cc55a5bbd43c72916a1c2ea3807457d4e33765
2015-03-12 16:38:02 +00: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
fdddf94570 API: Overhaul token handling
The current token handling is a mess. This simplifies things greatly:
* *All* tokens are obtained from action=query&meta=tokens, rather than
  being spread over action=tokens, action=query&prop=info,
  action=query&prop=revisions, action=query&prop=recentchanges, and
  action=query&prop=users. All these old methods are deprecated.
* Similarly, there is only one hook to register new token types. All old
  hooks are deprecated.
* All tokens are cacheable.
* Most token types are dropped in favor of a 'csrf' token. They already
  were returning the same token anyway.
* All token-using modules will document the required token type in a
  standard manner in action=help and are documented in machine-readable
  fashion in action=paraminfo.

Note this will require updates to all extensions using tokens.

Change-Id: I2793a3f2dd64a4bebb0b4d065e09af1e9f63fb89
2014-08-26 14:53:45 -04:00
Brad Jorsch
b5cd9e2f6b API: Log usage of various deprecated features
This will let us know how aggressively we can finally remove these.

Change-Id: I03fab36e921807e74fbabfa878756af254d89a1b
2014-08-14 16:51:14 -07: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
Kunal Mehta
e179b4f11b API: Allow 'infinity' as a valid protection expiry
Change-Id: If9eb1f3e835579f5c8b8be22297a1eb26beda4e7
2014-06-15 23:46:37 +00: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
Siebrand Mazeland
f077c4b1d6 Update formatting
Change-Id: I18aff576262479c9bb1c56eb8e1d1aaae200e4b1
2014-02-06 09:27:05 +01: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
Brad Jorsch
4101ab54f2 Cleanup watchlist preference usage
In general, the web UI does a check of the watchlist preferences along
the lines of "watch if watchdefault, or if watchcreations and the title
doesn't exist". So there's no way to have it watch edits but not
creations. Make the API behavior match this.

For API action=protect&watchlist=preferences, we want to use
'watchdefault' always to match the behavior of the web UI.

For Special:Upload, the code is all there to do a "watch if
watchdefault, or if watchcreations and the file doesn't exist". But for
some reason that code wasn't being used in favor of just using
watchcreations all the time. Fix that, too. And have the API use that
instead of checking if the file page exists.

Bug: 56766
Change-Id: I57fc46d9a97b3ea2169173727db842d0d7ecf81d
2013-11-08 20:12:55 +00:00
Brad Jorsch
c94454687f Return errors from WatchAction
Currently, WatchAction::doWatch and WatchAction::doUnwatch return true
always. Let's have them return a status object instead.

This also cleans up the handling of Status objects in some of the API
modules.

Change-Id: I9dd9f0fd499c37f29fa12bcdb6142238a1f11e4d
2013-06-20 15:51:05 -04:00
Yuri Astrakhan
0aa24ae558 Fixed many small spelling mistakes and php docs, var decl.
Change-Id: I1508ed7eb77e5e4f700fb63955d626c4f5915840
2013-03-10 23:45:51 -04:00
Antoine Musso
b2fba3f27f api: remove duplicate __contruct calls
For historical reasons, all our API class had a dummy __construct which
simply calls their parent constructor.  This patch removes all such
occurences to save out some bytes.

Change-Id: I667955d7821f780fc5ce23823d74dedb1729b9fa
2013-01-29 09:38:17 +01:00
Yuri Astrakhan
503cd2f4ae (bug 35885) remove api version string and parameter
API was using SVN's version keyword which GIT does not support.
All related methods were either removed, or for those that
could have been used from extensions, emptied out.
api.php?version now shows unrecognized param warning.

Change-Id: I910ca1448ed2ed697ac19b17c486d130aa1d7e03
2013-01-18 12:41:18 -05:00
umherirrender
99bc0ae1a5 Add hint for pipe-separated list to action=help
Also fix helptext for integer min/max for isMulti param

Change-Id: I84caf01ace8eefd9de4fe783a6cafac3201f2e0a
2012-07-29 10:48:52 +02:00
umherirrender
06166e334a (bug 38190) Add "required" flag to some token params
action=block/action=unblock can not have the token required because when
using the gettoken param, the token param can not set.

Change-Id: I15317f16c06f150d29c1b17de76f41a6cfa84820
2012-07-20 15:45:51 -07:00
Aaron Schulz
e6faa2fd76 Merge "escape HTML elements in docblock with double quotes" 2012-07-18 19:17:46 +00:00
Antoine Musso
4f5d2386f3 escape HTML elements in docblock with double quotes
Doxygen choke on text enclosed by '<' and '>' since it tries to
interpret them as HTML or XML elements. This patch adds double quotes
in includes/api/*.php files around the two following strings:

 <Firstname>.<Lastname>@gmail.com
 <Firstname><Lastname>@gmail.com

Which becomes:

 "<Firstname>.<Lastname>@gmail.com"
 "<Firstname><Lastname>@gmail.com"

Tested locally, it prevents doxygen 1.8.0 related warnings.

Change-Id: I36d82eb3fd4989ee3ffc65b0b527b83711d1ba69
2012-07-15 22:15:45 +02:00