Expose $wgMaxArticleSize in siteinfo query api
[mediawiki.git] / includes / logging / ProtectLogFormatter.php
blob045829719060797bb2e67662c472491dc6613874
1 <?php
2 /**
3 * Formatter for protect 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 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
22 * @since 1.26
25 /**
26 * This class formats protect log entries.
28 * @since 1.26
30 class ProtectLogFormatter extends LogFormatter {
31 public function getPreloadTitles() {
32 $subtype = $this->entry->getSubtype();
33 if ( $subtype === 'move_prot' ) {
34 $params = $this->extractParameters();
35 return [ Title::newFromText( $params[3] ) ];
37 return [];
40 protected function getMessageKey() {
41 $key = parent::getMessageKey();
42 $params = $this->extractParameters();
43 if ( isset( $params[4] ) && $params[4] ) {
44 // Messages: logentry-protect-protect-cascade, logentry-protect-modify-cascade
45 $key .= '-cascade';
48 return $key;
51 protected function getMessageParameters() {
52 $params = parent::getMessageParameters();
54 $subtype = $this->entry->getSubtype();
55 if ( $subtype === 'protect' || $subtype === 'modify' ) {
56 $rawParams = $this->entry->getParameters();
57 if ( isset( $rawParams['details'] ) ) {
58 $params[3] = $this->createProtectDescription( $rawParams['details'] );
59 } elseif ( isset( $params[3] ) ) {
60 // Old way of Restrictions and expiries
61 $params[3] = $this->context->getLanguage()->getDirMark() . $params[3];
62 } else {
63 // Very old way (nothing set)
64 $params[3] = '';
66 // Cascading flag
67 if ( isset( $params[4] ) ) {
68 // handled in getMessageKey
69 unset( $params[4] );
71 } elseif ( $subtype === 'move_prot' ) {
72 $oldname = $this->makePageLink( Title::newFromText( $params[3] ), [ 'redirect' => 'no' ] );
73 $params[3] = Message::rawParam( $oldname );
76 return $params;
79 public function getActionLinks() {
80 $subtype = $this->entry->getSubtype();
81 if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) // Action is hidden
82 || $subtype === 'move_prot' // the move log entry has the right action link
83 ) {
84 return '';
87 // Show history link for all changes after the protection
88 $title = $this->entry->getTarget();
89 $links = [
90 Linker::link( $title,
91 $this->msg( 'hist' )->escaped(),
92 [],
94 'action' => 'history',
95 'offset' => $this->entry->getTimestamp(),
100 // Show change protection link
101 if ( $this->context->getUser()->isAllowed( 'protect' ) ) {
102 $links[] = Linker::linkKnown(
103 $title,
104 $this->msg( 'protect_change' )->escaped(),
106 [ 'action' => 'protect' ]
110 return $this->msg( 'parentheses' )->rawParams(
111 $this->context->getLanguage()->pipeList( $links ) )->escaped();
114 protected function getParametersForApi() {
115 $entry = $this->entry;
116 $subtype = $this->entry->getSubtype();
117 $params = $entry->getParameters();
119 $map = [];
120 if ( $subtype === 'protect' || $subtype === 'modify' ) {
121 $map = [
122 '4::description',
123 '5:bool:cascade',
124 'details' => ':array:details',
126 } elseif ( $subtype === 'move_prot' ) {
127 $map = [
128 '4:title:oldtitle',
129 '4::oldtitle' => '4:title:oldtitle',
132 foreach ( $map as $index => $key ) {
133 if ( isset( $params[$index] ) ) {
134 $params[$key] = $params[$index];
135 unset( $params[$index] );
139 // Change string to explicit boolean
140 if ( isset( $params['5:bool:cascade'] ) && is_string( $params['5:bool:cascade'] ) ) {
141 $params['5:bool:cascade'] = $params['5:bool:cascade'] === 'cascade';
144 return $params;
147 public function formatParametersForApi() {
148 global $wgContLang;
150 $ret = parent::formatParametersForApi();
151 if ( isset( $ret['details'] ) && is_array( $ret['details'] ) ) {
152 foreach ( $ret['details'] as &$detail ) {
153 if ( isset( $detail['expiry'] ) ) {
154 $detail['expiry'] = $wgContLang->formatExpiry( $detail['expiry'], TS_ISO_8601, 'infinite' );
159 return $ret;
163 * Create the protect description to show in the log formatter
165 * @param array $details
166 * @return string
168 public function createProtectDescription( array $details ) {
169 $protectDescription = '';
171 foreach ( $details as $param ) {
172 $expiryText = $this->formatExpiry( $param['expiry'] );
174 // Messages: restriction-edit, restriction-move, restriction-create,
175 // restriction-upload
176 $action = $this->context->msg( 'restriction-' . $param['type'] )->escaped();
178 $protectionLevel = $param['level'];
179 // Messages: protect-level-autoconfirmed, protect-level-sysop
180 $message = $this->context->msg( 'protect-level-' . $protectionLevel );
181 if ( $message->isDisabled() ) {
182 // Require "$1" permission
183 $restrictions = $this->context->msg( "protect-fallback", $protectionLevel )->parse();
184 } else {
185 $restrictions = $message->escaped();
188 if ( $protectDescription !== '' ) {
189 $protectDescription .= $this->context->msg( 'word-separator' )->escaped();
192 $protectDescription .= $this->context->msg( 'protect-summary-desc' )
193 ->params( $action, $restrictions, $expiryText )->escaped();
196 return $protectDescription;
199 private function formatExpiry( $expiry ) {
200 if ( wfIsInfinity( $expiry ) ) {
201 return $this->context->msg( 'protect-expiry-indefinite' )->text();
203 $lang = $this->context->getLanguage();
204 $user = $this->context->getUser();
205 return $this->context->msg(
206 'protect-expiring-local',
207 $lang->userTimeAndDate( $expiry, $user ),
208 $lang->userDate( $expiry, $user ),
209 $lang->userTime( $expiry, $user )
210 )->text();