* (bug 16310) Credits page now lists IP addresses rather than saying the number of...
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Wed, 23 Sep 2009 11:31:52 +0000 (11:31 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Wed, 23 Sep 2009 11:31:52 +0000 (11:31 +0000)
* Some whitespaces fixes

RELEASE-NOTES
includes/Article.php
includes/Credits.php
languages/messages/MessagesEn.php
maintenance/language/messages.inc

index 303e194..644dc3d 100644 (file)
@@ -242,6 +242,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * New configuration variable $wgShowPageOnRedlink that can be set to show the page
   instead of an edit interface when visiting a red link. The value can be specified
   for specific usergroups and namespaces.
+* (bug 16310) Credits page now lists IP addresses rather than saying the number
+  of anonymous users that edited the page
 
 === Bug fixes in 1.16 ===
 
index 67cb5a6..900ffab 100644 (file)
@@ -692,29 +692,36 @@ class Article {
        public function getContributors($limit = 0, $offset = 0) {
                # XXX: this is expensive; cache this info somewhere.
 
-               $contribs = array();
                $dbr = wfGetDB( DB_SLAVE );
                $revTable = $dbr->tableName( 'revision' );
                $userTable = $dbr->tableName( 'user' );
-               $user = $this->getUser();
+
                $pageId = $this->getId();
 
-               $deletedBit = $dbr->bitAnd('rev_deleted', Revision::DELETED_USER); // username hidden?
+               $user = $this->getUser();
+               if ( $user ) {
+                       $excludeCond = "AND rev_user != $user";
+               } else {
+                       $userText = $dbr->addQuotes( $this->getUserText() );
+                       $excludeCond = "AND rev_user_text != $userText";
+               }
+
+               $deletedBit = $dbr->bitAnd( 'rev_deleted', Revision::DELETED_USER ); // username hidden?
 
-               $sql = "SELECT {$userTable}.*, MAX(rev_timestamp) as timestamp
+               $sql = "SELECT {$userTable}.*, rev_user_text as user_name, MAX(rev_timestamp) as timestamp
                        FROM $revTable LEFT JOIN $userTable ON rev_user = user_id
                        WHERE rev_page = $pageId
-                       AND rev_user != $user
+                       $excludeCond
                        AND $deletedBit = 0
-                       GROUP BY rev_user, rev_user_text, user_real_name
+                       GROUP BY rev_user, rev_user_text
                        ORDER BY timestamp DESC";
 
-               if($limit > 0)
-                       $sql = $dbr->limitResult($sql, $limit, $offset);
-
-               $sql .= ' '. $this->getSelectOptions();
+               if ( $limit > 0 )
+                       $sql = $dbr->limitResult( $sql, $limit, $offset );
 
-               $res = $dbr->query($sql, __METHOD__ );
+               $sql .= ' ' . $this->getSelectOptions();
+               wfVarDump( $sql );
+               $res = $dbr->query( $sql, __METHOD__ );
 
                return new UserArrayFromResult( $res );
        }
index ad7e029..35d4197 100644 (file)
@@ -55,13 +55,13 @@ class Credits {
         * @param $showIfMax Bool: whether to contributors if there more than $cnt
         * @return String: html
         */
-       public static function getCredits($article, $cnt, $showIfMax=true) {
+       public static function getCredits( Article $article, $cnt, $showIfMax = true ) {
                wfProfileIn( __METHOD__ );
                $s = '';
 
                if( isset( $cnt ) && $cnt != 0 ){
                        $s = self::getAuthor( $article );
-                       if ($cnt > 1 || $cnt < 0) {
+                       if ( $cnt > 1 || $cnt < 0 ) {
                                $s .= ' ' . self::getContributors( $article, $cnt - 1, $showIfMax );
                        }
                }
@@ -102,7 +102,7 @@ class Credits {
        
                $contributors = $article->getContributors();
        
-               $others_link = '';
+               $others_link = false;
        
                # Hmm... too many to fit!
                if( $cnt > 0 && $contributors->count() > $cnt ){
@@ -113,7 +113,7 @@ class Credits {
        
                $real_names = array();
                $user_names = array();
-               $anon = 0;
+               $anon_ips = array();
        
                # Sift for real versus user names
                foreach( $contributors as $user ) {
@@ -125,26 +125,36 @@ class Credits {
                                else
                                        $user_names[] = $link;
                        } else {
-                               $anon++;
+                               $anon_ips[] = self::link( $user );
                        }
                        if( $cnt == 0 ) break;
                }
        
-               # Two strings: real names, and user names
-               $real = $wgLang->listToText( $real_names );
-               $user = $wgLang->listToText( $user_names );
-               if( $anon )
-                       $anon = wfMsgExt( 'anonymous', array( 'parseinline' ), $anon );
+               if ( count( $real_names ) ) {
+                       $real = $wgLang->listToText( $real_names );
+               } else {
+                       $real = false;
+               }
        
                # "ThisSite user(s) A, B and C"
-               if( !empty( $user ) ){
-                       $user = wfMsgExt( 'siteusers', array( 'parsemag' ), $user, count( $user_names ) );
+               if( count( $user_names ) ){
+                       $user = wfMsgExt( 'siteusers', array( 'parsemag' ),
+                               $wgLang->listToText( $user_names ), count( $user_names ) );
+               } else {
+                       $user = false;
+               }
+
+               if( count( $anon_ips ) ){
+                       $anon = wfMsgExt( 'anonusers', array( 'parsemag' ),
+                               $wgLang->listToText( $anon_ips ), count( $anon_ips ) );
+               } else {
+                       $anon = false;
                }
        
                # This is the big list, all mooshed together. We sift for blank strings
                $fulllist = array();
                foreach( array( $real, $user, $anon, $others_link ) as $s ){
-                       if( !empty( $s ) ){
+                       if( $s ){
                                array_push( $fulllist, $s );
                        }
                }
@@ -153,7 +163,7 @@ class Credits {
                $creds = $wgLang->listToText( $fulllist );
 
                # "Based on work by ..."
-               return empty( $creds ) ? '' : wfMsg( 'othercontribs', $creds );
+               return strlen( $creds ) ? wfMsg( 'othercontribs', $creds ) : '';
        }
 
        /**
@@ -163,13 +173,15 @@ class Credits {
         */
        protected static function link( User $user ) {
                global $wgUser, $wgHiddenPrefs;
-               if( !in_array( 'realname', $wgHiddenPrefs ) )
+               if( !in_array( 'realname', $wgHiddenPrefs ) && !$user->isAnon() )
                        $real = $user->getRealName();
                else
                        $real = false;
 
                $skin = $wgUser->getSkin();
-               $page = $user->getUserPage();
+               $page = $user->isAnon() ?
+                       SpecialPage::getTitleFor( 'Contributions', $user->getName() ) :
+                       $user->getUserPage();
 
                return $skin->link( $page, htmlspecialchars( $real ? $real : $user->getName() ) );
        }
@@ -181,11 +193,11 @@ class Credits {
         * @return String: html
         */
        protected static function userLink( User $user ) {
+               $link = self::link( $user );
                if( $user->isAnon() ){
-                       return wfMsgExt( 'anonymous', array( 'parseinline' ), 1 );
+                       return wfMsgExt( 'anonuser', array( 'parseinline', 'replaceafter' ), $link );
                } else {
                        global $wgHiddenPrefs;
-                       $link = self::link( $user );
                        if( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() )
                                return $link;
                        else 
index 7ca405e..9141469 100644 (file)
@@ -3362,10 +3362,12 @@ It allows adding a reason in the summary.',
 # Attribution
 'anonymous'        => 'Anonymous {{PLURAL:$1|user|users}} of {{SITENAME}}',
 'siteuser'         => '{{SITENAME}} user $1',
+'anonuser'         => '{{SITENAME}} anonymous user $1',
 'lastmodifiedatby' => 'This page was last modified $2, $1 by $3.',
 'othercontribs'    => 'Based on work by $1.',
 'others'           => 'others',
 'siteusers'        => '{{SITENAME}} {{PLURAL:$2|user|users}} $1',
+'anonusers'        => '{{SITENAME}} anonymous {{PLURAL:$2|user|users}} $1',
 'creditspage'      => 'Page credits',
 'nocredits'        => 'There is no credits info available for this page.',
 
index c046769..13aca82 100644 (file)
@@ -2350,10 +2350,12 @@ $wgMessageStructure = array(
        'attribution' => array(
                'anonymous',
                'siteuser',
+               'anonuser',
                'lastmodifiedatby',
                'othercontribs',
                'others',
                'siteusers',
+               'anonusers',
                'creditspage',
                'nocredits',
        ),