Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
26.67% |
4 / 15 |
|
60.00% |
3 / 5 |
CRAP | |
0.00% |
0 / 1 |
FileImporterHooks | |
26.67% |
4 / 15 |
|
60.00% |
3 / 5 |
40.94 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
onBeforeInitialize | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
30 | |||
onChangeTagsListActive | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
onListDefinedTags | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
onUserGetReservedNames | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace FileImporter; |
4 | |
5 | use FileImporter\Html\ImportSuccessSnippet; |
6 | use MediaWiki\Actions\ActionEntryPoint; |
7 | use MediaWiki\ChangeTags\Hook\ChangeTagsListActiveHook; |
8 | use MediaWiki\ChangeTags\Hook\ListDefinedTagsHook; |
9 | use MediaWiki\Config\Config; |
10 | use MediaWiki\Hook\BeforeInitializeHook; |
11 | use MediaWiki\Output\OutputPage; |
12 | use MediaWiki\Request\WebRequest; |
13 | use MediaWiki\Title\Title; |
14 | use MediaWiki\User\Hook\UserGetReservedNamesHook; |
15 | use MediaWiki\User\User; |
16 | |
17 | /** |
18 | * @license GPL-2.0-or-later |
19 | * @author Andrew Kostka |
20 | */ |
21 | class FileImporterHooks implements |
22 | BeforeInitializeHook, |
23 | ChangeTagsListActiveHook, |
24 | ListDefinedTagsHook, |
25 | UserGetReservedNamesHook |
26 | { |
27 | |
28 | private Config $config; |
29 | |
30 | public function __construct( |
31 | Config $config |
32 | ) { |
33 | $this->config = $config; |
34 | } |
35 | |
36 | /** |
37 | * Show an import success message when appropriate. |
38 | * |
39 | * @see https://www.mediawiki.org/wiki/Manual:Hooks/BeforeInitialize |
40 | * |
41 | * @param Title $title |
42 | * @param null $unused |
43 | * @param OutputPage $output |
44 | * @param User $user |
45 | * @param WebRequest $request |
46 | * @param ActionEntryPoint $mediaWiki |
47 | */ |
48 | public function onBeforeInitialize( |
49 | $title, |
50 | $unused, |
51 | $output, |
52 | $user, |
53 | $request, |
54 | $mediaWiki |
55 | ) { |
56 | if ( $request->getVal( ImportSuccessSnippet::NOTICE_URL_KEY ) === null |
57 | || !$title->inNamespace( NS_FILE ) |
58 | || !$title->exists() |
59 | || !$user->isNamed() |
60 | ) { |
61 | return; |
62 | } |
63 | |
64 | $output->enableOOUI(); |
65 | $output->prependHTML( |
66 | ( new ImportSuccessSnippet() )->getHtml( |
67 | $output->getContext(), $title, $user ) ); |
68 | } |
69 | |
70 | /** |
71 | * @see https://www.mediawiki.org/wiki/Manual:Hooks/ChangeTagsListActive |
72 | * |
73 | * @param string[] &$tags |
74 | */ |
75 | public function onChangeTagsListActive( &$tags ) { |
76 | $tags[] = 'fileimporter'; |
77 | $tags[] = 'fileimporter-imported'; |
78 | } |
79 | |
80 | /** |
81 | * @see https://www.mediawiki.org/wiki/Manual:Hooks/ListDefinedTags |
82 | * |
83 | * @param string[] &$tags |
84 | */ |
85 | public function onListDefinedTags( &$tags ) { |
86 | $tags[] = 'fileimporter'; |
87 | $tags[] = 'fileimporter-imported'; |
88 | } |
89 | |
90 | /** |
91 | * Add FileImporter username to the list of reserved ones for |
92 | * replacing suppressed usernames in certain revisions |
93 | * |
94 | * @param string[] &$reservedUsernames |
95 | */ |
96 | public function onUserGetReservedNames( &$reservedUsernames ) { |
97 | $reservedUsernames[] = $this->config->get( 'FileImporterAccountForSuppressedUsername' ); |
98 | } |
99 | |
100 | } |