Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
Hooks | |
0.00% |
0 / 12 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
onSpecialMovepageAfterMove | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
onUserGetReservedNames | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | /** |
3 | * Hook functions for the Replace Text extension. |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation; either version 2 of the License, or |
8 | * (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License along |
16 | * with this program; if not, write to the Free Software Foundation, Inc., |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
18 | * https://www.gnu.org/copyleft/gpl.html |
19 | * |
20 | * @file |
21 | */ |
22 | namespace MediaWiki\Extension\ReplaceText; |
23 | |
24 | use MediaWiki\Config\Config; |
25 | use MediaWiki\Hook\SpecialMovepageAfterMoveHook; |
26 | use MediaWiki\SpecialPage\SpecialPageFactory; |
27 | use MediaWiki\Specials\SpecialMovePage; |
28 | use MediaWiki\Title\Title; |
29 | use MediaWiki\User\Hook\UserGetReservedNamesHook; |
30 | |
31 | class Hooks implements |
32 | SpecialMovepageAfterMoveHook, |
33 | UserGetReservedNamesHook |
34 | { |
35 | |
36 | /** @var Config */ |
37 | private $config; |
38 | |
39 | /** @var SpecialPageFactory */ |
40 | private $specialPageFactory; |
41 | |
42 | /** |
43 | * @param Config $config |
44 | * @param SpecialPageFactory $specialPageFactory |
45 | */ |
46 | public function __construct( |
47 | Config $config, |
48 | SpecialPageFactory $specialPageFactory |
49 | ) { |
50 | $this->config = $config; |
51 | $this->specialPageFactory = $specialPageFactory; |
52 | } |
53 | |
54 | /** |
55 | * Implements SpecialMovepageAfterMove hook. |
56 | * |
57 | * Adds a link to the Special:ReplaceText page at the end of a successful |
58 | * regular page move message. |
59 | * |
60 | * @param SpecialMovePage $form |
61 | * @param Title $ot Title object of the old article (moved from) |
62 | * @param Title $nt Title object of the new article (moved to) |
63 | */ |
64 | public function onSpecialMovepageAfterMove( $form, $ot, $nt ) { |
65 | if ( !$form->getUser()->isAllowed( 'replacetext' ) ) { |
66 | return; |
67 | } |
68 | $out = $form->getOutput(); |
69 | $page = $this->specialPageFactory->getPage( 'ReplaceText' ); |
70 | $pageLink = $form->getLinkRenderer()->makeLink( $page->getPageTitle() ); |
71 | $out->addHTML( $form->msg( 'replacetext_reminder' ) |
72 | ->rawParams( $pageLink )->parseAsBlock() ); |
73 | } |
74 | |
75 | /** |
76 | * Implements UserGetReservedNames hook. |
77 | * @param array &$names |
78 | */ |
79 | public function onUserGetReservedNames( &$names ) { |
80 | $replaceTextUser = $this->config->get( 'ReplaceTextUser' ); |
81 | if ( $replaceTextUser !== null ) { |
82 | $names[] = $replaceTextUser; |
83 | } |
84 | } |
85 | } |