MediaWiki REL1_33
ProtectLogFormatter.php
Go to the documentation of this file.
1<?php
26
33 public function getPreloadTitles() {
34 $subtype = $this->entry->getSubtype();
35 if ( $subtype === 'move_prot' ) {
36 $params = $this->extractParameters();
37 return [ Title::newFromText( $params[3] ) ];
38 }
39 return [];
40 }
41
42 protected function getMessageKey() {
43 $key = parent::getMessageKey();
44 $params = $this->extractParameters();
45 if ( isset( $params[4] ) && $params[4] ) {
46 // Messages: logentry-protect-protect-cascade, logentry-protect-modify-cascade
47 $key .= '-cascade';
48 }
49
50 return $key;
51 }
52
53 protected function getMessageParameters() {
54 $params = parent::getMessageParameters();
55
56 $subtype = $this->entry->getSubtype();
57 if ( $subtype === 'protect' || $subtype === 'modify' ) {
58 $rawParams = $this->entry->getParameters();
59 if ( isset( $rawParams['details'] ) ) {
60 $params[3] = $this->createProtectDescription( $rawParams['details'] );
61 } elseif ( isset( $params[3] ) ) {
62 // Old way of Restrictions and expiries
63 $params[3] = $this->context->getLanguage()->getDirMark() . $params[3];
64 } else {
65 // Very old way (nothing set)
66 $params[3] = '';
67 }
68 // Cascading flag
69 if ( isset( $params[4] ) ) {
70 // handled in getMessageKey
71 unset( $params[4] );
72 }
73 } elseif ( $subtype === 'move_prot' ) {
74 $oldname = $this->makePageLink( Title::newFromText( $params[3] ), [ 'redirect' => 'no' ] );
75 $params[3] = Message::rawParam( $oldname );
76 }
77
78 return $params;
79 }
80
81 public function getActionLinks() {
83 $subtype = $this->entry->getSubtype();
84 if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) // Action is hidden
85 || $subtype === 'move_prot' // the move log entry has the right action link
86 ) {
87 return '';
88 }
89
90 // Show history link for all changes after the protection
91 $title = $this->entry->getTarget();
92 $links = [
94 $this->msg( 'hist' )->text(),
95 [],
96 [
97 'action' => 'history',
98 'offset' => $this->entry->getTimestamp(),
99 ]
100 )
101 ];
102
103 // Show change protection link
104 if ( $this->context->getUser()->isAllowed( 'protect' ) ) {
105 $links[] = $linkRenderer->makeKnownLink(
106 $title,
107 $this->msg( 'protect_change' )->text(),
108 [],
109 [ 'action' => 'protect' ]
110 );
111 }
112
113 return $this->msg( 'parentheses' )->rawParams(
114 $this->context->getLanguage()->pipeList( $links ) )->escaped();
115 }
116
117 protected function getParametersForApi() {
119 $subtype = $this->entry->getSubtype();
121
122 $map = [];
123 if ( $subtype === 'protect' || $subtype === 'modify' ) {
124 $map = [
125 '4::description',
126 '5:bool:cascade',
127 'details' => ':array:details',
128 ];
129 } elseif ( $subtype === 'move_prot' ) {
130 $map = [
131 '4:title:oldtitle',
132 '4::oldtitle' => '4:title:oldtitle',
133 ];
134 }
135 foreach ( $map as $index => $key ) {
136 if ( isset( $params[$index] ) ) {
137 $params[$key] = $params[$index];
138 unset( $params[$index] );
139 }
140 }
141
142 // Change string to explicit boolean
143 if ( isset( $params['5:bool:cascade'] ) && is_string( $params['5:bool:cascade'] ) ) {
144 $params['5:bool:cascade'] = $params['5:bool:cascade'] === 'cascade';
145 }
146
147 return $params;
148 }
149
150 public function formatParametersForApi() {
151 $ret = parent::formatParametersForApi();
152 if ( isset( $ret['details'] ) && is_array( $ret['details'] ) ) {
153 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
154 foreach ( $ret['details'] as &$detail ) {
155 if ( isset( $detail['expiry'] ) ) {
156 $detail['expiry'] = $contLang->
157 formatExpiry( $detail['expiry'], TS_ISO_8601, 'infinite' );
158 }
159 }
160 }
161
162 return $ret;
163 }
164
171 public function createProtectDescription( array $details ) {
172 $protectDescription = '';
173
174 foreach ( $details as $param ) {
175 $expiryText = $this->formatExpiry( $param['expiry'] );
176
177 // Messages: restriction-edit, restriction-move, restriction-create,
178 // restriction-upload
179 $action = $this->context->msg( 'restriction-' . $param['type'] )->escaped();
180
181 $protectionLevel = $param['level'];
182 // Messages: protect-level-autoconfirmed, protect-level-sysop
183 $message = $this->context->msg( 'protect-level-' . $protectionLevel );
184 if ( $message->isDisabled() ) {
185 // Require "$1" permission
186 $restrictions = $this->context->msg( "protect-fallback", $protectionLevel )->parse();
187 } else {
188 $restrictions = $message->escaped();
189 }
190
191 if ( $protectDescription !== '' ) {
192 $protectDescription .= $this->context->msg( 'word-separator' )->escaped();
193 }
194
195 $protectDescription .= $this->context->msg( 'protect-summary-desc' )
196 ->params( $action, $restrictions, $expiryText )->escaped();
197 }
198
199 return $protectDescription;
200 }
201
202 private function formatExpiry( $expiry ) {
203 if ( wfIsInfinity( $expiry ) ) {
204 return $this->context->msg( 'protect-expiry-indefinite' )->text();
205 }
206 $lang = $this->context->getLanguage();
207 $user = $this->context->getUser();
208 return $this->context->msg(
209 'protect-expiring-local',
210 $lang->userTimeAndDate( $expiry, $user ),
211 $lang->userDate( $expiry, $user ),
212 $lang->userTime( $expiry, $user )
213 )->text();
214 }
215
216}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
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:34
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 document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:955
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:2003
return true to allow those checks to and false if checking is done & $user
Definition hooks.txt:1510
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
getParameters()
Get the extra parameters stored for this message.
getSubtype()
The log subtype.
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
$params
if(!isset( $args[0])) $lang