Only show last N contributors in the credits. Unfortunately, this required a
authorEvan Prodromou <evanprodromou@users.mediawiki.org>
Mon, 28 Jun 2004 20:24:23 +0000 (20:24 +0000)
committerEvan Prodromou <evanprodromou@users.mediawiki.org>
Mon, 28 Jun 2004 20:24:23 +0000 (20:24 +0000)
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.

includes/Article.php
includes/Credits.php
includes/DefaultSettings.php
includes/Metadata.php
includes/Skin.php

index 6dea674..5bbc6d2 100644 (file)
@@ -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;
        }
     
index 1f370f1..66d54a1 100644 (file)
@@ -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");
+}
+
 ?>
index 9c2640d..a78d784 100644 (file)
@@ -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; 
index 49a2275..00cb9ca 100644 (file)
@@ -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);
index 3387ebd..c14b377 100644 (file)
@@ -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();
                }