From efb7d28d830b1057cc0e57496dcb263955bbb358 Mon Sep 17 00:00:00 2001 From: Shashi Gowda Date: Fri, 8 Jul 2011 11:42:28 +0530 Subject: [PATCH 1/9] Fix problems in joinAdd with xampp Xampp ships with a different version of DB_DataObject PEAR package that cannot do joins using objects correctly. This patch fixes the problem --- classes/Profile_list.php | 8 +++++--- classes/Profile_tag.php | 21 +++++++++------------ lib/peopletagnoticestream.php | 4 +++- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/classes/Profile_list.php b/classes/Profile_list.php index 2395a369f3..0586a8688c 100644 --- a/classes/Profile_list.php +++ b/classes/Profile_list.php @@ -185,10 +185,12 @@ class Profile_list extends Memcached_DataObject function getSubscribers($offset=0, $limit=null, $since=0, $upto=0) { $subs = new Profile(); - $sub = new Profile_tag_subscription(); - $sub->profile_tag_id = $this->id; - $subs->joinAdd($sub); + $subs->joinAdd( + array('id', 'profile_tag_subscription:profile_id') + ); + $subs->whereAdd('profile_tag_subscription.profile_tag_id = ' . $this->id); + $subs->selectAdd('unix_timestamp(profile_tag_subscription.' . 'created) as "cursor"'); diff --git a/classes/Profile_tag.php b/classes/Profile_tag.php index 9e475e83ec..72dc9c7560 100644 --- a/classes/Profile_tag.php +++ b/classes/Profile_tag.php @@ -55,20 +55,17 @@ class Profile_tag extends Memcached_DataObject return $tags; } - $profile_tag = new Profile_tag(); - $profile_list->tagger = $tagger; - $profile_tag->tagged = $tagged; + $qry = 'select profile_list.* from profile_list left join '. + 'profile_tag on (profile_list.tag = profile_tag.tag and '. + 'profile_list.tagger = profile_tag.tagger) where '. + 'profile_tag.tagger = %d and profile_tag.tagged = %d '; + $qry = sprintf($qry, $tagger, $tagged); - $profile_list->selectAdd(); + if (!$include_priv) { + $qry .= 'profile_list.private = 0'; + } - // only fetch id, tag, mainpage and - // private hoping this will be faster - $profile_list->selectAdd('profile_list.id, ' . - 'profile_list.tag, ' . - 'profile_list.mainpage, ' . - 'profile_list.private'); - $profile_list->joinAdd($profile_tag); - $profile_list->find(); + $profile_list->query($qry); Profile_list::setCache($key, $profile_list); diff --git a/lib/peopletagnoticestream.php b/lib/peopletagnoticestream.php index 9477ca8ea6..4422261ae9 100644 --- a/lib/peopletagnoticestream.php +++ b/lib/peopletagnoticestream.php @@ -99,7 +99,9 @@ class RawPeopletagNoticeStream extends NoticeStream $ptag = new Profile_tag(); $ptag->tag = $this->profile_list->tag; $ptag->tagger = $this->profile_list->tagger; - $notice->joinAdd($ptag); + $notice->joinAdd(array('profile_id', 'profile_tag:tagged')); + $notice->whereAdd('profile_tag.tagger = ' . $this->profile_list->tagger); + $notice->whereAdd(sprintf('profile_tag.tag = "%s"', $this->profile_list->tag)); if ($since_id != 0) { $notice->whereAdd('notice.id > ' . $since_id); From ce044c40fb0c05d8f7869c8c06174b2c7428052b Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 27 Sep 2011 09:42:34 -0400 Subject: [PATCH 2/9] rewrite Profile_tag::getTagsArray() so it doesn't use joinAdd() --- classes/Profile_tag.php | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/classes/Profile_tag.php b/classes/Profile_tag.php index f1a60fdaa6..c9f8d96713 100644 --- a/classes/Profile_tag.php +++ b/classes/Profile_tag.php @@ -99,23 +99,26 @@ class Profile_tag extends Managed_DataObject static function getTagsArray($tagger, $tagged, $auth_user_id=null) { $ptag = new Profile_tag(); - $ptag->tagger = $tagger; - $ptag->tagged = $tagged; - if ($tagger != $auth_user_id) { - $list = new Profile_list(); - $list->private = false; - $ptag->joinAdd($list); - $ptag->selectAdd(); - $ptag->selectAdd('profile_tag.tag'); + $qry = sprint('select profile_tag.tag '. + 'from profile_tag join profile_list '. + ' on (profile_tag.tagger = profile_list.tagger ' . + ' and profile_tag.tag = profile_list.tag) ' . + 'where profile_tag.tagger = %d ' . + 'and profile_tag.tagged = %d ', + $tagger, $tagged); + + if ($auth_user_id != $tagger) { + $qry .= 'and profile_list.private = 0'; } $tags = array(); - $ptag->find(); + + $ptag->query($sql); + while ($ptag->fetch()) { $tags[] = $ptag->tag; } - $ptag->free(); return $tags; } From 707f90d0127e2c994f38d0708e7c829f9b26c2d0 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 27 Sep 2011 10:47:13 -0400 Subject: [PATCH 3/9] missed an AND --- classes/Profile_tag.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/Profile_tag.php b/classes/Profile_tag.php index c9f8d96713..0d90d4da14 100644 --- a/classes/Profile_tag.php +++ b/classes/Profile_tag.php @@ -86,7 +86,7 @@ class Profile_tag extends Managed_DataObject $qry = sprintf($qry, $tagger, $tagged); if (!$include_priv) { - $qry .= 'profile_list.private = 0'; + $qry .= ' and profile_list.private = 0'; } $profile_list->query($qry); From 88c00facc807d1c138146c02c703e2294b5d357b Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 27 Sep 2011 10:51:02 -0400 Subject: [PATCH 4/9] fix getOtherTags() to not use joinAdd() --- classes/Profile.php | 55 ++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/classes/Profile.php b/classes/Profile.php index 7f45031f66..f983225fd5 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -436,42 +436,55 @@ class Profile extends Managed_DataObject return new ArrayWrapper($lists); } + /** + * Get tags that other people put on this profile, in reverse-chron order + * + * @param (Profile|User) $auth_user Authorized user (used for privacy) + * @param int $offset Offset from latest + * @param int $limit Max number to get + * @param datetime $since_id max date + * @param datetime $max_id min date + * + * @return Profile_list resulting lists + */ + function getOtherTags($auth_user=null, $offset=0, $limit=null, $since_id=0, $max_id=0) { - $lists = new Profile_list(); + $list = new Profile_list(); - $tags = new Profile_tag(); - $tags->tagged = $this->id; + $qry = sprintf('select profile_list.*, unix_timestamp(profile_tag.modified) as "cursor" ' . + 'from profile_tag join profile_list '. + 'on (profile_tag.tagger = profile_list.tagger ' . + ' and profile_tag.tag = profile_list.tag) ' . + 'where profile_tag.tagged = %d ', + $this->id); - $lists->joinAdd($tags); - - #@fixme: postgres (round(date_part('epoch', my_date))) - $lists->selectAdd('unix_timestamp(profile_tag.modified) as "cursor"'); if ($auth_user instanceof User || $auth_user instanceof Profile) { - $lists->whereAdd('( ( profile_list.private = false ) ' . - 'OR ( profile_list.tagger = ' . $auth_user->id . ' AND ' . - 'profile_list.private = true ) )'); + $qry .= sprintf('AND ( ( profile_list.private = false ) ' . + 'OR ( profile_list.tagger = %d AND ' . + 'profile_list.private = true ) )', + $auth_user->id); } else { - $lists->private = false; + $qry .= 'AND profile_list.private = 0 '; } - if ($since_id>0) { - $lists->whereAdd('cursor > '.$since_id); + if ($since_id > 0) { + $qry .= sprintf('AND (cursor > %d) ', $since_id); } - if ($max_id>0) { - $lists->whereAdd('cursor <= '.$max_id); + if ($max_id > 0) { + $qry .= sprintf('AND (cursor < %d) ', $max_id); } - if($offset>=0 && !is_null($limit)) { - $lists->limit($offset, $limit); + $qry .= 'ORDER BY profile_tag.modified DESC '; + + if ($offset >= 0 && !is_null($limit)) { + $qry .= sprintf('LIMIT %d OFFSET %d ', $limit, $offset); } - $lists->orderBy('profile_tag.modified DESC'); - $lists->find(); - - return $lists; + $list->query($qry); + return $list; } function getPrivateTags($offset=0, $limit=null, $since_id=0, $max_id=0) From 5eddfd1eab2d3ee08a9478be93a18b01a1ec9df2 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 27 Sep 2011 10:55:10 -0400 Subject: [PATCH 5/9] remove unlinked publicpeopletagcloud --- actions/publicpeopletagcloud.php | 182 ------------------------------- doc-src/lists | 4 - doc-src/tags | 4 - lib/router.php | 4 - 4 files changed, 194 deletions(-) delete mode 100644 actions/publicpeopletagcloud.php diff --git a/actions/publicpeopletagcloud.php b/actions/publicpeopletagcloud.php deleted file mode 100644 index cb65bbb163..0000000000 --- a/actions/publicpeopletagcloud.php +++ /dev/null @@ -1,182 +0,0 @@ -. - * - * @category Public - * @package StatusNet - * @author Mike Cochrane - * @author Evan Prodromou - * @copyright 2008 Mike Cochrane - * @copyright 2008-2009 StatusNet, Inc. - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://status.net/ - */ - -if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } - -define('TAGS_PER_PAGE', 100); - -/** - * Public tag cloud for notices - * - * @category Personal - * @package StatusNet - * @author Mike Cochrane - * @author Evan Prodromou - * @copyright 2008 Mike Cochrane - * @copyright 2008-2009 StatusNet, Inc. - * @link http://status.net/ - */ -class PublicpeopletagcloudAction extends Action -{ - function isReadOnly($args) - { - return true; - } - - function title() - { - // TRANS: Title for page with public list cloud. - return _('Public list cloud'); - } - - function showPageNotice() - { - $this->element('p', 'instructions', - // TRANS: Page notice for page with public list cloud. - // TRANS: %s is a StatusNet sitename. - sprintf(_('These are largest lists on %s'), - common_config('site', 'name'))); - } - - function showEmptyList() - { - // TRANS: Empty list message on page with public list cloud. - // TRANS: This message contains Markdown links in the form [description](link). - $message = _('No one has [listed](%%doc.tags%%) anyone yet.') . ' '; - - if (common_logged_in()) { - // TRANS: Additional empty list message on page with public list cloud for logged in users. - $message .= _('Be the first to list someone!'); - } - else { - // TRANS: Additional empty list message on page with public list cloud for anonymous users. - // TRANS: This message contains Markdown links in the form [description](link). - $message .= _('Why not [register an account](%%action.register%%) and be the first to list someone!'); - } - - $this->elementStart('div', 'guide'); - $this->raw(common_markup_to_html($message)); - $this->elementEnd('div'); - } - - function showLocalNav() - { - $nav = new PublicGroupNav($this); - $nav->show(); - } - - function handle($args) - { - parent::handle($args); - $this->showPage(); - } - - function showContent() - { - // XXX: cache this - - $tags = new Profile_tag(); - $plist = new Profile_list(); - $plist->private = false; - - $tags->joinAdd($plist); - $tags->selectAdd(); - $tags->selectAdd('profile_tag.tag'); - $tags->selectAdd('count(profile_tag.tag) as weight'); - $tags->groupBy('profile_tag.tag'); - $tags->orderBy('weight DESC'); - - $tags->limit(TAGS_PER_PAGE); - - $cnt = $tags->find(); - - if ($cnt > 0) { - $this->elementStart('div', array('id' => 'tagcloud', - 'class' => 'section')); - - $tw = array(); - $sum = 0; - while ($tags->fetch()) { - $tw[$tags->tag] = $tags->weight; - $sum += $tags->weight; - } - - ksort($tw); - - $this->elementStart('dl'); - // TRANS: DT element on on page with public list cloud. - $this->element('dt', null, _('List cloud')); - $this->elementStart('dd'); - $this->elementStart('ul', 'tags xoxo tag-cloud'); - foreach ($tw as $tag => $weight) { - if ($sum) { - $weightedSum = $weight/$sum; - } else { - $weightedSum = 0.5; - } - $this->showTag($tag, $weight, $weightedSum); - } - $this->elementEnd('ul'); - $this->elementEnd('dd'); - $this->elementEnd('dl'); - $this->elementEnd('div'); - } else { - $this->showEmptyList(); - } - } - - function showTag($tag, $weight, $relative) - { - if ($relative > 0.1) { - $rel = 'tag-cloud-7'; - } else if ($relative > 0.05) { - $rel = 'tag-cloud-6'; - } else if ($relative > 0.02) { - $rel = 'tag-cloud-5'; - } else if ($relative > 0.01) { - $rel = 'tag-cloud-4'; - } else if ($relative > 0.005) { - $rel = 'tag-cloud-3'; - } else if ($relative > 0.002) { - $rel = 'tag-cloud-2'; - } else { - $rel = 'tag-cloud-1'; - } - - $this->elementStart('li', $rel); - - // TRANS: Link title for number of listed people. %d is the number of listed people. - $title = sprintf(_m('1 person listed','%d people listed',$weight),$weight); - $this->element('a', array('href' => common_local_url('peopletag', array('tag' => $tag)), - 'title' => $title), $tag); - $this->elementEnd('li'); - } -} diff --git a/doc-src/lists b/doc-src/lists index b2e93aa853..01c5d3b65f 100644 --- a/doc-src/lists +++ b/doc-src/lists @@ -56,10 +56,6 @@ private prepend a '.' to the tag in the tags editing box. To set an existing public tag as private or vice-versa, go to the tag's edit page. -The most used public tags are displayed in the -[public people tag cloud](%%action.publicpeopletagcloud%%). Their -size shows their frequency of use. - Remote people tags ------------------ diff --git a/doc-src/tags b/doc-src/tags index b2e93aa853..3e9065a100 100644 --- a/doc-src/tags +++ b/doc-src/tags @@ -17,10 +17,6 @@ latin characters are not supported, and non-roman scripts are right out. The HTML for the notice will link to a stream of all the other notices with that tag. This can be a great way to keep track of a conversation. -The most popular current tags on the site can be found in the [public -tag cloud](%%action.publictagcloud%%). Their size shows their -popularity and recency. - Tagging yourself ---------------- diff --git a/lib/router.php b/lib/router.php index b0124375de..2011d2708c 100644 --- a/lib/router.php +++ b/lib/router.php @@ -904,10 +904,6 @@ class Router // people tags - if (!common_config('performance', 'high')) { - $m->connect('peopletags', array('action' => 'publicpeopletagcloud')); - } - $m->connect('peopletag/:tag', array('action' => 'peopletag', 'tag' => self::REGEX_TAG)); From 841c71f37d45ec2e0df26961d211a29f02c8dbb7 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 27 Sep 2011 11:16:14 -0400 Subject: [PATCH 6/9] Add profile lists for all tags on upgrade --- scripts/upgrade.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/scripts/upgrade.php b/scripts/upgrade.php index 1bf444267c..7d81c19835 100644 --- a/scripts/upgrade.php +++ b/scripts/upgrade.php @@ -52,6 +52,8 @@ function main() initSubscriptionURI(); initGroupMemberURI(); + initProfileLists(); + Event::handle('EndUpgrade'); } } @@ -374,4 +376,47 @@ function initGroupMemberURI() printfnq("DONE.\n"); } +function initProfileLists() +{ + printfnq("Ensuring all profile tags have a corresponding list..."); + + $ptag = new Profile_tag(); + $ptag->selectAdd(); + $ptag->selectAdd('tagger, tag, count(*) as tagged_count'); + $ptag->whereAdd('NOT EXISTS (SELECT tagger, tagged from profile_list '. + 'where profile_tag.tagger = profile_list.tagger '. + 'and profile_tag.tag = profile_list.tag)'); + $ptag->groupBy('tagger, tag'); + $ptag->orderBy('tagger, tag'); + + if ($ptag->find()) { + while ($ptag->fetch()) { + $plist = new Profile_list(); + + $plist->tagger = $ptag->tagger; + $plist->tag = $ptag->tag; + $plist->private = 0; + $plist->created = common_sql_now(); + $plist->modified = $plist->created; + $plist->mainpage = common_local_url('showprofiletag', + array('tagger' => $plist->getTagger()->nickname, + 'tag' => $plist->tag));; + + $plist->tagged_count = $ptag->tagged_count; + $plist->subscriber_count = 0; + + $plist->insert(); + + $orig = clone($plist); + // After insert since it uses auto-generated ID + $plist->uri = common_local_url('profiletagbyid', + array('id' => $plist->id, 'tagger_id' => $plist->tagger)); + + $plist->update($orig); + } + } + + printfnq("DONE.\n"); +} + main(); From 8b35e69b341f5b5b9b382e3d16356403fa398701 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 27 Sep 2011 11:27:14 -0400 Subject: [PATCH 7/9] setup schemaversion first so we don't get errors on upgrade --- db/core.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/core.php b/db/core.php index b7881a7dc0..bf8cae3c4b 100644 --- a/db/core.php +++ b/db/core.php @@ -29,7 +29,8 @@ * double-check what we've been doing on postgres? */ -$classes = array('Profile', +$classes = array('Schema_version', + 'Profile', 'Avatar', 'Sms_carrier', 'User', @@ -85,7 +86,6 @@ $classes = array('Profile', 'Conversation', 'Local_group', 'User_urlshortener_prefs', - 'Schema_version', 'Old_school_prefs', ); From 5ccae1313c7c84bf4552ab5f91f905995e167714 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 27 Sep 2011 11:32:05 -0400 Subject: [PATCH 8/9] Query errors in Profile_tag --- classes/Profile_tag.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/classes/Profile_tag.php b/classes/Profile_tag.php index 0d90d4da14..07ed160d19 100644 --- a/classes/Profile_tag.php +++ b/classes/Profile_tag.php @@ -100,13 +100,13 @@ class Profile_tag extends Managed_DataObject { $ptag = new Profile_tag(); - $qry = sprint('select profile_tag.tag '. - 'from profile_tag join profile_list '. - ' on (profile_tag.tagger = profile_list.tagger ' . - ' and profile_tag.tag = profile_list.tag) ' . - 'where profile_tag.tagger = %d ' . - 'and profile_tag.tagged = %d ', - $tagger, $tagged); + $qry = sprintf('select profile_tag.tag '. + 'from profile_tag join profile_list '. + ' on (profile_tag.tagger = profile_list.tagger ' . + ' and profile_tag.tag = profile_list.tag) ' . + 'where profile_tag.tagger = %d ' . + 'and profile_tag.tagged = %d ', + $tagger, $tagged); if ($auth_user_id != $tagger) { $qry .= 'and profile_list.private = 0'; @@ -114,7 +114,7 @@ class Profile_tag extends Managed_DataObject $tags = array(); - $ptag->query($sql); + $ptag->query($qry); while ($ptag->fetch()) { $tags[] = $ptag->tag; From 3063caea83324e007a865e01fb2a5bf7584c49fd Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 27 Sep 2011 11:32:20 -0400 Subject: [PATCH 9/9] Incorrect constant for theme warning --- lib/theme.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/theme.php b/lib/theme.php index 1239e317f4..fbcbbe052a 100644 --- a/lib/theme.php +++ b/lib/theme.php @@ -106,9 +106,9 @@ class Theme // Ruh roh. Fall back to default, then. - common_log(LOG_WARN, sprintf("Unable to find theme '%s', falling back to default theme '%s'", - $name, - Theme::FALLBACK)); + common_log(LOG_WARNING, sprintf("Unable to find theme '%s', falling back to default theme '%s'", + $name, + Theme::FALLBACK)); $this->name = Theme::FALLBACK; $this->dir = $instroot.'/'.Theme::FALLBACK;