Commit graph

379 commits

Author SHA1 Message Date
Umherirrender
778d266c2e api: Use ParserFactory on module creation
Change "Parser" to "ParserFactory" in object specs
and get a instance when needed

Bug: T343070
Change-Id: I9b65c272726bb0035f4cdca4fbf417a0a11375cb
2023-08-29 20:19:32 +02: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
jenkins-bot
b9b5b04477 Merge "API: Add metrics for query modules" 2023-06-29 08:55:04 +00:00
daniel
6914b11b8d API: Add metrics for query modules
This adds metrics for individual query modules, to break down
the timing currently lumped together in api.query.executeTiming.

This will allow us to track repsonse latency for individual query
modules on https://grafana.wikimedia.org/d/000000002/api-backend-summary

Change-Id: I590fd2aff231789d0b7d31403a5222531f2b458d
2023-06-29 08:28:04 +00:00
jenkins-bot
3ae994553e Merge "api: Replace deprecated ApiPageSet::getGoodPages in action=query" 2023-06-26 20:52:31 +00:00
James D. Forrester
83d72bc108 API: Replace deprecated calls to wfExpandUrl with UrlUtils::expand
Bug: T319340
Change-Id: Ic987f9381ac17e9e46504abdb2d07a5a94ba3b4a
2023-06-22 16:49:01 -04:00
Umherirrender
46b5580f4f api: Replace deprecated ApiPageSet::getGoodPages in action=query
Inject TitleFormatter and TitleFactory to improve the best case
(getGoodPages) to avoid calling the factory there instead of using
Title::getPrefixedText after calling factory

Bug: T339384
Change-Id: I21cf9b738cfdb1a418c10e48ec834efefccb6ab7
2023-06-16 22:38:33 +02:00
Amir Sarabadani
a5dac5d598 Start using ChangeTagsStore
Also some clean ups here and there

Bug: T245964
Change-Id: Ibf20eec3257a2dc54e3ccbe766b679ebdfbab8d9
2023-06-09 15:09:06 +02:00
Amir Sarabadani
1ff0188dbf api: Drop ApiQuery::getNamedDB() and ApiQueryBase::selectNamedDB()
Both deprecated in 1.39 and hard-deprecated. Unused in production and
allow us to clean up dependency of ApiQuery to LB.

Depends-On: Ia94618b7f58fcca72e903fd2e2e9f0aaa501ac24
Change-Id: Ie0322e5346b94932a2eddc0b7aad5a384768b888
2023-06-01 11:11:58 +00:00
Bartosz Dziewoński
f0b5d1623c Add 'preloadcontent' and 'editintro' in API prop=info
Deprecate 'preload', which only supported one way of generating
preloaded content, and was confused about empty string and null.

Bug: T45683
Change-Id: Ie9f123920b69e41a186bc1c1c5db1bc0a6092a75
2023-05-20 16:10:49 +03:00
jenkins-bot
62dcbdc6ab Merge "api: Use a temp placeholder for signature on preview/pst" 2023-05-10 05:32:25 +00: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
Bartosz Dziewoński
77927cc2fa Expose automatic temporary user info in the API
action=query&prop=info&intestactions=...:
  Add &intestactionsautocreate=1 to also check whether the actions
  would result in a creation of a temporary user account.

action=query&meta=siteinfo:
  Add &siprop=autocreatetempuser to output the configuration
  of temporary user accounts.

Bug: T335532
Change-Id: I62b4bb630decac92cbb8c7ddf00307df0dadb516
2023-04-28 01:42:59 +02: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
Derick Alangi
6eaba36617 search: Make TitleMatcher a MediaWiki service object
@note: Deprecated SearchEngine::getNearMatcher and ::getDefaultMatcher()
and begin using the new interfaces. Renamed SearchNearMatcher to depict
what it really does like TitleMatcher when searching.

Also, I pulled out SpecialSearchTestMockResultSet class to a separate
file.

