aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/api/query
Commit message (Collapse)AuthorAgeFilesLines
* Namespace all remaining files in includes/skinJames D. Forrester2025-03-251-1/+1
| | | | | Bug: T353458 Change-Id: I3e829e35c93bcaae75e401b1801bddf93c0b416c
* Namespace all remaining files in includes/recentchangesJames D. Forrester2025-03-202-2/+2
| | | | | Bug: T353458 Change-Id: I2ae4577de79832b082adca282ff73cfabc8f9392
* Namespace all remaining files in includes/filerepoJames D. Forrester2025-03-191-1/+1
| | | | | Bug: T353458 Change-Id: I35864ad9bd48701703c51367d62f8ebde963c52d
* ApiQueryBlock: Don't return page restrictions when pages were deletedDayllan Maza2025-03-181-1/+2
| | | | | | | | * Special:Block and Special:BlockList ignore restrictions if the page has been removed. ApiQueryBlocks now matches that behavior Bug: T388511 Change-Id: I525fbf73eec6f4a62bd6244b2a14e71130c7e602
* Merge "block: Add localized duration to API responses"jenkins-bot2025-03-101-2/+7
|\
| * block: Add localized duration to API responsesTim Starling2025-03-101-2/+7
| | | | | | | | | | | | | | | | | | | | | | | | * Add duration-l10n to BlockLogFormatter with a localized duration string * Add duration-l10n to ApiQueryBlocks * Fix bug in Language::formatDurationBetweenTimestamps() which caused it to be off by one hour if the specified timestamp straddled a daylight savings boundary. Bug: T388089 Change-Id: Ie88ca47053b2b9d6e3119aff5374e676d1835a44
* | ApiQuerySiteInfo: Expose same PHP Libraries as SpecialVersionReedy2025-03-081-1/+3
|/ | | | | Bug: T355722 Change-Id: Ica70fd7be1bd8f988d1d18c37d3571ab94256e3f
* block: DatabaseBlock constructor caller migrationTim Starling2025-03-042-42/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | There's about 100 callers of the DatabaseBlock constructor in core tests, most of them passing an address parameter which needs access to the global service container to parse. Many are passing the constructed object straight to DatabaseBlockStore::insertBlock(). So add insertWithParams() for their convenience, which has some handy shortcut parameters, has service access, and throws on failure. The calling code tends to be shorter than before. For unit tests trying to construct DatabaseBlock objects without a service container, direct construction of BlockTarget subclasses is warranted. Add a default to the $wikiId parameters for their convenience. MockBlockManager had its own 'target' parameter, mixed in with block options, carrying its own special idea of a target, which conflicted with DatabaseBlock's new 'target' parameter. Harmonise the parameters and fix the callers. Bug: T382106 Bug: T385966 Change-Id: I78b45a6003b62962211379c36da5587081f90f00
* ApiQuerySiteinfo: Support $wgGroupInheritsPermissionsKevin Israel2025-02-191-2/+7
| | | | | | | | | | | | | | I noticed that the "confirmed" group was missing from the API result on en.wikipedia.org. It is defined using $wgGroupInheritsPermissions, not $wgGroupPermissions. Rather than only using the latter, obtain lists of user groups and granted permissions from UserGroupManager and GroupPermissionsLookup respectively (and not just for filtering undefined groups out of the lists of changeable groups). Bug: T357846 Change-Id: I473868449dcf360afcba3c731ac7f282b623b1cd
* ApiQueryInfo: Check for blocks against the requesting userThalia2025-02-051-0/+47
| | | | | | | | | | | | | | | | | | | | | | | | | Why: * When requesting information about an action that will cause a temporary user to be autocreated, permissions are checked against a placeholder temporary account. * Blocks are also checked against a placeholder temporary account, meaning that blocks are not checked against the IP address and other parts of the request object. * This causes incorrect block information to be returned, e.g. that there is no block when there is in fact a block against the IP address. * This is causing a bug in the mobile web editor, where the user only gets notified that they are blocked from editing after they submit the edit, instead of when the editor loads. What: * Check for blocks against the global session user in ApiQueryInfo::extractPageInfo. Bug: T357063 Change-Id: I942901f4f3a6845c2572623955e6a26d49954ca7
* build: Updating mediawiki/mediawiki-codesniffer to 46.0.0libraryupgrader2025-01-311-1/+1
| | | | Change-Id: I0f8a8cac36015bba52aea3ee2affd92f83d3574a
* block: Fix HideUserUtils error when user is hidden twiceTim Starling2025-01-101-2/+4
| | | | | | | | | | | * Add a limit to the HideUserUtils subqueries to avoid error "Subquery returns more than 1 row". We really want to know if at least one row exists. * Fix outdated doc comment * Add tests. Bug: T382399 Change-Id: Ib3bc22e0b3080b3ae6e1d2591ac7f2a1ef57c6b3
* Add ApiQueryCheckCanExecute hookGergő Tisza2024-12-031-0/+24
| | | | | | Adds the equivalent of ApiCheckCanExecute for query modules. Change-Id: I88effab746544c4788b607059a2184ead5b1bbac
* PHPUnit: Use FQCN with leading backslash in @covers annotationFomafix2024-11-1922-23/+23
| | | | | | | | | | | https://docs.phpunit.de/en/11.4/annotations.html#covers recommends: > Please note that this annotation requires a fully-qualified class > name (FQCN). To make this more obvious to the reader, it is > recommended to use a leading backslash (even if this not required for > the annotation to work correctly). Change-Id: I7eb4b997346387e5799fa27a61ab317573124fd0
* tests: Avoid repeated calls to setGroupPermissions in same testUmherirrender2024-10-311-2/+6
| | | | | | | setGroupPermissions() calls overrideConfigValue() for each config, that is not needed and can be combined into one call Change-Id: I5156b10c9df14773eaaf488d5bacfacd8846a80e
* Use ++ and -- rather than += 1 and -= 1Reedy2024-10-171-3/+6
| | | | Change-Id: I27b9a19ab952ede1267921bd042af0fe1c89e228
* Use explicit nullable type on parameter argumentsUmherirrender2024-10-161-2/+2
| | | | | | | | | | | Implicitly marking parameter $... as nullable is deprecated in php8.4, the explicit nullable type must be used instead Created with autofix from Ide15839e98a6229c22584d1c1c88c690982e1d7a Break one long line in SpecialPage.php Bug: T376276 Change-Id: I807257b2ba1ab2744ab74d9572c9c3d3ac2a968e
* Add namespace to includes/api classesJames D. Forrester2024-09-2525-33/+33
| | | | | Bug: T353458 Change-Id: I3ea6b08c5018ba03ba45c5766e1f46e12f6b8597
* tests: Consistently use class_alias comments like elsewhereJames D. Forrester2024-09-251-0/+1
| | | | | | Found via `[^*][^\\]\nclass_alias`. Change-Id: I9732f75226445f48fb131c432b209d0fd3eba1ba
* Update user widgets to support named and temp account exclusionJamie Kuppens2024-09-161-10/+161
| | | | | | | | | | | | | | | * This change introduces two new optional parameters to the 'allusers' API call named 'excludenamed' and 'excludetemp' that allows filtering accounts based on whether they're named accounts or temporary accounts. This is tested by using the temporary matchPattern configured with $wgAutoCreateTempUser. * User widgets that call 'allusers' have been updated so that 'excludenamed' and 'excludetemp' can be optionally set so that named or temporary accounts may not returned with user suggestions. Bug: T332030 Change-Id: I6563ae610017fd1cd35c36ba65906041f7f68c4b
* tests/api: Add missing documentation to class propertiesUmherirrender2024-09-108-2/+13
| | | | | | | | | | Add doc-typehints to class properties found by the PropertyDocumentation sniff to improve the documentation. Once the sniff is enabled it avoids that new code is missing type declarations. This is focused on documentation and does not change code. Change-Id: I48014b6464f3e7e2b7f083e67f517af0b1a9367e
* tests: Use const for some static data in test filesUmherirrender2024-09-011-65/+65
| | | | Change-Id: Id7ccd48e3bf626095e2d3929831b5d87ed0be948
* tests: Make use of ??= and ?? operators in various teststhiemowmde2024-08-151-3/+1
| | | | | | | The main benefit is that this syntax avoids repeating the variable name. It does the same as before. Change-Id: I2040be889c749f4e2416ca9948ba261345858af2
* Move Language and friends into Language namespaceJames D. Forrester2024-08-101-2/+2
| | | | | Bug: T353458 Change-Id: Id3202c0c4f4a2043bf97b7caee081acab684155c
* Add MediaWiki\Registration namespace to registration classesEbrahim Byagowi2024-08-101-1/+1
| | | | | Bug: T353458 Change-Id: Ifa3b6a6e0353bb4ce21a3f4456f1fc696c8d377c
* Add namespace to WikitextContentEbrahim Byagowi2024-08-062-2/+2
| | | | | | | It adds MediaWiki\Content namespace to WikitextContent and two classes related. Change-Id: Ib74e4c5b3edac6aa0e35d3b2093ce1d0b794cb6d
* Filter temporary accounts as anonymous in ApiQueryRecentChangesSTran2024-07-291-8/+40
| | | | | | | | | | | | Edits from temporary accounts are considered anonymous edits. ApiQueryRecentChanges doesn't correctly reflect this and needs to be updated to correctly return temporary account edits as anonymous (and similarly, not to return them when requesting !anon) - Update the anon|!anon query to accomodate temporary accounts Bug: T370803 Change-Id: Ica5225422ea53d2aa3a84b86d9c2f14832a34ed4
* RecentChange: Replace use of legacy error arraysBartosz Dziewoński2024-07-091-1/+1
| | | | | | | | | | | Replace uses of soon-to-be-deprecated methods: * ApiBase::errorArrayToStatus * PermissionStatus::toLegacyErrorArray Deprecate and replace uses of: * RecentChange::doMarkPatrolled Change-Id: I2311d1fa3772ba6be378ad6f497ed4c0df9b7aa8
* ApiQueryWatchlistIntegrationTest: Disable temp account in anon editKosta Harlan2024-06-261-2/+2
| | | | | | | | | | | | | | | | | Why: - The test class does anonymous edits, but did not first disable temp user creation What: - Disable temp user creation before attempting an anonymous edit - Enable temp account feature when calling doTempPageEdit - Remove call to enableAutoCreateTempUser in testShowAnonParamsTemp, as it's no longer needed Bug: T365669 Change-Id: I2ce83d5703ecc75fe680d7ddb44aa406c26c4df5
* ApiQueryUserContribsTest: Disable temp account featureKosta Harlan2024-06-261-0/+5
| | | | | | | | | | | | | Why: - This test exercises code that checks for IP edits What: - Disable temp user feature for this test class Bug: T365669 Change-Id: If385b71b76c16f9276c3973a02ca0c888b47d3a3
* ApiQueryRecentChangesIntegrationTest: Fixes for temp accountsKosta Harlan2024-06-261-2/+3
| | | | | | | | | | | | | | | | | Why: - This test does not pass when temp accounts are enabled What: - Set disableAutoCreateTempUser when doing an anon page edit - Set a valid pattern for the temp user name This patch does not fix testUserPropParameter but does solve the other failures for this class. Bug: T365669 Change-Id: I24b3ff10c6275a9c13c3f07d97ea14581f975067
* Replace db with getDb for TestsWandji692024-06-232-14/+14
| | | | | Bug: T316841 Change-Id: I29e535e8ee9b5641a4546d53b98cd5060d39681d
* Merge "api: Rewrite adrto/from/prefix handling to use expression builder"jenkins-bot2024-06-181-0/+77
|\
| * api: Rewrite adrto/from/prefix handling to use expression builderUmherirrender2024-06-171-0/+77
| | | | | | | | | | | | | | | | | | | | | | | | | | | | For a deduplication the raw sql is used as string key in an array. Now only the search term is part of the key, build the sql a bit later, as objects not usable in array keys. The deduplication is needed when namespaces have different first letter configs as happen with $wgCapitalLinks = false for all namespaces except the hard coded like user and mediawiki with talk. Searching for lower case titles splits the query Bug: T361023 Change-Id: Ia4e29d1d4d816f354318ef443ae19c954fd52274
* | ApiQuerySiteinfo: Use TempUserConfig classKosta Harlan2024-06-131-5/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Why: - Using TempUserConfig is more flexible as it doesn't require us to know about the internal details of the AutoCreateTempUser config object What: - Use TempUserConfig service instead of loading the AutoCreateTempUser object - Remove properties from ApiQuerySiteInfo that don't already have getters. If someone has a need for more this information to be exposed in ApiQuerySiteInfo, they can be added in a separate patch - This seems compatible with the goals of T335532 which was about making it possible to discover via the API if an action would result in a temp account - Implement __toString for Pattern, so that it can be used in ApiQuerySiteInfo Bug: T335532 Change-Id: Ica84b3e9b9865b8b83a9e9e513c99cd2e47661c9
* | TempUserTestTrait: Use an array for config overrides when disablingKosta Harlan2024-06-131-1/+1
|/ | | | | | | | | | | | | | Why: - Consistency with the enableAutoCreateTempUser method - Allows for overriding config properties (e.g. 'known') What: - Use an array as the parameter for `disableAutoCreateTempUser` instead of a string Change-Id: I1a495cc83effcf92364fa489f779c5f4bf2d29b9
* Add namespace and deprecation alias to WatchedItemQueryServiceEbrahim Byagowi2024-05-183-4/+4
| | | | | | | | | This patch introduces a namespace declaration for the MediaWiki\Watchlist to WatchedItemQueryService and establishes a class alias marked as deprecated since version 1.43. Bug: T353458 Change-Id: Ib1b5c19c89087940987730939e84c8cd35cd3760
* Merge "block: Deprecate and stop using $wgBlockTargetMigrationStage"jenkins-bot2024-05-111-33/+3
|\
| * block: Deprecate and stop using $wgBlockTargetMigrationStageTim Starling2024-05-101-33/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | * Deprecate and stop using $wgBlockTargetMigrationStage. Remove block_target migration code. * Make the $schema parameters to DatabaseBlockStore methods default to SCHEMA_BLOCK. Avoid passing these parameters where possible. * Remove cleanupBlocks.php * Deprecate DatabaseBlock static methods which try to present the old schema for b/c. Bug: T362133 Change-Id: I845bad8cc09a4528fef46a6f9d490ebdec881d99
* | Tests: remove a bunch of DummyServicesTrait-related commentsDannyS7122024-05-101-1/+0
|/ | | | | | Not sure why I added these, it should be clear from the method names Change-Id: Ie49881e6f31fad52bb65b0d2ac3e9379dbb7bfc5
* phpunit: Fix tests relying on implicit wgScript/wgArticlePathTimo Tijhof2024-05-051-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A number of tests have hardcoded expections that pass only in WMF CI where Quibble has LocalSettings.php with $wgScript and $wgArticlePath set a certain way. We could fix these by adding setMwGlobals() in their tests, as we often do, but these are so often forgotten that I'd rather we just add them to TestSetup.php so that it is simply impossible to write a test that that passes locally for you (if you have the same config) but not for someone else. There is a larger project in there somewhere about expanding this slowly such that we basically only pluck DB-settings and extension enablement from LocalSettings and otherwise run the tests with the default settings in PHPUnit. Pretty much by definition, any (other) setting you have in LocalSettings is irrelevant because it either: 1. has no effect on the test (majority, harmless either way), 2. has a custom default via TestSetup.php (which has precedence over LocalSettings.php), 3. is relevant to the code being tested and the test case correctly calls setMwGlobals() to ensure a consistent value during test. 4. is relevant to the tested code but has no override, thus only passes if you happen to have the "right" value set for it (undesirable). Case 4 is already categorically impossible for the most common config settings that influence random code because we give them a value in TestSetup.php. This patch expands that to include $wgScript and $wgArticlePath. Perhaps in the future we can think about a way to do this automatically by either re-applying MainConfigSchema (sans db settings) or by only selectively applying LocalSettings.php in the first place. This patch follows-up I072ddf89562fe, which added a test case in WikitextContentHandlerIntegrationTest.php that assumed "/index.php" as the value of $wgScript. This passes in WMF CI since Quibble uses that value, but the tests failed in most local development installs since those tend to use "/w" instead. Rather than one-off fixing that one test with overrideConfigValues(), switch to a more general fixture, since the precise values don't matter for this test. Bug: T349087 Bug: T277470 Change-Id: If4304b7ca4a838bd892d4516a0b5c6dfbc30986e
* Minor comment cleanup in ApiQueryTestBase.phpbpirkle2024-05-031-2/+2
| | | | Change-Id: I36cb706acc745a082b6fd90a55b859f24ed35eb9
* Run pagelinks migration for third parties tooAmir Sarabadani2024-04-271-1/+1
| | | | | | | | Production is read new almost everywhere, mediawiki core should reflect that as well. Bug: T299947 Change-Id: I8f05c4d7026394205bfc54b68dc725392852ae2a
* TempAccounts: Rate limit acquisition of temp account namesKosta Harlan2024-04-233-3/+6
| | | | | | | | | | | | | | | | | | | Why: - We don't want to allow unlimited acquisition of temp account names. These should be rate limited in similar way to how we limit the creation of temp accounts What: - Provide a TempAccountNameAcquisitionThrottle, and use it in the acquireName() method - Set a default that is 10 times the limit of TempAccountNameCreationThrottle Depends-On: If660aad1d0f04f366414084aff3f88484a19d416 Bug: T343101 Change-Id: I99d5973498a89ac227847de5837c0a8e895c28fb
* Ignore/fix MediaWiki.Commenting.PropertyDocumentation.WrongStyleTaavi Väänänen2024-04-223-1/+4
| | | | | | | | Fix the real issues found by this sniff, and convert the remaining false positive ignores to per-line ignores so that any more real issues won't be added. Change-Id: I18e75d59df327e2d93a3a487c115e92b9f268722
* tests: Migrate to IDatabase::newInsertQueryBuilderUmherirrender2024-04-143-71/+73
| | | | | | | | | Changed some inserts to use multi-row insert for small performance benefit where possible and not already used. InsertQueryBuilder does not return a value, deprecated since 1.33 Bug: T353219 Change-Id: I2380ebc8ec8db178dd790247aefbdd798b6d62ff
* Define ApiQuery::isWriteModeDreamy Jazz2024-04-051-0/+44
| | | | | | | | | | | | | | | | | | | | | | | | Why: * ApiQueryBase subclasses may define a ::isWriteMode override, as the API call may need to write to the DB. ** This is the case for the CheckUser extension, where the 'checkuser' API creates a log entry that allows users to audit usage of the API. * ApiQuery currently does not define a implementation of ::isWriteMode, which means that the definitions by any class that extends ApiQueryBase currently do nothing. * ApiQuery::isWriteMode should be defined and work in a similar way to ApiQuery::isReadMode, so that subclasses of ApiQueryBase can have their definitions of ::isWriteMode respected. What: * Define ApiQuery::isWriteMode in a similar way to how ApiQuery ::isReadMode is written, but also inspecting the modules that are used through the 'list' and 'prop' params. * Add tests for ApiQuery::isWriteMode. Bug: T361951 Change-Id: Idf1c8f95df58a861404e0c89507c885ec4554793
* Update wgAutoCreateTempUser config defaultsDreamy Jazz2024-04-036-64/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Why: * The default value of wgAutoCreateTempUser has not changed since the decision to use a different prefix for temporary accounts (T332805). * The default needs to be updated to reduce the number of overrides in operations/mediawiki-config and also to make the development experience more consistent with what is happening on WMF production. What: * Update the wgAutoCreateTempUser default in the following ways: ** Set expireAfterDays as 365 ** Set notifyBeforeExpirationDays as 10 ** Set genPattern and reservedPattern to '~$1' ** Set matchPattern to null, which will mean that the genPattern is used as the value. * Update RealTempUserConfig::getPlaceholderName to add the year to the placeholder name so that if the match pattern includes the first digit of the year, then the placeholder name still is considered a valid temporary account username. * Replace modifications of the wgAutoCreateTempUser config in integration tests with a use of the TempUserTestTrait to make the code cleaner and make it easier to find tests that relies on the values in wgAutoCreateTempUser. * Update multiple tests to handle the new defaults for the config. Bug: T359335 Change-Id: Ifa5a0123cd915bdb7c87e473c51fb93321622f12
* block: Clarify function of HideUserUtils aliases and use them consistentlyTim Starling2024-03-191-6/+6
| | | | | | | | | | | * Add a comment explaining why we need table aliases in HideUserUtils subqueries. * Use the table aliases consistently in inner field references. While this does not appear to be strictly necessary, since unprefixed fields refer to the inner query by default, it helps to improve the clarity of the code. Change-Id: Id68684ea12060a259dc87e66edd63b925da2c3b1
* block: Use a scalar subquery in HideUserUtils::getExpressionTim Starling2024-03-151-4/+4
| | | | | | | | | | | On en.wikipedia.org, MariaDB chooses to materialize the subquery, copying about 810,000 rows to a temporary table. So, use a dependent scalar subquery, which is not eligible for this "optimisation". Bug: T360163 Change-Id: I7819a6870871687ea96f92dfd3f8fe581b54cc24