MediaWiki  1.27.2
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 );
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++ ) {
135  $flags[$i] = self::formatBlockFlag( $flags[$i], $lang );
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'] ) ) {
206  $ts = wfTimestamp( TS_UNIX, $entry->getTimestamp() );
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 }
static newFromName($name, $validate= 'valid')
Static factory method for creation from username.
Definition: User.php:568
static rawParam($raw)
Definition: Message.php:975
makeUserLink(User $user, $toolFlags=0)
static linkKnown($target, $html=null, $customAttribs=[], $query=[], $options=[ 'known', 'noclasses'])
Identical to link(), except $options defaults to 'known'.
Definition: Linker.php:264
magic word the default is to use $key to get the and $key value or $key value text $key value html to format the value $key
Definition: hooks.txt:2321
static getTitleFor($name, $subpage=false, $fragment= '')
Get a localised Title object for a specified special page name.
Definition: SpecialPage.php:75
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:1798
LogEntryBase $entry
if(!isset($args[0])) $lang
msg($key)
Shortcut for wfMessage which honors local context.
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2548
getSubtype()
The log subtype.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
Definition: ApiResult.php:618
wfTimestamp($outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
const TOOL_LINKS_NOBLOCK
Flags for userToolLinks()
Definition: Linker.php:37
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 just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing 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 unsetoffset-wrap String Wrap the message in html(usually something like"&lt
$params
This class formats block log entries.
wfIsInfinity($str)
Determine input string is represents as infinity.
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:912
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
Definition: distributors.txt:9
static formatBlockFlags($flags, $lang)
Convert a comma-delimited list of block log flags into a more readable (and translated) form...
Implements the default log formatting.
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:35
this hook is for auditing only or null if authentication failed before getting that far $username
Definition: hooks.txt:762
getParameters()
Get the extra parameters stored for this message.
$messages
const TS_UNIX
Unix time - the number of seconds since 1970-01-01 00:00:00 UTC.
static formatBlockFlag($flag, $lang)
Translate a block log flag if possible.
const DELETED_ACTION
Definition: LogPage.php:33
getTimestamp()
Get the timestamp when the action was executed.