MediaWiki  1.29.1
CreditsAction.php
Go to the documentation of this file.
1 <?php
27 
32 
33  public function getName() {
34  return 'credits';
35  }
36 
37  protected function getDescription() {
38  return $this->msg( 'creditspage' )->escaped();
39  }
40 
46  public function onView() {
47 
48  if ( $this->page->getID() == 0 ) {
49  $s = $this->msg( 'nocredits' )->parse();
50  } else {
51  $s = $this->getCredits( -1 );
52  }
53 
54  return Html::rawElement( 'div', [ 'id' => 'mw-credits' ], $s );
55  }
56 
64  public function getCredits( $cnt, $showIfMax = true ) {
65  $s = '';
66 
67  if ( $cnt != 0 ) {
68  $s = $this->getAuthor( $this->page );
69  if ( $cnt > 1 || $cnt < 0 ) {
70  $s .= ' ' . $this->getContributors( $cnt - 1, $showIfMax );
71  }
72  }
73 
74  return $s;
75  }
76 
82  protected function getAuthor( Page $page ) {
83  $user = User::newFromName( $page->getUserText(), false );
84 
85  $timestamp = $page->getTimestamp();
86  if ( $timestamp ) {
87  $lang = $this->getLanguage();
88  $d = $lang->date( $page->getTimestamp(), true );
89  $t = $lang->time( $page->getTimestamp(), true );
90  } else {
91  $d = '';
92  $t = '';
93  }
94 
95  return $this->msg( 'lastmodifiedatby', $d, $t )->rawParams(
96  $this->userLink( $user ) )->params( $user->getName() )->escaped();
97  }
98 
105  protected function canShowRealUserName() {
106  $hiddenPrefs = $this->context->getConfig()->get( 'HiddenPrefs' );
107  return !in_array( 'realname', $hiddenPrefs );
108  }
109 
116  protected function getContributors( $cnt, $showIfMax ) {
117  $contributors = $this->page->getContributors();
118 
119  $others_link = false;
120 
121  # Hmm... too many to fit!
122  if ( $cnt > 0 && $contributors->count() > $cnt ) {
123  $others_link = $this->othersLink();
124  if ( !$showIfMax ) {
125  return $this->msg( 'othercontribs' )->rawParams(
126  $others_link )->params( $contributors->count() )->escaped();
127  }
128  }
129 
130  $real_names = [];
131  $user_names = [];
132  $anon_ips = [];
133 
134  # Sift for real versus user names
135 
136  foreach ( $contributors as $user ) {
137  $cnt--;
138  if ( $user->isLoggedIn() ) {
139  $link = $this->link( $user );
140  if ( $this->canShowRealUserName() && $user->getRealName() ) {
141  $real_names[] = $link;
142  } else {
143  $user_names[] = $link;
144  }
145  } else {
146  $anon_ips[] = $this->link( $user );
147  }
148 
149  if ( $cnt == 0 ) {
150  break;
151  }
152  }
153 
154  $lang = $this->getLanguage();
155 
156  if ( count( $real_names ) ) {
157  $real = $lang->listToText( $real_names );
158  } else {
159  $real = false;
160  }
161 
162  # "ThisSite user(s) A, B and C"
163  if ( count( $user_names ) ) {
164  $user = $this->msg( 'siteusers' )->rawParams( $lang->listToText( $user_names ) )->params(
165  count( $user_names ) )->escaped();
166  } else {
167  $user = false;
168  }
169 
170  if ( count( $anon_ips ) ) {
171  $anon = $this->msg( 'anonusers' )->rawParams( $lang->listToText( $anon_ips ) )->params(
172  count( $anon_ips ) )->escaped();
173  } else {
174  $anon = false;
175  }
176 
177  # This is the big list, all mooshed together. We sift for blank strings
178  $fulllist = [];
179  foreach ( [ $real, $user, $anon, $others_link ] as $s ) {
180  if ( $s !== false ) {
181  array_push( $fulllist, $s );
182  }
183  }
184 
185  $count = count( $fulllist );
186 
187  # "Based on work by ..."
188  return $count
189  ? $this->msg( 'othercontribs' )->rawParams(
190  $lang->listToText( $fulllist ) )->params( $count )->escaped()
191  : '';
192  }
193 
199  protected function link( User $user ) {
200  if ( $this->canShowRealUserName() && !$user->isAnon() ) {
201  $real = $user->getRealName();
202  } else {
203  $real = $user->getName();
204  }
205 
206  $page = $user->isAnon()
207  ? SpecialPage::getTitleFor( 'Contributions', $user->getName() )
208  : $user->getUserPage();
209 
210  return MediaWikiServices::getInstance()
211  ->getLinkRenderer()->makeLink( $page, $real );
212  }
213 
219  protected function userLink( User $user ) {
220  $link = $this->link( $user );
221  if ( $user->isAnon() ) {
222  return $this->msg( 'anonuser' )->rawParams( $link )->parse();
223  } else {
224  if ( $this->canShowRealUserName() && $user->getRealName() ) {
225  return $link;
226  } else {
227  return $this->msg( 'siteuser' )->rawParams( $link )->params( $user->getName() )->escaped();
228  }
229  }
230  }
231 
236  protected function othersLink() {
237  return MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
238  $this->getTitle(),
239  $this->msg( 'others' )->text(),
240  [],
241  [ 'action' => 'credits' ]
242  );
243  }
244 }
CreditsAction\canShowRealUserName
canShowRealUserName()
Whether we can display the user's real name (not a hidden pref)
Definition: CreditsAction.php:105
Page
Interface for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)
Definition: Page.php:24
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
User\isAnon
isAnon()
Get whether the user is anonymous.
Definition: User.php:3485
FormlessAction
An action which just does something, without showing a form first.
Definition: FormlessAction.php:28
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
captcha-old.count
count
Definition: captcha-old.py:225
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
CreditsAction\getName
getName()
Return the name of the action this object responds to.
Definition: CreditsAction.php:33
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
$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:246
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:556
$s
$s
Definition: mergeMessageFileList.php:188
SpecialPage\getTitleFor
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
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
CreditsAction\getAuthor
getAuthor(Page $page)
Get the last author with the last modification time.
Definition: CreditsAction.php:82
CreditsAction\othersLink
othersLink()
Get a link to action=credits of $article page.
Definition: CreditsAction.php:236
$contributors
$contributors
Definition: updateCredits.php:36
CreditsAction\getCredits
getCredits( $cnt, $showIfMax=true)
Get a list of contributors.
Definition: CreditsAction.php:64
CreditsAction\link
link(User $user)
Get a link to $user's user page.
Definition: CreditsAction.php:199
CreditsAction\getDescription
getDescription()
Returns the description that goes below the <h1> tag.
Definition: CreditsAction.php:37
User\getRealName
getRealName()
Get the user's real name.
Definition: User.php:2830
Action\getTitle
getTitle()
Shortcut to get the Title object from the page.
Definition: Action.php:246
CreditsAction\onView
onView()
This is largely cadged from PageHistory::history.
Definition: CreditsAction.php:46
Action\msg
msg()
Get a Message object with context set Parameters are the same as wfMessage()
Definition: Action.php:256
page
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 my talk page
Definition: hooks.txt:2536
Action\$page
$page
Page on which we're performing the action.
Definition: Action.php:44
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
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
Action\getLanguage
getLanguage()
Shortcut to get the user Language being used for this instance.
Definition: Action.php:236
$link
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition: hooks.txt:2929
true
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:1956
CreditsAction\getContributors
getContributors( $cnt, $showIfMax)
Get a list of contributors of $article.
Definition: CreditsAction.php:116
CreditsAction
Definition: CreditsAction.php:31
$t
$t
Definition: testCompression.php:67
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
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:50
User\getName
getName()
Get the user name, or the IP of an anonymous user.
Definition: User.php:2225
CreditsAction\userLink
userLink(User $user)
Get a link to $user's user page.
Definition: CreditsAction.php:219