Jack Phoenix has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/82199


Change subject: SocialProfile: restored filter feature on UserActivity.
......................................................................

SocialProfile: restored filter feature on UserActivity.

Original code is by the ArmchairGM developers, from the ArmchairGM, with
cleanup and modernization by me.

Also added some code for supporting network updates (SportsTeams
extension).

Change-Id: Ifac6f9676a9592d7d9f2d096a0c1fb7dc7e211d1
---
M UserActivity/UserActivity.body.php
M UserActivity/UserActivity.i18n.php
M UserActivity/UserActivityClass.php
M UserProfile/UserProfilePage.php
A images/note.gif
5 files changed, 186 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SocialProfile 
refs/changes/99/82199/1

diff --git a/UserActivity/UserActivity.body.php 
b/UserActivity/UserActivity.body.php
index 8b725be..fdf3b82 100644
--- a/UserActivity/UserActivity.body.php
+++ b/UserActivity/UserActivity.body.php
@@ -34,6 +34,11 @@
                $out->setPageTitle( $this->msg( 'useractivity-title' )->plain() 
);
 
                $output = '';
+               // Initialize all of these or otherwise we get a lot of 
E_NOTICEs about
+               // undefined variables when the filtering feature (described 
below) is
+               // active and we're viewing a filtered-down feed
+               $edits = $votes = $comments = $comments = $gifts = 
$relationships =
+                       $messages = $system_gifts = $messages_sent = 
$network_updates = 0;
 
                $rel_type = $request->getVal( 'rel_type' );
                $item_type = $request->getVal( 'item_type' );
@@ -70,6 +75,55 @@
                if ( $item_type == 'messages' || $item_type == 'all' ) {
                        $messages_sent = 1;
                }
