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
21 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
26 * This class formats protect log entries.
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] ) ];
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
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];
63 // Very old way (nothing set)
67 if ( isset( $params[4] ) ) {
68 // handled in getMessageKey
71 } elseif ( $subtype === 'move_prot' ) {
72 $oldname = $this->makePageLink( Title
::newFromText( $params[3] ), [ 'redirect' => 'no' ] );
73 $params[3] = Message
::rawParam( $oldname );
79 public function getActionLinks() {
80 $linkRenderer = $this->getLinkRenderer();
81 $subtype = $this->entry
->getSubtype();
82 if ( $this->entry
->isDeleted( LogPage
::DELETED_ACTION
) // Action is hidden
83 ||
$subtype === 'move_prot' // the move log entry has the right action link
88 // Show history link for all changes after the protection
89 $title = $this->entry
->getTarget();
91 $linkRenderer->makeLink( $title,
92 $this->msg( 'hist' )->text(),
95 'action' => 'history',
96 'offset' => $this->entry
->getTimestamp(),
101 // Show change protection link
102 if ( $this->context
->getUser()->isAllowed( 'protect' ) ) {
103 $links[] = $linkRenderer->makeKnownLink(
105 $this->msg( 'protect_change' )->text(),
107 [ 'action' => 'protect' ]
111 return $this->msg( 'parentheses' )->rawParams(
112 $this->context
->getLanguage()->pipeList( $links ) )->escaped();
115 protected function getParametersForApi() {
116 $entry = $this->entry
;
117 $subtype = $this->entry
->getSubtype();
118 $params = $entry->getParameters();
121 if ( $subtype === 'protect' ||
$subtype === 'modify' ) {
125 'details' => ':array:details',
127 } elseif ( $subtype === 'move_prot' ) {
130 '4::oldtitle' => '4:title:oldtitle',
133 foreach ( $map as $index => $key ) {
134 if ( isset( $params[$index] ) ) {
135 $params[$key] = $params[$index];
136 unset( $params[$index] );
140 // Change string to explicit boolean
141 if ( isset( $params['5:bool:cascade'] ) && is_string( $params['5:bool:cascade'] ) ) {
142 $params['5:bool:cascade'] = $params['5:bool:cascade'] === 'cascade';
148 public function formatParametersForApi() {
151 $ret = parent
::formatParametersForApi();
152 if ( isset( $ret['details'] ) && is_array( $ret['details'] ) ) {
153 foreach ( $ret['details'] as &$detail ) {
154 if ( isset( $detail['expiry'] ) ) {
155 $detail['expiry'] = $wgContLang->formatExpiry( $detail['expiry'], TS_ISO_8601
, 'infinite' );
164 * Create the protect description to show in the log formatter
166 * @param array $details
169 public function createProtectDescription( array $details ) {
170 $protectDescription = '';
172 foreach ( $details as $param ) {
173 $expiryText = $this->formatExpiry( $param['expiry'] );
175 // Messages: restriction-edit, restriction-move, restriction-create,
176 // restriction-upload
177 $action = $this->context
->msg( 'restriction-' . $param['type'] )->escaped();
179 $protectionLevel = $param['level'];
180 // Messages: protect-level-autoconfirmed, protect-level-sysop
181 $message = $this->context
->msg( 'protect-level-' . $protectionLevel );
182 if ( $message->isDisabled() ) {
183 // Require "$1" permission
184 $restrictions = $this->context
->msg( "protect-fallback", $protectionLevel )->parse();
186 $restrictions = $message->escaped();
189 if ( $protectDescription !== '' ) {
190 $protectDescription .= $this->context
->msg( 'word-separator' )->escaped();
193 $protectDescription .= $this->context
->msg( 'protect-summary-desc' )
194 ->params( $action, $restrictions, $expiryText )->escaped();
197 return $protectDescription;
200 private function formatExpiry( $expiry ) {
201 if ( wfIsInfinity( $expiry ) ) {
202 return $this->context
->msg( 'protect-expiry-indefinite' )->text();
204 $lang = $this->context
->getLanguage();
205 $user = $this->context
->getUser();
206 return $this->context
->msg(
207 'protect-expiring-local',
208 $lang->userTimeAndDate( $expiry, $user ),
209 $lang->userDate( $expiry, $user ),
210 $lang->userTime( $expiry, $user )