$contribs = array();
- $sql = 'SELECT old.old_user, old.old_user_text, ' .
- ' user.user_real_name, MAX(old.old_timestamp) as timestamp' .
- ' FROM old, user ' .
- ' WHERE old.old_user = user.user_id ' .
- ' AND old.old_namespace = ' . $title->getNamespace() .
+ $sql = 'SELECT old_user, old_user_text, ' .
+ ' user_real_name, MAX(old_timestamp) as timestamp' .
+ ' FROM old LEFT JOIN user ON old.old_user = user.user_id ' .
+ ' WHERE old.old_namespace = ' . $title->getNamespace() .
' AND old.old_title = "' . $title->getDBkey() . '"' .
- ' AND old.old_user != 0 ' .
' AND old.old_user != ' . $this->getUser() .
' GROUP BY old.old_user ' .
' ORDER BY timestamp DESC ';
$res = wfQuery($sql, DB_READ, $fname);
while ( $line = wfFetchObject( $res ) ) {
- $contribs[$line->old_user] =
- array($line->old_user_text, $line->user_real_name);
- }
-
- # Count anonymous users
-
- $res = wfQuery('SELECT COUNT(*) AS cnt ' .
- ' FROM old ' .
- ' WHERE old_namespace = ' . $title->getNamespace() .
- " AND old_title = '" . $title->getDBkey() . "'" .
- ' AND old_user = 0 ', DB_READ, $fname);
-
- while ( $line = wfFetchObject( $res ) ) {
- $contribs[0] = array($line->cnt, 'Anonymous');
- }
-
+ $contribs[] = array($line->old_user, $line->old_user_text, $line->user_real_name);
+ }
+
+ wfFreeResult($res);
+
return $contribs;
}
wfProfileOut( $fname );
}
-function getCredits($article, $cnt) {
+function getCredits($article, $cnt, $showIfMax=true) {
$s = '';
if (isset($cnt) && $cnt != 0) {
$s = getAuthorCredits($article);
if ($cnt > 1 || $cnt < 0) {
- $s .= ' ' . getContributorCredits($article, $cnt - 1);
+ $s .= ' ' . getContributorCredits($article, $cnt - 1, $showIfMax);
}
}
return wfMsg('lastmodifiedby', $d, $author_credit);
}
-function getContributorCredits($article, $cnt) {
+function getContributorCredits($article, $cnt, $showIfMax) {
global $wgLang, $wgAllowRealName;
- $contributors = $article->getContributors($cnt);
+ $contributors = $article->getContributors();
+
+ $others_link = '';
+ # Hmm... too many to fit!
+
+ if ($cnt > 0 && count($contributors) > $cnt) {
+ $others_link = creditOthersLink($article);
+ if (!$showIfMax) {
+ return wfMsg('othercontribs', $others_link);
+ } else {
+ $contributors = array_slice($contributors, 0, $cnt);
+ }
+ }
+
$real_names = array();
$user_names = array();
+ $anon = '';
+
# Sift for real versus user names
- foreach ($contributors as $user_id => $user_parts) {
- if ($user_id != 0) {
- if ($wgAllowRealName && !empty($user_parts[1])) {
- $real_names[$user_id] = creditLink($user_parts[0], $user_parts[1]);
+ foreach ($contributors as $user_parts) {
+ if ($user_parts[0] != 0) {
+ if ($wgAllowRealName && !empty($user_parts[2])) {
+ $real_names[$user_id] = creditLink($user_parts[1], $user_parts[2]);
} else {
- $user_names[$user_id] = creditLink($user_parts[0]);
+ $user_names[$user_id] = creditLink($user_parts[1]);
}
+ } else {
+ $anon = wfMsg('anonymous');
}
}
+
+ # Two strings: real names, and user names
$real = $wgLang->listToText(array_values($real_names));
$user = $wgLang->listToText(array_values($user_names));
+
+ # "ThisSite user(s) A, B and C"
if (!empty($user)) {
- $user = wfMsg('siteusers', $user);
+ $user = wfMsg('siteusers', $user);
}
+
+ # This is the big list, all mooshed together. We sift for blank strings
- if ($contributors[0] && $contributors[0][0] > 0) {
- $anon = wfMsg('anonymous');
- } else {
- $anon = '';
+ $fulllist = array();
+
+ foreach (array($real, $user, $anon, $others_link) as $s) {
+ if (!empty($s)) {
+ array_push($fulllist, $s);
+ }
}
+
+ # Make the list into text...
- $creds = $wgLang->listToText(array($real, $user, $anon));
+ $creds = $wgLang->listToText($fulllist);
+
+ # "Based on work by ..."
return wfMsg('othercontribs', $creds);
}
(empty($link_text)) ? $user_name : $link_text);
}
+function creditOthersLink($article) {
+ global $wgUser, $wgLang;
+ $skin = $wgUser->getSkin();
+ return $skin->makeKnownLink($article->mTitle->getPrefixedText(), wfMsg('others'), "action=credits");
+}
+
?>
# Set this to the number of authors that you want to be credited below an
# article text. Set it to zero to hide the attribution block, and a
# negative number (like -1) to show all authors. Note that this will
-# require checking the table of old revisions, which can have a significant
+# require 2-3 extra database hits, which can have a not insignificant
# impact on performance for large wikis.
$wgMaxCredits = 0;
+# If there are more than $wgMaxCredits authors, show $wgMaxCredits of them.
+# Otherwise, link to a separate credits page.
+$wgShowCreditsIfMax = true;
+
# Text matching this regular expression will be recognised as spam
# See http://en.wikipedia.org/wiki/Regular_expression
$wgSpamRegex = false;
$contributors = $article->getContributors();
- foreach ($contributors as $cid => $user_parts) {
- dcPerson('contributor', $cid, $user_parts[0], $user_parts[1]);
+ foreach ($contributors as $user_parts) {
+ dcPerson('contributor', $user_parts[0], $user_parts[1], $user_parts[2]);
}
dcRights($article);
function pageStats()
{
global $wgOut, $wgLang, $wgArticle, $wgRequest;
- global $wgDisableCounters, $wgMaxCredits;
+ global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax;
extract( $wgRequest->getValues( 'oldid', 'diff' ) );
if ( ! $wgOut->isArticle() ) { return ''; }
if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
require_once("Credits.php");
- $s .= ' ' . getCredits($wgArticle, $wgMaxCredits);
+ $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
} else {
$s .= $this->lastModified();
}