Merge "StringUtils: Add a utility for checking if a string is a valid regex"
[lhc/web/wiklou.git] / includes / logging / MoveLogFormatter.php
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\MediaWikiServices;
27
28 /**
29 * This class formats move log entries.
30 *
31 * @since 1.19
32 */
33 class MoveLogFormatter extends LogFormatter {
34 public function getPreloadTitles() {
35 $params = $this->extractParameters();
36
37 return [ Title::newFromText( $params[3] ) ];
38 }
39
40 protected function getMessageKey() {
41 $key = parent::getMessageKey();
42 $params = $this->extractParameters();
43 if ( isset( $params[4] ) && $params[4] === '1' ) {
44 // Messages: logentry-move-move-noredirect, logentry-move-move_redir-noredirect
45 $key .= '-noredirect';
46 }
47
48 return $key;
49 }
50
51 protected function getMessageParameters() {
52 $params = parent::getMessageParameters();
53 $oldname = $this->makePageLink( $this->entry->getTarget(), [ 'redirect' => 'no' ] );
54 $newname = $this->makePageLink( Title::newFromText( $params[3] ) );
55 $params[2] = Message::rawParam( $oldname );
56 $params[3] = Message::rawParam( $newname );
57 unset( $params[4] ); // handled in getMessageKey
58
59 return $params;
60 }
61
62 public function getActionLinks() {
63 if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) // Action is hidden
64 || $this->entry->getSubtype() !== 'move'
65 || !MediaWikiServices::getInstance()
66 ->getPermissionManager()
67 ->userHasRight( $this->context->getUser(), 'move' )
68 ) {
69 return '';
70 }
71
72 $params = $this->extractParameters();
73 $destTitle = Title::newFromText( $params[3] );
74 if ( !$destTitle ) {
75 return '';
76 }
77
78 $revert = $this->getLinkRenderer()->makeKnownLink(
79 SpecialPage::getTitleFor( 'Movepage' ),
80 $this->msg( 'revertmove' )->text(),
81 [],
82 [
83 'wpOldTitle' => $destTitle->getPrefixedDBkey(),
84 'wpNewTitle' => $this->entry->getTarget()->getPrefixedDBkey(),
85 'wpReason' => $this->msg( 'revertmove' )->inContentLanguage()->text(),
86 'wpMovetalk' => 0
87 ]
88 );
89
90 return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
91 }
92
93 protected function getParametersForApi() {
94 $entry = $this->entry;
95 $params = $entry->getParameters();
96
97 static $map = [
98 '4:title:target',
99 '5:bool:suppressredirect',
100 '4::target' => '4:title:target',
101 '5::noredir' => '5:bool:suppressredirect',
102 ];
103 foreach ( $map as $index => $key ) {
104 if ( isset( $params[$index] ) ) {
105 $params[$key] = $params[$index];
106 unset( $params[$index] );
107 }
108 }
109
110 if ( !isset( $params['5:bool:suppressredirect'] ) ) {
111 $params['5:bool:suppressredirect'] = false;
112 }
113
114 return $params;
115 }
116
117 }