Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
45.45% covered (danger)
45.45%
5 / 11
50.00% covered (danger)
50.00%
3 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
ApiClearHasMsg
45.45% covered (danger)
45.45%
5 / 11
50.00% covered (danger)
50.00%
3 / 6
11.84
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 execute
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 isWriteMode
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 mustBePosted
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getExamplesMessages
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 getHelpUrls
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * Copyright © 2014 Petr Bena (benapetr@gmail.com)
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
20 *
21 * @file
22 */
23
24use MediaWiki\User\TalkPageNotificationManager;
25
26/**
27 * API module that clears the hasmsg flag for current user
28 * @ingroup API
29 */
30class ApiClearHasMsg extends ApiBase {
31
32    private TalkPageNotificationManager $talkPageNotificationManager;
33
34    /**
35     * @param ApiMain $main
36     * @param string $action
37     * @param TalkPageNotificationManager $talkPageNotificationManager
38     */
39    public function __construct(
40        ApiMain $main,
41        $action,
42        TalkPageNotificationManager $talkPageNotificationManager
43    ) {
44        parent::__construct( $main, $action );
45        $this->talkPageNotificationManager = $talkPageNotificationManager;
46    }
47
48    public function execute() {
49        $this->talkPageNotificationManager->removeUserHasNewMessages( $this->getUser() );
50
51        $this->getResult()->addValue( null, $this->getModuleName(), 'success' );
52    }
53
54    public function isWriteMode() {
55        return true;
56    }
57
58    public function mustBePosted() {
59        return true;
60    }
61
62    protected function getExamplesMessages() {
63        return [
64            'action=clearhasmsg'
65                => 'apihelp-clearhasmsg-example-1',
66        ];
67    }
68
69    public function getHelpUrls() {
70        return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:ClearHasMsg';
71    }
72}