Commit graph

1227 commits

Author SHA1 Message Date
Reedy
e4bee84a27 AutoLoader: Use require_once rather than require
This was seen in WMF production during a train deployment, where namespacing of classes,
which had been serialized (for example CacheTime), along with our PSR-4 definitions may result
in cases where PHP tries to load the same PHP file more than once. Combined with non obvious
error messages, require_once gives us better behaviour and error messages.

More explicitly:
In T378006, the autoloader is entered from class_exists(), and the class has a filename
resolvable with PSR-4 which is already loaded by a non-PSR-4 class name. Using require_once
would allow class_exists() to return false in that case.

In T372500, the autoloader is entered from unserialize(). It looks like require_once would
just give you a more informative error message.

Bug: T378006
Bug: T372500
Change-Id: I928f29198af9baf81a3cae604b3adf41595c2176
(cherry picked from commit 03dd4ae7ae0e2ce7e45f0bf2cb913642eef842a8)
2024-10-24 01:36:18 +00:00
Umherirrender
be39a18332 build: Use inline ignore for Generic.CodeAnalysis.AssignmentInCondition
Avoid that new code contains this pattern.

Depends-On: I7a9b5c89129fe4b555d03861f2c3ce3e9e2b2446
Depends-On: Ic2bcc7eeb16d3333dcd019bd209bd7fde843dab9
Depends-On: If20eddd8376ae2e8e29c4e56cd51f7b8eb6642b0
Depends-On: I3414f7e17f4bcb801857bc986bae8eb97aa2bfb8
Depends-On: I38b2729418e8389c681c6cd84858f5e5ed25bd3e
Change-Id: I7cfd2e027edd327cf8be6471e348c137fefacda0
2024-09-01 00:15:10 +02:00
Timo Tijhof
8fb118cb8b recentchanges: Move rcfeed/ to includes/recentchanges/RCFeed/
It is part of the component at
https://phabricator.wikimedia.org/tag/mediawiki-recent-changes/
and
https://www.mediawiki.org/wiki/Developers/Maintainers
and
since Ifac20da51f7e809f under the same "Recent changes" doc group.

The Maintainers list oddly enough lists only rcfeed and completely
forgets the majority of it under /includes/changes (or now,
/includes/recentchanges).

Bug: T364652
Change-Id: I94e6705672c1e2821bdc726aa7a383d9e7c1f7b5
2024-08-29 03:51:40 +01:00
jenkins-bot
796d475ab7 Merge "AutoLoader: Add MediaWiki\RCFeed" 2024-05-21 21:21:02 +00:00
Reedy
5ab70409f5 Namespace includes/password
Bug: T353458
Change-Id: I1a701b5b7ff65356692abb0efde9a2207b6135b6
2024-05-18 16:17:38 +01:00
Reedy
c2b5d19fb4 AutoLoader: Add MediaWiki\RCFeed
Bug: T353458
Follows-Up: Ief351b40fb117e57a868ef7618df2109b550ff58
Change-Id: Ifd6f065b46e02acbbef8eaa62a97658e2b14d384
2024-05-16 23:21:44 +01:00
Reedy
72df6cb8da libs/composer: Namespace under Wikimedia\Composer
Change-Id: I5ffedacf31e60fb0f38e308f8dcf010e577f919e
2024-01-13 20:10:25 +00:00
RazeSoldier
20e77793b8 Refactor checkComposerLockUpToDate.php logic out to reuseable class
Introduce LockFileChecker that used to check whether
composer-installed dependencies (no-dev) are up-to-date.

Bug: T283389
Change-Id: I0d56f235604d5c856bae5d170230f8c7ca0729c6
2024-01-13 18:35:07 +00:00
Reedy
b440c5d27b AutoLoader: Make $psr4Namespaces private (reinstated)
This reapplies commit 8fb44ec4ad, reverted in 44cecd9e77.
Reason: Try again!