Change-Id: I09990e9f263c075a6ab137ee5bcb7285359f057c
2023-02-03 12:35:14 +00:00
Umherirrender
07697bb57c api: Replace deprecated Linker::formatComment
Bug: T324906
Change-Id: I1fcb7bd9d84754793c07ac9e39e50c38b364e4c1
2022-12-11 00:56:46 +01:00
Timo Tijhof
58d2a3ad0f api: Deprecate ApiQuery::getNamedDB and ::selectNamedDB()
The Rdbms library already takes care of caching and re-using connections
nowdays. Perhaps in a past where DBConnRef was less common or not
yet created this made sense, but we've now adopted that universally.

I don't know of a current use case for WMF, given the removal of
non-vertical query groups in T263127 (e.g. we keep "api" for all API
traffic, but not e.g. something individual classes would change).

For now I've documented that in someone does run into this, perhaps
in third-party code, that we recommend instead to override getDB()
instead of relying on this central mechanism. E.g. overriddet getDB()
to return `wfGetDB(DB_REPLICA,'mygroup')`.

Bug: T263127
Change-Id: I4c3cc7868f1f4210ee655541eb6a45705c643c70
2022-08-22 13:51:46 +01:00
Amir Sarabadani
12e56b5575 api: Support for links migration in ApiQueryBacklinks
Bug: T312865
Bug: T314112
Change-Id: Ic30a658f9cce503a2afbca826a3b828e087f0e65
2022-07-29 16:46:53 +00: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
jenkins-bot
3d17e2dc52 Merge "api: Change UserOptionsLookup to GenderCache in list=users" 2022-04-14 22:48:00 +00:00
Umherirrender
7e706bd779 api: Change UserOptionsLookup to GenderCache in list=users
Getting only the gender option from the UserOptionsLookup is expensive,
because each option results in one query to load all options.
The GenderCache allows for prefilling the gender for multiple
users and results in only one query. That can make a difference if
multiple user names are requested.

Change-Id: Id954a636452d5729eb3b8050db4a0068bf02c9ed
2022-04-14 22:26:12 +00: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
Umherirrender
3fdc798fe6 Replace usage of deprecated Title::getFilteredRestrictionTypes
Change-Id: I68ff2e8a29c7d1b0a48b94c557ca660ec29f78c6
2022-04-11 23:05:19 +02:00
Alexander Vorwerk
9b09bf3112 Use updated ObjectFactory namespace
Depends-On: I99c5e5664d2401c36a9890f148eba7c25e6e8324
Depends-On: I48ab818b2965da14af15ef370aa83ad9455badd9
Depends-On: I018371e4b77911e56152ca7b2df734afc73f58a5
Change-Id: I04ebdb52102f6191d49a9cc70b1f98308299e72f
2022-03-09 23:04:51 +00:00
Umherirrender
e37d3d84b6 api: Remove ApiQueryBlocks::prepareUsername
The parameter is using the UserDef validation,
which provides all this features

Also all params are guarded to be set in the $params array after
extractRequestParams(), no need to use isset on $params.
Make explicit that empty bkusers= or bkids= are ignored,
instead using the implicit check in addWhereFld.
Doing nothing when requesting nothing would be a breaking change.

Change-Id: I3602412874b1b3a954037d95ad7cefbe865e3893
2022-02-19 14:42:04 +01:00
jenkins-bot
24373dab6b Merge "Replace Content::getParserOutput call to ContentRenderer::getParserOutput" 2021-10-20 17:56:19 +00:00
Roman Stolar
fa5237eb48 Replace Content::getParserOutput call to ContentRenderer::getParserOutput
Bug: T287158
Change-Id: I8a13f45027e08e2d8ddefa140dd47a0c55094934
2021-10-20 12:11:24 +03:00
jenkins-bot
3c697fd5ee Merge "api: Inject services into ApiQuery class" 2021-10-19 20:16:07 +00:00
jenkins-bot
e7f4484611 Merge "Make first char of username in ApiQueryAllUsers case-insensitive" 2021-10-05 20:57:54 +00:00
Tim Starling
f7f84dddb3 Introduce CommentFormatter
CommentParser:

