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