Skip to content

Commit b19c76a

Browse files
Release version 1.5.0 (#60)
* fix: display error messages in content language * ci: Run phan in CI (#48) * docs: add instructions on running phan * style: use typed arguments in closures * ci: run phan in lint workflow Closes #46 * ci: lint on refactor branches * style: fix lines being too long * ci: run phan in ci instead of lint This is requires because MW core files are not available in the lint workflow. * style: use ! instead of empty https://www.mediawiki.org/wiki/Manual:Coding_conventions/PHP#empty() * style: suppress PhanCompatibleUnionType * style: use 'never' return type * style: use ??= to assign if null * style: suppress PhanParamTooFewInPHPDoc * ci: fix working directory * ci: specify minimum php version in phan config * Add various phan plugins (#49) definitely not stolen from ManageWiki * style: specify types * refactor: use Parser::msg instead of wfMessage * style: fix types * style: use strict equality * refactor: supply DataSourceProvider to legacy functions * style: remove redundant suppression * style: remove redundant @return declarations * Revert "style: remove redundant suppression" This reverts commit b97c9dc. * style: clean up doc types * style: clean up doc types * style: add closure return types * style: convert closures to typed arrow functions * style: add types to closure args * style: remove redundant doc type * use strict in_array * remove redundant doc comments * add/remove doc comments * specify return type * use string[] instead of array<string> * doc types * remove redundant return doc comments * use strict equality * remove redundant return type * specify types * doc types & strict comparison * use null coalescing instead of isset * doc types * make phan pass with plugins * add phan plugins * fix codesniffer issues * use non-strict comparison for arg validation * style: use ??= instead of if check * style: simplify isValidId * style: simplify verifyIsRobloxCdnUrl * chore!: drop support for MediaWiki 1.42 (#47) MW 1.42 has now reached EOL per https://lists.wikimedia.org/hyperkitty/list/mediawiki-l@lists.wikimedia.org/thread/WFVHGNA2U3G35IHPQKLKIB5UYTN64H5B/. * refactor: import namespaced Parser and FormatJson FormatJson was moved in 1.43, Parser in 1.42. * style: sort config options * style: remove redundant type hint * feat: display errors in error boxes (#53) * feat: $wgRobloxAPIDataSourceUsageLimits config option (#54) Closes #38. * feat: $wgRobloxAPIShowPlainErrors config option Also fixes parser tests. * refactor: use constants for config names (#57) Closes #52. * refactor: fully separate robloxapi-error-usage-limit-dependent Required so we can ->parse() all messages, which wouldn't be possible when passing the message through a parameter. * feat: parse all error messages (#55) Using ->plain() instead of ->parse() here since it's parsed after being returned. Allows styling/customizing errors using wikitext. * style: remove outdated comment * build(deps-dev): update mediawiki/mediawiki-phan-config requirement (#58) Updates the requirements on [mediawiki/mediawiki-phan-config](https://github.com/wikimedia/mediawiki-tools-phan) to permit the latest version. - [Changelog](https://github.com/wikimedia/mediawiki-tools-phan/blob/master/HISTORY.md) - [Commits](wikimedia/mediawiki-tools-phan@0.15.1...0.16.0) --- updated-dependencies: - dependency-name: mediawiki/mediawiki-phan-config dependency-version: 0.16.0 dependency-type: direct:development ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * docs: add phan to TOC * refactor(i18n): remove unused message `robloxapi-error-invalid-args-count` is unused since c38d697. * docs: update USAGE.md TOC * fix: use correct message parameter * docs: clarify limit behaviour with caching * refactor(i18n): use double quotes Single ones cause strings to become italicized since f114181. * test: add parser test for escaping errors * test: add parser test for ensuring escaping in error boxes * Revert "test: add parser test for ensuring escaping in error boxes" This reverts commit 4d0ef3d. Error box uses different class order on MW 1.43, so we can't properly test this. * chore: bump version to 1.5.0 Also drop support for 1.3.0. --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2 parents a8611fd + f8c9284 commit b19c76a

32 files changed

+433
-247
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ jobs:
1414
strategy:
1515
matrix:
1616
include:
17-
- mw: 'REL1_42'
18-
php: 8.1
19-
experimental: false
2017
- mw: 'REL1_43'
2118
php: 8.1
2219
experimental: false
@@ -79,3 +76,5 @@ jobs:
7976
- name: Run parser tests
8077
run: php tests/parser/parserTests.php --file=extensions/RobloxAPI/tests/parser/parserTests.txt
8178

79+
- name: Run phan
80+
run: composer run phan

.github/workflows/lint-check.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Lint Tests
22
on:
33
push:
4-
branches: [ master, development, feat/**, test/** ]
4+
branches: [ master, development, feat/**, refactor/**, test/** ]
55
pull_request:
66
branches: [ master, development ]
77
jobs:
@@ -33,5 +33,5 @@ jobs:
3333
- name: Composer install
3434
if: steps.vendor-cache.outputs.cache-hit != 'true'
3535
run: composer install --no-ansi --no-interaction --no-scripts --no-suggest --prefer-dist
36-
- name: Run Test
36+
- name: Lint code
3737
run: composer run test

.phan/config.php

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,46 @@
11
<?php
22

3-
return require __DIR__ . '/../vendor/mediawiki/mediawiki-phan-config/src/config.php';
3+
$config = require __DIR__ . '/../vendor/mediawiki/mediawiki-phan-config/src/config.php';
4+
5+
$config['minimum_target_php_version'] = '8.1';
6+
7+
$config['plugins'] = array_merge( $config['plugins'], [
8+
'AddNeverReturnTypePlugin',
9+
'AlwaysReturnPlugin',
10+
'DeprecateAliasPlugin',
11+
'DollarDollarPlugin',
12+
'DuplicateConstantPlugin',
13+
'EmptyMethodAndFunctionPlugin',
14+
'EmptyStatementListPlugin',
15+
'FFIAnalysisPlugin',
16+
'InlineHTMLPlugin',
17+
'InvalidVariableIssetPlugin',
18+
'InvokePHPNativeSyntaxCheckPlugin',
19+
'LoopVariableReusePlugin',
20+
'PHPDocRedundantPlugin',
21+
'PHPUnitAssertionPlugin',
22+
'PHPUnitNotDeadCodePlugin',
23+
'PreferNamespaceUsePlugin',
24+
'PrintfCheckerPlugin',
25+
'RedundantAssignmentPlugin',
26+
'SimplifyExpressionPlugin',
27+
'SleepCheckerPlugin',
28+
'StrictComparisonPlugin',
29+
'StrictLiteralComparisonPlugin',
30+
'SuspiciousParamOrderPlugin',
31+
'UnknownClassElementAccessPlugin',
32+
'UnknownElementTypePlugin',
33+
'UnreachableCodePlugin',
34+
'UnsafeCodePlugin',
35+
'UseReturnValuePlugin',
36+
] );
37+
38+
$config['suppress_issue_types'] = array_merge( $config['suppress_issue_types'], [
39+
// annoying
40+
'PhanPluginUnknownArrayClosureParamType',
41+
'PhanParamTooFewUnpack',
42+
// phan not detecting ::exec inherited docs properly
43+
'PhanPluginUnknownArrayMethodParamType',
44+
] );
45+
46+
return $config;

CONTRIBUTING.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
+ [Running tests](#running-tests)
99
- [PHP unit tests](#php-unit-tests)
1010
- [Parser tests](#parser-tests)
11+
- [Phan](#phan)
1112
- [JavaScript tests](#javascript-tests)
1213
+ [Code Style](#code-style)
1314
* [Releasing a new version](#releasing-a-new-version)
@@ -54,9 +55,15 @@ A data source must fulfill the following requirements:
5455
1. Run `php tests/parser/parserTests.php --file=extensions/RobloxAPI/tests/parser/parserTests.txt` to run the parser
5556
tests.
5657

58+
#### Phan
59+
60+
0. If you are running a MediaWiki docker container, go to the container's directory and run
61+
`docker compose exec mediawiki bash` to get a shell in the container.
62+
1. Run `MW_INSTALL_PATH=/var/www/html/w vendor/bin/phan -d . --long-progress-bar`
63+
5764
#### JavaScript tests
5865

59-
Running `npm test`will run automated code checks.
66+
Running `npm test` will run automated code checks.
6067

6168
### Code Style
6269

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Live Examples:
2525
> and install it with a click.
2626
2727
Requirements:
28-
* MediaWiki 1.42 or higher
28+
* MediaWiki 1.43 or higher
2929
* PHP 8.1.0 or higher
3030

3131
1. Download the repository using the following

SECURITY.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
## Supported Versions
44

5-
* MediaWiki: >= 1.42.x (until 1.42 reaches EOL)
5+
* MediaWiki: >= 1.43.x
66

77
| Version | Supported | Notes |
88
|---------|-----------|------------------|
9-
| 1.4.0 || Latest release |
10-
| 1.3.0 || Upgrade to 1.4.0 |
9+
| 1.5.0 || Latest release |
10+
| 1.4.0 || Upgrade to 1.5.0 |
11+
| 1.3.0 || Upgrade to 1.5.0 |
1112
| 1.2.0 || |
1213
| 1.1.0 || |
1314
| 1.0.0 || |

USAGE.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
+ [`$wgRobloxAPIDisableCache`](#wgrobloxapidisablecache)
4141
+ [`$wgRobloxAPIParserFunctionsExpensive`](#wgrobloxapiparserfunctionsexpensive)
4242
+ [`$wgRobloxAPIRegisterLegacyParserFunctions`](#wgrobloxapiregisterlegacyparserfunctions)
43+
+ [`$wgRobloxAPIDataSourceUsageLimits`](#wgrobloxapidatasourceusagelimits)
44+
+ [`$wgRobloxAPIShowPlainErrors`](#wgrobloxapishowplainerrors)
4345

4446
## Basic Usage
4547

@@ -791,3 +793,45 @@ If you do not need the legacy parser functions, you can set this variable to `fa
791793
```php
792794
$wgRobloxAPIRegisterLegacyParserFunctions = false;
793795
```
796+
797+
### `$wgRobloxAPIDataSourceUsageLimits`
798+
799+
The maximum number of times a data source can be used on a single page. By default, there are no limits:
800+
801+
```php
802+
$wgRobloxAPIDataSourceUsageLimits = [];
803+
```
804+
805+
If you want to limit the usage of a data source, you can do so like this:
806+
807+
```php
808+
$wgRobloxAPIDataSourceUsageLimits = [
809+
'gameData' => 1,
810+
'userId' => 2,
811+
];
812+
```
813+
814+
In this example, the `gameData` data source can only be used once per page, and the `userId` data source can be used
815+
twice per page. If a data source is used more than the allowed limit, an error message will be displayed.
816+
817+
The usage counter is evaluated after transclusion expansion and before cache lookup.
818+
Therefore, calls satisfied from cache still count towards the per-page limit.
819+
820+
Setting a limit for a data source will also affect data sources that depend on it. Dependent data sources themselves
821+
currently cannot be limited.
822+
823+
### `$wgRobloxAPIShowPlainErrors`
824+
825+
Whether to show errors in plain text format instead of rendering a codex error box.
826+
827+
By default, this is set to `false`, which means that errors are rendered in a codex error box:
828+
829+
```php
830+
$wgRobloxAPIShowPlainErrors = false;
831+
```
832+
833+
If you want to show errors in plain text format instead, you can set this variable to `true`:
834+
835+
```php
836+
$wgRobloxAPIShowPlainErrors = true;
837+
```

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"require-dev": {
33
"mediawiki/mediawiki-codesniffer": "47.0.0",
4-
"mediawiki/mediawiki-phan-config": "0.15.1",
4+
"mediawiki/mediawiki-phan-config": "0.16.0",
55
"mediawiki/minus-x": "1.1.3",
66
"php-parallel-lint/php-console-highlighter": "1.0.0",
77
"php-parallel-lint/php-parallel-lint": "1.4.0"

extension.json

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "RobloxAPI",
3-
"version": "1.4.0",
3+
"version": "1.5.0",
44
"author": [
55
"SomeRandomDeveloper"
66
],
@@ -9,7 +9,7 @@
99
"license-name": "GPL-2.0-or-later",
1010
"type": "parserhook",
1111
"requires": {
12-
"MediaWiki": ">= 1.42.0"
12+
"MediaWiki": ">= 1.43.0"
1313
},
1414
"AutoloadNamespaces": {
1515
"MediaWiki\\Extension\\RobloxAPI\\": "src/"
@@ -18,6 +18,32 @@
1818
"MediaWiki\\Extension\\RobloxAPI\\Tests\\": "tests/phpunit/unit/"
1919
},
2020
"config": {
21+
"RobloxAPIAllowedArguments": {
22+
"value": {},
23+
"description": "The arguments per argument type that are allowed to be used in the extension. If empty, all arguments for the type are allowed.",
24+
"merge_strategy": "array_plus_2d"
25+
},
26+
"RobloxAPICachingExpiries": {
27+
"value": {
28+
"*": 600,
29+
"assetThumbnail": 7200,
30+
"badgeInfo": 1800,
31+
"groupData": 3600,
32+
"userAvatarThumbnail": 3600,
33+
"userId": 86400,
34+
"userInfo": 86400
35+
},
36+
"description": "The amount of seconds after the cache for a data source expires. '*' is a wildcard for all data sources."
37+
},
38+
"RobloxAPIDataSourceUsageLimits": {
39+
"value": {},
40+
"description": "The maximum amount of times a data source can be used per page. If empty, no limit is applied.",
41+
"merge_strategy": "array_plus_2d"
42+
},
43+
"RobloxAPIDisableCache": {
44+
"value": false,
45+
"description": "Whether or not to disable the cache for the extension."
46+
},
2147
"RobloxAPIEnabledDatasources": {
2248
"value": [
2349
"gameData",
@@ -46,38 +72,21 @@
4672
"merge_strategy": "provide_default",
4773
"description": "The data sources that should be enabled and available."
4874
},
49-
"RobloxAPICachingExpiries": {
50-
"value": {
51-
"*": 600,
52-
"assetThumbnail": 7200,
53-
"badgeInfo": 1800,
54-
"groupData": 3600,
55-
"userAvatarThumbnail": 3600,
56-
"userId": 86400,
57-
"userInfo": 86400
58-
},
59-
"description": "The amount of seconds after the cache for a data source expires. '*' is a wildcard for all data sources."
60-
},
61-
"RobloxAPIAllowedArguments": {
62-
"value": {},
63-
"description": "The arguments per argument type that are allowed to be used in the extension. If empty, all arguments for the type are allowed.",
64-
"merge_strategy": "array_plus_2d"
65-
},
66-
"RobloxAPIRequestUserAgent": {
67-
"value": null,
68-
"description": "The user agent that should be used when making requests to the Roblox API."
69-
},
70-
"RobloxAPIDisableCache": {
71-
"value": false,
72-
"description": "Whether or not to disable the cache for the extension."
73-
},
7475
"RobloxAPIParserFunctionsExpensive": {
7576
"value": true,
7677
"description": "Whether or not to make the parser functions expensive."
7778
},
7879
"RobloxAPIRegisterLegacyParserFunctions": {
7980
"value": true,
8081
"description": "Whether or not to register the legacy parser functions that became deprecated in v1.2.0."
82+
},
83+
"RobloxAPIRequestUserAgent": {
84+
"value": null,
85+
"description": "The user agent that should be used when making requests to the Roblox API."
86+
},
87+
"RobloxAPIShowPlainErrors": {
88+
"value": false,
89+
"description": "Whether errors should be shown as plain text instead of being rendered in an error box."
8190
}
8291
},
8392
"ConfigRegistry": {

i18n/en.json

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,26 @@
66
},
77
"robloxapi-desc": "Provides easy access to the Roblox API via parser functions.",
88
"robloxapi-error-no-arguments": "Please provide a valid data source!",
9-
"robloxapi-error-invalid-args-count": "Invalid number of arguments!",
10-
"robloxapi-error-invalid-id": "Invalid ID value '$1'!",
9+
"robloxapi-error-invalid-id": "Invalid ID value \"$1\"!",
1110
"robloxapi-error-invalid-data": "Endpoint returned invalid data!",
1211
"robloxapi-error-decode-failure": "Failed to decode response!",
13-
"robloxapi-error-datasource-not-found": "Data source '$1' not found!",
12+
"robloxapi-error-datasource-not-found": "Data source \"$1\" not found!",
1413
"robloxapi-error-unexpected-data-structure": "Unexpected data structure!",
1514
"robloxapi-error-datasource-returned-no-data": "Data source returned no data!",
1615
"robloxapi-error-user-group-not-found": "Failed to find the group data for the given user! The user may not be in the group.",
1716
"robloxapi-error-request-failed": "Request failed!",
18-
"robloxapi-error-arg-not-allowed": "Argument '$1' is not allowed for type '$2'!",
17+
"robloxapi-error-arg-not-allowed": "Argument \"$1\" is not allowed for type \"$2\"!",
1918
"robloxapi-error-invalid-thumbnail-size": "Invalid thumbnail size!",
2019
"robloxapi-error-invalid-username": "Invalid username!",
2120
"robloxapi-error-missing-argument": "A required argument of type $1 is missing!",
22-
"robloxapi-error-missing-optional-argument-value": "Incorrectly formatted optional argument! Note that optional arguments must be in the format of 'key=value'.",
23-
"robloxapi-error-unknown-optional-argument": "Unknown optional argument '$1'!",
24-
"robloxapi-error-invalid-thumbnail-format": "Invalid thumbnail format '$1'! Possible values are 'Webp' and 'Png'.",
25-
"robloxapi-error-invalid-boolean": "Invalid boolean value '$1'! Must be 'true' or 'false'.",
26-
"robloxapi-error-invalid-return-policy": "Invalid return policy '$1'! Must be 'PlaceHolder', 'ForcePlaceHolder', 'AutoGenerated', or 'ForceAutoGenerated'.",
27-
"robloxapi-error-too-many-required-args": "The argument '$1' exceeds the maximum number of required arguments for this data source! Please refer to the documentation.",
28-
"robloxapi-error-invalid-user-games-limit": "Invalid limit '$1'! Must be 10, 25 or 50.",
29-
"robloxapi-error-invalid-sort-order": "Invalid sort order '$1'! Must be 'Asc' or 'Desc'."
21+
"robloxapi-error-missing-optional-argument-value": "Incorrectly formatted optional argument! Note that optional arguments must be in the format of \"key=value\".",
22+
"robloxapi-error-unknown-optional-argument": "Unknown optional argument \"$1\"!",
23+
"robloxapi-error-invalid-thumbnail-format": "Invalid thumbnail format \"$1\"! Possible values are \"Webp\" and \"Png\".",
24+
"robloxapi-error-invalid-boolean": "Invalid boolean value \"$1\"! Must be \"true\" or \"false\".",
25+
"robloxapi-error-invalid-return-policy": "Invalid return policy \"$1\"! Must be \"PlaceHolder\", \"ForcePlaceHolder\", \"AutoGenerated\", or \"ForceAutoGenerated\".",
26+
"robloxapi-error-too-many-required-args": "The argument \"$1\" exceeds the maximum number of required arguments for this data source! Please refer to the documentation.",
27+
"robloxapi-error-invalid-user-games-limit": "Invalid limit \"$1\"! Must be 10, 25 or 50.",
28+
"robloxapi-error-invalid-sort-order": "Invalid sort order \"$1\"! Must be \"Asc\" or \"Desc\".",
29+
"robloxapi-error-usage-limit": "The \"$1\" data source can only be used $2 times per page!",
30+
"robloxapi-error-usage-limit-dependent": "The \"$1\" data source (called through dependent data source $3) can only be used $2 times per page!"
3031
}

0 commit comments

Comments
 (0)