Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
66.67% covered (warning)
66.67%
2 / 3
CRAP
37.50% covered (danger)
37.50%
6 / 16
FileImporterHooks
0.00% covered (danger)
0.00%
0 / 1
66.67% covered (warning)
66.67%
2 / 3
18.96
37.50% covered (danger)
37.50%
6 / 16
 onBeforeInitialize
0.00% covered (danger)
0.00%
0 / 1
30
0.00% covered (danger)
0.00%
0 / 10
 onListDefinedTags
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 onUserGetReservedNames
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
<?php
namespace FileImporter;
use FileImporter\Html\ImportSuccessSnippet;
use MediaWiki;
use MediaWiki\MediaWikiServices;
use OutputPage;
use Title;
use User;
use WebRequest;
/**
 * @license GPL-2.0-or-later
 * @author Andrew Kostka
 */
class FileImporterHooks {
    /**
     * Show an import success message when appropriate.
     *
     * @see https://www.mediawiki.org/wiki/Manual:Hooks/BeforeInitialize
     *
     * @param Title $title
     * @param null $unused
     * @param OutputPage $output
     * @param User $user
     * @param WebRequest $request
     * @param MediaWiki $mediaWiki
     */
    public static function onBeforeInitialize(
        Title $title,
        $unused,
        OutputPage $output,
        User $user,
        WebRequest $request,
        $mediaWiki
    ) {
        if ( $request->getVal( ImportSuccessSnippet::NOTICE_URL_KEY ) === null
            || !$title->inNamespace( NS_FILE )
            || !$title->exists()
            || $user->isAnon()
        ) {
            return;
        }
        $output->enableOOUI();
        $output->prependHTML(
            ( new ImportSuccessSnippet() )->getHtml(
                $output->getContext(), $title ) );
    }
    /**
     * @see https://www.mediawiki.org/wiki/Manual:Hooks/ChangeTagsListActive
     * @see https://www.mediawiki.org/wiki/Manual:Hooks/ListDefinedTags
     *
     * @param string[] &$tags
     */
    public static function onListDefinedTags( array &$tags ) {
        $tags[] = 'fileimporter';
        $tags[] = 'fileimporter-imported';
    }
    /**
     * Add FileImporter username to the list of reserved ones for
     * replacing suppressed usernames in certain revisions
     *
     * @param string[] &$reservedUsernames
     */
    public static function onUserGetReservedNames( array &$reservedUsernames ) {
        $config = MediaWikiServices::getInstance()->getMainConfig();
        $reservedUsernames[] = $config->get( 'FileImporterAccountForSuppressedUsername' );
    }
}