Commit graph

108 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
Taavi Väänänen
3f4cb7969d
api: Fix PSR2.Classes.PropertyDeclaration.Multiple errors
Change-Id: I7859191740d66d00595c4bdeea12b227ac25bcc5
2024-04-21 23:05:59 +03: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
c03cb71796 Use real type hints for services etc. in api/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: Ie78be1c614985d7c2964156e454cc9266515dc18
2023-08-29 01:02:40 +00:00
Timo Tijhof
8207004738 LinkBatch: Re-apply makeWhereFrom2d/constructSet exception
Follows-up Ifdf3ea54 (678326e6fb) and its
partial revert I665c3a6e8 (d48115b2bf).

Bug: T336964
Bug: T336980
Change-Id: Ia5d8f652d6d1522543ebb8338e68f5ccd8742dac
2023-06-15 21:30:07 +00:00
James D. Forrester
ad06527fb4 Reorg: Namespace the Title class
This is moderately messy.

Process was principally:

* xargs rg --files-with-matches '^use Title;' | grep 'php$' | \
  xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1'
* rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \
  xargs rg --files-with-matches 'Title\b' | \
  xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1'
* composer fix

Then manual fix-ups for a few files that don't have any use statements.

Bug: T166010
Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a
Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
2023-03-02 08:46:53 -05:00
Tim Starling
0077c5da15 Use short array destructuring instead of list()
Introduced in PHP 7.1. Because it's shorter and looks nice.

I used regex replacement.

Change-Id: I0555e199d126cd44501f859cb4589f8bd49694da
2022-10-21 15:33:37 +11:00
Bartosz Dziewoński
a8c9e98661 Deduplicate code for parsing API 'continue' parameters
30+ API modules had nearly identical code to split and validate
the value of the 'continue' parameter.

Introduce the ApiBase::parseContinueParamOrDie() method and use it to
replace most usages of ApiBase::dieContinueUsageIf(). A few remain in
modules with more complex continuation handling.

Inline most single-use variables that remained after validation was
moved into the new method.

Change-Id: I66bd59ecd4ad16e2039e90f7d66cfa276e6c1c2a
2022-09-29 16:05:31 +00:00
Bartosz Dziewoński
00b74a0e4b Use buildComparison() instead of raw SQL in more API modules (easy cases)
See ec79aa3943 about the new method.

These changes all follow the same simple patterns. More complex cases
are handled in I6231b6beae13474d4986929367a9adc6bb76b0db.

This commit was created by running the following terrible Ruby script
I devised: https://phabricator.wikimedia.org/P34833, then manually
reviewing the results: checking that the output makes sense in general,
that the affected variables are not used elsewhere in the file, and
that no comparison conditions have been lost. A few incorrect changes
were undone or corrected.

Change-Id: I8ed363bd6b80a9481d44434a526f078cce20220f
2022-09-29 16:04:23 +00:00
jenkins-bot
c624357cb7 Merge "api: Report external titles in more places as apierror-invalidtitle" 2022-08-05 01:07:04 +00: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
d79fd02d4b Use injection for LinksMigration on LinkBatch, action, api, special page
Even the service does not long stay in that classes,
it should be injected to avoid global state

Bug: T304780
Change-Id: Ib488037f5a6966ab61042ed3cd889ddc50f1ba8e
2022-05-10 20:19:58 +00:00
Amir Sarabadani
43fc4c43a5 api: Add support for linksmigration in ApiQueryLinks
Bug: T304780
Change-Id: I958ddd996b1f3ed2ef1b085cb6c8827612680e24
2022-05-09 07:22:29 +02:00
Umherirrender
00bc7a2b28 api: Report external titles in more places as apierror-invalidtitle
It is only useful to use local titles for various api parameters

Change-Id: Ife2a951e6b48b59e2b77d455c8343f79f1163b0a
2022-04-16 19:28:45 +00:00
Umherirrender
19753b0d45 api: Replace ApiPageSet::getGoodTitles where PageIdentity is not used
Change-Id: I6097c3e2e75715d40e067b6913849e930f40c876
2022-02-11 20:11:24 +00:00
Umherirrender
3b0d82baf6 api: Inject services into ApiQueryLinks
Bug: T259960
Change-Id: I523a1b95b305fbd4fdec0addb3e77494809fd517
2021-07-02 14:38:45 +00:00
Tim Starling
9c3c0b704b Use array_fill_keys() instead of array_flip() if that reflects the developer's intention
array_fill_keys() was introduced in PHP 5.2.0 and works like
array_flip() except that it does only one thing (copying keys) instead
of two things (copying keys and values). That makes it faster and more
obvious.

When array_flip() calls were paired, I left them as is, because that
pattern is too cute. I couldn't kill something so cute.

