Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
44.44% covered (danger)
44.44%
4 / 9
66.67% covered (warning)
66.67%
4 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
RegistrationHooks
44.44% covered (danger)
44.44%
4 / 9
66.67% covered (warning)
66.67%
4 / 6
12.17
0.00% covered (danger)
0.00%
0 / 1
 registerExtension
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 onListDefinedTags
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 onChangeTagsAllowedAdd
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 onChangeTagsListActive
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 onUserGetReservedNames
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 onLoadExtensionSchemaUpdates
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Extension\MediaUploader\Hooks;
4
5use DatabaseUpdater;
6use MediaWiki\ChangeTags\Hook\ChangeTagsAllowedAddHook;
7use MediaWiki\ChangeTags\Hook\ChangeTagsListActiveHook;
8use MediaWiki\ChangeTags\Hook\ListDefinedTagsHook;
9use MediaWiki\Extension\MediaUploader\Maintenance\MigrateCampaigns;
10use MediaWiki\Installer\Hook\LoadExtensionSchemaUpdatesHook;
11use MediaWiki\User\Hook\UserGetReservedNamesHook;
12
13/**
14 * Hooks loosely related to extension registration.
15 */
16class RegistrationHooks implements
17    UserGetReservedNamesHook,
18    ListDefinedTagsHook,
19    ChangeTagsListActiveHook,
20    ChangeTagsAllowedAddHook,
21    LoadExtensionSchemaUpdatesHook
22{
23    /**
24     * Change tags used in the extension.
25     */
26    public const CHANGE_TAGS = [ 'uploadwizard' ];
27
28    /**
29     * Sets up constants.
30     */
31    public static function registerExtension(): void {
32        require_once dirname( __DIR__, 2 ) . '/defines.php';
33    }
34
35    /**
36     * Lists tags used by MediaUploader (via ListDefinedTags,
37     * ListExplicitlyDefinedTags & ChangeTagsListActive hooks)
38     *
39     * @param string[] &$tags
40     *
41     * @return void
42     */
43    public function onListDefinedTags( &$tags ) {
44        $tags = array_merge( $tags, self::CHANGE_TAGS );
45    }
46
47    /**
48     * @inheritDoc
49     */
50    public function onChangeTagsAllowedAdd( &$allowedTags, $addTags, $user ) {
51        $this->onListDefinedTags( $allowedTags );
52    }
53
54    /**
55     * @inheritDoc
56     */
57    public function onChangeTagsListActive( &$tags ) {
58        $this->onListDefinedTags( $tags );
59    }
60
61    /**
62     * Reserves the 'MediaUploader' username.
63     *
64     * @param array &$reservedUsernames
65     *
66     * @return void
67     */
68    public function onUserGetReservedNames( &$reservedUsernames ) {
69        $reservedUsernames[] = 'MediaUploader';
70    }
71
72    /**
73     * @param DatabaseUpdater $updater
74     *
75     * @return void
76     */
77    public function onLoadExtensionSchemaUpdates( $updater ) {
78        $type = $updater->getDB()->getType();
79        $path = dirname( __DIR__, 2 ) . '/sql';
80
81        $updater->addExtensionTable( 'mu_campaign', "$path/$type/tables-generated.sql" );
82
83        $updater->addPostDatabaseUpdateMaintenance( MigrateCampaigns::class );
84    }
85}