MediaWiki REL1_32
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 $params[4] = Message::rawParam(
61 "<span class=\"blockExpiry\" title=\"$durationTooltip\">" .
62 $this->context->getLanguage()->translateBlockExpiry(
63 $params[4],
64 $this->context->getUser(),
65 wfTimestamp( TS_UNIX, $this->entry->getTimestamp() )
66 ) .
67 '</span>'
68 );
69 $params[5] = isset( $params[5] ) ?
70 self::formatBlockFlags( $params[5], $this->context->getLanguage() ) : '';
71 }
72
73 return $params;
74 }
75
76 protected function extractParameters() {
77 $params = parent::extractParameters();
78 // Legacy log params returning the params in index 3 and 4, moved to 4 and 5
79 if ( $this->entry->isLegacy() && isset( $params[3] ) ) {
80 if ( isset( $params[4] ) ) {
81 $params[5] = $params[4];
82 }
83 $params[4] = $params[3];
84 $params[3] = '';
85 }
86 return $params;
87 }
88
89 public function getPreloadTitles() {
90 $title = $this->entry->getTarget();
91 // Preload user page for non-autoblocks
92 if ( substr( $title->getText(), 0, 1 ) !== '#' ) {
93 return [ $title->getTalkPage() ];
94 }
95 return [];
96 }
97
98 public function getActionLinks() {
99 $subtype = $this->entry->getSubtype();
101 if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) // Action is hidden
102 || !( $subtype === 'block' || $subtype === 'reblock' )
103 || !$this->context->getUser()->isAllowed( 'block' )
104 ) {
105 return '';
106 }
107
108 // Show unblock/change block link
109 $title = $this->entry->getTarget();
110 $links = [
112 SpecialPage::getTitleFor( 'Unblock', $title->getDBkey() ),
113 $this->msg( 'unblocklink' )->text()
114 ),
116 SpecialPage::getTitleFor( 'Block', $title->getDBkey() ),
117 $this->msg( 'change-blocklink' )->text()
118 )
119 ];
120
121 return $this->msg( 'parentheses' )->rawParams(
122 $this->context->getLanguage()->pipeList( $links ) )->escaped();
123 }
124
133 public static function formatBlockFlags( $flags, Language $lang ) {
134 $flags = trim( $flags );
135 if ( $flags === '' ) {
136 return ''; // nothing to do
137 }
138 $flags = explode( ',', $flags );
139 $flagsCount = count( $flags );
140
141 for ( $i = 0; $i < $flagsCount; $i++ ) {
142 $flags[$i] = self::formatBlockFlag( $flags[$i], $lang );
143 }
144
145 return wfMessage( 'parentheses' )->inLanguage( $lang )
146 ->rawParams( $lang->commaList( $flags ) )->escaped();
147 }
148
156 public static function formatBlockFlag( $flag, Language $lang ) {
157 static $messages = [];
158
159 if ( !isset( $messages[$flag] ) ) {
160 $messages[$flag] = htmlspecialchars( $flag ); // Fallback
161
162 // For grepping. The following core messages can be used here:
163 // * block-log-flags-angry-autoblock
164 // * block-log-flags-anononly
165 // * block-log-flags-hiddenname
166 // * block-log-flags-noautoblock
167 // * block-log-flags-nocreate
168 // * block-log-flags-noemail
169 // * block-log-flags-nousertalk
170 $msg = wfMessage( 'block-log-flags-' . $flag )->inLanguage( $lang );
171
172 if ( $msg->exists() ) {
173 $messages[$flag] = $msg->escaped();
174 }
175 }
176
177 return $messages[$flag];
178 }
179
180 protected function getParametersForApi() {
183
184 static $map = [
185 // While this looks wrong to be starting at 5 rather than 4, it's
186 // because getMessageParameters uses $4 for its own purposes.
187 '5::duration',
188 '6:array:flags',
189 '6::flags' => '6:array:flags',
190 ];
191 foreach ( $map as $index => $key ) {
192 if ( isset( $params[$index] ) ) {
193 $params[$key] = $params[$index];
194 unset( $params[$index] );
195 }
196 }
197
198 $subtype = $entry->getSubtype();
199 if ( $subtype === 'block' || $subtype === 'reblock' ) {
200 // Defaults for old log entries missing some fields
201 $params += [
202 '5::duration' => 'infinite',
203 '6:array:flags' => [],
204 ];
205
206 if ( !is_array( $params['6:array:flags'] ) ) {
207 $params['6:array:flags'] = $params['6:array:flags'] === ''
208 ? []
209 : explode( ',', $params['6:array:flags'] );
210 }
211
212 if ( !wfIsInfinity( $params['5::duration'] ) ) {
213 $ts = wfTimestamp( TS_UNIX, $entry->getTimestamp() );
214 $expiry = strtotime( $params['5::duration'], $ts );
215 if ( $expiry !== false && $expiry > 0 ) {
216 $params[':timestamp:expiry'] = $expiry;
217 }
218 }
219 }
220
221 return $params;
222 }
223
224 public function formatParametersForApi() {
225 $ret = parent::formatParametersForApi();
226 if ( isset( $ret['flags'] ) ) {
227 ApiResult::setIndexedTagName( $ret['flags'], 'f' );
228 }
229 return $ret;
230 }
231
232}
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.
getMessageParameters()
Formats parameters intented for action message from array of all parameters.
static formatBlockFlags( $flags, Language $lang)
Convert a comma-delimited list of block log flags into a more readable (and translated) form.
static formatBlockFlag( $flag, Language $lang)
Translate a block log flag if possible.
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.
Internationalisation code.
Definition Language.php:35
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:34
makeKnownLink(LinkTarget $target, $text=null, array $extraAttribs=[], array $query=[])
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition User.php:592
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:2054
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 use $formDescriptor instead 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
this hook is for auditing only or null if authentication failed before getting that far $username
Definition hooks.txt:815
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