Commit graph

1196 commits

Author SHA1 Message Date
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
Tim Starling
09cd8eb080 MessageFormatterFactory
An injectable service interface for message formatting, somewhat
narrowed compared to Message.

Only the text format is implemented in this framework so far, with
getTextFormatter() returning a formatter that converts to the text
format. Other formatters could be added to MessageFormatterFactory.

Bug: T226598
Change-Id: Id053074c1dbcb692e8309fdca602f94a385bca0c
2019-08-28 12:28:05 +10:00
Brad Jorsch
002f409a0b
API: Abstract out parameter validation
With the introduction of a REST API into MediaWiki core, we're going to
want to share parameter validation logic rather than having similar code
in both the Action API and the REST API. This abstracts out parameter
validation logic as a library.

There will be at least two follow-up patches:
* One to add calls in the REST API, plus the interface for the REST API
  to do body validation. Should be reasonably straightforward.
* One to adjust the Action API to use this. That'll be much less
  straightforward, as the Action API needs some MediaWiki-specific types
  (which the REST API might use too in the future) and needs to override
  the defaults on some of the library's checks (to maintain back-compat).

Bug: T142080
Bug: T223239
Change-Id: I5c0cc3a8d686ace97596df5832c450a6a50f902c
Depends-On: Iea05dc439688871c574c639e617765ae88a75ff7
2019-06-23 10:58:44 +02:00
Tim Starling
3f0056a252 REST API initial commit
Add some of the basic REST API class hierarchies:

* EntryPoint
* Router
* Request
* Response
* Handler

The actual entry point file rest.php has been moved to a separate
commit, so this is just an unused library and service.

Bug: T221177
Change-Id: Ifca6bcb8a304e8e8b7f52b79c607bdcebf805cd1
2019-06-12 10:22:28 +10:00
Vedmaka
8e1342ed47 Introduce PermissionManager service
First iteration of adding a PermissionManager service as a replacement
for Title::userCan and User::isBlockedFrom methods.

- Created PermissionManager service
- Migrated Title::userCan to PermissionManager::userCan and deprecated the first
- Migrated Title::quickUserCan to PermissionManager::quickUserCan and deprecated the first
- Migrated User::isBlockedFrom to PermissionManager::isBlockedFrom and deprecated the first

Same for User::isBlockedFrom and PermissionManager::isBlockedFrom - the
$user parameter is now required so the declaration is changed from
isBlockedFrom( $title, ... ) to isBlockedFrom( $user, $title, .. ) which
means before User::isBlockedFrom removal all calls to it need to be updated.

Added PermissionManagerTest, it copies TitlePermissionTest but uses
PermissionManager instance instead of Title methods, this way keeping both tests
in place, we can ensure that nothing was broken and both are in working state
during the deprecation phase.

Bug: T208768
Change-Id: I94479b44afb3068695f8e327b46bda38e44e691f
2019-04-05 14:54:51 +00:00
Kunal Mehta
cc5d9a92a2 build: Updating mediawiki/mediawiki-codesniffer to 24.0.0
Change-Id: I66b1775b7c1d36076d9ca78cbeb42787a743f2aa
2019-02-07 18:39:42 +00:00
Lucas Werkmeister
7585985a46 Fully extract services framework as a library
This code doesn’t use any MediaWiki-specific code, so rename
MediaWiki\Services to Wikimedia\Services and move it below libs/. (Of
course, this does not apply to the MediaWikiServices subclass.)

Class aliases are added to retain backwards compatibity for now.

Bug: T211608
Change-Id: Ic14ea28ef21c359695b309d4293dbaaf5deedc09
2019-01-16 17:31:05 +01:00
Dayllan Maza
a562611e5b Add block restriction classes
Partial blocks logic will be used in multiple places. This
classes will group block restriction functionality to avoid
code duplication

