MediaWiki REL1_28
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( "<span class='blockExpiry' title='$durationTooltip'>" .
61 $this->context->getLanguage()->translateBlockExpiry( $params[4],
62 $this->context->getUser() ) . '</span>' );
63 $params[5] = isset( $params[5] ) ?
64 self::formatBlockFlags( $params[5], $this->context->getLanguage() ) : '';
65 }
66
67 return $params;
68 }
69
70 protected function extractParameters() {
71 $params = parent::extractParameters();
72 // Legacy log params returning the params in index 3 and 4, moved to 4 and 5
73 if ( $this->entry->isLegacy() && isset( $params[3] ) ) {
74 if ( isset( $params[4] ) ) {
75 $params[5] = $params[4];
76 }
77 $params[4] = $params[3];
78 $params[3] = '';
79 }
80 return $params;
81 }
82
83 public function getPreloadTitles() {
84 $title = $this->entry->getTarget();
85 // Preload user page for non-autoblocks
86 if ( substr( $title->getText(), 0, 1 ) !== '#' ) {
87 return [ $title->getTalkPage() ];
88 }
89 return [];
90 }
91
92 public function getActionLinks() {
93 $subtype = $this->entry->getSubtype();
94 if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) // Action is hidden
95 || !( $subtype === 'block' || $subtype === 'reblock' )
96 || !$this->context->getUser()->isAllowed( 'block' )
97 ) {
98 return '';
99 }
100
101 // Show unblock/change block link
102 $title = $this->entry->getTarget();
103 $links = [
105 SpecialPage::getTitleFor( 'Unblock', $title->getDBkey() ),
106 $this->msg( 'unblocklink' )->escaped()
107 ),
109 SpecialPage::getTitleFor( 'Block', $title->getDBkey() ),
110 $this->msg( 'change-blocklink' )->escaped()
111 )
112 ];
113
114 return $this->msg( 'parentheses' )->rawParams(
115 $this->context->getLanguage()->pipeList( $links ) )->escaped();
116 }
117
126 public static function formatBlockFlags( $flags, $lang ) {
127 $flags = trim( $flags );
128 if ( $flags === '' ) {
129 return ''; // nothing to do
130 }
131 $flags = explode( ',', $flags );
132 $flagsCount = count( $flags );
133
134 for ( $i = 0; $i < $flagsCount; $i++ ) {
136 }
137
138 return wfMessage( 'parentheses' )->inLanguage( $lang )
139 ->rawParams( $lang->commaList( $flags ) )->escaped();
140 }
141
149 public static function formatBlockFlag( $flag, $lang ) {
150 static $messages = [];
151
152 if ( !isset( $messages[$flag] ) ) {
153 $messages[$flag] = htmlspecialchars( $flag ); // Fallback
154
155 // For grepping. The following core messages can be used here:
156 // * block-log-flags-angry-autoblock
157 // * block-log-flags-anononly
158 // * block-log-flags-hiddenname
159 // * block-log-flags-noautoblock
160 // * block-log-flags-nocreate
161 // * block-log-flags-noemail
162 // * block-log-flags-nousertalk
163 $msg = wfMessage( 'block-log-flags-' . $flag )->inLanguage( $lang );
164
165 if ( $msg->exists() ) {
166 $messages[$flag] = $msg->escaped();
167 }
168 }
169
170 return $messages[$flag];
171 }
172
173 protected function getParametersForApi() {
176
177 static $map = [
178 // While this looks wrong to be starting at 5 rather than 4, it's
179 // because getMessageParameters uses $4 for its own purposes.
180 '5::duration',
181 '6:array:flags',
182 '6::flags' => '6:array:flags',
183 ];
184 foreach ( $map as $index => $key ) {
185 if ( isset( $params[$index] ) ) {
186 $params[$key] = $params[$index];
187 unset( $params[$index] );
188 }
189 }
190
191 $subtype = $entry->getSubtype();
192 if ( $subtype === 'block' || $subtype === 'reblock' ) {
193 // Defaults for old log entries missing some fields
194 $params += [
195 '5::duration' => 'infinite',
196 '6:array:flags' => [],
197 ];
198
199 if ( !is_array( $params['6:array:flags'] ) ) {
200 $params['6:array:flags'] = $params['6:array:flags'] === ''
201 ? []
202 : explode( ',', $params['6:array:flags'] );
203 }
204
205 if ( !wfIsInfinity( $params['5::duration'] ) ) {
207 $expiry = strtotime( $params['5::duration'], $ts );
208 if ( $expiry !== false && $expiry > 0 ) {
209 $params[':timestamp:expiry'] = $expiry;
210 }
211 }
212 }
213
214 return $params;
215 }
216
217 public function formatParametersForApi() {
218 $ret = parent::formatParametersForApi();
219 if ( isset( $ret['flags'] ) ) {
220 ApiResult::setIndexedTagName( $ret['flags'], 'f' );
221 }
222 return $ret;
223 }
224
225}
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.
static linkKnown( $target, $html=null, $customAttribs=[], $query=[], $options=[ 'known'])
Identical to link(), except $options defaults to 'known'.
Definition Linker.php:255
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)
const DELETED_ACTION
Definition LogPage.php:33
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,...
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:986
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
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition hooks.txt:2710
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:1949
this hook is for auditing only or null if authentication failed before getting that far $username
Definition hooks.txt:807
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
const TS_UNIX
Unix time - the number of seconds since 1970-01-01 00:00:00 UTC.
Definition defines.php:6