MediaWiki  master
RightsLogFormatter.php
Go to the documentation of this file.
1 <?php
27 
34  protected function makePageLink( Title $title = null, $parameters = [], $html = null ) {
36 
37  if ( !$this->plaintext ) {
38  $text = MediaWikiServices::getInstance()->getContentLanguage()->
39  ucfirst( $title->getDBkey() );
40  $parts = explode( $wgUserrightsInterwikiDelimiter, $text, 2 );
41 
42  if ( count( $parts ) === 2 ) {
43  $titleLink = WikiMap::foreignUserLink(
44  $parts[1],
45  $parts[0],
46  htmlspecialchars(
47  strtr( $parts[0], '_', ' ' ) .
48  $wgUserrightsInterwikiDelimiter .
49  $parts[1]
50  )
51  );
52 
53  if ( $titleLink !== false ) {
54  return $titleLink;
55  }
56  }
57  }
58 
59  return parent::makePageLink( $title, $parameters, $title ? $title->getText() : null );
60  }
61 
62  protected function getMessageKey() {
63  $key = parent::getMessageKey();
64  $params = $this->getMessageParameters();
65  if ( !isset( $params[3] ) && !isset( $params[4] ) ) {
66  // Messages: logentry-rights-rights-legacy
67  $key .= '-legacy';
68  }
69 
70  return $key;
71  }
72 
73  protected function getMessageParameters() {
74  $params = parent::getMessageParameters();
75 
76  // Really old entries that lack old/new groups
77  if ( !isset( $params[3] ) && !isset( $params[4] ) ) {
78  return $params;
79  }
80 
81  $oldGroups = $this->makeGroupArray( $params[3] );
82  $newGroups = $this->makeGroupArray( $params[4] );
83 
84  $userName = $this->entry->getTarget()->getText();
85  if ( !$this->plaintext && count( $oldGroups ) ) {
86  foreach ( $oldGroups as &$group ) {
87  $group = UserGroupMembership::getGroupMemberName( $group, $userName );
88  }
89  }
90  if ( !$this->plaintext && count( $newGroups ) ) {
91  foreach ( $newGroups as &$group ) {
92  $group = UserGroupMembership::getGroupMemberName( $group, $userName );
93  }
94  }
95 
96  // fetch the metadata about each group membership
97  $allParams = $this->entry->getParameters();
98 
99  if ( count( $oldGroups ) ) {
100  $params[3] = [ 'raw' => $this->formatRightsList( $oldGroups,
101  $allParams['oldmetadata'] ?? [] ) ];
102  } else {
103  $params[3] = $this->msg( 'rightsnone' )->text();
104  }
105  if ( count( $newGroups ) ) {
106  // Array_values is used here because of T44211
107  // see use of array_unique in UserrightsPage::doSaveUserGroups on $newGroups.
108  $params[4] = [ 'raw' => $this->formatRightsList( array_values( $newGroups ),
109  $allParams['newmetadata'] ?? [] ) ];
110  } else {
111  $params[4] = $this->msg( 'rightsnone' )->text();
112  }
113 
114  $params[5] = $userName;
115 
116  return $params;
117  }
118 
119  protected function formatRightsList( $groups, $serializedUGMs = [] ) {
120  $uiLanguage = $this->context->getLanguage();
121  $uiUser = $this->context->getUser();
122  // separate arrays of temporary and permanent memberships
123  $tempList = $permList = [];
124 
125  reset( $groups );
126  reset( $serializedUGMs );
127  while ( current( $groups ) ) {
128  $group = current( $groups );
129 
130  if ( current( $serializedUGMs ) &&
131  isset( current( $serializedUGMs )['expiry'] ) &&
132  current( $serializedUGMs )['expiry']
133  ) {
134  // there is an expiry date; format the group and expiry into a friendly string
135  $expiry = current( $serializedUGMs )['expiry'];
136  $expiryFormatted = $uiLanguage->userTimeAndDate( $expiry, $uiUser );
137  $expiryFormattedD = $uiLanguage->userDate( $expiry, $uiUser );
138  $expiryFormattedT = $uiLanguage->userTime( $expiry, $uiUser );
139  $tempList[] = $this->msg( 'rightslogentry-temporary-group' )->params( $group,
140  $expiryFormatted, $expiryFormattedD, $expiryFormattedT )->parse();
141  } else {
142  // the right does not expire; just insert the group name
143  $permList[] = $group;
144  }
145 
146  next( $groups );
147  next( $serializedUGMs );
148  }
149 
150  // place all temporary memberships first, to avoid the ambiguity of
151  // "adinistrator, bureaucrat and importer (temporary, until X time)"
152  return $uiLanguage->listToText( array_merge( $tempList, $permList ) );
153  }
154 
155  protected function getParametersForApi() {
158 
159  static $map = [
160  '4:array:oldgroups',
161  '5:array:newgroups',
162  '4::oldgroups' => '4:array:oldgroups',
163  '5::newgroups' => '5:array:newgroups',
164  ];
165  foreach ( $map as $index => $key ) {
166  if ( isset( $params[$index] ) ) {
167  $params[$key] = $params[$index];
168  unset( $params[$index] );
169  }
170  }
171 
172  // Really old entries do not have log params, so form them from whatever info
173  // we have.
174  // Also walk through the parallel arrays of groups and metadata, combining each
175  // metadata array with the name of the group it pertains to
176  if ( isset( $params['4:array:oldgroups'] ) ) {
177  $params['4:array:oldgroups'] = $this->makeGroupArray( $params['4:array:oldgroups'] );
178 
179  $oldmetadata =& $params['oldmetadata'];
180  // unset old metadata entry to ensure metadata goes at the end of the params array
181  unset( $params['oldmetadata'] );
182  $params['oldmetadata'] = array_map( function ( $index ) use ( $params, $oldmetadata ) {
183  $result = [ 'group' => $params['4:array:oldgroups'][$index] ];
184  if ( isset( $oldmetadata[$index] ) ) {
185  $result += $oldmetadata[$index];
186  }
187  $result['expiry'] = ApiResult::formatExpiry( $result['expiry'] ?? null );
188 
189  return $result;
190  }, array_keys( $params['4:array:oldgroups'] ) );
191  }
192 
193  if ( isset( $params['5:array:newgroups'] ) ) {
194  $params['5:array:newgroups'] = $this->makeGroupArray( $params['5:array:newgroups'] );
195 
196  $newmetadata =& $params['newmetadata'];
197  // unset old metadata entry to ensure metadata goes at the end of the params array
198  unset( $params['newmetadata'] );
199  $params['newmetadata'] = array_map( function ( $index ) use ( $params, $newmetadata ) {
200  $result = [ 'group' => $params['5:array:newgroups'][$index] ];
201  if ( isset( $newmetadata[$index] ) ) {
202  $result += $newmetadata[$index];
203  }
204  $result['expiry'] = ApiResult::formatExpiry( $result['expiry'] ?? null );
205 
206  return $result;
207  }, array_keys( $params['5:array:newgroups'] ) );
208  }
209 
210  return $params;
211  }
212 
213  public function formatParametersForApi() {
214  $ret = parent::formatParametersForApi();
215  if ( isset( $ret['oldgroups'] ) ) {
216  ApiResult::setIndexedTagName( $ret['oldgroups'], 'g' );
217  }
218  if ( isset( $ret['newgroups'] ) ) {
219  ApiResult::setIndexedTagName( $ret['newgroups'], 'g' );
220  }
221  if ( isset( $ret['oldmetadata'] ) ) {
222  ApiResult::setArrayType( $ret['oldmetadata'], 'array' );
223  ApiResult::setIndexedTagName( $ret['oldmetadata'], 'g' );
224  }
225  if ( isset( $ret['newmetadata'] ) ) {
226  ApiResult::setArrayType( $ret['newmetadata'], 'array' );
227  ApiResult::setIndexedTagName( $ret['newmetadata'], 'g' );
228  }
229  return $ret;
230  }
231 
232  private function makeGroupArray( $group ) {
233  // Migrate old group params from string to array
234  if ( $group === '' ) {
235  $group = [];
236  } elseif ( is_string( $group ) ) {
237  $group = array_map( 'trim', explode( ',', $group ) );
238  }
239  return $group;
240  }
241 }
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 just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition: hooks.txt:1982
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:1982
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
LogEntryBase $entry
This class formats rights log entries.
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
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
Definition: ApiResult.php:616
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED since 1.28! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1980
static formatExpiry( $expiry, $infinity='infinity')
Format an expiry timestamp for API output.
Definition: ApiResult.php:1205
static getGroupMemberName( $group, $username)
Gets the localized name for a member of a group, if it exists.
$params
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
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
formatRightsList( $groups, $serializedUGMs=[])
makePageLink(Title $title=null, $parameters=[], $html=null)
Implements the default log formatting.
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
getParameters()
Get the extra parameters stored for this message.
msg( $key)
Shortcut for wfMessage which honors local context.
$wgUserrightsInterwikiDelimiter
Character used as a delimiter when testing for interwiki userrights (In Special:UserRights, it is possible to modify users on different databases if the delimiter is used, e.g.
static foreignUserLink( $wikiID, $user, $text=null)
Convenience to get a link to a user page on a foreign wiki.
Definition: WikiMap.php:137
static setArrayType(array &$arr, $type, $kvpKeyName=null)
Set the array data type.
Definition: ApiResult.php:728