2021-02-16 07:51:49 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools;
|
|
|
|
|
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
|
2023-01-13 12:01:25 +00:00
|
|
|
// PHP unit does not understand code coverage for this file
|
|
|
|
// as the @covers annotation cannot cover a specific file
|
|
|
|
// This is fully tested in ServiceWiringTest.php
|
|
|
|
// @codeCoverageIgnoreStart
|
|
|
|
|
2021-02-16 07:51:49 +00:00
|
|
|
return [
|
Change CommentParser into a service
Goal:
-----
To have a method like CommentParser::parse(), which just takes a node
to parse and a title and returns plain data, so that we don't need to
keep track of the config to construct a CommentParser object (the
required config like content language is provided by services) and
we don't need to keep that object around after parsing.
Changes:
--------
CommentParser.php:
* …is now a service. Constructor only takes services as arguments.
The node and title are passed to a new parse() method.
* parse() should return plain data, but I split this part to a separate
patch for ease of review: I49bfe019aa460651447fd383f73eafa9d7180a92.
* CommentParser still cheats and accesses global state in a few places,
e.g. calling Title::makeTitleSafe or CommentUtils::getTitleFromUrl,
so we can't turn its tests into true unit tests. This work is left
for future commits.
LanguageData.php:
* …is now a service, instead of a static class.
Parser.js:
* …is not a real service, but it's changed to behave in a similar way.
Constructor takes only the required config as argument,
and node and title are instead passed to a new parse() method.
CommentParserTest.php:
parser.test.js:
* Can be simplified, now that we don't need a useless node and title
to test internal methods that don't use them.
testUtils.js:
* Can be simplified, now that we don't need to override internal
ResourceLoader stuff just to change the parser config.
Change-Id: Iadb7757debe000025e52770ca51ebcf24ca8ee66
2022-02-19 02:43:21 +00:00
|
|
|
'DiscussionTools.CommentParser' => static function ( MediaWikiServices $services ): CommentParser {
|
|
|
|
return new CommentParser(
|
|
|
|
$services->getMainConfig(),
|
2022-02-21 17:39:36 +00:00
|
|
|
$services->getContentLanguage(),
|
|
|
|
$services->getLanguageConverterFactory(),
|
2022-02-21 22:07:38 +00:00
|
|
|
$services->getService( 'DiscussionTools.LanguageData' ),
|
|
|
|
$services->getTitleParser()
|
Change CommentParser into a service
Goal:
-----
To have a method like CommentParser::parse(), which just takes a node
to parse and a title and returns plain data, so that we don't need to
keep track of the config to construct a CommentParser object (the
required config like content language is provided by services) and
we don't need to keep that object around after parsing.
Changes:
--------
CommentParser.php:
* …is now a service. Constructor only takes services as arguments.
The node and title are passed to a new parse() method.
* parse() should return plain data, but I split this part to a separate
patch for ease of review: I49bfe019aa460651447fd383f73eafa9d7180a92.
* CommentParser still cheats and accesses global state in a few places,
e.g. calling Title::makeTitleSafe or CommentUtils::getTitleFromUrl,
so we can't turn its tests into true unit tests. This work is left
for future commits.
LanguageData.php:
* …is now a service, instead of a static class.
Parser.js:
* …is not a real service, but it's changed to behave in a similar way.
Constructor takes only the required config as argument,
and node and title are instead passed to a new parse() method.
CommentParserTest.php:
parser.test.js:
* Can be simplified, now that we don't need a useless node and title
to test internal methods that don't use them.
testUtils.js:
* Can be simplified, now that we don't need to override internal
ResourceLoader stuff just to change the parser config.
Change-Id: Iadb7757debe000025e52770ca51ebcf24ca8ee66
2022-02-19 02:43:21 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
'DiscussionTools.LanguageData' => static function ( MediaWikiServices $services ): LanguageData {
|
|
|
|
return new LanguageData(
|
|
|
|
$services->getMainConfig(),
|
|
|
|
$services->getContentLanguage(),
|
|
|
|
$services->getLanguageConverterFactory(),
|
|
|
|
$services->getSpecialPageFactory()
|
|
|
|
);
|
|
|
|
},
|
2021-07-22 07:25:13 +00:00
|
|
|
'DiscussionTools.SubscriptionStore' => static function ( MediaWikiServices $services ): SubscriptionStore {
|
2021-02-16 07:51:49 +00:00
|
|
|
return new SubscriptionStore(
|
2021-12-15 16:15:01 +00:00
|
|
|
$services->getConfigFactory(),
|
2021-02-16 07:51:49 +00:00
|
|
|
$services->getDBLoadBalancerFactory(),
|
|
|
|
$services->getReadOnlyMode(),
|
2023-06-02 19:11:36 +00:00
|
|
|
$services->getUserFactory(),
|
2023-07-26 10:32:27 +00:00
|
|
|
$services->getUserIdentityUtils()
|
2021-02-16 07:51:49 +00:00
|
|
|
);
|
2022-02-16 23:29:10 +00:00
|
|
|
},
|
|
|
|
'DiscussionTools.ThreadItemStore' => static function ( MediaWikiServices $services ): ThreadItemStore {
|
|
|
|
return new ThreadItemStore(
|
|
|
|
$services->getConfigFactory(),
|
|
|
|
$services->getDBLoadBalancerFactory(),
|
|
|
|
$services->getReadOnlyMode(),
|
|
|
|
$services->getPageStore(),
|
|
|
|
$services->getRevisionStore(),
|
|
|
|
$services->getTitleFormatter(),
|
|
|
|
$services->getActorStore()
|
|
|
|
);
|
|
|
|
},
|
|
|
|
'DiscussionTools.ThreadItemFormatter' => static function ( MediaWikiServices $services ): ThreadItemFormatter {
|
|
|
|
return new ThreadItemFormatter(
|
|
|
|
$services->getLinkRenderer()
|
|
|
|
);
|
|
|
|
},
|
2021-02-16 07:51:49 +00:00
|
|
|
];
|
2023-01-13 12:01:25 +00:00
|
|
|
|
|
|
|
// @codeCoverageIgnoreEnd
|