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(), array( 'event', 'revision' ) ) ) {
35 if ( count( $this->getMessageParameters() ) < 5 ) {
43 protected function getMessageParameters() {
44 if ( isset( $this->parsedParametersDeleteLog
) ) {
45 return $this->parsedParametersDeleteLog
;
48 $params = parent
::getMessageParameters();
49 $subtype = $this->entry
->getSubtype();
50 if ( in_array( $subtype, array( 'event', 'revision' ) ) ) {
51 // $params[3] here is 'revision' or 'archive' for page revisions, 'oldimage' or
52 // 'filearchive' for file versions, or a comma-separated list of log_ids for log
53 // entries. $subtype here is 'revision' for page revisions and file
54 // versions, or 'event' for log entries.
55 if ( ( $subtype === 'event' && count( $params ) === 6 )
56 ||
( $subtype === 'revision' && isset( $params[3] )
57 && ( $params[3] === 'revision' ||
$params[3] === 'oldimage'
58 ||
$params[3] === 'archive' ||
$params[3] === 'filearchive' )
61 $paramStart = $subtype === 'revision' ?
4 : 3;
63 $old = $this->parseBitField( $params[$paramStart +
1] );
64 $new = $this->parseBitField( $params[$paramStart +
2] );
65 list( $hid, $unhid, $extra ) = RevisionDeleter
::getChanges( $new, $old );
67 // messages used: revdelete-content-hid, revdelete-summary-hid, revdelete-uname-hid
68 foreach ( $hid as $v ) {
69 $changes[] = $this->msg( "$v-hid" )->plain();
71 // messages used: revdelete-content-unhid, revdelete-summary-unhid, revdelete-uname-unhid
72 foreach ( $unhid as $v ) {
73 $changes[] = $this->msg( "$v-unhid" )->plain();
75 foreach ( $extra as $v ) {
76 $changes[] = $this->msg( $v )->plain();
78 $changeText = $this->context
->getLanguage()->listToText( $changes );
80 $newParams = array_slice( $params, 0, 3 );
81 $newParams[3] = $changeText;
82 $ids = is_array( $params[$paramStart] )
83 ?
$params[$paramStart]
84 : explode( ',', $params[$paramStart] );
85 $newParams[4] = $this->context
->getLanguage()->formatNum( count( $ids ) );
87 $this->parsedParametersDeleteLog
= $newParams;
88 return $this->parsedParametersDeleteLog
;
90 $this->parsedParametersDeleteLog
= array_slice( $params, 0, 3 );
91 return $this->parsedParametersDeleteLog
;
95 $this->parsedParametersDeleteLog
= $params;
96 return $this->parsedParametersDeleteLog
;
99 protected function parseBitField( $string ) {
100 // Input is like ofield=2134 or just the number
101 if ( strpos( $string, 'field=' ) === 1 ) {
102 list( , $field ) = explode( '=', $string );
110 public function getActionLinks() {
111 $user = $this->context
->getUser();
112 if ( !$user->isAllowed( 'deletedhistory' )
113 ||
$this->entry
->isDeleted( LogPage
::DELETED_ACTION
)
118 switch ( $this->entry
->getSubtype() ) {
119 case 'delete': // Show undelete link
120 if ( $user->isAllowed( 'undelete' ) ) {
121 $message = 'undeletelink';
123 $message = 'undeleteviewlink';
125 $revert = Linker
::linkKnown(
126 SpecialPage
::getTitleFor( 'Undelete' ),
127 $this->msg( $message )->escaped(),
129 array( 'target' => $this->entry
->getTarget()->getPrefixedDBkey() )
132 return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
134 case 'revision': // If an edit was hidden from a page give a review link to the history
135 $params = $this->extractParameters();
136 if ( !isset( $params[3] ) ||
!isset( $params[4] ) ) {
140 // Different revision types use different URL params...
142 // This is a array or CSV of the IDs
143 $ids = is_array( $params[4] )
145 : explode( ',', $params[4] );
149 // If there's only one item, we can show a diff link
150 if ( count( $ids ) == 1 ) {
151 // Live revision diffs...
152 if ( $key == 'oldid' ||
$key == 'revision' ) {
153 $links[] = Linker
::linkKnown(
154 $this->entry
->getTarget(),
155 $this->msg( 'diff' )->escaped(),
158 'diff' => intval( $ids[0] ),
162 // Deleted revision diffs...
163 } elseif ( $key == 'artimestamp' ||
$key == 'archive' ) {
164 $links[] = Linker
::linkKnown(
165 SpecialPage
::getTitleFor( 'Undelete' ),
166 $this->msg( 'diff' )->escaped(),
169 'target' => $this->entry
->getTarget()->getPrefixedDBkey(),
171 'timestamp' => $ids[0]
177 // View/modify link...
178 $links[] = Linker
::linkKnown(
179 SpecialPage
::getTitleFor( 'Revisiondelete' ),
180 $this->msg( 'revdel-restore' )->escaped(),
183 'target' => $this->entry
->getTarget()->getPrefixedText(),
185 'ids' => implode( ',', $ids ),
189 return $this->msg( 'parentheses' )->rawParams(
190 $this->context
->getLanguage()->pipeList( $links ) )->escaped();
192 case 'event': // Hidden log items, give review link
193 $params = $this->extractParameters();
194 if ( !isset( $params[3] ) ) {
197 // This is a CSV of the IDs
199 // Link to each hidden object ID, $params[1] is the url param
200 $revert = Linker
::linkKnown(
201 SpecialPage
::getTitleFor( 'Revisiondelete' ),
202 $this->msg( 'revdel-restore' )->escaped(),
205 'target' => $this->entry
->getTarget()->getPrefixedText(),
211 return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();