Bug: T202036
Change-Id: I675316dddf272fd0d6172ecad3882160752bf780
2018-10-23 17:41:50 -07:00
Brad Jorsch
dff469a408 Re-namespace RevisionStore and RevisionRecord classes
During development a lot of classes were placed in MediaWiki\Storage\.
The precedent set would mean that every class relating to something
stored in a database table, plus all related value classes and such,
would go into that namespace.

Let's put them into MediaWiki\Revision\ instead. Then future classes
related to the 'page' table can go into MediaWiki\Page\, future classes
related to the 'user' table can go into MediaWiki\User\, and so on.

Note I didn't move DerivedPageDataUpdater, PageUpdateException,
PageUpdater, or RevisionSlotsUpdate in this patch. If these are kept
long-term, they probably belong in MediaWiki\Page\ or MediaWiki\Edit\
instead.

Bug: T204158
Change-Id: I16bea8927566a3c73c07e4f4afb3537e05aa04a5
2018-10-09 10:22:48 -04:00
Umherirrender
a4caa4d0c6 build: Updating mediawiki/mediawiki-codesniffer to 22.0.0
Added spaces around .
Removed empty return statement which are not required
Removed return after phpunit markTestIncomplete,
which is throwing to exit the test, no need for a return

Change-Id: I2c80b965ee52ba09949e70ea9e7adfc58a1d89ce
2018-09-16 15:51:11 +00:00
Kunal Mehta
e5ded68cf0 Use PSR-4 autoloader for includes/auth/
Change-Id: I63dec06f231a57093086f129b3c1d0ebe1389bab
2018-09-01 20:55:53 +00:00
Kunal Mehta
dc4fb23cfa Improve AutoLoader test coverage
Change-Id: Iddb24cad41979a4798392ab08d104dac41ed736d
2018-05-26 21:29:36 -07:00
Kunal Mehta
386bd27f64 Switch includes/{sparql,Storage,tidy} to use the PSR-4 autoloader
Change-Id: I1ae3cb3833a28286eb4ae09b586785d156917e8e
2018-05-24 18:58:18 -07:00
Kunal Mehta
ec76c5b50e Switch includes/{preferences,services,session,shell} to use the PSR-4 autoloader
Change-Id: Ic095ed65d05517cdb7b383cde8c664044f790f05
2018-05-24 18:58:10 -07:00
Kunal Mehta
5cff12767e Move includes/auth back to the standard classmap autoloader
Partially reverts c587ab1375.

Change-Id: Ie8cfe356b07f08d481370b9f61b1d08ed6c9c799
2018-05-24 18:57:42 -07:00
Kunal Mehta
c587ab1375 Switch includes/{auth,edit,editpage} to use the PSR-4 autoloader
Change-Id: I9210d26c1031d69f6691fef038cc2db6f391b70e
2018-05-23 19:36:51 -07:00
Mark A. Hershberger
3b85e362a4 Don't require trailing slash in PSR-4 autoloader directory
This avoids the confusing error “Fatal error: Uncaught
InvalidArgumentException” or similar.

Bug: T195211
Change-Id: Ifda59a26f8bd968a2d0acbdb157d81dc0bf6aab4
2018-05-20 18:42:27 +00:00
mainframe98
70e92cdad5 Fix additional usage of incorrect case
Courtesy of the PhpStorm inspection Case mismatch in method call or
class usage.

