Patched jquery-1.4.2 to not crash in IE7 when a style property is set with 'null...
[mediawiki.git] / includes / Credits.php
blob65a879393675b9f84bb0b40eb107b6d65ac07139
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 {
25 /**
26 * This is largely cadged from PageHistory::history
27 * @param $article Article object
29 public static function showPage( Article $article ) {
30 global $wgOut;
32 wfProfileIn( __METHOD__ );
34 $wgOut->setPageTitle( $article->mTitle->getPrefixedText() );
35 $wgOut->setSubtitle( wfMsg( 'creditspage' ) );
36 $wgOut->setArticleFlag( false );
37 $wgOut->setArticleRelated( true );
38 $wgOut->setRobotPolicy( 'noindex,nofollow' );
40 if( $article->mTitle->getArticleID() == 0 ) {
41 $s = wfMsg( 'nocredits' );
42 } else {
43 $s = self::getCredits( $article, -1 );
46 $wgOut->addHTML( $s );
48 wfProfileOut( __METHOD__ );
51 /**
52 * Get a list of contributors of $article
53 * @param $article Article object
54 * @param $cnt Int: maximum list of contributors to show
55 * @param $showIfMax Bool: whether to contributors if there more than $cnt
56 * @return String: html
58 public static function getCredits( Article $article, $cnt, $showIfMax = true ) {
59 wfProfileIn( __METHOD__ );
60 $s = '';
62 if( isset( $cnt ) && $cnt != 0 ){
63 $s = self::getAuthor( $article );
64 if ( $cnt > 1 || $cnt < 0 ) {
65 $s .= ' ' . self::getContributors( $article, $cnt - 1, $showIfMax );
69 wfProfileOut( __METHOD__ );
70 return $s;
73 /**
74 * Get the last author with the last modification time
75 * @param $article Article object
77 protected static function getAuthor( Article $article ){
78 global $wgLang;
80 $user = User::newFromId( $article->getUser() );
82 $timestamp = $article->getTimestamp();
83 if( $timestamp ){
84 $d = $wgLang->date( $article->getTimestamp(), true );
85 $t = $wgLang->time( $article->getTimestamp(), true );
86 } else {
87 $d = '';
88 $t = '';
90 return wfMsgExt( 'lastmodifiedatby', 'parsemag', $d, $t, self::userLink( $user ), $user->getName() );
93 /**
94 * Get a list of contributors of $article
95 * @param $article Article object
96 * @param $cnt Int: maximum list of contributors to show
97 * @param $showIfMax Bool: whether to contributors if there more than $cnt
98 * @return String: html
100 protected static function getContributors( Article $article, $cnt, $showIfMax ) {
101 global $wgLang, $wgHiddenPrefs;
103 $contributors = $article->getContributors();
105 $others_link = false;
107 # Hmm... too many to fit!
108 if( $cnt > 0 && $contributors->count() > $cnt ){
109 $others_link = self::othersLink( $article );
110 if( !$showIfMax )
111 return wfMsgExt( 'othercontribs', 'parsemag', $others_link, $contributors->count() );
114 $real_names = array();
115 $user_names = array();
116 $anon_ips = array();
118 # Sift for real versus user names
119 foreach( $contributors as $user ) {
120 $cnt--;
121 if( $user->isLoggedIn() ){
122 $link = self::link( $user );
123 if( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() )
124 $real_names[] = $link;
125 else
126 $user_names[] = $link;
127 } else {
128 $anon_ips[] = self::link( $user );
130 if( $cnt == 0 ) break;
133 if ( count( $real_names ) ) {
134 $real = $wgLang->listToText( $real_names );
135 } else {
136 $real = false;
139 # "ThisSite user(s) A, B and C"
140 if( count( $user_names ) ){
141 $user = wfMsgExt( 'siteusers', array( 'parsemag' ),
142 $wgLang->listToText( $user_names ), count( $user_names ) );
143 } else {
144 $user = false;
147 if( count( $anon_ips ) ){
148 $anon = wfMsgExt( 'anonusers', array( 'parsemag' ),
149 $wgLang->listToText( $anon_ips ), count( $anon_ips ) );
150 } else {
151 $anon = false;
154 # This is the big list, all mooshed together. We sift for blank strings
155 $fulllist = array();
156 foreach( array( $real, $user, $anon, $others_link ) as $s ){
157 if( $s ){
158 array_push( $fulllist, $s );
162 # Make the list into text...
163 $creds = $wgLang->listToText( $fulllist );
165 # "Based on work by ..."
166 return strlen( $creds )
167 ? wfMsgExt( 'othercontribs', 'parsemag', $creds, count( $fulllist ) )
168 : '';
172 * Get a link to $user's user page
173 * @param $user User object
174 * @return String: html
176 protected static function link( User $user ) {
177 global $wgUser, $wgHiddenPrefs;
178 if( !in_array( 'realname', $wgHiddenPrefs ) && !$user->isAnon() )
179 $real = $user->getRealName();
180 else
181 $real = false;
183 $skin = $wgUser->getSkin();
184 $page = $user->isAnon() ?
185 SpecialPage::getTitleFor( 'Contributions', $user->getName() ) :
186 $user->getUserPage();
188 return $skin->link( $page, htmlspecialchars( $real ? $real : $user->getName() ) );
192 * Get a link to $user's user page
193 * @param $user User object
194 * @return String: html
196 protected static function userLink( User $user ) {
197 $link = self::link( $user );
198 if( $user->isAnon() ){
199 return wfMsgExt( 'anonuser', array( 'parseinline', 'replaceafter' ), $link );
200 } else {
201 global $wgHiddenPrefs;
202 if( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() )
203 return $link;
204 else
205 return wfMsgExt( 'siteuser', array( 'parseinline', 'replaceafter' ), $link );
210 * Get a link to action=credits of $article page
211 * @param $article Article object
212 * @return String: html
214 protected static function othersLink( Article $article ) {
215 global $wgUser;
216 $skin = $wgUser->getSkin();
217 return $skin->link( $article->getTitle(), wfMsgHtml( 'others' ), array(), array( 'action' => 'credits' ), array( 'known' ) );