Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
26.67% |
4 / 15 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
FileImporterHooks | |
26.67% |
4 / 15 |
|
50.00% |
2 / 4 |
33.24 | |
0.00% |
0 / 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% |
2 / 2 |
|
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\Hook\BeforeInitializeHook; |
10 | use MediaWiki\MediaWikiServices; |
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 | /** |
29 | * Show an import success message when appropriate. |
30 | * |
31 | * @see https://www.mediawiki.org/wiki/Manual:Hooks/BeforeInitialize |
32 | * |
33 | * @param Title $title |
34 | * @param null $unused |
35 | * @param OutputPage $output |
36 | * @param User $user |
37 | * @param WebRequest $request |
38 | * @param ActionEntryPoint $mediaWiki |
39 | */ |
40 | public function onBeforeInitialize( |
41 | $title, |
42 | $unused, |
43 | $output, |
44 | $user, |
45 | $request, |
46 | $mediaWiki |
47 | ) { |
48 | if ( $request->getVal( ImportSuccessSnippet::NOTICE_URL_KEY ) === null |
49 | || !$title->inNamespace( NS_FILE ) |
50 | || !$title->exists() |
51 | || !$user->isNamed() |
52 | ) { |
53 | return; |
54 | } |
55 | |
56 | $output->enableOOUI(); |
57 | $output->prependHTML( |
58 | ( new ImportSuccessSnippet() )->getHtml( |
59 | $output->getContext(), $title, $user ) ); |
60 | } |
61 | |
62 | /** |
63 | * @see https://www.mediawiki.org/wiki/Manual:Hooks/ChangeTagsListActive |
64 | * |
65 | * @param string[] &$tags |
66 | */ |
67 | public function onChangeTagsListActive( &$tags ) { |
68 | $tags[] = 'fileimporter'; |
69 | $tags[] = 'fileimporter-imported'; |
70 | } |
71 | |
72 | /** |
73 | * @see https://www.mediawiki.org/wiki/Manual:Hooks/ListDefinedTags |
74 | * |
75 | * @param string[] &$tags |
76 | */ |
77 | public function onListDefinedTags( &$tags ) { |
78 | $tags[] = 'fileimporter'; |
79 | $tags[] = 'fileimporter-imported'; |
80 | } |
81 | |
82 | /** |
83 | * Add FileImporter username to the list of reserved ones for |
84 | * replacing suppressed usernames in certain revisions |
85 | * |
86 | * @param string[] &$reservedUsernames |
87 | */ |
88 | public function onUserGetReservedNames( &$reservedUsernames ) { |
89 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
90 | $reservedUsernames[] = $config->get( 'FileImporterAccountForSuppressedUsername' ); |
91 | } |
92 | |
93 | } |