MediaWiki master
MoveLogFormatter.php
Go to the documentation of this file.
1<?php
12namespace MediaWiki\Logging;
13
19
26 private TitleParser $titleParser;
27
28 public function __construct(
30 TitleParser $titleParser
31 ) {
32 parent::__construct( $entry );
33 $this->titleParser = $titleParser;
34 }
35
37 public function getPreloadTitles() {
38 $params = $this->extractParameters();
39
40 try {
41 return [ $this->titleParser->parseTitle( $params[3] ) ];
42 } catch ( MalformedTitleException ) {
43 // namespace configuration may have changed to make $params[3] invalid (T370396);
44 // nothing to preload in this case
45 return [];
46 }
47 }
48
50 protected function getMessageKey() {
51 $key = parent::getMessageKey();
52 $params = $this->extractParameters();
53 if ( isset( $params[4] ) && $params[4] === '1' ) {
54 // Messages: logentry-move-move-noredirect, logentry-move-move_redir-noredirect
55 $key .= '-noredirect';
56 }
57
58 return $key;
59 }
60
62 protected function getMessageParameters() {
63 $params = parent::getMessageParameters();
64 $oldname = $this->makePageLink( $this->entry->getTarget(), [ 'redirect' => 'no' ] );
65 $newname = $this->makePageLink( Title::newFromText( $params[3] ) );
66 $params[2] = Message::rawParam( $oldname );
67 $params[3] = Message::rawParam( $newname );
68 unset( $params[4] ); // handled in getMessageKey
69
70 return $params;
71 }
72
74 public function getActionLinks() {
75 if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) // Action is hidden
76 || $this->entry->getSubtype() !== 'move'
77 || !$this->context->getAuthority()->isAllowed( 'move' )
78 ) {
79 return '';
80 }
81
82 $params = $this->extractParameters();
83 $destTitle = Title::newFromText( $params[3] );
84 if ( !$destTitle || !$destTitle->exists() ) {
85 return '';
86 }
87
88 $revert = $this->getLinkRenderer()->makeKnownLink(
89 SpecialPage::getTitleFor( 'Movepage' ),
90 $this->msg( 'revertmove' )->text(),
91 [],
92 [
93 'wpOldTitle' => $destTitle->getPrefixedDBkey(),
94 'wpNewTitle' => $this->entry->getTarget()->getPrefixedDBkey(),
95 'wpReason' => $this->msg( 'revertmove-summary' )->inContentLanguage()->text(),
96 'wpMovetalk' => 0
97 ]
98 );
99
100 return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
101 }
102
104 protected function getParametersForApi() {
106 $params = $entry->getParameters();
107
108 static $map = [
109 '4:title:target',
110 '5:bool:suppressredirect',
111 '4::target' => '4:title:target',
112 '5::noredir' => '5:bool:suppressredirect',
113 ];
114 foreach ( $map as $index => $key ) {
115 if ( isset( $params[$index] ) ) {
116 $params[$key] = $params[$index];
117 unset( $params[$index] );
118 }
119 }
120
121 if ( !isset( $params['5:bool:suppressredirect'] ) ) {
122 $params['5:bool:suppressredirect'] = false;
123 }
124
125 return $params;
126 }
127
128}
129
131class_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.1.25 to override array
__construct(LogEntry $entry, TitleParser $titleParser)
getMessageKey()
Returns a key to be used for formatting the action sentence.Default is logentry-TYPE-SUBTYPE for mode...
getMessageParameters()
Formats parameters intended for action message from array of all parameters.There are three hardcoded...
getActionLinks()
Returns extra links that comes after the action text, like "revert", etc.to override string
getPreloadTitles()
to override LinkTarget[] Array of titles that should be preloaded with LinkBatch
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition Message.php:144
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:70
An individual log entry.
Definition LogEntry.php:23
getParameters()
Get the extra parameters stored for this message.