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 foreach ( $hid as $v ) {
68 $changes[] = $this->msg( "$v-hid" )->plain();
70 foreach ( $unhid as $v ) {
71 $changes[] = $this->msg( "$v-unhid" )->plain();
73 foreach ( $extra as $v ) {
74 $changes[] = $this->msg( $v )->plain();
76 $changeText = $this->context
->getLanguage()->listToText( $changes );
78 $newParams = array_slice( $params, 0, 3 );
79 $newParams[3] = $changeText;
80 $count = count( explode( ',', $params[$paramStart] ) );
81 $newParams[4] = $this->context
->getLanguage()->formatNum( $count );
83 $this->parsedParametersDeleteLog
= $newParams;
84 return $this->parsedParametersDeleteLog
;
86 $this->parsedParametersDeleteLog
= array_slice( $params, 0, 3 );
87 return $this->parsedParametersDeleteLog
;
91 $this->parsedParametersDeleteLog
= $params;
92 return $this->parsedParametersDeleteLog
;
95 protected function parseBitField( $string ) {
96 // Input is like ofield=2134 or just the number
97 if ( strpos( $string, 'field=' ) === 1 ) {
98 list( , $field ) = explode( '=', $string );
106 public function getActionLinks() {
107 $user = $this->context
->getUser();
108 if ( !$user->isAllowed( 'deletedhistory' )
109 ||
$this->entry
->isDeleted( LogPage
::DELETED_ACTION
)
114 switch ( $this->entry
->getSubtype() ) {
115 case 'delete': // Show undelete link
116 if ( $user->isAllowed( 'undelete' ) ) {
117 $message = 'undeletelink';
119 $message = 'undeleteviewlink';
121 $revert = Linker
::linkKnown(
122 SpecialPage
::getTitleFor( 'Undelete' ),
123 $this->msg( $message )->escaped(),
125 array( 'target' => $this->entry
->getTarget()->getPrefixedDBkey() )
128 return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
130 case 'revision': // If an edit was hidden from a page give a review link to the history
131 $params = $this->extractParameters();
132 if ( !isset( $params[3] ) ||
!isset( $params[4] ) ) {
136 // Different revision types use different URL params...
138 // This is a CSV of the IDs
139 $ids = explode( ',', $params[4] );
143 // If there's only one item, we can show a diff link
144 if ( count( $ids ) == 1 ) {
145 // Live revision diffs...
146 if ( $key == 'oldid' ||
$key == 'revision' ) {
147 $links[] = Linker
::linkKnown(
148 $this->entry
->getTarget(),
149 $this->msg( 'diff' )->escaped(),
152 'diff' => intval( $ids[0] ),
156 // Deleted revision diffs...
157 } elseif ( $key == 'artimestamp' ||
$key == 'archive' ) {
158 $links[] = Linker
::linkKnown(
159 SpecialPage
::getTitleFor( 'Undelete' ),
160 $this->msg( 'diff' )->escaped(),
163 'target' => $this->entry
->getTarget()->getPrefixedDBkey(),
165 'timestamp' => $ids[0]
171 // View/modify link...
172 $links[] = Linker
::linkKnown(
173 SpecialPage
::getTitleFor( 'Revisiondelete' ),
174 $this->msg( 'revdel-restore' )->escaped(),
177 'target' => $this->entry
->getTarget()->getPrefixedText(),
179 'ids' => implode( ',', $ids ),
183 return $this->msg( 'parentheses' )->rawParams(
184 $this->context
->getLanguage()->pipeList( $links ) )->escaped();
186 case 'event': // Hidden log items, give review link
187 $params = $this->extractParameters();
188 if ( !isset( $params[3] ) ) {
191 // This is a CSV of the IDs
193 // Link to each hidden object ID, $params[1] is the url param
194 $revert = Linker
::linkKnown(
195 SpecialPage
::getTitleFor( 'Revisiondelete' ),
196 $this->msg( 'revdel-restore' )->escaped(),
199 'target' => $this->entry
->getTarget()->getPrefixedText(),
205 return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();