jenkins-bot has submitted this change and it was merged.

Change subject: Sort member list between active/inactive.
......................................................................


Sort member list between active/inactive.

Probably needs to tweak how transclusion works.

Bug: T141184
Change-Id: I5d92bdb3545edfae1a0c1d4d2704130478a13d1b
---
M i18n/en.json
M i18n/qqq.json
M includes/content/CollaborationListContent.php
3 files changed, 62 insertions(+), 21 deletions(-)

Approvals:
  Brian Wolff: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/i18n/en.json b/i18n/en.json
index 758bf87..62f7fb9 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -115,5 +115,7 @@
        "collaborationkit-green1": "Forest green",
        "collaborationkit-green2": "Bright green",
        "collaborationkit-green3": "Khaki",
-       "collaborationkit-black": "Black"
+       "collaborationkit-black": "Black",
+       "collaborationkit-column-active": "Active members",
+       "collaborationkit-column-inactive": "Inactive members"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 2859656..51ea868 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -115,5 +115,7 @@
        "collaborationkit-green1": "Color label",
        "collaborationkit-green2": "Color label",
        "collaborationkit-green3": "Color label",
-       "collaborationkit-black": "Color label"
+       "collaborationkit-black": "Color label",
+       "collaborationkit-column-active": "Column header for the list of active 
members of a collaboration hub project",
+       "collaborationkit-column-inactive": "Column header for the list of 
members of a project who are no longer active on wiki."
 }
diff --git a/includes/content/CollaborationListContent.php 
b/includes/content/CollaborationListContent.php
index 46ba902..6a8012d 100644
--- a/includes/content/CollaborationListContent.php
+++ b/includes/content/CollaborationListContent.php
@@ -234,10 +234,16 @@
                        return $text;
                }
 
-               $listclass = count( $this->columns ) > 1 ? 'mw-ck-multilist' : 
'mw-ck-singlelist';
+               if ( $this->displaymode === 'members' && count( $this->columns 
) === 1 ) {
+                       $columns = $this->sortUsersIntoColumns( 
$this->columns[0] );
+               } else {
+                       $columns = $this->columns;
+               }
+
+               $listclass = count( $columns ) > 1 ? 'mw-ck-multilist' : 
'mw-ck-singlelist';
                $text .= '<div class="mw-ck-list ' . $listclass . '">' . "\n";
                $offset = $options['defaultSort'] === 'random' ? 0 : 
$options['offset'];
-               foreach ( $this->columns as $column ) {
+               foreach ( $columns as $column ) {
                        $text .= '<div class="mw-ck-list-column">' . "\n";
                        if ( isset( $column->label ) && $column->label !== '' ) 
{
                                $text .= "=== {$column->label} ===\n";
@@ -833,17 +839,53 @@
        }
 
        /**
+        * Sort users into active/inactive column
+        *
+        * @param $column Array An array containing key items, which
+        *  is an array of stdClass's representing each list item.
+        *  Each of these has a key named title which contains
+        *  a user name (including namespace). May have non-users too.
+        * @return Array Two column structure sorted active/inactive.
+        * @todo Should link property be taken into account as actual name?
+        */
+       private function sortUsersIntoColumns( $column ) {
+               $nonUserItems = [];
+               $userItems = [];
+               foreach ( $column->items as $item ) {
+                       $title = Title::newFromText( $item->title );
+                       if ( !$title ||
+                               !$title->inNamespace( NS_USER ) ||
+                               $title->isSubpage()
+                       ) {
+                               $nonUserItems[] = $item;
+                       } else {
+                               $userItems[ $title->getDBKey() ] = $item;
+                       }
+               }
+               $res = $this->filterActiveUsers( $userItems );
+               $inactiveFlatList = array_merge( array_values( $res['inactive'] 
), $nonUserItems );
+
+               $activeColumn = (object)[
+                       'items' => array_values( $res['active'] ),
+                       'label' => wfMessage( 'collaborationkit-column-active' 
)->inContentLanguage()->text(),
+               ];
+               $inactiveColumn = (object)[
+                       'items' => $inactiveFlatList,
+                       'label' => wfMessage( 
'collaborationkit-column-inactive' )->inContentLanguage()->text(),
+               ];
+
+               return [ $activeColumn, $inactiveColumn ];
+       }
+
+       /**
         * Filter users into active and inactive.
         *
-        * @param $userList Array of titles
+        * @note The results of this function get stored in parser cache.
+        * @param $userList Array of user dbkeys => stdClass
         * @return Array [ 'active' => [..], 'inactive' => '[..]' ]
         */
-       public function filterActiveUsers( $userList ) {
-               $users = [];
-               foreach ( $userList as $user ) {
-                       $users[] = $user->getDBKey();
-               }
-
+       private function filterActiveUsers( $userList ) {
+               $users = array_keys( $userList );
                $dbr = wfGetDB( DB_REPLICA );
                $res = $dbr->select(
                        'querycachetwo',
@@ -853,21 +895,16 @@
                                // TODO: Perhaps should use batching.
                                'qcc_title' => $users,
                                'qcc_type' => 'activeusers'
-                       ]
+                       ],
+                       __METHOD__
                );
 
                $active = [];
-               $inactive = [];
-               $usersFlipped = array_flip( $users );
                foreach ( $res as $row ) {
-                       $active[] = Title::makeTitle( NS_USER, $row->qcc_title 
);
-                       unset( $usersFlipped[$row->qcc_title] );
+                       $active[$row->qcc_title] = $userList[$row->qcc_title];
+                       unset( $userList[$row->qcc_title] );
                }
-               $remainingUsers = array_keys( $usersFlipped );
-               foreach ( $remainingUsers as $user ) {
-                       $inactive[] = Title::makeTitleSafe( NS_USER, $user );
-               }
-               return [ 'active' => $active, 'inactive' => $inactive ];
+               return [ 'active' => $active, 'inactive' => $userList ];
        }
 
        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/322153
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I5d92bdb3545edfae1a0c1d4d2704130478a13d1b
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/CollaborationKit
Gerrit-Branch: master
Gerrit-Owner: Brian Wolff <bawolff...@gmail.com>
Gerrit-Reviewer: Brian Wolff <bawolff...@gmail.com>
Gerrit-Reviewer: Siebrand <siebr...@kitano.nl>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to