Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 36 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
LegacyLogFormatter | |
0.00% |
0 / 36 |
|
0.00% |
0 / 4 |
132 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getComment | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
getActionMessage | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
20 | |||
getActionLinks | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | /** |
3 | * Contains a class for formatting log legacy entries |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation; either version 2 of the License, or |
8 | * (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License along |
16 | * with this program; if not, write to the Free Software Foundation, Inc., |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
18 | * http://www.gnu.org/copyleft/gpl.html |
19 | * |
20 | * @file |
21 | * @author Niklas Laxström |
22 | * @license GPL-2.0-or-later |
23 | * @since 1.19 |
24 | */ |
25 | |
26 | use MediaWiki\HookContainer\HookContainer; |
27 | use MediaWiki\HookContainer\HookRunner; |
28 | |
29 | /** |
30 | * This class formats all log entries for log types |
31 | * which have not been converted to the new system. |
32 | * This is not about old log entries which store |
33 | * parameters in a different format - the new |
34 | * LogFormatter classes have code to support formatting |
35 | * those too. |
36 | * @since 1.19 |
37 | */ |
38 | class LegacyLogFormatter extends LogFormatter { |
39 | /** |
40 | * Backward compatibility for extension changing the comment from |
41 | * the LogLine hook. This will be set by the first call on getComment(), |
42 | * then it might be modified by the hook when calling getActionLinks(), |
43 | * so that the modified value will be returned when calling getComment() |
44 | * a second time. |
45 | * |
46 | * @var string|null |
47 | */ |
48 | private $comment = null; |
49 | |
50 | /** |
51 | * Cache for the result of getActionLinks() so that it does not need to |
52 | * run multiple times depending on the order that getComment() and |
53 | * getActionLinks() are called. |
54 | * |
55 | * @var string|null |
56 | */ |
57 | private $revert = null; |
58 | |
59 | private HookRunner $hookRunner; |
60 | |
61 | public function __construct( |
62 | LogEntry $entry, |
63 | HookContainer $hookContainer |
64 | ) { |
65 | parent::__construct( $entry ); |
66 | $this->hookRunner = new HookRunner( $hookContainer ); |
67 | } |
68 | |
69 | public function getComment() { |
70 | $this->comment ??= parent::getComment(); |
71 | |
72 | // Make sure we execute the LogLine hook so that we immediately return |
73 | // the correct value. |
74 | if ( $this->revert === null ) { |
75 | $this->getActionLinks(); |
76 | } |
77 | |
78 | return $this->comment; |
79 | } |
80 | |
81 | /** |
82 | * @return string |
83 | * @return-taint onlysafefor_html |
84 | */ |
85 | protected function getActionMessage() { |
86 | $entry = $this->entry; |
87 | $action = LogPage::actionText( |
88 | $entry->getType(), |
89 | $entry->getSubtype(), |
90 | $entry->getTarget(), |
91 | $this->plaintext ? null : $this->context->getSkin(), |
92 | (array)$entry->getParameters(), |
93 | !$this->plaintext // whether to filter [[]] links |
94 | ); |
95 | |
96 | $performer = $this->getPerformerElement(); |
97 | if ( !$this->irctext ) { |
98 | $sep = $this->msg( 'word-separator' ); |
99 | $sep = $this->plaintext ? $sep->text() : $sep->escaped(); |
100 | $action = $performer . $sep . $action; |
101 | } |
102 | |
103 | return $action; |
104 | } |
105 | |
106 | public function getActionLinks() { |
107 | if ( $this->revert !== null ) { |
108 | return $this->revert; |
109 | } |
110 | |
111 | if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) ) { |
112 | $this->revert = ''; |
113 | return $this->revert; |
114 | } |
115 | |
116 | $title = $this->entry->getTarget(); |
117 | $type = $this->entry->getType(); |
118 | $subtype = $this->entry->getSubtype(); |
119 | |
120 | // Do nothing. The implementation is handled by the hook modifying the |
121 | // passed-by-ref parameters. This also changes the default value so that |
122 | // getComment() and getActionLinks() do not call them indefinitely. |
123 | $this->revert = ''; |
124 | |
125 | // This is to populate the $comment member of this instance so that it |
126 | // can be modified when calling the hook just below. |
127 | if ( $this->comment === null ) { |
128 | $this->getComment(); |
129 | } |
130 | |
131 | $params = $this->entry->getParameters(); |
132 | |
133 | $this->hookRunner->onLogLine( |
134 | $type, $subtype, $title, $params, $this->comment, $this->revert, $this->entry->getTimestamp() ); |
135 | |
136 | return $this->revert; |
137 | } |
138 | } |