This does not include use of MediaWiki\Maintenance\Maintenance,
assuming the maintenance scripts going into the same namespace
Change-Id: I488f95b537ce86eb5e463be7bce3653610dd13d9
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: I7dec01892a987a87b1b79374a1c28f97d055e8fa
Why:
* Maintenance scripts in core have bolierplate code that is
added before and after the class to allow directly running
the maintenance script.
* Running the maintenance script directly has been deprecated
since 1.40, so this boilerplate code is only to support a now
deprecated method of running maintenance scripts.
* This code cannot also be marked as covered, due to PHPUnit
not recognising code coverage for files.
* Therefore, it is best to ignore this boilerplate code in code
coverage reports as it cannot be marked as covered and also
is for deprecated code.
What:
* Wrap the boilerplate code (requiring Maintenance.php and then
later defining the maintenance script class and running if the
maintenance script was called directly) with @codeCoverageIgnore
comments.
* Some files use a different boilerplate code, however, these
should also be marked as ignored for coverage for the same
reason that coverage is not properly reported for files.
Bug: T371167
Change-Id: I32f5c6362dfb354149a48ce9c28da9a7fc494f7c
And deprecated aliases for the the no namespaced classes.
ReplicatedBagOStuff that already is deprecated isn't moved.
Bug: T353458
Change-Id: Ie01962517e5b53e59b9721e9996d4f1ea95abb51
This is to make it clearer that they're related to converting serialized
content back into JSON, rather than stating that things are not
representable in JSON.
Change-Id: Ic440ac2d05b5ac238a1c0e4821d3f2d858bc3d76
And start using them instead of wfGetDB(), LB/LBF connection methods or
worse, $this->getDB().
$this->getDB() reuses the database object regardless of whether you're
calling a replica or primary, leading to returning a replica on a
primary and other way around.
Bug: T330641
Change-Id: I9e2cf85ca277022284fc26b9f37db57bd12aaa81
This adds support for ES6 and ES7 syntax to user scripts, thus
matching the wikimedia/minify library.
Bug: T75714
Depends-On: I43d4619a32e37eb42e1aaa55a1f602962609c52b
Depends-On: If3b2b4a75013baeaa0d9b92cd10dfb06e5534153
Change-Id: Ie309e761f8b20640f7c0e85def0a3d1ccc8a658e
In preparation for the underlying library changing, generalize the
tests for this code so that test changes are kept to a minimum in
the actual commit. Rather than test the upstream directly, move
our custom test cases from JsMinPlusTest to ResourceLoader/ModuleTest.
Fix benchmarkJSMinPlus.php to not emit warnings on PHP 8.2 due to
use of dynamic property creation:
> PHP Deprecated: Creation of dynamic property JSNode::$readOnly
> is deprecated in /mediawiki/includes/libs/jsminplus.php:1728
Bug: T75714
Change-Id: I0515be8229f51de48c1f0c92f09e2d827e1b1add
Maintenance class provides a method for getting a fresh reference
of the MW services container instance. Let's make use of these in
maintenance scripts now that we have it.
NOTE: There are still some static methods like in refreshLinks.php
that makes use of services that we can't use this method for now.
Change-Id: Idba744057577896fc97c9ecf4724db27542bf01c
Using a php parser written on top of ANTLR4, done semi-automatically.
I checked everything and made adjustments.
Bug: T311866
Change-Id: I6150c6909bce8f3dbd745a26380cc0af9d9c547f
benchmarkHooks.php just gave a fatal error. So update it to use
HookContainer::register() and HookContainer::run().
Change-Id: Ifa1fe5a39d70f6779c002815be19e46ad81f6dc6
There is no way to express that Title::castFromPageIdentity(),
Title::castFromPageReference() and Title::castFromLinkTarget()
can only return null when the parameter is null. We need to add
Phan suppressions or explicit types almost everywhere that these
methods are used with parameters that are known to not be null.
Instead, introduce new methods Title::newFromPageIdentity() and
Title::newFromPageReference() (Title::newFromLinkTarget() already
exists), without the null-coalescing behavior, and use them when
the parameter is not null. This lets static analysis tools, and
humans, easily understand where nulls can't appear.
Do the same with the corresponding TitleFactory methods.
Change the obvious uses of castFrom*() to newFrom*() (if there is
a Phan suppression, a type check, or a method call on the result).
Change-Id: Ida4da75953cf3bca372a40dc88022443109ca0cb
The purpose of MW_USE_LEGACY_DEFAULT_SETTINGS was to allow Setup.php to
load default values from DefaultSettings.php, instead of using
MainConfigSchema. It was put into place for the benefit of third-party
installations that encounter issues with using MainConfigSchema. No such
issues have been reported, so we can remove the compatibility switch in
1.40.
The use of DefaultSettings.php as been deprecated since 1.39, but there
are still several extensions that rely on loading it. It remains a stub
for MainConfigSchema::listDefaultValues() for now.
Change-Id: I280f80e5be15fbcd809596087b299add5f83af1f
Allows ad-hoc defining of a function that is then invoked with some
additional context from the code snippet. Using the example from
<https://wikitech.wikimedia.org/wiki/Performance/Guides/PHP_optimisation_tips>
```
$ php maintenance/benchmarks/benchmarkEval.php \
--setup 'function getFirstElement($array) { return reset( $array ); }' \
--code '$array = range(0, 1000000); getFirstElement($array);'
$ php maintenance/benchmarks/benchmarkEval.php \
--setup 'function getFirstElement($array) { return $array[0]; }' \
--code '$array = range(0, 1000000); getFirstElement($array);'
```
This behaves notably different from e.g. placing a `return reset()`
directly in the eval code body, presumably due to lack of function
indirection.
Change-Id: I024b44504d94786caa64a2ad7d4558aa755af984
Previously, SettingsBuilder would allow configuration to be loaded
and modified until it was "finalized", at which point configuration
became read only. This patch introduces an intermediate stage where
registration dynamic manipulation of config values can be performed,
after all extensions have been loaded and all config schemas are known.
Motivation:
Extension registration callbacks are typically used to dynamically set
config variables, often based on other configuration. This should be
done using SettingsBuilder rather than global variables. But previously,
we could only be sure that all extensions are known after SettingsBuilder
was "finalized", at which point it would be impossible to change config
values.
Change-Id: I6f8f9f3f7252f0024282d7b005671f28a5b3acc3
The goal is to keep the actual default values for settings in the same
place as the setting is declared, and applied using the regular means
for loading the settings -- not in a separate piece of code that needs
to be loaded through some entirely different mechanism.
SetupDynamicConfig.php now contains a few categories of things:
* Post-processing of configuration settings, where already-set settings
are altered. This could be moved to MainConfigSchema too as a separate
set of methods.
* Processing of old aliases of settings (blacklist, slave) that are not
registered as settings anymore and therefore are not available to
MainConfigSchema. This could perhaps be moved to LocalSettings
processing somehow?
* Setting $wgUseEnotif, which is also not registered as a setting.
Easiest would be just to declare it as a setting and have it set
unconditionally.
* Setting the actual timezone to $wgLocaltimezone. This is not related
to configuration and should just be in Setup.php.
Bug: T305093
Change-Id: Ia5c23b52dbbfcb3d07ffcf5d3b7f2d7befba2a26
This is a modified rebase of a patch by Tim,
see I75f405930a7b14561389c59d147640e870146bec.
Some benchmark results (from my laptop):
Loading defaults from config-schema.php:
- Master: 115/sec ( 8.7ms)
- I75f4059: (Tim): 575/sec ( 1.7ms)
- Id9dd0bf: (Daniel): 1120/sec ( 0.9ms)
- This (Tim+Daniel): 1420/sec ( 0.7ms)
Loading defaults and merging settings (worst case):
- Master: 80/sec (12.4ms)
- I75f4059: (Tim): 93/sec (10.8ms)
- Id9dd0bf: (Daniel): 200/sec ( 4.9ms)
- This (Tim+Daniel): 682/sec ( 1.5ms)
Original commit message by Tim:
* Explicitly import function array_key_exists to activate the special
opcode
* Batch creation of MergeStrategy objects
* Batch default assignment to ArrayConfigBuilder
The batches mostly help by allowing more inlining, eliminating some
function calls.
Reduced time for apply/finalize benchmark from 540µs to 170µs.
Co-Authored-By: Tim Starling <tstarling@wikimedia.org>
Change-Id: I3d4dd685eaaa4351801b3bac6ce1592eea925c5f
Make phan stricter about null types by setting null_casts_as_any_type to
false (the default in mediawiki-phan-config)
Remaining false positive issues are suppressed.
The suppression and the setting change can only be done together
Bug: T242536
Bug: T301991
Change-Id: I0f295382b96fb3be8037a01c10487d9d591e7e01
php internal functions like floor/round/ceil documented to return
float, most cases the result is used as int, added casts
Found by phan strict checks
Change-Id: I92daeb0f7be8a0566fd9258f66ed3aced9a7b792
Rename Sanitizer::removeHTMLtags() into an @internal method named
::internalRemoveHtmlTags() so that we can deprecate external use.
Code search:
https://codesearch.wmcloud.org/deployed/?q=removeHTMLtags&i=nope&files=&excludeFiles=&repos=
Followup-To: Ic864c01471c292f11799c4fbdac4d7d30b8bc50f
Depends-On: Iaca83ed06e9c61d8366579cd2283cba653c82319
Depends-On: I1963bfe9a99198ea02ca482a5769467ce806cd58
Depends-On: I83923d8b38d33f3638cd53958dd10f257ec21f7c
Depends-On: I018b34bb5f6e113056da9b04cc72d4318422adce
Change-Id: I202826f8b27519f7be89643e24eda47a6e3fc9f6
The existing Sanitizer::removeHTMLtags() method, in addition to having
dodgy capitalization, uses regular expressions to parse the HTML.
That produces corner cases like T298401 and T67747 and is not guaranteed
to yield balanced or well-formed HTML.
Instead, introduce and use a new Sanitizer::removeSomeTags() method
which is guaranteed to always return balanced and well-formed HTML.
Note that Sanitizer::removeHTMLtags()/::removeSomeTags() take a callback
argument which (as far as I can tell) is never used outside core. Mark
that argument as @internal, and clean up the version used by
::removeSomeTags().
Use the new ::removeSomeTags() method in the two places where
DISPLAYTITLE is handled (following up on T67747). The use by the
legacy parser is more difficult to replace (and would have a
performace cost), so leave the old ::removeHTMLtags() method in place
for that call site for now: when the legacy parser is replaced by
Parsoid the need for the old ::removeHTMLtags() will go away. In a
follow-up patch we'll rename ::removeHTMLtags() and mark it @internal
so that we can deprecate ::removeHTMLtags() for external use.
Some benchmarking code added. On my machine, with PHP 7.4, the new
method tidies short 30-character title strings at a rate of about
6764/s while the tidy-based method being replaced here managed 6384/s.
Sanitizer::removeHTMLtags blazes through short strings 20x faster
(120,915/s); some of this difference is due to the set up cost of
creating the tag whitelist and the Remex pipeline, so further
optimizations could doubtless be done if Sanitizer::removeSomeTags()
is more widely used.
Bug: T299722
Bug: T67747
Change-Id: Ic864c01471c292f11799c4fbdac4d7d30b8bc50f