* Move comment formatting backend from Linker to a CommentParser service.
  Allow link existence and file existence to be batched.
* Rename $local to $samePage since I think that is clearer.
* Rename $title to $selfLinkTarget since it was unclear what the title
  was used for.
* Rename the "autocomment" concept to "section link" in public
  interfaces, although the old term remains in CSS classes.
* Keep unsafe HTML pass-through in separate "unsafe" methods, for easier
  static analysis and code review.

CommentFormatter:

* Add CommentFormatter and RowCommentFormatter services as a usable
  frontend for comment batches, and to replace the Linker static methods.
* Provide fluent and parametric interfaces.

Linker:

* Remove Linker::makeCommentLink() without deprecation -- nothing calls
  it and it is obviously an internal helper.
* Soft-deprecate Linker methods formatComment(), formatLinksInComment(),
  commentBlock() and revComment().

Caller migration:

* CommentFormatter single: Linker, RollbackAction, ApiComparePages,
  ApiParse
* CommentFormatter parametric batch: ImageHistoryPseudoPager
* CommentFormatter fluent batch: ApiQueryFilearchive
* RowCommentFormatter sequential: History feed, BlocklistPager,
  ProtectedPagesPager, ApiQueryProtectedTitles
* RowCommentFormatter with index: ChangesFeed, ChangesList,
  ApiQueryDeletedrevs, ApiQueryLogEvents, ApiQueryRecentChanges
* RevisionCommentBatch: HistoryPager, ContribsPager

Bug: T285917
Change-Id: Ia3fd50a4a13138ba5003d884962da24746d562d0
2021-09-28 11:13:03 -07:00
Fomafix
213d45e5dd Make first char of username in ApiQueryAllUsers case-insensitive
This change uses $contentLanguage->ucfirst( $name ) to get the
canonical username like this is done in UserNameUtils::getCanonical().
This makes the first character case-insensitive. The toUpperCase() in
JavaScript is not needed anymore.

toUpperCase() in JavaScript and $contentLanguage->ucfirst() in PHP
differ on some characters:
* JavaScript: "ß".toUpperCase() // "SS"
* PHP: $contentLanguage->ucfirst( "ß" ) // "ß"

Bug: T291339
Change-Id: Id9afb2dd0212e4b871bb6a7a9d8762e1bcb81d6a
2021-09-21 06:21:21 +00:00
Umherirrender
5e7cd5fdd1 api: Inject services into ApiQuery class
Bug: T259960
Change-Id: I64b0c62f0c51e10c799794d8ad399dd8428f63b5
2021-09-17 00:57:37 +02:00
jenkins-bot
76ba780e41 Merge "WikiExporter: inject services" 2021-09-16 17:04:04 +00:00
Umherirrender
07b499fbcf build: Update mediawiki/mediawiki-phan-config to 0.11.0
Addition and remove of suppression needs to be done with the version
update.

Change-Id: I3288b3cefa744b507eadebb67b8ab08c86517c1c
2021-09-07 17:19:05 +02:00
Alexander Vorwerk
2fbf13812a WikiExporter: inject services
This patch injects services into WikiExporter. It also adds a
WikiExporterFactory service for creating WikiExporter instances.

Change-Id: Ib1547defea54c309865c116bc83d617c21568843
2021-09-06 10:03:37 +00:00
Umherirrender
5b3d3ef802 collation: Create CollationFactory service
Use ObjectFactory specs for collation classes
Avoid the language construction in the factory class,
make it a detail of the implementation of each class

Follow-Up of Ifc96f851e6091ce834dbaf0e91695c648a42169c

Bug: T286079
Change-Id: Ib581f64aec8619986fb8dd49ceee0524d59a1b84
2021-09-04 02:46:06 +02:00
Umherirrender
de676bd359 API: Change object specs for remaining un-serviced API modules
There are no services yet to use on these API modules.
Prepare for easier injection for the future.

