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