Kill NamespaceCompat. Nothing, anywhere (not even comments, since r70692) still refer...
[mediawiki.git] / includes / Credits.php
blob53718cb0bcdec8a5078c79cbf0bda5b6832c5f9d
1 <?php
2 /**
3 * Credits.php -- formats credits for articles
4 * Copyright 2004, Evan Prodromou <evan@wikitravel.org>.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 * @author <evan@wikitravel.org>
23 class Credits {
24 /**
25 * This is largely cadged from PageHistory::history
26 * @param $article Article object
28 public static function showPage( Article $article ) {
29 global $wgOut;
31 wfProfileIn( __METHOD__ );
33 $wgOut->setPageTitle( $article->mTitle->getPrefixedText() );
34 $wgOut->setSubtitle( wfMsg( 'creditspage' ) );
35 $wgOut->setArticleFlag( false );
36 $wgOut->setArticleRelated( true );
37 $wgOut->setRobotPolicy( 'noindex,nofollow' );
39 if ( $article->mTitle->getArticleID() == 0 ) {
40 $s = wfMsg( 'nocredits' );
41 } else {
42 $s = self::getCredits( $article, -1 );
45 $wgOut->addHTML( $s );
47 wfProfileOut( __METHOD__ );
50 /**
51 * Get a list of contributors of $article
52 * @param $article Article object
53 * @param $cnt Int: maximum list of contributors to show
54 * @param $showIfMax Bool: whether to contributors if there more than $cnt
55 * @return String: html
57 public static function getCredits( Article $article, $cnt, $showIfMax = true ) {
58 wfProfileIn( __METHOD__ );
59 $s = '';
61 if ( isset( $cnt ) && $cnt != 0 ) {
62 $s = self::getAuthor( $article );
63 if ( $cnt > 1 || $cnt < 0 ) {
64 $s .= ' ' . self::getContributors( $article, $cnt - 1, $showIfMax );
68 wfProfileOut( __METHOD__ );
69 return $s;
72 /**
73 * Get the last author with the last modification time
74 * @param $article Article object
76 protected static function getAuthor( Article $article ) {
77 global $wgLang;
79 $user = User::newFromId( $article->getUser() );
81 $timestamp = $article->getTimestamp();
82 if ( $timestamp ) {
83 $d = $wgLang->date( $article->getTimestamp(), true );
84 $t = $wgLang->time( $article->getTimestamp(), true );
85 } else {
86 $d = '';
87 $t = '';
89 return wfMsgExt( 'lastmodifiedatby', 'parsemag', $d, $t, self::userLink( $user ), $user->getName() );
92 /**
93 * Get a list of contributors of $article
94 * @param $article Article object
95 * @param $cnt Int: maximum list of contributors to show
96 * @param $showIfMax Bool: whether to contributors if there more than $cnt
97 * @return String: html
99 protected static function getContributors( Article $article, $cnt, $showIfMax ) {
100 global $wgLang, $wgHiddenPrefs;
102 $contributors = $article->getContributors();
104 $others_link = false;
106 # Hmm... too many to fit!
107 if ( $cnt > 0 && $contributors->count() > $cnt ) {
108 $others_link = self::othersLink( $article );
109 if ( !$showIfMax )
110 return wfMsgExt( 'othercontribs', 'parsemag', $others_link, $contributors->count() );
113 $real_names = array();
114 $user_names = array();
115 $anon_ips = array();
117 # Sift for real versus user names
118 foreach ( $contributors as $user ) {
119 $cnt--;
120 if ( $user->isLoggedIn() ) {
121 $link = self::link( $user );
122 if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) {
123 $real_names[] = $link;
124 } else {
125 $user_names[] = $link;
127 } else {
128 $anon_ips[] = self::link( $user );
131 if ( $cnt == 0 ) {
132 break;
136 if ( count( $real_names ) ) {
137 $real = $wgLang->listToText( $real_names );
138 } else {
139 $real = false;
142 # "ThisSite user(s) A, B and C"
143 if ( count( $user_names ) ) {
144 $user = wfMsgExt(
145 'siteusers',
146 'parsemag',
147 $wgLang->listToText( $user_names ), count( $user_names )
149 } else {
150 $user = false;
153 if ( count( $anon_ips ) ) {
154 $anon = wfMsgExt(
155 'anonusers',
156 'parsemag',
157 $wgLang->listToText( $anon_ips ), count( $anon_ips )
159 } else {
160 $anon = false;
163 # This is the big list, all mooshed together. We sift for blank strings
164 $fulllist = array();
165 foreach ( array( $real, $user, $anon, $others_link ) as $s ) {
166 if ( $s ) {
167 array_push( $fulllist, $s );
171 # Make the list into text...
172 $creds = $wgLang->listToText( $fulllist );
174 # "Based on work by ..."
175 return strlen( $creds )
176 ? wfMsgExt( 'othercontribs', 'parsemag', $creds, count( $fulllist ) )
177 : '';
181 * Get a link to $user's user page
182 * @param $user User object
183 * @return String: html
185 protected static function link( User $user ) {
186 global $wgUser, $wgHiddenPrefs;
187 if ( !in_array( 'realname', $wgHiddenPrefs ) && !$user->isAnon() ) {
188 $real = $user->getRealName();
189 } else {
190 $real = false;
193 $skin = $wgUser->getSkin();
194 $page = $user->isAnon() ?
195 SpecialPage::getTitleFor( 'Contributions', $user->getName() ) :
196 $user->getUserPage();
198 return $skin->link( $page, htmlspecialchars( $real ? $real : $user->getName() ) );
202 * Get a link to $user's user page
203 * @param $user User object
204 * @return String: html
206 protected static function userLink( User $user ) {
207 $link = self::link( $user );
208 if ( $user->isAnon() ) {
209 return wfMsgExt( 'anonuser', array( 'parseinline', 'replaceafter' ), $link );
210 } else {
211 global $wgHiddenPrefs;
212 if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) {
213 return $link;
214 } else {
215 return wfMsgExt( 'siteuser', 'parsemag', $link, $user->getName() );
221 * Get a link to action=credits of $article page
222 * @param $article Article object
223 * @return String: html
225 protected static function othersLink( Article $article ) {
226 global $wgUser;
227 $skin = $wgUser->getSkin();
228 return $skin->link(
229 $article->getTitle(),
230 wfMsgHtml( 'others' ),
231 array(),
232 array( 'action' => 'credits' ),
233 array( 'known' )