MediaWiki  master
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 = $this->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  if ( !is_array( $rawParams['5::ids'] ) ) {
276  $rawParams['5::ids'] = explode( ',', $rawParams['5::ids'] );
277  }
278 
279  $params = [
280  '::type' => $rawParams['4::type'],
281  ':array:ids' => $rawParams['5::ids'],
282  ];
283 
284  static $fields = [
285  RevisionRecord::DELETED_TEXT => 'content',
286  RevisionRecord::DELETED_COMMENT => 'comment',
287  RevisionRecord::DELETED_USER => 'user',
288  RevisionRecord::DELETED_RESTRICTED => 'restricted',
289  ];
290 
291  if ( isset( $rawParams['6::ofield'] ) ) {
292  $old = $this->parseBitField( $rawParams['6::ofield'] );
293  $params[':assoc:old'] = [ 'bitmask' => $old ];
294  foreach ( $fields as $bit => $key ) {
295  $params[':assoc:old'][$key] = (bool)( $old & $bit );
296  }
297  }
298  if ( isset( $rawParams['7::nfield'] ) ) {
299  $new = $this->parseBitField( $rawParams['7::nfield'] );
300  $params[':assoc:new'] = [ 'bitmask' => $new ];
301  foreach ( $fields as $bit => $key ) {
302  $params[':assoc:new'][$key] = (bool)( $new & $bit );
303  }
304  }
305  } elseif ( $subtype === 'restore' ) {
306  $rawParams = $entry->getParameters();
307  if ( isset( $rawParams[':assoc:count'] ) ) {
308  $params[':assoc:count'] = $rawParams[':assoc:count'];
309  }
310  }
311 
312  return $params;
313  }
314 
315  public function formatParametersForApi() {
316  $ret = parent::formatParametersForApi();
317  if ( isset( $ret['ids'] ) ) {
318  ApiResult::setIndexedTagName( $ret['ids'], 'id' );
319  }
320  return $ret;
321  }
322 }
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
return true to allow those checks to and false if checking is done remove or add to the links of a group of changes in EnhancedChangesList Hook subscribers can return false to omit this line from recentchanges use this to change the tables headers change it to an object instance and return false override the list derivative used $groups Array of ChangesListFilterGroup objects(added in 1.34) 'FileDeleteComplete' null for the local 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:1529
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging a wrapping ErrorException create2 Corresponds to logging log_action database field and which is displayed in the UI & $revert
Definition: hooks.txt:2147
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:1972
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
LogEntryBase $entry
static getChanges( $n, $o)
Gets an array of message keys describing the changes made to the visibility of the revision...
This class formats delete log entries.
LinkRenderer null $linkRenderer
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
Definition: ApiResult.php:616
$params
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don&#39;t need a full Title object...
Definition: SpecialPage.php:83
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
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
getParameters()
Get the extra parameters stored for this message.
msg( $key)
Shortcut for wfMessage which honors local context.
extractParameters()
Extracts the optional extra parameters for use in action messages.
const DELETED_ACTION
Definition: LogPage.php:34
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1454