MediaWiki  1.28.0
CreditsAction.php
Go to the documentation of this file.
1 <?php
30 
31  public function getName() {
32  return 'credits';
33  }
34 
35  protected function getDescription() {
36  return $this->msg( 'creditspage' )->escaped();
37  }
38 
44  public function onView() {
45 
46  if ( $this->page->getID() == 0 ) {
47  $s = $this->msg( 'nocredits' )->parse();
48  } else {
49  $s = $this->getCredits( -1 );
50  }
51 
52  return Html::rawElement( 'div', [ 'id' => 'mw-credits' ], $s );
53  }
54 
62  public function getCredits( $cnt, $showIfMax = true ) {
63  $s = '';
64 
65  if ( $cnt != 0 ) {
66  $s = $this->getAuthor( $this->page );
67  if ( $cnt > 1 || $cnt < 0 ) {
68  $s .= ' ' . $this->getContributors( $cnt - 1, $showIfMax );
69  }
70  }
71 
72  return $s;
73  }
74 
80  protected function getAuthor( Page $page ) {
81  $user = User::newFromName( $page->getUserText(), false );
82 
83  $timestamp = $page->getTimestamp();
84  if ( $timestamp ) {
85  $lang = $this->getLanguage();
86  $d = $lang->date( $page->getTimestamp(), true );
87  $t = $lang->time( $page->getTimestamp(), true );
88  } else {
89  $d = '';
90  $t = '';
91  }
92 
93  return $this->msg( 'lastmodifiedatby', $d, $t )->rawParams(
94  $this->userLink( $user ) )->params( $user->getName() )->escaped();
95  }
96 
103  protected function canShowRealUserName() {
104  $hiddenPrefs = $this->context->getConfig()->get( 'HiddenPrefs' );
105  return !in_array( 'realname', $hiddenPrefs );
106  }
107 
114  protected function getContributors( $cnt, $showIfMax ) {
115  $contributors = $this->page->getContributors();
116 
117  $others_link = false;
118 
119  # Hmm... too many to fit!
120  if ( $cnt > 0 && $contributors->count() > $cnt ) {
121  $others_link = $this->othersLink();
122  if ( !$showIfMax ) {
123  return $this->msg( 'othercontribs' )->rawParams(
124  $others_link )->params( $contributors->count() )->escaped();
125  }
126  }
127 
128  $real_names = [];
129  $user_names = [];
130  $anon_ips = [];
131 
132  # Sift for real versus user names
133 
134  foreach ( $contributors as $user ) {
135  $cnt--;
136  if ( $user->isLoggedIn() ) {
137  $link = $this->link( $user );
138  if ( $this->canShowRealUserName() && $user->getRealName() ) {
139  $real_names[] = $link;
140  } else {
141  $user_names[] = $link;
142  }
143  } else {
144  $anon_ips[] = $this->link( $user );
145  }
146 
147  if ( $cnt == 0 ) {
148  break;
149  }
150  }
151 
152  $lang = $this->getLanguage();
153 
154  if ( count( $real_names ) ) {
155  $real = $lang->listToText( $real_names );
156  } else {
157  $real = false;
158  }
159 
160  # "ThisSite user(s) A, B and C"
161  if ( count( $user_names ) ) {
162  $user = $this->msg( 'siteusers' )->rawParams( $lang->listToText( $user_names ) )->params(
163  count( $user_names ) )->escaped();
164  } else {
165  $user = false;
166  }
167 
168  if ( count( $anon_ips ) ) {
169  $anon = $this->msg( 'anonusers' )->rawParams( $lang->listToText( $anon_ips ) )->params(
170  count( $anon_ips ) )->escaped();
171  } else {
172  $anon = false;
173  }
174 
175  # This is the big list, all mooshed together. We sift for blank strings
176  $fulllist = [];
177  foreach ( [ $real, $user, $anon, $others_link ] as $s ) {
178  if ( $s !== false ) {
179  array_push( $fulllist, $s );
180  }
181  }
182 
183  $count = count( $fulllist );
184 
185  # "Based on work by ..."
186  return $count
187  ? $this->msg( 'othercontribs' )->rawParams(
188  $lang->listToText( $fulllist ) )->params( $count )->escaped()
189  : '';
190  }
191 
197  protected function link( User $user ) {
198  if ( $this->canShowRealUserName() && !$user->isAnon() ) {
199  $real = $user->getRealName();
200  } else {
201  $real = false;
202  }
203 
204  $page = $user->isAnon()
205  ? SpecialPage::getTitleFor( 'Contributions', $user->getName() )
206  : $user->getUserPage();
207 
208  return Linker::link( $page, htmlspecialchars( $real ? $real : $user->getName() ) );
209  }
210 
216  protected function userLink( User $user ) {
217  $link = $this->link( $user );
218  if ( $user->isAnon() ) {
219  return $this->msg( 'anonuser' )->rawParams( $link )->parse();
220  } else {
221  if ( $this->canShowRealUserName() && $user->getRealName() ) {
222  return $link;
223  } else {
224  return $this->msg( 'siteuser' )->rawParams( $link )->params( $user->getName() )->escaped();
225  }
226  }
227  }
228 
233  protected function othersLink() {
234  return Linker::linkKnown(
235  $this->getTitle(),
236  $this->msg( 'others' )->escaped(),
237  [],
238  [ 'action' => 'credits' ]
239  );
240  }
241 }
static newFromName($name, $validate= 'valid')
Static factory method for creation from username.
Definition: User.php:525
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
getTitle()
Shortcut to get the Title object from the page.
Definition: Action.php:246
static getTitleFor($name, $subpage=false, $fragment= '')
Get a localised Title object for a specified special page name If you don't need a full Title object...
Definition: SpecialPage.php:82
static rawElement($element, $attribs=[], $contents= '')
Returns an HTML element in a string.
Definition: Html.php:209
if(!isset($args[0])) $lang
getRealName()
Get the user's real name.
Definition: User.php:2739
getLanguage()
Shortcut to get the user Language being used for this instance.
Definition: Action.php:236
getAuthor(Page $page)
Get the last author with the last modification time.
$contributors
userLink(User $user)
Get a link to $user's user page.
canShowRealUserName()
Whether we can display the user's real name (not a hidden pref)
getName()
Get the user name, or the IP of an anonymous user.
Definition: User.php:2108
getCredits($cnt, $showIfMax=true)
Get a list of contributors.
link(User $user)
Get a link to $user's user page.
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition: hooks.txt:2889
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 true
Definition: hooks.txt:1936
Interface for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)
Definition: Page.php:24
onView()
This is largely cadged from PageHistory::history.
isAnon()
Get whether the user is anonymous.
Definition: User.php:3388
if($limit) $timestamp
static linkKnown($target, $html=null, $customAttribs=[], $query=[], $options=[ 'known'])
Identical to link(), except $options defaults to 'known'.
Definition: Linker.php:255
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
$page
Page on which we're performing the action.
Definition: Action.php:44
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 local account $user
Definition: hooks.txt:242
static link($target, $html=null, $customAttribs=[], $query=[], $options=[])
This function returns an HTML link to the given target.
Definition: Linker.php:203
getContributors($cnt, $showIfMax)
Get a list of contributors of $article.
An action which just does something, without showing a form first.
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
getUserPage()
Get this user's personal page title.
Definition: User.php:4151
$count
othersLink()
Get a link to action=credits of $article page.
msg()
Get a Message object with context set Parameters are the same as wfMessage()
Definition: Action.php:256
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk page
Definition: hooks.txt:2491