Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 30
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
GlobalRenameUserLogger
0.00% covered (danger)
0.00%
0 / 30
0.00% covered (danger)
0.00%
0 / 3
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 log
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
2
 logPromotion
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Extension\CentralAuth\GlobalRename;
4
5use ManualLogEntry;
6use MediaWiki\SpecialPage\SpecialPage;
7use MediaWiki\User\UserIdentity;
8
9/**
10 * Log a global rename into the local log
11 *
12 * @license GPL-2.0-or-later
13 * @author Marius Hoch < hoo@online.de >
14 */
15class GlobalRenameUserLogger {
16
17    private UserIdentity $performingUser;
18
19    public function __construct( UserIdentity $performingUser ) {
20        $this->performingUser = $performingUser;
21    }
22
23    /**
24     * @param string $oldName
25     * @param string $newName
26     * @param array $options
27     */
28    public function log( $oldName, $newName, $options ) {
29        $logEntry = new ManualLogEntry( 'gblrename', 'rename' );
30        $logEntry->setPerformer( $this->performingUser );
31        $logEntry->setTarget( SpecialPage::getTitleFor( 'CentralAuth', $newName ) );
32        $logEntry->setComment( $options['reason'] );
33        $logEntry->setParameters( [
34            '4::olduser' => $oldName,
35            '5::newuser' => $newName,
36            'movepages' => $options['movepages'],
37            'suppressredirects' => $options['suppressredirects'],
38        ] );
39
40        $logEntry->setRelations( [
41            'oldname' => $oldName,
42        ] );
43
44        $logid = $logEntry->insert();
45        $logEntry->publish( $logid );
46    }
47
48    /**
49     * Log the promotion of a local unattached to a global
50     *
51     * @param string $oldName
52     * @param string $wiki
53     * @param string $newName
54     * @param string $reason
55     */
56    public function logPromotion( $oldName, $wiki, $newName, $reason ) {
57        $logEntry = new ManualLogEntry( 'gblrename', 'promote' );
58        $logEntry->setPerformer( $this->performingUser );
59        $logEntry->setTarget( SpecialPage::getTitleFor( 'CentralAuth', $newName ) );
60        $logEntry->setComment( $reason );
61        $logEntry->setParameters( [
62            '4::olduser' => $oldName,
63            '5::newuser' => $newName,
64            '6::oldwiki' => $wiki,
65        ] );
66
67        $logEntry->setRelations( [
68            'oldname' => $oldName,
69        ] );
70
71        $logid = $logEntry->insert();
72        $logEntry->publish( $logid );
73    }
74}