SpecialLinkSearch: clean up munged query variable handling
[mediawiki.git] / includes / logging / DeleteLogFormatter.php
blob8b30e9ba94bb443ce23756797388345358996abb
1 <?php
2 /**
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
20 * @file
21 * @author Niklas Laxström
22 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
23 * @since 1.22
26 /**
27 * This class formats delete log entries.
29 * @since 1.19
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 ) {
36 return "$key-legacy";
40 return $key;
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' )
60 ) {
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 );
66 $changes = array();
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 $count = count( explode( ',', $params[$paramStart] ) );
83 $newParams[4] = $this->context->getLanguage()->formatNum( $count );
85 $this->parsedParametersDeleteLog = $newParams;
86 return $this->parsedParametersDeleteLog;
87 } else {
88 $this->parsedParametersDeleteLog = array_slice( $params, 0, 3 );
89 return $this->parsedParametersDeleteLog;
93 $this->parsedParametersDeleteLog = $params;
94 return $this->parsedParametersDeleteLog;
97 protected function parseBitField( $string ) {
98 // Input is like ofield=2134 or just the number
99 if ( strpos( $string, 'field=' ) === 1 ) {
100 list( , $field ) = explode( '=', $string );
102 return (int)$field;
103 } else {
104 return (int)$string;
108 public function getActionLinks() {
109 $user = $this->context->getUser();
110 if ( !$user->isAllowed( 'deletedhistory' )
111 || $this->entry->isDeleted( LogPage::DELETED_ACTION )
113 return '';
116 switch ( $this->entry->getSubtype() ) {
117 case 'delete': // Show undelete link
118 if ( $user->isAllowed( 'undelete' ) ) {
119 $message = 'undeletelink';
120 } else {
121 $message = 'undeleteviewlink';
123 $revert = Linker::linkKnown(
124 SpecialPage::getTitleFor( 'Undelete' ),
125 $this->msg( $message )->escaped(),
126 array(),
127 array( 'target' => $this->entry->getTarget()->getPrefixedDBkey() )
130 return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
132 case 'revision': // If an edit was hidden from a page give a review link to the history
133 $params = $this->extractParameters();
134 if ( !isset( $params[3] ) || !isset( $params[4] ) ) {
135 return '';
138 // Different revision types use different URL params...
139 $key = $params[3];
140 // This is a CSV of the IDs
141 $ids = explode( ',', $params[4] );
143 $links = array();
145 // If there's only one item, we can show a diff link
146 if ( count( $ids ) == 1 ) {
147 // Live revision diffs...
148 if ( $key == 'oldid' || $key == 'revision' ) {
149 $links[] = Linker::linkKnown(
150 $this->entry->getTarget(),
151 $this->msg( 'diff' )->escaped(),
152 array(),
153 array(
154 'diff' => intval( $ids[0] ),
155 'unhide' => 1
158 // Deleted revision diffs...
159 } elseif ( $key == 'artimestamp' || $key == 'archive' ) {
160 $links[] = Linker::linkKnown(
161 SpecialPage::getTitleFor( 'Undelete' ),
162 $this->msg( 'diff' )->escaped(),
163 array(),
164 array(
165 'target' => $this->entry->getTarget()->getPrefixedDBkey(),
166 'diff' => 'prev',
167 'timestamp' => $ids[0]
173 // View/modify link...
174 $links[] = Linker::linkKnown(
175 SpecialPage::getTitleFor( 'Revisiondelete' ),
176 $this->msg( 'revdel-restore' )->escaped(),
177 array(),
178 array(
179 'target' => $this->entry->getTarget()->getPrefixedText(),
180 'type' => $key,
181 'ids' => implode( ',', $ids ),
185 return $this->msg( 'parentheses' )->rawParams(
186 $this->context->getLanguage()->pipeList( $links ) )->escaped();
188 case 'event': // Hidden log items, give review link
189 $params = $this->extractParameters();
190 if ( !isset( $params[3] ) ) {
191 return '';
193 // This is a CSV of the IDs
194 $query = $params[3];
195 // Link to each hidden object ID, $params[1] is the url param
196 $revert = Linker::linkKnown(
197 SpecialPage::getTitleFor( 'Revisiondelete' ),
198 $this->msg( 'revdel-restore' )->escaped(),
199 array(),
200 array(
201 'target' => $this->entry->getTarget()->getPrefixedText(),
202 'type' => 'logging',
203 'ids' => $query
207 return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
208 default:
209 return '';