Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 42
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
RenameuserLogFormatter
0.00% covered (danger)
0.00%
0 / 42
0.00% covered (danger)
0.00%
0 / 4
240
0.00% covered (danger)
0.00%
0 / 1
 getMessageParameters
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 1
20
 myPageLink
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
20
 getMessageKey
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
12
 getPreloadTitles
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2
3use MediaWiki\Message\Message;
4use MediaWiki\Title\Title;
5
6/**
7 * LogFormatter for renameuser/renameuser logs
8 */
9class RenameuserLogFormatter extends LogFormatter {
10
11    /**
12     * @inheritDoc
13     */
14    protected function getMessageParameters() {
15        $params = parent::getMessageParameters();
16        /* Current format:
17         * 1,2,3: normal logformatter params
18         * 4: old username (linked)
19         *    (legaciest doesn't have this at all, all in comment)
20         *    (legacier uses this as new name and stores old name in target)
21         * 5: new username (linked)
22         * 6: number of edits the user had at the time
23         *    (not available except in newest log entries)
24         * 7: new username (raw format for GENDER)
25         * Note that the arrays are zero-indexed, while message parameters
26         * start from 1, so substract one to get array entries below.
27         */
28
29        if ( !isset( $params[3] ) ) {
30            // The oldest format
31            return $params;
32        } elseif ( !isset( $params[4] ) ) {
33            // See comments above
34            $params[4] = $params[3];
35            $params[3] = $this->entry->getTarget()->getText();
36        }
37
38        if ( isset( $params[5] ) ) {
39            // Make sure number of edits is formatted
40            $params[5] = Message::numParam( $params[5] );
41        }
42
43        // Nice link to old user page
44        $title = Title::makeTitleSafe( NS_USER, $params[3] );
45        // @phan-suppress-next-line SecurityCheck-DoubleEscaped
46        $link = $this->myPageLink( $title, $params[3],
47            [ 'redirect' => 'no' ] );
48        // @phan-suppress-next-line SecurityCheck-XSS
49        $params[3] = Message::rawParam( $link );
50
51        // Nice link to new user page
52        $title = Title::makeTitleSafe( NS_USER, $params[4] );
53        // @phan-suppress-next-line SecurityCheck-DoubleEscaped
54        $link = $this->myPageLink( $title, $params[4] );
55        // @phan-suppress-next-line SecurityCheck-XSS
56        $params[4] = Message::rawParam( $link );
57        // GENDER support (using new user page)
58        $params[6] = $title->getText();
59
60        return $params;
61    }
62
63    /**
64     * @param Title|null $title
65     * @param string $text
66     * @param array $query
67     * @return string wikitext or html
68     * @return-taint onlysafefor_html
69     */
70    protected function myPageLink( ?Title $title, $text, $query = [] ) {
71        if ( !$this->plaintext ) {
72            if ( !$title instanceof Title ) {
73                $link = htmlspecialchars( $text );
74            } else {
75                $link = $this->getLinkRenderer()->makeLink( $title, $text, [], $query );
76            }
77        } else {
78            if ( !$title instanceof Title ) {
79                $link = "[[User:$text]]";
80            } else {
81                $link = '[[' . $title->getPrefixedText() . ']]';
82            }
83        }
84
85        return $link;
86    }
87
88    public function getMessageKey() {
89        $key = parent::getMessageKey();
90        $params = $this->extractParameters();
91
92        // Very old log format, everything in comment
93        if ( !isset( $params[3] ) ) {
94            // Message: logentry-renameuser-renameuser-legaciest
95            return "$key-legaciest";
96        } elseif ( !isset( $params[5] ) ) {
97            // Message: logentry-renameuser-renameuser-legacier
98            return "$key-legacier";
99        }
100
101        // Message: logentry-renameuser-renameuser
102        return $key;
103    }
104
105    public function getPreloadTitles() {
106        $params = $this->extractParameters();
107        if ( !isset( $params[3] ) ) {
108            // Very old log format, everything in comment - legaciest
109            return [];
110        }
111        if ( !isset( $params[4] ) ) {
112            // Old log format - legacier
113            $newUserName = $params[3];
114        } else {
115            $newUserName = $params[4];
116        }
117
118        $title = Title::makeTitleSafe( NS_USER, $newUserName );
119        if ( $title ) {
120            return [ $title ];
121        }
122
123        return [];
124    }
125}