[DATABASE] Check SQL boolean values with "IS TRUE"

This way UNKNOWN (NULL) explicitly turns to FALSE when three-valued logic is
reduced to binary.
In pgsqlschema, however, use "IS FALSE" as boolean attributes in pg_index are
non-nullable, there is no outer join and there's no clear preference for NULL
reduction.

Over-complicated constructions in TagCloud queries have been simplified, which
should not affect their performance.

Additionally, in TagCloud's lib/subscriptionspeopleselftagcloudsection.php
a typing mistake in an equi-join of "profile_tag" and "profile_list" on
"tagger" was fixed.
That regression was introduced in f446db8e2a
This commit is contained in:
Alexei Sorokin 2020-07-21 18:06:39 +03:00
parent f7ded4d87b
commit 7081720ecb
14 changed files with 255 additions and 211 deletions

View File

@ -1,39 +1,32 @@
<?php <?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/** /**
* StatusNet, the distributed open-source microblogging tool
*
* Lists by a user * Lists by a user
* *
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* PHP version 5
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Personal * @category Personal
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @author Zach Copley <zach@status.net> * @author Zach Copley <zach@status.net>
* @author Shashi Gowda <connect2shashi@gmail.com> * @author Shashi Gowda <connect2shashi@gmail.com>
* @copyright 2009 StatusNet, Inc. * @copyright 2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://status.net/
*/ */
if (!defined('STATUSNET') && !defined('LACONICA')) { defined('GNUSOCIAL') || die();
exit(1);
}
require_once INSTALLDIR . '/lib/profile/peopletaglist.php'; require_once INSTALLDIR . '/lib/profile/peopletaglist.php';
// cache 3 pages // cache 3 pages
@ -41,15 +34,15 @@ define('PEOPLETAG_CACHE_WINDOW', PEOPLETAGS_PER_PAGE*3 + 1);
class PeopletagAction extends Action class PeopletagAction extends Action
{ {
var $page = null; public $page = null;
var $tag = null; public $tag = null;
function isReadOnly($args) public function isReadOnly($args)
{ {
return true; return true;
} }
function title() public function title()
{ {
if ($this->page == 1) { if ($this->page == 1) {
// TRANS: Title for list page. // TRANS: Title for list page.
@ -62,7 +55,7 @@ class PeopletagAction extends Action
} }
} }
function prepare(array $args = array()) public function prepare(array $args = [])
{ {
parent::prepare($args); parent::prepare($args);
$this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
@ -84,19 +77,19 @@ class PeopletagAction extends Action
return true; return true;
} }
function handle() public function handle()
{ {
parent::handle(); parent::handle();
$this->showPage(); $this->showPage();
} }
function showLocalNav() public function showLocalNav()
{ {
$nav = new PublicGroupNav($this); $nav = new PublicGroupNav($this);
$nav->show(); $nav->show();
} }
function showAnonymousMessage() public function showAnonymousMessage()
{ {
$notice = $notice =
// TRANS: Message for anonymous users on list page. // TRANS: Message for anonymous users on list page.
@ -106,13 +99,13 @@ class PeopletagAction extends Action
'(http://en.wikipedia.org/wiki/Micro-blogging) service ' . '(http://en.wikipedia.org/wiki/Micro-blogging) service ' .
'based on the Free Software [StatusNet](http://status.net/) tool. ' . 'based on the Free Software [StatusNet](http://status.net/) tool. ' .
'You can then easily keep track of what they ' . 'You can then easily keep track of what they ' .
'are doing by subscribing to the list\'s timeline.' ); "are doing by subscribing to the list's timeline.");
$this->elementStart('div', array('id' => 'anon_notice')); $this->elementStart('div', array('id' => 'anon_notice'));
$this->raw(common_markup_to_html($notice)); $this->raw(common_markup_to_html($notice));
$this->elementEnd('div'); $this->elementEnd('div');
} }
function showContent() public function showContent()
{ {
$offset = ($this->page-1) * PEOPLETAGS_PER_PAGE; $offset = ($this->page-1) * PEOPLETAGS_PER_PAGE;
$limit = PEOPLETAGS_PER_PAGE + 1; $limit = PEOPLETAGS_PER_PAGE + 1;
@ -143,9 +136,15 @@ class PeopletagAction extends Action
$ptags->find(); $ptags->find();
} }
} else { } else {
$ptags->whereAdd('(profile_list.private = false OR (' . $ptags->whereAdd(sprintf(
' profile_list.tagger =' . $user->id . <<<'END'
' AND profile_list.private = true) )'); (
(profile_list.tagger = %d AND profile_list.private IS TRUE)
OR profile_list.private IS NOT TRUE
)
END,
$user->getID()
));
$ptags->orderBy('profile_list.modified DESC'); $ptags->orderBy('profile_list.modified DESC');
$ptags->find(); $ptags->find();
@ -154,11 +153,16 @@ class PeopletagAction extends Action
$pl = new PeopletagList($ptags, $this); $pl = new PeopletagList($ptags, $this);
$cnt = $pl->show(); $cnt = $pl->show();
$this->pagination($this->page > 1, $cnt > PEOPLETAGS_PER_PAGE, $this->pagination(
$this->page, 'peopletag', array('tag' => $this->tag)); ($this->page > 1),
($cnt > PEOPLETAGS_PER_PAGE),
$this->page,
'peopletag',
['tag' => $this->tag]
);
} }
function showSections() public function showSections()
{ {
} }
} }

