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 ) {
42 protected function getMessageParameters() {
43 if ( isset( $this->parsedParametersDeleteLog
) ) {
44 return $this->parsedParametersDeleteLog
;
47 $params = parent
::getMessageParameters();
48 $subtype = $this->entry
->getSubtype();
49 if ( in_array( $subtype, array( 'event', 'revision' ) ) ) {
50 // $params[3] here is 'revision' for page revisions, 'oldimage' for file versions, or a comma-separated list of log_ids for log entries.
51 // $subtype here is 'revision' for page revisions and file versions, or 'event' for log entries.
53 ( $subtype === 'event' && count( $params ) === 6 ) ||
54 ( $subtype === 'revision' && isset( $params[3] ) && ( $params[3] === 'revision' ||
$params[3] === 'oldimage' ) )
56 $paramStart = $subtype === 'revision' ?
4 : 3;
58 $old = $this->parseBitField( $params[$paramStart +
1] );
59 $new = $this->parseBitField( $params[$paramStart +
2] );
60 list( $hid, $unhid, $extra ) = RevisionDeleter
::getChanges( $new, $old );
62 foreach ( $hid as $v ) {
63 $changes[] = $this->msg( "$v-hid" )->plain();
65 foreach ( $unhid as $v ) {
66 $changes[] = $this->msg( "$v-unhid" )->plain();
68 foreach ( $extra as $v ) {
69 $changes[] = $this->msg( $v )->plain();
71 $changeText = $this->context
->getLanguage()->listToText( $changes );
73 $newParams = array_slice( $params, 0, 3 );
74 $newParams[3] = $changeText;
75 $count = count( explode( ',', $params[$paramStart] ) );
76 $newParams[4] = $this->context
->getLanguage()->formatNum( $count );
77 return $this->parsedParametersDeleteLog
= $newParams;
79 return $this->parsedParametersDeleteLog
= array_slice( $params, 0, 3 );
83 return $this->parsedParametersDeleteLog
= $params;
86 protected function parseBitField( $string ) {
87 // Input is like ofield=2134 or just the number
88 if ( strpos( $string, 'field=' ) === 1 ) {
89 list( , $field ) = explode( '=', $string );
96 public function getActionLinks() {
97 $user = $this->context
->getUser();
98 if ( !$user->isAllowed( 'deletedhistory' ) ||
$this->entry
->isDeleted( LogPage
::DELETED_ACTION
) ) {
102 switch ( $this->entry
->getSubtype() ) {
103 case 'delete': // Show undelete link
104 if ( $user->isAllowed( 'undelete' ) ) {
105 $message = 'undeletelink';
107 $message = 'undeleteviewlink';
109 $revert = Linker
::linkKnown(
110 SpecialPage
::getTitleFor( 'Undelete' ),
111 $this->msg( $message )->escaped(),
113 array( 'target' => $this->entry
->getTarget()->getPrefixedDBkey() )
115 return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
117 case 'revision': // If an edit was hidden from a page give a review link to the history
118 $params = $this->extractParameters();
119 if ( !isset( $params[3] ) ||
!isset( $params[4] ) ) {
123 // Different revision types use different URL params...
125 // This is a CSV of the IDs
126 $ids = explode( ',', $params[4] );
130 // If there's only one item, we can show a diff link
131 if ( count( $ids ) == 1 ) {
132 // Live revision diffs...
133 if ( $key == 'oldid' ||
$key == 'revision' ) {
134 $links[] = Linker
::linkKnown(
135 $this->entry
->getTarget(),
136 $this->msg( 'diff' )->escaped(),
139 'diff' => intval( $ids[0] ),
143 // Deleted revision diffs...
144 } elseif ( $key == 'artimestamp' ||
$key == 'archive' ) {
145 $links[] = Linker
::linkKnown(
146 SpecialPage
::getTitleFor( 'Undelete' ),
147 $this->msg( 'diff' )->escaped(),
150 'target' => $this->entry
->getTarget()->getPrefixedDBkey(),
152 'timestamp' => $ids[0]
158 // View/modify link...
159 $links[] = Linker
::linkKnown(
160 SpecialPage
::getTitleFor( 'Revisiondelete' ),
161 $this->msg( 'revdel-restore' )->escaped(),
164 'target' => $this->entry
->getTarget()->getPrefixedText(),
166 'ids' => implode( ',', $ids ),
170 return $this->msg( 'parentheses' )->rawParams(
171 $this->context
->getLanguage()->pipeList( $links ) )->escaped();
173 case 'event': // Hidden log items, give review link
174 $params = $this->extractParameters();
175 if ( !isset( $params[3] ) ) {
178 // This is a CSV of the IDs
180 // Link to each hidden object ID, $params[1] is the url param
181 $revert = Linker
::linkKnown(
182 SpecialPage
::getTitleFor( 'Revisiondelete' ),
183 $this->msg( 'revdel-restore' )->escaped(),
186 'target' => $this->entry
->getTarget()->getPrefixedText(),
191 return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();