Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
LogHookHandler
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 3
132
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
 onSpecialLogAddLogSearchRelations
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
42
 onLogEventsListGetExtraInputs
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
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
21namespace MediaWiki\Extension\CentralAuth\Hooks\Handlers;
22
23use LogEventsList;
24use LogPage;
25use MediaWiki\Hook\LogEventsListGetExtraInputsHook;
26use MediaWiki\Hook\SpecialLogAddLogSearchRelationsHook;
27use MediaWiki\Request\WebRequest;
28use MediaWiki\User\UserNameUtils;
29use Wikimedia\Rdbms\IConnectionProvider;
30
31class LogHookHandler implements
32    LogEventsListGetExtraInputsHook,
33    SpecialLogAddLogSearchRelationsHook
34{
35
36    private IConnectionProvider $dbProvider;
37    private UserNameUtils $userNameUtils;
38
39    public function __construct(
40        IConnectionProvider $dbProvider,
41        UserNameUtils $userNameUtils
42    ) {
43        $this->dbProvider = $dbProvider;
44        $this->userNameUtils = $userNameUtils;
45    }
46
47    /**
48     * @param string $type
49     * @param WebRequest $request
50     * @param string[] &$qc
51     * @return bool|void
52     */
53    public function onSpecialLogAddLogSearchRelations( $type, $request, &$qc ) {
54        if ( $type === 'gblrename' ) {
55            $oldname = trim( $request->getText( 'oldname' ) );
56            $canonicalOldname = $this->userNameUtils->getCanonical( $oldname );
57            if ( $oldname !== '' ) {
58                $qc = [ 'ls_field' => 'oldname', 'ls_value' => $canonicalOldname ];
59
60                $hiddenBits = 0;
61                $user = $request->getSession()->getUser();
62                if ( !$user->isAllowed( 'deletedhistory' ) ) {
63                    $hiddenBits = LogPage::DELETED_ACTION;
64                } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
65                    $hiddenBits = LogPage::DELETED_ACTION | LogPage::DELETED_RESTRICTED;
66                }
67
68                if ( $hiddenBits ) {
69                    $bitfield = $this->dbProvider->getReplicaDatabase()
70                        ->bitAnd( 'log_deleted', $hiddenBits );
71                    $qc[] = "$bitfield != $hiddenBits";
72                }
73            }
74        }
75    }
76
77    /**
78     * @param string $type
79     * @param LogEventsList $list
80     * @param string &$input HTML
81     * @param array &$formDescriptor Form descriptor
82     */
83    public function onLogEventsListGetExtraInputs(
84        $type, $list, &$input, &$formDescriptor
85    ) {
86        if ( $type === 'gblrename' ) {
87            $value = $list->getRequest()->getVal( 'oldname' );
88            if ( $value !== null ) {
89                $name = $this->userNameUtils->getCanonical( $value );
90                $value = $name === false ? '' : $name;
91            }
92            $formDescriptor = [
93                'type' => 'text',
94                'label-message' => 'centralauth-log-gblrename-oldname',
95                'name' => 'oldname',
96                'id' => 'mw-log-gblrename-oldname',
97                'default' => $value,
98            ];
99        }
100    }
101}