MediaWiki REL1_31
BlockLogFormatter.php
Go to the documentation of this file.
1<?php
31 protected function getMessageParameters() {
32 $params = parent::getMessageParameters();
33
34 $title = $this->entry->getTarget();
35 if ( substr( $title->getText(), 0, 1 ) === '#' ) {
36 // autoblock - no user link possible
37 $params[2] = $title->getText();
38 $params[3] = ''; // no user name for gender use
39 } else {
40 // Create a user link for the blocked
41 $username = $title->getText();
42 // @todo Store the user identifier in the parameters
43 // to make this faster for future log entries
44 $targetUser = User::newFromName( $username, false );
45 $params[2] = Message::rawParam( $this->makeUserLink( $targetUser, Linker::TOOL_LINKS_NOBLOCK ) );
46 $params[3] = $username; // plain user name for gender use
47 }
48
49 $subtype = $this->entry->getSubtype();
50 if ( $subtype === 'block' || $subtype === 'reblock' ) {
51 if ( !isset( $params[4] ) ) {
52 // Very old log entry without duration: means infinite
53 $params[4] = 'infinite';
54 }
55 // Localize the duration, and add a tooltip
56 // in English to help visitors from other wikis.
57 // The lrm is needed to make sure that the number
58 // is shown on the correct side of the tooltip text.
59 $durationTooltip = '&lrm;' . htmlspecialchars( $params[4] );
60 $blockExpiry = $this->context->getLanguage()->translateBlockExpiry(
61 $params[4],
62 $this->context->getUser(),
63 wfTimestamp( TS_UNIX, $this->entry->getTimestamp() )
64 );
65 $params[4] = Message::rawParam(
66 "<span class=\"blockExpiry\" title=\"$durationTooltip\">" .
67 htmlspecialchars( $blockExpiry ) .
68 '</span>'
69 );
70 $params[5] = isset( $params[5] ) ?
71 self::formatBlockFlags( $params[5], $this->context->getLanguage() ) : '';
72 }
73
74 return $params;
75 }
76
77 protected function extractParameters() {
78 $params = parent::extractParameters();
79 // Legacy log params returning the params in index 3 and 4, moved to 4 and 5
80 if ( $this->entry->isLegacy() && isset( $params[3] ) ) {
81 if ( isset( $params[4] ) ) {
82 $params[5] = $params[4];
83 }
84 $params[4] = $params[3];
85 $params[3] = '';
86 }
87 return $params;
88 }
89
90 public function getPreloadTitles() {
91 $title = $this->entry->getTarget();
92 // Preload user page for non-autoblocks
93 if ( substr( $title->getText(), 0, 1 ) !== '#' ) {
94 return [ $title->getTalkPage() ];
95 }
96 return [];
97 }
98
99 public function getActionLinks() {
100 $subtype = $this->entry->getSubtype();
102 if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) // Action is hidden
103 || !( $subtype === 'block' || $subtype === 'reblock' )
104 || !$this->context->getUser()->isAllowed( 'block' )
105 ) {
106 return '';
107 }
108
109 // Show unblock/change block link
110 $title = $this->entry->getTarget();
111 $links = [
113 SpecialPage::getTitleFor( 'Unblock', $title->getDBkey() ),
114 $this->msg( 'unblocklink' )->text()
115 ),
117 SpecialPage::getTitleFor( 'Block', $title->getDBkey() ),
118 $this->msg( 'change-blocklink' )->text()
119 )
120 ];
121
122 return $this->msg( 'parentheses' )->rawParams(
123 $this->context->getLanguage()->pipeList( $links ) )->escaped();
124 }
125
134 public static function formatBlockFlags( $flags, $lang ) {
135 $flags = trim( $flags );
136 if ( $flags === '' ) {
137 return ''; // nothing to do
138 }
139 $flags = explode( ',', $flags );
140 $flagsCount = count( $flags );
141
142 for ( $i = 0; $i < $flagsCount; $i++ ) {
143 $flags[$i] = self::formatBlockFlag( $flags[$i], $lang );
144 }
145
146 return wfMessage( 'parentheses' )->inLanguage( $lang )
147 ->rawParams( $lang->commaList( $flags ) )->escaped();
148 }
149
157 public static function formatBlockFlag( $flag, $lang ) {
158 static $messages = [];
159
160 if ( !isset( $messages[$flag] ) ) {
161 $messages[$flag] = htmlspecialchars( $flag ); // Fallback
162
163 // For grepping. The following core messages can be used here:
164 // * block-log-flags-angry-autoblock
165 // * block-log-flags-anononly
166 // * block-log-flags-hiddenname
167 // * block-log-flags-noautoblock
168 // * block-log-flags-nocreate
169 // * block-log-flags-noemail
170 // * block-log-flags-nousertalk
171 $msg = wfMessage( 'block-log-flags-' . $flag )->inLanguage( $lang );
172
173 if ( $msg->exists() ) {
174 $messages[$flag] = $msg->escaped();
175 }
176 }
177
178 return $messages[$flag];
179 }
180
181 protected function getParametersForApi() {
184
185 static $map = [
186 // While this looks wrong to be starting at 5 rather than 4, it's
187 // because getMessageParameters uses $4 for its own purposes.
188 '5::duration',
189 '6:array:flags',
190 '6::flags' => '6:array:flags',
191 ];
192 foreach ( $map as $index => $key ) {
193 if ( isset( $params[$index] ) ) {
194 $params[$key] = $params[$index];
195 unset( $params[$index] );
196 }
197 }
198
199 $subtype = $entry->getSubtype();
200 if ( $subtype === 'block' || $subtype === 'reblock' ) {
201 // Defaults for old log entries missing some fields
202 $params += [
203 '5::duration' => 'infinite',
204 '6:array:flags' => [],
205 ];
206
207 if ( !is_array( $params['6:array:flags'] ) ) {
208 $params['6:array:flags'] = $params['6:array:flags'] === ''
209 ? []
210 : explode( ',', $params['6:array:flags'] );
211 }
212
213 if ( !wfIsInfinity( $params['5::duration'] ) ) {
214 $ts = wfTimestamp( TS_UNIX, $entry->getTimestamp() );
215 $expiry = strtotime( $params['5::duration'], $ts );
216 if ( $expiry !== false && $expiry > 0 ) {
217 $params[':timestamp:expiry'] = $expiry;
218 }
219 }
220 }
221
222 return $params;
223 }
224
225 public function formatParametersForApi() {
226 $ret = parent::formatParametersForApi();
227 if ( isset( $ret['flags'] ) ) {
228 ApiResult::setIndexedTagName( $ret['flags'], 'f' );
229 }
230 return $ret;
231 }
232
233}
wfIsInfinity( $str)
Determine input string is represents as infinity.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
$messages
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
This class formats block log entries.
static formatBlockFlags( $flags, $lang)
Convert a comma-delimited list of block log flags into a more readable (and translated) form.
static formatBlockFlag( $flag, $lang)
Translate a block log flag if possible.
getMessageParameters()
Formats parameters intented for action message from array of all parameters.
getActionLinks()
Returns extra links that comes after the action text, like "revert", etc.
getParametersForApi()
Get the array of parameters, converted from legacy format if necessary.
formatParametersForApi()
Format parameters for API output.
extractParameters()
Extracts the optional extra parameters for use in action messages.
const TOOL_LINKS_NOBLOCK
Flags for userToolLinks()
Definition Linker.php:38
Implements the default log formatting.
LogEntryBase $entry
msg( $key)
Shortcut for wfMessage which honors local context.
makeUserLink(User $user, $toolFlags=0)
LinkRenderer null $linkRenderer
const DELETED_ACTION
Definition LogPage.php:32
makeKnownLink(LinkTarget $target, $text=null, array $extraAttribs=[], array $query=[])
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition User.php:591
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:964
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt;div ...>$1&lt;/div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition hooks.txt:2005
this hook is for auditing only or null if authentication failed before getting that far $username
Definition hooks.txt:785
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
getParameters()
Get the extra parameters stored for this message.
getTimestamp()
Get the timestamp when the action was executed.
getSubtype()
The log subtype.
$params
if(!isset( $args[0])) $lang