aboutsummaryrefslogtreecommitdiffstats
path: root/includes/api/ApiQueryBlocks.php
Commit message (Collapse)AuthorAgeFilesLines
* ApiQueryBlock: Don't return page restrictions when pages were deletedDayllan Maza2025-03-181-3/+4
| | | | | | | | * Special:Block and Special:BlockList ignore restrictions if the page has been removed. ApiQueryBlocks now matches that behavior Bug: T388511 Change-Id: I525fbf73eec6f4a62bd6244b2a14e71130c7e602
* block: Add localized duration to API responsesTim Starling2025-03-101-0/+9
| | | | | | | | | | | | * 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
* ApiQueryBlocks: add 'parsedreason' propMusikAnimal2025-01-091-2/+13
| | | | | | | | | | This gives feature parity with ApiQueryLogEvents's 'parsedcomment' leprop. Needed by I2c24da2e44630b2bbbf1c041cb3c85cb1a1f7d66 Bug: T383180 Change-Id: Ia0c0c799e0b10b788ab414c9d7bd2fa3f018c3c7
* rdbms: fix table prefixing in "FOR UPDATE" clause generation in PostgresAaron Schulz2024-12-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | Make SqlPlatform::tableNameWithAlias() include the unqualified table name as an alias if doing so is not redundant. This assures that the default alias from JoinGroupBase::addJoin(), equal to the unqualified table name, will be usable in SQL (regardless of table prefixes). Clean up use of identifier quotes for sqlite_master tables. The called methods expect unqualified names and a passthrough exception already exists for sqlite_* tables. Use "block_target.bt_user" directly in ApiQueryBlocks and BlockPager, instead of using addIdentifierQuotes(). The "block_target" alias is automatically added to the SQL by the rdbms layer when it's not clearly redundant, so it is always safe to use block_target.bt_user. Also, there is no reason for aliases to include quote characters. They are supposed to be simple alphanumerics like column names. This makes it easy for tableNameWithAlias() to avoid redundant aliases by checking tableName(). Avoid unneeded quotes around pg_catalog.* table names in the Postgres installer. The relevant documentation of methods like selectField() is that the table names be unqualified (no quotes nor dots), though dots are still supported internally for compatibility reasons and ease of querying schemas like pg_catalog and information_schema. Change-Id: Ic7d7826da31f49915141692cb3bd84ed1e872e96
* api: Use type-declaration for string arg in ApiBase::__constructUmherirrender2024-10-171-10/+1
| | | | | | | Also for all sub-classes Remove simple doc-blocks without further information Change-Id: I981934efe32d44f52e5ab865a9b887be5bd0f41e
* Add namespace to includes/api classesJames D. Forrester2024-09-251-0/+5
| | | | | Bug: T353458 Change-Id: I3ea6b08c5018ba03ba45c5766e1f46e12f6b8597
* Use expression builder instead of raw sqlUmherirrender2024-07-231-3/+7
| | | | | Bug: T361023 Change-Id: Ibf1c93ddbf8f680e8fb9442816f6fed94a069c0a
* block: Deprecate and stop using $wgBlockTargetMigrationStageTim Starling2024-05-101-153/+97
| | | | | | | | | | | | | * 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
* block: Fix ApiQueryBlocks query error when a table prefix is usedTim Starling2024-04-231-1/+1
| | | | | | | If a qualified field name is used, the table part must either refer to an alias or the output of tableName(). Change-Id: I59839a3d0061b471b65c4e33c78e6ea92c1d2906
* block: Fix exception in ApiQueryBlocks when specified users are not blockedTim Starling2024-03-191-1/+5
| | | | | | | Fix exception due to empty array passed to makeList() for bt_id. Bug: T360088 Change-Id: I1336923976aae02bb4a4013c2cefa0a3629bc99a
* block: In ApiQueryBlocks use a union when querying for both users and IPsTim Starling2024-03-151-8/+24
| | | | | | | Avoid slow query due to lack of optimisation of "OR" operator. Bug: T360088 Change-Id: Ic8e38fcebee674e1ce48e703be969f89eb77fe15
* Special:BlockList: Improve display of hidden usersTim Starling2023-12-051-2/+13
| | | | | | | | | | | | | | | | With multiblocks the user might be hidden even if bl_deleted=0 in the block row being formatted. So: * Add a subquery with a second block_target/block table which determines whether the user is deleted. * When formatting each row, redact the name if it is deleted and the authority does not have permission to see it. * Add a parameter to show which block is the one responsible for deleting the user. * Similarly add a subquery in ApiQueryBlocks. Change-Id: Id9900397618e1f626802ada6fe4ee4ad10f32495
* Add 'temp' to allowed user types in various APIsThalia2023-11-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Why: * Before this task, when an API parameter specifies allowed user types, temporary users and permanent users are in the same category: 'name'. * However, it is useful to separate them out, and sometimes allow a permanent user but not a temporary user (e.g. ApiResetPassword, since temporary users don't have passwords). * We therefore re-defined the 'name' type only to refer to permanent (named) users, and add a new 'temp' type. * This fixes params that currently intend to allow temp users, and that use 'name' to do so, by adding 'temp'. What: * Based on a search for `UserDef::PARAM_ALLOWED_USER_TYPES`, add the 'temp' type where necessary. * The following were not updated, because they shouldn't apply to temporary users: - owners for includes/api/ApiQueryWatchlist.php, includes/api/ApiQueryWatchlistRaw.php - users for includes/api/ApiResetPassword.php, includes/api/ApiUserrights.php, includes/api/ApiValidatePassword.php Bug: T350701 Change-Id: If5ccf1d469327791acff74d013343307e411cca9
* Support new block schemaTim Starling2023-11-291-65/+139
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Support migration stages when reading and writing blocks. I tried to set it up for an easy next stage, in which support for the old schema is removed. I tried to avoid factoring out of shared code between the two schemas, so that the old schema cases can simply be deleted without the need to revert unnecessary abstractions. However, I added HideUserUtils to factor out ipb_deleted queries. Code review showed that this was already quite complex, with multiple approaches to the problem, so it benefits from refactoring even without the schema abstraction. HideUserUtils is a service rather than a standalone class to support unit tests, since unit tests do not allow global config access. When the migration stage config is removed, it will be a service with no constructor parameters -- an unnecessary abstraction which should ideally be resolved at that time. When interpreting result rows, it is possible to share code by using field aliases. But when constructing WHERE conditions, the actual field names need to be used, so the migration is more intrusive in ApiQueryBlocks and SpecialBlockList, where complex conditions are used. Bug: T346293 Bug: T51504 Bug: T349883 Change-Id: I408acf7a57b0100fe18c455fc13141277a598925
* api: Migrate away from buildLike to expression builderAmir Sarabadani2023-11-081-1/+3
| | | | | | | | Also while we are here, migrate buildComparison() calls with one field only to expr() Bug: T210206 Change-Id: I2ac7adbe4fb26af3383a38106e9a36381148c828
* Migrate another batch to use $db->expr instead of raw SQLAmir Sarabadani2023-10-301-7/+3
| | | | | Bug: T210206 Change-Id: I327517fef250c24392565a26bbe7b296dc19508a
* Mass migrate simple cases to use expression builderAmir Sarabadani2023-10-261-1/+1
| | | | | | | | | | | | | | | Done via '([A-Za-z_\.]+) ?(=|!=|<|<=|>|>=) ?' . (\$db(?:r|w|))->addQuotes\( (.+?) \) to: $3->expr\( '$1', '$2', $4 \) And '([A-Za-z_\.]+) IS NULL OR ([A-Za-z_\.]+) ?(=|!=|<|<=|>|>=) ?' . (\$db(?:r|w|))->addQuotes\( (.+?) \) to: $4->expr( '$1', '=', null )->or\( '$2', '$3', $5 \) Bug: T210206 Change-Id: I109bf2a712bdefa9e074f775b1bee41ac5b9d665
* Blocks documentation reviewTim Starling2023-09-061-7/+5
| | | | | | | | | | | | | | | | | * Use a consistent single-line comment style. * Start each sentence with a capital letter. * Use imperative mood. * Put a space between the adjective and the noun in "hardblock" and "rangeblock". * Capitalise acronyms. * Break long lines. * Remove excessively obvious or off-topic comments. * Indent the non-initial lines of a multi-line @ command. * Don't try to apply @deprecated to a parameter. Doxygen and PHPStorm interpret this as method deprecation. Bug: T345683 Change-Id: I7df126f7a031dde241dd46f66e5e83722f9b383c
* Use real type hints for services etc. in api/ApiQuery*.phpBartosz Dziewoński2023-08-291-8/+3
| | | | | | | | | | | | | | | 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
* i18n: Split apihelp for standard dir parameterUmherirrender2023-08-051-0/+4
| | | | | | | | | Easier to translate There is no visible change for example on Special:ApiHelp/query+watchlist Bug: T285545 Change-Id: I536fa3e07a951f3ff98870678ffdbc294a3c7bc0
* Simplify WHERE conditions with field IS NULLUmherirrender2023-07-241-3/+2
| | | | | | Reduce raw sql fragments on simple compares Change-Id: I3f2340dfdbf5197cc22546911e6c5653dc5a6269
* Api: Fix some very old copyright statements for RoanJames D. Forrester2023-03-161-1/+1
| | | | Change-Id: I820a2d388922653a6a5b9048b0feaafbb4297d91
* Split a base class out of CommentStoreAlexander Vorwerk2023-01-011-0/+1
| | | | | | | | | | so that extensions (i.e. CheckUser) can implement their own comment store without having a lot of code duplication basically the comment store version of I3a6486532f2ef36 Bug: T233004 Change-Id: Ib40f99e00a514d41776ce521baf113e46d37e9cd
* api: Validate timestamp in continue parameterUmherirrender2022-11-011-1/+1
| | | | | Bug: T321265 Change-Id: Ib46bc3e643938f56e0c58a3c5f5e093327e00964
* Use short array destructuring instead of list()Tim Starling2022-10-211-2/+2
| | | | | | | | Introduced in PHP 7.1. Because it's shorter and looks nice. I used regex replacement. Change-Id: I0555e199d126cd44501f859cb4589f8bd49694da
* Deduplicate code for parsing API 'continue' parametersBartosz Dziewoński2022-09-291-5/+2
| | | | | | | | | | | | | | 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
* SQLPlatform: Introduce buildComparison()Bartosz Dziewoński2022-09-101-6/+5
| | | | | | | | | | | | | | | | | Builds a condition comparing multiple values, for use with indexes that cover multiple fields, common when e.g. paging through results or doing batch operations. Can also be to generate a simple comparison without writing raw SQL (see T210206). Update a few manually constructed conditions to use this method. There are more maintenance scripts and API classes that use the same patterns, but this is a start. As you can see by the code I'm replacing, there are many ways to do this. I picked the one used by maintenance/TableCleanup.php, since I found it the easiest to understand. Change-Id: Ic368a87fb5ce4c13608b03206cd68518ec9732d4
* api: Minor code cleanupReedy2022-08-141-1/+2
| | | | Change-Id: I1f20597093448d00435158a9ac861873000bb057
* api: Replace numerous deprecated constantsReedy2022-06-061-18/+20
| | | | Change-Id: I34ffcb70efbfa257da8dab6e0790aa0d697caf5b
* Use MainConfigNames instead of string literals, #2Aryeh Gregor2022-04-131-3/+4
| | | | | | | This covers all occurrences of /onfig->.*get( '/ in includes/. Undoubtedly there are still plenty more to go. Change-Id: I33196c4153437778496f40436bcde399638ac361
* Merge "api: Fix documenation/types related to null and int types"jenkins-bot2022-02-241-1/+1
|\
| * api: Fix documenation/types related to null and int typesUmherirrender2022-02-241-1/+1
| | | | | | | | | | | | Found by phan strict checks Change-Id: I2b2ae12ca39d67140f0f3c1cc5066c8ef72716de
* | api: Remove ApiQueryBlocks::prepareUsernameUmherirrender2022-02-191-35/+5
|/ | | | | | | | | | | | | 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
* Use array_fill_keys() instead of array_flip() if that reflects the ↵Tim Starling2021-06-151-2/+2
| | | | | | | | | | | | | | | | | | 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
* Reapply "Hard Deprecate User ::getCanonicalName, ::isUsableName, ↵Vlad.shapik2021-05-311-1/+1
| | | | | | | | | | ::isCreatableName"" This reverts commit ecf826a2ee9442ee669e8057328a0118c1a5d0f8. Reason for revert: need to edit the patch and then it will be GTG in order to finish hard deprecating of User ::getCanonicalName, ::isUsableName, ::isCreatableName Change-Id: I2f57f56728fcbeada96dc2228f07dc8bcaa5d4f6
* Return the action name instead of action id in API responseSTran2021-05-111-0/+10
| | | | | | | | When block restrictions are queried from the API, return the name of the action blocked Bug: T280566 Change-Id: I2e639864cfcdd3854fd67173b138fe8eb6f877cb
* Revert "Hard Deprecate User ::getCanonicalName, ::isUsableName, ↵Ppchelko2021-05-051-1/+1
| | | | | | | | | | ::isCreatableName" This reverts commit b491279268fe1769a8787cbf30b5309c8aa91363. Reason for revert: caused CentralAuth tests to fail. Change-Id: Icb3ed094578df427622e0da2a7462645adcc3d6f
* Hard Deprecate User ::getCanonicalName, ::isUsableName, ::isCreatableNamevladshapik2021-05-041-1/+1
| | | | | Bug: T275030 Change-Id: I60689ee6519c2dbd6d000afa8ac05c3e6b7895d2
* Stop using legacy ActionMigration field "ipb_by"Tim Starling2021-04-281-6/+5
| | | | | Bug: T278917 Change-Id: I392b0bf23f23a2ca08664e4b49c9eeb26df348de
* Merge "Introduce infrastructure for partial blocks for actions"jenkins-bot2021-04-271-0/+4
|\
| * Introduce infrastructure for partial blocks for actionsThalia2021-04-271-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds a new type of block restriction for actions, which extends AbstractRestriction. Like page and namespace restrictions, action restrictions are stored in the ipblocks_restrictions table. Blockable actions are defined in a BlockActionInfo service, with a method for getting all the blockable actions, getAllBlockActions. Action blocks are checked for in PermissionManager::checkUserBlock using DatabaseBlock::appliesToRight. To make this work, this patch also removes the 'edit' case from AbstractBlock::appliesToRight, which always returned true. This was incorrect, as blocks do not always apply to edit, so cases that called appliesToRight('edit') were fixed before this commit. appliesToRight('edit') now returns null (i.e. unsure), which is correct because it is not possible to determine whether a block applies to editing a particular page without knowing what that page is, and appliesToRight doesn't know that page. There are some flags on sitewide blocks that predate partial blocks, which block particular actions: 'createaccount' and 'sendemail'. These are still handled in AbstractBlock::appliesToRight, and are still checked for separately in the peripheral components. The feature flag $wgEnablePartialActionBlocks must set to true to enable partial action blocks. Bug: T279556 Bug: T6995 Change-Id: I17962bb7c4247a12c722e7bc6bcaf8c36efd8600
* | Hard deprecate User ::isIP, ::getOptionsvladshapik2021-04-261-2/+9
|/ | | | | Bug: T275602 Change-Id: Id4be13751ca0a900e51214c1855a4624077a5a62
* Inject CommentStore service into api query modulesDannyS7122021-04-231-4/+9
| | | | | | | | | | | | | | - ApiQueryBlocks - ApiQueryDeletedrevs - ApiQueryFilearchive - ApiQueryLogEvents - ApiQueryProtectedTitles - ApiQueryRecentChanges - ApiQueryUserContribs - ApiQueryWatchlist Bug: T259960 Change-Id: Ib7ee815fcea3e72523124eb6a2eaf20ad9565cfe
* Inject BlockRestrictionStore into ApiQueryBlocksThalia2021-04-191-6/+18
| | | | | | ApiQueryBlocks::getRestrictionData is also no longer static. Change-Id: I5dc8416829250e880711e41a03057c28cd06b497
* Use Authority and GroupPermissionLookup in Action APICindy Cicalese2021-02-231-1/+1
| | | | | | | | | | | | | | | | | | | Replaces calls directly to PermissionManager with calls to the Authority object available from Context or the GroupPermissionLookup service. This patch does not address use of PermissionManager for blocks. Deprecations: - ApiBase::checkUserRightsAny deprecated passing optional User parameter - ApiBase::checkTitleUserPermissions deprecated passing LinkTarget as first parameter, takes PageIdentity instead Bug: T271462 Bug: T271854 Change-Id: I5d7cac1c28a37e074750c46cda03283980a07fca
* API: Use ParamValidator libraryBrad Jorsch2020-02-041-0/+2
| | | | | | | | | | | | | | | | | This brings significant modularization to the Action API's parameter validation, and allows the Action API and MW REST API to share validation code. Note there are several changes in this patch that may affect other code; see the entries in RELEASE-NOTES-1.35 for details. Bug: T142080 Bug: T232672 Bug: T21195 Bug: T34675 Bug: T154774 Change-Id: I1462edc1701278760fa695308007006868b249fc Depends-On: I10011be060fe6d27c7527312ad41218786b3f40d
* Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNullJames D. Forrester2020-01-101-2/+2
| | | | Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
* Coding style: Auto-fix MediaWiki.Classes.UnsortedUseStatements.UnsortedUseJames D. Forrester2020-01-101-1/+1
| | | | Change-Id: I94a0ae83c65e8ee419bbd1ae1e86ab21ed4d8210
* Use namespaced IPUtils classKunal Mehta2020-01-011-8/+9
| | | | Change-Id: I047e099a93203a59093946d336a143d899d0271f
* Unsuppress another phan issue (part 7)Daimona Eaytoy2019-09-031-0/+2
| | | | | | | Bug: T231636 Depends-On: I2cd24e73726394e3200a570c45d5e86b6849bfa9 Depends-On: I4fa3e6aad872434ca397325ed7a83f94973661d0 Change-Id: Ie6233561de78457cae5e4e44e220feec2d1272d8