MediaWiki  1.23.2
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  wfProfileIn( __METHOD__ );
46 
47  if ( $this->page->getID() == 0 ) {
48  $s = $this->msg( 'nocredits' )->parse();
49  } else {
50  $s = $this->getCredits( -1 );
51  }
52 
53  wfProfileOut( __METHOD__ );
54 
55  return Html::rawElement( 'div', array( 'id' => 'mw-credits' ), $s );
56  }
57 
65  public function getCredits( $cnt, $showIfMax = true ) {
66  wfProfileIn( __METHOD__ );
67  $s = '';
68 
69  if ( $cnt != 0 ) {
70  $s = $this->getAuthor( $this->page );
71  if ( $cnt > 1 || $cnt < 0 ) {
72  $s .= ' ' . $this->getContributors( $cnt - 1, $showIfMax );
73  }
74  }
75 
76  wfProfileOut( __METHOD__ );
77 
78  return $s;
79  }
80 
86  protected function getAuthor( Page $page ) {
88 
90  if ( $timestamp ) {
91  $lang = $this->getLanguage();
92  $d = $lang->date( $page->getTimestamp(), true );
93  $t = $lang->time( $page->getTimestamp(), true );
94  } else {
95  $d = '';
96  $t = '';
97  }
98 
99  return $this->msg( 'lastmodifiedatby', $d, $t )->rawParams(
100  $this->userLink( $user ) )->params( $user->getName() )->escaped();
101  }
102 
109  protected function getContributors( $cnt, $showIfMax ) {
110  global $wgHiddenPrefs;
111 
112  $contributors = $this->page->getContributors();
113 
114  $others_link = false;
115 
116  # Hmm... too many to fit!
117  if ( $cnt > 0 && $contributors->count() > $cnt ) {
118  $others_link = $this->othersLink();
119  if ( !$showIfMax ) {
120  return $this->msg( 'othercontribs' )->rawParams(
121  $others_link )->params( $contributors->count() )->escaped();
122  }
123  }
124 
125  $real_names = array();
126  $user_names = array();
127  $anon_ips = array();
128 
129  # Sift for real versus user names
130 
131  foreach ( $contributors as $user ) {
132  $cnt--;
133  if ( $user->isLoggedIn() ) {
134  $link = $this->link( $user );
135  if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) {
136  $real_names[] = $link;
137  } else {
138  $user_names[] = $link;
139  }
140  } else {
141  $anon_ips[] = $this->link( $user );
142  }
143 
144  if ( $cnt == 0 ) {
145  break;
146  }
147  }
148 
149  $lang = $this->getLanguage();
150 
151  if ( count( $real_names ) ) {
152  $real = $lang->listToText( $real_names );
153  } else {
154  $real = false;
155  }
156 
157  # "ThisSite user(s) A, B and C"
158  if ( count( $user_names ) ) {
159  $user = $this->msg( 'siteusers' )->rawParams( $lang->listToText( $user_names ) )->params(
160  count( $user_names ) )->escaped();
161  } else {
162  $user = false;
163  }
164 
165  if ( count( $anon_ips ) ) {
166  $anon = $this->msg( 'anonusers' )->rawParams( $lang->listToText( $anon_ips ) )->params(
167  count( $anon_ips ) )->escaped();
168  } else {
169  $anon = false;
170  }
171 
172  # This is the big list, all mooshed together. We sift for blank strings
173  $fulllist = array();
174  foreach ( array( $real, $user, $anon, $others_link ) as $s ) {
175  if ( $s !== false ) {
176  array_push( $fulllist, $s );
177  }
178  }
179 
180  $count = count( $fulllist );
181 
182  # "Based on work by ..."
183  return $count
184  ? $this->msg( 'othercontribs' )->rawParams(
185  $lang->listToText( $fulllist ) )->params( $count )->escaped()
186  : '';
187  }
188 
194  protected function link( User $user ) {
195  global $wgHiddenPrefs;
196  if ( !in_array( 'realname', $wgHiddenPrefs ) && !$user->isAnon() ) {
197  $real = $user->getRealName();
198  } else {
199  $real = false;
200  }
201 
202  $page = $user->isAnon()
203  ? SpecialPage::getTitleFor( 'Contributions', $user->getName() )
204  : $user->getUserPage();
205 
206  return Linker::link( $page, htmlspecialchars( $real ? $real : $user->getName() ) );
207  }
208 
214  protected function userLink( User $user ) {
215  $link = $this->link( $user );
216  if ( $user->isAnon() ) {
217  return $this->msg( 'anonuser' )->rawParams( $link )->parse();
218  } else {
219  global $wgHiddenPrefs;
220  if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) {
221  return $link;
222  } else {
223  return $this->msg( 'siteuser' )->rawParams( $link )->params( $user->getName() )->escaped();
224  }
225  }
226  }
227 
232  protected function othersLink() {
233  return Linker::linkKnown(
234  $this->getTitle(),
235  $this->msg( 'others' )->escaped(),
236  array(),
237  array( 'action' => 'credits' )
238  );
239  }
240 }
Page
Abstract class for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)
Definition: WikiPage.php:26
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
FormlessAction
An action which just does something, without showing a form first.
Definition: FormlessAction.php:29
$timestamp
if( $limit) $timestamp
Definition: importImages.php:104
wfProfileIn
wfProfileIn( $functionname)
Begin profiling of a function.
Definition: Profiler.php:33
CreditsAction\getName
getName()
Return the name of the action this object responds to.
Definition: CreditsAction.php:31
WikiPage\getUserText
getUserText( $audience=Revision::FOR_PUBLIC, User $user=null)
Definition: WikiPage.php:773
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:388
$s
$s
Definition: mergeMessageFileList.php:156
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name.
Definition: SpecialPage.php:74
$link
set to $title object and return false for a match for latest after cache objects are set use the ContentHandler facility to handle CSS and JavaScript for highlighting & $link
Definition: hooks.txt:2149
Linker\linkKnown
static linkKnown( $target, $html=null, $customAttribs=array(), $query=array(), $options=array( 'known', 'noclasses'))
Identical to link(), except $options defaults to 'known'.
Definition: Linker.php:264
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:1530
CreditsAction\getAuthor
getAuthor(Page $page)
Get the last author with the last modification time.
Definition: CreditsAction.php:86
Linker\link
static link( $target, $html=null, $customAttribs=array(), $query=array(), $options=array())
This function returns an HTML link to the given target.
Definition: Linker.php:192
CreditsAction\othersLink
othersLink()
Get a link to action=credits of $article page.
Definition: CreditsAction.php:232
wfProfileOut
wfProfileOut( $functionname='missing')
Stop profiling of a function.
Definition: Profiler.php:46
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
CreditsAction\getCredits
getCredits( $cnt, $showIfMax=true)
Get a list of contributors.
Definition: CreditsAction.php:65
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:188
CreditsAction\link
link(User $user)
Get a link to $user's user page.
Definition: CreditsAction.php:194
CreditsAction\getDescription
getDescription()
Returns the description that goes below the <h1> tag.
Definition: CreditsAction.php:35
Action\getTitle
getTitle()
Shortcut to get the Title object from the page.
Definition: Action.php:237
CreditsAction\onView
onView()
This is largely cadged from PageHistory::history.
Definition: CreditsAction.php:44
$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:237
$count
$count
Definition: UtfNormalTest2.php:96
Action\msg
msg()
Get a Message object with context set Parameters are the same as wfMessage()
Definition: Action.php:247
Action\$page
WikiPage Article ImagePage CategoryPage Page $page
Page on which we're performing the action $page.
Definition: Action.php:42
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
Action\getLanguage
getLanguage()
Shortcut to get the user Language being used for this instance.
Definition: Action.php:218
CreditsAction\getContributors
getContributors( $cnt, $showIfMax)
Get a list of contributors of $article.
Definition: CreditsAction.php:109
CreditsAction
Definition: CreditsAction.php:29
$t
$t
Definition: testCompression.php:65
WikiPage\getTimestamp
getTimestamp()
Definition: WikiPage.php:708
Html\rawElement
static rawElement( $element, $attribs=array(), $contents='')
Returns an HTML element in a string.
Definition: Html.php:124
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:59
User\getName
getName()
Get the user name, or the IP of an anonymous user.
Definition: User.php:1876
CreditsAction\userLink
userLink(User $user)
Get a link to $user's user page.
Definition: CreditsAction.php:214
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 my talk page
Definition: hooks.txt:1956