Bug: T332930
Change-Id: Ifdb2106242823c802371a7aa994ae6ac6ffe2dbc
2023-08-08 00:40:31 +00:00
DannyS712
07af42e199 Add DeferredUpdatesManager service to replace DeferredUpdates
This patch doesn't deal with the injection of dependencies
and removal of the global state, but rather moves the code
from DeferredUpdates to the new service essentially as-is,
to simplify review. The changes to inject the various
services needed and make DeferredUpdatesManager a proper
service will be done in follow-ups, to make them easier
to follow.

While almost everything is changed from static to non-static,
DeferredUpdates::$scopeStack remains static as
DeferredUpdatesManager::$scopeStack, just in case multiple
versions of the service are created, to ensure that no
updates are missed.

Bug: T265749
Change-Id: I7f07eddf2fc399b15db4fe9be4c792ef8eb0747b
2023-05-29 03:59:03 +00:00
Reedy
44cecd9e77 Revert "AutoLoader: Make $psr4Namespaces private"
This reverts commit 8fb44ec4ad.

Reason for revert: Breaks parsoid CI

Bug: T332930
Change-Id: I39ca6403d8e696c8447995a3a415627bbafdaa14
2023-03-24 13:49:21 +00:00
Reedy
8fb44ec4ad AutoLoader: Make $psr4Namespaces private
Bug: T332930
Bug: T240535
Follows-Up: I1abb27bd70898d04c9253e0b7467447fa96d15a4
Change-Id: I17ed14c7c3ff57ba611867ea779327e6de5678d0
2023-03-23 19:15:29 +00:00
Timo Tijhof
adb9c0cc1b poolcounter: Merge Client and ConnectionManager from extension repo
Code moved as-is from the extension repo with minor changes:

* Adopt PSR-4 namespace.
* Keep backward-compatibility with "PoolCounter_Client"
  in LocalSettings, from before the extension was namespaced recently.
* Document how `connect_timeout` actually works, and that it
  was introduced in MW 1.28 (via extension).
* Add stable interface annotations.

Bug: T201223
Change-Id: Iadec5b4b5d2fc7e76509c9be0a8fa605d95c64a7
2022-12-14 20:28:14 +00:00
Kevin Israel
8ae7194fae AutoLoader: Drop support for $wgAutoloadAttemptLowercase
This setting has been deprecated since 1.35.

Bug: T231412
Change-Id: I88cb45a2dcbb19c2976824279bf95a66ae9afd91
2022-12-04 02:38:57 -05:00
Moh'd Khier Abualruz
efb72f2c67 SpecialContribute Follow up
Follow up to I7f064a954a77373dfec86efae7e378402f500198

From: I28aa164119bc0dbc00f5fcf20bc53dc4851ca0b5
* Fix typo in contribute.css
* Removes selector specificity (scoped to body class to prevent
these styles loading on other special pages)
* Removes non-existent mediawiki.special.contribute module
* Fixes font-sizes to match specification (existing values were invalid).

From: Icfd8a7965d83f2429637139ca0de9ed1520b4169
This module contains all the possible icons this page could make use
of. Seems better to load this one than create an additional ResourceLoader
module to fragment things further.

Changes:
* Use Context for messages instead of wfMessage
* Use generated URLs rather than static ones for the default card
* ContributeCardsHook::onContributeCards is void ( no prevention mode )
* SpecialContribute fixed typo
* Fixed capitalization in messages jsons
* Load Classes with PSR-4
* Redirected always to user's page of the Special:Contribute page ( fixes default selection of tab)

Bug: T286466
includes: I28aa164119bc0dbc00f5fcf20bc53dc4851ca0b5
includes: Icfd8a7965d83f2429637139ca0de9ed1520b4169
Change-Id: Iac34777a89e3e6732a0916dbf0a22677cbc6d121
2022-09-30 19:19:43 +00:00
jenkins-bot
988cd29108 Merge "Collect autoloader info in ExtensionProcessor" 2022-06-08 06:11:58 +00:00
daniel
92e8f4e40a Collect autoloader info in ExtensionProcessor
This change cleans up when and how we register autoloader info for
extensions.

