MediaWiki  1.30.0
DeleteLogFormatter.php
Go to the documentation of this file.
1 <?php
27 
34  protected function getMessageKey() {
35  $key = parent::getMessageKey();
36  if ( in_array( $this->entry->getSubtype(), [ 'event', 'revision' ] ) ) {
37  if ( count( $this->getMessageParameters() ) < 5 ) {
38  // Messages: logentry-delete-event-legacy, logentry-delete-revision-legacy,
39  // logentry-suppress-event-legacy, logentry-suppress-revision-legacy
40  return "$key-legacy";
41  }
42  } elseif ( $this->entry->getSubtype() === 'restore' ) {
43  $rawParams = $this->entry->getParameters();
44  if ( !isset( $rawParams[':assoc:count'] ) ) {
45  // Message: logentry-delete-restore-nocount
46  return $key . '-nocount';
47  }
48  }
49 
50  return $key;
51  }
52 
53  protected function getMessageParameters() {
54  if ( isset( $this->parsedParametersDeleteLog ) ) {
55  return $this->parsedParametersDeleteLog;
56  }
57 
58  $params = parent::getMessageParameters();
59  $subtype = $this->entry->getSubtype();
60  if ( in_array( $subtype, [ 'event', 'revision' ] ) ) {
61  // $params[3] here is 'revision' or 'archive' for page revisions, 'oldimage' or
62  // 'filearchive' for file versions, or a comma-separated list of log_ids for log
63  // entries. $subtype here is 'revision' for page revisions and file
64  // versions, or 'event' for log entries.
65  if (
66  ( $subtype === 'event' && count( $params ) === 6 )
67  || (
68  $subtype === 'revision' && isset( $params[3] )
69  && in_array( $params[3], [ 'revision', 'archive', 'oldimage', 'filearchive' ] )
70  )
71  ) {
72  // See RevDelList::getLogParams()/RevDelLogList::getLogParams()
73  $paramStart = $subtype === 'revision' ? 4 : 3;
74 
75  $old = $this->parseBitField( $params[$paramStart + 1] );
76  $new = $this->parseBitField( $params[$paramStart + 2] );
77  list( $hid, $unhid, $extra ) = RevisionDeleter::getChanges( $new, $old );
78  $changes = [];
79  // messages used: revdelete-content-hid, revdelete-summary-hid, revdelete-uname-hid
80  foreach ( $hid as $v ) {
81  $changes[] = $this->msg( "$v-hid" )->plain();
82  }
83  // messages used: revdelete-content-unhid, revdelete-summary-unhid,
84  // revdelete-uname-unhid
85  foreach ( $unhid as $v ) {
86  $changes[] = $this->msg( "$v-unhid" )->plain();
87  }
88  foreach ( $extra as $v ) {
89  $changes[] = $this->msg( $v )->plain();
90  }
91  $changeText = $this->context->getLanguage()->listToText( $changes );
92 
93  $newParams = array_slice( $params, 0, 3 );
94  $newParams[3] = $changeText;
95  $ids = is_array( $params[$paramStart] )
96  ? $params[$paramStart]
97  : explode( ',', $params[$paramStart] );
98  $newParams[4] = $this->context->getLanguage()->formatNum( count( $ids ) );
99 
100  $this->parsedParametersDeleteLog = $newParams;
101  return $this->parsedParametersDeleteLog;
102  } else {
103  $this->parsedParametersDeleteLog = array_slice( $params, 0, 3 );
104  return $this->parsedParametersDeleteLog;
105  }
106  } elseif ( $subtype === 'restore' ) {
107  $rawParams = $this->entry->getParameters();
108  if ( isset( $rawParams[':assoc:count'] ) ) {
109  $countList = [];
110  foreach ( $rawParams[':assoc:count'] as $type => $count ) {
111  if ( $count ) {
112  // Messages: restore-count-revisions, restore-count-files
113  $countList[] = $this->context->msg( 'restore-count-' . $type )
114  ->numParams( $count )->plain();
115  }
116  }
117  $params[3] = $this->context->getLanguage()->listToText( $countList );
118  }
119  }
120 
121  $this->parsedParametersDeleteLog = $params;
122  return $this->parsedParametersDeleteLog;
123  }
124 
125  protected function parseBitField( $string ) {
126  // Input is like ofield=2134 or just the number
127  if ( strpos( $string, 'field=' ) === 1 ) {
128  list( , $field ) = explode( '=', $string );
129 
130  return (int)$field;
131  } else {
132  return (int)$string;
133  }
134  }
135 
136  public function getActionLinks() {
137  $user = $this->context->getUser();
138  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
139  if ( !$user->isAllowed( 'deletedhistory' )
140  || $this->entry->isDeleted( LogPage::DELETED_ACTION )
141  ) {
142  return '';
143  }
144 
145  switch ( $this->entry->getSubtype() ) {
146  case 'delete': // Show undelete link
147  case 'delete_redir':
148  if ( $user->isAllowed( 'undelete' ) ) {
149  $message = 'undeletelink';
150  } else {
151  $message = 'undeleteviewlink';
152  }
153  $revert = $linkRenderer->makeKnownLink(
154  SpecialPage::getTitleFor( 'Undelete' ),
155  $this->msg( $message )->text(),
156  [],
157  [ 'target' => $this->entry->getTarget()->getPrefixedDBkey() ]
158  );
159 
160  return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
161 
162  case 'revision': // If an edit was hidden from a page give a review link to the history
163  $params = $this->extractParameters();
164  if ( !isset( $params[3] ) || !isset( $params[4] ) ) {
165  return '';
166  }
167 
168  // Different revision types use different URL params...
169  $key = $params[3];
170  // This is a array or CSV of the IDs
171  $ids = is_array( $params[4] )
172  ? $params[4]
173  : explode( ',', $params[4] );
174 
175  $links = [];
176 
177  // If there's only one item, we can show a diff link
178  if ( count( $ids ) == 1 ) {
179  // Live revision diffs...
180  if ( $key == 'oldid' || $key == 'revision' ) {
181  $links[] = $linkRenderer->makeKnownLink(
182  $this->entry->getTarget(),
183  $this->msg( 'diff' )->text(),
184  [],
185  [
186  'diff' => intval( $ids[0] ),
187  'unhide' => 1
188  ]
189  );
190  // Deleted revision diffs...
191  } elseif ( $key == 'artimestamp' || $key == 'archive' ) {
192  $links[] = $linkRenderer->makeKnownLink(
193  SpecialPage::getTitleFor( 'Undelete' ),
194  $this->msg( 'diff' )->text(),
195  [],
196  [
197  'target' => $this->entry->getTarget()->getPrefixedDBkey(),
198  'diff' => 'prev',
199  'timestamp' => $ids[0]
200  ]
201  );
202  }
203  }
204 
205  // View/modify link...
206  $links[] = $linkRenderer->makeKnownLink(
207  SpecialPage::getTitleFor( 'Revisiondelete' ),
208  $this->msg( 'revdel-restore' )->text(),
209  [],
210  [
211  'target' => $this->entry->getTarget()->getPrefixedText(),
212  'type' => $key,
213  'ids' => implode( ',', $ids ),
214  ]
215  );
216 
217  return $this->msg( 'parentheses' )->rawParams(
218  $this->context->getLanguage()->pipeList( $links ) )->escaped();
219 
220  case 'event': // Hidden log items, give review link
221  $params = $this->extractParameters();
222  if ( !isset( $params[3] ) ) {
223  return '';
224  }
225  // This is a CSV of the IDs
226  $query = $params[3];
227  if ( is_array( $query ) ) {
228  $query = implode( ',', $query );
229  }
230  // Link to each hidden object ID, $params[1] is the url param
231  $revert = $linkRenderer->makeKnownLink(
232  SpecialPage::getTitleFor( 'Revisiondelete' ),
233  $this->msg( 'revdel-restore' )->text(),
234  [],
235  [
236  'target' => $this->entry->getTarget()->getPrefixedText(),
237  'type' => 'logging',
238  'ids' => $query
239  ]
240  );
241 
242  return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
243  default:
244  return '';
245  }
246  }
247 
248  protected function getParametersForApi() {
250  $params = [];
251 
252  $subtype = $this->entry->getSubtype();
253  if ( in_array( $subtype, [ 'event', 'revision' ] ) ) {
254  $rawParams = $entry->getParameters();
255  if ( $subtype === 'event' ) {
256  array_unshift( $rawParams, 'logging' );
257  }
258 
259  static $map = [
260  '4::type',
261  '5::ids',
262  '6::ofield',
263  '7::nfield',
264  '4::ids' => '5::ids',
265  '5::ofield' => '6::ofield',
266  '6::nfield' => '7::nfield',
267  ];
268  foreach ( $map as $index => $key ) {
269  if ( isset( $rawParams[$index] ) ) {
270  $rawParams[$key] = $rawParams[$index];
271  unset( $rawParams[$index] );
272  }
273  }
274 
275  $old = $this->parseBitField( $rawParams['6::ofield'] );
276  $new = $this->parseBitField( $rawParams['7::nfield'] );
277  if ( !is_array( $rawParams['5::ids'] ) ) {
278  $rawParams['5::ids'] = explode( ',', $rawParams['5::ids'] );
279  }
280 
281  $params = [
282  '::type' => $rawParams['4::type'],
283  ':array:ids' => $rawParams['5::ids'],
284  ':assoc:old' => [ 'bitmask' => $old ],
285  ':assoc:new' => [ 'bitmask' => $new ],
286  ];
287 
288  static $fields = [
289  Revision::DELETED_TEXT => 'content',
290  Revision::DELETED_COMMENT => 'comment',
291  Revision::DELETED_USER => 'user',
292  Revision::DELETED_RESTRICTED => 'restricted',
293  ];
294  foreach ( $fields as $bit => $key ) {
295  $params[':assoc:old'][$key] = (bool)( $old & $bit );
296  $params[':assoc:new'][$key] = (bool)( $new & $bit );
297  }
298  } elseif ( $subtype === 'restore' ) {
299  $rawParams = $entry->getParameters();
300  if ( isset( $rawParams[':assoc:count'] ) ) {
301  $params[':assoc:count'] = $rawParams[':assoc:count'];
302  }
303  }
304 
305  return $params;
306  }
307 
308  public function formatParametersForApi() {
309  $ret = parent::formatParametersForApi();
310  if ( isset( $ret['ids'] ) ) {
311  ApiResult::setIndexedTagName( $ret['ids'], 'id' );
312  }
313  return $ret;
314  }
315 }
DeleteLogFormatter\getParametersForApi
getParametersForApi()
Get the array of parameters, converted from legacy format if necessary.
Definition: DeleteLogFormatter.php:248
Revision\DELETED_USER
const DELETED_USER
Definition: Revision.php:92
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:244
Revision\DELETED_RESTRICTED
const DELETED_RESTRICTED
Definition: Revision.php:93
Revision\DELETED_COMMENT
const DELETED_COMMENT
Definition: Revision.php:91
LogEntry\getParameters
getParameters()
Get the extra parameters stored for this message.
captcha-old.count
count
Definition: captcha-old.py:249
text
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition: design.txt:12
LogFormatter\$entry
LogEntryBase $entry
Definition: LogFormatter.php:83
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
DeleteLogFormatter\parseBitField
parseBitField( $string)
Definition: DeleteLogFormatter.php:125
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
DeleteLogFormatter\getMessageKey
getMessageKey()
Returns a key to be used for formatting the action sentence.
Definition: DeleteLogFormatter.php:34
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
LogFormatter\msg
msg( $key)
Shortcut for wfMessage which honors local context.
Definition: LogFormatter.php:733
$query
null for the wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1581
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
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
RevisionDeleter\getChanges
static getChanges( $n, $o)
Gets an array of message keys describing the changes made to the visibility of the revision.
Definition: RevisionDeleter.php:127
$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:1965
$revert
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging a wrapping ErrorException instead of letting the login form give the generic error message that the account does not exist For when the account has been renamed or deleted or an array to pass a message key and parameters create2 Corresponds to logging log_action database field and which is displayed in the UI & $revert
Definition: hooks.txt:2141
LogFormatter
Implements the default log formatting.
Definition: LogFormatter.php:38
LogFormatter\$linkRenderer
LinkRenderer null $linkRenderer
Definition: LogFormatter.php:109
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
DeleteLogFormatter\getMessageParameters
getMessageParameters()
Formats parameters intented for action message from array of all parameters.
Definition: DeleteLogFormatter.php:53
DeleteLogFormatter\formatParametersForApi
formatParametersForApi()
Format parameters for API output.
Definition: DeleteLogFormatter.php:308
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
DeleteLogFormatter\getActionLinks
getActionLinks()
Returns extra links that comes after the action text, like "revert", etc.
Definition: DeleteLogFormatter.php:136
Revision\DELETED_TEXT
const DELETED_TEXT
Definition: Revision.php:90
LogFormatter\extractParameters
extractParameters()
Extracts the optional extra parameters for use in action messages.
Definition: LogFormatter.php:498
DeleteLogFormatter
This class formats delete log entries.
Definition: DeleteLogFormatter.php:33
$type
$type
Definition: testCompression.php:48