MediaWiki  REL1_31
ProtectLogFormatter.php
Go to the documentation of this file.
1 <?php
31  public function getPreloadTitles() {
32  $subtype = $this->entry->getSubtype();
33  if ( $subtype === 'move_prot' ) {
34  $params = $this->extractParameters();
35  return [ Title::newFromText( $params[3] ) ];
36  }
37  return [];
38  }
39 
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';
46  }
47 
48  return $key;
49  }
50 
51  protected function getMessageParameters() {
52  $params = parent::getMessageParameters();
53 
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] = '';
65  }
66  // Cascading flag
67  if ( isset( $params[4] ) ) {
68  // handled in getMessageKey
69  unset( $params[4] );
70  }
71  } elseif ( $subtype === 'move_prot' ) {
72  $oldname = $this->makePageLink( Title::newFromText( $params[3] ), [ 'redirect' => 'no' ] );
73  $params[3] = Message::rawParam( $oldname );
74  }
75 
76  return $params;
77  }
78 
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
84  ) {
85  return '';
86  }
87 
88  // Show history link for all changes after the protection
89  $title = $this->entry->getTarget();
90  $links = [
91  $linkRenderer->makeLink( $title,
92  $this->msg( 'hist' )->text(),
93  [],
94  [
95  'action' => 'history',
96  'offset' => $this->entry->getTimestamp(),
97  ]
98  )
99  ];
100 
101  // Show change protection link
102  if ( $this->context->getUser()->isAllowed( 'protect' ) ) {
103  $links[] = $linkRenderer->makeKnownLink(
104  $title,
105  $this->msg( 'protect_change' )->text(),
106  [],
107  [ 'action' => 'protect' ]
108  );
109  }
110 
111  return $this->msg( 'parentheses' )->rawParams(
112  $this->context->getLanguage()->pipeList( $links ) )->escaped();
113  }
114 
115  protected function getParametersForApi() {
117  $subtype = $this->entry->getSubtype();
119 
120  $map = [];
121  if ( $subtype === 'protect' || $subtype === 'modify' ) {
122  $map = [
123  '4::description',
124  '5:bool:cascade',
125  'details' => ':array:details',
126  ];
127  } elseif ( $subtype === 'move_prot' ) {
128  $map = [
129  '4:title:oldtitle',
130  '4::oldtitle' => '4:title:oldtitle',
131  ];
132  }
133  foreach ( $map as $index => $key ) {
134  if ( isset( $params[$index] ) ) {
135  $params[$key] = $params[$index];
136  unset( $params[$index] );
137  }
138  }
139 
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';
143  }
144 
145  return $params;
146  }
147 
148  public function formatParametersForApi() {
150 
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' );
156  }
157  }
158  }
159 
160  return $ret;
161  }
162 
169  public function createProtectDescription( array $details ) {
170  $protectDescription = '';
171 
172  foreach ( $details as $param ) {
173  $expiryText = $this->formatExpiry( $param['expiry'] );
174 
175  // Messages: restriction-edit, restriction-move, restriction-create,
176  // restriction-upload
177  $action = $this->context->msg( 'restriction-' . $param['type'] )->escaped();
178 
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();
185  } else {
186  $restrictions = $message->escaped();
187  }
188 
189  if ( $protectDescription !== '' ) {
190  $protectDescription .= $this->context->msg( 'word-separator' )->escaped();
191  }
192 
193  $protectDescription .= $this->context->msg( 'protect-summary-desc' )
194  ->params( $action, $restrictions, $expiryText )->escaped();
195  }
196 
197  return $protectDescription;
198  }
199 
200  private function formatExpiry( $expiry ) {
201  if ( wfIsInfinity( $expiry ) ) {
202  return $this->context->msg( 'protect-expiry-indefinite' )->text();
203  }
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 )
211  )->text();
212  }
213 
214 }
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:247
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:273
ProtectLogFormatter\createProtectDescription
createProtectDescription(array $details)
Create the protect description to show in the log formatter.
Definition: ProtectLogFormatter.php:169
array
the array() calling protocol came about after MediaWiki 1.4rc1.
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
LogEntry\getParameters
getParameters()
Get the extra parameters stored for this message.
text
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
ProtectLogFormatter\formatParametersForApi
formatParametersForApi()
Format parameters for API output.
Definition: ProtectLogFormatter.php:148
LogFormatter\$entry
LogEntryBase $entry
Definition: LogFormatter.php:83
ProtectLogFormatter\formatExpiry
formatExpiry( $expiry)
Definition: ProtectLogFormatter.php:200
$ret
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:2005
$params
$params
Definition: styleTest.css.php:40
ProtectLogFormatter\getPreloadTitles
getPreloadTitles()
Definition: ProtectLogFormatter.php:31
ProtectLogFormatter
This class formats protect log entries.
Definition: ProtectLogFormatter.php:30
php
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
LogFormatter\msg
msg( $key)
Shortcut for wfMessage which honors local context.
Definition: LogFormatter.php:735
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:964
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:95
LogPage\DELETED_ACTION
const DELETED_ACTION
Definition: LogPage.php:32
Message\rawParam
static rawParam( $raw)
Definition: Message.php:1017
ProtectLogFormatter\getMessageKey
getMessageKey()
Returns a key to be used for formatting the action sentence.
Definition: ProtectLogFormatter.php:40
wfIsInfinity
wfIsInfinity( $str)
Determine input string is represents as infinity.
Definition: GlobalFunctions.php:3321
LogEntry\getSubtype
getSubtype()
The log subtype.
LogFormatter
Implements the default log formatting.
Definition: LogFormatter.php:38
ProtectLogFormatter\getMessageParameters
getMessageParameters()
Formats parameters intented for action message from array of all parameters.
Definition: ProtectLogFormatter.php:51
LogFormatter\$linkRenderer
LinkRenderer null $linkRenderer
Definition: LogFormatter.php:109
as
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
Definition: distributors.txt:22
LogFormatter\getLinkRenderer
getLinkRenderer()
Definition: LogFormatter.php:136
ProtectLogFormatter\getActionLinks
getActionLinks()
Returns extra links that comes after the action text, like "revert", etc.
Definition: ProtectLogFormatter.php:79
LogFormatter\extractParameters
extractParameters()
Extracts the optional extra parameters for use in action messages.
Definition: LogFormatter.php:494
LogFormatter\makePageLink
makePageLink(Title $title=null, $parameters=[], $html=null)
Helper to make a link to the page, taking the plaintext value in consideration.
Definition: LogFormatter.php:641
$wgContLang
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 content language as $wgContLang
Definition: design.txt:57
ProtectLogFormatter\getParametersForApi
getParametersForApi()
Get the array of parameters, converted from legacy format if necessary.
Definition: ProtectLogFormatter.php:115