MediaWiki REL1_30
ProtectLogFormatter.php
Go to the documentation of this file.
1<?php
25
32 public function getPreloadTitles() {
33 $subtype = $this->entry->getSubtype();
34 if ( $subtype === 'move_prot' ) {
35 $params = $this->extractParameters();
36 return [ Title::newFromText( $params[3] ) ];
37 }
38 return [];
39 }
40
41 protected function getMessageKey() {
42 $key = parent::getMessageKey();
43 $params = $this->extractParameters();
44 if ( isset( $params[4] ) && $params[4] ) {
45 // Messages: logentry-protect-protect-cascade, logentry-protect-modify-cascade
46 $key .= '-cascade';
47 }
48
49 return $key;
50 }
51
52 protected function getMessageParameters() {
53 $params = parent::getMessageParameters();
54
55 $subtype = $this->entry->getSubtype();
56 if ( $subtype === 'protect' || $subtype === 'modify' ) {
57 $rawParams = $this->entry->getParameters();
58 if ( isset( $rawParams['details'] ) ) {
59 $params[3] = $this->createProtectDescription( $rawParams['details'] );
60 } elseif ( isset( $params[3] ) ) {
61 // Old way of Restrictions and expiries
62 $params[3] = $this->context->getLanguage()->getDirMark() . $params[3];
63 } else {
64 // Very old way (nothing set)
65 $params[3] = '';
66 }
67 // Cascading flag
68 if ( isset( $params[4] ) ) {
69 // handled in getMessageKey
70 unset( $params[4] );
71 }
72 } elseif ( $subtype === 'move_prot' ) {
73 $oldname = $this->makePageLink( Title::newFromText( $params[3] ), [ 'redirect' => 'no' ] );
74 $params[3] = Message::rawParam( $oldname );
75 }
76
77 return $params;
78 }
79
80 public function getActionLinks() {
81 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
82 $subtype = $this->entry->getSubtype();
83 if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) // Action is hidden
84 || $subtype === 'move_prot' // the move log entry has the right action link
85 ) {
86 return '';
87 }
88
89 // Show history link for all changes after the protection
90 $title = $this->entry->getTarget();
91 $links = [
92 $linkRenderer->makeLink( $title,
93 $this->msg( 'hist' )->text(),
94 [],
95 [
96 'action' => 'history',
97 'offset' => $this->entry->getTimestamp(),
98 ]
99 )
100 ];
101
102 // Show change protection link
103 if ( $this->context->getUser()->isAllowed( 'protect' ) ) {
104 $links[] = $linkRenderer->makeKnownLink(
105 $title,
106 $this->msg( 'protect_change' )->text(),
107 [],
108 [ 'action' => 'protect' ]
109 );
110 }
111
112 return $this->msg( 'parentheses' )->rawParams(
113 $this->context->getLanguage()->pipeList( $links ) )->escaped();
114 }
115
116 protected function getParametersForApi() {
118 $subtype = $this->entry->getSubtype();
120
121 $map = [];
122 if ( $subtype === 'protect' || $subtype === 'modify' ) {
123 $map = [
124 '4::description',
125 '5:bool:cascade',
126 'details' => ':array:details',
127 ];
128 } elseif ( $subtype === 'move_prot' ) {
129 $map = [
130 '4:title:oldtitle',
131 '4::oldtitle' => '4:title:oldtitle',
132 ];
133 }
134 foreach ( $map as $index => $key ) {
135 if ( isset( $params[$index] ) ) {
136 $params[$key] = $params[$index];
137 unset( $params[$index] );
138 }
139 }
140
141 // Change string to explicit boolean
142 if ( isset( $params['5:bool:cascade'] ) && is_string( $params['5:bool:cascade'] ) ) {
143 $params['5:bool:cascade'] = $params['5:bool:cascade'] === 'cascade';
144 }
145
146 return $params;
147 }
148
149 public function formatParametersForApi() {
150 global $wgContLang;
151
152 $ret = parent::formatParametersForApi();
153 if ( isset( $ret['details'] ) && is_array( $ret['details'] ) ) {
154 foreach ( $ret['details'] as &$detail ) {
155 if ( isset( $detail['expiry'] ) ) {
156 $detail['expiry'] = $wgContLang->formatExpiry( $detail['expiry'], TS_ISO_8601, 'infinite' );
157 }
158 }
159 }
160
161 return $ret;
162 }
163
170 public function createProtectDescription( array $details ) {
171 $protectDescription = '';
172
173 foreach ( $details as $param ) {
174 $expiryText = $this->formatExpiry( $param['expiry'] );
175
176 // Messages: restriction-edit, restriction-move, restriction-create,
177 // restriction-upload
178 $action = $this->context->msg( 'restriction-' . $param['type'] )->escaped();
179
180 $protectionLevel = $param['level'];
181 // Messages: protect-level-autoconfirmed, protect-level-sysop
182 $message = $this->context->msg( 'protect-level-' . $protectionLevel );
183 if ( $message->isDisabled() ) {
184 // Require "$1" permission
185 $restrictions = $this->context->msg( "protect-fallback", $protectionLevel )->parse();
186 } else {
187 $restrictions = $message->escaped();
188 }
189
190 if ( $protectDescription !== '' ) {
191 $protectDescription .= $this->context->msg( 'word-separator' )->escaped();
192 }
193
194 $protectDescription .= $this->context->msg( 'protect-summary-desc' )
195 ->params( $action, $restrictions, $expiryText )->escaped();
196 }
197
198 return $protectDescription;
199 }
200
201 private function formatExpiry( $expiry ) {
202 if ( wfIsInfinity( $expiry ) ) {
203 return $this->context->msg( 'protect-expiry-indefinite' )->text();
204 }
205 $lang = $this->context->getLanguage();
206 $user = $this->context->getUser();
207 return $this->context->msg(
208 'protect-expiring-local',
209 $lang->userTimeAndDate( $expiry, $user ),
210 $lang->userDate( $expiry, $user ),
211 $lang->userTime( $expiry, $user )
212 )->text();
213 }
214
215}
wfIsInfinity( $str)
Determine input string is represents as infinity.
Implements the default log formatting.
LogEntryBase $entry
msg( $key)
Shortcut for wfMessage which honors local context.
LinkRenderer null $linkRenderer
makePageLink(Title $title=null, $parameters=[], $html=null)
Helper to make a link to the page, taking the plaintext value in consideration.
extractParameters()
Extracts the optional extra parameters for use in action messages.
const DELETED_ACTION
Definition LogPage.php:32
makeKnownLink(LinkTarget $target, $text=null, array $extraAttribs=[], array $query=[])
makeLink(LinkTarget $target, $text=null, array $extraAttribs=[], array $query=[])
MediaWikiServices is the service locator for the application scope of MediaWiki.
This class formats protect log entries.
getMessageParameters()
Formats parameters intented for action message from array of all parameters.
getActionLinks()
Returns extra links that comes after the action text, like "revert", etc.
createProtectDescription(array $details)
Create the protect description to show in the log formatter.
getParametersForApi()
Get the array of parameters, converted from legacy format if necessary.
getMessageKey()
Returns a key to be used for formatting the action sentence.
formatParametersForApi()
Format parameters for API output.
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
Definition design.txt:57
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition design.txt:18
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition hooks.txt:1975
getParameters()
Get the extra parameters stored for this message.
getSubtype()
The log subtype.
$params
if(!isset( $args[0])) $lang