Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
22.22% covered (danger)
22.22%
4 / 18
14.29% covered (danger)
14.29%
1 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
CommunityRequestsHooks
22.22% covered (danger)
22.22%
4 / 18
14.29% covered (danger)
14.29%
1 / 7
79.75
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 onGetDoubleUnderscoreIDs
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 onParserAfterParse
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
 onParserFirstCallInit
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 onLoginFormValidErrorMessages
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 renderRequest
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 renderFocusArea
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Extension\CommunityRequests;
4
5use MediaWiki\Config\Config;
6use MediaWiki\Hook\GetDoubleUnderscoreIDsHook;
7use MediaWiki\Hook\LoginFormValidErrorMessagesHook;
8use MediaWiki\Hook\ParserFirstCallInitHook;
9use MediaWiki\Parser\Parser;
10
11class CommunityRequestsHooks implements
12    GetDoubleUnderscoreIDsHook,
13    LoginFormValidErrorMessagesHook,
14    ParserFirstCallInitHook
15{
16
17    public const MAGIC_MACHINETRANSLATION = 'machinetranslation';
18
19    private Config $config;
20    private bool $enabled;
21
22    public function __construct( Config $config ) {
23        $this->config = $config;
24        $this->enabled = $this->config->get( 'CommunityRequestsEnable' );
25    }
26
27    /** @inheritDoc */
28    public function onGetDoubleUnderscoreIDs( &$doubleUnderscoreIDs ) {
29        if ( !$this->enabled ) {
30            return;
31        }
32        $doubleUnderscoreIDs[] = self::MAGIC_MACHINETRANSLATION;
33    }
34
35    /** @inheritDoc */
36    public function onParserAfterParse( $parser, &$text, $stripState ) {
37        if ( !$this->enabled ) {
38            return;
39        }
40        if ( $parser->getOutput()->getPageProperty( self::MAGIC_MACHINETRANSLATION ) !== null ) {
41            $parser->getOutput()->addModules( [ 'ext.communityrequests.mint' ] );
42        }
43    }
44
45    /** @inheritDoc */
46    public function onParserFirstCallInit( $parser ) {
47        if ( !$this->enabled ) {
48            return;
49        }
50        $parser->setHook( 'community-request', [ $this, 'renderRequest' ] );
51        $parser->setHook( 'focus-area', [ $this, 'renderFocusArea' ] );
52    }
53
54    /** @inheritDoc */
55    public function onLoginFormValidErrorMessages( array &$messages ) {
56        if ( !$this->enabled ) {
57            return;
58        }
59        $messages[] = 'communityrequests-please-log-in';
60    }
61
62    /**
63     * Render the <community-request> parser function, persisting the data to the database.
64     *
65     * @param string|null $text
66     * @param array $params
67     * @param Parser $parser
68     * @return string
69     */
70    public function renderRequest( ?string $text, array $params, Parser $parser ): string {
71        // TODO: Implement
72        return '';
73    }
74
75    /**
76     * Render the <focus-area> parser function, persisting the data to the database.
77     *
78     * @param string|null $text
79     * @param array $params
80     * @param Parser $parser
81     * @return string
82     */
83    public function renderFocusArea( ?string $text, array $params, Parser $parser ): string {
84        // TODO: Implement
85        return '';
86    }
87}