Merge "Whitelist the <wbr> element."
[mediawiki.git] / includes / logging / DeleteLogFormatter.php
blob44334baf5bf276ff8c04e238cb2e7abe03579494
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";
39 return $key;
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.
52 if (
53 ( $subtype === 'event' && count( $params ) === 6 ) ||
54 ( $subtype === 'revision' && isset( $params[3] ) && ( $params[3] === 'revision' || $params[3] === 'oldimage' ) )
55 ) {
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 );
61 $changes = array();
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;
78 } else {
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 );
90 return (int) $field;
91 } else {
92 return (int) $string;
96 public function getActionLinks() {
97 $user = $this->context->getUser();
98 if ( !$user->isAllowed( 'deletedhistory' ) || $this->entry->isDeleted( LogPage::DELETED_ACTION ) ) {
99 return '';
102 switch ( $this->entry->getSubtype() ) {
103 case 'delete': // Show undelete link
104 if ( $user->isAllowed( 'undelete' ) ) {
105 $message = 'undeletelink';
106 } else {
107 $message = 'undeleteviewlink';
109 $revert = Linker::linkKnown(
110 SpecialPage::getTitleFor( 'Undelete' ),
111 $this->msg( $message )->escaped(),
112 array(),
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] ) ) {
120 return '';
123 // Different revision types use different URL params...
124 $key = $params[3];
125 // This is a CSV of the IDs
126 $ids = explode( ',', $params[4] );
128 $links = array();
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(),
137 array(),
138 array(
139 'diff' => intval( $ids[0] ),
140 'unhide' => 1
143 // Deleted revision diffs...
144 } elseif ( $key == 'artimestamp' || $key == 'archive' ) {
145 $links[] = Linker::linkKnown(
146 SpecialPage::getTitleFor( 'Undelete' ),
147 $this->msg( 'diff' )->escaped(),
148 array(),
149 array(
150 'target' => $this->entry->getTarget()->getPrefixedDBkey(),
151 'diff' => 'prev',
152 'timestamp' => $ids[0]
158 // View/modify link...
159 $links[] = Linker::linkKnown(
160 SpecialPage::getTitleFor( 'Revisiondelete' ),
161 $this->msg( 'revdel-restore' )->escaped(),
162 array(),
163 array(
164 'target' => $this->entry->getTarget()->getPrefixedText(),
165 'type' => $key,
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] ) ) {
176 return '';
178 // This is a CSV of the IDs
179 $query = $params[3];
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(),
184 array(),
185 array(
186 'target' => $this->entry->getTarget()->getPrefixedText(),
187 'type' => 'logging',
188 'ids' => $query
191 return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
192 default:
193 return '';