MediaWiki REL1_29
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
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}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
msg()
Get a Message object with context set Parameters are the same as wfMessage()
Definition Action.php:256
$page
Page on which we're performing the action.
Definition Action.php:44
getTitle()
Shortcut to get the Title object from the page.
Definition Action.php:246
getLanguage()
Shortcut to get the user Language being used for this instance.
Definition Action.php:236
getCredits( $cnt, $showIfMax=true)
Get a list of contributors.
getName()
Return the name of the action this object responds to.
getContributors( $cnt, $showIfMax)
Get a list of contributors of $article.
getAuthor(Page $page)
Get the last author with the last modification time.
canShowRealUserName()
Whether we can display the user's real name (not a hidden pref)
othersLink()
Get a link to action=credits of $article page.
getDescription()
Returns the description that goes below the <h1> tag.
link(User $user)
Get a link to $user's user page.
onView()
This is largely cadged from PageHistory::history.
userLink(User $user)
Get a link to $user's user page.
An action which just does something, without showing a form first.
MediaWikiServices is the service locator for the application scope of MediaWiki.
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,...
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:50
getName()
Get the user name, or the IP of an anonymous user.
Definition User.php:2226
getRealName()
Get the user's real name.
Definition User.php:2831
isAnon()
Get whether the user is anonymous.
Definition User.php:3486
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:18
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
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:249
usually copyright or history_copyright This message must be in HTML not wikitext if the section is included from a template to be included in the link
Definition hooks.txt:2939
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition hooks.txt:2937
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:2579
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:37
Interface for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)
Definition Page.php:24
if(!isset( $args[0])) $lang
$contributors