This bumps CACHE_VERSION to 8, to avoid issues in case this patch gets
reverted: the new code doesn't copy the map of class files into
$info['globals']['AutoloadClasses']. If old code was to read a new cache
entry, autoloading would fail.

BREAKING CHANGE: The following methods have been removed from
  ExtensionRegistry without deprecation and without replacement.
  They had been introduced in 1.35 for use in the testing framework,
  and were not in use by any known extension:
  - exportAutoloadClassesAndNamespaces
  - exportTestAutoloadClassesAndNamespaces

NOTE: breaks the hack that SocialProfile has in place for T243861.

Bug: T240535
Change-Id: I6e1ceac034c443d9475f1adc1babecddd6af6d05
2022-06-07 17:39:00 +02:00
Umherirrender
615c077105 Autoloader: Use @phpcs-require-sorted-array
Resort array
The different order for EditPage and Edit seems based on php natcasesort
When using strtolower + natsort it looks good,
when using strtoupper + natsort it looks like natcasesort (not so good)

Change-Id: I335bdce67feb243ba2d409662d57655657f6db34
2022-06-01 21:20:44 +00:00
Tim Starling
3e2653f83b ResourceLoader namespace (attempt 2)
Move ResourceLoader classes to their own namespace. Strip the
"ResourceLoader" prefix from all except ResourceLoader itself.

Move the tests by analogy.

I used a namespace alias "RL" in some callers since RL\Module is less
ambiguous at the call site than just "Module".

I did not address DependencyStore which continues to have a non-standard
location and namespace.

Revert of a241d83e0a.

Bug: T308718
Change-Id: Id08a220e1d6085e2b33f3f6c9d0e3935a4204659
2022-05-24 15:41:46 +00:00
Lucas Werkmeister (WMDE)
a241d83e0a Revert "ResourceLoader namespace"
This reverts commit e08ea8ccb9.

Reason for revert: Breaks Phan in extensions, and as far as I’m aware,
this change isn’t urgently needed for anything, so the simplest fix is
to revert it again for now. After PHP 7.4 it should be safer to try this
again (we hopefully won’t need the two “hack” classes by then).

Bug: T308443
Change-Id: Iff3318cbf97a67f821f78e60da62a583f63e389e
2022-05-16 14:43:33 +00:00
Tim Starling
e08ea8ccb9 ResourceLoader namespace
Move ResourceLoader classes to their own namespace. Strip the
"ResourceLoader" prefix from all except ResourceLoader and
ResourceLoaderContext.

Move the tests by analogy.

I used a namespace alias "RL" in some callers since RL\Module is less
ambiguous at the call site than just "Module".

I did not address DependencyStore which continues to have a non-standard
location and namespace.

Change-Id: I92998ae6a82e0b935c13e02a183e7c324fa410a3
2022-05-16 14:41:27 +10:00
daniel
37af531721 AutoLoader: provide methods for registering classes
This introduces static methods for registering classes and namespaces,
so we don't have to mess with global variables and static members
fields.

Bug: T240535
Change-Id: I1abb27bd70898d04c9253e0b7467447fa96d15a4
2022-05-10 13:55:53 +10:00
Tim Starling
0fc58f7e4d Fix autoload order
For performance, MediaWiki's autoloader needs to be registered before
Composer's autoloader.

Following up I7407bf7a5b201836fde24db97be2dab2856738b5

Change-Id: Ib23fff226a2e1d337e3045f4aa6ba01eaf1b32ce
2022-05-03 12:13:31 +10:00
Aryeh Gregor
246ac2af0c Autoload vendor from AutoLoader, not Setup
Nothing in vendor can depend on anything in our classes, whereas the
reverse dependency could exist, so it makes sense to load vendor first.
This ensures that vendor facilities are available in anything loaded
from our autoloader, for instance polyfills like
str_starts_with()/str_ends_with.

