MediaWiki  1.29.1
BlockLogFormatter.php
Go to the documentation of this file.
1 <?php
26 
33  protected function getMessageParameters() {
34  $params = parent::getMessageParameters();
35 
36  $title = $this->entry->getTarget();
37  if ( substr( $title->getText(), 0, 1 ) === '#' ) {
38  // autoblock - no user link possible
39  $params[2] = $title->getText();
40  $params[3] = ''; // no user name for gender use
41  } else {
42  // Create a user link for the blocked
43  $username = $title->getText();
44  // @todo Store the user identifier in the parameters
45  // to make this faster for future log entries
46  $targetUser = User::newFromName( $username, false );
47  $params[2] = Message::rawParam( $this->makeUserLink( $targetUser, Linker::TOOL_LINKS_NOBLOCK ) );
48  $params[3] = $username; // plain user name for gender use
49  }
50 
51  $subtype = $this->entry->getSubtype();
52  if ( $subtype === 'block' || $subtype === 'reblock' ) {
53  if ( !isset( $params[4] ) ) {
54  // Very old log entry without duration: means infinite
55  $params[4] = 'infinite';
56  }
57  // Localize the duration, and add a tooltip
58  // in English to help visitors from other wikis.
59  // The lrm is needed to make sure that the number
60  // is shown on the correct side of the tooltip text.
61  $durationTooltip = '&lrm;' . htmlspecialchars( $params[4] );
62  $params[4] = Message::rawParam(
63  "<span class='blockExpiry' title='$durationTooltip'>" .
64  $this->context->getLanguage()->translateBlockExpiry(
65  $params[4],
66  $this->context->getUser(),
67  wfTimestamp( TS_UNIX, $this->entry->getTimestamp() )
68  ) .
69  '</span>'
70  );
71  $params[5] = isset( $params[5] ) ?
72  self::formatBlockFlags( $params[5], $this->context->getLanguage() ) : '';
73  }
74 
75  return $params;
76  }
77 
78  protected function extractParameters() {
79  $params = parent::extractParameters();
80  // Legacy log params returning the params in index 3 and 4, moved to 4 and 5
81  if ( $this->entry->isLegacy() && isset( $params[3] ) ) {
82  if ( isset( $params[4] ) ) {
83  $params[5] = $params[4];
84  }
85  $params[4] = $params[3];
86  $params[3] = '';
87  }
88  return $params;
89  }
90 
91  public function getPreloadTitles() {
92  $title = $this->entry->getTarget();
93  // Preload user page for non-autoblocks
94  if ( substr( $title->getText(), 0, 1 ) !== '#' ) {
95  return [ $title->getTalkPage() ];
96  }
97  return [];
98  }
99 
100  public function getActionLinks() {
101  $subtype = $this->entry->getSubtype();
102  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
103  if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) // Action is hidden
104  || !( $subtype === 'block' || $subtype === 'reblock' )
105  || !$this->context->getUser()->isAllowed( 'block' )
106  ) {
107  return '';
108  }
109 
110  // Show unblock/change block link
111  $title = $this->entry->getTarget();
112  $links = [
113  $linkRenderer->makeKnownLink(
114  SpecialPage::getTitleFor( 'Unblock', $title->getDBkey() ),
115  $this->msg( 'unblocklink' )->text()
116  ),
117  $linkRenderer->makeKnownLink(
118  SpecialPage::getTitleFor( 'Block', $title->getDBkey() ),
119  $this->msg( 'change-blocklink' )->text()
120  )
121  ];
122 
123  return $this->msg( 'parentheses' )->rawParams(
124  $this->context->getLanguage()->pipeList( $links ) )->escaped();
125  }
126 
135  public static function formatBlockFlags( $flags, $lang ) {
136  $flags = trim( $flags );
137  if ( $flags === '' ) {
138  return ''; // nothing to do
139  }
140  $flags = explode( ',', $flags );
141  $flagsCount = count( $flags );
142 
143  for ( $i = 0; $i < $flagsCount; $i++ ) {
145  }
146 
147  return wfMessage( 'parentheses' )->inLanguage( $lang )
148  ->rawParams( $lang->commaList( $flags ) )->escaped();
149  }
150 
158  public static function formatBlockFlag( $flag, $lang ) {
159  static $messages = [];
160 
161  if ( !isset( $messages[$flag] ) ) {
162  $messages[$flag] = htmlspecialchars( $flag ); // Fallback
163 
164  // For grepping. The following core messages can be used here:
165  // * block-log-flags-angry-autoblock
166  // * block-log-flags-anononly
167  // * block-log-flags-hiddenname
168  // * block-log-flags-noautoblock
169  // * block-log-flags-nocreate
170  // * block-log-flags-noemail
171  // * block-log-flags-nousertalk
172  $msg = wfMessage( 'block-log-flags-' . $flag )->inLanguage( $lang );
173 
174  if ( $msg->exists() ) {
175  $messages[$flag] = $msg->escaped();
176  }
177  }
178 
179  return $messages[$flag];
180  }
181 
182  protected function getParametersForApi() {
185 
186  static $map = [
187  // While this looks wrong to be starting at 5 rather than 4, it's
188  // because getMessageParameters uses $4 for its own purposes.
189  '5::duration',
190  '6:array:flags',
191  '6::flags' => '6:array:flags',
192  ];
193  foreach ( $map as $index => $key ) {
194  if ( isset( $params[$index] ) ) {
195  $params[$key] = $params[$index];
196  unset( $params[$index] );
197  }
198  }
199 
200  $subtype = $entry->getSubtype();
201  if ( $subtype === 'block' || $subtype === 'reblock' ) {
202  // Defaults for old log entries missing some fields
203  $params += [
204  '5::duration' => 'infinite',
205  '6:array:flags' => [],
206  ];
207 
208  if ( !is_array( $params['6:array:flags'] ) ) {
209  $params['6:array:flags'] = $params['6:array:flags'] === ''
210  ? []
211  : explode( ',', $params['6:array:flags'] );
212  }
213 
214  if ( !wfIsInfinity( $params['5::duration'] ) ) {
215  $ts = wfTimestamp( TS_UNIX, $entry->getTimestamp() );
216  $expiry = strtotime( $params['5::duration'], $ts );
217  if ( $expiry !== false && $expiry > 0 ) {
218  $params[':timestamp:expiry'] = $expiry;
219  }
220  }
221  }
222 
223  return $params;
224  }
225 
226  public function formatParametersForApi() {
227  $ret = parent::formatParametersForApi();
228  if ( isset( $ret['flags'] ) ) {
229  ApiResult::setIndexedTagName( $ret['flags'], 'f' );
230  }
231  return $ret;
232  }
233 
234 }
Linker\TOOL_LINKS_NOBLOCK
const TOOL_LINKS_NOBLOCK
Flags for userToolLinks()
Definition: Linker.php:38
LogEntry\getTimestamp
getTimestamp()
Get the timestamp when the action was executed.
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
LogFormatter\makeUserLink
makeUserLink(User $user, $toolFlags=0)
Definition: LogFormatter.php:710
LogEntry\getParameters
getParameters()
Get the extra parameters stored for this message.
captcha-old.count
count
Definition: captcha-old.py:225
BlockLogFormatter\formatBlockFlag
static formatBlockFlag( $flag, $lang)
Translate a block log flag if possible.
Definition: BlockLogFormatter.php:158
LogFormatter\$entry
LogEntryBase $entry
Definition: LogFormatter.php:81
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1994
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
$params
$params
Definition: styleTest.css.php:40
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:556
$linkRenderer
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 before processing starts Return false to skip default processing and return $ret $linkRenderer
Definition: hooks.txt:1956
SpecialPage\getTitleFor
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,...
Definition: SpecialPage.php:82
$messages
$messages
Definition: LogTests.i18n.php:8
php
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
BlockLogFormatter\formatParametersForApi
formatParametersForApi()
Format parameters for API output.
Definition: BlockLogFormatter.php:226
LogFormatter\msg
msg( $key)
Shortcut for wfMessage which honors local context.
Definition: LogFormatter.php:706
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:934
BlockLogFormatter\getPreloadTitles
getPreloadTitles()
Definition: BlockLogFormatter.php:91
LogPage\DELETED_ACTION
const DELETED_ACTION
Definition: LogPage.php:32
ApiResult\setIndexedTagName
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
Definition: ApiResult.php:616
wfIsInfinity
wfIsInfinity( $str)
Determine input string is represents as infinity.
Definition: GlobalFunctions.php:3577
$ret
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:1956
BlockLogFormatter\getMessageParameters
getMessageParameters()
Formats parameters intented for action message from array of all parameters.
Definition: BlockLogFormatter.php:33
BlockLogFormatter\extractParameters
extractParameters()
Extracts the optional extra parameters for use in action messages.
Definition: BlockLogFormatter.php:78
LogEntry\getSubtype
getSubtype()
The log subtype.
LogFormatter
Implements the default log formatting.
Definition: LogFormatter.php:36
as
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
BlockLogFormatter\getActionLinks
getActionLinks()
Returns extra links that comes after the action text, like "revert", etc.
Definition: BlockLogFormatter.php:100
BlockLogFormatter
This class formats block log entries.
Definition: BlockLogFormatter.php:32
wfMessage
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
MediaWikiServices
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 MediaWikiServices
Definition: injection.txt:23
$username
this hook is for auditing only or null if authentication failed before getting that far $username
Definition: hooks.txt:783
BlockLogFormatter\formatBlockFlags
static formatBlockFlags( $flags, $lang)
Convert a comma-delimited list of block log flags into a more readable (and translated) form.
Definition: BlockLogFormatter.php:135
$flags
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2749
BlockLogFormatter\getParametersForApi
getParametersForApi()
Get the array of parameters, converted from legacy format if necessary.
Definition: BlockLogFormatter.php:182