3 * Formatter for delete log entries.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @author Niklas Laxström
22 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
27 * This class formats delete log entries.
31 class DeleteLogFormatter
extends LogFormatter
{
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
45 protected function getMessageParameters() {
46 if ( isset( $this->parsedParametersDeleteLog
) ) {
47 return $this->parsedParametersDeleteLog
;
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' )
63 $paramStart = $subtype === 'revision' ?
4 : 3;
65 $old = $this->parseBitField( $params[$paramStart +
1] );
66 $new = $this->parseBitField( $params[$paramStart +
2] );
67 list( $hid, $unhid, $extra ) = RevisionDeleter
::getChanges( $new, $old );
69 // messages used: revdelete-content-hid, revdelete-summary-hid, revdelete-uname-hid
70 foreach ( $hid as $v ) {
71 $changes[] = $this->msg( "$v-hid" )->plain();
73 // messages used: revdelete-content-unhid, revdelete-summary-unhid, revdelete-uname-unhid
74 foreach ( $unhid as $v ) {
75 $changes[] = $this->msg( "$v-unhid" )->plain();
77 foreach ( $extra as $v ) {
78 $changes[] = $this->msg( $v )->plain();
80 $changeText = $this->context
->getLanguage()->listToText( $changes );
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 ) );
89 $this->parsedParametersDeleteLog
= $newParams;
90 return $this->parsedParametersDeleteLog
;
92 $this->parsedParametersDeleteLog
= array_slice( $params, 0, 3 );
93 return $this->parsedParametersDeleteLog
;
97 $this->parsedParametersDeleteLog
= $params;
98 return $this->parsedParametersDeleteLog
;
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 );
112 public function getActionLinks() {
113 $user = $this->context
->getUser();
114 if ( !$user->isAllowed( 'deletedhistory' )
115 ||
$this->entry
->isDeleted( LogPage
::DELETED_ACTION
)
120 switch ( $this->entry
->getSubtype() ) {
121 case 'delete': // Show undelete link
122 if ( $user->isAllowed( 'undelete' ) ) {
123 $message = 'undeletelink';
125 $message = 'undeleteviewlink';
127 $revert = Linker
::linkKnown(
128 SpecialPage
::getTitleFor( 'Undelete' ),
129 $this->msg( $message )->escaped(),
131 [ 'target' => $this->entry
->getTarget()->getPrefixedDBkey() ]
134 return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
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] ) ) {
142 // Different revision types use different URL params...
144 // This is a array or CSV of the IDs
145 $ids = is_array( $params[4] )
147 : explode( ',', $params[4] );
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(),
160 'diff' => intval( $ids[0] ),
164 // Deleted revision diffs...
165 } elseif ( $key == 'artimestamp' ||
$key == 'archive' ) {
166 $links[] = Linker
::linkKnown(
167 SpecialPage
::getTitleFor( 'Undelete' ),
168 $this->msg( 'diff' )->escaped(),
171 'target' => $this->entry
->getTarget()->getPrefixedDBkey(),
173 'timestamp' => $ids[0]
179 // View/modify link...
180 $links[] = Linker
::linkKnown(
181 SpecialPage
::getTitleFor( 'Revisiondelete' ),
182 $this->msg( 'revdel-restore' )->escaped(),
185 'target' => $this->entry
->getTarget()->getPrefixedText(),
187 'ids' => implode( ',', $ids ),
191 return $this->msg( 'parentheses' )->rawParams(
192 $this->context
->getLanguage()->pipeList( $links ) )->escaped();
194 case 'event': // Hidden log items, give review link
195 $params = $this->extractParameters();
196 if ( !isset( $params[3] ) ) {
199 // This is a CSV of the IDs
201 if ( is_array( $query ) ) {
202 $query = implode( ',', $query );
204 // Link to each hidden object ID, $params[1] is the url param
205 $revert = Linker
::linkKnown(
206 SpecialPage
::getTitleFor( 'Revisiondelete' ),
207 $this->msg( 'revdel-restore' )->escaped(),
210 'target' => $this->entry
->getTarget()->getPrefixedText(),
216 return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
222 protected function getParametersForApi() {
223 $entry = $this->entry
;
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' );
238 '4::ids' => '5::ids',
239 '5::ofield' => '6::ofield',
240 '6::nfield' => '7::nfield',
242 foreach ( $map as $index => $key ) {
243 if ( isset( $rawParams[$index] ) ) {
244 $rawParams[$key] = $rawParams[$index];
245 unset( $rawParams[$index] );
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'] );
256 '::type' => $rawParams['4::type'],
257 ':array:ids' => $rawParams['5::ids'],
258 ':assoc:old' => [ 'bitmask' => $old ],
259 ':assoc:new' => [ 'bitmask' => $new ],
263 Revision
::DELETED_TEXT
=> 'content',
264 Revision
::DELETED_COMMENT
=> 'comment',
265 Revision
::DELETED_USER
=> 'user',
266 Revision
::DELETED_RESTRICTED
=> 'restricted',
268 foreach ( $fields as $bit => $key ) {
269 $params[':assoc:old'][$key] = (bool)( $old & $bit );
270 $params[':assoc:new'][$key] = (bool)( $new & $bit );
277 public function formatParametersForApi() {
278 $ret = parent
::formatParametersForApi();
279 if ( isset( $ret['ids'] ) ) {
280 ApiResult
::setIndexedTagName( $ret['ids'], 'id' );