From 01f6d83b86901f6a0da6a9026185445e456121cc Mon Sep 17 00:00:00 2001 From: tenma Date: Wed, 30 Oct 2019 23:52:14 +0000 Subject: [PATCH] [MODULES] Fix VERSION constant to MODULE_VERSION in various modules --- .../ActivityModerationPlugin.php | 214 ------------------ modules/ActivityVerb/ActivityVerbModule.php | 4 +- modules/AuthCrypt/AuthCryptModule.php | 4 +- modules/Favorite/FavoriteModule.php | 4 +- .../HTMLPurifierSchemesModule.php | 4 +- modules/Share/ShareModule.php | 4 +- 6 files changed, 10 insertions(+), 224 deletions(-) delete mode 100644 modules/ActivityModeration/ActivityModerationPlugin.php diff --git a/modules/ActivityModeration/ActivityModerationPlugin.php b/modules/ActivityModeration/ActivityModerationPlugin.php deleted file mode 100644 index 25a790ebe6..0000000000 --- a/modules/ActivityModeration/ActivityModerationPlugin.php +++ /dev/null @@ -1,214 +0,0 @@ - - */ -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/modules/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)); - } -} diff --git a/modules/ActivityVerb/ActivityVerbModule.php b/modules/ActivityVerb/ActivityVerbModule.php index 7c4fb1f5c8..38ffd27814 100644 --- a/modules/ActivityVerb/ActivityVerbModule.php +++ b/modules/ActivityVerb/ActivityVerbModule.php @@ -31,7 +31,7 @@ if (!defined('GNUSOCIAL')) { exit(1); } class ActivityVerbModule extends Module { - const PLUGIN_VERSION = '2.0.0'; + const MODULE_VERSION = '2.0.0'; public function onRouterInitialized(URLMapper $m) { @@ -60,7 +60,7 @@ class ActivityVerbModule extends Module public function onModuleVersion(array &$versions): bool { $versions[] = array('name' => 'Activity Verb', - 'version' => self::PLUGIN_VERSION, + 'version' => self::MODULE_VERSION, 'author' => 'Mikael Nordfeldth', 'homepage' => 'https://www.gnu.org/software/social/', 'rawdescription' => diff --git a/modules/AuthCrypt/AuthCryptModule.php b/modules/AuthCrypt/AuthCryptModule.php index c938548dfc..8ec2a1a362 100644 --- a/modules/AuthCrypt/AuthCryptModule.php +++ b/modules/AuthCrypt/AuthCryptModule.php @@ -32,7 +32,7 @@ if (!defined('GNUSOCIAL')) { exit(1); } class AuthCryptModule extends AuthenticationModule { - const PLUGIN_VERSION = '2.0.0'; + const MODULE_VERSION = '2.0.0'; protected $hash = '$6$'; // defaults to SHA512, i.e. '$6$', in onInitializeModule() protected $statusnet = true; // if true, also check StatusNet style password hash protected $overwrite = true; // if true, password change means overwrite with crypt() @@ -177,7 +177,7 @@ class AuthCryptModule extends AuthenticationModule public function onModuleVersion(array &$versions): bool { $versions[] = array('name' => 'AuthCrypt', - 'version' => self::PLUGIN_VERSION, + 'version' => self::MODULE_VERSION, 'author' => 'Mikael Nordfeldth', 'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/AuthCrypt', 'rawdescription' => diff --git a/modules/Favorite/FavoriteModule.php b/modules/Favorite/FavoriteModule.php index 3bd7e7a6cd..073df30975 100644 --- a/modules/Favorite/FavoriteModule.php +++ b/modules/Favorite/FavoriteModule.php @@ -25,7 +25,7 @@ defined('GNUSOCIAL') || die(); class FavoriteModule extends ActivityVerbHandlerModule { - const PLUGIN_VERSION = '2.0.0'; + const MODULE_VERSION = '2.0.0'; protected $email_notify_fave = 1; @@ -629,7 +629,7 @@ class FavoriteModule extends ActivityVerbHandlerModule public function onModuleVersion(array &$versions): bool { $versions[] = array('name' => 'Favorite', - 'version' => self::PLUGIN_VERSION, + 'version' => self::MODULE_VERSION, 'author' => 'Mikael Nordfeldth', 'homepage' => 'http://gnu.io/', 'rawdescription' => diff --git a/modules/HTMLPurifierSchemes/HTMLPurifierSchemesModule.php b/modules/HTMLPurifierSchemes/HTMLPurifierSchemesModule.php index f59a94f57b..b94bd1bba2 100644 --- a/modules/HTMLPurifierSchemes/HTMLPurifierSchemesModule.php +++ b/modules/HTMLPurifierSchemes/HTMLPurifierSchemesModule.php @@ -25,12 +25,12 @@ if (!defined('GNUSOCIAL')) { exit(1); } */ class HTMLPurifierSchemesModule extends Module { - const PLUGIN_VERSION = '2.0.0'; + const MODULE_VERSION = '2.0.0'; public function onModuleVersion(array &$versions): bool { $versions[] = array('name' => 'HTMLPurifier Schemes', - 'version' => self::PLUGIN_VERSION, + 'version' => self::MODULE_VERSION, 'author' => 'Mikael Nordfeldth', 'homepage' => 'https://gnu.io/social', 'rawdescription' => diff --git a/modules/Share/ShareModule.php b/modules/Share/ShareModule.php index 7c41bbbc8b..b37fab7c40 100644 --- a/modules/Share/ShareModule.php +++ b/modules/Share/ShareModule.php @@ -25,7 +25,7 @@ if (!defined('GNUSOCIAL')) { exit(1); } */ class ShareModule extends ActivityVerbHandlerModule { - const PLUGIN_VERSION = '2.0.0'; + const MODULE_VERSION = '2.0.0'; public function tag() { @@ -371,7 +371,7 @@ class ShareModule extends ActivityVerbHandlerModule public function onModuleVersion(array &$versions): bool { $versions[] = array('name' => 'Share verb', - 'version' => self::PLUGIN_VERSION, + 'version' => self::MODULE_VERSION, 'author' => 'Mikael Nordfeldth', 'homepage' => 'https://gnu.io/', 'rawdescription' =>