Modules are:
- ApiLogout
- ApiRsd
- ApiTokens
- ApiCheckToken
- ApiCSPReport
- ApiEmailUser
- ApiRevisionDelete
- ApiManageTags
- ApiFormatJson
- ApiFormatPhp
- ApiFormatXml
- ApiFormatNone
- ApiQueryCategories
- ApiQueryCategoryInfo
- ApiQueryExternalLinks
- ApiQueryBacklinksprop
- ApiQueryImages
- ApiQueryIWLinks
- ApiQueryAllCategories
- ApiQueryMyStashedFiles
- ApiQueryBacklinks
- ApiQueryCategoryMembers
- ApiQueryExtLinksUsage
- ApiQueryIWBacklinks
- ApiQueryLangBacklinks
- ApiQueryPagesWithProp
- ApiQueryPagePropNames
- ApiQueryRandom
- ApiQueryTags
- ApiQueryTokens

Also normalize use of trailing commas.

Bug: T259960
Change-Id: Ibe8a79abf6fce70713775d07d4f4b5a1338934f6
2021-09-03 23:23:03 +00:00
Roman Stolar
3d1f0d7f7a Replace Content::preSaveTransform call to ContentTransformer::preSaveTransform
Bug: T287156
Change-Id: I5709441318abc210b3d3beb0be6f2bcbe45ddd36
2021-08-19 20:29:28 +03:00
DannyS712
18d732811d ApiQueryInfo: add associatedpage prop
Returns the prefixed title for the associated page,
if it could exist (i.e. does not do anything for special pages)

Bug: T257014
Change-Id: I49cdc138c6182b323c4933e90dc96c5e06b6ccba
2021-07-09 19:48:20 +00:00
Umherirrender
aa39959bc6 api: Inject GroupPermissionsLookup into modules
Remove the @internal getter for the global and
use MediaWikiServices directly at one remaining place.

Change-Id: I120f9c00d22d6dcf2a996eec5b9d5e5d41b68284
2021-07-06 20:48:35 +00:00
Umherirrender
84d1542e67 api: Inject services into ApiQuery(All)(Deleted)Revisions
All classes extending ApiQueryRevisionsBase, for searching:
ApiQueryAllRevisions, ApiQueryAllDeletedRevisions
ApiQueryRevisions, ApiQueryDeletedRevisions

Including services for the ApiQueryRevisionsBase class

Bug: T259960
Change-Id: I001a9d39355becacab2e34a00027d04ddf7602b5
2021-07-05 20:03:06 +02:00
jenkins-bot
caa36dbcb9 Merge "api: Inject services into ApiQueryFileRepoInfo" 2021-07-05 17:13:02 +00:00
jenkins-bot
195fb38405 Merge "api: Inject services into ApiQueryImageInfo/ApiQueryStashImageInfo" 2021-07-04 23:41:42 +00:00
DannyS712
27d9452f6d Inject dependencies into SearchApi
Used in api classes where services can be injected,
no need to rely on MediaWikiServices

Will make it possible to convert ApiOpenSearchTest to
a unit test, since everything is injected, but that will be
done in a follow-up

Plus some minor cleanup to SearchApi

Change-Id: If0a3a60f1ead897947143b57d98a3a506387f6d5
2021-07-04 10:58:36 +00:00
jenkins-bot
b700db02a1 Merge "api: Replace deprecated language variant functions in ApiQueryInfo" 2021-07-03 23:24:24 +00:00
jenkins-bot
81cdb1fd5a Merge "api: Inject services into ApiQueryWatchlistRaw/ApiQueryWatchlist" 2021-07-03 23:23:01 +00:00
jenkins-bot
1789a62021 Merge "api: Inject services into ApiQueryAllMessages" 2021-07-03 23:22:54 +00:00
jenkins-bot
3902829693 Merge "api: Inject services into ApiQueryAllImages" 2021-07-03 23:22:48 +00:00