MediaWiki master
MergeLogFormatter.php
Go to the documentation of this file.
1<?php
25namespace MediaWiki\Logging;
26
32
39 private TitleParser $titleParser;
40
41 public function __construct(
43 TitleParser $titleParser
44 ) {
45 parent::__construct( $entry );
46 $this->titleParser = $titleParser;
47 }
48
49 public function getPreloadTitles() {
50 $params = $this->extractParameters();
51
52 try {
53 return [ $this->titleParser->parseTitle( $params[3] ) ];
54 } catch ( MalformedTitleException $_ ) {
55 }
56 return [];
57 }
58
59 protected function getMessageParameters() {
60 $params = parent::getMessageParameters();
61 $oldname = $this->makePageLink( $this->entry->getTarget(), [ 'redirect' => 'no' ] );
62 $newname = $this->makePageLink( Title::newFromText( $params[3] ) );
63 $params[2] = Message::rawParam( $oldname );
64 $params[3] = Message::rawParam( $newname );
65 $params[4] = $this->context->getLanguage()
66 ->userTimeAndDate( $params[4], $this->context->getUser() );
67 return $params;
68 }
69
70 public function getActionLinks() {
71 if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) // Action is hidden
72 || !$this->context->getAuthority()->isAllowed( 'mergehistory' )
73 ) {
74 return '';
75 }
76
77 // Show unmerge link
78 $params = $this->extractParameters();
79 if ( isset( $params[5] ) ) {
80 $mergePoint = $params[4] . "|" . $params[5];
81 } else {
82 // This is an old log entry from before we recorded the revid separately
83 $mergePoint = $params[4];
84 }
85 $revert = $this->getLinkRenderer()->makeKnownLink(
86 SpecialPage::getTitleFor( 'MergeHistory' ),
87 $this->msg( 'revertmerge' )->text(),
88 [],
89 [
90 'target' => $params[3],
91 'dest' => $this->entry->getTarget()->getPrefixedDBkey(),
92 'mergepoint' => $mergePoint,
93 'submitted' => 1 // show the revisions immediately
94 ]
95 );
96
97 return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
98 }
99
100 protected function getParametersForApi() {
102 $params = $entry->getParameters();
103
104 static $map = [
105 '4:title:dest',
106 '5:timestamp:mergepoint',
107 '4::dest' => '4:title:dest',
108 '5::mergepoint' => '5:timestamp:mergepoint',
109 '6::mergerevid'
110 ];
111 foreach ( $map as $index => $key ) {
112 if ( isset( $params[$index] ) ) {
113 $params[$key] = $params[$index];
114 unset( $params[$index] );
115 }
116 }
117
118 return $params;
119 }
120}
121
123class_alias( MergeLogFormatter::class, 'MergeLogFormatter' );
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 merge log entries.
getParametersForApi()
Get the array of parameters, converted from legacy format if necessary.
__construct(LogEntry $entry, TitleParser $titleParser)
getActionLinks()
Returns extra links that comes after the action text, like "revert", etc.
getMessageParameters()
Formats parameters intended for action message from array of all parameters.
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.
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...