]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch '1.0.x'
authorEvan Prodromou <evan@status.net>
Wed, 21 Mar 2012 20:40:51 +0000 (16:40 -0400)
committerEvan Prodromou <evan@status.net>
Wed, 21 Mar 2012 20:40:51 +0000 (16:40 -0400)
EVENTS.txt
classes/Notice.php
lib/default.php
lib/filteringnoticestream.php
lib/groupnoticestream.php
lib/noticelist.php
lib/noticelistitem.php
lib/profileaction.php
lib/profilenoticestream.php
lib/scopingnoticestream.php

index 8358bed0b7dc75b505937eb7dc0afb344d02bb9f..0c08a46478b26a3bd784544bd5b30cd89e98bc86 100644 (file)
@@ -1425,3 +1425,28 @@ EndUpgrade: when ending a site upgrade; good place to do your own upgrades
 HaveIMPlugin: is there an IM plugin loaded?
 - &$haveIMPlugin: set me to true if you're loaded!
 
+StartShowNoticeOptionItems: Before showing first controls in a notice list item; inside the div
+- $nli: NoticeListItem being shown
+
+EndShowNoticeOptionItems: After showing last controls in a notice list item; inside the div
+- $nli: NoticeListItem being shown
+
+StartNoticeInScope: Before checking if a notice should be visible to a user
+- $notice: The notice to check
+- $profile: The profile to check for scope
+- &$bResult: The boolean result; fill this in if you want to skip
+
+EndNoticeInScope: After checking if a notice should be visible to a user
+- $notice: The notice to check
+- $profile: The profile to check for scope
+- &$bResult: The boolean result; overwrite this if you so desire
+
+StartNoticeListPrefill: Before pre-filling a list of notices with extra data
+- &$notices: Notices to be pre-filled
+- $avatarSize: The avatar size for the list
+
+EndNoticeListPrefill: After pre-filling a list of notices with extra data
+- &$notices: Notices that were pre-filled
+- &$profiles: Profiles that were pre-filled 
+- $avatarSize: The avatar size for the list
+
index b186b3ad086c4fcb7ea41058eca150e4d63d80ff..a0b2e910658077273120bcdf9c81c4eae73ee06d 100644 (file)
@@ -2365,7 +2365,11 @@ class Notice extends Managed_DataObject
         $result = self::cacheGet($keypart);
 
         if ($result === false) {
-            $bResult = $this->_inScope($profile);
+            $bResult = false;
+            if (Event::handle('StartNoticeInScope', array($this, $profile, &$bResult))) {
+                $bResult = $this->_inScope($profile);
+                Event::handle('EndNoticeInScope', array($this, $profile, &$bResult));
+            }
             $result = ($bResult) ? 1 : 0;
             self::cacheSet($keypart, $result, 0, 300);
         }
@@ -2383,75 +2387,100 @@ class Notice extends Managed_DataObject
 
         // If there's no scope, anyone (even anon) is in scope.
 
