MediaWiki  1.30.0
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() {
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 }
$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:244
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:268
ProtectLogFormatter\createProtectDescription
createProtectDescription(array $details)
Create the protect description to show in the log formatter.
Definition: ProtectLogFormatter.php:170
$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:12
ProtectLogFormatter\formatParametersForApi
formatParametersForApi()
Format parameters for API output.
Definition: ProtectLogFormatter.php:149
LogFormatter\$entry
LogEntryBase $entry
Definition: LogFormatter.php:83
ProtectLogFormatter\formatExpiry
formatExpiry( $expiry)
Definition: ProtectLogFormatter.php:201
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
$params
$params
Definition: styleTest.css.php:40
ProtectLogFormatter\getPreloadTitles
getPreloadTitles()
Definition: ProtectLogFormatter.php:32
ProtectLogFormatter
This class formats protect log entries.
Definition: ProtectLogFormatter.php:31
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:35
LogFormatter\msg
msg( $key)
Shortcut for wfMessage which honors local context.
Definition: LogFormatter.php:733
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:932
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
LogPage\DELETED_ACTION
const DELETED_ACTION
Definition: LogPage.php:32
ProtectLogFormatter\getMessageKey
getMessageKey()
Returns a key to be used for formatting the action sentence.
Definition: ProtectLogFormatter.php:41
wfIsInfinity
wfIsInfinity( $str)
Determine input string is represents as infinity.
Definition: GlobalFunctions.php:3377
$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:1965
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:52
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:9
MediaWikiServices
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 MediaWikiServices
Definition: injection.txt:23
ProtectLogFormatter\getActionLinks
getActionLinks()
Returns extra links that comes after the action text, like "revert", etc.
Definition: ProtectLogFormatter.php:80
LogFormatter\extractParameters
extractParameters()
Extracts the optional extra parameters for use in action messages.
Definition: LogFormatter.php:498
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:646
array
the array() calling protocol came about after MediaWiki 1.4rc1.
$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:56
ProtectLogFormatter\getParametersForApi
getParametersForApi()
Get the array of parameters, converted from legacy format if necessary.
Definition: ProtectLogFormatter.php:116