View File

@ -107,10 +107,10 @@ class SelftagAction extends Action
$user = common_current_user(); $user = common_current_user();
if (empty($user)) { if (empty($user)) {
$qry .= 'AND profile_list.private = false '; $qry .= 'AND profile_list.private IS NOT TRUE ';
} else { } else {
$qry .= 'AND (profile_list.tagger = ' . $user->id . $qry .= 'AND (profile_list.tagger = ' . $user->id .
' OR profile_list.private = false) '; ' OR profile_list.private IS NOT TRUE) ';
} }
$qry .= 'ORDER BY profile_tag.modified DESC ' . $qry .= 'ORDER BY profile_tag.modified DESC ' .

View File

@ -504,13 +504,13 @@ class Profile extends Managed_DataObject
if (!is_null($scoped)) { if (!is_null($scoped)) {
$qry .= sprintf( $qry .= sprintf(
'AND ( profile_list.private = false ' . 'AND ( profile_list.private IS NOT TRUE ' .
'OR ( profile_list.tagger = %d AND ' . 'OR ( profile_list.tagger = %d AND ' .
'profile_list.private = TRUE ) )', 'profile_list.private IS TRUE ) )',
$scoped->getID() $scoped->getID()
); );
} else { } else {
$qry .= 'AND profile_list.private = FALSE '; $qry .= 'AND profile_list.private IS NOT TRUE ';
} }
if ($since > 0) { if ($since > 0) {

View File

@ -95,7 +95,7 @@ class Profile_tag extends Managed_DataObject
$qry = sprintf($qry, $tagger, $tagged); $qry = sprintf($qry, $tagger, $tagged);
if (!$include_priv) { if (!$include_priv) {
$qry .= ' AND profile_list.private = FALSE'; $qry .= ' AND profile_list.private IS NOT TRUE';
} }
$profile_list->query($qry); $profile_list->query($qry);
@ -121,7 +121,7 @@ class Profile_tag extends Managed_DataObject
); );
if (!$scoped instanceof Profile || $scoped->getID() !== $tagger) { if (!$scoped instanceof Profile || $scoped->getID() !== $tagger) {
$qry .= 'AND profile_list.private = FALSE'; $qry .= 'AND profile_list.private IS NOT TRUE';
} }
$tags = array(); $tags = array();

View File

