Replace usages of deprecated User::isAllowed. Step 2.
[lhc/web/wiklou.git] / includes / logging / MergeLogFormatter.php
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\MediaWikiServices;
26
27 /**
28 * This class formats merge log entries.
29 *
30 * @since 1.25
31 */
32 class MergeLogFormatter extends LogFormatter {
33 public function getPreloadTitles() {
34 $params = $this->extractParameters();
35
36 return [ Title::newFromText( $params[3] ) ];
37 }
38
39 protected function getMessageParameters() {
40 $params = parent::getMessageParameters();
41 $oldname = $this->makePageLink( $this->entry->getTarget(), [ 'redirect' => 'no' ] );
42 $newname = $this->makePageLink( Title::newFromText( $params[3] ) );
43 $params[2] = Message::rawParam( $oldname );
44 $params[3] = Message::rawParam( $newname );
45 $params[4] = $this->context->getLanguage()
46 ->userTimeAndDate( $params[4], $this->context->getUser() );
47 return $params;
48 }
49
50 public function getActionLinks() {
51 if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) // Action is hidden
52 || !MediaWikiServices::getInstance()
53 ->getPermissionManager()
54 ->userHasRight( $this->context->getUser(), 'mergehistory' )
55 ) {
56 return '';
57 }
58
59 // Show unmerge link
60 $params = $this->extractParameters();
61 $revert = $this->getLinkRenderer()->makeKnownLink(
62 SpecialPage::getTitleFor( 'MergeHistory' ),
63 $this->msg( 'revertmerge' )->text(),
64 [],
65 [
66 'target' => $params[3],
67 'dest' => $this->entry->getTarget()->getPrefixedDBkey(),
68 'mergepoint' => $params[4],
69 'submitted' => 1 // show the revisions immediately
70 ]
71 );
72
73 return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
74 }
75
76 protected function getParametersForApi() {
77 $entry = $this->entry;
78 $params = $entry->getParameters();
79
80 static $map = [
81 '4:title:dest',
82 '5:timestamp:mergepoint',
83 '4::dest' => '4:title:dest',
84 '5::mergepoint' => '5:timestamp:mergepoint',
85 ];
86 foreach ( $map as $index => $key ) {
87 if ( isset( $params[$index] ) ) {
88 $params[$key] = $params[$index];
89 unset( $params[$index] );
90 }
91 }
92
93 return $params;
94 }
95 }