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