aboutsummaryrefslogtreecommitdiffstats
path: root/includes/api/ApiBase.php
Commit message (Collapse)AuthorAgeFilesLines
* Namespace all remaining files in includes/exceptionJames D. Forrester2025-03-251-1/+1
| | | | | | | | | In MediaWiki/Exception, to follow PSR-4 per plural vs. singular (this can be changed later if people really care). Also, move the couple of exceptions in here that were already namespaced in the MW-top-level into the new space. Bug: T353458 Change-Id: I12ed850ae99effb699a6d7ada173f54e72f0570e
* Namespace all remaining files in includes/pageJames D. Forrester2025-03-181-1/+1
| | | | | Bug: T353458 Change-Id: I7a9c74f2106655d41ae029742090253f541bd4a6
* fix(ApiParamValidator): PARAM_HELP_MSG_PER_VALUE for multi-string typesMichael Große2025-03-071-0/+1
| | | | | | | | | | | In I53f9ae840c (commit 7c03a6f), the option was added to use PARAM_HELP_MSG_PER_VALUE to also document parameters for multi-string types, like templated parameters. See there for the reasoning. This change adds the support in ApiParamValidator for that. Follow-Up-To: I53f9ae840c0a7eee76c4b57f95390b5045707efd Change-Id: Ia8c1abdcb68823650582208caa9be3fa2c47daa8
* Generate machine-readable block info in BlockErrorFormatterBartosz Dziewoński2025-02-181-50/+1
| | | | | | | | | | | | | | | | | | | | | Previously, BlockErrorFormatter would only generate a human-readable error message for permission errors caused by blocks, and PermissionManager would build a PermissionStatus object out of them. Machine-readable block info was added later: UserAuthority would add a Block object to each one, then finally each API module (via ApiBlockInfoTrait) would generate block info from these Block objects. Now all of this happens in BlockErrorFormatter and PermissionManager. For compatibility with older code, remove the extra information when using the deprecated PermissionManager::getPermissionErrors() method. This is a small hack that can be removed together with that method in the future. The changes seem to make a workaround for T357063 in ApiQueryInfo unnecessary (tests added in c55d33ef11 still pass). Bug: T357063 Change-Id: Id121d51a24fbb1d8210e60bdd54c61b16938dd70
* Replace isset() with falsy checksUmherirrender2024-12-191-1/+1
| | | | | | | | | isset() should only be used to suppress errors, not for null check. When the property is always defined, there is no need to use isset. Found by a new phan plugin (2efea9f989) https://www.mediawiki.org/wiki/Manual:Coding_conventions/PHP#isset Change-Id: I186e799256fbaf5ee77558bd146f9418dd5eaacc
* block: Multiblocks block APITim Starling2024-12-161-0/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In ApiBlock: * Add an "id" parameter. If this is given, update the specified block. * Add a "newblock" parameter. If this is given, always add a new block, don't check if the target is already blocked. * If "reblock" is given and the target has more than one block, fail with an "ambiguous-block" error. Supporting changes: * Add BlockUserFactory::newUpdateBlock(), which takes a DatabaseBlock instead of a target union to act on. The block is passed through to the BlockUser constructor. * Rename the first parameter to BlockUser::placeBlock() from $reblock to $conflictMode, and style it like an enum. Add the CONFLICT_NEW value, to support the "newblock" API option. * In DatabaseBlockStore::newFromId(), add $fromPrimary, so that ApiBlock can pass data to BlockUserFactory with equivalent freshness to the LHS. Also: * In BlockUser, memoize prior blocks loaded from the DB * Move T287798 autoblock check to the memoized accessor. Just don't return autoblocks. * Move "TODO handle failure" comment in BlockUser to the called method. It really can't fail. * In DatabaseBlockStore::newFromId(), add an $includeExpired parameter and default to false although it was previously implicitly true. Based on a brief review of callers, I think this is beneficial. Bug: T378147 Change-Id: Iea5b77cb27006b33f3dde61660be5ad2c374a425
* Remove deprecated ApiBase::errorArrayToStatus()Bartosz Dziewoński2024-12-111-46/+0
| | | | Change-Id: I87cde531c3ba5a119a7c02c5240355b61be70ba9
* api: Use type-declaration for string arg in ApiBase::__constructUmherirrender2024-10-171-1/+1
| | | | | | | Also for all sub-classes Remove simple doc-blocks without further information Change-Id: I981934efe32d44f52e5ab865a9b887be5bd0f41e
* Use explicit nullable type on parameter argumentsUmherirrender2024-10-161-4/+4
| | | | | | | | | | | 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-251-1/+13
| | | | | Bug: T353458 Change-Id: I3ea6b08c5018ba03ba45c5766e1f46e12f6b8597
* api: Add missing documentation to class propertiesUmherirrender2024-09-071-0/+1
| | | | | | | | | | 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: I8b33b5f4d91c1935228e7010327dbc6ce138fc00
* api: Use MW_INSTALL_PATH in ApiBaseTimo Tijhof2024-08-291-1/+1
| | | | | | Does not need to be configurable. Change-Id: Iaf58333db54a09af1dca2f39bbb86d256e7eb0a0
* Merge "Clarify Action::requiresWrite() and ApiBase::isWriteMode() comments"jenkins-bot2024-08-261-4/+4
|\
| * Clarify Action::requiresWrite() and ApiBase::isWriteMode() commentsAaron Schulz2024-08-261-4/+4
| | | | | | | | | | | | | | | | | | Make the description of Action::requiresWrite() better align with Action::doneWrites(). These methods should be combined at some point. Further discourage system state dependencies in ApiBase::isWriteMode(). Change-Id: I5ee18c8c15f6f360d01d63ee6e7299babb5bdea7
* | Merge "Fix specifying messages with params as arrays in API documentation"jenkins-bot2024-08-211-38/+37
|\ \ | |/ |/|
| * Fix specifying messages with params as arrays in API documentationBartosz Dziewoński2024-08-211-38/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Follow-up to 12a4c08ad83ef55e440b88e5f9d511fd224afa6f. I didn't review it carefully enough to notice that when these functions return arrays, they contain a message key and parameters, not a key and fallback keys (while other API documentation message code uses fallback keys). Instead of `$this->msg( $msg )`, this code must be written as `is_array( $msg ) ? $this->msg( ...$msg ) : $this->msg( $msg )` or `$this->msg( Message::newFromSpecifier( $msg ) )`, both of which are ugly, but the latter looks a bit better to me. Bonus changes: * Add documentation to prevent a repeat of this mistake in the future * Remove some unreachable dieDebug() calls (the Message class already throws for bad inputs) It seems that we don't have any definitions using such arrays in the core API classes. There are only a few uses in extensions, e.g. AbuseFilter's 'apihelp-query+abuselog-param-filter' message, which is passed the wrong parameter without this change. Bug: T372988 Change-Id: I44c1c3c7d0c069e500c85a58c27e9b675b0b68ee
* | Merge "API: clarify the meaning of write access"jenkins-bot2024-08-201-6/+22
|\ \ | |/ |/|
| * API: clarify the meaning of write accessdaniel2024-08-131-6/+22
| | | | | | | | | | | | | | | | | | Improve docs for Handler::needsWriteAccess and ApiBase::isWriteMode() by explaining the contract in terms of what is observable from the client. Essentially, no write access is needed if the request is "safe" in the sense defined by RFC 7231 section 4.2.1. Change-Id: Ifab56a8d6bea3ad4c5282f30bb4eb8d8f5a719b9
* | Merge "Deprecate ApiBase::makeMessage"jenkins-bot2024-08-161-16/+14
|\ \
| * | Deprecate ApiBase::makeMessagetheprotonade2024-08-161-16/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | Replace usages of ApiBase::makeMessage with ApiBase::msg and deprecate the former method Bug: T370240 Change-Id: I9e6e775dad7f3e3cfd78351f87f4732677d90971
* | | Add MediaWiki\Registration namespace to registration classesEbrahim Byagowi2024-08-101-0/+1
| | | | | | | | | | | | | | | Bug: T353458 Change-Id: Ifa3b6a6e0353bb4ce21a3f4456f1fc696c8d377c
* | | Merge "ApiBase: Deprecate unused ApiBase::errorArrayToStatus()"jenkins-bot2024-08-081-0/+5
|\ \ \ | |/ / |/| |
| * | ApiBase: Deprecate unused ApiBase::errorArrayToStatus()Bartosz Dziewoński2024-07-091-0/+5
| |/ | | | | | | | | | | | | | | | | | | This method has become unnecessary after we introduced interfaces that return StatusValue objects directly instead of legacy error arrays. Depends-On: I2311d1fa3772ba6be378ad6f497ed4c0df9b7aa8 Depends-On: I3af555c31320d8e9b1362dfc8bf0d8315539ba4f Depends-On: I1d9e1c94b814b22a7691b710ed033526cc823032 Change-Id: Ifa67cf4e05a318539f6254a631de14156c41d462
* / Namespace MessageSpecifier under Wikimedia\Message\Bartosz Dziewoński2024-07-281-0/+1
|/ | | | | | | | | | In change I625a48a6ecd3fad5c2ed76b23343a0fef91e1b83 I am planning to make Wikimedia\Message\MessageValue use it, and we try to pretend that it is a library separate from MediaWiki, so it makes sense to move MessageSpecifier to the same namespace under Wikimedia\. Bug: T353458 Change-Id: I9ff4ff7beb098b60c92f564591937c7d789c6684
* api: Use namespaced classesUmherirrender2024-06-141-0/+1
| | | | | | Changes to the use statements done automatically via script Change-Id: Icc5b59f9ef6319d1fb785fcda17f43c94f94cc38
* Add ApiLogFeatureUsage hookAaron Schulz2024-06-121-0/+9
| | | | | Bug: T313731 Change-Id: I8bbf806501d542a0f91a67e197913a894bdee127
* Document more ApiBase methods that accept MessageSpecifier, not just MessageMichael Große2024-05-311-3/+2
| | | | | | | | | | The documentation for ApiErrorFormatter::addError() was updated in I1323d18baf17a8a27cc9bed31860c4cc89e61a22 Otherwise, phan complains about handing a MessageSpecifier to that method. Change-Id: If421729d58cd7e3e7dd7b866c671915ea8f47154
* Use StatusValue::getMessages() instead of deprecated methodsBartosz Dziewoński2024-05-181-11/+8
| | | | | | | | | This commit replaces some of the uses of getErrorsArray(), getWarningsArray(), getErrorsByType(), and getErrors(). In many cases the code becomes shorter and clearer. Follow-up to Ibc4ce11594cf36ce7b2495d2636ee080d3443b04. Change-Id: Id0ebeac26ae62231edb48458dbd2e13ddcbd0a9e
* api: Fix PSR2.Classes.PropertyDeclaration.Multiple errorsTaavi Väänänen2024-04-211-1/+10
| | | | Change-Id: I7859191740d66d00595c4bdeea12b227ac25bcc5
* Merge "api: Replace null $httpCode by 0 in ApiBase::dieWithErrorOrDebug"jenkins-bot2024-04-121-1/+1
|\
| * api: Replace null $httpCode by 0 in ApiBase::dieWithErrorOrDebugUmherirrender2024-04-101-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | The $httpCode is passed to Exception::__construct and type-hinted as integer since php8.2 When a module requires POST, but is used with GET a deprecation notice is shown in php8.2 validatepassword: Passing null to parameter #2 ($code) of type int is deprecated Bug: T362272 Change-Id: Ib5c6a24abf0808a0557c57170279b325b4bddcea
* | Document more methods that accept MessageSpecifier, not just MessageBartosz Dziewoński2024-04-091-2/+2
|/ | | | | | | These methods can already handle any MessageSpecifier, but their documentation didn't show this. Change-Id: I1323d18baf17a8a27cc9bed31860c4cc89e61a22
* Add explicit parentheses around mixed boolean operatorUmherirrender2024-03-231-1/+1
| | | | | | | Mixing different binary boolean operators within an expression without using parentheses to clarify precedence is not allowed (T358966) Change-Id: I24ca752d5dac7c948fdbcabf721f6f0aef8a466f
* Deprecate Linker::generateTOC() and related methodsBartosz Dziewoński2024-03-071-1/+1
| | | | | | Move the code to private methods in the only place that needs it. Change-Id: I7aa038e055adc1aea9faafd17b86e304ee2ca758
* Add missing block message keys to ApiBase and ApiMessageTraitThalia2024-02-231-0/+2
| | | | | | | Add blockedtext-tempuser and autoblockedtext-tempuser to ApiBase::BLOCK_CODE_MAP and ApiMessageTrait::messageMap Change-Id: Ia365a300b16ee1ebd39556bc138c183f39b464ed
* Namespace includes/contextJames D. Forrester2024-02-081-0/+2
| | | | | Bug: T353458 Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
* Move creation of BlockErrorFormatter into FormatterFactorydaniel2024-01-261-2/+3
| | | | | | | | The idea is that all formatters that need the user language or other request specific context should be instantiated by FormatterFactory. Change-Id: I8334cc89dcf0f293298b82e004116be50a90f0d1
* Replace more instances of unchecked MWExceptionDaimona Eaytoy2024-01-231-1/+0
| | | | | | | | Most (all?) of the remaining usages are caught somewhere and will be migrated later. Bug: T328220 Change-Id: I5c36693a5361dd75b4f1e7a0bab5ad48626ed75c
* Change uses of getDBLoadBalancerFactory() to getConnectionProvider()Bartosz Dziewoński2024-01-221-1/+1
| | | | | | | | | | | | Update cases where one of the IConnectionProvider methods is called immediately. This doesn't really change anything, but I hope it helps promote getConnectionProvider() as the common way to do this. Follow-up to 8604c384f624273f46b653ec252ffaed30e6ff89. Change-Id: Id0e7d02bab0c570343c2b1f03c70b44ee39db112
* Replace unspecific exceptions with InvalidArgumentExceptionthiemowmde2024-01-201-1/+1
| | | | | | | | | | | | | | | A LogicException is very generic and doesn't mean much. An InvalidArgumentException is also a LogicException, but more specific: A method was called (for whatever reason – bad code, bad user input – we don't know) with an invalid, unsupported argument. This is exactly what's going on in these cases. BadMethodCallException does have a confusing name and is often misused because of this. It's documented as "thrown if a callback refers to an undefined method or if some arguments are missing". That's something else and not what's going on in these cases. Change-Id: Id446227f578ba701e22acd5e530ffb795e76c147
* ApiBase: Make sure that requirePostedParameters() implies mustBePosted()Bartosz Dziewoński2023-10-111-0/+14
| | | | | | | | In order to allow client code to choose the correct method (GET or POST) depending *only* on mustBePosted(), make sure that the module requires posting if any of its potential parameters require posting. Change-Id: I63117523e3f4511f72e893facb238d9df1fd20b9
* ApiBase::checkUserRightsAny: Drop second paramter, deprecated since 1.36James D. Forrester2023-09-271-8/+2
| | | | Change-Id: I1566dfec82da4a3d26c7704ac8bedba7296d295b
* ApiBase::checkTitleUserPermissions: Enforce PageIdentity inputJames D. Forrester2023-09-271-8/+2
| | | | Change-Id: I7712f5165d17e1fea83231f226232798c74f5562
* Merge "Migrate another major batch to SelectQueryBuilder"jenkins-bot2023-09-201-9/+4
|\
| * Migrate another major batch to SelectQueryBuilderAmir Sarabadani2023-09-201-9/+4
| | | | | | | | | | | | | | | | I fixed some edge cases in the script that migrates to SQB and it managed to fix these now. Bug: T344971 Change-Id: I00cc9a6660d9bd4c64c976121b2121ccd7aae1f0
* | Namespace User under \MediaWiki\UserJames D. Forrester2023-09-191-0/+1
|/ | | | | Bug: T166010 Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
* Namespace SpecialVersion under \MediaWiki\SpecialsJames D. Forrester2023-09-141-0/+1
| | | | Change-Id: Ibeb181c653dac3796c44b36c8ff9f2ed572d5f42
* Reorg: Move Status to MediaWiki\Status\Amir Sarabadani2023-08-251-0/+1
| | | | | | | | | | This class is used heavily basically everywhere, moving it to Utils wouldn't make much sense. Also with this change, we can move StatusValue to MediaWiki\Status as well. Bug: T321882 Depends-On: I5f89ecf27ce1471a74f31c6018806461781213c3 Change-Id: I04c1dcf5129df437589149f0f3e284974d7c98fa
* Merge "ApiBase: Restore 'user' support in checkTitleUserPermissions()"jenkins-bot2023-08-161-2/+4
|\
| * ApiBase: Restore 'user' support in checkTitleUserPermissions()Bartosz Dziewoński2023-08-081-2/+4
| | | | | | | | | | | | | | The support for passing $options['user'] has been lost in change f6e1891c6f36a4fb4248512e1a21d65bb56138cf, despite being documented. Change-Id: Ibcaa2739518f5b3d89beddeed058504d8093896d