From: Evan Prodromou Date: Mon, 28 Jun 2004 20:24:23 +0000 (+0000) Subject: Only show last N contributors in the credits. Unfortunately, this required a X-Git-Tag: 1.5.0alpha1~2752 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=51a38cfbc52ebfd8964f2185837ae3447722f7bc;p=lhc%2Fweb%2Fwiklou.git Only show last N contributors in the credits. Unfortunately, this required a change in the getContributors() method of Article, which in turn required some code changes in the Metadata module. However, it now seems to work. If the number of contributors is greater than N, then show a link to the full credits page. An additional bit: it may be that we don't want to show _any_ contributors if we are over the max. So, there's a flag to check this. --- diff --git a/includes/Article.php b/includes/Article.php index 6dea6747dc..5bbc6d2a6f 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -597,13 +597,11 @@ class Article { $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 '; @@ -615,22 +613,11 @@ class Article { $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; } diff --git a/includes/Credits.php b/includes/Credits.php index 1f370f1832..66d54a1bb9 100644 --- a/includes/Credits.php +++ b/includes/Credits.php @@ -45,14 +45,14 @@ function showCreditsPage($article) 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); } } @@ -88,41 +88,70 @@ function getAuthorCredits($article) { 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); } @@ -134,4 +163,10 @@ function creditLink($user_name, $link_text = '') { (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"); +} + ?> diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 9c2640db6a..a78d784681 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -375,10 +375,14 @@ $wgImportSources = array(); # 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; diff --git a/includes/Metadata.php b/includes/Metadata.php index 49a2275c34..00cb9ca3a1 100644 --- a/includes/Metadata.php +++ b/includes/Metadata.php @@ -119,8 +119,8 @@ function wfCreativeCommonsRdf($article) { $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); diff --git a/includes/Skin.php b/includes/Skin.php index 3387ebdcb6..c14b37703f 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -768,7 +768,7 @@ class Skin { function pageStats() { global $wgOut, $wgLang, $wgArticle, $wgRequest; - global $wgDisableCounters, $wgMaxCredits; + global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax; extract( $wgRequest->getValues( 'oldid', 'diff' ) ); if ( ! $wgOut->isArticle() ) { return ''; } @@ -785,7 +785,7 @@ class Skin { if (isset($wgMaxCredits) && $wgMaxCredits != 0) { require_once("Credits.php"); - $s .= ' ' . getCredits($wgArticle, $wgMaxCredits); + $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax); } else { $s .= $this->lastModified(); }