Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
51.16% |
22 / 43 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
MergeLogFormatter | |
51.16% |
22 / 43 |
|
50.00% |
2 / 4 |
18.43 | |
0.00% |
0 / 1 |
getPreloadTitles | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getMessageParameters | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
getActionLinks | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
20 | |||
getParametersForApi | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | /** |
3 | * Formatter for merge 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 | * @license GPL-2.0-or-later |
22 | * @since 1.25 |
23 | */ |
24 | |
25 | use MediaWiki\SpecialPage\SpecialPage; |
26 | use MediaWiki\Title\Title; |
27 | |
28 | /** |
29 | * This class formats merge log entries. |
30 | * |
31 | * @since 1.25 |
32 | */ |
33 | class MergeLogFormatter extends LogFormatter { |
34 | public function getPreloadTitles() { |
35 | $params = $this->extractParameters(); |
36 | |
37 | return [ Title::newFromText( $params[3] ) ]; |
38 | } |
39 | |
40 | protected function getMessageParameters() { |
41 | $params = parent::getMessageParameters(); |
42 | $oldname = $this->makePageLink( $this->entry->getTarget(), [ 'redirect' => 'no' ] ); |
43 | $newname = $this->makePageLink( Title::newFromText( $params[3] ) ); |
44 | $params[2] = Message::rawParam( $oldname ); |
45 | $params[3] = Message::rawParam( $newname ); |
46 | $params[4] = $this->context->getLanguage() |
47 | ->userTimeAndDate( $params[4], $this->context->getUser() ); |
48 | return $params; |
49 | } |
50 | |
51 | public function getActionLinks() { |
52 | if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) // Action is hidden |
53 | || !$this->context->getAuthority()->isAllowed( 'mergehistory' ) |
54 | ) { |
55 | return ''; |
56 | } |
57 | |
58 | // Show unmerge link |
59 | $params = $this->extractParameters(); |
60 | if ( isset( $params[5] ) ) { |
61 | $mergePoint = $params[4] . "|" . $params[5]; |
62 | } else { |
63 | // This is an old log entry from before we recorded the revid separately |
64 | $mergePoint = $params[4]; |
65 | } |
66 | $revert = $this->getLinkRenderer()->makeKnownLink( |
67 | SpecialPage::getTitleFor( 'MergeHistory' ), |
68 | $this->msg( 'revertmerge' )->text(), |
69 | [], |
70 | [ |
71 | 'target' => $params[3], |
72 | 'dest' => $this->entry->getTarget()->getPrefixedDBkey(), |
73 | 'mergepoint' => $mergePoint, |
74 | 'submitted' => 1 // show the revisions immediately |
75 | ] |
76 | ); |
77 | |
78 | return $this->msg( 'parentheses' )->rawParams( $revert )->escaped(); |
79 | } |
80 | |
81 | protected function getParametersForApi() { |
82 | $entry = $this->entry; |
83 | $params = $entry->getParameters(); |
84 | |
85 | static $map = [ |
86 | '4:title:dest', |
87 | '5:timestamp:mergepoint', |
88 | '4::dest' => '4:title:dest', |
89 | '5::mergepoint' => '5:timestamp:mergepoint', |
90 | '6::mergerevid' |
91 | ]; |
92 | foreach ( $map as $index => $key ) { |
93 | if ( isset( $params[$index] ) ) { |
94 | $params[$key] = $params[$index]; |
95 | unset( $params[$index] ); |
96 | } |
97 | } |
98 | |
99 | return $params; |
100 | } |
101 | } |