Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
61.11% |
33 / 54 |
|
83.33% |
5 / 6 |
CRAP | |
0.00% |
0 / 1 |
MoveLogFormatter | |
62.26% |
33 / 53 |
|
83.33% |
5 / 6 |
32.53 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getPreloadTitles | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
getMessageKey | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
getMessageParameters | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
getActionLinks | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
42 | |||
getParametersForApi | |
100.00% |
15 / 15 |
|
100.00% |
1 / 1 |
4 |
1 | <?php |
2 | /** |
3 | * Formatter for move log 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.22 |
24 | */ |
25 | |
26 | namespace MediaWiki\Logging; |
27 | |
28 | use MediaWiki\Message\Message; |
29 | use MediaWiki\SpecialPage\SpecialPage; |
30 | use MediaWiki\Title\MalformedTitleException; |
31 | use MediaWiki\Title\Title; |
32 | use MediaWiki\Title\TitleParser; |
33 | |
34 | /** |
35 | * This class formats move log entries. |
36 | * |
37 | * @since 1.19 |
38 | */ |
39 | class MoveLogFormatter extends LogFormatter { |
40 | private TitleParser $titleParser; |
41 | |
42 | public function __construct( |
43 | LogEntry $entry, |
44 | TitleParser $titleParser |
45 | ) { |
46 | parent::__construct( $entry ); |
47 | $this->titleParser = $titleParser; |
48 | } |
49 | |
50 | public function getPreloadTitles() { |
51 | $params = $this->extractParameters(); |
52 | |
53 | try { |
54 | return [ $this->titleParser->parseTitle( $params[3] ) ]; |
55 | } catch ( MalformedTitleException $_ ) { |
56 | // namespace configuration may have changed to make $params[3] invalid (T370396); |
57 | // nothing to preload in this case |
58 | return []; |
59 | } |
60 | } |
61 | |
62 | protected function getMessageKey() { |
63 | $key = parent::getMessageKey(); |
64 | $params = $this->extractParameters(); |
65 | if ( isset( $params[4] ) && $params[4] === '1' ) { |
66 | // Messages: logentry-move-move-noredirect, logentry-move-move_redir-noredirect |
67 | $key .= '-noredirect'; |
68 | } |
69 | |
70 | return $key; |
71 | } |
72 | |
73 | protected function getMessageParameters() { |
74 | $params = parent::getMessageParameters(); |
75 | $oldname = $this->makePageLink( $this->entry->getTarget(), [ 'redirect' => 'no' ] ); |
76 | $newname = $this->makePageLink( Title::newFromText( $params[3] ) ); |
77 | $params[2] = Message::rawParam( $oldname ); |
78 | $params[3] = Message::rawParam( $newname ); |
79 | unset( $params[4] ); // handled in getMessageKey |
80 | |
81 | return $params; |
82 | } |
83 | |
84 | public function getActionLinks() { |
85 | if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) // Action is hidden |
86 | || $this->entry->getSubtype() !== 'move' |
87 | || !$this->context->getAuthority()->isAllowed( 'move' ) |
88 | ) { |
89 | return ''; |
90 | } |
91 | |
92 | $params = $this->extractParameters(); |
93 | $destTitle = Title::newFromText( $params[3] ); |
94 | if ( !$destTitle || !$destTitle->exists() ) { |
95 | return ''; |
96 | } |
97 | |
98 | $revert = $this->getLinkRenderer()->makeKnownLink( |
99 | SpecialPage::getTitleFor( 'Movepage' ), |
100 | $this->msg( 'revertmove' )->text(), |
101 | [], |
102 | [ |
103 | 'wpOldTitle' => $destTitle->getPrefixedDBkey(), |
104 | 'wpNewTitle' => $this->entry->getTarget()->getPrefixedDBkey(), |
105 | 'wpReason' => $this->msg( 'revertmove-summary' )->inContentLanguage()->text(), |
106 | 'wpMovetalk' => 0 |
107 | ] |
108 | ); |
109 | |
110 | return $this->msg( 'parentheses' )->rawParams( $revert )->escaped(); |
111 | } |
112 | |
113 | protected function getParametersForApi() { |
114 | $entry = $this->entry; |
115 | $params = $entry->getParameters(); |
116 | |
117 | static $map = [ |
118 | '4:title:target', |
119 | '5:bool:suppressredirect', |
120 | '4::target' => '4:title:target', |
121 | '5::noredir' => '5:bool:suppressredirect', |
122 | ]; |
123 | foreach ( $map as $index => $key ) { |
124 | if ( isset( $params[$index] ) ) { |
125 | $params[$key] = $params[$index]; |
126 | unset( $params[$index] ); |
127 | } |
128 | } |
129 | |
130 | if ( !isset( $params['5:bool:suppressredirect'] ) ) { |
131 | $params['5:bool:suppressredirect'] = false; |
132 | } |
133 | |
134 | return $params; |
135 | } |
136 | |
137 | } |
138 | |
139 | /** @deprecated class alias since 1.44 */ |
140 | class_alias( MoveLogFormatter::class, 'MoveLogFormatter' ); |