Sometimes it was hard to figure out whether the values in array_flip()
result were used. That's the point of this change. If you use
array_fill_keys(), the intention is obvious.

Change-Id: If8d340a8bc816a15afec37e64f00106ae45e10ed
2021-06-15 00:11:10 +00:00
Thiemo Kreuz
08cf4c49df Add PHPDoc documentation to all API query module constructors
Change-Id: I2bc140576efc891bb9b6e50e44041d5bb022ac8f
2020-10-27 19:16:41 +00:00
Umherirrender
ac9fbbaca5 Use LinkBatchFactory in api modules
Change-Id: Ie3a445af44de273b1591eb2ddc5281eb2c955cd5
2020-09-06 09:32:16 +00:00
Reedy
b80a9f4f6a Fix even more PSR12.Properties.ConstantVisibility.NotFound
Change-Id: I5e04824d6fa6a4c36ce489850bb0ed7b4ac588f9
2020-05-16 00:51:14 +01: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
c7ad21c25f Improve param docs
Change-Id: I746a69f6ed01c3ff000da125457df62b02d13b34
2019-11-28 19:08:59 +01:00
Umherirrender
731d9f748e Run GenderCache for api query modules using ApiQueryBase::addTitleInfo
When converting a Title object into a string for user or user talk
namespace the gender information are needed.

This patch set improves performance on wikis with gender distinction
like dewiki or ruwiki by combining the fetch of the information into one
query and avoids a query per unique user name.
It also avoids false results for request with apihighlimit, because the
apihighlimit with 5000 is higher than the query max limit of the
GenderCache with 1000

Bug: T200238
Change-Id: Ibe0561b210dbeb654117dad777e839640f51b4e4
2019-11-02 22:23:23 +01:00
Reedy
4691389fa4 Use (int) rather than intval()
Bug: T216969
Change-Id: I4c06716c83b69d128f26fa7f68736808aa2d3d64
2019-02-25 00:38:33 +00:00
Max Semenik
6e956d55aa Replace call_user_func_array(), part 2
Uses new PHP 5.6 syntax like ...parameter unpacking and
calling anything looking like a callback to make the code more readable.
There are much more occurrences but this commit is intentionally limited
to an easily reviewable size.

In one occurrence, a simple conditional instead of trickery was much more readable.

This patch finishes all the easy stuf in the core, the remainder is either unobvious
or would result in smaller readability gains. It will be carefully dealt with in
further commits.

Change-Id: I79a16c48bfb98b75e5b99f2f6f4fa07b3ae02c5b
2018-06-07 20:19:26 -07: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
Brad Jorsch
9f86261000 API: Account for PHP 7.2 change
PHP 7.2 broke existing functionality in making count( null ) raise a
warning. So add tests for null all over the place, or change tests where
we know the value is null or an array (but not false, empty-string, or
0) to just cast to boolean.

Bug: T182004
Change-Id: Idfe23a07daa9f60eee72f2daf04304be87057a29
2017-12-04 13:46:33 -05:00
Brad Jorsch
8c36aa3373 ApiQueryLinks: Avoid MySQL order-by bug
MySQL (and MariaDB) have a strange bug where it will often get confused
and insist on filesorting if a field that is constant in the WHERE
clause is also present in ORDER BY. We've worked around this in several
places in the API, and in fact it was done in this very module in r34720
and r37250.

But when r67450 added the pltitles and tltemplates parameters, it didn't
adjust the logic for avoiding the DB bug. This does that now.

Change-Id: I9f37f8812a94cdd088d3940da43d1046ebd455d6
2017-10-13 00:27:01 +00:00
Brad Jorsch
61de3c3e61 API: Handle pltitles/tltemplates/clcategories/imimages with only invalid titles
If the parameter contains only invalid titles, it shouldn't be ignored.

Bug: T162816
Change-Id: I3ee6aeab421db5732b652fed21292d8509f8d757
2017-10-12 15:48:15 +00:00
Brad Jorsch
f3926df575 ApiQueryLinks: Remove index forcing
Appears to have been added for T16102, which has hopefully been fixed
since. Let's try it and see if queries break.

Bug: T162774
Change-Id: If60442b9c8856b80a071ed9df830f9a3397218c9
2017-09-06 08:53:44 +00:00
Reedy
0f13fff160 Convert UNIQUE keys into PRIMARY KEY
WMF DBAs have been doing a massive effort to convert UNIQUE KEYS into
PRIMARY KEY.

Having a PK is essential to do maintenance, specially on large tasks.
By not having a PK it is impossible to add it in a safe way if not done
directly on the master.

Having a PK means that we can easily change the PK into another one if
needed in the future. The ones we chose might not be the best ones, but
will allow us to get them changed.

