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