MediaWiki master
MoveLogFormatter.php
Go to the documentation of this file.
1<?php
26namespace MediaWiki\Logging;
27
33
40 private TitleParser $titleParser;
41
42 public function __construct(
44 TitleParser $titleParser
45 ) {
46 parent::__construct( $entry );
47 $this->titleParser = $titleParser;
48 }
49
50 public function getPreloadTitles() {
51 $params = $this->extractParameters();
52
53 try {
54 return [ $this->titleParser->parseTitle( $params[3] ) ];
55 } catch ( MalformedTitleException $_ ) {
56 // namespace configuration may have changed to make $params[3] invalid (T370396);
57 // nothing to preload in this case
58 return [];
59 }
60 }
61
62 protected function getMessageKey() {
63 $key = parent::getMessageKey();
64 $params = $this->extractParameters();
65 if ( isset( $params[4] ) && $params[4] === '1' ) {
66 // Messages: logentry-move-move-noredirect, logentry-move-move_redir-noredirect
67 $key .= '-noredirect';
68 }
69
70 return $key;
71 }
72
73 protected function getMessageParameters() {
74 $params = parent::getMessageParameters();
75 $oldname = $this->makePageLink( $this->entry->getTarget(), [ 'redirect' => 'no' ] );
76 $newname = $this->makePageLink( Title::newFromText( $params[3] ) );
77 $params[2] = Message::rawParam( $oldname );
78 $params[3] = Message::rawParam( $newname );
79 unset( $params[4] ); // handled in getMessageKey
80
81 return $params;
82 }
83
84 public function getActionLinks() {
85 if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) // Action is hidden
86 || $this->entry->getSubtype() !== 'move'
87 || !$this->context->getAuthority()->isAllowed( 'move' )
88 ) {
89 return '';
90 }
91
92 $params = $this->extractParameters();
93 $destTitle = Title::newFromText( $params[3] );
94 if ( !$destTitle || !$destTitle->exists() ) {
95 return '';
96 }
97
98 $revert = $this->getLinkRenderer()->makeKnownLink(
99 SpecialPage::getTitleFor( 'Movepage' ),
100 $this->msg( 'revertmove' )->text(),
101 [],
102 [
103 'wpOldTitle' => $destTitle->getPrefixedDBkey(),
104 'wpNewTitle' => $this->entry->getTarget()->getPrefixedDBkey(),
105 'wpReason' => $this->msg( 'revertmove-summary' )->inContentLanguage()->text(),
106 'wpMovetalk' => 0
107 ]
108 );
109
110 return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
111 }
112
113 protected function getParametersForApi() {
115 $params = $entry->getParameters();
116
117 static $map = [
118 '4:title:target',
119 '5:bool:suppressredirect',
120 '4::target' => '4:title:target',
121 '5::noredir' => '5:bool:suppressredirect',
122 ];
123 foreach ( $map as $index => $key ) {
124 if ( isset( $params[$index] ) ) {
125 $params[$key] = $params[$index];
126 unset( $params[$index] );
127 }
128 }
129
130 if ( !isset( $params['5:bool:suppressredirect'] ) ) {
131 $params['5:bool:suppressredirect'] = false;
132 }
133
134 return $params;
135 }
136
137}
138
140class_alias( MoveLogFormatter::class, 'MoveLogFormatter' );
Implements the default log formatting.
makePageLink(?Title $title=null, $parameters=[], $html=null)
Helper to make a link to the page, taking the plaintext value in consideration.
extractParameters()
Extracts the optional extra parameters for use in action messages.
msg( $key,... $params)
Shortcut for wfMessage which honors local context.
This class formats move log entries.
getParametersForApi()
Get the array of parameters, converted from legacy format if necessary.
__construct(LogEntry $entry, TitleParser $titleParser)
getMessageKey()
Returns a key to be used for formatting the action sentence.
getMessageParameters()
Formats parameters intended for action message from array of all parameters.
getActionLinks()
Returns extra links that comes after the action text, like "revert", etc.
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition Message.php:157
Parent class for all special pages.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
MalformedTitleException is thrown when a TitleParser is unable to parse a title string.
A title parser service for MediaWiki.
Represents a title within MediaWiki.
Definition Title.php:78
An individual log entry.
Definition LogEntry.php:37
getParameters()
Get the extra parameters stored for this message.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...