Bug: T172514
Change-Id: Id635297838938c7c5dfe65d45285a4d16d65152d
2017-08-29 18:25:37 +01:00
Reedy
7e18aed900 Don't declare ApiQueryLinks::$titlesParam dynamically
Change-Id: Ie7b553b2d368766df2c3989d58e42f1b6d3d6779
2017-08-04 19:12:29 +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
47e2bec361 API: Allow finding log events and links to special pages
Log events are sometimes attributed to a special page; it should be
allowed to use rcnamespace or lenamespace to filter for these.

It's also possible for special pages to be the targets of redirects, so
list=allredirects and prop=redirects should find them.

Maybe someday we'll record links to and transclusions of special pages
too (see T19597), so we may as well make it possible to query for those
as well via list=alllinks, list=alltransclusions, list=backlinks,
list=embeddedin, prop=linkshere, prop=transcludedin, prop=links, and
prop=templates.

NS_MEDIA has similar considerations: although we currently "normalize"
page links to the corresponding File and I don't think anything logs the
Media title rather than the File, transclusions and redirects do show
up in those tables.

Bug: T154319
Change-Id: I00348f83855c6c703b6bd6015f6d3bedc5bfd1c5
2017-01-06 13:07:29 -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
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
RobinHood70
15ecc5a93a Update getHelpUrls() for reworked mw.org API pages
Community members restructured the mediawiki.org API pages, e.g.
the meta allmessages query submodule is no longer in the catch-all
https://www.mediawiki.org/wiki/API:Meta?oldid=1408361#allmessages_.2F_am
but its own https://www.mediawiki.org/wiki/API:Allmessages

The links in the generated API help, e.g.
https://www.mediawiki.org/wiki/Special:ApiHelp/query+allmessages,  are no
correct. They're not 404s but they don't take you directly to the
relevant page.

This patch set fixes the getHelpUrls() URLs (and does nothing else).
I tested them all.

Thanks RobinHood70!

Change-Id: Icea94abdd22d1ad468172642a21641e7c5ce2046
2015-05-04 08:15:54 +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
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
Thiemo Mättig
23632a4ecd Use precise ApiMain/ApiQuery type hints in all API modules
Which type is used depends on the ApiModuleManager responsible for
the API module. There are two managers, one in ApiMain and one in
ApiQuery. Both contain a list of API modules they instantiate.
Both use $this as the first parameter in the constructors of the
individual modules. There is no other regular way to instantiate the
modules, so we know the type must either be ApiMain or ApiQuery.

The lists don't intersect.

I would have prefered the naming scheme $mainModule for ApiMain
modules and $queryModule for ApiQuery modules but since this
doesn't add much I left the shorter variable names untouched.

Change-Id: Ie6bf19150f1c9b619655a06a8e051412665e54db
2014-05-16 11:07:23 -04:00
addshore
719d7a2f03 Add final period to API module descriptions
Change-Id: Icae68c1ab1fd0006e00a3a9a56ae8f831d3d0d45
2014-03-10 09:04:08 +00:00
Siebrand Mazeland
4c3bc3f865 Add/update/remove incomplete/incorrect documentation
Change-Id: I3c2c7f61d9a579ad794ce7b564ccc8a7cfb9b6fc
2013-11-17 21:53:34 +00:00
Siebrand Mazeland
770f2a2d41 Fix CodeSniffer errors and warnings (you guessed it, on API classes)
Change-Id: I56f9632975d53bdfe33ff9412e1a4ba010bdb2aa
2013-11-15 18:08:13 +00:00
Siebrand Mazeland
789c20044b Update formatting, return of the API classes
Change-Id: I8c3a5b4396a1c3bba22f676137f640c6aa3c8960
2013-11-14 18:25:45 +00:00
umherirrender
d63121016d fix some spacing
Added/removed spaces around logical/arithmetic operator
Reduced multiple empty lines to one empty line
Removed wrong tabs before comments at end of line
Removed too many spaces in assigments

Change-Id: I2bba4e72f9b5f88c53324d7b70e6042f1aad8f6b
2013-03-07 17:53:21 +01:00
Reedy
bb9241b54f Fix double colons in api help output
Get links from the [[Main Page]]::
    api.php?action=query&prop=links&titles=Main%20Page
  Get information about the link pages in the [[Main Page]]::
    api.php?action=query&generator=links&titles=Main%20Page&prop=info
  Get links from the Main Page in the User and Template namespaces::
    api.php?action=query&prop=links&titles=Main%20Page&plnamespace=2|10

Change-Id: I3645bd72d80aef3f99da7f8f5fa1d63a1b28ad78
2013-01-30 19:19:18 +00: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