Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 31 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
LogHookHandler | |
0.00% |
0 / 31 |
|
0.00% |
0 / 3 |
132 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
onSpecialLogAddLogSearchRelations | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
42 | |||
onLogEventsListGetExtraInputs | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | namespace MediaWiki\Extension\CentralAuth\Hooks\Handlers; |
22 | |
23 | use LogEventsList; |
24 | use LogPage; |
25 | use MediaWiki\Hook\LogEventsListGetExtraInputsHook; |
26 | use MediaWiki\Hook\SpecialLogAddLogSearchRelationsHook; |
27 | use MediaWiki\Request\WebRequest; |
28 | use MediaWiki\User\UserNameUtils; |
29 | use Wikimedia\Rdbms\LBFactory; |
30 | |
31 | class LogHookHandler implements |
32 | LogEventsListGetExtraInputsHook, |
33 | SpecialLogAddLogSearchRelationsHook |
34 | { |
35 | /** @var LBFactory */ |
36 | private $lbFactory; |
37 | |
38 | /** @var UserNameUtils */ |
39 | private $userNameUtils; |
40 | |
41 | /** |
42 | * @param LBFactory $lbFactory |
43 | * @param UserNameUtils $userNameUtils |
44 | */ |
45 | public function __construct( |
46 | LBFactory $lbFactory, |
47 | UserNameUtils $userNameUtils |
48 | ) { |
49 | $this->lbFactory = $lbFactory; |
50 | $this->userNameUtils = $userNameUtils; |
51 | } |
52 | |
53 | /** |
54 | * @param string $type |
55 | * @param WebRequest $request |
56 | * @param string[] &$qc |
57 | * @return bool|void |
58 | */ |
59 | public function onSpecialLogAddLogSearchRelations( $type, $request, &$qc ) { |
60 | if ( $type === 'gblrename' ) { |
61 | $oldname = trim( $request->getText( 'oldname' ) ); |
62 | $canonicalOldname = $this->userNameUtils->getCanonical( $oldname ); |
63 | if ( $oldname !== '' ) { |
64 | $qc = [ 'ls_field' => 'oldname', 'ls_value' => $canonicalOldname ]; |
65 | |
66 | $hiddenBits = 0; |
67 | $user = $request->getSession()->getUser(); |
68 | if ( !$user->isAllowed( 'deletedhistory' ) ) { |
69 | $hiddenBits = LogPage::DELETED_ACTION; |
70 | } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) { |
71 | $hiddenBits = LogPage::DELETED_ACTION | LogPage::DELETED_RESTRICTED; |
72 | } |
73 | |
74 | if ( $hiddenBits ) { |
75 | $bitfield = $this->lbFactory |
76 | ->getMainLB() |
77 | ->getConnection( DB_REPLICA ) |
78 | ->bitAnd( 'log_deleted', $hiddenBits ); |
79 | $qc[] = "$bitfield != $hiddenBits"; |
80 | } |
81 | } |
82 | } |
83 | } |
84 | |
85 | /** |
86 | * @param string $type |
87 | * @param LogEventsList $list |
88 | * @param string &$input HTML |
89 | * @param array &$formDescriptor Form descriptor |
90 | */ |
91 | public function onLogEventsListGetExtraInputs( |
92 | $type, $list, &$input, &$formDescriptor |
93 | ) { |
94 | if ( $type === 'gblrename' ) { |
95 | $value = $list->getRequest()->getVal( 'oldname' ); |
96 | if ( $value !== null ) { |
97 | $name = $this->userNameUtils->getCanonical( $value ); |
98 | $value = $name === false ? '' : $name; |
99 | } |
100 | $formDescriptor = [ |
101 | 'type' => 'text', |
102 | 'label-message' => 'centralauth-log-gblrename-oldname', |
103 | 'name' => 'oldname', |
104 | 'id' => 'mw-log-gblrename-oldname', |
105 | 'default' => $value, |
106 | ]; |
107 | } |
108 | } |
109 | } |