[CORE] Move core plugins to a new modules directory
For reference (raised by rozzin in IRC): * http://foldoc.org/module * http://foldoc.org/library * http://foldoc.org/plugin As noted by XRevan86, modules are not necessarily non-essential. As we will keep the modules directory in GS root [therefore, near to plugins/], it is evidenced the difference between both. This is a simple yet fundamental structural change. It doesn't change functionality but makes clearer the way we understand GNU social's internals.
This commit is contained in:
214
modules/ActivityModeration/ActivityModerationPlugin.php
Normal file
214
modules/ActivityModeration/ActivityModerationPlugin.php
Normal file
@@ -0,0 +1,214 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Activity
|
||||
* @maintainer Mikael Nordfeldth <mmn@hethane.se>
|
||||
*/
|
||||
class ActivityModerationPlugin extends ActivityVerbHandlerPlugin
|
||||
{
|
||||
public function tag()
|
||||
{
|
||||
return 'actmod';
|
||||
}
|
||||
|
||||
public function types()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function verbs()
|
||||
{
|
||||
return array(ActivityVerb::DELETE);
|
||||
}
|
||||
|
||||
public function onBeforePluginCheckSchema()
|
||||
{
|
||||
Deleted_notice::beforeSchemaUpdate();
|
||||
return true;
|
||||
}
|
||||
|
||||
public function onCheckSchema()
|
||||
{
|
||||
$schema = Schema::get();
|
||||
$schema->ensureTable('deleted_notice', Deleted_notice::schemaDef());
|
||||
return true;
|
||||
}
|
||||
|
||||
public function onGetNoticeSqlTimestamp($id, &$timestamp)
|
||||
{
|
||||
try {
|
||||
$deleted = Deleted_notice::getByID($id);
|
||||
$timestamp = $deleted->act_created;
|
||||
} catch (NoResultException $e) {
|
||||
return true;
|
||||
}
|
||||
// we're done for the event, so return false to stop it
|
||||
return false;
|
||||
}
|
||||
|
||||
public function onIsNoticeDeleted($id, &$deleted)
|
||||
{
|
||||
try {
|
||||
$found = Deleted_notice::getByID($id);
|
||||
$deleted = ($found instanceof Deleted_notice);
|
||||
} catch (NoResultException $e) {
|
||||
$deleted = false;
|
||||
}
|
||||
// return true (continue event) if $deleted is false, return false (stop event) if deleted notice was found
|
||||
return !$deleted;
|
||||
}
|
||||
|
||||
protected function getActionTitle(ManagedAction $action, $verb, Notice $target, Profile $scoped)
|
||||
{
|
||||
// FIXME: switch based on action type
|
||||
return _m('TITLE', 'Notice moderation');
|
||||
}
|
||||
|
||||
protected function doActionPreparation(ManagedAction $action, $verb, Notice $target, Profile $scoped)
|
||||
{
|
||||
// pass
|
||||
}
|
||||
|
||||
protected function doActionPost(ManagedAction $action, $verb, Notice $target, Profile $scoped)
|
||||
{
|
||||
switch (true) {
|
||||
case ActivityUtils::compareVerbs($verb, array(ActivityVerb::DELETE)):
|
||||
// do whatever preparation is necessary to delete a verb
|
||||
$target->deleteAs($scoped);
|
||||
break;
|
||||
default:
|
||||
throw new ServerException('ActivityVerb POST not handled by plugin that was supposed to do it.');
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteRelated(Notice $notice)
|
||||
{
|
||||
// pass
|
||||
}
|
||||
|
||||
public function onDeleteNoticeAsProfile(Notice $stored, Profile $actor, &$result) {
|
||||
// By adding a new object with the 'delete' verb we will trigger
|
||||
// $this->saveObjectFromActivity that will do the actual ->delete()
|
||||
if (false === Deleted_notice::addNew($stored, $actor)) {
|
||||
// false is returned if we did not have an error, but did not create the object
|
||||
// (i.e. the author is currently being deleted)
|
||||
return true;
|
||||
}
|
||||
|
||||
// We return false (to stop the event) if the deleted_notice entry was
|
||||
// added, which means we have already run $this->saveObjectFromActivity
|
||||
// which in turn has called the delete function of the notice.
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is run when a 'delete' verb activity comes in.
|
||||
*
|
||||
* @return boolean hook flag
|
||||
*/
|
||||
protected function saveObjectFromActivity(Activity $act, Notice $stored, array $options=array())
|
||||
{
|
||||
// Everything is done in the StartNoticeSave event
|
||||
return true;
|
||||
}
|
||||
|
||||
// FIXME: Put this in lib/activityhandlerplugin.php when we're ready
|
||||
// with the other microapps/activityhandlers as well.
|
||||
// Also it should be StartNoticeAsActivity (with a prepped Activity, including ->context etc.)
|
||||
public function onEndNoticeAsActivity(Notice $stored, Activity $act, Profile $scoped=null)
|
||||
{
|
||||
if (!$this->isMyNotice($stored)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
common_debug('Extending activity '.$stored->id.' with '.get_called_class());
|
||||
$this->extendActivity($stored, $act, $scoped);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is run before ->insert, so our task in this function is just to
|
||||
* delete if it is the delete verb.
|
||||
*/
|
||||
public function onStartNoticeSave(Notice $stored)
|
||||
{
|
||||
// DELETE is a bit special, we have to remove the existing entry and then
|
||||
// add a new one with the same URI in order to trigger the distribution.
|
||||
// (that's why we don't use $this->isMyNotice(...))
|
||||
if (!ActivityUtils::compareVerbs($stored->verb, array(ActivityVerb::DELETE))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
$target = Notice::getByUri($stored->uri);
|
||||
} catch (NoResultException $e) {
|
||||
throw new AlreadyFulfilledException('Notice URI not found, so we have nothing to delete.');
|
||||
}
|
||||
|
||||
$actor = $stored->getProfile();
|
||||
$owner = $target->getProfile();
|
||||
|
||||
if ($owner->hasRole(Profile_role::DELETED)) {
|
||||
// Don't bother with replacing notices if its author is being deleted.
|
||||
// The later "StoreActivityObject" will pick this up and execute
|
||||
// the deletion then.
|
||||
// (the "delete verb notice" is too new to ever pass through Notice::saveNew
|
||||
// which otherwise wouldn't execute the StoreActivityObject event)
|
||||
return true;
|
||||
}
|
||||
|
||||
// Since the user deleting may not be the same as the notice's owner,
|
||||
// double-check this and also set the "re-stored" notice profile_id.
|
||||
if (!$actor->sameAs($owner) && !$actor->hasRight(Right::DELETEOTHERSNOTICE)) {
|
||||
throw new AuthorizationException(_('You are not allowed to delete another user\'s notice.'));
|
||||
}
|
||||
|
||||
// We copy the identifying fields and replace the sensitive ones.
|
||||
//$stored->id = $target->id; // We can't copy this since DB_DataObject won't inject it anyway
|
||||
$props = array('uri', 'profile_id', 'conversation', 'reply_to', 'created', 'repeat_of', 'object_type', 'is_local', 'scope');
|
||||
foreach($props as $prop) {
|
||||
$stored->$prop = $target->$prop;
|
||||
}
|
||||
|
||||
// Let's see if this has been deleted already.
|
||||
try {
|
||||
$deleted = Deleted_notice::getByKeys( ['uri' => $stored->getUri()] );
|
||||
return $deleted;
|
||||
} catch (NoResultException $e) {
|
||||
$deleted = new Deleted_notice();
|
||||
|
||||
$deleted->id = $target->getID();
|
||||
$deleted->profile_id = $actor->getID();
|
||||
$deleted->uri = $stored->getUri();
|
||||
$deleted->act_created = $stored->created;
|
||||
$deleted->created = common_sql_now();
|
||||
|
||||
// throws exception on error
|
||||
$result = $deleted->insert();
|
||||
}
|
||||
|
||||
// Now we delete the original notice, leaving the id and uri free.
|
||||
$target->delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function extendActivity(Notice $stored, Activity $act, Profile $scoped=null)
|
||||
{
|
||||
Deleted_notice::extendActivity($stored, $act, $scoped);
|
||||
}
|
||||
|
||||
public function activityObjectFromNotice(Notice $notice)
|
||||
{
|
||||
$object = Deleted_notice::fromStored($notice);
|
||||
return $object->asActivityObject();
|
||||
}
|
||||
|
||||
protected function getActivityForm(ManagedAction $action, $verb, Notice $target, Profile $scoped)
|
||||
{
|
||||
if (!$scoped instanceof Profile || !($scoped->sameAs($target->getProfile()) || $scoped->hasRight(Right::DELETEOTHERSNOTICE))) {
|
||||
throw new AuthorizationException(_('You are not allowed to delete other user\'s notices'));
|
||||
}
|
||||
return DeletenoticeForm($action, array('notice'=>$target));
|
||||
}
|
||||
}
|
||||
227
modules/ActivityModeration/classes/Deleted_notice.php
Normal file
227
modules/ActivityModeration/classes/Deleted_notice.php
Normal file
@@ -0,0 +1,227 @@
|
||||
<?php
|
||||
/*
|
||||
* Laconica - a distributed open-source microblogging tool
|
||||
* Copyright (C) 2008, 2009, Control Yourself, Inc.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||
|
||||
/**
|
||||
* Table Definition for deleted_notice
|
||||
*/
|
||||
|
||||
class Deleted_notice extends Managed_DataObject
|
||||
{
|
||||
public $__table = 'deleted_notice'; // table name
|
||||
public $id; // int(4) primary_key not_null
|
||||
public $profile_id; // int(4) not_null
|
||||
public $uri; // varchar(191) unique_key not 255 because utf8mb4 takes more space
|
||||
public $act_created; // datetime() not_null
|
||||
public $created; // datetime() not_null
|
||||
|
||||
public static function schemaDef()
|
||||
{
|
||||
return array(
|
||||
'fields' => array(
|
||||
'id' => array('type' => 'int', 'not null' => true, 'description' => 'notice ID'),
|
||||
'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'profile that deleted the notice'),
|
||||
'uri' => array('type' => 'varchar', 'length' => 191, 'description' => 'URI of the deleted notice'),
|
||||
'act_created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date the notice record was created'),
|
||||
'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date the notice record was deleted'),
|
||||
),
|
||||
'primary key' => array('id'),
|
||||
'unique keys' => array(
|
||||
'deleted_notice_uri_key' => array('uri'),
|
||||
),
|
||||
'indexes' => array(
|
||||
'deleted_notice_profile_id_idx' => array('profile_id'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public static function addNew(Notice $notice, Profile $actor=null)
|
||||
{
|
||||
if (is_null($actor)) {
|
||||
$actor = $notice->getProfile();
|
||||
}
|
||||
|
||||
if ($notice->getProfile()->hasRole(Profile_role::DELETED)) {
|
||||
// Don't emit notices if the notice author is (being) deleted
|
||||
return false;
|
||||
}
|
||||
|
||||
$act = new Activity();
|
||||
$act->verb = ActivityVerb::DELETE;
|
||||
$act->time = time();
|
||||
$act->id = $notice->getUri();
|
||||
|
||||
$act->content = sprintf(_m('<a href="%1$s">%2$s</a> deleted notice <a href="%3$s">{{%4$s}}</a>.'),
|
||||
htmlspecialchars($actor->getUrl()),
|
||||
htmlspecialchars($actor->getBestName()),
|
||||
htmlspecialchars($notice->getUrl()),
|
||||
htmlspecialchars($notice->getUri())
|
||||
);
|
||||
|
||||
$act->actor = $actor->asActivityObject();
|
||||
$act->target = new ActivityObject(); // We don't save the notice object, as it's supposed to be removed!
|
||||
$act->target->id = $notice->getUri();
|
||||
try {
|
||||
$act->target->type = $notice->getObjectType();
|
||||
} catch (NoObjectTypeException $e) {
|
||||
// This could be for example an RSVP which is a verb and carries no object-type
|
||||
$act->target->type = null;
|
||||
}
|
||||
$act->objects = array(clone($act->target));
|
||||
|
||||
$url = $notice->getUrl();
|
||||
$act->selfLink = $url;
|
||||
$act->editLink = $url;
|
||||
|
||||
// This will make ActivityModeration run saveObjectFromActivity which adds
|
||||
// a new Deleted_notice entry in the database as well as deletes the notice
|
||||
// if the actor has permission to do so.
|
||||
$stored = Notice::saveActivity($act, $actor);
|
||||
|
||||
return $stored;
|
||||
}
|
||||
|
||||
static public function fromStored(Notice $stored)
|
||||
{
|
||||
$class = get_called_class();
|
||||
return self::getByKeys( ['uri' => $stored->getUri()] );
|
||||
}
|
||||
|
||||
// The one who deleted the notice, not the notice's author
|
||||
public function getActor()
|
||||
{
|
||||
return Profile::getByID($this->profile_id);
|
||||
}
|
||||
|
||||
// As above: The one who deleted the notice, not the notice's author
|
||||
public function getActorObject()
|
||||
{
|
||||
return $this->getActor()->asActivityObject();
|
||||
}
|
||||
|
||||
static public function getObjectType()
|
||||
{
|
||||
return 'activity';
|
||||
}
|
||||
|
||||
protected $_stored = array();
|
||||
|
||||
public function getStored()
|
||||
{
|
||||
$uri = $this->getUri();
|
||||
if (!isset($this->_stored[$uri])) {
|
||||
$this->_stored[$uri] = Notice::getByPK(array('uri' => $uri));
|
||||
}
|
||||
return $this->_stored[$uri];
|
||||
}
|
||||
|
||||
public function getUri()
|
||||
{
|
||||
return $this->uri;
|
||||
}
|
||||
|
||||
public function asActivityObject(Profile $scoped=null)
|
||||
{
|
||||
$actobj = new ActivityObject();
|
||||
$actobj->id = $this->getUri();
|
||||
$actobj->type = ActivityObject::ACTIVITY;
|
||||
$actobj->actor = $this->getActorObject();
|
||||
$actobj->target = new ActivityObject();
|
||||
$actobj->target->id = $this->getUri();
|
||||
// FIXME: actobj->target->type? as in extendActivity, and actobj->target->actor maybe?
|
||||
$actobj->objects = array(clone($actobj->target));
|
||||
$actobj->verb = ActivityVerb::DELETE;
|
||||
$actobj->title = ActivityUtils::verbToTitle($actobj->verb);
|
||||
|
||||
$actor = $this->getActor();
|
||||
// TRANS: Notice HTML content of a deleted notice. %1$s is the
|
||||
// TRANS: actor's URL, %2$s its "fancy name" and %3$s the notice URI.
|
||||
$actobj->content = sprintf(_m('<a href="%1$s">%2$s</a> deleted notice {{%3$s}}.'),
|
||||
htmlspecialchars($actor->getUrl()),
|
||||
htmlspecialchars($actor->getFancyName()),
|
||||
htmlspecialchars($this->getUri())
|
||||
);
|
||||
|
||||
return $actobj;
|
||||
}
|
||||
|
||||
static public function extendActivity(Notice $stored, Activity $act, Profile $scoped=null)
|
||||
{
|
||||
// the original notice id and type is still stored in the Notice table
|
||||
// so we use that information to describe the delete activity
|
||||
$act->target = new ActivityObject();
|
||||
$act->target->id = $stored->getUri();
|
||||
$act->target->type = $stored->getObjectType();
|
||||
$act->objects = array(clone($act->target));
|
||||
|
||||
$act->title = ActivityUtils::verbToTitle($act->verb);
|
||||
}
|
||||
|
||||
static public function beforeSchemaUpdate()
|
||||
{
|
||||
$table = strtolower(get_called_class());
|
||||
$schema = Schema::get();
|
||||
$schemadef = $schema->getTableDef($table);
|
||||
|
||||
// 2015-12-31 If we have the act_uri field we want to remove it
|
||||
// since there's no difference in delete verbs and the original URI
|
||||
// but the act_created field stays.
|
||||
if (!isset($schemadef['fields']['act_uri']) && isset($schemadef['fields']['act_created'])) {
|
||||
// We don't have an act_uri field, and we also have act_created, so no need to migrate.
|
||||
return;
|
||||
} elseif (isset($schemadef['fields']['act_uri']) && !isset($schemadef['fields']['act_created'])) {
|
||||
throw new ServerException('Something is wrong with your database, you have the act_uri field but NOT act_created in deleted_notice!');
|
||||
}
|
||||
|
||||
if (!isset($schemadef['fields']['act_created'])) {
|
||||
// this is a "normal" upgrade from StatusNet for example
|
||||
echo "\nFound old $table table, upgrading it to add 'act_created' field...";
|
||||
|
||||
$schemadef['fields']['act_created'] = array('type' => 'datetime', 'not null' => true, 'description' => 'datetime the notice record was created');
|
||||
$schemadef['fields']['uri']['length'] = 191; // we likely don't have to discover too long keys here
|
||||
$schema->ensureTable($table, $schemadef);
|
||||
|
||||
$deleted = new Deleted_notice();
|
||||
// we don't actually know when the notice was created for the old ones
|
||||
$deleted->query('UPDATE deleted_notice SET act_created=created;');
|
||||
} else {
|
||||
// 2015-10-03 For a while we had act_uri and act_created fields which
|
||||
// apparently wasn't necessary.
|
||||
echo "\nFound old $table table, upgrading it to remove 'act_uri' field...";
|
||||
|
||||
// we stored what should be in 'uri' in the 'act_uri' field for some night-coding reason.
|
||||
$deleted = new Deleted_notice();
|
||||
$deleted->query('UPDATE deleted_notice SET uri=act_uri;');
|
||||
}
|
||||
print "DONE.\n";
|
||||
print "Resuming core schema upgrade...";
|
||||
}
|
||||
|
||||
function insert()
|
||||
{
|
||||
$result = parent::insert();
|
||||
|
||||
if ($result === false) {
|
||||
common_log_db_error($this, 'INSERT', __FILE__);
|
||||
// TRANS: Server exception thrown when a stored object entry cannot be saved.
|
||||
throw new ServerException('Could not save Deleted_notice');
|
||||
}
|
||||
}
|
||||
}
|
||||
67
modules/ActivityModeration/forms/deletenotice.php
Normal file
67
modules/ActivityModeration/forms/deletenotice.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||
|
||||
class DeletenoticeForm extends Form
|
||||
{
|
||||
protected $notice = null;
|
||||
|
||||
function __construct(HTMLOutputter $out=null, array $formOpts=array())
|
||||
{
|
||||
if (!array_key_exists('notice', $formOpts) || !$formOpts['notice'] instanceof Notice) {
|
||||
throw new ServerException('No notice provided to DeletenoticeForm');
|
||||
}
|
||||
|
||||
parent::__construct($out);
|
||||
|
||||
$this->notice = $formOpts['notice'];
|
||||
}
|
||||
|
||||
function id()
|
||||
{
|
||||
return 'form_notice_delete-' . $this->notice->getID();
|
||||
}
|
||||
|
||||
function formClass()
|
||||
{
|
||||
return 'form_settings';
|
||||
}
|
||||
|
||||
function action()
|
||||
{
|
||||
return common_local_url('deletenotice', array('notice' => $this->notice->getID()));
|
||||
}
|
||||
|
||||
function formLegend()
|
||||
{
|
||||
$this->out->element('legend', null, _('Delete notice'));
|
||||
}
|
||||
|
||||
function formData()
|
||||
{
|
||||
$this->out->element('p', null, _('Are you sure you want to delete this notice?'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Action elements
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function formActions()
|
||||
{
|
||||
$this->out->submit('form_action-no',
|
||||
// TRANS: Button label on the delete notice form.
|
||||
_m('BUTTON','No'),
|
||||
'submit form_action-primary',
|
||||
'no',
|
||||
// TRANS: Submit button title for 'No' when deleting a notice.
|
||||
_('Do not delete this notice.'));
|
||||
$this->out->submit('form_action-yes',
|
||||
// TRANS: Button label on the delete notice form.
|
||||
_m('BUTTON','Yes'),
|
||||
'submit form_action-secondary',
|
||||
'yes',
|
||||
// TRANS: Submit button title for 'Yes' when deleting a notice.
|
||||
_('Delete this notice.'));
|
||||
}
|
||||
}
|
||||
47
modules/ActivityModeration/locale/ActivityModeration.pot
Normal file
47
modules/ActivityModeration/locale/ActivityModeration.pot
Normal file
@@ -0,0 +1,47 @@
|
||||
# SOME DESCRIPTIVE TITLE.
|
||||
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
||||
# This file is distributed under the same license as the PACKAGE package.
|
||||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||
#
|
||||
#, fuzzy
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2019-06-08 18:20+0100\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
"Language: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=CHARSET\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
|
||||
#: classes/Deleted_notice.php:71
|
||||
#, php-format
|
||||
msgid "<a href=\"%1$s\">%2$s</a> deleted notice <a href=\"%3$s\">{{%4$s}}</a>."
|
||||
msgstr ""
|
||||
|
||||
#. TRANS: Notice HTML content of a deleted notice. %1$s is the
|
||||
#. TRANS: actor's URL, %2$s its "fancy name" and %3$s the notice URI.
|
||||
#: classes/Deleted_notice.php:156
|
||||
#, php-format
|
||||
msgid "<a href=\"%1$s\">%2$s</a> deleted notice {{%3$s}}."
|
||||
msgstr ""
|
||||
|
||||
#. TRANS: Button label on the delete notice form.
|
||||
#: forms/deletenotice.php:54
|
||||
msgctxt "BUTTON"
|
||||
msgid "No"
|
||||
msgstr ""
|
||||
|
||||
#. TRANS: Button label on the delete notice form.
|
||||
#: forms/deletenotice.php:61
|
||||
msgctxt "BUTTON"
|
||||
msgid "Yes"
|
||||
msgstr ""
|
||||
|
||||
#: ActivityModerationPlugin.php:64
|
||||
msgctxt "TITLE"
|
||||
msgid "Notice moderation"
|
||||
msgstr ""
|
||||
Reference in New Issue
Block a user