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