MediaWiki  1.30.0
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  if ( $this->page->getID() == 0 ) {
48  $s = $this->msg( 'nocredits' )->parse();
49  } else {
50  $s = $this->getCredits( -1 );
51  }
52 
53  return Html::rawElement( 'div', [ 'id' => 'mw-credits' ], $s );
54  }
55 
63  public function getCredits( $cnt, $showIfMax = true ) {
64  $s = '';
65 
66  if ( $cnt != 0 ) {
67  $s = $this->getAuthor( $this->page );
68  if ( $cnt > 1 || $cnt < 0 ) {
69  $s .= ' ' . $this->getContributors( $cnt - 1, $showIfMax );
70  }
71  }
72 
73  return $s;
74  }
75 
81  protected function getAuthor( Page $page ) {
82  $user = User::newFromName( $page->getUserText(), false );
83 
84  $timestamp = $page->getTimestamp();
85  if ( $timestamp ) {
86  $lang = $this->getLanguage();
87  $d = $lang->date( $page->getTimestamp(), true );
88  $t = $lang->time( $page->getTimestamp(), true );
89  } else {
90  $d = '';
91  $t = '';
92  }
93 
94  return $this->msg( 'lastmodifiedatby', $d, $t )->rawParams(
95  $this->userLink( $user ) )->params( $user->getName() )->escaped();
96  }
97 
104  protected function canShowRealUserName() {
105  $hiddenPrefs = $this->context->getConfig()->get( 'HiddenPrefs' );
106  return !in_array( 'realname', $hiddenPrefs );
107  }
108 
115  protected function getContributors( $cnt, $showIfMax ) {
116  $contributors = $this->page->getContributors();
117 
118  $others_link = false;
119 
120  # Hmm... too many to fit!
121  if ( $cnt > 0 && $contributors->count() > $cnt ) {
122  $others_link = $this->othersLink();
123  if ( !$showIfMax ) {
124  return $this->msg( 'othercontribs' )->rawParams(
125  $others_link )->params( $contributors->count() )->escaped();
126  }
127  }
128 
129  $real_names = [];
130  $user_names = [];
131  $anon_ips = [];
132 
133  # Sift for real versus user names
134 
135  foreach ( $contributors as $user ) {
136  $cnt--;
137  if ( $user->isLoggedIn() ) {
138  $link = $this->link( $user );
139  if ( $this->canShowRealUserName() && $user->getRealName() ) {
140  $real_names[] = $link;
141  } else {
142  $user_names[] = $link;
143  }
144  } else {
145  $anon_ips[] = $this->link( $user );
146  }
147 
148  if ( $cnt == 0 ) {
149  break;
150  }
151  }
152 
153  $lang = $this->getLanguage();
154 
155  if ( count( $real_names ) ) {
156  $real = $lang->listToText( $real_names );
157  } else {
158  $real = false;
159  }
160 
161  # "ThisSite user(s) A, B and C"
162  if ( count( $user_names ) ) {
163  $user = $this->msg( 'siteusers' )->rawParams( $lang->listToText( $user_names ) )->params(
164  count( $user_names ) )->escaped();
165  } else {
166  $user = false;
167  }
168 
169  if ( count( $anon_ips ) ) {
170  $anon = $this->msg( 'anonusers' )->rawParams( $lang->listToText( $anon_ips ) )->params(
171  count( $anon_ips ) )->escaped();
172  } else {
173  $anon = false;
174  }
175 
176  # This is the big list, all mooshed together. We sift for blank strings
177  $fulllist = [];
178  foreach ( [ $real, $user, $anon, $others_link ] as $s ) {
179  if ( $s !== false ) {
180  array_push( $fulllist, $s );
181  }
182  }
183 
184  $count = count( $fulllist );
185 
186  # "Based on work by ..."
187  return $count
188  ? $this->msg( 'othercontribs' )->rawParams(
189  $lang->listToText( $fulllist ) )->params( $count )->escaped()
190  : '';
191  }
192 
198  protected function link( User $user ) {
199  if ( $this->canShowRealUserName() && !$user->isAnon() ) {
200  $real = $user->getRealName();
201  } else {
202  $real = $user->getName();
203  }
204 
205  $page = $user->isAnon()
206  ? SpecialPage::getTitleFor( 'Contributions', $user->getName() )
207  : $user->getUserPage();
208 
209  return MediaWikiServices::getInstance()
210  ->getLinkRenderer()->makeLink( $page, $real );
211  }
212 
218  protected function userLink( User $user ) {
219  $link = $this->link( $user );
220  if ( $user->isAnon() ) {
221  return $this->msg( 'anonuser' )->rawParams( $link )->parse();
222  } else {
223  if ( $this->canShowRealUserName() && $user->getRealName() ) {
224  return $link;
225  } else {
226  return $this->msg( 'siteuser' )->rawParams( $link )->params( $user->getName() )->escaped();
227  }
228  }
229  }
230 
235  protected function othersLink() {
236  return MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
237  $this->getTitle(),
238  $this->msg( 'others' )->text(),
239  [],
240  [ 'action' => 'credits' ]
241  );
242  }
243 }
CreditsAction\canShowRealUserName
canShowRealUserName()
Whether we can display the user's real name (not a hidden pref)
Definition: CreditsAction.php:104
$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
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:187
User\isAnon
isAnon()
Get whether the user is anonymous.
Definition: User.php:3510
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:249
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\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:550
$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
page
target page
Definition: All_system_messages.txt:1267
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:81
Action\msg
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: Action.php:256
CreditsAction\othersLink
othersLink()
Get a link to action=credits of $article page.
Definition: CreditsAction.php:235
$contributors
$contributors
Definition: updateCredits.php:36
CreditsAction\getCredits
getCredits( $cnt, $showIfMax=true)
Get a list of contributors.
Definition: CreditsAction.php:63
CreditsAction\link
link(User $user)
Get a link to $user's user page.
Definition: CreditsAction.php:198
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:2855
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\$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:2981
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:1965
CreditsAction\getContributors
getContributors( $cnt, $showIfMax)
Get a list of contributors of $article.
Definition: CreditsAction.php:115
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:51
User\getName
getName()
Get the user name, or the IP of an anonymous user.
Definition: User.php:2249
CreditsAction\userLink
userLink(User $user)
Get a link to $user's user page.
Definition: CreditsAction.php:218