-        if ($scope == 0) {
-            return true;
-        }
+        if ($scope == 0) { // Not private
 
-        // If there's scope, anon cannot be in scope
+            return !$this->isHiddenSpam($profile);
 
-        if (empty($profile)) {
-            return false;
-        }
+        } else { // Private, somehow
 
-        // Author is always in scope
+            // If there's scope, anon cannot be in scope
 
-        if ($this->profile_id == $profile->id) {
-            return true;
-        }
+            if (empty($profile)) {
+                return false;
+            }
 
-        // Only for users on this site
+            // Author is always in scope
 
-        if ($scope & Notice::SITE_SCOPE) {
-            $user = $profile->getUser();
-            if (empty($user)) {
-                return false;
+            if ($this->profile_id == $profile->id) {
+                return true;
+            }
+
+            // Only for users on this site
+
+            if ($scope & Notice::SITE_SCOPE) {
+                $user = $profile->getUser();
+                if (empty($user)) {
+                    return false;
+                }
             }
-        }
 
-        // Only for users mentioned in the notice
+            // Only for users mentioned in the notice
 
-        if ($scope & Notice::ADDRESSEE_SCOPE) {
+            if ($scope & Notice::ADDRESSEE_SCOPE) {
 
-                       $repl = Reply::pkeyGet(array('notice_id' => $this->id,
-                                                                                'profile_id' => $profile->id));
+                $repl = Reply::pkeyGet(array('notice_id' => $this->id,
+                                             'profile_id' => $profile->id));
                                                                                 
-            if (empty($repl)) {
-                return false;
+                if (empty($repl)) {
+                    return false;
+                }
             }
-        }
 
-        // Only for members of the given group
+            // Only for members of the given group
 
-        if ($scope & Notice::GROUP_SCOPE) {
+            if ($scope & Notice::GROUP_SCOPE) {
 
-            // XXX: just query for the single membership
+                // XXX: just query for the single membership
 
-            $groups = $this->getGroups();
+                $groups = $this->getGroups();
 
-            $foundOne = false;
+                $foundOne = false;
 
-            foreach ($groups as $group) {
-                if ($profile->isMember($group)) {
-                    $foundOne = true;
-                    break;
+                foreach ($groups as $group) {
+                    if ($profile->isMember($group)) {
+                        $foundOne = true;
+                        break;
+                    }
+                }
+
+                if (!$foundOne) {
+                    return false;
                 }
             }
 
-            if (!$foundOne) {
-                return false;
+            // Only for followers of the author
+
+            $author = null;
+
+            if ($scope & Notice::FOLLOWER_SCOPE) {
+
+                $author = $this->getProfile();
+        
+                if (!Subscription::exists($profile, $author)) {
+                    return false;
+                }
             }
+
+            return !$this->isHiddenSpam($profile);
         }
+    }
 
-        // Only for followers of the author
+    function isHiddenSpam($profile) {
+        
+        // Hide posts by silenced users from everyone but moderators.
+
+        if (common_config('notice', 'hidespam')) {
 
-        if ($scope & Notice::FOLLOWER_SCOPE) {
             $author = $this->getProfile();
-            if (!Subscription::exists($profile, $author)) {
-                return false;
+
+            if ($author->hasRole(Profile_role::SILENCED)) {
+                if (empty($profile) || !$profile->hasRole(Profile_role::MODERATOR)) {
+                    return true;
+                }
             }
         }
 
-        return true;
+        return false;
     }
 
     static function groupsFromText($text, $profile)
index b20af476d659bf016f66952a41c9167a4b9bc975..82ffe80a5db4a51d678950d04a4861a94c756233 100644 (file)
@@ -288,7 +288,8 @@ $default =
               'gc_limit' => 1000), // max sessions to expire at a time
         'notice' =>
         array('contentlimit' => null,
-              'defaultscope' => null), // null means 1 if site/private, 0 otherwise
+              'defaultscope' => null, // null means 1 if site/private, 0 otherwise
+              'hidespam' => false), // Whether to hide silenced users from timelines
         'message' =>
         array('contentlimit' => null),
         'location' =>
index 0b0fab481eb37393a1e336bab9ada36d7e65b63a..b5def44da7ad092cc71b595e1f012f8bd89fcd68 100644 (file)
@@ -70,9 +70,12 @@ abstract class FilteringNoticeStream extends NoticeStream
         // or we get nothing from upstream.
 
         $results = null;
+        $round = 0;
 
         do {
 
+            common_debug(get_class($this) . ": ($offset, $limit) Round $round: fetching $askFor notices starting at $startAt");
+
             $raw = $this->upstream->getNotices($startAt, $askFor, $sinceId, $maxId);
 
             $results = $raw->N;
@@ -81,14 +84,11 @@ abstract class FilteringNoticeStream extends NoticeStream
                 break;
             }
 
-                       $notices = $raw->fetchAll();
-                       
-                       // XXX: this should probably only be in the scoping one.
-                       
-                       Notice::fillGroups($notices);
-                       Notice::fillReplies($notices);
-                       
-                       foreach ($notices as $notice) {
+            $notices = $raw->fetchAll();
+            
+            $this->prefill($notices);
+
+            foreach ($notices as $notice) {
                 if ($this->filter($notice)) {
                     $filtered[] = $notice;
                     if (count($filtered) >= $total) {
@@ -100,9 +100,22 @@ abstract class FilteringNoticeStream extends NoticeStream
             // XXX: make these smarter; factor hit rate into $askFor
 
             $startAt += $askFor;
-            $askFor   = max($total - count($filtered), NOTICES_PER_PAGE);
+            
+            $hits = count($filtered);
+
+            $lastAsk = $askFor;
+
+            if ($hits === 0) {
+                $askFor = max(min(2 * $askFor, NOTICES_PER_PAGE * 50), NOTICES_PER_PAGE);
+            } else {
+                $askFor = max(min((($total - $hits)*$startAt)/$hits, NOTICES_PER_PAGE * 50), NOTICES_PER_PAGE);
+            }
 
-        } while (count($filtered) < $total && $results !== 0);
+            common_debug(get_class($this) . ": ($offset, $limit) Round $round hits is $hits, results = $results.");
+
+            $round++;
+
+        } while (count($filtered) < $total && $results >= $lastAsk);
 
         return new ArrayWrapper(array_slice($filtered, $offset, $limit));
     }
@@ -119,4 +132,9 @@ abstract class FilteringNoticeStream extends NoticeStream
 
         return $ids;
     }
+
+    function prefill($notices)
+    {
+        return;
+    }
 }
index 26784458e0ea1c7a7590cd068593098bcc13dab5..723f064cb3523dab13b8de075fbd66b0e140ff1a 100644 (file)
@@ -46,15 +46,49 @@ if (!defined('STATUSNET')) {
  */
 class GroupNoticeStream extends ScopingNoticeStream
 {
+    var $group;
+    var $userProfile;
+
     function __construct($group, $profile = -1)
     {
         if (is_int($profile) && $profile == -1) {
             $profile = Profile::current();
         }
+        $this->group = $group;
+        $this->userProfile = $profile;
+
         parent::__construct(new CachingNoticeStream(new RawGroupNoticeStream($group),
                                                     'user_group:notice_ids:' . $group->id),
                             $profile);
     }
+
+    function getNoticeIds($offset, $limit, $since_id, $max_id)
+    {
+        if ($this->impossibleStream()) {
+            return array();
+        } else {
+            return parent::getNoticeIds($offset, $limit, $since_id, $max_id);
+        }
+    }
+
+    function getNotices($offset, $limit, $sinceId = null, $maxId = null)
+    {
+        if ($this->impossibleStream()) {
+            return new ArrayWrapper(array());
+        } else {
+            return parent::getNotices($offset, $limit, $sinceId, $maxId);
+        }
+    }
+
+    function impossibleStream() 
+    {
+        if ($this->group->force_scope &&
+            (empty($this->userProfile) || !$this->userProfile->isMember($this->group))) {
+            return true;
+        }
+
+        return false;
+    }
 }
 
 /**
index 91acbb8d580b6c8bb72b4de58c1f9b9d9a50fe6e..7f38cf005b29469dddca30197946a0cc78da5b4d 100644 (file)
@@ -124,29 +124,34 @@ class NoticeList extends Widget
     
     static function prefill(&$notices, $avatarSize=AVATAR_STREAM_SIZE)
     {
-        // Prefill attachments
-        Notice::fillAttachments($notices);
-        // Prefill attachments
-        Notice::fillFaves($notices);
-        // Prefill repeat data
-        Notice::fillRepeats($notices);
-       // Prefill the profiles
-       $profiles = Notice::fillProfiles($notices);
-       // Prefill the avatars
-       Profile::fillAvatars($profiles, $avatarSize);
+        if (Event::handle('StartNoticeListPrefill', array(&$notices, $avatarSize))) {
+
+            // Prefill attachments
+            Notice::fillAttachments($notices);
+            // Prefill attachments
+            Notice::fillFaves($notices);
+            // Prefill repeat data
+            Notice::fillRepeats($notices);
+            // Prefill the profiles
+            $profiles = Notice::fillProfiles($notices);
+            // Prefill the avatars
+            Profile::fillAvatars($profiles, $avatarSize);
        
-       $p = Profile::current();
+            $p = Profile::current();
        
-       if (!empty($p)) {
+            if (!empty($p)) {
 
-            $ids = array();
+                $ids = array();
        
-            foreach ($notices as $notice) {
-                $ids[] = $notice->id;
-            }
+                foreach ($notices as $notice) {
+                    $ids[] = $notice->id;
+                }
        
-               Memcached_DataObject::pivotGet('Fave', 'notice_id', $ids, array('user_id' => $p->id));
-               Memcached_DataObject::pivotGet('Notice', 'repeat_of', $ids, array('profile_id' => $p->id));
-       }
+                Memcached_DataObject::pivotGet('Fave', 'notice_id', $ids, array('user_id' => $p->id));
+                Memcached_DataObject::pivotGet('Notice', 'repeat_of', $ids, array('profile_id' => $p->id));
+            }
+
+            Event::handle('EndNoticeListPrefill', array(&$notices, &$profiles, $avatarSize));
+        }
     }
 }
index ef7fc0d1e6123c0ea149328ceb7a4e2f80a9a296..d045f0034299a46fd4a932b4c094c8e4273154bd 100644 (file)
@@ -144,10 +144,13 @@ class NoticeListItem extends Widget
             $user = common_current_user();
             if ($user) {
                 $this->out->elementStart('div', 'notice-options');
-                $this->showFaveForm();
-                $this->showReplyLink();
-                $this->showRepeatForm();
-                $this->showDeleteLink();
+                if (Event::handle('StartShowNoticeOptionItems', array($this))) {
+                    $this->showFaveForm();
+                    $this->showReplyLink();
+                    $this->showRepeatForm();
+                    $this->showDeleteLink();
+                    Event::handle('EndShowNoticeOptionItems', array($this));
+                }
                 $this->out->elementEnd('div');
             }
             Event::handle('EndShowNoticeOptions', array($this));
index 1bc14945576258416e4034dde7d608b037816d2a..45866b52f9bde88a5d855bf16f3e998375891ad3 100644 (file)
@@ -86,6 +86,13 @@ class ProfileAction extends Action
             return false;
         }
 
+        $user = common_current_user();
+
+        if ($this->profile->hasRole(Profile_role::SILENCED) &&
+            (empty($user) || !$user->hasRight(Right::SILENCEUSER))) {
+            throw new ClientException(_('This profile has been silenced by site moderators'), 403);
+        }
+
         $this->tag = $this->trimmed('tag');
         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
         common_set_returnto($this->selfUrl());
index 64cd31abc48d64f5d83276c5b2ea8db95b8d7d9b..1fde1c6025e2408191284f5ae6b4be93387aa8e5 100644 (file)
@@ -47,15 +47,61 @@ if (!defined('STATUSNET')) {
 
 class ProfileNoticeStream extends ScopingNoticeStream
 {
+    var $streamProfile;
+    var $userProfile;
+
     function __construct($profile, $userProfile = -1)
     {
         if (is_int($userProfile) && $userProfile == -1) {
             $userProfile = Profile::current();
         }
+        $this->streamProfile = $profile;
+        $this->userProfile   = $userProfile;
         parent::__construct(new CachingNoticeStream(new RawProfileNoticeStream($profile),
                                                     'profile:notice_ids:' . $profile->id),
                             $userProfile);
     }
+
+    function getNoticeIds($offset, $limit, $since_id, $max_id)
+    {
+        if ($this->impossibleStream()) {
+            return array();
+        } else {
+            return parent::getNoticeIds($offset, $limit, $since_id, $max_id);
+        }
+    }
+
+    function getNotices($offset, $limit, $sinceId = null, $maxId = null)
+    {
+        if ($this->impossibleStream()) {
+            return new ArrayWrapper(array());
+        } else {
+            return parent::getNotices($offset, $limit, $sinceId, $maxId);
+        }
+    }
+
+    function impossibleStream() 
+    {
+        $user = User::staticGet('id', $this->streamProfile->id);
+
+        // If it's a private stream, and no user or not a subscriber
+
+        if (!empty($user) && $user->private_stream && 
+            (empty($this->userProfile) || !$this->userProfile->isSubscribed($this->streamProfile))) {
+            return true;
+        }
+
+        // If it's a spammy stream, and no user or not a moderator
+
+        if (common_config('notice', 'hidespam')) {
+            if ($this->streamProfile->hasRole(Profile_role::SILENCED) &&
+                (empty($this->userProfile) || !$this->userProfile->hasRole(Profile_role::MODERATOR))) {
+                return true;
+            }
+        }
+
+        return false;
+    }
 }
 
 /**
index 30b80f10e57569866d4b50518a0ec61078e1058b..9a101fa3ac03cd314f8e76ec3299ff077d1c354d 100644 (file)
@@ -73,4 +73,26 @@ class ScopingNoticeStream extends FilteringNoticeStream
     {
         return $notice->inScope($this->profile);
     }
+
+    function prefill($notices)
+    {
+        // XXX: this should probably only be in the scoping one.
+            
+        Notice::fillGroups($notices);
+        Notice::fillReplies($notices);
+
+        if (common_config('notice', 'hidespam')) {
+
+            $profiles = Notice::getProfiles($notices);
+
+            foreach ($profiles as $profile) {
+                $pids[] = $profile->id;
+            }
+            
+            Memcached_DataObject::pivotGet('Profile_role',
+                                           'profile_id',
+                                           $pids,
+                                           array('role' => Profile_role::SILENCED));
+        }
+    }
 }