MediaWiki  1.27.2
DeleteLogFormatter.php
Go to the documentation of this file.
1 <?php
32  protected function getMessageKey() {
33  $key = parent::getMessageKey();
34  if ( in_array( $this->entry->getSubtype(), [ 'event', 'revision' ] ) ) {
35  if ( count( $this->getMessageParameters() ) < 5 ) {
36  // Messages: logentry-delete-event-legacy, logentry-delete-revision-legacy,
37  // logentry-suppress-event-legacy, logentry-suppress-revision-legacy
38  return "$key-legacy";
39  }
40  }
41 
42  return $key;
43  }
44 
45  protected function getMessageParameters() {
46  if ( isset( $this->parsedParametersDeleteLog ) ) {
47  return $this->parsedParametersDeleteLog;
48  }
49 
50  $params = parent::getMessageParameters();
51  $subtype = $this->entry->getSubtype();
52  if ( in_array( $subtype, [ 'event', 'revision' ] ) ) {
53  // $params[3] here is 'revision' or 'archive' for page revisions, 'oldimage' or
54  // 'filearchive' for file versions, or a comma-separated list of log_ids for log
55  // entries. $subtype here is 'revision' for page revisions and file
56  // versions, or 'event' for log entries.
57  if ( ( $subtype === 'event' && count( $params ) === 6 )
58  || ( $subtype === 'revision' && isset( $params[3] )
59  && ( $params[3] === 'revision' || $params[3] === 'oldimage'
60  || $params[3] === 'archive' || $params[3] === 'filearchive' )
61  )
62  ) {
63  $paramStart = $subtype === 'revision' ? 4 : 3;
64 
65  $old = $this->parseBitField( $params[$paramStart + 1] );
66  $new = $this->parseBitField( $params[$paramStart + 2] );
67  list( $hid, $unhid, $extra ) = RevisionDeleter::getChanges( $new, $old );
68  $changes = [];
69  // messages used: revdelete-content-hid, revdelete-summary-hid, revdelete-uname-hid
70  foreach ( $hid as $v ) {
71  $changes[] = $this->msg( "$v-hid" )->plain();
72  }
73  // messages used: revdelete-content-unhid, revdelete-summary-unhid, revdelete-uname-unhid
74  foreach ( $unhid as $v ) {
75  $changes[] = $this->msg( "$v-unhid" )->plain();
76  }
77  foreach ( $extra as $v ) {
78  $changes[] = $this->msg( $v )->plain();
79  }
80  $changeText = $this->context->getLanguage()->listToText( $changes );
81 
82  $newParams = array_slice( $params, 0, 3 );
83  $newParams[3] = $changeText;
84  $ids = is_array( $params[$paramStart] )
85  ? $params[$paramStart]
86  : explode( ',', $params[$paramStart] );
87  $newParams[4] = $this->context->getLanguage()->formatNum( count( $ids ) );
88 
89  $this->parsedParametersDeleteLog = $newParams;
90  return $this->parsedParametersDeleteLog;
91  } else {
92  $this->parsedParametersDeleteLog = array_slice( $params, 0, 3 );
93  return $this->parsedParametersDeleteLog;
94  }
95  }
96 
97  $this->parsedParametersDeleteLog = $params;
98  return $this->parsedParametersDeleteLog;
99  }
100 
101  protected function parseBitField( $string ) {
102  // Input is like ofield=2134 or just the number
103  if ( strpos( $string, 'field=' ) === 1 ) {
104  list( , $field ) = explode( '=', $string );
105 
106  return (int)$field;
107  } else {
108  return (int)$string;
109  }
110  }
111 
112  public function getActionLinks() {
113  $user = $this->context->getUser();
114  if ( !$user->isAllowed( 'deletedhistory' )
115  || $this->entry->isDeleted( LogPage::DELETED_ACTION )
116  ) {
117  return '';
118  }
119 
120  switch ( $this->entry->getSubtype() ) {
121  case 'delete': // Show undelete link
122  if ( $user->isAllowed( 'undelete' ) ) {
123  $message = 'undeletelink';
124  } else {
125  $message = 'undeleteviewlink';
126  }
128  SpecialPage::getTitleFor( 'Undelete' ),
129  $this->msg( $message )->escaped(),
130  [],
131  [ 'target' => $this->entry->getTarget()->getPrefixedDBkey() ]
132  );
133 
134  return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
135 
136  case 'revision': // If an edit was hidden from a page give a review link to the history
137  $params = $this->extractParameters();
138  if ( !isset( $params[3] ) || !isset( $params[4] ) ) {
139  return '';
140  }
141 
142  // Different revision types use different URL params...
143  $key = $params[3];
144  // This is a array or CSV of the IDs
145  $ids = is_array( $params[4] )
146  ? $params[4]
147  : explode( ',', $params[4] );
148 
149  $links = [];
150 
151  // If there's only one item, we can show a diff link
152  if ( count( $ids ) == 1 ) {
153  // Live revision diffs...
154  if ( $key == 'oldid' || $key == 'revision' ) {
155  $links[] = Linker::linkKnown(
156  $this->entry->getTarget(),
157  $this->msg( 'diff' )->escaped(),
158  [],
159  [
160  'diff' => intval( $ids[0] ),
161  'unhide' => 1
162  ]
163  );
164  // Deleted revision diffs...
165  } elseif ( $key == 'artimestamp' || $key == 'archive' ) {
166  $links[] = Linker::linkKnown(
167  SpecialPage::getTitleFor( 'Undelete' ),
168  $this->msg( 'diff' )->escaped(),
169  [],
170  [
171  'target' => $this->entry->getTarget()->getPrefixedDBkey(),
172  'diff' => 'prev',
173  'timestamp' => $ids[0]
174  ]
175  );
176  }
177  }
178 
179  // View/modify link...
180  $links[] = Linker::linkKnown(
181  SpecialPage::getTitleFor( 'Revisiondelete' ),
182  $this->msg( 'revdel-restore' )->escaped(),
183  [],
184  [
185  'target' => $this->entry->getTarget()->getPrefixedText(),
186  'type' => $key,
187  'ids' => implode( ',', $ids ),
188  ]
189  );
190 
191  return $this->msg( 'parentheses' )->rawParams(
192  $this->context->getLanguage()->pipeList( $links ) )->escaped();
193 
194  case 'event': // Hidden log items, give review link
195  $params = $this->extractParameters();
196  if ( !isset( $params[3] ) ) {
197  return '';
198  }
199  // This is a CSV of the IDs
200  $query = $params[3];
201  if ( is_array( $query ) ) {
202  $query = implode( ',', $query );
203  }
204  // Link to each hidden object ID, $params[1] is the url param
206  SpecialPage::getTitleFor( 'Revisiondelete' ),
207  $this->msg( 'revdel-restore' )->escaped(),
208  [],
209  [
210  'target' => $this->entry->getTarget()->getPrefixedText(),
211  'type' => 'logging',
212  'ids' => $query
213  ]
214  );
215 
216  return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
217  default:
218  return '';
219  }
220  }
221 
222  protected function getParametersForApi() {
224  $params = [];
225 
226  $subtype = $this->entry->getSubtype();
227  if ( in_array( $subtype, [ 'event', 'revision' ] ) ) {
228  $rawParams = $entry->getParameters();
229  if ( $subtype === 'event' ) {
230  array_unshift( $rawParams, 'logging' );
231  }
232 
233  static $map = [
234  '4::type',
235  '5::ids',
236  '6::ofield',
237  '7::nfield',
238  '4::ids' => '5::ids',
239  '5::ofield' => '6::ofield',
240  '6::nfield' => '7::nfield',
241  ];
242  foreach ( $map as $index => $key ) {
243  if ( isset( $rawParams[$index] ) ) {
244  $rawParams[$key] = $rawParams[$index];
245  unset( $rawParams[$index] );
246  }
247  }
248 
249  $old = $this->parseBitField( $rawParams['6::ofield'] );
250  $new = $this->parseBitField( $rawParams['7::nfield'] );
251  if ( !is_array( $rawParams['5::ids'] ) ) {
252  $rawParams['5::ids'] = explode( ',', $rawParams['5::ids'] );
253  }
254 
255  $params = [
256  '::type' => $rawParams['4::type'],
257  ':array:ids' => $rawParams['5::ids'],
258  ':assoc:old' => [ 'bitmask' => $old ],
259  ':assoc:new' => [ 'bitmask' => $new ],
260  ];
261 
262  static $fields = [
263  Revision::DELETED_TEXT => 'content',
264  Revision::DELETED_COMMENT => 'comment',
265  Revision::DELETED_USER => 'user',
266  Revision::DELETED_RESTRICTED => 'restricted',
267  ];
268  foreach ( $fields as $bit => $key ) {
269  $params[':assoc:old'][$key] = (bool)( $old & $bit );
270  $params[':assoc:new'][$key] = (bool)( $new & $bit );
271  }
272  }
273 
274  return $params;
275  }
276 
277  public function formatParametersForApi() {
278  $ret = parent::formatParametersForApi();
279  if ( isset( $ret['ids'] ) ) {
280  ApiResult::setIndexedTagName( $ret['ids'], 'id' );
281  }
282  return $ret;
283  }
284 }
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
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:1418
static linkKnown($target, $html=null, $customAttribs=[], $query=[], $options=[ 'known', 'noclasses'])
Identical to link(), except $options defaults to 'known'.
Definition: Linker.php:264
static getChanges($n, $o)
Gets an array of message keys describing the changes made to the visibility of the revision...
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
msg($key)
Shortcut for wfMessage which honors local context.
This class formats delete log entries.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
Definition: ApiResult.php:618
$params
const DELETED_RESTRICTED
Definition: Revision.php:79
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
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 local account $user
Definition: hooks.txt:242
const DELETED_TEXT
Definition: Revision.php:76
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.
const DELETED_USER
Definition: Revision.php:78
extractParameters()
Extracts the optional extra parameters for use in action messages.
const DELETED_COMMENT
Definition: Revision.php:77
const DELETED_ACTION
Definition: LogPage.php:33
this hook is for auditing only etc 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:1946