MediaWiki  1.28.0
RightsLogFormatter.php
Go to the documentation of this file.
1 <?php
32  protected function makePageLink( Title $title = null, $parameters = [], $html = null ) {
33  global $wgContLang, $wgUserrightsInterwikiDelimiter;
34 
35  if ( !$this->plaintext ) {
36  $text = $wgContLang->ucfirst( $title->getDBkey() );
37  $parts = explode( $wgUserrightsInterwikiDelimiter, $text, 2 );
38 
39  if ( count( $parts ) === 2 ) {
40  $titleLink = WikiMap::foreignUserLink(
41  $parts[1],
42  $parts[0],
43  htmlspecialchars(
44  strtr( $parts[0], '_', ' ' ) .
45  $wgUserrightsInterwikiDelimiter .
46  $parts[1]
47  )
48  );
49 
50  if ( $titleLink !== false ) {
51  return $titleLink;
52  }
53  }
54  }
55 
56  return parent::makePageLink( $title, $parameters, $title ? $title->getText() : null );
57  }
58 
59  protected function getMessageKey() {
60  $key = parent::getMessageKey();
61  $params = $this->getMessageParameters();
62  if ( !isset( $params[3] ) && !isset( $params[4] ) ) {
63  // Messages: logentry-rights-rights-legacy
64  $key .= '-legacy';
65  }
66 
67  return $key;
68  }
69 
70  protected function getMessageParameters() {
71  $params = parent::getMessageParameters();
72 
73  // Really old entries
74  if ( !isset( $params[3] ) && !isset( $params[4] ) ) {
75  return $params;
76  }
77 
78  $oldGroups = $this->makeGroupArray( $params[3] );
79  $newGroups = $this->makeGroupArray( $params[4] );
80 
81  $userName = $this->entry->getTarget()->getText();
82  if ( !$this->plaintext && count( $oldGroups ) ) {
83  foreach ( $oldGroups as &$group ) {
84  $group = User::getGroupMember( $group, $userName );
85  }
86  }
87  if ( !$this->plaintext && count( $newGroups ) ) {
88  foreach ( $newGroups as &$group ) {
89  $group = User::getGroupMember( $group, $userName );
90  }
91  }
92 
93  $lang = $this->context->getLanguage();
94  if ( count( $oldGroups ) ) {
95  $params[3] = $lang->listToText( $oldGroups );
96  } else {
97  $params[3] = $this->msg( 'rightsnone' )->text();
98  }
99  if ( count( $newGroups ) ) {
100  // Array_values is used here because of T44211
101  // see use of array_unique in UserrightsPage::doSaveUserGroups on $newGroups.
102  $params[4] = $lang->listToText( array_values( $newGroups ) );
103  } else {
104  $params[4] = $this->msg( 'rightsnone' )->text();
105  }
106 
107  $params[5] = $userName;
108 
109  return $params;
110  }
111 
112  protected function getParametersForApi() {
115 
116  static $map = [
117  '4:array:oldgroups',
118  '5:array:newgroups',
119  '4::oldgroups' => '4:array:oldgroups',
120  '5::newgroups' => '5:array:newgroups',
121  ];
122  foreach ( $map as $index => $key ) {
123  if ( isset( $params[$index] ) ) {
124  $params[$key] = $params[$index];
125  unset( $params[$index] );
126  }
127  }
128 
129  // Really old entries does not have log params
130  if ( isset( $params['4:array:oldgroups'] ) ) {
131  $params['4:array:oldgroups'] = $this->makeGroupArray( $params['4:array:oldgroups'] );
132  }
133  if ( isset( $params['5:array:newgroups'] ) ) {
134  $params['5:array:newgroups'] = $this->makeGroupArray( $params['5:array:newgroups'] );
135  }
136 
137  return $params;
138  }
139 
140  public function formatParametersForApi() {
141  $ret = parent::formatParametersForApi();
142  if ( isset( $ret['oldgroups'] ) ) {
143  ApiResult::setIndexedTagName( $ret['oldgroups'], 'g' );
144  }
145  if ( isset( $ret['newgroups'] ) ) {
146  ApiResult::setIndexedTagName( $ret['newgroups'], 'g' );
147  }
148  return $ret;
149  }
150 
151  private function makeGroupArray( $group ) {
152  // Migrate old group params from string to array
153  if ( $group === '' ) {
154  $group = [];
155  } elseif ( is_string( $group ) ) {
156  $group = array_map( 'trim', explode( ',', $group ) );
157  }
158  return $group;
159  }
160 }
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:1936
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:1936
LogEntryBase $entry
if(!isset($args[0])) $lang
static foreignUserLink($wikiID, $user, $text=null)
Convenience to get a link to a user page on a foreign wiki.
Definition: WikiMap.php:134
This class formats rights log entries.
msg($key)
Shortcut for wfMessage which honors local context.
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
Definition: ApiResult.php:618
$params
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:953
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
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.
static getGroupMember($group, $username= '#')
Get the localized descriptive name for a member of a group, if it exists.
Definition: User.php:4706
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:56