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.
58 ( $subtype === 'event' && count( $params ) === 6 )
60 $subtype === 'revision' && isset( $params[3] )
61 && in_array( $params[3], [ 'revision', 'archive', 'oldimage', 'filearchive' ] )
64 // See RevDelList::getLogParams()/RevDelLogList::getLogParams()
65 $paramStart = $subtype === 'revision' ?
4 : 3;
67 $old = $this->parseBitField( $params[$paramStart +
1] );
68 $new = $this->parseBitField( $params[$paramStart +
2] );
69 list( $hid, $unhid, $extra ) = RevisionDeleter
::getChanges( $new, $old );
71 // messages used: revdelete-content-hid, revdelete-summary-hid, revdelete-uname-hid
72 foreach ( $hid as $v ) {
73 $changes[] = $this->msg( "$v-hid" )->plain();
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();
80 foreach ( $extra as $v ) {
81 $changes[] = $this->msg( $v )->plain();
83 $changeText = $this->context
->getLanguage()->listToText( $changes );
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 ) );
92 $this->parsedParametersDeleteLog
= $newParams;
93 return $this->parsedParametersDeleteLog
;
95 $this->parsedParametersDeleteLog
= array_slice( $params, 0, 3 );
96 return $this->parsedParametersDeleteLog
;
100 $this->parsedParametersDeleteLog
= $params;
101 return $this->parsedParametersDeleteLog
;
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 );
115 public function getActionLinks() {
116 $user = $this->context
->getUser();
117 if ( !$user->isAllowed( 'deletedhistory' )
118 ||
$this->entry
->isDeleted( LogPage
::DELETED_ACTION
)
123 switch ( $this->entry
->getSubtype() ) {
124 case 'delete': // Show undelete link
126 if ( $user->isAllowed( 'undelete' ) ) {
127 $message = 'undeletelink';
129 $message = 'undeleteviewlink';
131 $revert = Linker
::linkKnown(
132 SpecialPage
::getTitleFor( 'Undelete' ),
133 $this->msg( $message )->escaped(),
135 [ 'target' => $this->entry
->getTarget()->getPrefixedDBkey() ]
138 return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
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] ) ) {
146 // Different revision types use different URL params...
148 // This is a array or CSV of the IDs
149 $ids = is_array( $params[4] )
151 : explode( ',', $params[4] );
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(),
164 'diff' => intval( $ids[0] ),
168 // Deleted revision diffs...
169 } elseif ( $key == 'artimestamp' ||
$key == 'archive' ) {
170 $links[] = Linker
::linkKnown(
171 SpecialPage
::getTitleFor( 'Undelete' ),
172 $this->msg( 'diff' )->escaped(),
175 'target' => $this->entry
->getTarget()->getPrefixedDBkey(),
177 'timestamp' => $ids[0]
183 // View/modify link...
184 $links[] = Linker
::linkKnown(
185 SpecialPage
::getTitleFor( 'Revisiondelete' ),
186 $this->msg( 'revdel-restore' )->escaped(),
189 'target' => $this->entry
->getTarget()->getPrefixedText(),
191 'ids' => implode( ',', $ids ),
195 return $this->msg( 'parentheses' )->rawParams(
196 $this->context
->getLanguage()->pipeList( $links ) )->escaped();
198 case 'event': // Hidden log items, give review link
199 $params = $this->extractParameters();
200 if ( !isset( $params[3] ) ) {
203 // This is a CSV of the IDs
205 if ( is_array( $query ) ) {
206 $query = implode( ',', $query );
208 // Link to each hidden object ID, $params[1] is the url param
209 $revert = Linker
::linkKnown(
210 SpecialPage
::getTitleFor( 'Revisiondelete' ),
211 $this->msg( 'revdel-restore' )->escaped(),
214 'target' => $this->entry
->getTarget()->getPrefixedText(),
220 return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
226 protected function getParametersForApi() {
227 $entry = $this->entry
;
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' );
242 '4::ids' => '5::ids',
243 '5::ofield' => '6::ofield',
244 '6::nfield' => '7::nfield',
246 foreach ( $map as $index => $key ) {
247 if ( isset( $rawParams[$index] ) ) {
248 $rawParams[$key] = $rawParams[$index];
249 unset( $rawParams[$index] );
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'] );
260 '::type' => $rawParams['4::type'],
261 ':array:ids' => $rawParams['5::ids'],
262 ':assoc:old' => [ 'bitmask' => $old ],
263 ':assoc:new' => [ 'bitmask' => $new ],
267 Revision
::DELETED_TEXT
=> 'content',
268 Revision
::DELETED_COMMENT
=> 'comment',
269 Revision
::DELETED_USER
=> 'user',
270 Revision
::DELETED_RESTRICTED
=> 'restricted',
272 foreach ( $fields as $bit => $key ) {
273 $params[':assoc:old'][$key] = (bool)( $old & $bit );
274 $params[':assoc:new'][$key] = (bool)( $new & $bit );
281 public function formatParametersForApi() {
282 $ret = parent
::formatParametersForApi();
283 if ( isset( $ret['ids'] ) ) {
284 ApiResult
::setIndexedTagName( $ret['ids'], 'id' );