MediaWiki REL1_40
DeleteLogFormatter.php
Go to the documentation of this file.
1<?php
27
35 private $parsedParametersDeleteLog;
36
40 protected function getMessageKey() {
41 $key = parent::getMessageKey();
42 if ( in_array( $this->entry->getSubtype(), [ 'event', 'revision' ] ) ) {
43 if ( count( $this->getMessageParameters() ) < 5 ) {
44 // Messages: logentry-delete-event-legacy, logentry-delete-revision-legacy,
45 // logentry-suppress-event-legacy, logentry-suppress-revision-legacy
46 return "$key-legacy";
47 }
48 } elseif ( $this->entry->getSubtype() === 'restore' ) {
49 $rawParams = $this->entry->getParameters();
50 if ( !isset( $rawParams[':assoc:count'] ) ) {
51 // Message: logentry-delete-restore-nocount
52 return $key . '-nocount';
53 }
54 }
55
56 return $key;
57 }
58
62 protected function getMessageParameters() {
63 if ( $this->parsedParametersDeleteLog !== null ) {
64 return $this->parsedParametersDeleteLog;
65 }
66
67 $params = parent::getMessageParameters();
68 $subtype = $this->entry->getSubtype();
69 if ( in_array( $subtype, [ 'event', 'revision' ] ) ) {
70 // $params[3] here is 'revision' or 'archive' for page revisions, 'oldimage' or
71 // 'filearchive' for file versions, or a comma-separated list of log_ids for log
72 // entries. $subtype here is 'revision' for page revisions and file
73 // versions, or 'event' for log entries.
74 if (
75 ( $subtype === 'event' && count( $params ) === 6 )
76 || (
77 $subtype === 'revision' && isset( $params[3] ) && count( $params ) === 7
78 && in_array( $params[3], [ 'revision', 'archive', 'oldimage', 'filearchive' ] )
79 )
80 ) {
81 // See RevDelList::getLogParams()/RevDelLogList::getLogParams()
82 $paramStart = $subtype === 'revision' ? 4 : 3;
83
84 $old = $this->parseBitField( $params[$paramStart + 1] );
85 $new = $this->parseBitField( $params[$paramStart + 2] );
86 [ $hid, $unhid, $extra ] = RevisionDeleter::getChanges( $new, $old );
87 $changes = [];
88 // messages used: revdelete-content-hid, revdelete-summary-hid, revdelete-uname-hid
89 foreach ( $hid as $v ) {
90 $changes[] = $this->msg( "$v-hid" )->plain();
91 }
92 // messages used: revdelete-content-unhid, revdelete-summary-unhid,
93 // revdelete-uname-unhid
94 foreach ( $unhid as $v ) {
95 $changes[] = $this->msg( "$v-unhid" )->plain();
96 }
97 foreach ( $extra as $v ) {
98 $changes[] = $this->msg( $v )->plain();
99 }
100 $changeText = $this->context->getLanguage()->listToText( $changes );
101
102 $newParams = array_slice( $params, 0, 3 );
103 $newParams[3] = $changeText;
104 $ids = is_array( $params[$paramStart] )
105 ? $params[$paramStart]
106 : explode( ',', $params[$paramStart] );
107 $newParams[4] = $this->context->getLanguage()->formatNum( count( $ids ) );
108
109 $this->parsedParametersDeleteLog = $newParams;
110 return $this->parsedParametersDeleteLog;
111 } else {
112 $this->parsedParametersDeleteLog = array_slice( $params, 0, 3 );
113 return $this->parsedParametersDeleteLog;
114 }
115 } elseif ( $subtype === 'restore' ) {
116 $rawParams = $this->entry->getParameters();
117 if ( isset( $rawParams[':assoc:count'] ) ) {
118 $countList = [];
119 foreach ( $rawParams[':assoc:count'] as $type => $count ) {
120 if ( $count ) {
121 // Messages: restore-count-revisions, restore-count-files
122 $countList[] = $this->context->msg( 'restore-count-' . $type )
123 ->numParams( $count )->plain();
124 }
125 }
126 $params[3] = $this->context->getLanguage()->listToText( $countList );
127 }
128 }
129
130 $this->parsedParametersDeleteLog = $params;
131 return $this->parsedParametersDeleteLog;
132 }
133
134 protected function parseBitField( $string ) {
135 // Input is like ofield=2134 or just the number
136 if ( strpos( $string, 'field=' ) === 1 ) {
137 [ , $field ] = explode( '=', $string );
138
139 return (int)$field;
140 } else {
141 return (int)$string;
142 }
143 }
144
145 public function getActionLinks() {
146 $linkRenderer = $this->getLinkRenderer();
147 if ( !$this->context->getAuthority()->isAllowed( 'deletedhistory' )
148 || $this->entry->isDeleted( LogPage::DELETED_ACTION )
149 ) {
150 return '';
151 }
152
153 switch ( $this->entry->getSubtype() ) {
154 case 'delete': // Show undelete link
155 case 'delete_redir':
156 case 'delete_redir2':
157 if ( $this->context->getAuthority()->isAllowed( 'undelete' ) ) {
158 $message = 'undeletelink';
159 } else {
160 $message = 'undeleteviewlink';
161 }
162 $revert = $linkRenderer->makeKnownLink(
163 SpecialPage::getTitleFor( 'Undelete' ),
164 $this->msg( $message )->text(),
165 [],
166 [ 'target' => $this->entry->getTarget()->getPrefixedDBkey() ]
167 );
168
169 return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
170
171 case 'revision': // If an edit was hidden from a page give a review link to the history
172 $params = $this->extractParameters();
173 if ( !isset( $params[3] ) || !isset( $params[4] ) ) {
174 return '';
175 }
176
177 // Different revision types use different URL params...
178 $key = $params[3];
179 // This is a array or CSV of the IDs
180 $ids = is_array( $params[4] )
181 ? $params[4]
182 : explode( ',', $params[4] );
183
184 $links = [];
185
186 // If there's only one item, we can show a diff link
187 if ( count( $ids ) == 1 ) {
188 // Live revision diffs...
189 if ( $key == 'oldid' || $key == 'revision' ) {
190 $links[] = $linkRenderer->makeKnownLink(
191 $this->entry->getTarget(),
192 $this->msg( 'diff' )->text(),
193 [],
194 [
195 'diff' => intval( $ids[0] ),
196 'unhide' => 1
197 ]
198 );
199 // Deleted revision diffs...
200 } elseif ( $key == 'artimestamp' || $key == 'archive' ) {
201 $links[] = $linkRenderer->makeKnownLink(
202 SpecialPage::getTitleFor( 'Undelete' ),
203 $this->msg( 'diff' )->text(),
204 [],
205 [
206 'target' => $this->entry->getTarget()->getPrefixedDBkey(),
207 'diff' => 'prev',
208 'timestamp' => $ids[0]
209 ]
210 );
211 }
212 }
213
214 // View/modify link...
215 $links[] = $linkRenderer->makeKnownLink(
216 SpecialPage::getTitleFor( 'Revisiondelete' ),
217 $this->msg( 'revdel-restore' )->text(),
218 [],
219 [
220 'target' => $this->entry->getTarget()->getPrefixedText(),
221 'type' => $key,
222 'ids' => implode( ',', $ids ),
223 ]
224 );
225
226 return $this->msg( 'parentheses' )->rawParams(
227 $this->context->getLanguage()->pipeList( $links ) )->escaped();
228
229 case 'event': // Hidden log items, give review link
230 $params = $this->extractParameters();
231 if ( !isset( $params[3] ) ) {
232 return '';
233 }
234 // This is a CSV of the IDs
235 $query = $params[3];
236 if ( is_array( $query ) ) {
237 $query = implode( ',', $query );
238 }
239 // Link to each hidden object ID, $params[1] is the url param
240 $revert = $linkRenderer->makeKnownLink(
241 SpecialPage::getTitleFor( 'Revisiondelete' ),
242 $this->msg( 'revdel-restore' )->text(),
243 [],
244 [
245 'target' => $this->entry->getTarget()->getPrefixedText(),
246 'type' => 'logging',
247 'ids' => $query
248 ]
249 );
250
251 return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
252 default:
253 return '';
254 }
255 }
256
257 protected function getParametersForApi() {
258 $entry = $this->entry;
259 $params = [];
260
261 $subtype = $this->entry->getSubtype();
262 if ( in_array( $subtype, [ 'event', 'revision' ] ) ) {
263 $rawParams = $entry->getParameters();
264 if ( $subtype === 'event' ) {
265 array_unshift( $rawParams, 'logging' );
266 }
267
268 static $map = [
269 '4::type',
270 '5::ids',
271 '6::ofield',
272 '7::nfield',
273 '4::ids' => '5::ids',
274 '5::ofield' => '6::ofield',
275 '6::nfield' => '7::nfield',
276 ];
277 foreach ( $map as $index => $key ) {
278 if ( isset( $rawParams[$index] ) ) {
279 $rawParams[$key] = $rawParams[$index];
280 unset( $rawParams[$index] );
281 }
282 }
283
284 if ( !is_array( $rawParams['5::ids'] ) ) {
285 $rawParams['5::ids'] = explode( ',', $rawParams['5::ids'] );
286 }
287
288 $params = [
289 '::type' => $rawParams['4::type'],
290 ':array:ids' => $rawParams['5::ids'],
291 ];
292
293 static $fields = [
294 RevisionRecord::DELETED_TEXT => 'content',
295 RevisionRecord::DELETED_COMMENT => 'comment',
296 RevisionRecord::DELETED_USER => 'user',
297 RevisionRecord::DELETED_RESTRICTED => 'restricted',
298 ];
299
300 if ( isset( $rawParams['6::ofield'] ) ) {
301 $old = $this->parseBitField( $rawParams['6::ofield'] );
302 $params[':assoc:old'] = [ 'bitmask' => $old ];
303 foreach ( $fields as $bit => $key ) {
304 $params[':assoc:old'][$key] = (bool)( $old & $bit );
305 }
306 }
307 if ( isset( $rawParams['7::nfield'] ) ) {
308 $new = $this->parseBitField( $rawParams['7::nfield'] );
309 $params[':assoc:new'] = [ 'bitmask' => $new ];
310 foreach ( $fields as $bit => $key ) {
311 $params[':assoc:new'][$key] = (bool)( $new & $bit );
312 }
313 }
314 } elseif ( $subtype === 'restore' ) {
315 $rawParams = $entry->getParameters();
316 if ( isset( $rawParams[':assoc:count'] ) ) {
317 $params[':assoc:count'] = $rawParams[':assoc:count'];
318 }
319 }
320
321 return $params;
322 }
323
324 public function formatParametersForApi() {
325 $ret = parent::formatParametersForApi();
326 if ( isset( $ret['ids'] ) ) {
327 ApiResult::setIndexedTagName( $ret['ids'], 'id' );
328 }
329 return $ret;
330 }
331}
This class formats delete log entries.
formatParametersForApi()
Format parameters for API output.
getMessageParameters()
Formats parameters intended for action message from array of all parameters.There are three hardcoded...
getParametersForApi()
Get the array of parameters, converted from legacy format if necessary.
getMessageKey()
Returns a key to be used for formatting the action sentence.Default is logentry-TYPE-SUBTYPE for mode...
getActionLinks()
Returns extra links that comes after the action text, like "revert", etc.
Implements the default log formatting.
LogEntryBase $entry
msg( $key,... $params)
Shortcut for wfMessage which honors local context.
extractParameters()
Extracts the optional extra parameters for use in action messages.
Page revision base class.
static getChanges( $n, $o)
Gets an array of message keys describing the changes made to the visibility of the revision.
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,...
getParameters()
Get the extra parameters stored for this message.
getSubtype()
The log subtype.