PHPSessionHandler: Implement SessionHandlerInterface
[mediawiki.git] / includes / logging / DeleteLogFormatter.php
blobf0598aa74981c53bddf36e6794c8df91927c9815
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 $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;
89 } else {
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 );
104 return (int)$field;
105 } else {
106 return (int)$string;
110 public function getActionLinks() {
111 $user = $this->context->getUser();
112 if ( !$user->isAllowed( 'deletedhistory' )
113 || $this->entry->isDeleted( LogPage::DELETED_ACTION )
115 return '';
118 switch ( $this->entry->getSubtype() ) {
119 case 'delete': // Show undelete link
120 if ( $user->isAllowed( 'undelete' ) ) {
121 $message = 'undeletelink';
122 } else {
123 $message = 'undeleteviewlink';
125 $revert = Linker::linkKnown(
126 SpecialPage::getTitleFor( 'Undelete' ),
127 $this->msg( $message )->escaped(),
128 array(),
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] ) ) {
137 return '';
140 // Different revision types use different URL params...
141 $key = $params[3];
142 // This is a array or CSV of the IDs
143 $ids = is_array( $params[4] )
144 ? $params[4]
145 : explode( ',', $params[4] );
147 $links = array();
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(),
156 array(),
157 array(
158 'diff' => intval( $ids[0] ),
159 'unhide' => 1
162 // Deleted revision diffs...
163 } elseif ( $key == 'artimestamp' || $key == 'archive' ) {
164 $links[] = Linker::linkKnown(
165 SpecialPage::getTitleFor( 'Undelete' ),
166 $this->msg( 'diff' )->escaped(),
167 array(),
168 array(
169 'target' => $this->entry->getTarget()->getPrefixedDBkey(),
170 'diff' => 'prev',
171 'timestamp' => $ids[0]
177 // View/modify link...
178 $links[] = Linker::linkKnown(
179 SpecialPage::getTitleFor( 'Revisiondelete' ),
180 $this->msg( 'revdel-restore' )->escaped(),
181 array(),
182 array(
183 'target' => $this->entry->getTarget()->getPrefixedText(),
184 'type' => $key,
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] ) ) {
195 return '';
197 // This is a CSV of the IDs
198 $query = $params[3];
199 if ( is_array( $query ) ) {
200 $query = implode( ',', $query );
202 // Link to each hidden object ID, $params[1] is the url param
203 $revert = Linker::linkKnown(
204 SpecialPage::getTitleFor( 'Revisiondelete' ),
205 $this->msg( 'revdel-restore' )->escaped(),
206 array(),
207 array(
208 'target' => $this->entry->getTarget()->getPrefixedText(),
209 'type' => 'logging',
210 'ids' => $query
214 return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
215 default:
216 return '';
220 protected function getParametersForApi() {
221 $entry = $this->entry;
222 $params = array();
224 $subtype = $this->entry->getSubtype();
225 if ( in_array( $subtype, array( 'event', 'revision' ) ) ) {
226 $rawParams = $entry->getParameters();
227 if ( $subtype === 'event' ) {
228 array_unshift( $rawParams, 'logging' );
231 static $map = array(
232 '4::type',
233 '5::ids',
234 '6::ofield',
235 '7::nfield',
236 '4::ids' => '5::ids',
237 '5::ofield' => '6::ofield',
238 '6::nfield' => '7::nfield',
240 foreach ( $map as $index => $key ) {
241 if ( isset( $rawParams[$index] ) ) {
242 $rawParams[$key] = $rawParams[$index];
243 unset( $rawParams[$index] );
247 $old = $this->parseBitField( $rawParams['6::ofield'] );
248 $new = $this->parseBitField( $rawParams['7::nfield'] );
249 if ( !is_array( $rawParams['5::ids'] ) ) {
250 $rawParams['5::ids'] = explode( ',', $rawParams['5::ids'] );
253 $params = array(
254 '::type' => $rawParams['4::type'],
255 ':array:ids' => $rawParams['5::ids'],
256 ':assoc:old' => array( 'bitmask' => $old ),
257 ':assoc:new' => array( 'bitmask' => $new ),
260 static $fields = array(
261 Revision::DELETED_TEXT => 'content',
262 Revision::DELETED_COMMENT => 'comment',
263 Revision::DELETED_USER => 'user',
264 Revision::DELETED_RESTRICTED => 'restricted',
266 foreach ( $fields as $bit => $key ) {
267 $params[':assoc:old'][$key] = (bool)( $old & $bit );
268 $params[':assoc:new'][$key] = (bool)( $new & $bit );
272 return $params;
275 public function formatParametersForApi() {
276 $ret = parent::formatParametersForApi();
277 if ( isset( $ret['ids'] ) ) {
278 ApiResult::setIndexedTagName( $ret['ids'], 'id' );
280 return $ret;