Bug: T166759
Change-Id: I27c53658b99048fa0dd8f9d6ef1398620386e1cc
2017-12-15 11:58:11 +01:00
Kunal Mehta
036f5b47ef Enable using PSR-4 autoloader for MediaWiki core and extensions
This adds support for a PSR-4 (<http://www.php-fig.org/psr/psr-4/>)
autoloader, so instead of needing to manually list each class, just the
namespace prefix is needed.

Extensions can set a "AutoloadNamespaces" property in extension.json to
register PSR-4 compatible namespaces to be autoloaded.

The implementation is based off of the example implementation
(<http://www.php-fig.org/psr/psr-4/examples/>) with some modifications
for performance, notably cutting down on function calls, and only trying
to look up classes that are namespaced.

The generateLocalAutoload.php script will ignore any directory that is
registered as a PSR-4 namespace.

Bug: T99865
Bug: T173799
Change-Id: Id095dde37cbb40aa424fb628bd3c94e684ca2f65
2017-12-12 00:20:11 +00:00
Chad Horohoe
da6e284638 Remove AutoLoader::loadClass()
A poor design decision if I ever made one. Luckily nobody uses it.

Change-Id: Ia6482cce2e17046346c1f8ea196f9510008faebd
2016-07-22 10:29:02 -07:00
jenkins-bot
9ba3fca2d8 Merge "Remove fix for a 5.3 problem" 2016-02-29 14:46:40 +00:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
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
2016-02-17 01:33:00 -08:00
Max Semenik
014a5f35f3 Remove fix for a 5.3 problem
Change-Id: Icafe66793a4e91aa0461c13987f73c692b2926d0
2016-02-11 15:02:58 -08:00
Timo Tijhof
6a0d8892bc autoloader: Remove incorrect documentation comment
Follows-up I8b1bdb84a969. This is not generated by that script,
the autoload.php file is, but that one has a similar comment
in it already.

Change-Id: Icb44f3dab356820f1e3aa5ba56949219af1b5719
2014-12-19 06:02:34 +00:00
Erik Bernhardson
396a76f2ff Generate $wgAutoloadLocalClasses with a maint script
Currently all new classes in core need to be registered
with the autoloader.  This is acceptable but inconvenient.

This patch adds a script to read the output of php's tokenizer
to determine the names of all the classes within mediawiki core.
Patches with new or removed classes will just need to rerun
the maint script rather than manually adjusting the arrays.

A full conversion to psr-0 + composer would solve this as well,
but this is a very non-intrusive patch that can get us some
portion of the benefit(reduced manual maintenance) today rather
than months down the line once we figure out all the intricacies
of mediawiki + composer.

Change-Id: I8b1bdb84a9699de79f8b9951fa61e5437d083c55
2014-11-13 15:41:31 -08:00
Aaron Schulz
0bfa6b6264 Move request-only template profiling to an always-on parser report
Change-Id: I0660c8d6cac0dadab648eac9736504b7939320f3
2014-11-12 18:06:00 -08:00
jenkins-bot
0e2a9baff3 Merge "Enable profiling via xhprof" 2014-11-12 22:00:30 +00:00
Aaron Schulz
93d2167ca6 Moved MapCacheLRU to libs/
Change-Id: Icb820787afe7298dd3124f5168d3efff19e53ab6
2014-11-10 22:51:29 +00:00
Kunal Mehta
fb54343d6f cdb: One class per file
Change-Id: I18c6f58d8b3747c4da9d74884a3c9a3571f403f3
2014-11-10 19:05:34 +00:00
Kunal Mehta
102fc2ac7b Move Cdb classes into includes/libs/cdb/
Change-Id: I2c4fa605acf5e0cf1fdd4821fe6bcdd690b02759
2014-11-10 10:42:30 -08:00
Aaron Schulz
db5d7a807f Removed incomplete/unused DatabaseType interface
Change-Id: I95b64f0a74f0203092464c4900fef2ac97e3ba35
2014-11-09 22:56:23 -08:00
Bryan Davis
46c47e11bc Enable profiling via xhprof
Add a helper class to assist in collecting profiling information using
XHProf <https://github.com/phacility/xhprof> and a Profiler
implementation to hook it into the existing MediaWiki profiling system.

The Profiler includes support for generating tabular reports similar to
the traditional output of ProfilerSimpleText and ProfilerSimpleTrace or
sending data to a udpprofile daemon as supported by ProfilerSimpleUDP.
It also produces data compatible with the debugging toolbar.

Bug: T759
Change-Id: I16a75cb7636cb5dcef3830d738b2dcd2047d0aaa
2014-11-08 11:47:25 -07:00