aboutsummaryrefslogtreecommitdiffstats
path: root/includes/api/ApiResult.php
Commit message (Collapse)AuthorAgeFilesLines
* Use array_fill_keys() instead of array_flip() if that reflects the ↵Tim Starling2021-06-151-1/+1
| | | | | | | | | | | | | | | | | | 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
* Api: Cache the ContentLanguage object in ApiResultDaimona Eaytoy2021-02-111-1/+6
| | | | | | | | | | This code was querying the service locator for each value, which showed up on xhgui: according to https://performance.wikimedia.org/xhgui/run/view?id=601eefa1beb2155092df5c24, there are 6945 calls to MediaWikiServices::getContentLanguage for a request, of which roughly 500 outside of this method. Change-Id: Ibabdd236d6945a1c742a724c8357a0b7015e9071
* API: Optimize hot code paths in ApiResult by re-arrangingThiemo Kreuz2021-02-111-7/+8
| | | | | | | | | | | | | | | | | | | This does not change what this code does in any way. All it does is re-arranging the code paths from most likely to least likely. For example: * It's much more likely that an element in an API result is a string, and much less likely it's an array. This change increases the chance that the long if-elseif ends after the first check, and rarely executes the other checks. * There are not many arrays in an API result, but many, many more scalar values. Doing the is_array() check first avoids many, many calls of the hot isMetadataKey() function. This makes quite a difference in my benchmarks. Change-Id: I47c1525bdedbc8ca26e10ea7480715a7ecd7d5b2
* Micro-optimize ApiResult::isMetadataKey even moreDaimona Eaytoy2021-02-081-3/+4
| | | | | | | | | | | | | Since this is a very hot method, it must be really quick. ord() is useful here, because it discards everything after the first character and it works with integers. A quick benchmark on 3v4l reveals that it's consistently faster than the previoust code on all PHP versions, taking something between 38% and 71% of the current runtime, with an average of 50%. Follow-up: I368cd3b526edeb247a6ebda7420897a51357407d Change-Id: I0b471dafd645aeb11ecdc68915c28aff93f809d9
* Merge "API: Micro-optimize ApiResult::isMetadataKey()"jenkins-bot2021-01-311-2/+4
|\
| * API: Micro-optimize ApiResult::isMetadataKey()Kunal Mehta2021-01-311-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is an extremely hot function, appearing at the top or second in a few XHGUI profiles I ran when sorted by self wall time. We can micro-optimize by switching the substr() function call to check the 0th character of the string. In my benchmarking of 1,000,000 loops (see P14054), this went from a total time of 784.20ms to 651.67ms. A further optimization could remove checking whether the string is empty but that would be a behavior change and while I'm pretty sure all API keys are non-zero length, I'm not 100% sure. Change-Id: I368cd3b526edeb247a6ebda7420897a51357407d
* | ApiResult: Avoid huge conditional clauseAmmarpad2021-01-301-79/+79
|/ | | | | | | | | | | Huge `if` clause is almost always bad. It impacts code readability and requires a lot of scrolling (both mental and physical) to see the `else` block and make sense of everything together. Use early return to improve the code readability. The functionality of the logic remains the same. Change-Id: Ibdb706cd35a5fbd219c042a882326c5b21cd18ba
* Allow replacing ApiResult value with same valueLucas Werkmeister2021-01-261-1/+1
| | | | | | | | | | There’s no need for setValue() to raise an error if the old and new value are identical. Bug: T160504 Bug: T202725 Bug: T271105 Change-Id: Icfa6c181666b2293494c67875777d3de8816587a
* Improve custom folding and groupingTim Starling2020-12-231-18/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | PHPStorm can use custom folding regions defined in either the VisualStudio style or the NetBeans style. The VisualStudio style is more pleasing to the eye and also works as a vim foldmarker. So get rid of the previous vim foldmarkers, and use region/endregion. region/endregion need to be in a single-line comment which is not a doc comment, and the rest of the comment is used as a region heading (by both PHPStorm and vim). So to retain Doxygen @name tags, it is necessary to repeat the section heading, once in a @name and once in a region. Establish a standard style for this, with a divider and three spaces before the heading, to better set off the heading name in plain text. Besides being the previous vim foldmarker, @{ is also a Doxygen grouping command. However, almost all prior usages of @{ ... @} in this sense were broken for one reason or another. It's necessary for the @{ to be in a doc comment, and DISTRIBUTE_GROUP_DOC doesn't work if any of the individual members in the group are separately documented. @name alone is sufficient to create a Doxygen section when the sections are adjacent, but if there is ungrouped content after the section, it is necessary to use @{ ... @} to avoid having the Doxygen group run on. So I retained, fixed or added @{ ... @} in certain cases. I wasn't able to test the changes to the trait documentation in Doxygen since trait syntax is not recognised and the output is badly broken. Change-Id: I7d819fdb376c861f40bfc01aed74cd3706141b20
* Improve docs in api related classesUmherirrender2020-11-131-6/+6
| | | | Change-Id: I78338d48530f098fa5d36fe84cfd45c0d160f444
* Remove documentation that literally repeats the codeThiemo Kreuz2020-10-271-1/+0
| | | | | | | | | | | | | | | For example, documenting the method getUser() with "get the User object" does not add any information that's not already there. But I have to read the text first to understand that it doesn't document anything that's not already obvious from the code. Some of this is from a time when we had a PHPCS sniff that was complaining when a line like `@param User $user` doesn't end with some descriptive text. Some users started adding text like `@param User $user The User` back then. Let's please remove this. Change-Id: I0ea8d051bc732466c73940de9259f87ffb86ce7a
* Fix even more PSR12.Properties.ConstantVisibility.NotFoundReedy2020-05-161-13/+13
| | | | Change-Id: I5e04824d6fa6a4c36ce489850bb0ed7b4ac588f9
* Stop accepting ApiMain instances in ApiResult::__constructDaimona Eaytoy2020-03-181-14/+2
| | | | | | | This was deprecated in 1.25, no code doing that: https://codesearch.wmflabs.org/search/?q=new%20%5C%5C%3FApiResult%5C(%5Cs*(new%7C%5C%24)&i=nope&files=&repos= Change-Id: I21fff4fa66478d2eada13e2ff801bcd6a58b865a
* Clean up spacing of doc commentsUmherirrender2019-08-051-3/+3
| | | | | | Align the doc stars and normalize start and end tokens Change-Id: Ib0d92e128e7b882bb5b838bd00c74fc16ef14303
* API: Fix missing return in ApiResult::addContentValue()Kunal Mehta2019-03-231-1/+1
| | | | | | Spotted by phan. Change-Id: Ifca5e15a1360008b5d91e1b6f483da8e0367819a
* Mass conversion of $wgContLang to serviceAryeh Gregor2018-08-111-3/+3
| | | | | | | Brought to you by vim macros. Bug: T200246 Change-Id: I79e919f4553e3bd3eb714073fed7a43051b4fb2a
* Fix PhanTypeMismatchDeclaredParamUmherirrender2018-07-071-5/+5
| | | | | | Auto fix MediaWiki.Commenting.FunctionComment.DefaultNullTypeParam sniff Change-Id: I865323fd0295aabd06f3e3c75e0e5043fb31069e
* Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenientBartosz Dziewoński2018-05-301-5/+3
| | | | | | | | | | | | | | Find: /isset\(\s*([^()]+?)\s*\)\s*\?\s*\1\s*:\s*/ Replace with: '\1 ?? ' (Everywhere except includes/PHPVersionCheck.php) (Then, manually fix some line length and indentation issues) Then manually reviewed the replacements for cases where confusing operator precedence would result in incorrect results (fixing those in I478db046a1cc162c6767003ce45c9b56270f3372). Change-Id: I33b421c8cb11cdd4ce896488c9ff5313f03a38cf
* Use PHP 5.6 constant expressions for some bitfield constantsBartosz Dziewoński2018-05-301-1/+1
| | | | | | | | | I searched the entire codebase for 'const' and looked for things that looked suspiciously like manually calculated bitfield unions. As of PHP 5.6, we can have them calculated automatically when defining constants. Change-Id: I7d971d1a63f8916db2f8f6c053c7dd0a13add92d
* build: Update mediawiki/mediawiki-codesniffer to 0.10.1Kunal Mehta2017-07-221-21/+21
| | | | | | | | | And auto-fix all errors. The `<exclude-pattern>` stanzas are now included in the default ruleset and don't need to be repeated. Change-Id: I928af549dc88ac2c6cb82058f64c7c7f3111598a
* includes/api: Replace implicitly-Bugzilla bug numbers with Phab onesJames D. Forrester2017-02-241-1/+1
| | | | | | | It's unreasonable to expect newbies to know that "bug 12345" means "Task T14345" except where it doesn't, so let's just standardise on the real numbers. Change-Id: I49e2a10350a328a8572fcedd44012751a29e1068
* ApiResult: Add ApiResult::formatExpiry()Brad Jorsch2017-01-111-0/+23
| | | | | | | | This allows for removing $wgContLang from many API modules where it was only used to call $wgContLang->formatExpiry() in a way in which the results don't actually depend on the language. Change-Id: Ib0f25f288b9b87d2e4131297c552e5971696db87
* API: i18n for warnings and errorsBrad Jorsch2016-12-061-5/+3
| | | | | | | | | | | | | | | | | | | | | | | | | 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
* API: Remove deprecated methodsBrad Jorsch2016-09-201-311/+5
| | | | | | | | | | | | | | All deprecated ApiResult methods are removed. These have been deprecated since 1.24 or 1.25, and the only users remaining in Gerrit are wrapped in backwards-compatibility checks and so should not be being called. ApiBase, ApiFormatBase, ApiMain, and ApiQuery methods for generating the pre-Ib14c00df help text are removed. Nothing has called these for a long time, and only Flow implemented them in any way. Deprecated methods for providing the text for such help, such as getDescription(), haven't been removed yet, though, since some extensions still call some of them. Change-Id: I3ca7c98174b4a3f6f67f2b023e0f4446637e7a84
* ApiResult: Remove double space in error messageBartosz Dziewoński2016-08-291-1/+1
| | | | Change-Id: I5888d617ab9aebe5ae1fe4da6873639a81f60fc3
* Clean up array() syntax in docs, part IIAmir Sarabadani2016-08-071-1/+1
| | | | Change-Id: I226ce6bcb5bbf6ed3802042dd2790f85617833e1
* Clean up array() in docs, Part IAmir Sarabadani2016-07-251-4/+4
| | | | Change-Id: Ia6bb3944c05b056677979035cb38385554ee8a4f
* Always use 'bool' instead of 'boolean' in Doxygen tagsRicordisamoa2016-03-241-1/+1
| | | | | | Just like commit f86a5590aae7fbe6d9b8a3d129c7a04a11a27579 Change-Id: Ic9d08bca6524d6bb4baf5170c081ad0f3d738e28
* Replace uses of join() by implode()Siebrand Mazeland2016-03-081-3/+3
| | | | | | All of core uses implode() consistently now. Change-Id: Iba50898c64c43f356d1caf8869f484e90d9ff651
* Use single quotes in API where possibleSiebrand Mazeland2016-03-081-4/+4
| | | | Change-Id: I972e296f4820f78f5dfcecc27bc4912ca84a3178
* Convert all array() syntax to []Kunal Mehta2016-02-171-51/+51
| | | | | | | | | | 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
* API: Work around PHP bug 45959Brad Jorsch2016-01-141-1/+5
| | | | | | | | | Sigh, PHP. You allow for an array to have string "1" as a key (e.g. when casting from object to array), but then you do everything wrong when trying to deal with it. Bug: T123663 Change-Id: I49f09901a69aab39ca1519bbe9e41267bf9a1216
* Fixed incorrect size for api resultYuri Astrakhan2015-12-121-1/+1
| | | | | | Added a unit test to highlight the problem Change-Id: I5d4bcb755bd3686a92e7b111946a49892699729f
* Add/update phpdocReedy2015-11-071-3/+4
| | | | Change-Id: I9cb6f041a0242c3257a24aac6538f7fbbca60cb0
* Remove various unused variablesReedy2015-11-071-1/+0
| | | | Change-Id: I4b1b20b4126735cb32a80e473fe48d523bcb24d1
* API: Finish killing "raw mode"Brad Jorsch2015-09-171-12/+7
| | | | | | | | It was kept around in the ApiResult rewrite because Wikibase was (mis)using it as an "XML mode" flag. Bug: T96596 Change-Id: Ic8259649c8cb0cce0444c907607c36d96fb2eb7e
* Remove return of void method resultsjeroendedauw2015-09-101-1/+1
| | | | Change-Id: I095ba37ceb150fcb7bee9df80201437c78426938
* ApiResult: Fix size checkingBrad Jorsch2015-09-081-6/+9
| | | | | | | | | | | Two bugs here: * Setting NO_SIZE_CHECK also bypassed validation * ApiResult::valueSize() didn't handle ApiSerializable, which is fixed by defining that the value needs to be passed through ApiResult::validateValue() first. Bug: T111796 Change-Id: I7c00d8ee53364a26f8f63f82a4d83b92baf5383e
* Comment typo fixBrad Jorsch2015-08-311-1/+1
| | | | Change-Id: I52e36f1ecbef8e8c18066d3dde84bda086ef9808
* API: Add ApiResult::META_KVP_MERGEBrad Jorsch2015-08-281-11/+47
| | | | | | | | | | | | | | | | | This allows for merging the KVP key into the value for the alternative output format. Specifically, { "key": { "foo": "bar" } } can now be turned into [{ "name": "key", "foo": "bar" }] instead of [{ "name": "key", "value": { "foo": "bar" } }] Change-Id: Ie1f9235893dbbcd2948c46e0356360b5635a3ddd
* Expose RL modules and js config vars in action=expandtemplatesMarc Ordinas i Llopis2015-06-051-4/+66
| | | | | | | | | | | | | | | Adds the 'modules', 'jsconfigvars', and 'encodedjsconfigvars' props to action=expandtemplates, that output the modules and Javascript configuration variables added to ResourceLoader by extensions and parser functions, in the same way action=parse does. This is needed by Parsoid to correctly include all modules used by parser functions. Based on I5c3ccb25385e57633639bb0c7e6f562eb58b05a2 by @Jackmcbarn. Bug: T69540 Change-Id: Iaf58c66c987a318c0dd1ee2b81774106c40e7561
* API: Ignore META_BC_SUBELEMENTS elements that aren't actually setBrad Jorsch2015-05-051-5/+7
| | | | | | | Shouldn't happen, but if it does let's not log a bunch of warnings. Bug: T98185 Change-Id: I7e626ab2c829633a84f3db0358080011baf5d9f2
* API: ApiResult must validate even when using numeric auto-indexesBrad Jorsch2015-04-291-4/+4
| | | | | Bug: T97490 Change-Id: I5301a615a992b090000a59f86e13b9f78dcd5aec
* Merge "API: Add wfDeprecated() to deprecated ApiResult methods"jenkins-bot2015-04-211-92/+10
|\
| * API: Add wfDeprecated() to deprecated ApiResult methodsBrad Jorsch2015-04-201-92/+10
| | | | | | | | | | Bug: T96596 Change-Id: Ib0068b4cd3cc9c1765d82a8ade7b3d435c57f1d5
* | Change API result data structure to be cleaner in new formatsBrad Jorsch2015-04-201-2/+4
|/ | | | | | | | | | | Nothing in this patch should result in changed output for format=json or format=php except as noted in RELEASE-NOTES-1.25, and changed output for format=xml should be similar or cosmetic. However, other code accessing the result data directly may need to be updated. Bug: T87053 Bug: T12887 Change-Id: I3500708965cb8869b5aed1543381aad208dadd13
* Merge "Follow-up 1c57794e371: change 'nobools' to 'nobool' in docs"jenkins-bot2015-04-171-2/+2
|\
| * Follow-up 1c57794e371: change 'nobools' to 'nobool' in docsRoan Kattouw2015-04-171-2/+2
| | | | | | | | | | | | Because 'nobool' is what's actually used in the code. Change-Id: Ia846e6abbf973d3b060a509e0216023a8278d7f6
* | Add missing 'return'Brad Jorsch2015-04-171-1/+1
|/ | | | | Bug: T96422 Change-Id: Ib797af8d86cf33c56b023e53240dc1cd0bad2fb0
* API: Overhaul ApiResult, make format=xml not throw, and add json formatversionBrad Jorsch2015-04-101-392/+1241
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ApiResult was a mess: some methods could only be used with an array reference instead of manipulating the stored data, methods that had both array-ref and internal-data versions had names that didn't at all correspond, some methods that worked on an array reference were annoyingly non-static, and then the whole mess with setIndexedTagName. ApiFormatXml is also entirely annoying to deal with, as it liked to throw exceptions if certain metadata wasn't provided that no other formatter required. Its legacy also means we have this silly convention of using empty-string rather than boolean true, annoying restrictions on keys (leading to things that should be hashes being arrays of key-value object instead), '*' used as a key all over the place, and so on. So, changes here: * ApiResult is no longer an ApiBase or a ContextSource. * Wherever sensible, ApiResult provides a static method working on an arrayref and a non-static method working on internal data. * Metadata is now always added to ApiResult's internal data structure. Formatters are responsible for stripping it if necessary. "raw mode" is deprecated. * New metadata to replace the '*' key, solve the array() => '[]' vs '{}' question, and so on. * New class for formatting warnings and errors using i18n messages, and support for multiple errors and a more machine-readable format for warnings. For the moment, though, the actual output will not be changing yet (see T47843 for future plans). * New formatversion parameter for format=json and format=php, to select between BC mode and the modern output. * In BC mode, booleans will be converted to empty-string presence style; modules currently returning booleans will need to use ApiResult::META_BC_BOOLS to preserve their current output. Actual changes to the API modules' output (e.g. actually returning booleans for the new formatversion) beyond the use of ApiResult::setContentValue() are left for a future change. Bug: T76728 Bug: T57371 Bug: T33629 Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f