Change-Id: I7407bf7a5b201836fde24db97be2dab2856738b5
2022-04-28 20:36:44 +03:00
Amir Sarabadani
236a0941c0 rdmbs: Start of SQLPlatform to split out of Database
This is the first step to split parts of Database that doesn't require a
connection and are used for query parts.

Bug: T299691
Change-Id: I140aa4328865994499926f898233867ce383908c
2022-04-24 16:07:44 +00:00
Aryeh Gregor
472a914c63 Refactor URL-parsing global functions to class
The new class, UrlUtils, is usable standalone or as a service. Using it
as a service will just automatically load a few settings from site
configuration.

In addition to just making our code cleaner, this will enable making
some of Setup.php's dynamic configuration more sane.

Test coverage is all lines except invalid URLs -- I couldn't find any.

Bug: T305093
Change-Id: I706ef8a50aafb518e13222719575d274c3583b90
2022-04-12 15:14:35 +03:00
C. Scott Ananian
2d66ee70a2 Copy over Parsoid's Config and ServiceWiring classes
* This is the first step of migrating Parsoid integration code into
  core and transitioning Parsoid from an extension to a pure library.

* Parsoid already has conditional code to skip loading Parsoid's
  copy of its classes, but it relies on the existence of ParsoidServices.
  Technically ParsoidServices isn't needed once Parsoid is migrated to
  core -- users can just use MediaWikiServices instead -- but we need
  to temporarily add ParsoidServices as a marker class during the
  transition.

This version of Parsoid's ServiceWiring comes from Parsoid commit
898c813fd832b3f2d7b5a37f60bd65e8368ce18f.

Bug: T302118
Change-Id: I0b388d93143a782c2c3b72e46407572e5c586e4a
2022-03-28 12:36:38 -04:00
daniel
cf581bb2ca Define MW_INSTALL_PATH constant and BaseDirectory config.
Application logic should use the BaseDirectory config variable.
Framework code should use MW_INSTALL_PATH to locate files should.

NOTE: Update https://www.mediawiki.org/wiki/Manual:$IP

Bug: T300301
Depends-On: I7142af16d692f26e90673b058029f572c1ea3991
Change-Id: Ib4caa80bb7007c4c7960a2fd370cf5da7d9ba344
2022-03-04 14:18:27 +01:00
jenkins-bot
51fbd273ab Merge "LinksUpdate refactor" 2022-01-10 18:34:18 +00:00
Kosta Harlan
891b51b258 Prefer is_dir/is_file to file_exists
Mirco-optimisation for performance, part II.

Change-Id: Ie8d5332a510bd18456ebc4a851f4d47f6a010dcb
2022-01-04 11:03:09 +01:00
Tim Starling
d3b2b80067 LinksUpdate refactor
* In LinksUpdate, put each table in its own class, so that the
  special code for each table has a more elegant place to go.
* Use generators to abstract and flatten out the underlying ParserOutput
  data structures, without requiring the data to be copied. This allows
  the incremental logic which was previously duplicated for each table,
  i.e. computing insertions and deletions from the old and new state,
  to be factored out. The per-table batch classes act as container
  abstractions for the underlying data.

Bug: T263437
Depends-On: I472f4a023969bfde6298eb56112c16d2ae842199
Change-Id: Id40be19a8caa7b4669911927964cfd6755c25238
2022-01-04 15:35:57 +11:00
jenkins-bot
ad54b01068 Merge "AutoLoader: Use ?? instead of multiple if-isset-else branches" 2021-08-12 02:05:25 +00:00
Timo Tijhof
58bda4034a AutoLoader: Use ?? instead of multiple if-isset-else branches
I noticed anecdotally that 3% of load.php at WMF is spent in
AutoLoader::find(). It's unclear to me why that's so high, but
this change seemed to help a little bit (tested in a tight loop
on PHP 7.2 on bare macOS, and in a VM with Ubuntu).

[1] https://performance.wikimedia.org/arclamp/svgs/daily/2021-07-10.excimer.load.reversed.svgz