@ -299,8 +299,11 @@ class User_group extends Managed_DataObject
public function getAdmins($offset = null, $limit = null) public function getAdmins($offset = null, $limit = null)
{ {
$admins = new Profile(); $admins = new Profile();
$admins->joinAdd(array('id', 'group_member:profile_id')); $admins->joinAdd(['id', 'group_member:profile_id']);
$admins->whereAdd('group_member.group_id = ' . $this->id . ' AND group_member.is_admin = true'); $admins->whereAdd(sprintf(
'group_member.group_id = %d AND group_member.is_admin IS TRUE',
$this->getID()
));
$admins->orderBy('group_member.modified ASC'); $admins->orderBy('group_member.modified ASC');
$admins->limit($offset, $limit); $admins->limit($offset, $limit);
$admins->find(); $admins->find();

View File

@ -260,14 +260,20 @@ class MysqlSchema extends Schema
*/ */
public function fetchIndexInfo(string $table): array public function fetchIndexInfo(string $table): array
{ {
$query = 'SELECT INDEX_NAME AS `key_name`, INDEX_TYPE AS `key_type`, COLUMN_NAME AS `col` ' .
'FROM INFORMATION_SCHEMA.STATISTICS ' .
'WHERE TABLE_SCHEMA = \'%s\' AND TABLE_NAME = \'%s\' AND NON_UNIQUE = TRUE ' .
'AND INDEX_NAME NOT IN (SELECT CONSTRAINT_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_NAME IS NOT NULL) ' .
'ORDER BY SEQ_IN_INDEX';
$schema = $this->conn->dsn['database']; $schema = $this->conn->dsn['database'];
$sql = sprintf($query, $schema, $table); $data = $this->fetchQueryData(
$data = $this->fetchQueryData($sql); <<<END
SELECT INDEX_NAME AS `key_name`, INDEX_TYPE AS `key_type`, COLUMN_NAME AS `col`
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = '{$schema}' AND TABLE_NAME = '{$table}'
AND NON_UNIQUE IS TRUE
AND INDEX_NAME NOT IN (
SELECT CONSTRAINT_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE REFERENCED_TABLE_NAME IS NOT NULL
)
ORDER BY SEQ_IN_INDEX;
END
);
$rows = []; $rows = [];
foreach ($data as $row) { foreach ($data as $row) {

View File

@ -201,12 +201,16 @@ class PgsqlSchema extends Schema
*/ */
public function fetchIndexInfo(string $table): array public function fetchIndexInfo(string $table): array
{ {
$query = 'SELECT indexname AS key_name, indexdef AS key_def, pg_index.* ' . return $this->fetchQueryData(
'FROM pg_index INNER JOIN pg_indexes ON pg_index.indexrelid = CAST(pg_indexes.indexname AS regclass) ' . <<<END
'WHERE tablename = \'%s\' AND indisprimary = FALSE AND indisunique = FALSE ' . SELECT indexname AS key_name, indexdef AS key_def, pg_index.*
'ORDER BY indrelid, indexrelid'; FROM pg_index INNER JOIN pg_indexes
$sql = sprintf($query, $table); ON pg_index.indexrelid = CAST(pg_indexes.indexname AS regclass)
return $this->fetchQueryData($sql); WHERE pg_indexes.tablename = '{$table}'
AND indisprimary IS FALSE AND indisunique IS FALSE
ORDER BY indrelid, indexrelid;
END
);
} }
/** /**

View File

@ -34,26 +34,28 @@ defined('GNUSOCIAL') || die();
*/ */
class PeopletagsBySubsSection extends PeopletagSection class PeopletagsBySubsSection extends PeopletagSection
{ {
function getPeopletags() public function getPeopletags()
{ {
$limit = PEOPLETAGS_PER_SECTION; $limit = PEOPLETAGS_PER_SECTION;
$qry = 'SELECT profile_list.*, subscriber_count AS value ' . $qry = <<<END
'FROM profile_list WHERE profile_list.private = FALSE ' . SELECT profile_list.*, subscriber_count AS value
'ORDER BY value DESC ' . FROM profile_list WHERE profile_list.private IS NOT TRUE
'LIMIT ' . $limit; ORDER BY value DESC
LIMIT {$limit};
END;
$peopletag = Memcached_DataObject::cachedQuery('Profile_list', $qry, 3600); $peopletag = Memcached_DataObject::cachedQuery('Profile_list', $qry, 3600);
return $peopletag; return $peopletag;
} }
function title() public function title()
{ {
// TRANS: Title for section contaning lists with the most subscribers. // TRANS: Title for section contaning lists with the most subscribers.
return _('Popular lists'); return _('Popular lists');
} }
function divId() public function divId()
{ {
return 'top_peopletags_by_subs'; return 'top_peopletags_by_subs';
} }

View File

@ -434,11 +434,11 @@ function mail_broadcast_notice_sms($notice)
// Users (other than the sender) who `want SMS notices': // Users (other than the sender) who `want SMS notices':
'WHERE %1$s.id <> %2$d ' . 'WHERE %1$s.id <> %2$d ' .
'AND %1$s.smsemail IS NOT NULL ' . 'AND %1$s.smsemail IS NOT NULL ' .
'AND %1$s.smsnotify = TRUE ' . 'AND %1$s.smsnotify IS TRUE ' .
// ... where either the user _is_ subscribed to the sender // ... where either the user _is_ subscribed to the sender
// (any of the "subscription" fields IS NOT NULL) // (any of the "subscription" fields IS NOT NULL)
// and wants to get SMS for all of this scribe's notices... // and wants to get SMS for all of this scribe's notices...
'AND (subscription.sms = TRUE ' . 'AND (subscription.sms IS TRUE ' .
// ... or where the user was mentioned in // ... or where the user was mentioned in
// or replied-to with the notice: // or replied-to with the notice:
$repliesQry . $repliesQry .

View File

@ -83,9 +83,14 @@ function silencespammer($filter, $user, $minimum, $percent)
$ss = new Spam_score(); $ss = new Spam_score();
$ss->query(sprintf("SELECT count(*) as spam_count ". $ss->query(sprintf(
"FROM notice join spam_score on notice.id = spam_score.notice_id ". <<<'END'
'WHERE notice.profile_id = %d AND spam_score.is_spam = TRUE', $profile->id)); SELECT COUNT(*) AS spam_count
FROM notice INNER JOIN spam_score ON notice.id = spam_score.notice_id
WHERE notice.profile_id = %d AND spam_score.is_spam IS TRUE;
END,
$profile->getID()
));
while ($ss->fetch()) { while ($ss->fetch()) {
$spam_count = $ss->spam_count; $spam_count = $ss->spam_count;

View File

@ -1,58 +1,61 @@
<?php <?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/** /**
* StatusNet, the distributed open-source microblogging tool
*
* Personal tag cloud section * Personal tag cloud section
* *
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Widget * @category Widget
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @copyright 2009 StatusNet, Inc. * @copyright 2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://status.net/
*/ */
if (!defined('STATUSNET') && !defined('LACONICA')) { defined('GNUSOCIAL') || die();
exit(1);
}
/** /**
* Personal tag cloud section * Personal tag cloud section
* *
* @category Widget * @category Widget
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://status.net/
*/ */
class SubscribersPeopleSelfTagCloudSection extends SubPeopleTagCloudSection class SubscribersPeopleSelfTagCloudSection extends SubPeopleTagCloudSection
{ {
function title() public function title()
{ {
// TRANS: Title of personal tag cloud section. // TRANS: Title of personal tag cloud section.
return _('People Tagcloud as self-tagged'); return _('People Tagcloud as self-tagged');
} }
function query() { public function query()
// return 'select tag, count(tag) as weight from subscription left join profile_tag on tagger = subscriber where subscribed=%d and subscribed != subscriber and tagger = tagged group by tag order by weight desc'; {
return <<<'END'
return 'select profile_tag.tag, count(profile_tag.tag) as weight from subscription left join (profile_tag, profile_list) on profile_list.tag = profile_tag.tag and profile_list.tagger = profile_tag.tagger and profile_tag.tagger = subscriber where subscribed=%d and subscribed != subscriber and profile_tag.tagger = tagged and profile_list.private = false and profile_tag.tag is not null group by profile_tag.tag order by weight desc'; SELECT profile_tag.tag, COUNT(profile_tag.tag) AS weight
FROM profile_tag
// return 'select tag, count(tag) as weight from subscription left join profile_tag on tagger = subscribed where subscriber=%d and subscribed != subscriber and tagger = tagged and tag is not null group by tag order by weight desc'; INNER JOIN subscription AS sub
ON profile_tag.tagger = sub.subscriber
LEFT JOIN profile_list
ON profile_tag.tag = profile_list.tag
AND profile_tag.tagger = profile_list.tagger
WHERE profile_tag.tagger = profile_tag.tagged
AND profile_list.private IS NOT TRUE
AND sub.subscribed = %d AND sub.subscribed <> sub.subscriber
GROUP BY profile_tag.tag ORDER BY weight DESC;
END;
} }
} }

View File

@ -1,60 +1,67 @@
<?php <?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/** /**
* StatusNet, the distributed open-source microblogging tool
*
* Personal tag cloud section * Personal tag cloud section
* *
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Widget * @category Widget
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @copyright 2009 StatusNet, Inc. * @copyright 2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://status.net/
*/ */
if (!defined('STATUSNET') && !defined('LACONICA')) { defined('GNUSOCIAL') || die();
exit(1);
}
/** /**
* Personal tag cloud section * Personal tag cloud section
* *
* @category Widget * @category Widget
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://status.net/
*/ */
class SubscribersPeopleTagCloudSection extends SubPeopleTagCloudSection class SubscribersPeopleTagCloudSection extends SubPeopleTagCloudSection
{ {
function title() public function title()
{ {
// TRANS: Title of personal tag cloud section. // TRANS: Title of personal tag cloud section.
return _('People Tagcloud as tagged'); return _('People Tagcloud as tagged');
} }
function tagUrl($tag) { public function tagUrl($tag)
{
$nickname = $this->out->profile->nickname; $nickname = $this->out->profile->nickname;
return common_local_url('subscribers', array('nickname' => $nickname, 'tag' => $tag)); return common_local_url('subscribers', array('nickname' => $nickname, 'tag' => $tag));
} }
function query() { public function query()
// return 'select tag, count(tag) as weight from subscription left join profile_tag on subscriber=tagged and subscribed=tagger where subscribed=%d and subscriber != subscribed group by tag order by weight desc'; {
return 'select profile_tag.tag, count(profile_tag.tag) as weight from subscription left join (profile_tag, profile_list) on subscriber=profile_tag.tagged and subscribed=profile_tag.tagger and profile_tag.tagger = profile_list.tagger and profile_tag.tag = profile_list.tag where subscribed=%d and subscriber != subscribed and profile_list.private = false and profile_tag.tag is not null group by profile_tag.tag order by weight desc'; return <<<'END'
SELECT profile_tag.tag, COUNT(profile_tag.tag) AS weight
FROM profile_tag
INNER JOIN subscription AS sub
ON profile_tag.tagged = sub.subscriber
AND profile_tag.tagger = sub.subscribed
LEFT JOIN profile_list
ON profile_tag.tagger = profile_list.tagger
AND profile_tag.tag = profile_list.tag
WHERE profile_list.private IS NOT TRUE
AND sub.subscribed = %d AND sub.subscriber <> sub.subscribed
GROUP BY profile_tag.tag ORDER BY weight DESC;
END;
} }
} }

View File

@ -1,58 +1,61 @@
<?php <?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/** /**
* StatusNet, the distributed open-source microblogging tool
*
* Personal tag cloud section * Personal tag cloud section
* *
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Widget * @category Widget
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @copyright 2009 StatusNet, Inc. * @copyright 2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://status.net/
*/ */
if (!defined('STATUSNET') && !defined('LACONICA')) { defined('GNUSOCIAL') || die();
exit(1);
}
/** /**
* Personal tag cloud section * Personal tag cloud section
* *
* @category Widget * @category Widget
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://status.net/
*/ */
class SubscriptionsPeopleSelfTagCloudSection extends SubPeopleTagCloudSection class SubscriptionsPeopleSelfTagCloudSection extends SubPeopleTagCloudSection
{ {
function title() public function title()
{ {
// TRANS: Title of personal tag cloud section. // TRANS: Title of personal tag cloud section.
return _('People Tagcloud as self-tagged'); return _('People Tagcloud as self-tagged');
} }
function query() { public function query()
// return 'select tag, count(tag) as weight from subscription left join profile_tag on tagger = subscriber where subscribed=%d and subscriber != subscribed and tagger = tagged group by tag order by weight desc'; {
return <<<'END'
return 'select profile_tag.tag, count(profile_tag.tag) as weight from subscription left join (profile_tag, profile_list) on profile_tag.tagger = subscribed and profile_tag.tag = profile_list.tag and profile_tag.tagger = profile_tag.tagger where subscriber=%d and subscribed != subscriber and profile_tag.tagger = profile_tag.tagged and profile_list.private = false and profile_tag.tag is not null group by profile_tag.tag order by weight desc'; SELECT profile_tag.tag, COUNT(profile_tag.tag) AS weight
FROM profile_tag
// return 'select tag, count(tag) as weight from subscription left join profile_tag on tagger = subscriber where subscribed=%d and subscribed != subscriber and tagger = tagged and tag is not null group by tag order by weight desc'; INNER JOIN subscription AS sub
ON profile_tag.tagger = sub.subscribed
LEFT JOIN profile_list
ON profile_tag.tag = profile_list.tag
AND profile_tag.tagger = profile_list.tagger
WHERE profile_tag.tagger = profile_tag.tagged
AND profile_list.private IS NOT TRUE
AND sub.subscriber = %d AND sub.subscribed <> sub.subscriber
GROUP BY profile_tag.tag ORDER BY weight DESC;
END;
} }
} }

View File

@ -1,60 +1,67 @@
<?php <?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/** /**
* StatusNet, the distributed open-source microblogging tool
*
* Personal tag cloud section * Personal tag cloud section
* *
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Widget * @category Widget
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @copyright 2009 StatusNet, Inc. * @copyright 2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://status.net/
*/ */
if (!defined('STATUSNET') && !defined('LACONICA')) { defined('GNUSOCIAL') || die();
exit(1);
}
/** /**
* Personal tag cloud section * Personal tag cloud section
* *
* @category Widget * @category Widget
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://status.net/
*/ */
class SubscriptionsPeopleTagCloudSection extends SubPeopleTagCloudSection class SubscriptionsPeopleTagCloudSection extends SubPeopleTagCloudSection
{ {
function title() public function title()
{ {
// TRANS: Title of personal tag cloud section. // TRANS: Title of personal tag cloud section.
return _('People Tagcloud as tagged'); return _('People Tagcloud as tagged');
} }
function tagUrl($tag) { public function tagUrl($tag)
{
$nickname = $this->out->profile->nickname; $nickname = $this->out->profile->nickname;
return common_local_url('subscriptions', array('nickname' => $nickname, 'tag' => $tag)); return common_local_url('subscriptions', array('nickname' => $nickname, 'tag' => $tag));
} }
function query() { public function query()
// return 'select tag, count(tag) as weight from subscription left join profile_tag on subscriber=tagger and subscribed=tagged where subscriber=%d and subscriber != subscribed group by tag order by weight desc'; {
return 'select profile_tag.tag, count(profile_tag.tag) as weight from subscription left join (profile_tag, profile_list) on subscriber=profile_tag.tagger and subscribed=tagged and profile_tag.tag = profile_list.tag and profile_tag.tagger = profile_list.tagger where subscriber=%d and subscriber != subscribed and profile_list.private = false and profile_tag.tag is not null group by profile_tag.tag order by weight desc'; return <<<'END'
SELECT profile_tag.tag, COUNT(profile_tag.tag) AS weight
FROM profile_tag
INNER JOIN subscription AS sub
ON profile_tag.tagger = sub.subscriber
AND profile_tag.tagged = sub.subscribed
LEFT JOIN profile_list
ON profile_tag.tag = profile_list.tag
AND profile_tag.tagger = profile_list.tagger
WHERE profile_list.private IS NOT TRUE
AND sub.subscriber = %d AND sub.subscriber <> sub.subscribed
GROUP BY profile_tag.tag ORDER BY weight DESC;
END;
} }
} }