+               if ( $item_type == 'thoughts' || $item_type == 'all' ) {
+                       $network_updates = 1;
+               }
+
+               // Filtering feature, if enabled
+               // The filter message's format is:
+               // *filter name (item_type URL parameter)|Displayed text (can 
be the name of a MediaWiki: message, too)|Type icon name (*not* the image name; 
see UserActivity::getTypeIcon())
+               // For example:
+               // *messages|Board Messages|user_message
+               // This would add a link that allows filtering non-board 
messages
+               // related events from the filter, only showing board message 
activity
+
+               $filterMsg = $this->msg( 'useractivity-friendsactivity-filter' 
);
+               if ( !$filterMsg->isDisabled() ) {
+                       $output .= '<div class="user-home-links-container">
+                       <h2>' . $this->msg( 'useractivity-filter' )->plain() . 
'</h2>
+                       <div class="user-home-links">';
+
+                       $lines = explode( "\n", 
$filterMsg->inContentLanguage()->text() );
+
+                       foreach ( $lines as $line ) {
+                               if ( strpos( $line, '*' ) !== 0 ) {
+                                       continue;
+                               } else {
+                                       $line = explode( '|' , trim( $line, '* 
' ), 3 );
+                                       $filter = $line[0];
+                                       $link_text = $line[1];
+
+                                       // Maybe it's the name of a MediaWiki: 
message? I18n is
+                                       // always nice, so at least try it and 
see what happens...
+                                       $linkMsgObj = wfMessage( $link_text );
+                                       if ( !$linkMsgObj->isDisabled() ) {
+                                               $link_text = 
$linkMsgObj->parse();
+                                       }
+
+                                       $link_image = $line[2];
+                                       $output .= '<a href="' . 
$this->getTitle()->escapeFullURL( "item_type={$filter}" ) .
+                                               "\"><img 
src=\"{$wgExtensionAssetsPath}/SocialProfile/images/" .
+                                               UserActivity::getTypeIcon( 
$link_image ) . "\"/>{$link_text}</a>";
+                               }
+                       }
+
+                       $output .= Linker::link(
+                               $this->getTitle(),
+                               $this->msg( 'useractivity-all' )->plain()
+                       );
+                       $output .= '</div>
+                       </div>';
+               }
 
                $output .= '<div class="user-home-feed">';
 
@@ -82,6 +136,7 @@
                $rel->setActivityToggle( 'show_system_messages', $messages );
                $rel->setActivityToggle( 'show_system_gifts', $system_gifts );
                $rel->setActivityToggle( 'show_messages_sent', $messages_sent );
+               $rel->setActivityToggle( 'show_network_updates', 
$network_updates );
 
                /**
                 * Get all relationship activity
diff --git a/UserActivity/UserActivity.i18n.php 
b/UserActivity/UserActivity.i18n.php
index 9e28abb..ae24c2f 100644
--- a/UserActivity/UserActivity.i18n.php
+++ b/UserActivity/UserActivity.i18n.php
@@ -18,12 +18,15 @@
        'useractivity-all' => 'View all',
        'useractivity-edit' => '$1 {{PLURAL:$4|edited the page|edited the 
following pages:}} $3', // Supports GENDER for the editor ($1) as $6 if $1 is 
one user.
        'useractivity-foe' => '$1 {{PLURAL:$2|is now foes with|are now foes 
with}} $3', // Supports GENDER for $1 as $6 if $1 is one user.
+       'useractivity-filter' => 'Filter',
        'useractivity-friend' => '$1 {{PLURAL:$2|is now friends with|are now 
friends with}} $3', // Supports GENDER for the $1 as $6 if $1 is one user.
+       'useractivity-friendsactivity-filter' => '',
        'useractivity-gift' => '$1 received a gift from $2', // Supports GENDER 
for the editor ($1) as $6 if $1 is one user.
        'useractivity-group-edit' => '{{PLURAL:$1|one edit|$1 edits}}', // 
Supports GENDER for the one having made edits as $2
        'useractivity-group-comment' => '{{PLURAL:$1|one comment|$1 
comments}}', // Supports GENDER for the one having made comments as $2
        'useractivity-group-user_message' => '{{PLURAL:$1|one message|$1 
messages}}', // Supports GENDER for the one having messages as $2
        'useractivity-group-friend' => '{{PLURAL:$1|one friend|$1 friends}}', 
// Supports GENDER for the one having friends as $2
+       'useractivity-network-thought' => '<b><a href="$4">$2</a></b> has a 
thought for the $3 network',
        'useractivity-siteactivity' => 'Site activity',
        'useractivity-title' => "Friends' activity",
        'useractivity-user_message' => '$1 {{PLURAL:$4|sent a message to|sent 
messages to}} $3', // Supports GENDER for the sender ($1) as $6 if $1 is one 
user.
diff --git a/UserActivity/UserActivityClass.php 
b/UserActivity/UserActivityClass.php
index 4ff5a1c..ec33614 100644
--- a/UserActivity/UserActivityClass.php
+++ b/UserActivity/UserActivityClass.php
@@ -13,6 +13,7 @@
        private $user_name;             # Text form (spaces not underscores) of 
the main part
        private $items;         # Text form (spaces not underscores) of the 
main part
        private $rel_type;
+       private $show_current_user = false;
        private $show_edits = 1;
        private $show_votes = 0;
        private $show_comments = 1;
@@ -22,6 +23,7 @@
        private $show_system_gifts = 1;
        private $show_system_messages = 1;
        private $show_messages_sent = 1;
+       private $show_network_updates = 0;
 
        /**
         * Constructor
@@ -831,6 +833,112 @@
                }
        }
 
+       /**
+        * Get recent network updates (but only if the SportsTeams extension is
+        * installed) and set them in the appropriate class member variables.
+        */
+       private function setNetworkUpdates() {
+               global $wgLang;
+
+               if ( !class_exists( 'SportsTeams' ) ) {
+                       return;
+               }
+
+               $dbr = wfGetDB( DB_SLAVE );
+
+               $where = array();
+
+               if ( !empty( $this->rel_type ) ) {
+                       $users = $dbr->select(
+                               'user_relationship',
+                               'r_user_id_relation',
+                               array(
+                                       'r_user_id' => $this->user_id,
+                                       'r_type' => $this->rel_type
+                               ),
+                               __METHOD__
+                       );
+                       $userArray = array();
+                       foreach ( $users as $user ) {
+                               $userArray[] = $user;
+                       }
+                       $userIDs = implode( ',', $userArray );
+                       if ( !empty( $userIDs ) ) {
+                               $where[] = "us_user_id IN ($userIDs)";
+                       }
+               }
+
+               if ( $this->show_current_user ) {
+                       $where['us_user_id'] = $this->user_id;
+               }
+
+               $res = $dbr->select(
+                       'user_status',
+                       array(
+                               'us_id', 'us_user_id', 'us_user_name', 
'us_text',
+                               'UNIX_TIMESTAMP(us_date) AS item_date', 
'us_sport_id',
+                               'us_team_id'
+                       ),
+                       $where,
+                       __METHOD__,
+                       array(
+                               'ORDER BY' => 'us_id DESC',
+                               'LIMIT' => $this->item_max,
+                               'OFFSET' => 0
+                       )
+               );
+
+               foreach ( $res as $row ) {
+                       if ( $row->us_team_id ) {
+                               $team = SportsTeams::getTeam( $row->us_team_id 
);
+                               $network_name = $team['name'];
+                       } else {
+                               $sport = SportsTeams::getSport( 
$row->us_sport_id );
+                               $network_name = $sport['name'];
+                       }
+
+                       $this->items[] = array(
+                               'id' => $row->us_id,
+                               'type' => 'network_update',
+                               'timestamp' => $row->item_date,
+                               'pagetitle' => '',
+                               'namespace' => '',
+                               'username' => $row->us_user_name,
+                               'userid' => $row->us_user_id,
+                               'comment' => $row->us_text,
+                               'sport_id' => $row->us_sport_id,
+                               'team_id' => $row->us_team_id,
+                               'network' => $network_name
+                       );
+
+                       $user_title = Title::makeTitle( NS_USER, 
$row->us_user_name );
+                       $user_name_short = $wgLang->truncate( 
$row->us_user_name, 15 );
+                       $page_link = '<a href="' . SportsTeams::getNetworkURL( 
$row->us_sport_id, $row->us_team_id ) .
+                               "\" rel=\"nofollow\">{$network_name}</a>";
+                       $network_image = SportsTeams::getLogo( 
$row->us_sport_id, $row->us_team_id, 's' );
+
+                       $html = wfMessage(
+                               'useractivity-network-thought',
+                               $row->us_user_name,
+                               $user_name_short,
+                               $page_link,
+                               $user_title->escapeFullURL()
+                       )->text() .
+                                       '<div class="item">
+                                               <a href="' . 
SportsTeams::getNetworkURL( $row->us_sport_id, $row->us_team_id ) . "\" 
rel=\"nofollow\">
+                                                       {$network_image}
+                                                       \"{$row->us_text}\"
+                                               </a>
+                                       </div>";
+
+                       $this->activityLines[] = array(
+                               'type' => 'network_update',
+                               'timestamp' => $row->item_date,
+                               'data' => $html,
+                       );
+               }
+       }
+
        public function getEdits() {
                $this->setEdits();
                return $this->items;
@@ -876,6 +984,11 @@
                return $this->items;
        }
 
+       public function getNetworkUpdates() {
+               $this->setNetworkUpdates();
+               return $this->items;
+       }
+
        public function getActivityList() {
                if ( $this->show_edits ) {
                        $this->setEdits();
@@ -903,6 +1016,9 @@
                }
                if ( $this->show_messages_sent ) {
                        $this->getMessagesSent();
+               }
+               if ( $this->show_network_updates ) {
+                       $this->getNetworkUpdates();
                }
 
                if ( $this->items ) {
@@ -933,9 +1049,11 @@
                if ( !isset( $this->activityLines ) ) {
                        $this->activityLines = array();
                }
+
                if ( isset( $this->activityLines ) && is_array( 
$this->activityLines ) ) {
                        usort( $this->activityLines, array( 'UserActivity', 
'sortItems' ) );
                }
+
                return $this->activityLines;
        }
 
@@ -1092,6 +1210,8 @@
                                return 'awardIcon.png';
                        case 'user_message':
                                return 'emailIcon.gif';
+                       case 'network_update':
+                               return 'note.gif';
                }
        }
 
diff --git a/UserProfile/UserProfilePage.php b/UserProfile/UserProfilePage.php
index f8d7686..eed01a3 100644
--- a/UserProfile/UserProfilePage.php
+++ b/UserProfile/UserProfilePage.php
@@ -1241,6 +1241,14 @@
                                                                
\"{$item['namespace']}\"
                                                                </div>";
                                                break;
+                                       case 'network_update':
+                                               $network_image = 
SportsTeams::getLogo( $item['sport_id'], $item['team_id'], 's' );
+                                               $item_html .= wfMsg( 
"user-recent-activity-network-update" ) .
+                                                               '<div 
class="item">
+                                                                       <a 
href="' . SportsTeams::getNetworkURL( $item['sport_id'], $item['team_id'] ) .
+                                                                       "\" 
rel=\"nofollow\">{$network_image} \"{$item['comment']}\"</a>
+                                                               </div>";
+                                               break;
                                        }
 
                                        $item_html .= '</div>';
diff --git a/images/note.gif b/images/note.gif
new file mode 100644
index 0000000..17b9f41
--- /dev/null
+++ b/images/note.gif
Binary files differ

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifac6f9676a9592d7d9f2d096a0c1fb7dc7e211d1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SocialProfile
Gerrit-Branch: master
Gerrit-Owner: Jack Phoenix <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to