Change-Id: I6ad04d90595f92cc093cc8b922d15025248c73ad
2021-08-11 04:23:19 +00:00
Timo Tijhof
e07a279a39 language: Add MediaWiki\Languages\Data namespace to PSR-4 autoloader
Bug: T225756
Change-Id: I7e30a5f5c9f3c36e8a9e3f1fb6ebebb3bbe727ab
2021-08-10 22:00:25 +00:00
DannyS712
20293e4c99 Add an ActionFactory and start converting to DI
$wgActions used to map string action names to true,
false, a string, a callable, or an object. Now it can also
be an array (that isn't a callable) corresponding to an
ObjectFactory spec for DI.

This patch converts the revisiondelete and rollback actions to
use DI, with the rest to be converted later. The new structure
of $wgActions is fully backwards-compatible.

We don't yet deprecate Action::factory(), ::getActionName(),
and ::exists(), those will be deprecated in a follow-up.

Additionally, we no longer impose a rule that only some
actions can be overridden on a per-article basis via
Article::getActionOverrides().

Bug: T253078
Change-Id: I0fc3c53d671eced1758458f9a0148180b40c6c9b
2021-07-29 01:32:43 +00:00
mainframe98
ae55be3000 Add a JobQueueGroupFactory service
This replaces JobQueueGroup::singleton and ::destroySingletons.
A JobQueueGroup service has been added to serve as convenience
getter.

Bug: T277648
Change-Id: Ic8709119773ab788a07531193dc65d418536eda2
2021-05-07 06:50:29 +00:00
daniel
6627e42284 Add script for resolving class names to files
Use case: for a list of classes used in a specific context such as
MediaWikiServices, list all files containing these classes, so they can
be processed with command line tools such as grep.

Change-Id: I88dbee72dc5a560624f8cc1da0d905460309f624
2021-04-16 11:04:39 +00:00
Petr Pchelko
c621548cf8 Convert mail namespace to Authority/UserIdentity
Change-Id: I1e1ea72f94735ddaf66eab29aad1296e1abffb9b
2021-04-01 15:46:09 -06:00
Daimona Eaytoy
9881e82ef7 AutoLoader: Various micro-optimizations
Spotted a few of these while looking at flamegraphs for T273312. I don't
really think these fixes are going to have a noticeable effect, though,
since the slowness seems to be chiefly caused by FS functions.

Still I think these changes are worth the (low) effort, given that these
code paths are presumably hot, and that readability isn't affected IMHO.

Change-Id: I18c25e8a591d7fdc950c286370b7db5e85f3985f
2021-03-18 17:23:58 +00:00
Tim Starling
20d06b34bb Safer autoloading with respect to file-scope code
Many files were in the autoloader despite having potentially harmful
file-scope code.

* Exclude all CommandLineInc maintenance scripts from the autoloader.
* Introduce  "NO_AUTOLOAD" tag which excludes the file containing it
  from the autoloader. Use it on CommandLineInc.php and a few
  suspicious-looking files without classes in case they are refactored
  to add classes in the future.
* Add a test which parses all non-PSR4 class files and confirms that
  they do not contain dangerous file-scope code. It's slow (15s) but
  its results were enlightening.
* Several maintenance scripts define constants in the file scope,
  intending to modify the behaviour of MediaWiki. Either move the
  define() to a later setup function, or protect with NO_AUTOLOAD.
* Use require_once consistently with Maintenance.php and
  doMaintenance.php, per the original convention which is supposed to
  allow one maintenance script to use the class of another maintenance
  script. Using require breaks autoloading of these maintenance class
  files.
* When Maintenance.php is included, check if MediaWiki has already
  started, and if so, return early. Revert the fix for T250003 which
  is incompatible with this safety measure. Hopefully it was superseded
  by splitting out the class file.
* In runScript.php add a redundant PHP_SAPI check since it does some
  things in file-scope code before any other check will be run.
* Change the if(false) class_alias(...) to something more hackish and
  more compatible with the new test.
* Some site-related scripts found Maintenance.php in a non-standard way.
  Use the standard way.
* fileOpPerfTest.php called error_reporting(). Probably debugging code
  left in; removed.
* Moved mediawiki.compress.7z registration from the class file to the
  caller.

Change-Id: I1b1be90343a5ab678df6f1b1bdd03319dcf6537f
2021-01-11 11:59:36 +11:00
Petr Pchelko
7c68ae9296 Safe ParserOutput extension data and JsonUnserializable helper.
One major difference with what we've had before is that now we
actually write class names into the serialization - given that
this new mechanism is extencible, we can't establish any kind
of mapping of allowed classes. I do not think it's a problem
though.

Bug: T264394
Change-Id: Ia152f3b76b967aabde2d8a182e3aec7d3002e5ea
2020-11-10 11:21:09 -07:00
Timo Tijhof
d04f04097a resourceloader: Use a local HookRunner
Also move ResourceLoaderRegisterModulesHook under the same
namespace. I forgot this one in commit b7ac554304.

This is mainly motivated by making the collaboration graph
on doc.wikimedia.org not huge by pulling in the full range
of core hook interfaces.
<https://doc.wikimedia.org/mediawiki-core/master/php/classResourceLoader.html>

Depends-On: Ifa53d96dd3e4592208dbc991e2af9e6b7598e44d
Depends-On: Ib4571d80f55a4716e28b76ba1d007f95b0fb2540
Change-Id: I576305a5edb36a2ffb513e6d557bbf1d337cb17e
2020-09-17 01:53:18 +00:00
Kunal Mehta
0d9ff859c7 AutoLoader: Remove entry for Wikimedia\Services
Was supposed to be removed as a part of f6603734d2.

Bug: T259448
Change-Id: Ib1ae8102b76dbea42d42b1f44cfed3fa9427511a
2020-08-05 23:50:43 -07:00
Ed Sanders
0cf40a4f7a Flip Yoda conditionals
Change-Id: Id3495b6f15c267123c89f3a0ace496e6ecbeb58e
2020-07-22 17:49:12 +01:00
daniel
f59bf8a22f Use @internal instead of @private per policy
https://www.mediawiki.org/wiki/Stable_interface_policy mandates the use
of @internal. The semantics of @private was never properly defined.

Bug: T247862
Change-Id: I4c7c6e7b5a80e86456965521f88d1dfa7d698f84
2020-06-26 14:14:23 +02:00
Reedy
43c4860c7a Explicit visibility modifiers to AutoLoader.php
Change-Id: I1dbebd79018d12385b8c5ffc01ea3e35036453df
2020-05-09 22:38:07 +00:00
Timo Tijhof
b7ac554304 resourceloader: Move RL hooks to own namespace, use PSR-4
Follows-up f5aaf75ad1.

* Improve some docs for these hooks.
* Add type hints.
* Add them as a subgroup within the ResourceLoader docgroup
  for easy navigation.

Bug: T246855
Change-Id: I52f31e2b63dcf265b27e68ba8fd4f885d82088ac
2020-05-04 22:42:00 +00:00
Tim Starling
f81462048a Add PSR-4 mappings for existing namespaces and the top level
This reduces the size of the class map ($wgAutoloadLocalClasses),
and allows new classes and namespaces to be added without modifying
the class or namespace map as long as they conform to PSR-4.

Adding a PSR-4 mapping for the top-level MediaWiki namespace means that
conforming subnamespaces do not need to be listed.

I did not add some odd or broken cases, since I figure it's better to
fix them by moving the files, which can be done in a separate commit.

I removed testPSR4Completeness, since PSR-4 completeness is no longer
required, that's the point.

Bug: T166010
Change-Id: Ie5e50ecb519b99a1197688c046c7be245ce6da1b
2020-03-10 21:08:30 +11:00
Brad Jorsch
c2b1525908 API: Use ParamValidator library
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
2020-02-04 13:36:14 -05:00
Reedy
4b98c798cd Use https for php-fig url
Change-Id: I60f18839d1d6edb865d12f7cfdef1284c7d1453a
2019-10-16 22:49:25 +01:00