MediaWiki master
RenameuserLogFormatter.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Logging;
4
8
13 private TitleParser $titleParser;
14
15 public function __construct(
17 TitleParser $titleParser
18 ) {
19 parent::__construct( $entry );
20 $this->titleParser = $titleParser;
21 }
22
26 protected function getMessageParameters() {
27 $params = parent::getMessageParameters();
28 /* Current format:
29 * 1,2,3: normal logformatter params
30 * 4: old username (linked)
31 * (legaciest doesn't have this at all, all in comment)
32 * (legacier uses this as new name and stores old name in target)
33 * 5: new username (linked)
34 * 6: number of edits the user had at the time
35 * (not available except in newest log entries)
36 * 7: new username (raw format for GENDER)
37 * Note that the arrays are zero-indexed, while message parameters
38 * start from 1, so substract one to get array entries below.
39 */
40
41 if ( !isset( $params[3] ) ) {
42 // The oldest format
43 return $params;
44 } elseif ( !isset( $params[4] ) ) {
45 // See comments above
46 $params[4] = $params[3];
47 $params[3] = $this->entry->getTarget()->getText();
48 }
49
50 if ( isset( $params[5] ) ) {
51 // Make sure number of edits is formatted
52 $params[5] = Message::numParam( $params[5] );
53 }
54
55 // Nice link to old user page
56 $title = Title::makeTitleSafe( NS_USER, $params[3] );
57 // @phan-suppress-next-line SecurityCheck-DoubleEscaped
58 $link = $this->myPageLink( $title, $params[3],
59 [ 'redirect' => 'no' ] );
60 // @phan-suppress-next-line SecurityCheck-XSS
61 $params[3] = Message::rawParam( $link );
62
63 // Nice link to new user page
64 $title = Title::makeTitleSafe( NS_USER, $params[4] );
65 // @phan-suppress-next-line SecurityCheck-DoubleEscaped
66 $link = $this->myPageLink( $title, $params[4] );
67 // @phan-suppress-next-line SecurityCheck-XSS
68 $params[4] = Message::rawParam( $link );
69 // GENDER support (using new user page)
70 $params[6] = $title->getText();
71
72 return $params;
73 }
74
82 protected function myPageLink( ?Title $title, $text, $query = [] ) {
83 if ( !$this->plaintext ) {
84 if ( !$title instanceof Title ) {
85 $link = htmlspecialchars( $text );
86 } else {
87 $link = $this->getLinkRenderer()->makeLink( $title, $text, [], $query );
88 }
89 } else {
90 if ( !$title instanceof Title ) {
91 $link = "[[User:$text]]";
92 } else {
93 $link = '[[' . $title->getPrefixedText() . ']]';
94 }
95 }
96
97 return $link;
98 }
99
100 public function getMessageKey() {
101 $key = parent::getMessageKey();
102 $params = $this->extractParameters();
103
104 // Very old log format, everything in comment
105 if ( !isset( $params[3] ) ) {
106 // Message: logentry-renameuser-renameuser-legaciest
107 return "$key-legaciest";
108 } elseif ( !isset( $params[5] ) ) {
109 // Message: logentry-renameuser-renameuser-legacier
110 return "$key-legacier";
111 }
112
113 // Message: logentry-renameuser-renameuser
114 return $key;
115 }
116
117 public function getPreloadTitles() {
118 $params = $this->extractParameters();
119 if ( !isset( $params[3] ) ) {
120 // Very old log format, everything in comment - legaciest
121 return [];
122 }
123 if ( !isset( $params[4] ) ) {
124 // Old log format - legacier
125 $newUserName = $params[3];
126 } else {
127 $newUserName = $params[4];
128 }
129
130 $title = $this->titleParser->makeTitleValueSafe( NS_USER, $newUserName );
131 if ( $title ) {
132 return [ $title ];
133 }
134
135 return [];
136 }
137}
138
140class_alias( RenameuserLogFormatter::class, 'RenameuserLogFormatter' );
const NS_USER
Definition Defines.php:67
Implements the default log formatting.
extractParameters()
Extracts the optional extra parameters for use in action messages.
LogFormatter for renameuser/renameuser logs.
getMessageParameters()
Formats parameters intended for action message from array of all parameters.There are three hardcoded...
myPageLink(?Title $title, $text, $query=[])
__construct(LogEntry $entry, TitleParser $titleParser)
getMessageKey()
Returns a key to be used for formatting the action sentence.
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition Message.php:157
A title parser service for MediaWiki.
Represents a title within MediaWiki.
Definition Title.php:78
getPrefixedText()
Get the prefixed title with spaces.
Definition Title.php:1855
An individual log entry.
Definition LogEntry.php:37
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...